Re: LaTeX listings and (o)caml

From: Christian Lindig (
Date: Sat Nov 06 1999 - 12:16:37 MET

Date: Sat, 6 Nov 1999 12:16:37 +0100
From: Christian Lindig <>
To: Vincent Poirriez <>
Subject: Re: LaTeX listings and (o)caml
In-Reply-To: <>; from on Fri, Nov 05, 1999 at 04:04:19PM +0000

On Fri, Nov 05, 1999 at 04:04:19PM +0000, Vincent Poirriez wrote:

> before I start the work, does someone have designed a "definition"
> of the caml languages to be used with the package listings of LaTeX?
> This should provide an easy way to have nice formatted code in
> slides

I don't know about the package listing of LaTeX but have written a
tool that marks up OCaml code for HTML, XML, Vile, and Lout. It has a
modular design, so adding a new LaTeX backend takes less than 100
lines of code. The tool recognizes comments, strings, keywords,
operators, etc by scanning an OCaml source and permits the backend to
format them. All other parts of a source file pass untouched. The
man page is attached below -- mail me for the code if you are
interested. I think a similar tool was announced on this list some
time ago.

-- Christian

 Christian Lindig       Gaertner Datensysteme GbR, Braunschweig,  Germany 
                        phone: +49 531 233 55 55   fax: +49 531 233 55 56 

NAME ocamldoc - markup Objective Caml source ocde

SYNOPSIS ocamldoc [ *format* ] [ *file* ]

ocamldoc -help

ocamldoc -version

DESCRIPTION ocamldoc reads an Objective Caml (see ocaml(1)) source file and pretty prints it accordingly to *format*. Pretty printing is done by highlighting keywords, comments, operators, and literals in the source; all other parts of the source pass untouched. The OCaml source is read from *file* or *stdin*; output goes to *stdout*. Please note, that ocamldoc does not reformat the source code like indent(1) does for C code. It only marks up some syntactic classes inside the code.

OPTIONS -html [ -title *title* ] The OCaml source is prepared for HTML. When a *title* is specified a standalone HTML file is generated. Without the - title flag code is embedded into a <pre> element but the mandatory outer structure of a HTML document is missing. The -title flag can be abbreviated as -t. Highlighting is not hard coded into the output but achieved through Cascading Style Sheets (CSS): each syntactical element is embedded into a <span> element with an additional class attribute denoting its syntactical class. For example:

let hello = "hello"

becomes (without the line breakes):

<span class='keyword'>let</span> hello <span class='operator'>=</span> <span class='strlit'>"hello"</span>

The class attributes are matched by CSS rules which define the actual appearance of the code. A sample CSS file comes with the distribution. A standalone HTML page points to a CSS file ocaml.css in the actual directory.

-xml [ -title *title* ] The formatting for XML works very much like the formatting for HTML. With a given *title* a standalone XML document is generated; the outermost element is <src> with a title attribute. The code inside this element is exactly like when formatting for HTML.

-vile Highlighting for the Vile editor vi(1). Syntax highlighting in Vile is done by external filters like this. See the Vile documentation for the format. This version of ocamldoc works with Vile 8.3.

When the ocamldoc binary is called under the name vile- ocaml-filt and without a format option it formats the input also for Vile. This feature makes ocamldoc compliant to the Vile filter naming scheme.

-lout Source code is marked up for the Basser Lout document formatter and a Lout package camlprint provided by Basile Starynkevitch.

-ascii The input is not marked up at all. This serves mainly as a test case for the internal scanner of ocamldoc.

-version Reports the current version of ocamldoc to stdout.

-help Prints a summary of command line options to stderr.

RETURN VALUE ocamldoc returns 1 in case of an error and 0 on success.

SEE ALSO ocaml(1)

AUTHOR Christian Lindig,,

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:28 MET