This repository has been archived on 2022-08-10. You can view files and clone it, but cannot push or open issues or pull requests.
chez-openbsd/stex/doc/stex.html

968 lines
24 KiB
HTML
Raw Permalink Normal View History

2022-07-29 15:12:07 +02:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><!-- DO NOT EDIT THIS FILE-->
<!-- Edit the .tex version instead-->
<html>
<head>
<title>Introduction to stex</title>
<link href="stex.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Introduction to stex</h1>
<h2>R. Kent Dybvig and Oscar Waddell</h2>
<h3>April 2016</h3>
<p>
<table cellpadding=0 cellspacing=0>
<tr><td align="right"><b>1.&nbsp;</b><td><b><a class=plain href="./stex.html#g0">Overview</a></b></td></tr>
<tr><td align="right"><b>2.&nbsp;</b><td><b><a class=plain href="./stex.html#g1">Installation</a></b></td></tr>
<tr><td align="right"><b>3.&nbsp;</b><td><b><a class=plain href="./stex.html#g2">Usage notes</a></b></td></tr>
<tr><td align="right"><b>4.&nbsp;</b><td><b><a class=plain href="./stex.html#g3">Basic stex commands</a></b></td></tr>
<tr><td></td><td><table cellpadding=0 cellspacing=0>
<tr><td><b>4.1.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g4">Inline code</a></b></td></tr>
<tr><td><b>4.2.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g5">Code displays</a></b></td></tr>
<tr><td><b>4.3.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g6">Variables</a></b></td></tr>
<tr><td><b>4.4.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g7">Raw text in code</a></b></td></tr>
<tr><td><b>4.5.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g8">Generated output</a></b></td></tr>
<tr><td><b>4.6.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g9">Verbatim Scheme displays</a></b></td></tr>
</table></td></tr>
<tr><td align="right"><b>5.&nbsp;</b><td><b><a class=plain href="./stex.html#g10">Scheme transcripts</a></b></td></tr>
<tr><td></td><td><table cellpadding=0 cellspacing=0>
<tr><td><b>5.1.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g11">Automatic transcript generation</a></b></td></tr>
<tr><td><b>5.2.&nbsp;</b></td><td><b><a class=plain href="./stex.html#g12">Loading initialization code</a></b></td></tr>
</table></td></tr>
<tr><td align="right"><b>6.&nbsp;</b><td><b><a class=plain href="./stex.html#g13">html-prep support for the <tt>tabular</tt> environment</a></b></td></tr>
</table>
<p>
<p>
<a name="g0"></a>
<h3><a name="./stex:h0"></a>1. Overview</h3>
<p>
The <i>stex</i> package consists of two main programs and some supporting
items, such as make files, make-file templates, class files, and style
files.
The two main programs are <b>scheme-prep</b> and <b>html-prep</b>.
<b>scheme-prep</b> performs a conversion from "stex"-formatted files
into latex-formatted files, while <b>html-prep</b> converts (some)
latex-formatted files into html-formatted files.
<p>
An stex file is really just a latex file extended with a handful of
commands for including Scheme code (or pretty much any other kind of code,
as long as you don't plan to use the Scheme-specific transcript support)
in a document, plus a couple of additional features rather arbitrarily
thrown in.
<p>
The subset of latex-formatted files <b>html-prep</b> is capable of
handling is rather small but has nevertheless been useful for our
purposes, which include producing html versions of a couple of books
(<i>The Scheme Programming Language</i>, Editions 2-4 and the Chez Scheme
User's Guides for Versions 6-9), the scheme.com web site, class websites,
class assignments, and various other documents.
<p>
<a name="g1"></a>
<h3><a name="./stex:h1"></a>2. Installation</h3>
<p>
A prerequisite to building and using stex is to have Chez Scheme or
Petite Chez Scheme installed on your system.
You'll also need pdflatex, dvips, ghostscript, and netbpm.
We've run stex under Linux and OS X but have not tried to run it under
Windows.
<p>
The simplest way to install stex for your personal use is to clone the
stex directory into your home directory, cd into the stex directory,
and run make:
<p>
<p><tt>make&nbsp;BIN=<i>bindir</i></tt>
<p>where <tt><i>bindir</i></tt> is the directory where make will find the scheme or
petite executables.
<p>
This will create a subdirectory, named for the installed Chez Scheme
machine type, containing binary versions of the programs.
<p>
You can also use "make install" to make stex available for other users.
<p>
<p><tt>sudo&nbsp;make&nbsp;install&nbsp;BIN=<i>bindir</i>&nbsp;LIB=<i>libdir</i></tt>
<p>where <tt><i>bindir</i></tt> is as described above, and <tt><i>libdir</i></tt> is the
directory where the stex library directory should be installed.
<p>
<a name="g2"></a>
<h3><a name="./stex:h2"></a>3. Usage notes</h3>
<p>
The simplest way to get started with stex is to get this document to
build (in the doc directory) and create your own document by cloning
this document's source file (stex.stex) and make file (Makefile).
If you've installed stex in your home directory, you should be able to
build this document by running "make" without arguments in the doc
directory.
If you've installed stex elsewhere, you'll first have to modify the
include for Mf-stex to reflect its installed location.
<p>
Makefile is where you declare your stex sources and various other things,
like bibtex and graphics files.
If you don't have anything much more complicated than this document,
you might just need to change the line that declares the main stex entry
point, i.e., the line that reads <tt>x&nbsp;=&nbsp;stex</tt>, to reflect the name
of your document.
<p>
The make is orchestrated by Mf-stex, which knows how to run
<b>scheme-prep</b>, <b>html-prep</b>, <b>pdflatex</b> (multiple
times), and various other commands to produce both pdf and html versions
of the stex document.
<p>
You can also consult the more elaborate stex source and make files for the
Chez Scheme User's Guide in the csug directory of a Chez Scheme release.
<p>
<a name="g3"></a>
<h3><a name="./stex:h3"></a>4. Basic stex commands</h3>
<p>
<a name="g4"></a>
<h4><a name="./stex:h4"></a>4.1. Inline code</h4>
<p>
An stex document includes inline Scheme (or other) code via the
<tt>\scheme</tt> command, e.g.:
<p>
<blockquote>
<pre>
When called with two arguments, \scheme{cons} creates a pair of the two
arguments, e.g., \scheme{(cons 3 4)} produces \scheme{(3 . 4)}.
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
When called with two arguments, <tt>cons</tt> creates a pair of the two
arguments, e.g., <tt>(cons&nbsp;3&nbsp;4)</tt> produces <tt>(3&nbsp;.&nbsp;4)</tt>.
</blockquote>
<p>
<a name="g5"></a>
<h4><a name="./stex:h5"></a>4.2. Code displays</h4>
<p>
An stex document includes out-of-line Scheme (or other) code via
<tt>\schemedisplay</tt> and <tt>\endschemedisplay</tt>, e.g.:
<p>
<blockquote>
<pre>
\schemedisplay
(define fact
(lambda (x)
"a light year is a measure of distance"))
(define fib
(lambda (x)
"a light year is a measure of time"))
\endschemedisplay
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
<p><tt>(define&nbsp;fact<br>
&nbsp;&nbsp;(lambda&nbsp;(x)<br>
&nbsp;&nbsp;&nbsp;&nbsp;"a&nbsp;light&nbsp;year&nbsp;is&nbsp;a&nbsp;measure&nbsp;of&nbsp;distance"))
<br>
<br>
(define&nbsp;fib<br>
&nbsp;&nbsp;(lambda&nbsp;(x)<br>
&nbsp;&nbsp;&nbsp;&nbsp;"a&nbsp;light&nbsp;year&nbsp;is&nbsp;a&nbsp;measure&nbsp;of&nbsp;time"))</tt>
<p></blockquote>
<p>
Within a Scheme display, <tt>;=&gt;</tt> is converted into a double right arrow
(<img src="math/stex/0.gif" alt="<graphic>">), <tt>;-&gt;</tt> into a single right arrow (<img src="math/stex/1.gif" alt="<graphic>">), and
<tt>;==</tt> into a phantom of the same size.
This is useful for showing what a piece of code translates or evaluates to,
e.g.:
<p>
<blockquote>
<pre>
A \scheme{let} expression expands into a call to a \scheme{lambda}
expression, e.g.:
\schemedisplay
(let ([a 17]) ;-&gt; ((lambda (a) (+ a a))
(+ a a)) ;== 17)
\endschemedisplay
A \scheme{let} expression first evaluates the right-hand-side
expression, then evaluates the body in an environment that binds
the left-hand-side variable to the resulting value, e.g.:
\schemedisplay
(let ([a 17]) ;=&gt; 17
(+ a a))
\endschemedisplay
</pre>
<p>
</blockquote>
<p>
produces
<p>
<blockquote>
A <tt>let</tt> expression expands into a call to a <tt>lambda</tt>
expression, e.g.:
<p><tt>(let&nbsp;([a&nbsp;17])&nbsp;<img src="math/stex/1.gif" alt="<graphic>">&nbsp;((lambda&nbsp;(a)&nbsp;(+&nbsp;a&nbsp;a))<br>
&nbsp;&nbsp;(+&nbsp;a&nbsp;a))&nbsp;&nbsp;&nbsp;&nbsp;<img src="gifs/ghostRightarrow.gif">&nbsp;&nbsp;17)</tt>
<p>A <tt>let</tt> expression first evaluates the right-hand-side
expression, then evaluates the body in an environment that binds
the left-hand-side variable to the resulting value, e.g.:
<p><tt>(let&nbsp;([a&nbsp;17])&nbsp;<img src="math/stex/0.gif" alt="<graphic>">&nbsp;17<br>
&nbsp;&nbsp;(+&nbsp;a&nbsp;a))</tt>
<p></blockquote>
<p>
<a name="g6"></a>
<h4><a name="./stex:h6"></a>4.3. Variables</h4>
<p>
Code can include emphasized variables via the <tt>\var</tt> command, e.g.:
<p>
<blockquote>
<pre>
\scheme{(let ([\var{x} \var{e}]) \var{body})} binds the variable \var{x} to
the value of \var{e} in \var{body}.
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
<tt>(let&nbsp;([<i>x</i>&nbsp;<i>e</i>])&nbsp;<i>body</i>)</tt> binds the variable <tt><i>x</i></tt> to
the value of <tt><i>e</i></tt> in <tt><i>body</i></tt>.
</blockquote>
<p>
If the text within a <tt>\var</tt> form contains an underscore, the
following character or bracketed subform is converted into a subscript,
e.g., <tt>\var&#123;abc_3&#125;</tt>
produces <tt><i>abc<sub>3</sub></i></tt>, and <tt>\var&#123;7e5_16&#125;</tt>
produces <tt><i>7e5<sub>16</sub></i></tt>.
<p>
<tt>\var</tt> forms may appear within a <tt>\scheme</tt> form, within a Scheme display
formed by <tt>\schemedisplay</tt> and <tt>\endschemedisplay</tt> commands,
or by itself outside of either.
<p>
<a name="g7"></a>
<h4><a name="./stex:h7"></a>4.4. Raw text in code</h4>
<p>
Raw text can be included in code via the <tt>\raw</tt> command.
For example:
<p>
<blockquote>
<pre>
\schemedisplay
(sqrt \raw{$x$}) \is \raw{$\sqrt{x}$}.
\endschemedisplay
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
<p><tt>(sqrt&nbsp;<i>x</i>)&nbsp;<img src="math/stex/0.gif" alt="<graphic>">&nbsp;<img src="math/stex/2.gif" alt="<graphic>">.</tt>
<p></blockquote>
<p>
<a name="g8"></a>
<h4><a name="./stex:h8"></a>4.5. Generated output</h4>
<p>
Output generated by a Scheme program can be inserted into the output via
<tt>\generated</tt> and <tt>\endgenerated</tt> commands, e.g.:
<p>
<blockquote>
<pre>
\generated
(let ()
(define fibs
(lambda (x y n)
(if (= n 0)
'()
(cons x (fibs y (+ x y) (- n 1))))))
(let ([n 5])
(printf "first ~r primes: ~{~s~^, ~}\n" n (fibs 0 1 n))))
\endgenerated
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
first five primes: 0, 1, 1, 2, 3
<p>
</blockquote>
<p>
<a name="g9"></a>
<h4><a name="./stex:h9"></a>4.6. Verbatim Scheme displays</h4>
<p>
When special features, like <tt>\var</tt> forms, need to be
suppressed within a Scheme display, a document can use
<tt>\schemeverbatim</tt> and <tt>\endschemeverbatim</tt> instead of
<tt>\schemedisplay</tt> and <tt>\endschemedisplay</tt>.
This document makes extensive use of this feature.
<p>
<a name="g10"></a>
<h3><a name="./stex:h10"></a>5. Scheme transcripts</h3>
<p>
<a name="g11"></a>
<h4><a name="./stex:h11"></a>5.1. Automatic transcript generation</h4>
<p>
The <b>scheme-prep</b> package supports a
<tt>\transcript</tt> command for automatically generating Scheme transcripts
from input supplied in the document source.
All text from the <tt>\transcript</tt> marker up to and including the
<tt>\endtranscript</tt> marker is replaced with a transcript generated
by supplying the intervening text as the input to a Scheme caf&eacute; (REPL).
If the Scheme transcript needs to contain the sequence
<tt>\endtranscript</tt>, a different terminator may be specified as an
optional argument to <tt>\transcript</tt>.
The terminator must be a backslash followed by one or more alphabetic
characters, and is specified without the backslash in the optional argument.
<p>
Three pairs of commands may be redefined to customize the typesetting
of different elements within generated transcripts.
To modify the typesetting of error messages, redefine <tt>\transerr</tt>
and <tt>\endtranserr</tt>.
To modify the typesetting of user input read from the current input port
of the caf&eacute;, redefine <tt>\transin</tt> and <tt>\endtransin</tt>.
To modify the typesetting of program output written to the current
output port of new caf&eacute;, redefine <tt>\transout</tt> and
<tt>\endtransout</tt>.
<p>
For example, the following:
<p>
<blockquote>
<pre>
\transcript
(define f
(lambda (x) ; indentation and comments are
(if (zero? x) ; preserved in the transcript
1
(* x (f (- x 1))))))
(values f (f 0) (f 5) (f 20))
(trace f)
(f 4)
\endtranscript
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
<p><tt>&gt;&nbsp;(define&nbsp;f<br>
&nbsp;&nbsp;&nbsp;&nbsp;(lambda&nbsp;(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;indentation&nbsp;and&nbsp;comments&nbsp;are<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(if&nbsp;(zero?&nbsp;x)&nbsp;&nbsp;&nbsp;;&nbsp;preserved&nbsp;in&nbsp;the&nbsp;transcript<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(*&nbsp;x&nbsp;(f&nbsp;(-&nbsp;x&nbsp;1))))))<br>
&gt;&nbsp;(values&nbsp;f&nbsp;(f&nbsp;0)&nbsp;(f&nbsp;5)&nbsp;(f&nbsp;20))<br>
#&lt;procedure&nbsp;f&gt;<br>
1<br>
120<br>
2432902008176640000<br>
&gt;&nbsp;(trace&nbsp;f)<br>
(f)<br>
&gt;&nbsp;(f&nbsp;4)<br>
<font color="#0000ff">|(f&nbsp;4)<br>
|&nbsp;(f&nbsp;3)<br>
|&nbsp;|(f&nbsp;2)<br>
|&nbsp;|&nbsp;(f&nbsp;1)<br>
|&nbsp;|&nbsp;|(f&nbsp;0)<br>
|&nbsp;|&nbsp;|1<br>
|&nbsp;|&nbsp;1<br>
|&nbsp;|2<br>
|&nbsp;6<br>
|24<br>
</font>24</tt>
<p></blockquote>
<p>
The following example shows how to specify a different transcript
terminator and shows the default formatting imposed by <tt>\transerr</tt>,
<tt>\transin</tt>, and <tt>\transout</tt>.
<p>
<blockquote>
<pre>
\transcript[\stopthistranscript]
#e4.5
(begin (display "Enter a character: ") (read-char))
(begin (display "Enter a character: ") (read-char))Z
(begin (clear-input-port) (display "Enter a character: ") (read-char))
Z
(list (read-char) (read-char) (read-char))abc def
(define silly-repl
(lambda (prompt)
(display prompt)
(let ([x (read)])
(unless (eof-object? x)
(let ([result (eval x)])
(unless (eq? result (void))
(pretty-print result))
(silly-repl prompt))))))
(silly-repl "Enter a Scheme expression: ")
(list 1
2
3)
(silly-repl "Now what? ")
(define interview
(lambda ()
(let* ([fname (begin (display "First name: ") (read))]
[lname (begin (display "Last name: ") (read))])
(printf "Hello ~a ~a!~%" fname lname))))
(interview)
john
doe
#!eof
(printf "good to be back~%")
#!eof
\stopthistranscript
</pre>
<p>
</blockquote>
<p>
produces:
<p>
<blockquote>
<p><tt>&gt;&nbsp;#e4.5<br>
9/2<br>
&gt;&nbsp;(begin&nbsp;(display&nbsp;"Enter&nbsp;a&nbsp;character:&nbsp;")&nbsp;(read-char))<font color="#ff0000"><br>
</font><font color="#0000ff">Enter&nbsp;a&nbsp;character:&nbsp;</font>#\newline<br>
&gt;&nbsp;(begin&nbsp;(display&nbsp;"Enter&nbsp;a&nbsp;character:&nbsp;")&nbsp;(read-char))<font color="#ff0000">Z</font><br>
<font color="#0000ff">Enter&nbsp;a&nbsp;character:&nbsp;</font>#\Z<br>
&gt;&nbsp;(begin&nbsp;(clear-input-port)&nbsp;(display&nbsp;"Enter&nbsp;a&nbsp;character:&nbsp;")&nbsp;(read-char))<br>
<font color="#0000ff">Enter&nbsp;a&nbsp;character:&nbsp;</font><font color="#ff0000">Z</font><br>
#\Z<br>
&gt;&nbsp;(list&nbsp;(read-char)&nbsp;(read-char)&nbsp;(read-char))<font color="#ff0000">abc</font>&nbsp;def<br>
(#\b&nbsp;#\c&nbsp;#\a)<br>
&gt;&nbsp;<br>
Exception:&nbsp;variable&nbsp;def&nbsp;is&nbsp;not&nbsp;bound<br>
Type&nbsp;(debug)&nbsp;to&nbsp;enter&nbsp;the&nbsp;debugger.<br>
&gt;&nbsp;(define&nbsp;silly-repl<br>
&nbsp;&nbsp;&nbsp;&nbsp;(lambda&nbsp;(prompt)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(display&nbsp;prompt)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let&nbsp;([x&nbsp;(read)])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(unless&nbsp;(eof-object?&nbsp;x)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(let&nbsp;([result&nbsp;(eval&nbsp;x)])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(unless&nbsp;(eq?&nbsp;result&nbsp;(void))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(pretty-print&nbsp;result))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(silly-repl&nbsp;prompt))))))<br>
&gt;&nbsp;(silly-repl&nbsp;"Enter&nbsp;a&nbsp;Scheme&nbsp;expression:&nbsp;")<font color="#ff0000"><br>
</font><font color="#0000ff">Enter&nbsp;a&nbsp;Scheme&nbsp;expression:&nbsp;</font><font color="#ff0000">(list&nbsp;1<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3)<br>
</font><font color="#0000ff">(1&nbsp;2&nbsp;3)<br>
Enter&nbsp;a&nbsp;Scheme&nbsp;expression:&nbsp;</font><font color="#ff0000">(silly-repl&nbsp;"Now&nbsp;what?&nbsp;")<br>
</font><font color="#0000ff">Now&nbsp;what?&nbsp;</font><font color="#ff0000">(define&nbsp;interview<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;(lambda&nbsp;()<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;&nbsp;&nbsp;(let*&nbsp;([fname&nbsp;(begin&nbsp;(display&nbsp;"First&nbsp;name:&nbsp;")&nbsp;(read))]<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[lname&nbsp;(begin&nbsp;(display&nbsp;"Last&nbsp;name:&nbsp;")&nbsp;(read))])<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(printf&nbsp;"Hello&nbsp;~a&nbsp;~a!~%"&nbsp;fname&nbsp;lname))))<br>
</font><font color="#0000ff">Now&nbsp;what?&nbsp;</font><font color="#ff0000">(interview)<br>
</font><font color="#0000ff">First&nbsp;name:&nbsp;</font><font color="#ff0000">john<br>
</font><font color="#0000ff">Last&nbsp;name:&nbsp;</font><font color="#ff0000">&nbsp;&nbsp;doe<br>
</font><font color="#0000ff">Hello&nbsp;john&nbsp;doe!<br>
Now&nbsp;what?&nbsp;</font><font color="#ff0000">#!eof<br>
</font><font color="#0000ff">Enter&nbsp;a&nbsp;Scheme&nbsp;expression:&nbsp;</font><font color="#ff0000">(printf&nbsp;"good&nbsp;to&nbsp;be&nbsp;back~%")<br>
</font><font color="#0000ff">good&nbsp;to&nbsp;be&nbsp;back<br>
Enter&nbsp;a&nbsp;Scheme&nbsp;expression:&nbsp;</font><font color="#ff0000">#!eof</font></tt>
<p></blockquote>
<p>
Transcripts do not include a trailing prompt by design.
This is done in such a way that an explicitly displayed string that
happens to look like the prompt is not suppressed.
For example:
<p>
<blockquote>
<pre>
\transcript
(begin (display "&gt; \n") (exit))
\endtranscript
</pre>
<p>
</blockquote>
<p>
should leave the apparent prompt alone since it is generated as program
output.
<p>
<blockquote>
<p><tt>&gt;&nbsp;(begin&nbsp;(display&nbsp;"&gt;&nbsp;\n")&nbsp;(exit))<br>
<font color="#0000ff">&gt;&nbsp;<br>
</font></tt>
<p></blockquote>
<p>
Prompt suppression works even with
changes to <tt>waiter-prompt-string</tt>.
For example:
<p>
<blockquote>
<pre>
\transcript
(waiter-prompt-string "antelope? ")
"no thanks"
\endtranscript
</pre>
<p>
</blockquote>
<p>
produces no trailing "antelope? " prompt:
<p>
<blockquote>
<p><tt>&gt;&nbsp;(waiter-prompt-string&nbsp;"antelope?&nbsp;")<br>
antelope?&nbsp;&nbsp;"no&nbsp;thanks"<br>
"no&nbsp;thanks"</tt>
<p></blockquote>
<p>
<a name="g12"></a>
<h4><a name="./stex:h12"></a>5.2. Loading initialization code</h4>
<p>
The <tt>stex</tt> commands <tt>\schemeinit</tt> and <tt>\endschemeinit</tt>
are used to bracket Scheme expressions that should be evaluated without
generating a transcript of the results.
This is useful, for example, when writing the description of a programming
assignment. The solutions can be loaded via <tt>\schemeinit</tt> and a
transcript showing how the solutions behave can be generated using the
<tt>\transcript</tt> command.
<p>
For example, the following text:
<p>
<blockquote>
<pre>
\schemeinit
(waiter-prompt-string "&gt;") ; restore the original prompt setting so we
; don't get "antelope?" as the prompt
(define compute-length
(lambda (x)
(cond
[(list? x) (length x)]
[(vector? x) (vector-length x)]
[(string? x) (string-length x)]
[else (errorf 'compute-length "cannot handle ~s" ls)])))
\endschemeinit
\emph{The \scheme{compute-length} procedure behaves as follows:}
\transcript
(compute-length '())
(compute-length '(a b c))
(compute-length "abcd")
(compute-length (vector 1 2 3 4 5 6))
(compute-length compute-length)
\endtranscript
</pre>
<p>
</blockquote>
<p>
produces the output shown below.
<p>
<blockquote>
<p>
<i>The <tt>compute-length</tt> procedure behaves as follows:</i>
<p><tt>&gt;&nbsp;(compute-length&nbsp;'())<br>
0<br>
&gt;&nbsp;(compute-length&nbsp;'(a&nbsp;b&nbsp;c))<br>
3<br>
&gt;&nbsp;(compute-length&nbsp;"abcd")<br>
4<br>
&gt;&nbsp;(compute-length&nbsp;(vector&nbsp;1&nbsp;2&nbsp;3&nbsp;4&nbsp;5&nbsp;6))<br>
6<br>
&gt;&nbsp;(compute-length&nbsp;compute-length)
<br>
<br>
Exception&nbsp;in&nbsp;compute-length:&nbsp;cannot&nbsp;handle&nbsp;#&lt;procedure&nbsp;compute-length&gt;<br>
Type&nbsp;(debug)&nbsp;to&nbsp;enter&nbsp;the&nbsp;debugger.</tt>
<p></blockquote>
<p>
the last line of input intentionally causes an error, which is
displayed just as it would be displayed in a caf&eacute;.
<p>
<a name="g13"></a>
<h3><a name="./stex:h13"></a>6. html-prep support for the <tt>tabular</tt> environment</h3>
<p>
Support for tables comes with a few caveats:
<p>
<ol>
<a name="g14"></a><li><tt>@&#123;&#125;</tt> directives within <tt>tabular</tt>
column specifiers are flat-out ignored for the time being.
<a name="g15"></a><li><tt>|</tt> directives within <tt>tabular</tt>
column specifiers are essentially ignored. Their only effect is
to globally enable borders for the entire HTML table.
<a name="g16"></a><li><tt>\hrule</tt> and <tt>\cline</tt> are not yet implemented.
<a name="g17"></a><li>no warranty is expressed or implied.
</ol>
<p>
<p>
The following code:
<p>
<blockquote>
<pre>
\begin{tabular}{rcl|r}
y &amp;=&amp; f(x) &amp; without loss of generality \\
z &amp; \multicolumn{2}{r}{whee} &amp; this is fun? \\
\multicolumn{4}{c}{
\begin{tabular}{cc}
1 &amp; 2 \\
3 &amp; 4
\end{tabular}
} \\
a &amp; b &amp; c &amp; d \\
12345 &amp; z &amp; \multicolumn{2}{l}{\scheme{(define~x~"foo")}}
\end{tabular}
</pre>
</blockquote>
<p>
generates this table:
<p>
<blockquote>
<TABLE border="1"><TR><TD nowrap align="right">
y </TD><TD nowrap align="center">=</TD><TD nowrap align="left"> f(x) </TD><TD nowrap align="right"> without loss of generality </TD></TR><TR><TD nowrap align="right">
z </TD><TD nowrap colspan="2" align="right"> whee </TD><TD nowrap align="left"> this is fun? </TD></TR><TR><TD nowrap colspan="4" align="center">
<TABLE><TR><TD nowrap align="center">
1 </TD><TD nowrap align="center"> 2 </TD></TR><TR><TD nowrap align="center">
3 </TD><TD nowrap align="center"> 4
</TD></TR></TABLE>
</TD></TR><TR><TD nowrap align="right">
a </TD><TD nowrap align="center"> b </TD><TD nowrap align="left"> c </TD><TD nowrap align="right"> d </TD></TR><TR><TD nowrap align="right">
12345 </TD><TD nowrap align="center"> z </TD><TD nowrap colspan="2" align="left"> <tt>(define&nbsp;x&nbsp;"foo")</tt>
</TD></TR></TABLE>
</blockquote>
<p>
&copy;&nbsp;1998-2016 R. Kent Dybvig and Oscar Waddell</body>
</html>