beta-0.89.2
[luatex.git] / source / texk / web2c / cwebdir / cwebmac.tex
blobd50987da9be54a9ae45dab526978bfd34ee2ccf2
1 % standard macros for CWEB listings (in addition to plain.tex)
2 % Version 3.68 --- January 2016
3 \ifx\renewenvironment\undefined\else\endinput\fi % LaTeX will use other macros
4 \xdef\fmtversion{\fmtversion+CWEB3.68}
5 \chardef\cwebversion=3 \chardef\cwebrevision=68
6 \newif\ifpdf
7 \ifx\pdf+\pdftrue\fi
8 % Uncomment the following line if you want PDF goodies to be the default
9 %\ifx\pdf-\else\pdftrue\fi
10 \def\pdflinkcolor{0 0 1} % the RGB values for hyperlink color
11 \newif\ifpdftex
12 \ifx\pdfoutput\undefined \pdftexfalse \else\ifnum\pdfoutput=0 \pdftexfalse
13 \else \pdftextrue \pdfoutput=1 \input pdfcolor \let\setcolor\pdfsetcolor \fi\fi
14 \newif\ifacro \ifpdf\acrotrue\fi \ifpdftex\acrotrue\fi
16 \let\:=\. % preserve a way to get the dot accent
17 % (all other accents will still work as usual)
19 \parskip 0pt % no stretch between paragraphs
20 \parindent 1em % for paragraphs and for the first line of C text
22 \font\ninerm=cmr9
23 \let\mc=\ninerm % medium caps
24 \def\CEE/{{\mc C\spacefactor1000}}
25 \def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
26 \def\TEX/{\TeX}
27 \def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
28 \def\Cee{\CEE/} % for backward compatibility
29 \def\9#1{}
30 % with this definition of \9 you can say @:sort key}{TeX code@>
31 % to alphabetize an index entry by the sort key but format with the TeX code
32 \font\eightrm=cmr8
33 \let\sc=\eightrm % for smallish caps (NOT a caps-and-small-caps font)
34 \let\mainfont=\tenrm
35 \let\cmntfont\tenrm
36 %\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
37 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
38 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
39 \font\tentex=cmtex10 % TeX extended character set (used in strings)
40 \fontdimen7\tentex=0pt % no double space after sentences
42 \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
43 \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
44 \def\&#1{\leavevmode\hbox{\bf
45 \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
46 #1\/\kern.05em}} % boldface type for reserved words
47 \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
48 \let\\=\BS % backslash in a string
49 \let\{=\LB % left brace in a string
50 \let\}=\RB % right brace in a string
51 \let\~=\TL % tilde in a string
52 \let\ =\SP % space in a string
53 \let\_=\UL % underline in a string
54 \let\&=\AM % ampersand in a string
55 \let\^=\CF % circumflex in a string
56 #1\kern.05em}}
57 \def\){{\tentex\kern-.05em}\discretionary{\hbox{\tentex\BS}}{}{}}
58 \def\AT{@} % at sign for control text (not needed in versions >= 2.9)
59 \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
60 \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
61 tangles as \tentex "#2"\egroup\par}
62 \def\noATL#1 #2 {}
63 \def\noatl{\let\ATL=\noATL} % suppress output from @l
64 \def\ATH{{\acrofalse\X\kern-.5em:Preprocessor definitions\X}}
65 \let\PB=\relax % hook for program brackets |...| in TeX part or section name
67 \chardef\AM=`\& % ampersand character in a string
68 \chardef\BS=`\\ % backslash in a string
69 \chardef\LB=`\{ % left brace in a string
70 \chardef\RB=`\} % right brace in a string
71 \def\SP{{\tt\char`\ }} % (visible) space in a string
72 \chardef\TL=`\~ % tilde in a string
73 \chardef\UL=`\_ % underline character in a string
74 \chardef\CF=`\^ % circumflex character in a string
76 \newbox\PPbox % symbol for ++
77 \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
78 \def\PP{\copy\PPbox}
79 \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
80 \kern-1pt\char0}\kern.5pt}
81 \def\MM{\copy\MMbox}
82 \newbox\MGbox % symbol for ->
83 \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
84 \def\MG{\copy\MGbox}
85 \def\MRL#1{\mathrel{\let\K==#1}}
86 %\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
87 \let\GG=\gg
88 \let\LL=\ll
89 \let\NULL=\Lambda
90 \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
91 \let\OR=\mid % bitwise or
92 \let\XOR=\oplus % bitwise exclusive or
93 \def\CM{{\sim}} % bitwise complement
94 \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
95 \def\MOD{\mathbin{\copy\MODbox}}
96 \def\DC{\kern.1em{::}\kern.1em} % symbol for ::
97 \def\PA{\mathbin{.*}} % symbol for .*
98 \def\MGA{\mathbin{\MG*}} % symbol for ->*
99 \def\this{\&{this}}
101 \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
102 \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
104 \newcount\ind % current indentation in ems
105 \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
106 \def\2{\global\advance\ind by-1} % indent one less notch
107 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
108 \def\4{\copy\bak} % backspace one notch
109 \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
110 \def\6{\ifmmode\else\par % forced break
111 \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
112 \def\7{\Y\6} % forced break and a little extra space
113 \def\8{\hskip-\ind em\hskip 2em} % no indentation
115 \newcount\gdepth % depth of current major group, plus one
116 \newcount\secpagedepth
117 \secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
118 \newtoks\gtitle % title of current major group
119 \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
120 \let\yskip=\smallskip
121 \def\?{\mathrel?}
122 \def\note#1#2.{\Y\noindent{\hangindent2em%
123 \baselineskip10pt\eightrm#1~\ifacro{\pdfnote#2.}\else#2\fi.\par}}
125 \newtoks\toksA \newtoks\toksB \newtoks\toksC \newtoks\toksD
126 \newtoks\toksE \newtoks\toksF \newtoks\usersanitizer
127 \newcount\countA \countA=0 \newcount\countB \countB=0
128 \newcount\countC \countC=0
129 \newif\iftokprocessed \newif\ifTnum \newif\ifinstr
130 {\def\\{\global\let\spacechar= }\\ }
132 \ifacro % The following are pdf macros
133 \def\thewidth{\the\wd0 \space}
134 \def\theheight{\the\ht\strutbox\space}
135 \def\thedepth{\the\dp\strutbox\space}
136 \ifpdftex
137 \ifx\pdfannotlink\undefined\let\pdfannotlink\pdfstartlink\fi% for pdfTeX 0.14
138 \def\pdflink#1#2{\hbox{\pdfannotlink height\ht\strutbox depth\dp\strutbox
139 attr{/Border [0 0 0]} goto num #1 \BlueGreen #1\Black\pdfendlink}}
140 \else\def\pdflink#1#2{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
141 \special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
142 depth \thedepth << /Type /Annot /Subtype /Link
143 /Border [0 0 0] /A << /S /GoTo /D (#2) >> >>}\box0\relax}\fi
144 \def\pdfnote#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
145 \def\firstsecno#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}%
146 \def\makenote{\addtokens\toksB{\the\toksC}\def\makenote{\toksD={}
147 \toksC={}\let\space\empty}\makenote}\maketoks}}
148 \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
149 \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}%
150 \ifcat\noexpand\first0\countB=`#1\else\countB=0\fi\toksA={#2}}
151 \def\maketoks{\expandafter\poptoks\the\toksA|ENDTOKS|%
152 \ifnum\countB>`9 \countB=0 \fi
153 \ifnum\countB<`0
154 \ifnum0=\countC\else\makenote\fi
155 \ifx\first.\let\next=\maketoksdone\else
156 \let\next=\maketoks
157 \addtokens\toksB{\the\toksD}
158 \ifx\first,\addtokens\toksB{\space}\fi
160 \else \addtokens\toksC{\the\toksD}\global\countC=1\let\next=\maketoks
162 \next
164 \def\makenote{\addtokens\toksB
165 {\noexpand\pdflink{\the\toksC}{\romannumeral\the\toksC}}\toksC={}\global\countC=0}
166 \def\maketoksdone{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
167 \def\pdfURL#1#2{\ifpdftex\pdfannotlink height\ht\strutbox depth\dp\strutbox
168 attr {/Border [0 0 0]} user { /Type /Action /Subtype /Link /A
169 << /S /URI /URI (#2) >>}\BlueGreen #1\Black \pdfendlink
170 \else \ifpdf{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
171 \special{pdf: ec}}\special{pdf: ann width \thewidth\space height \theheight
172 \space depth \thedepth\space << /Border [0 0 0]
173 /Type /Action /Subtype /Link /A << /S /URI /URI (#2) >> >>}\box0\relax}%
174 \else #1 ({\tt#2})\fi\fi}
175 {\catcode`\~=12 \gdef\TILDE/{~}} % ~ in a URL
176 {\catcode`\_=12 \gdef\UNDER/{_}} % _ in a URL
177 \def\sanitizecommand#1#2{\addtokens\usersanitizer
178 {\noexpand\dosanitizecommand\noexpand#1{#2}}}
179 \def\dosanitizecommand#1#2{\ifx\nxt#1\addF{#2}\fi}
181 \catcode`\[=1 \catcode`\]=2 \catcode`\{=12 \catcode`\}=12
182 \def\lbchar[{] \def\rbchar[}]
183 \catcode`\[=12 \catcode`\]=12 \catcode`\{=1 \catcode`\}=2
184 \catcode`\~=12 \def\tildechar{~} \catcode`\~=13
185 \catcode`\|=0 |catcode`|\=12 |def|bschar{\} |catcode`|\=0 \catcode`\|=12
186 \def\makeoutlinetoks{\Tnumfalse\afterassignment\makeolproctok\let\nxt= }
187 \def\makeolnexttok{\afterassignment\makeolproctok\let\nxt= }
188 \def\makeolgobbletok{\afterassignment\makeolnexttok\let\nxt= }
189 \def\addF#1{\addtokens\toksF{#1}\tokprocessedtrue}
190 % now comes a routine to "sanitize" section names, for pdf outlines
191 \def\makeolproctok{\tokprocessedfalse
192 \let\next\makeolnexttok % default
193 \ifx\nxt\outlinedone\let\next\outlinedone
194 \else\ifx{\nxt \else\ifx}\nxt \Tnumfalse \instrfalse % skip braces
195 \else\ifx$\nxt % or a $ sign
196 \else\ifx^\nxt \addF^\else\ifx_\nxt \addF_% sanitize ^ and _
197 \else\ifx\nxt\spacechar \addF\space
198 \else\if\noexpand\nxt\relax % we have a control sequence; is it one we know?
199 \ifx\nxt~\addF\space
200 \else\ifx\nxt\onespace\addF\space
201 \else\the\usersanitizer
202 \iftokprocessed\else\makeolproctokctli
203 \iftokprocessed\else\makeolproctokctlii
204 \iftokprocessed\else\makeolproctokctliii % if not recognised, skip it
205 \fi\fi\fi\fi\fi
206 \else % we don't have a control sequence, it's an ordinary char
207 \ifx/\nxt \addF{\string\/}% quote chars special to PDF with backslash
208 \else\ifx(\nxt \addF{\string\(}\else\ifx)\nxt \addF{\string\)}%
209 \else\ifx[\nxt \addF{\string\[}\else\ifx]\nxt \addF{\string\]}%
210 \else\expandafter\makeolproctokchar\meaning\nxt
211 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
212 \next
214 \def\makeolproctokchar#1 #2 #3{\addF{#3}}
215 \def\makeolproctokctli{%
216 \ifx\nxt\CEE\addF{C}\let\next\makeolgobbletok % \CEE/
217 \else\ifx\nxt\UNIX\addF{UNIX}\let\next\makeolgobbletok % \UNIX/
218 \else\ifx\nxt\TEX\addF{TeX}\let\next\makeolgobbletok % \TEX/
219 \else\ifx\nxt\TeX\addF{TeX}\else\ifx\nxt\LaTeX\addF{LaTeX}%
220 \else\ifx\nxt\CPLUSPLUS\addF{C++}\let\next\makeolgobbletok % \CPLUSPLUS/
221 \else\ifx\nxt\Cee\addF{C}%
222 \else\ifx\nxt\PB \let\next\makeolgobbletok \tokprocessedtrue % \PB{...}
223 \else\ifx\nxt\.\tokprocessedtrue\instrtrue % \.{...}
224 % skip \|
225 \else\ifx\nxt\\\ifinstr\addF{\bschar\bschar}\else\tokprocessedtrue\fi
226 \else\ifx\nxt\&\ifinstr\addF&\else\tokprocessedtrue\fi
227 \else\ifx\nxt\~\ifTnum\addF{0}\else\addF\tildechar\fi % 077->\T{\~77}
228 \else\ifx\nxt\_\ifTnum\addF{E}\else\addF_\fi % 0.1E5->\T{0.1\_5}
229 \else\ifx\nxt\^\ifTnum\addF{0x}\else\addF^\fi % 0x77 -> \T{\^77}
230 \else\ifx\nxt\$\ifTnum\tokprocessedtrue\else\addF$\fi % \T{77\$L}
231 \else\ifx\nxt\{\addF\lbchar \else\ifx\nxt\}\addF\rbchar
232 \else\ifx\nxt\ \addF\space \else\ifx\nxt\#\addF{\string\#}%
233 \else\ifx\nxt\PP\addF{++}\else\ifx\nxt\MM\addF{--}%
234 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
236 \def\makeolproctokctlii{%
237 \ifx\nxt\MG\addF{->}\else\ifx\nxt\GG\addF{>>}%
238 \else\ifx\nxt\LL\addF{<<}\else\ifx\nxt\NULL\addF{NULL}%
239 \else\ifx\nxt\AND\addF&\else\ifx\nxt\OR\addF|%
240 \else\ifx\nxt\XOR\addF^\else\ifx\nxt\CM\addF\tildechar
241 \else\ifx\nxt\MOD\addF{\string\%}\else\ifx\nxt\DC\addF{::}%
242 \else\ifx\nxt\PA\addF{.*}\else\ifx\nxt\MGA\addF{->*}%
243 \else\ifx\nxt\this\addF{this}\else\ifx\nxt\?\addF?%
244 \else\ifx\nxt\E\addF{==}\else\ifx\nxt\G\addF{>=}%
245 \else\ifx\nxt\I\addF{!=}\else\ifx\nxt\K\addF{=}%
246 \else\ifx\nxt\l\addF{l}\else\ifx\nxt\L\addF{L}%
247 \else\ifx\nxt\o\addF{o}\else\ifx\nxt\O\addF{O}%
248 \else\ifx\nxt\R\addF!%
249 \else\ifx\nxt\T \Tnumtrue \let\next\makeolgobbletok
250 \tokprocessedtrue % \T{number}
251 \else\ifx\nxt\AM\addF&\else\ifx\nxt\%\addF{\string\%}%
252 \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
253 \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
254 \fi\fi\fi\fi\fi\fi
256 \def\makeolproctokctliii{%
257 \ifx\nxt\V\addF{||}\else\ifx\nxt\W\addF{&&}\else\ifx\nxt\Z\addF{<=}%
258 \else\ifx\nxt\*\addF*\else\ifx\nxt\Xand\addF{\space and\space}%
259 \else\ifx\nxt\Xandxeq\addF{\space and_eq\space}%
260 \else\ifx\nxt\Xbitand\addF{\space bitand\space}%
261 \else\ifx\nxt\Xbitor\addF{\space bitor\space}%
262 \else\ifx\nxt\Xcompl\addF{\space compl\space}%
263 \else\ifx\nxt\Xnot\addF{\space not\space}%
264 \else\ifx\nxt\Xnotxeq\addF{\space not_eq\space}%
265 \else\ifx\nxt\Xor\addF{\space or\space}%
266 \else\ifx\nxt\Xorxeq\addF{\space or_eq\space}%
267 \else\ifx\nxt\Xxor\addF{\space xor\space}%
268 \else\ifx\nxt\Xxorxeq\addF{\space xor_eq\space}%
269 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
270 \fi\fi\fi\fi\fi
272 \def\outlinedone{\edef\outlinest{\global\noexpand\toksE={\the\toksF}}%
273 \outlinest\let\outlinedone=\relax}
274 \fi % End of pdf macros
276 \def\lapstar{\rlap{*}}
277 \def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
278 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
279 \noindent{\let\*=\lapstar\bf\secstar.\quad}%
280 \ifpdftex\smash{\raise\baselineskip\hbox to0pt{%
281 % \let\*=\empty\pdfdest num \secstar fith}} % bad space in versions < 3.68
282 \let\*=\empty\pdfdest num \secstar fith}}% changed in version 3.68
283 \else\ifpdf\smash{\raise\baselineskip\hbox to0pt{%
284 \let\*=\empty\special{%
285 pdf: dest (\romannumeral\secstar) [ @thispage /FitH @ypos ]}}}\fi\fi}
286 \let\startsection=\stsec
287 \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
288 \def\A{\note{See also section}} % xref for doubly defined section name
289 \def\As{\note{See also sections}} % xref for multiply defined section name
290 \def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
291 \sfcode`;=3000
292 \pretolerance 10000
293 \hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
294 \exhyphenpenalty 10000
295 \global\ind=2 \1\ \unskip}
296 \def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
297 \let\SHC\C % "// short comments" treated like "/* ordinary comments */"
298 %\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
299 %\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
300 \def\D{\defin{\#define}} % macro definition
301 \let\E=\equiv % equivalence sign
302 \def\ET{ and~} % conjunction between two section numbers
303 \def\ETs{, and~} % conjunction between the last two of several section numbers
304 \def\F{\defin{format}} % format definition
305 \let\G=\ge % greater than or equal sign
306 % \H is long Hungarian umlaut accent
307 \let\I=\ne % unequal sign
308 \def\J{\.{@\&}} % TANGLE's join operation
309 \let\K== % assignment operator
310 %\let\K=\leftarrow % "honest" alternative to standard assignment operator
311 % \L is Polish letter suppressed-L
312 \outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
313 \vskip\intersecskip\startsection\ignorespaces}
314 \outer\def\N#1#2#3.{% beginning of starred section
315 \ifacro{\toksF={}\makeoutlinetoks#3\outlinedone\outlinedone}\fi
316 \gdepth=#1\gtitle={#3}\MN{#2}%
317 \ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
318 \else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
319 \message{*\secno} % progress report
320 \def\stripprefix##1>{}\def\gtitletoks{#3}%
321 \edef\gtitletoks{\expandafter\stripprefix\meaning\gtitletoks}%
322 \edef\next{\write\cont{\ZZ{\gtitletoks}{#1}{\secno}% write to contents file
323 {\noexpand\the\pageno}{\the\toksE}}}\next % \ZZ{title}{depth}{sec}{page}{ss}
324 \ifpdftex\expandafter\xdef\csname curr#1\endcsname{\secno}
325 \ifnum#1>0\countB=#1 \advance\countB by-1
326 \advancenumber{chunk\the\countB.\expnumber{curr\the\countB}}\fi\fi
327 \ifpdf\special{pdf: outline #1 << /Title (\the\toksE) /Dest
328 [ @thispage /FitH @ypos ] >>}\fi
329 \ifon\startsection{\bf#3.\quad}\ignorespaces}
330 \def\MN#1{\par % common code for \M, \N
331 {\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
332 \ifx\secno\secstar \onmaybe \else\ontrue \fi
333 \mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
334 % each \mark is {section reference or null}{depth plus 1}{group title}
335 % \O is Scandinavian letter O-with-slash
336 % \P is paragraph sign
337 \def\Q{\note{This code is cited in section}} % xref for mention of a section
338 \def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
339 \let\R=\lnot % logical not
340 % \S is section sign
341 \def\T#1{\leavevmode % octal, hex or decimal constant
342 \hbox{$\def\?{\kern.2em}%
343 % \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant % versions < 3.67
344 \def\$##1{\egroup_{\rm##1}\bgroup}% suffix to constant % in version 3.67
345 \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
346 \let\~=\oct \let\^=\hex {#1}$}}
347 \def\U{\note{This code is used in section}} % xref for use of a section
348 \def\Us{\note{This code is used in sections}} % xref for uses of a section
349 \let\V=\lor % logical or
350 \let\W=\land % logical and
351 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
352 \XX$\langle\,${\let\I=\ne#2\eightrm\kern.5em
353 \ifacro{\pdfnote#1.}\else#1\fi}$\,\rangle$\XX}
354 \def\Y{\par\yskip}
355 \let\Z=\le
356 \let\ZZ=\let % now you can \write the control sequence \ZZ
357 \let\*=*
359 \def\Xand{\W} \def\Xandxeq{\MRL{{\AND}{\K}}} \def\Xbitand{\AND}
360 \def\Xbitor{\OR} \def\Xcompl{\CM} \def\Xnot{\R} \def\Xnotxeq{\I} \def\Xor{\V}
361 \def\Xorxeq{\MRL{{\OR}{\K}}} \def\Xxor{\XOR} \def\Xxorxeq{\MRL{{\XOR}{\K}}}
363 %\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
364 %\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
365 \def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
366 \def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
367 \def\vb#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
368 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
369 \hrule}\vrule\kern2pt}} % verbatim string
371 \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
372 \newif\ifon \newif\iftitle \newif\ifpagesaved
374 \newif\ifheader
375 \def\lheader{\headertrue\mainfont\the\pageno\eightrm\qquad\grouptitle
376 \hfill\title\qquad\mainfont\topsecno} % top line on left-hand pages
377 \def\rheader{\headertrue\mainfont\topsecno\eightrm\qquad\title\hfill
378 \grouptitle\qquad\mainfont\the\pageno} % top line on right-hand pages
379 \def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
380 \takethree\topmark}}
381 \def\topsecno{\expandafter\takeone\topmark}
382 \def\takeone#1#2#3{#1}
383 \def\taketwo#1#2#3{#2}
384 \def\takethree#1#2#3{#3}
385 \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
387 \let\page=\pagebody \raggedbottom
388 % \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
389 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
390 \shipout\vbox{
391 \vbox to\fullpageheight{
392 \iftitle\global\titlefalse
393 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
394 \vfill#1}} % parameter #1 is the page itself
395 \global\advance\pageno by1}
397 \gtitle={\.{CWEB} output} % this running head is reset by starred sections
398 \mark{\noexpand\nullsec0{\the\gtitle}}
399 \def\title{\expandafter\uppercase\expandafter{\jobname}}
400 \def\topofcontents{\centerline{\titlefont\title}\vskip.7in
401 \vfill} % this material will start the table of contents page
402 \def\startpdf{\ifpdftex\pdfcatalog{/PageMode /UseOutlines}\else
403 \ifpdf{\special{pdf: docview << /PageMode /UseOutlines >>}}\fi\fi}
404 \def\botofcontents{\vfill
405 \centerline{\covernote}} % this material will end the table of contents page
406 \def\covernote{}
407 \def\contentspagenumber{0} % default page number for table of contents
408 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
409 \newdimen\pageheight \pageheight=8.7in % the height of each page
410 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
411 \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
412 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
413 \fullpageheight=9truein\setpage}
414 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
415 \def\contentsfile{\jobname.toc} % file that gets table of contents info
416 \def\readcontents{\input \contentsfile}
417 \def\readindex{\input \jobname.idx}
418 \def\readsections{\input \jobname.scn}
420 \newwrite\cont
421 \output{\setbox0=\page % the first page is garbage
422 \openout\cont=\contentsfile
423 \write\cont{\catcode `\noexpand\@=11\relax} % \makeatletter
424 \global\output{\normaloutput\page\lheader\rheader}}
425 \setpage
426 \vbox to \vsize{} % the first \topmark won't be null
428 \def\ch{\note{The following sections were changed by the change file:}
429 \let\*=\relax}
430 \newbox\sbox % saved box preceding the index
431 \newbox\lbox % lefthand column in the index
432 \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
433 \def\page{\box255 } \normalbottom
434 \write\cont{} % ensure that the contents file isn't empty
435 \write\cont{\catcode `\noexpand\@=12\relax} % \makeatother
436 \closeout\cont % the contents information has been fully gathered
437 \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
438 \global\setbox\sbox=\page \global\pagesavedtrue}
439 \pagesavedfalse \eject % eject the page-so-far and predecessors
440 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
441 \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
442 \hsize=.5\pagewidth \advance\hsize by -10pt
443 % column width for the index (20pt between cols)
444 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
445 \def\lr{L} % this tells whether the left or right column is next
446 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
447 \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
448 \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
449 \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
450 \message{Index:}
451 \parskip 0pt plus .5pt
452 \outer\def\I##1, ##2.{\par\hangindent2em\noindent##1:\kern1em
453 \ifacro\pdfnote##2.\else##2\fi.} % index entry
454 \def\[##1]{$\underline{##1}$} % underlined index item
455 \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
456 \hyphenpenalty 10000 \parindent0pt
457 \readindex}
458 \def\fin{\par\vfill\eject % this is done when we are ending the index
459 \ifpagesaved\null\vfill\eject\fi % output a null index column
460 \if L\lr\else\null\vfill\eject\fi % finish the current page
461 \ifpdftex \makebookmarks \fi % added in Version 3.68
462 \parfillskip 0pt plus 1fil
463 \def\grouptitle{NAMES OF THE SECTIONS}
464 \let\topsecno=\nullsec
465 \message{Section names:}
466 \output={\normaloutput\page\lheader\rheader}
467 \setpage
468 \def\note##1##2.{\quad{\eightrm##1~\ifacro{\pdfnote##2.}\else{##2}\fi.}}
469 \def\Q{\note{Cited in section}} % crossref for mention of a section
470 \def\Qs{\note{Cited in sections}} % crossref for mentions of a section
471 \def\U{\note{Used in section}} % crossref for use of a section
472 \def\Us{\note{Used in sections}} % crossref for uses of a section
473 \def\I{\par\hangindent 2em}\let\*=*
474 \ifacro \def\outsecname{Names of the sections} \let\Xpdf\X
475 % \ifpdftex \makebookmarks \pdfdest name {NOS} fitb % in versions < 3.68
476 \ifpdftex \pdfdest name {NOS} fitb % changed in version 3.68
477 \pdfoutline goto name {NOS} count -\secno {\outsecname}
478 \def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
479 {\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
480 \pdfoutline goto num \the\toksA \expandafter{\the\toksE}}
481 \else\ifpdf
482 \special{pdf: outline -1 << /Title (\outsecname)
483 /Dest [ @thispage /FitH @ypos ] >>}
484 \def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
485 {\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
486 \special{pdf: outline 0 << /Title (\the\toksE)
487 /A << /S /GoTo /D (\romannumeral\the\toksA) >> >>}}
488 \fi\fi\fi
489 \readsections}
490 \def\makebookmarks{\let\ZZ=\writebookmarkline \readcontents\relax}
491 \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
492 \else \csname#1\endcsname \fi} % Petr Olsak's macros from texinfo.tex
493 \def\advancenumber#1{\countA=\expnumber{#1}\relax \advance\countA by1
494 \expandafter\xdef\csname#1\endcsname{\the\countA}}
495 \def\writebookmarkline#1#2#3#4#5{{%
496 \let\(=\let \let\)=\let \let\[=\let \let\]=\let \let\/=\let
497 \pdfoutline goto num #3 count -\expnumber{chunk#2.#3} {#5}}}
498 \def\con{\par\vfill\eject % finish the section names
499 % \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
500 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
501 \setpage \output={\normaloutput\page\lheader\rheader}
502 \titletrue % prepare to output the table of contents
503 \pageno=\contentspagenumber
504 \def\grouptitle{TABLE OF CONTENTS}
505 \message{Table of contents:}
506 \topofcontents \startpdf
507 \line{\hfil Section\hbox to3em{\hss Page}}
508 \let\ZZ=\contentsline
509 \readcontents\relax % read the contents info
510 \botofcontents \end} % print the contents page(s) and terminate
511 \def\contentsline#1#2#3#4#5{\ifnum#2=0 \smallbreak\fi
512 \line{\consetup{#2}#1
513 \rm\leaders\hbox to .5em{.\hfil}\hfil
514 \ \ifacro\pdflink{#3}{\romannumeral#3}\else#3\fi\hbox to3em{\hss#4}}}
515 \def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
516 \or % depth 0 (@*)
517 \or \hskip2em % depth 1 (@*1)
518 \or \hskip4em \or \hskip6em \or \hskip8em \or \hskip10em % depth 2,3,4,5
519 \else \hskip12em \fi} % depth 6 or more
520 \def\noinx{\let\inx=\end} % no indexes or table of contents
521 \def\nosecs{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
522 % no index of section names or table of contents
523 \def\nocon{\let\con=\end} % no table of contents
524 \def\today{\ifcase\month\or
525 January\or February\or March\or April\or May\or June\or
526 July\or August\or September\or October\or November\or December\fi
527 \space\number\day, \number\year}
528 \newcount\twodigits
529 \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
530 \multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
531 \def\gobbleone1{}
532 \def\printtwodigits{\advance\twodigits100
533 \expandafter\gobbleone\number\twodigits
534 \advance\twodigits-100 }
535 \def\TeX{{\ifmmode\it\fi
536 \leavevmode\hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
537 \def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
538 \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
539 \let\startsection=\stsec\stsec}}
540 % say `\datethis' in limbo, to get your listing timestamped before section 1
541 %\def\datecontentspage{% versions up to 3.65
542 % \def\topofcontents{\leftline{\sc\today\ at \hours}\bigskip
543 % \centerline{\titlefont\title}\vfill}} % timestamps the contents page
544 \def\datecontentspage{% changed in version 3.66
545 \def\botofcontents{\vfill
546 \centerline{\covernote}
547 \bigskip
548 \leftline{\sc\today\ at \hours}}} % timestamps the contents page