SchemeWEB

John D. Ramsdell

SchemeWEB provides simple support for literate programming in any dialect of Lisp. Originally created for use with Scheme, it defines a new source file format which may be used to produce LaTEX input or Lisp code.

SchemeWEB source lines are divided into text and code. Lines of code start with a line beginning with “(”, and continue until the line containing the matching “)”. The remaining lines are text lines, and they are treated as comments.

When producing a LaTEX document, both the text lines and the code lines are copied into the document source file, but the code lines are surrounded by a pair of formatting commands (\begin{astyped} and \end{astyped}). This LaTEX environment formats the code as written, in typewriter font. A Lisp comment within a code line is formatted in an \mbox in Roman font. A SchemeWEB style command should include the astyped style option, so that the astyped environment is available. An example:

    \documentstyle[astyped]{article}

SchemeWEB was designed under the constraint that code lines must be unmodified Lisp code, and text lines must be unmodified LaTEX code. Text editors with support for Lisp and LaTEX, such as Emacs, may be used for SchemeWEB code much as they are used for Lisp code and LaTEX code.

For those who prefer not to modify the reader used by their Lisp system’s loader and compiler, the rule that text lines must be unmodified LaTEX code has been relaxed. Text lines that begin with “;” are copied without the initial “;”.

Usage in Scheme

The file sweb.scm contains programs used to obtain code or LaTEX from a SchemeWEB source file. The Scheme expression

                                                 .SUFFIXES:      .dvi .tex .scm .sw
                                                 .sw.dvi:
                                                         make $*.tex && make $*.dvi
                                                 .sw.tex:
                                                         sweave $*.sw $*.tex
                                                 .tex.dvi:
                                                         latex $*
                                                 .sw.scm:
                                                         stangle $*.sw $*.scm

Figure 1: A SchemeWEB Makefile

                                                     (TANGLE "SchemeWEB file" "Scheme
                                                     file")

creates Scheme source from a SchemeWEB file, and the expression

                                                     (WEAVE "SchemeWEB file" "LaTEX
                                                     file")

creates LaTEX source.

The file reader.sw contains a SchemeWEB reader in R^{4}R Scheme. Use that reader with your Scheme system’s loader and compiler to avoid running TANGLE and creating a temporary file.

Usage in a Unix shell

Files are produced from SchemeWEB source using the Unix shell commands

                                                     sweave [SchemeWEB file] [LaTEX file]
                                                     stangle [SchemeWEB file] [Scheme
                                                     file]

The obvious make file is in Figure 1. It uses the convention that the extension for SchemeWEB files is

“.sw.”