The extract-code tool

View this page in Romanian courtesy of azoft


The extract-code tool takes an source file annotated with special comment forms and extracts LaTeX files that can be used in a document. The generated LaTeX uses the code.sty package. Currently, it supports both SML and Moby source files, but it is easy to extend to other languages. The tool can also produce HTML files in a form suitable for inclusion in a LaTeX document being processed by HeVeA.


The extract-code tool is distributed in source form as a gzipped tar file (extract-code.tgz). It was last modified on May 17, 2014; see the CHANGES file in the distribution for more information.

You can also get the source via anonymous svn using the command

% svn co --username anonsvn \ extract-code

The password is anonsvn.


To install extract-code, you must have SML/NJ installed on your machine and in your PATH. Assuming that this is the case, then installation is simple:
  1. Configure the installation by running the configure script. You can set the installation directory by using the --prefix option (the default is /usr/local).
  2. Build the system using the build make target.
  3. Install the system using the install make target.
For example, to build and install the system /usr, one would use the following commands:
% ./configure --prefix=/usr
% make build
% make install
After running these commands, /usr/bin would hold the extract-code command.


extract-code options files
where options are taken from the following:
-lang language

Use language as the input language. Currently, the following languages are supported:

Language File suffix
cml .cml
manticore .pml
moby .mby
sml .sml and .sig


Generate HeVeA as the output format (this is the default). Output files will have a .hva suffix.


Generate LaTeX as the output format (this is the default). Output files will have a .tex suffix.


Generate text files with formatting comments stripped.


Strip the formatting comments from the source files; for an input file foo, the stripped output will be in foo.strip.

Formatting commands

Formattting commands are written as comments in the source language. These comments must start in the first column of their line. Here are the commands and their descriptions:
(*@FILE attributes files *)
open the list of files for extracted output with the specified attibutes (attributes are either @LEFT, @CENTER)

(*@BEGIN files *)
start directing output to the list of files (these files are called active).

(*@END files *)
stop directing output to the list of files; if files is empty, then all active files are stoped.

suspend/resume output to the currently active files.

suspend/resume highlighting the output to the current files. Currently, highlighting is represented by underlining.

(*@IF-FILE files *)
(*@ELIF-FILE files *)
(*@ELSE *)
(*@END-IF *)
conditional extraction.

  ... stuff ...
insert the stuff into the currently active files.
treat the token as a keyword. This markup is not supported for all source languages.

Last modified: May 28, 2014.
Comments to: John Reppy