# 1  Introductory example

We now present a short text that illustrates the most basic features of SLaTeX. Luckily, these cover the commands you will need and use the most. There are a couple of minor differences between the ways SLaTeX is used in LaTeX and in plain TeX (but see the entry in section 3 for \defslatexenvstyle if you wish to use the plain-TeX style with the LaTeX format, or the LaTeX style with the plain format).

# SLaTeX for LaTeX users

Consider the following LaTeX (and SLaTeX) file quick.tex:

% quick.tex
\documentclass{article}
\usepackage{slatex}
%
%That was LaTeX2e.  If you use
%LaTeX2.09, or LaTeX2e in
%2.09 compatibility mode, use
%
%\documentstyle[slatex]{article}
%
%or
%
%\documentstyle{article}
%\input slatex.sty
\begin{document}

In Scheme, the expression
\scheme|(set! x 42)| returns
an unspecified value, rather
than \scheme'42'.  However,
one could get a \scheme{set!}
of the latter style with:

\begin{schemedisplay}
(define-syntax setq
(syntax-rules ()
[(setq x a)
(begin (set! x a)
x)]))
\end{schemedisplay}

\end{document}


First, the SLaTeX definitions in the style file slatex.sty are loaded into your LaTeX file. This may be done either via \usepackage or \input — or, if you use LaTeX 2.09, as a \documentstyle option.

In-text code is introduced by the SLaTeX control sequence \scheme and is flanked by a pair of identical characters that are not alphabetic letters or “{”. As a special convenient case, SLaTeX also allows the form \scheme{...}.

The SLaTeX control sequences for displayed code are the opening

\begin{schemedisplay}


and the closing

\end{schemedisplay}


The file is now SLaTeX’d by running the command slatex on it from the Unix or DOS or OS/2 command line:

slatex quick


or

slatex quick.tex


Alternatively, you can load the file callsla.scm into your Scheme or Common Lisp, and then call

(call-slatex "quick")


This calls a Scheme program slatex.scm that typesets the Scheme code fragments from quick.tex into temporary files. Thereafter, quick.tex along with the temporary files are passed to LaTeX. (For information on judiciously reusing temporary files, see \separateincludes.) The resulting quick.dvi file, when viewed or printed, looks like:

In Scheme, the expression (set! x 42) returns an unspecified value, rather than 42. However, one could get a set! of the latter style with:

(define-syntax setq
(syntax-rules ()
[(setq x a)
(begin (set! x a)
x)]))


Note that setq, although not normally a syntactic keyword in Scheme, is nevertheless automatically recognized as such because of the context in which it occurs. No special treatment is needed to ensure that it will continue be treated as such in any subsequent Scheme code in the document.

# SLaTeX for plain TeX users

SLaTeX works much the same way with plain TeX as with LaTeX, but for only two exceptions. First, since plain TeX doesn’t have \documentstyle, the file slatex.sty must be introduced via an \input statement before its commands can be used in the plain TeX source.

Second, since plain TeX does not have LaTeX’s \begin{env} ... \end{env} style of environments, any environment commands in SLaTeX are invoked with the opening \env and the closing \endenv.

The plain TeX version of quick.tex looks like:

% quick.tex
\input slatex.sty

In Scheme, the expression
\scheme|(set! x 42)| returns
an unspecified value, rather
than \scheme'42'.  However,
one could get a \scheme{set!}
of the latter style with:

\schemedisplay
(define-syntax setq
(syntax-rules ()
[(setq x a)
(begin (set! x a)
x)]))
\endschemedisplay
\bye


The file is now SLaTeX’d by invoking slatex as before — SLaTeX is clever enough to figure out whether the file it operates on should later be sent to LaTeX or plain TeX.