Consider a TeX document circle.tex
with
the following contents:
\input eval4tex % defines the \eval macro The ratio of the circumference of a circle to its diameter is \eval{
;following prints pi, because cos(pi) = -1 (display (acos -1))
}. \bye
We have chosen a plain TeX document for our example, but the same approach works for LaTeX documents too.
circle.tex
first inputs the TeX macro
file eval4tex.tex
, which is available in the
eval4tex distribution, and which defines
a TeX macro
called \eval
. This \eval
macro is used in the body of
circle.tex
and its argument is some Scheme code
enclosed in braces.
Now run TeX on circle.tex
:
tex circle
(If circle.tex
were a LaTeX file, you would use
latex circle
here.) This creates an
auxiliary file called circle.eval4tex
that extracts the \eval
-embedded Scheme code from circle.tex
.
Now evaluate the Scheme file circle.eval4tex
. For example, with
Racket, you could do
racket -f circle.eval4tex
This produces an auxiliary TeX file circle‑Z‑E‑1.tex
containing an appropriate TeX replacement for the
\eval
’d Scheme code in circle.tex
. In general,
you will get an aux TeX file
for each \eval
in
the source document, and if the source document is
named circle.tex
, the aux files are named
circle‑Z‑E‑n.tex
, where n = 1, 2,
…
.
Re-running TeX on circle.tex
will now insert the
aux file circle‑Z‑E‑1.tex
at the point of
the \eval
, so the final DVI output,
circle.dvi
, looks like:
The ratio of the circumference of a circle to its diameter is 3.141592653589793.
To summarize, we did
tex circle; racket -f circle.eval4tex; tex circle
The first call to tex
wrote out an aux file; the
call to eval4tex
processed this aux file to produce
one or more other aux files; and the final call to
tex
slurped these latter aux files into the
document.
This strategy is quite common in the TeX world. The popular TeX-support programs BibTeX and MakeIndex, which generate bibliographies and indices respectively, both operate this way.
You can also run the program TeX2page [5] on circle.tex
to get an HTML
version of the document with the same content. As TeX2page is written in
Scheme, it will automatically convert the \eval
s in circle.tex
without requiring you to call Scheme separately.
tex2page circle
N.B. TeX documents intended to be processed by TeX2page typically load the
macro file tex2page.tex
. Please see the TeX2page documentation for
more details.