Debian Codegraph @

texmf-dist/tex/plain/cweb/cwebbin/twimac-web.tex

raw
1 % standard macros for WEB listings (in addition to plain.tex)
2 % note that these macros are quite different from DEK's 'twimac.tex'
3 % available on CTAN (https://mirrors.ctan.org/systems/knuth/local/lib)
4
5 \xdef\fmtversion{\fmtversion+TWIMAC+WEB}
6
7 \newif\ifsorted
8 \newread\sreffile \openin\sreffile=\jobname.sref
9 \newwrite\reffile
10 \ifeof\sreffile \immediate\openout\reffile=\jobname.ref
11 \sortedfalse \message{This is the first pass!}
12 \else \sortedtrue \message{This is the second pass!} \fi
13
14 \newdimen\em \em=10pt
15 \parskip 0pt % no stretch between paragraphs
16 \parindent 1\em % for paragraphs and for the first line of Pascal text
17
18 \font\manual=manfnt
19 \font\ninerm=cmr9
20 \font\eightrm=cmr8
21 \font\sixrm=cmr6
22 \font\ninei=cmmi9
23 \font\eighti=cmmi8
24 \font\sixi=cmmi6
25 \skewchar\ninei='177 \skewchar\eighti='177 \skewchar\sixi='177
26 \font\ninesy=cmsy9
27 \font\eightsy=cmsy8
28 \font\sixsy=cmsy6
29 \skewchar\ninesy='60 \skewchar\eightsy='60 \skewchar\sixsy='60
30 \font\ninebf=cmbx9
31 \font\eightbf=cmbx8
32 \font\sixbf=cmbx6
33 \font\ninett=cmtt9
34 \font\eighttt=cmtt8
35 \hyphenchar\ninett=-1 \hyphenchar\eighttt=-1
36 \font\ninesl=cmsl9
37 \font\eightsl=cmsl8
38 \font\nineit=cmti9
39 \font\eightit=cmti8
40
41 \newif\iftenpoint
42 \def\tenpoint{\tenpointtrue
43 \def\rm{\fam0\tenrm}%
44 \textfont0=\tenrm \scriptfont0=\sevenrm \scriptscriptfont0=\fiverm
45 \textfont1=\teni \scriptfont1=\seveni \scriptscriptfont1=\fivei
46 \textfont2=\tensy \scriptfont2=\sevensy \scriptscriptfont2=\fivesy
47 \textfont3=\tenex \scriptfont3=\tenex \scriptscriptfont3=\tenex
48 \def\it{\fam\itfam\tenit}%
49 \textfont\itfam=\tenit
50 \def\sl{\fam\slfam\tensl}%
51 \textfont\slfam=\tensl
52 \def\bf{\fam\bffam\tenbf}%
53 \textfont\bffam=\tenbf \scriptfont\bffam=\sevenbf
54 \scriptscriptfont\bffam=\fivebf
55 \def\tt{\fam\ttfam\tentt}%
56 \textfont\ttfam=\tentt
57 \def\ttx{\tentex}%
58 \normalbaselineskip=12pt
59 \def\MF{{\manual META}\-{\manual FONT}}%
60 \let\sc=\eightrm
61 \let\big=\tenbig
62 \setbox\strutbox=\hbox{\vrule height8pt depth3pt width 0pt}%
63 \normalbaselines\rm}
64
65 \def\ninepoint{\tenpointfalse
66 \def\rm{\fam0\ninerm}%
67 \textfont0=\ninerm \scriptfont0=\sixrm \scriptscriptfont0=\fiverm
68 \textfont1=\ninei \scriptfont1=\sixi \scriptscriptfont1=\fivei
69 \textfont2=\ninesy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
70 \textfont3=\tenex \scriptfont3=\tenex \scriptscriptfont3=\tenex
71 \def\it{\fam\itfam\nineit}%
72 \textfont\itfam=\nineit
73 \def\sl{\fam\slfam\ninesl}%
74 \textfont\slfam=\ninesl
75 \def\bf{\fam\bffam\ninebf}%
76 \textfont\bffam=\ninebf \scriptfont\bffam=\sixbf
77 \scriptscriptfont\bffam=\fivebf
78 \def\tt{\fam\ttfam\ninett}%
79 \textfont\ttfam=\ninett
80 \def\ttx{\ninetex}%
81 \normalbaselineskip=11pt
82 \def\MF{{\manual hijk}\-{\manual lmnj}}%
83 \let\sc=\sevenrm
84 \let\big=\ninebig
85 \setbox\strutbox=\hbox{\vrule height8pt depth3pt width 0pt}%
86 \normalbaselines\rm}
87
88 \def\eightpoint{%
89 \def\rm{\fam0\eightrm}%
90 \textfont0=\eightrm \scriptfont0=\sixrm \scriptscriptfont0=\fiverm
91 \textfont1=\eighti \scriptfont1=\sixi \scriptscriptfont1=\fivei
92 \textfont2=\eightsy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
93 \textfont3=\tenex \scriptfont3=\tenex \scriptscriptfont3=\tenex
94 \def\it{\fam\itfam\eightit}%
95 \textfont\itfam=\eightit
96 \def\sl{\fam\slfam\eightsl}%
97 \textfont\slfam=\eightsl
98 \def\bf{\fam\bffam\eightbf}%
99 \textfont\bffam=\eightbf \scriptfont\bffam=\sixbf
100 \scriptscriptfont\bffam=\fivebf
101 \def\tt{\fam\ttfam\eighttt}%
102 \textfont\ttfam=\eighttt
103 \def\ttx{\eighttex}%
104 \normalbaselineskip=9pt
105 \def\MF{{\manual opqr}\-{\manual stuq}}%
106 \let\sc=\sixrm
107 \let\big=\eightbig
108 \setbox\strutbox=\hbox{\vrule height7pt depth2pt width 0pt}%
109 \normalbaselines\rm}
110
111 \def\tenbig#1{{\hbox{$\left#1\vbox to8.5pt{}\right.\nulldelimiterspace=0pt$}}}
112 \def\ninebig#1{{\hbox{$\textfont0=\tenrm\textfont2=\tensy
113 \left#1\vbox to7.25pt{}\right.\nulldelimiterspace=0pt$}}}
114 \def\eightbig#1{{\hbox{$\textfont0=\ninerm\textfont2=\ninesy
115 \left#1\vbox to6.5pt{}\right.\nulldelimiterspace=0pt$}}}
116
117 \font\tentex=cmtex10
118 \font\ninetex=cmtex9 % TeX extended character set (used in strings)
119 \font\eighttex=cmtex8
120
121 \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
122 \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
123 \def\&#1{\hbox{\bf#1\/}} % boldface type for reserved words
124 \def\.#1{\hbox{\ttx % typewriter type for strings
125 \let\\=\BS % backslash in a string
126 \let\'=\RQ % right quote in a string
127 \let\`=\LQ % left quote in a string
128 \let\{=\LB % left brace in a string
129 \let\}=\RB % right brace in a string
130 \let\~=\TL % tilde in a string
131 \let\ =\SP % space in a string
132 \let\_=\UL % underline in a string
133 \let\&=\AM % ampersand in a string
134 #1}}
135 \def\#{\hbox{\tt\char`\#}} % parameter sign
136 \def\${\hbox{\tt\char`\$}} % dollar sign
137 \def\%{\hbox{\tt\char`\%}} % percent sign
138 \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
139 % circumflex accents can be obtained from \^^D instead of \^
140 \def\AT!{@} % at sign for control text
141 \def\pct!{{\char`\%}} % percent sign in ordinary text
142
143 \chardef\AM=`\& % ampersand character in a string
144 \chardef\BS=`\\ % backslash in a string
145 \chardef\LB=`\{ % left brace in a string
146 \def\LQ{{\tt\char'22}} % left quote in a string
147 \chardef\RB=`\} % right brace in a string
148 \def\RQ{{\tt\char'23}} % right quote in a string
149 \def\SP{{\tt\char`\ }} % (visible) space in a string
150 \chardef\TL=`\~ % tilde in a string
151 \chardef\UL=`\_ % underline character in a string
152
153 \newbox\bak \setbox\bak=\hbox to -\em{} % backspace one em
154 \newbox\bakk\setbox\bakk=\hbox to -2\em{} % backspace two ems
155
156 \newcount\ind % current indentation in ems
157 \def\1{\global\advance\ind by1\hangindent\ind\em} % indent one more notch
158 \def\2{\global\advance\ind by-1} % indent one less notch
159 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
160 \def\4{\copy\bak} % backspace one notch
161 \def\5{\hfil\penalty-1\hfilneg\kern2.5\em\copy\bakk\ignorespaces}%optional break
162 \def\6{\ifmmode\else\par % forced break
163 \hangindent\ind\em\noindent\kern\ind\em\copy\bakk\ignorespaces\fi}
164 \def\7{\Y\6} % forced break and a little extra space
165
166 \let\yskip=\smallskip
167 \def\to{\mathrel{.\,.}} % double dot, used only in math mode
168 \def\ellipsis{\kern5\em\smash{\vdots}\qquad\vbox to12pt{}\par}
169 \def\note#1#2.{\par\penalty5000
170 \Y\noindent{\hangindent2\em\baselineskip10pt\eightrm#1 #2.\par}}
171 \def\startsection{\Q\noindent\strut{\bf\modno.\quad}}
172 \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
173 \def\A{\note{See also}} % cross-reference for multiply defined section names
174 \def\B{\mathopen{\.{@\{}}} % begin controlled comment
175 \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% Pascal comments
176 \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
177 \def\D{\defin{define}} % macro definition
178 \def\E{\cdot10^} % exponent in floating point constant
179 \def\F{\defin{format}} % format definition
180 \let\G=\ge % greater than or equal sign
181 \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
182 \let\I=\ne % unequal sign
183 \def\J{\.{@\&}} % TANGLE's join operation
184 \let\K=\gets % left arrow
185 \let\L=\le % less than or equal sign
186 \outer\def\M#1.{\def\modno{#1}\startsection\ignorespaces}
187 \outer\def\N#1. #2.{\def\modno{#1}\flushout % begin starred section
188 \gdef\rhead{\uppercase{#2}} % define running headline
189 \global\let\rrhead=\rhead
190 \message{*\modno} % progress report
191 \startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
192 \outer\def\NN#1. \[#2]#3.{\def\modno{#1} % begin starred section on rh page
193 \global\setbox\partialpage=\vbox{
194 \vbox to 44pc{\box\partialpage\vfill}\break}
195 \gdef\rrhead{PART #2:\uppercase{#3}} % define running headline
196 \message{!\modno} % progress report
197 \startsection{\bf\ignorespaces#3.\quad}\ignorespaces}
198 \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
199 \def\P{\iftenpoint \ninepoint\fi
200 \rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
201 \sfcode`;=3000
202 \pretolerance 10000
203 \hyphenpenalty 10000 \exhyphenpenalty 10000
204 \global\ind=2 \1\ \unskip}
205 \def\Q{\tenpoint
206 \rightskip=0pt % get out of Pascal mode
207 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
208 \let\R=\lnot % logical not
209 \let\S=\equiv % equivalence sign
210 \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
211 \def\U{\note{This code is used in}} % cross-reference for uses of sections
212 \let\V=\lor % logical or
213 \let\W=\land % logical and
214 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
215 \XX$\langle\,$#2{\sevenrm\kern.5em#1}$\,\rangle$\XX}
216 \def\Y{\par\yskip}
217 \let\Z=\let % now you can \send the control sequence \Z
218 \def\){\hbox{\.{@\$}}} %$% sign for string pool check sum
219 \def\]{\hbox{\.{@\\}}} % sign for forced line break
220 \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
221 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
222 \hrule}\vrule}\kern2pt} % verbatim string
223 \let\~=\ignorespaces
224
225 \newcount\nrefs % total number of references in partial page
226 \newcount\baseno % smallest module number in partial page
227 \countdef\nprefs=199 % the number in \prefs
228 \countdef\nfrefs=220 % the number in \frefs
229 \toksdef\prefs=199 \toksdef\frefs=220
230 % \count and \toks registers 200--219 are also used to keep track of refs
231 \newcount\nn \newcount\mm \newcount\pp
232 \newdimen\nsize \newdimen\msize
233 \newskip\intermodskip \intermodskip=8pt plus 2pt minus 3pt
234 \newbox\partialpage
235 \newbox\newmod
236 \newtoks\newrefs
237 \newdimen\ninept \ninept=9pt
238
239 \def\uline{_}
240 \begingroup\catcode`\_=\active \globaldefs=1
241 \def\flushout{\ifvoid\partialpage\else
242 \setbox0=\vsplit\partialpage to 44pc
243 \setbox2=\vbox{
244 \vbox to 3pc{
245 \hbox to 35pc{\vbox to10pt{}\nineit\rhead\hfil\eightrm\folio}\vfill}
246 \nointerlineskip\box0}%
247 \shipout\box2
248 \global\advance\pageno 1
249 \let\[=\makeref
250 \ifsorted \let\readin=\readln \readrefs
251 \else \immediate\write\reffile{!\the\pageno}\let\readin=\readrefs \fi
252 \setbox0=\vbox{\eightpoint \hsize=11pc \catcode`\_=\active \let_=\_
253 \rightskip=0pt plus 100pt minus 10pt
254 \pretolerance 10000
255 \hyphenpenalty 10000 \exhyphenpenalty 10000
256 \noindent\vbox to1pt{}\par % 1pt = \topskip - \ninept
257 \readin}
258 \setbox2=\vbox to47pc{
259 \vbox to 3pc{
260 \hbox to 35pc{\vbox to10pt{}\eightrm\folio\hfil\nineit\rrhead\/}\vfill}
261 \unvbox\partialpage
262 \vfill
263 \ifdim\ht0>1pt \kern11pt\hrule \hbox{% changed 8pt to 11pt Oct 87 by DEK!
264 \nsize=\ht0 \advance\nsize-\topskip
265 \divide\nsize by 3 \divide\nsize by\ninept
266 \multiply\nsize by\ninept \advance\nsize\topskip
267 \vsplit0 to\nsize \kern1pc
268 \msize=\ht0 \advance\msize-\topskip
269 \divide\msize by 2 \divide\msize by\ninept
270 \multiply\msize by\ninept \advance\msize\topskip
271 \vbox to\nsize{\vsplit0 to\msize\vss}\kern1pc
272 \vbox to\nsize{\box0\vss}} \fi}%
273 \shipout\box2
274 \global\advance\pageno 1 \global\let\rhead=\rrhead\fi
275 {\globaldefs=1
276 \nn=199 \loop \ifnum\nn<221 \toks\nn={} \count\nn=0 \advance\nn 1 \repeat
277 \nrefs=0
278 \baseno=\modno}}
279
280 \def\mini{\begingroup \catcode`\_=\active \let_=\uline \globaldefs=1
281 \newrefs=\bgroup}
282 \def\FI{\nn=\modno \advance\nn-\baseno \advance\nn 200
283 \advance\nrefs-\count\nn \nn=\nrefs
284 \let\[=\countnewref \the\newrefs \endgroup
285 \nobreak\null\nobreak\vskip-\baselineskip\penalty-500\vfil\eject}
286 \def\twillout{\setbox\newmod=\vbox{\unvbox255}
287 \ifnum\nn=0 \nsize=0pt
288 % \else \nsize=3pt \multiply\nsize\nn \advance\nsize 1pc \fi
289 \else \nsize=3pt \multiply\nsize\nn \advance\nsize 1.25pc \fi % changed Oct 87!
290 \ifvoid\partialpage\else\advance\nsize 5pt \advance\nsize\ht\partialpage\fi
291 \advance\nsize\ht\newmod
292 \message{\the\nsize} % show the page break decision amount
293 \ifdim\nsize>88pc \flushout \message{\modno}\fi
294 \addtopartialpage}
295 \def\addtopartialpage{\let\[=\addnewref \catcode`\_=\active \let_=\uline
296 \globaldefs=1 \the\newrefs
297 \nsize=\dp\partialpage
298 \setbox\partialpage=\ifvoid\partialpage \box\newmod
299 \else \vbox{\unvbox\partialpage \vfilneg
300 \vskip\intermodskip \unvbox\newmod}\fi}
301 \endgroup
302 \def\shortpage{\par\vskip-2\baselineskip
303 \null\vfill\penalty-5000\message{(shortpage)}}
304
305 \def\countnewref #1 #2 {\ifnum#2<\baseno \let\next\cn
306 \else\ifnum#2>\modno \let\next\cn \else\let\next\flushref\fi\fi\next#1 #2 }
307 \def\cn #1 #2 {\expandafter\cnr\csname#1 #2\endcsname #2 }
308 \def\cnr#1#2 #3 {\ifx#1\relax \advance\nn 1 \fi}
309 \def\flushref#1 #2 #3 {}
310 \def\addnewref #1 #2 {\ifnum#2<\baseno \let\next\an \nn=199
311 \else\ifnum#2>\modno \let\next\an \nn=#2 \advance\nn-\baseno
312 \advance\nn200 \ifnum\nn>219 \nn=220 \fi
313 \else\let\next\flushref\fi\fi\next#1 #2 }
314 \def\an #1 #2 {\expandafter\anr\csname#1 #2\endcsname #1 #2 }
315 \def\anr#1#2 #3 #4 {\ifx#1\relax
316 \advance\nrefs1 \advance\count\nn 1
317 \def#1{\[#2 #3 #4 }\toks\nn=\expandafter{\the\toks\nn\lmda#1}\fi}
318 \ifsorted \def\lmda#1{\global\let#1\relax}
319 \else \def\lmda#1{#1\global\let#1\relax} \fi
320 \def\makeref #1 #2 #3#4 {\nn=#2 \hangindent=1em
321 \ifsorted\else\toks0={#1 #2 #3#4}\immediate\write\reffile{+ \the\toks0}\fi
322 \noindent\\{#1}\ifx#3\none\else
323 \if#3:: \else\unhcopy\eqbox \fi#4\fi, \section\number\nn.\par}
324 \newbox\eqbox \setbox\eqbox=\hbox{\kern2pt\eightrm=\kern2pt}
325 \def\section{\mathhexbox278}
326 \def\none{\none}
327 \def\readrefs{\the\prefs \mm=\modno \advance\mm-\baseno \advance\mm200
328 {\def\lmda##1{\global\let##1\relax}\pp=200 % this patch made AFTER first
329 \loop\ifnum\pp<\mm \the\toks\pp \advance\pp 1 \repeat} % edition of Vol B!!
330 \loop\ifnum\mm<222 \the\toks\mm \advance\mm 1 \repeat}
331 \def\readln{\read\sreffile to\next \expandafter\next\space \readin}
332 \def\donewithpage#1 {%\ifnum\pageno=#1 \else\message{page #1??}\fi
333 \let\readin=\relax}
334 \def\rhead{BLANK PAGE TO THROW AWAY}
335
336 \hsize=35pc \vsize=\maxdimen \output={\twillout}
337
338 % the remaining stuff applies only to the rear matter
339
340 \newif\ifpagesaved
341 \def\lheader{\vbox to10pt{}\nineit\rhead\hfil\eightrm\folio}
342 \def\rheader{\vbox to10pt{}\eightrm\folio\hfil\nineit\rhead\/}
343 \def\page{\box255 }
344 \def\normaloutput#1{\setbox2=\vbox{
345 \vbox to 3pc{
346 \hbox to 35pc{\ifodd\pageno\rheader\else\lheader\fi}\vfill}
347 \nointerlineskip#1}%
348 \shipout\box2
349 \global\advance\pageno 1 }
350
351 \def\ch{\note{The following sections were changed by the change file:}
352 \let\*=\relax}
353 \newbox\sbox % saved box preceding the index
354 \newbox\lbox % lefthand column in the index
355 \def\inx{\box\partialpage
356 \vskip24pt plus 1fil % we are beginning the index
357 \output{\ifpagesaved\normaloutput{\box\sbox}\fi
358 \global\setbox\sbox=\page \global\pagesavedtrue}
359 \pagesavedfalse \eject % eject the page-so-far and predecessors
360 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
361 \vsize=44pc \advance\vsize by -\ht\sbox % the remaining height
362 \hsize=17pc % column width for the index (1pc between cols)
363 \eightpoint
364 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
365 \def\lr{L} % this tells whether the left or right column is next
366 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
367 \else\normaloutput{\vbox to44pc{\box\sbox\vss
368 \hbox to35pc{\box\lbox\hfil\page}}}
369 \global\vsize=44pc\gdef\lr{L}\global\pagesavedfalse\fi}
370 \message{Index:}
371 \parskip 0pt plus .5pt
372 \gdef\rhead{INDEX}
373 \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
374 \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
375 \def\[##1]{$\underline{##1}$} % underlined index item
376 \rm \rightskip0pt plus 2.5em \tolerance 10000
377 \hyphenpenalty 10000 \parindent0pt}
378 \def\fin{\par\vfill\eject % this is done when we are ending the index
379 \ifpagesaved\null\vfill\eject\fi % output a null index column
380 \if L\lr\else\null\vfill\eject\fi % finish the current page
381 \parfillskip 0pt plus 1fil
382 \gdef\rhead{NAMES OF THE SECTIONS}
383 \message{Section names:}
384 \output{\normaloutput\page}
385 \ninepoint
386 \hsize=35pc \vsize=44pc
387 \def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\eightrm##1 ##2.}}
388 \linepenalty=10 % try to conserve lines
389 \def\U{\note{Used in}} % cross-reference for uses of sections
390 \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry}
391 \def\con{\par\vfill\eject\end} % finish the section names
392
393 % To produce only a subset of pages, put the page numbers on separate
394 % lines in a file called pages.tex
395 \let\Shipout=\shipout
396 \newread\pages \newcount\nextpage \openin\pages=pages
397 \def\getnextpage{\ifeof\pages\else
398 {\endlinechar=-1\read\pages to\next
399 \ifx\next\empty % in this case we should have eof now
400 \else\global\nextpage=\next\fi}\fi}
401 \ifeof\pages\else\message{OK, I'll ship only the requested pages!}
402 \getnextpage\fi
403 \def\shipout{\ifeof\pages\let\next=\Shipout
404 \else\ifnum\pageno=\nextpage\getnextpage\let\next=\Shipout
405 \else\let\next=\Tosspage\fi\fi \next}
406 \newbox\garbage \def\Tosspage{\deadcycles=0\setbox\garbage=}