967 lines
		
	
	
	
		
			24 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			967 lines
		
	
	
	
		
			24 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!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. </b><td><b><a class=plain href="./stex.html#g0">Overview</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td align="right"><b>2. </b><td><b><a class=plain href="./stex.html#g1">Installation</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td align="right"><b>3. </b><td><b><a class=plain href="./stex.html#g2">Usage notes</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td align="right"><b>4. </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. </b></td><td><b><a class=plain href="./stex.html#g4">Inline code</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>4.2. </b></td><td><b><a class=plain href="./stex.html#g5">Code displays</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>4.3. </b></td><td><b><a class=plain href="./stex.html#g6">Variables</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>4.4. </b></td><td><b><a class=plain href="./stex.html#g7">Raw text in code</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>4.5. </b></td><td><b><a class=plain href="./stex.html#g8">Generated output</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>4.6. </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. </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. </b></td><td><b><a class=plain href="./stex.html#g11">Automatic transcript generation</a></b></td></tr>
 | |
| 
 | |
| 
 | |
| 
 | |
| <tr><td><b>5.2. </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. </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 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 make install BIN=<i>bindir</i> 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 = 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 3 4)</tt> produces <tt>(3 . 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 fact<br>
 | |
| 
 | |
|   (lambda (x)<br>
 | |
| 
 | |
|     "a light year is a measure of distance"))
 | |
| <br>
 | |
| <br>
 | |
| (define fib<br>
 | |
| 
 | |
|   (lambda (x)<br>
 | |
| 
 | |
|     "a light year is a measure of time"))</tt>
 | |
| <p></blockquote>
 | |
| 
 | |
| <p>
 | |
| Within a Scheme display, <tt>;=></tt> is converted into a double right arrow
 | |
| (<img src="math/stex/0.gif" alt="<graphic>">), <tt>;-></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]) ;-> ((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]) ;=> 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 ([a 17]) <img src="math/stex/1.gif" alt="<graphic>"> ((lambda (a) (+ a a))<br>
 | |
| 
 | |
|   (+ a a))    <img src="gifs/ghostRightarrow.gif">  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 ([a 17]) <img src="math/stex/0.gif" alt="<graphic>"> 17<br>
 | |
| 
 | |
|   (+ a 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 ([<i>x</i> <i>e</i>]) <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{abc_3}</tt>
 | |
| produces <tt><i>abc<sub>3</sub></i></tt>, and <tt>\var{7e5_16}</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 <i>x</i>) <img src="math/stex/0.gif" alt="<graphic>"> <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é (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é, redefine <tt>\transin</tt> and <tt>\endtransin</tt>.
 | |
| To modify the typesetting of program output written to the current
 | |
| output port of new café, 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>> (define f<br>
 | |
| 
 | |
|     (lambda (x)       ; indentation and comments are<br>
 | |
| 
 | |
|       (if (zero? x)   ; preserved in the transcript<br>
 | |
| 
 | |
|           1<br>
 | |
| 
 | |
|           (* x (f (- x 1))))))<br>
 | |
| 
 | |
| > (values f (f 0) (f 5) (f 20))<br>
 | |
| 
 | |
| #<procedure f><br>
 | |
| 
 | |
| 1<br>
 | |
| 
 | |
| 120<br>
 | |
| 
 | |
| 2432902008176640000<br>
 | |
| 
 | |
| > (trace f)<br>
 | |
| 
 | |
| (f)<br>
 | |
| 
 | |
| > (f 4)<br>
 | |
| 
 | |
| <font color="#0000ff">|(f 4)<br>
 | |
| 
 | |
| | (f 3)<br>
 | |
| 
 | |
| | |(f 2)<br>
 | |
| 
 | |
| | | (f 1)<br>
 | |
| 
 | |
| | | |(f 0)<br>
 | |
| 
 | |
| | | |1<br>
 | |
| 
 | |
| | | 1<br>
 | |
| 
 | |
| | |2<br>
 | |
| 
 | |
| | 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>> #e4.5<br>
 | |
| 
 | |
| 9/2<br>
 | |
| 
 | |
| > (begin (display "Enter a character: ") (read-char))<font color="#ff0000"><br>
 | |
| 
 | |
| </font><font color="#0000ff">Enter a character: </font>#\newline<br>
 | |
| 
 | |
| > (begin (display "Enter a character: ") (read-char))<font color="#ff0000">Z</font><br>
 | |
| 
 | |
| <font color="#0000ff">Enter a character: </font>#\Z<br>
 | |
| 
 | |
| > (begin (clear-input-port) (display "Enter a character: ") (read-char))<br>
 | |
| 
 | |
| <font color="#0000ff">Enter a character: </font><font color="#ff0000">Z</font><br>
 | |
| 
 | |
| #\Z<br>
 | |
| 
 | |
| > (list (read-char) (read-char) (read-char))<font color="#ff0000">abc</font> def<br>
 | |
| 
 | |
| (#\b #\c #\a)<br>
 | |
| 
 | |
| > <br>
 | |
| 
 | |
| Exception: variable def is not bound<br>
 | |
| 
 | |
| Type (debug) to enter the debugger.<br>
 | |
| 
 | |
| > (define silly-repl<br>
 | |
| 
 | |
|     (lambda (prompt)<br>
 | |
| 
 | |
|       (display prompt)<br>
 | |
| 
 | |
|       (let ([x (read)])<br>
 | |
| 
 | |
|         (unless (eof-object? x)<br>
 | |
| 
 | |
|           (let ([result (eval x)])<br>
 | |
| 
 | |
|             (unless (eq? result (void))<br>
 | |
| 
 | |
|               (pretty-print result))<br>
 | |
| 
 | |
|             (silly-repl prompt))))))<br>
 | |
| 
 | |
| > (silly-repl "Enter a Scheme expression: ")<font color="#ff0000"><br>
 | |
| 
 | |
| </font><font color="#0000ff">Enter a Scheme expression: </font><font color="#ff0000">(list 1<br>
 | |
| 
 | |
| </font>                           <font color="#ff0000">      2<br>
 | |
| 
 | |
| </font>                           <font color="#ff0000">      3)<br>
 | |
| 
 | |
| </font><font color="#0000ff">(1 2 3)<br>
 | |
| 
 | |
| Enter a Scheme expression: </font><font color="#ff0000">(silly-repl "Now what? ")<br>
 | |
| 
 | |
| </font><font color="#0000ff">Now what? </font><font color="#ff0000">(define interview<br>
 | |
| 
 | |
| </font>          <font color="#ff0000">  (lambda ()<br>
 | |
| 
 | |
| </font>          <font color="#ff0000">    (let* ([fname (begin (display "First name: ") (read))]<br>
 | |
| 
 | |
| </font>          <font color="#ff0000">           [lname (begin (display "Last name: ") (read))])<br>
 | |
| 
 | |
| </font>          <font color="#ff0000">      (printf "Hello ~a ~a!~%" fname lname))))<br>
 | |
| 
 | |
| </font><font color="#0000ff">Now what? </font><font color="#ff0000">(interview)<br>
 | |
| 
 | |
| </font><font color="#0000ff">First name: </font><font color="#ff0000">john<br>
 | |
| 
 | |
| </font><font color="#0000ff">Last name: </font><font color="#ff0000">  doe<br>
 | |
| 
 | |
| </font><font color="#0000ff">Hello john doe!<br>
 | |
| 
 | |
| Now what? </font><font color="#ff0000">#!eof<br>
 | |
| 
 | |
| </font><font color="#0000ff">Enter a Scheme expression: </font><font color="#ff0000">(printf "good to be back~%")<br>
 | |
| 
 | |
| </font><font color="#0000ff">good to be back<br>
 | |
| 
 | |
| Enter a Scheme expression: </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 "> \n") (exit))
 | |
| \endtranscript
 | |
| </pre>
 | |
| 
 | |
| 
 | |
| <p>
 | |
| </blockquote>
 | |
| 
 | |
| <p>
 | |
| should leave the apparent prompt alone since it is generated as program
 | |
| output.
 | |
| 
 | |
| <p>
 | |
| <blockquote>
 | |
| 
 | |
| <p><tt>> (begin (display "> \n") (exit))<br>
 | |
| 
 | |
| <font color="#0000ff">> <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>> (waiter-prompt-string "antelope? ")<br>
 | |
| 
 | |
| antelope?  "no thanks"<br>
 | |
| 
 | |
| "no 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 ">")    ; 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>> (compute-length '())<br>
 | |
| 
 | |
| 0<br>
 | |
| 
 | |
| > (compute-length '(a b c))<br>
 | |
| 
 | |
| 3<br>
 | |
| 
 | |
| > (compute-length "abcd")<br>
 | |
| 
 | |
| 4<br>
 | |
| 
 | |
| > (compute-length (vector 1 2 3 4 5 6))<br>
 | |
| 
 | |
| 6<br>
 | |
| 
 | |
| > (compute-length compute-length)
 | |
| <br>
 | |
| <br>
 | |
| Exception in compute-length: cannot handle #<procedure compute-length><br>
 | |
| 
 | |
| Type (debug) to enter the 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é.
 | |
| 
 | |
| <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>@{}</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 &=& f(x) & without loss of generality \\
 | |
| z & \multicolumn{2}{r}{whee} & this is fun? \\
 | |
| \multicolumn{4}{c}{
 | |
|  \begin{tabular}{cc}
 | |
|    1 & 2 \\
 | |
|    3 & 4
 | |
|  \end{tabular}
 | |
| } \\
 | |
| a & b & c & d \\
 | |
| 12345 & z & \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 x "foo")</tt>
 | |
| </TD></TR></TABLE>
 | |
| </blockquote>
 | |
| 
 | |
| <p>
 | |
| 
 | |
|  
 | |
|  © 1998-2016 R. Kent Dybvig and Oscar Waddell</body>
 | |
| </html>
 | 
