Prev Next Up Home Keys Figs Search New

Prolog Code in LaTeX

Appeared in Volume 9/1, February 1996

Keywords: latex.


passani@idt.unit.no
Luca Passani
17th September 1995

I added some Prolog code to my thesis by inserting it in a verbatim environment. It looked a bit ugly, and I couldn't understand why. Then I suddenly realized that all of the tabs had been ignored, spoiling the indentation, and flattening everything down to the left margin of the page.

Any hints on how to fix this?


schauer@informatik.uni-koblenz.de
Holger Schauer
19th September 1995

This is caused by the fact that LaTeX doesn't interpret tabs the way you might think.

Try latex2pl from the cmu ai repository. It allows you to program in Prolog and document your code in one piece of text. But be warned: it won't work with latex2e, but works with latex2.09.


mathieu@lifl.fr
Mathieu Philippe Philou
19th September 1995

You could use tgrind which indents your Prolog code in a TeX file. You just have to include the result in your text after.

Synopsis:

tgrind [ -f ] [ - ] [ -n ] [ -h header ]
       [ - d <description file> ] 
       [ -l<language> ] [ -r ] [ -s <size> ] 
        name ...

tgrind formats program sources in a nice style using TeX(1). Comments are placed in italics, keywords in bold face and strings in typewriter font. Source file line numbers appear in the right margin (every 10 lines). The start of a function is indicated by the function name in large type in the right margin.

In regular mode tgrind processes its input file(s) and passes them to TeX(1) for formating and output.

In format mode (i.e., when the -f flag is used), tgrind processes its input file(s) and writes the result to standard output. This output can be saved for later editting, inclusion in a larger document, etc.

The options are:
-f Forces format mode

- Take input from standard input

-n Don't boldface keywords

-h Specifies text to go on the left side of every output page (default is none)

-d Specifies the language definitions file (default is /usr/local/lib/vgrindefs)

-l Specifies the language to use. Currently known are PASCAL ( -lp), RATFOR (-lr), Modula-2 (-lm2), MODEL (-lm), C (-lc or the default), ISP (-li), Yacc ( - ly), Prolog ( - lprolog), Icon (-lI), TeX (-ltex), CSH (-lcsh), and Bourne Shell (-lsh).

-r Forces landscape format for output (the default is portrait).

-s Specifies the fontsize of the main text in points (default is 10). The available sizes are 8, 9 and 10.


alain.kessi@psi.ch
Alain Kessi
19th September 1995

There are two ways that come to my mind which will allow you to enhance the look of your document. The simple way is to use the verbatimtab environment, as defined in the moreverb package (which is based on the verbatim package). LaTeX usually considers tabs to be equivalent to single spaces. verbatimtab makes the exception to the rule that you want for listings. Have a look also at the \listinginput command in the same package, which can also number the lines of your listing.

The second way to go is to use the lgrind program (available in C source), which allows you to typeset (pretty-print) listings of various programming languages. It uses a database of definitions for various programming languages, with information on keywords, etc. to be highlighted. One Prolog dialect is included in the database. Here's the entry in the database, so you can judge if it's the dialect you use:

prolog|PROLOG:\
        :bb=\:-:be=.:cb=%:ce=$:ab=/*:ae=*/:\
        :zb=@:ze=@:tb=%%:te=%%:mb=%\$:me=\$%:vb=%\|:ve=\|%:\
        :sb=":se=\e":lb=':le=\e':oc:\
        :kw=op mod abort ancestors arg ascii ask assert asserta assertz\
        atom atomic char clause close concat consult ed ef em eof fail\
        file findall write functor getc integer is length listing load name\
        nl nonvar not numbervars op or pp prin print private prompt putc\
        ratom read read_from_this_file rename repeat retract retractall\
        save see seeing seen sh skip statistics subgoal_of system tab\
        tell telling time told trace true unload untrace var write:

You can find both moreverb/verbatim and lgrind on CTAN (ftp://ftp.dante.de/ or ftp://ftp.tex.ac.uk). Type:
quote site index moreverb (or verbatim, or lgrind)

to locate the package in the directory tree. To download the entire directory of lgrind at once, go to its parent directory, set binary, and type 'get lgrind.tar.Z' (or lgrind.tar.gz).

Prev Next Up Home Keys Figs Search New