2  Using eval

Everything of course depends on what the Scheme code inside the \evals is. As above, one can use Scheme as a scratchpad to perform calculations that are beyond TeX. But one can also use \eval to define a specification language in Scheme, and then make effective use of that language in subsequent \evals.

In the following, we use a picture language called PicScheme, which is defined in Scheme. The operators of PicScheme generate TeX and MetaPost [12] code fragments, but their true power lies in their allowing the use of the high-level language Scheme to compose complex pictures. The PicScheme code is defined inside an \eval in the TeX macro file picscheme.tex. For a sample use of PicScheme, create a file circlepic.tex with the following contents:

\input eval4tex     % load \eval 
\input picscheme    % load picture language PicScheme 

\eval{
(set! *unit‑length* (dimen 4 'cm))

(picture
  (lambda ()
    ;draw circle of dia 1 with center at (0,0)
    (draw (full‑circle))
    ;draw horizontal diameter
    (draw (path (point ‑.5 0) '‑‑ (point .5 0)))
    ;write length of diameter just above center
    (label (point 0 .05) "1")
    ;write length of circumference just outside
    ;circle, at 45 degrees
    (let ((x (/ .55 (sqrt 2))))
      (label (point x x) "$\\pi$"))))
}

\bye 

Note that this example contains two \evals: The first is the \eval in picscheme.tex which defines the PicScheme operators, and the second is the \eval in the body of circlepic.tex that uses the PicScheme operators to draw the circle.

We enable the \eval Scheme code in circlepic.tex the same way as before. We run TeX on circlepic.tex, then Scheme on circlepic.eval4tex, and then TeX again on circlepic.tex:

tex circlepic 
racket -f circlepic.eval4tex 
tex circlepic 

The resulting circlepic.dvi has the following picture:

[index-Z-G-1.gif]

In addition, you can run TeX2page directly on circlepic.tex to produce a Web-browsable version:

tex2page circlepic 

We will now describe in detail the capabilities provided by PicScheme.