SMLNJtrans is a Standard ML program for generating SML/NJ transcripts in LaTeX. It makes use of the Unix structure of the Standard ML Basis Library, and so isn't currently available for Windows.
Under Unix/Linux/Mac OS X, it is invoked as follows:
smlnjtrans SMLNJ PROMPTS FILE...
SMLNJ should be an SML/NJ executable, PROMPTS should be a (possibly empty) string of prompt characters, and FILE... should be existing files of SML code (optionally annotated with overlay counters — see below).
SMLNJ need not not be fully qualified; if necessary, it is fully qualified using the value of the user's PATH environment variable. SMLNJ should be a shell script that invokes an SML/NJ heap image.
The characters of PROMPTS, which must be printable, non-white space characters, plus the characters "-" and "=", must be SMLNJ's prompt characters. Whenever SMLNJ, or the SML code in the files, prompts for input, it must do so by printing, at the beginning of a line, one of the prompt characters followed by a single blank. Furthermore, SMLNJ, or the SML code in the files, must never begin a line with a prompt character followed by a blank, when it is not prompting for input.
SMLNJtrans runs SMLNJ as a child process. It discards the output from SMLNJ until it receives SMLNJ's first prompt. Then, smlnjtrans enters its main loop, in which it processes the files, in order.
When it processes file, FILE, smlnjtrans produces a LaTeX transcript, FILE.tex, of the result of feeding the lines of FILE to SMLNJ. The transcript is indented to \leftmargini, and is typeset at size \small, in typewriter font. The text of FILE is set in upright shape, whereas the output of SMLNJ is set in slanted shape. The transcript may be included in a larger document with the command \input{FILE.tex}.
If file FILE is annotated with an overlay counter, and so has the form FIL:CTR where CTR is a numeral, then the LaTeX generated for FILE will use the Beamer document class's Seminar-style cumulative overlays feature to single-step through the evaluation of FIL. The overlay corresponding to the first input prompt will be CTR.
Suppose that foo, goo and hoo are the files
val x = 4; (* /hello{there} ~*) val y = x + 1; val z = "-\\{hello}~*\n"; print z; print "==\n";
and
fun f nil = 0 | f (_ :: xs) = 1 + f xs;
and
f [1, 2, 3, x]; f nil;
respectively. Running the command
smlnjtrans sml "" foo goo hoo
produces the files foo.tex, goo.tex and hoo.tex. Let example.tex be the file
\documentclass[11pt]{article} \begin{document} Some initial text that repeats that repeats that repeats that repeats that repeats that repeats that repeats that repeats that repeats. \input{foo.tex} Some more text. \input{goo.tex} Yet some more. \input{hoo.tex} The final text. \end{document}
Running the commands
latex example.tex dvips -Ppdf example.dvi -o example.ps ps2pdf example.ps
produces example.pdf.
SMLNJtrans's distribution, including source and an example, is hosted on GitHub: github.com/alleystoughton/SMLNJtrans.