Debian Codegraph @

texmf-dist/tex/plain/pwebmac/pwebmac.tex

raw
1 % standard macros for WEB listings (in addition to PLAIN.TEX)
2 % pdfTeX adjustments provided by Han The Thanh <[email protected]>.
3 % XeTeX adjustments provided by Khaled Hosny <[email protected]>.
4 % HiTeX adjustments provided by Martin Ruckert <[email protected]>.
5 % macro integration \`a la CWEB by Andreas Scherer <[email protected]>.
6 % This file is not copyrighted and can be used freely.
7 \ifx\renewenvironment\undefined\else\endinput\fi % LaTeX will use other macros
8 \xdef\fmtversion{\fmtversion+PWEBMAC5.1}
9
10 \parskip 0pt % no stretch between paragraphs
11 \parindent 1em % for paragraphs and for the first line of Pascal text
12
13 \font\eightrm=cmr8
14 \let\sc=\eightrm % for smallish caps (NOT a caps-and-small-caps font)
15 \let\mainfont=\tenrm
16 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
17 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
18 \font\tentex=cmtex10 % TeX extended character set (used in strings)
19 \fontdimen7\tentex=0pt % no double space after sentences
20
21 \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
22 \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
23 \def\&#1{\leavevmode\hbox{\bf
24 \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
25 #1\/\kern.05em}} % boldface type for reserved words
26 \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
27 \let\\=\BS % backslash in a string
28 \let\'=\RQ % right quote in a string
29 \let\`=\LQ % left quote in a string
30 \let\{=\LB % left brace in a string
31 \let\}=\RB % right brace in a string
32 \let\~=\TL % tilde in a string
33 \let\ =\SP % space in a string
34 \let\_=\UL % underline in a string
35 \let\&=\AM % ampersand in a string
36 #1}}
37 \def\#{\hbox{\tt\char`\#}} % parameter sign
38 \def\${\hbox{\tt\char`\$}} % dollar sign
39 \def\%{\hbox{\tt\char`\%}} % percent sign
40 \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
41 % circumflex accents can be obtained from \^^D instead of \^
42 \def\AT!{@} % at sign for control text
43
44 \chardef\AM=`\& % ampersand character in a string
45 \chardef\BS=`\\ % backslash in a string
46 \chardef\LB=`\{ % left brace in a string
47 \def\LQ{{\tt\char'22}} % left quote in a string
48 \chardef\RB=`\} % right brace in a string
49 \def\RQ{{\tt\char'23}} % right quote in a string
50 \def\SP{{\tt\char`\ }} % (visible) space in a string
51 \chardef\TL=`\~ % tilde in a string
52 \chardef\UL=`\_ % underline character in a string
53
54 \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
55 \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
56
57 \newcount\ind % current indentation in ems
58 \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
59 \def\2{\global\advance\ind by-1} % indent one less notch
60 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
61 \def\4{\copy\bak} % backspace one notch
62 \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
63 \def\6{\ifmmode\else\par % forced break
64 \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
65 \def\7{\Y\6} % forced break and a little extra space
66
67 \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
68 \newtoks\gtitle % title of current major group
69 \let\yskip=\smallskip
70 \def\to{\mathrel{.\,.}} % double dot, used only in math mode
71 \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt%
72 \eightrm#1~\ifacrohint{\pdfnote#2.}\else#2\fi.\par}}
73
74 \newtoks\toksA \newtoks\toksB \newtoks\toksC \newtoks\toksD
75 \newtoks\toksE \newtoks\toksF \newtoks\usersanitizer
76 \newcount\countA \countA=0 \newcount\countB \countB=0
77 \newcount\countNOS \countNOS=0
78 \newif\iftokprocessed \newif\ifTnum \newif\ifinstr \newif\ifhavenum
79 {\def\\{\global\let\spacechar= }\\ }
80
81 % Here we decide the output format, depending on the TeX engine in use:
82 \input iftex.sty % TeX engine tests
83 \ifx\pdf+\pdftrue\fi % for plain TeX in combination with dvipdfm
84 % Uncomment the following line if you want PDF goodies to be the default
85 %\ifx\pdf-\else\pdftrue\fi
86 \ifxetex\pdftrue\fi % XeTeX produces PDF output
87 \ifpdf \def\pdflinkcolor{0 0 1} \fi % the RGB values for hyperlink color
88 \newif\ifacrohint \ifpdf\acrohinttrue\fi \ifhint\acrohinttrue\fi
89 \newif\ifpdflua \ifluatex\pdfluatrue\fi \ifpdftex\pdfluatrue\fi
90 \ifpdflua % pdfTeX and luaTeX produce PDF output if \pdfoutput>0 (default)
91 \def\Black{\pdfliteral{0 g 0 G}} % use rgb colors for direct PDF output too
92 \def\Blue{\pdfliteral{\pdflinkcolor\space rg \pdflinkcolor\space RG}} \fi
93
94 \ifluatex % LuaTeX is almost like pdfTeX
95 \protected\def\pdfliteral {\pdfextension literal}
96 \protected\def\pdfstartlink {\pdfextension startlink\space}
97 \protected\def\pdfendlink {\pdfextension endlink}
98 \protected\def\pdfoutline {\pdfextension outline\space}
99 \protected\def\pdfdest {\pdfextension dest\space}
100 \protected\def\pdfcatalog {\pdfextension catalog}
101 \chardef\pdfshellescape % excerpt from 'shellesc.sty'
102 \directlua{tex.sprint((status.shell_escape or os.execute()) .. " ")}
103 \edef\pdfhorigin {\pdfvariable horigin}
104 \edef\pdfvorigin {\pdfvariable vorigin}
105 \let\pdfpagewidth=\pagewidth
106 \let\pdfpageheight=\pageheight
107 \let\pdfoutput=\outputmode
108 \fi % end of LuaTeX->pdfTeX redirection macros
109
110 \ifacrohint % Common macros for \ifpdf and \ifhint for \pdflink's
111 \def\pdfnote#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
112 \def\firstsecno#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}%
113 \def\makenote{\addtokens\toksB{\the\toksC}\def\makenote{\let\space\empty
114 \toksC={}\toksD={}}\makenote}\maketoks}}
115 \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
116 \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}%
117 \ifcat\noexpand\first0\countB=`#1\else\countB=0\fi}
118 \def\maketoks{\expandafter\poptoks\the\toksA|ENDTOKS|%
119 \let\next=\maketoks % continue processing by default
120 \ifnum\countB>`9 \countB=0 \fi
121 \ifnum\countB<`0
122 \ifhavenum\makenote\fi
123 \ifx\first.\let\next=\maketoksdone % fullstop
124 \else\addtokens\toksB{\the\toksD}%
125 \ifx\first,\addtokens\toksB{\space}\fi
126 \fi
127 \else\addtokens\toksC{\the\toksD}\global\havenumtrue
128 \fi
129 \next
130 }
131 \def\makenote{\addtokens\toksB
132 {\noexpand\pdflink{\the\toksC}}\toksC={}\global\havenumfalse}
133 \def\maketoksdone{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
134 \fi % End of common pdf/hint macros
135
136 \ifpdf % The following are general pdf macros from 'cwebmac.tex 3.70'
137 \def\thewidth{\the\wd0 \space}
138 \def\theheight{\the\ht\strutbox\space}
139 \def\thedepth{\the\dp\strutbox\space}
140 \ifpdflua
141 \ifx\pdfannotlink\undefined\let\pdfannotlink\pdfstartlink\fi% for pdfTeX 0.14
142 \def\pdflink#1{\hbox{\pdfannotlink height \theheight depth \thedepth
143 attr{/Border [0 0 0]} goto num #1 \Blue #1\Black\pdfendlink}}
144 \else\def\pdflink#1{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
145 \special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
146 depth \thedepth << /Type /Annot /Subtype /Link /Border [0 0 0]
147 /A << /S /GoTo /D (\romannumeral#1) >> >>}\box0\relax}\fi
148 \def\sanitizecommand#1#2{\addtokens\usersanitizer
149 {\noexpand\dosanitizecommand\noexpand#1{#2}}}
150 \def\dosanitizecommand#1#2{\ifx\nxt#1\addF{#2}\fi}
151 \ifhint\else\sanitizecommand\to{..}\fi % a trivial example; requires \addtokens
152
153 \catcode`\[=1 \catcode`\]=2 \catcode`\{=12 \catcode`\}=12
154 \def\lbchar[{] \def\rbchar[}]
155 \catcode`\[=12 \catcode`\]=12 \catcode`\{=1 \catcode`\}=2
156 \catcode`\~=12 \def\tildechar{~} \catcode`\~=13
157 \catcode`\|=0 |catcode`|\=12 |def|bschar{\} |catcode`|\=0 \catcode`\|=12
158 \def\makeoutlinetoks{\toksF={}\Tnumfalse
159 \afterassignment\makeolproctok\let\nxt= }
160 \def\makeolnexttok{\afterassignment\makeolproctok\let\nxt= }
161 \def\makeolgobbletok{\afterassignment\makeolnexttok\let\nxt= }
162 \def\makeolgobbletokk{\afterassignment\makeolgobbletok\let\nxt= }
163 \def\addF#1{\addtokens\toksF{#1}\tokprocessedtrue}
164 % now comes a routine to "sanitize" section names, for pdf outlines
165 \def\makeolproctok{\tokprocessedfalse
166 \let\next\makeolnexttok % default
167 \ifx\nxt\outlinedone\let\next\outlinedone
168 \else\ifx{\nxt \else\ifx}\nxt \Tnumfalse \instrfalse % skip braces
169 \else\ifx$\nxt % or a $ sign
170 \else\ifx^\nxt \addF^\else\ifx_\nxt \addF_% sanitize ^ and _
171 \else\ifx\nxt\spacechar \addF\space
172 \else\if\noexpand\nxt\relax % we have a control sequence; is it one we know?
173 \ifx\nxt~\addF\space
174 \else\ifx\nxt\onespace\addF\space
175 \else\the\usersanitizer
176 \iftokprocessed\else\makeolproctokctl
177 \iftokprocessed\else\makeolproctokmath % if not recognised, skip it
178 \fi\fi
179 \fi\fi
180 \else % we don't have a control sequence, it's an ordinary char
181 \ifx(\nxt \addF{\string\(}\else\ifx)\nxt \addF{\string\)}%
182 %\else\ifx[\nxt \addF{\string\[}\else\ifx]\nxt \addF{\string\]}%
183 %\else\ifx/\nxt \addF{\string\/}% quote chars special to PDF with backslash
184 \else\expandafter\makeolproctokchar\meaning\nxt
185 \fi\fi%\fi\f\fi
186 \fi\fi\fi\fi\fi \fi\fi\fi
187 \next
188 }
189 \def\makeolproctokctl{%
190 \ifx\nxt\PASCAL\addF{Pascal\space}\let\next\makeolgobbletok % \PASCAL/
191 \else\ifx\nxt\UNIX\addF{UNIX}\let\next\makeolgobbletok % \UNIX/
192 \else\ifx\nxt\TEX\addF{TeX}\let\next\makeolgobbletok % \TEX/
193 \else\ifx\nxt\TeX\addF{TeX}\else\ifx\nxt\LaTeX\addF{LaTeX}%
194 \else\ifx\nxt\CPLUSPLUS\addF{C++}\let\next\makeolgobbletok % \CPLUSPLUS/
195 \else\ifx\nxt\CEE\addF{C}\else\ifx\nxt\Cee\addF{C}%
196 \else\ifx\nxt\PB \let\next\makeolgobbletok \tokprocessedtrue % \PB{...}
197 \else\ifx\nxt\9 \expandafter\nxt\relax \let\next\makeolgobbletokk % \9{#1}
198 \else\ifx\nxt\.\tokprocessedtrue\instrtrue % \.{...}
199 % skip \|
200 \else\ifx\nxt\\\ifinstr\addF{\bschar\bschar}\else\tokprocessedtrue\fi
201 \else\ifx\nxt\&\ifinstr\addF&\else\tokprocessedtrue\fi
202 \else\ifx\nxt\~\ifTnum\addF{0}\else\addF\tildechar\fi % 077->\T{\~77}
203 \else\ifx\nxt\_\ifTnum\addF{E}\else\addF_\fi % 0.1E5->\T{0.1\_5}
204 \else\ifx\nxt\^\ifTnum\addF{0x}\else\addF^\fi % 0x77 -> \T{\^77}
205 \else\ifx\nxt\$\ifTnum\tokprocessedtrue\else\addF$\fi %$% \T{77\$L}
206 \else\ifx\nxt\{\addF\lbchar\else\ifx\nxt\}\addF\rbchar
207 \else\ifx\nxt\ \addF\space\else\ifx\nxt\#\addF{\string\#}%
208 \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
209 \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
210 \fi
211 }
212 \def\makeolproctokmath{%
213 \ifx\nxt\alpha\addF{alpha}\else\ifx\nxt\beta\addF{beta}%
214 \else\ifx\nxt\gamma\addF{gamma}\else\ifx\nxt\delta\addF{delta}%
215 \else\ifx\nxt\theta\addF{theta}\else\ifx\nxt\psqrt\addF{root\space}%
216 \else\ifx\nxt\H\addF{"}\else\ifx\nxt\O\addF{'}\else\ifx\nxt\v\addF{|}%
217 \else\ifx\nxt\prime\addF{'}\else\ifx\nxt\K\addF{:=}\else\ifx\nxt\S\addF{==}%
218 \else\ifx\nxt\dots\addF{...\space}\else\ifx\nxt\<\addF{<}%
219 \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
220 \fi\fi\fi\fi
221 }
222 \def\makeolproctokchar#1 #2 #3{\addF{#3}}
223 \def\outlinedone{\edef\outlinest{\global\noexpand\toksE={\the\toksF}}%
224 \outlinest\let\outlinedone=\relax\outlinedone}
225 \fi % End of general pdf macros
226
227 \ifhint
228 % The following uses HINT primitives to implement:
229 % \HINThome to mark the position of the home page
230 % \HINTlabel to attach a label to the top of a section
231 % \HINTlink to link a section number to the section label
232 % \HINTcontents to produce an 'outline' item
233 % These are the top level HINT macros that are used in this file
234 % No HINT primitives are used directly.
235 \def\HINThome{\HINTdest name {HINT.home}%
236 \HINToutline goto name {HINT.home} depth 1 {Table of Contents}}
237 \def\HINTlabel{{\let\*=\empty\HINTdest num \modstar top}}
238 \def\HINTlink#1{\HINTstartlink goto num #1 {#1}\HINTendlink}
239 \def\HINTcontents#1#2{\HINToutline goto num #2 depth 1 {#1}}
240 \let\pdflink=\HINTlink
241 \fi % End of HINT macros
242
243 \def\pdfURL#1#2{\ifpdf \ifpdflua\pdfannotlink height \theheight depth \thedepth
244 attr {/Border [0 0 0]} user { /Type /Annot /Subtype /Link /A
245 << /S /URI /URI (#2) >> }\Blue #1\Black \pdfendlink
246 \else {\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
247 \special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
248 depth \thedepth << /Border [0 0 0] /Type /Annot /Subtype /Link /A
249 << /S /URI /URI (#2) >> >>}\box0\relax}\fi
250 \else #1 ({\tt#2})\fi}
251 {\catcode`\~=12 \gdef\TILDE/{~}} % ~ in a URL
252 {\catcode`\_=12 \gdef\UNDER/{_}} % _ in a URL
253
254 \def\lapstar{\rlap{*}}
255 \def\stsec{\rightskip=0pt % get out of Pascal mode (cf. \P)
256 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
257 \ifhint\HINTlabel\fi% Start page before section
258 \noindent{\let\*=\lapstar\bf\modstar.\quad}%
259 \ifpdf \smash{\raise\baselineskip\hbox to0pt{\let\*=\empty
260 \ifpdflua \pdfdest num \modstar fith%
261 \else \special{pdf: dest (\romannumeral\modstar)
262 [ @thispage /FitH @ypos ]}\fi}}\fi}
263 \let\startsection=\stsec
264 \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
265 \def\A{\note{See also section}} % xref for doubly defined section name
266 \def\As{\note{See also sections}} % xref for multiply defined section name
267 \def\B{\mathopen{\.{@\{}}} % begin controlled comment
268 \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% Pascal comments
269 \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
270 \def\D{\defin{define}} % macro definition
271 \def\E{\cdot10^} % exponent in floating point constant
272 \def\ET{ and~} % conjunction between two section numbers
273 \def\ETs{, and~} % conjunction between the last two of several section numbers
274 \def\F{\defin{format}} % format definition
275 \let\G=\ge % greater than or equal sign
276 \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
277 \let\I=\ne % unequal sign
278 \def\J{\.{@\&}} % TANGLE's join operation
279 \let\K=\gets % left arrow
280 \let\L=\le % less than or equal sign
281 \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
282 \vskip\intersecskip\startsection\ignorespaces}
283 \outer\def\N#1.#2.{% beginning of starred section
284 \ifpdf{\makeoutlinetoks#2\outlinedone}\fi
285 \gtitle={#2}\MN#1.\vfil\eject % define running headline
286 \message{*\modno} % progress report
287 \def\stripprefix##1>{}\def\gtitletoks{#2}%
288 \edef\gtitletoks{\expandafter\stripprefix\meaning\gtitletoks}%
289 \edef\next{\write\cont{\Z{\gtitletoks}{\modno}% write to contents file
290 {\noexpand\the\pageno}{\the\toksE}}}\next % \Z{title}{sec}{page}{ss}
291 \ifpdf \ifpdflua\relax
292 \else \special{pdf: outline 0 << /Title (\the\toksE) /Dest
293 [ @thispage /FitH @ypos ] >>}\fi\fi
294 \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
295 \def\MN#1.{\par % common code for \M, \N
296 {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}% remove \* from section name
297 \ifx\modno\modstar \onmaybe \else\ontrue \fi
298 \mark{{{\tensy x}\modno}{\the\gtitle}}}
299 % each \mark is {section reference or null}{group title}
300 \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
301 \def\P{\rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
302 \sfcode`;=3000
303 \pretolerance 10000
304 \hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
305 \exhyphenpenalty 10000
306 \global\ind=2 \1\ \unskip}
307 \let\R=\lnot % logical not
308 \let\S=\equiv % equivalence sign
309 \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
310 \def\U{\note{This code is used in section}} % xref for use of a section
311 \def\Us{\note{This code is used in sections}} % xref for uses of a section
312 \let\V=\lor % logical or
313 \let\W=\land % logical and
314 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
315 \XX$\langle\,$#2{\eightrm\kern.5em
316 \ifacrohint{\pdfnote#1.}\else#1\fi}$\,\rangle$\XX}
317 \def\Y{\par\yskip}
318 \let\Z=\let % now you can \send the control sequence \Z
319 \def\){\hbox{\.{@\$}}} % sign for string pool check sum
320 \def\]{\hbox{\.{@\\}}} % sign for forced line break
321 \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
322 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
323 \hrule}\vrule}\kern2pt} % verbatim string
324 \let\~=\ignorespaces
325 \let\*=*
326
327 \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
328 \newif\ifon \newif\iftitle \newif\ifpagesaved
329 \def\lheader{\mainfont\the\pageno\eightrm\qquad\grouptitle
330 \hfill\title\qquad\mainfont\topsecno} % top line on left-hand pages
331 \def\rheader{\mainfont\topsecno\eightrm\qquad\title\hfill
332 \grouptitle\qquad\mainfont\the\pageno} % top line on right-hand pages
333 \def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
334 \taketwo\topmark}}
335 \def\topsecno{\expandafter\takeone\topmark}
336 \def\takeone#1#2{#1}
337 \def\taketwo#1#2{#2}
338 \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
339
340 %\let\page=\pagebody \raggedbottom % cweb 3.2 uses this instead of next line
341 \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
342 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
343 \shipout\vbox{
344 \vbox to\fullpageheight{
345 \iftitle\global\titlefalse
346 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
347 \vfill#1}} % parameter #1 is the page itself
348 \global\advance\pageno by1}
349
350 \gtitle={{\tentex WEB} output} % this running head is reset by starred sections
351 \mark{\noexpand\nullsec{\the\gtitle}}
352 \def\title{\expandafter\uppercase\expandafter{\jobname}}
353 \def\topofcontents{\centerline{\titlefont\title}\vskip.7in
354 \vfill} % this material will start the table of contents page
355 \def\startpdf{\ifpdf\def\pagemode{/PageMode /UseOutlines}
356 \ifnum\contentspagenumber=0 \advance \pageno by -1
357 \def\pagelabels{/PageLabels << /Nums [ 0 << /S/D/St 1 >>
358 \the\pageno << /P(Contents) >> ] >>}
359 \else \twodigits=\pageno \pageno=\contentspagenumber
360 \advance \pageno by 1 \advance \twodigits by -\pageno
361 \def\pagelabels{/PageLabels << /Nums [ 0 << /S/D/St \the\pageno >>
362 \the\twodigits << /S/D/St \contentspagenumber >> ] >>} \fi
363 \ifpdflua\pdfcatalog{\pagemode\space\pagelabels}
364 \else \special{pdf: docview << \pagemode\space\pagelabels >>}\fi\fi}
365 \def\botofcontents{\vfill
366 \centerline{\covernote}} % this material will end the table of contents page
367 \def\covernote{}
368 \def\contentspagenumber{0} % default page number for table of contents
369 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
370 \newdimen\pageheight \pageheight=8.7in % the height of each page
371 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
372 \newdimen\pageshift \pageshift=\hoffset
373 % shift righthand pages wrt lefthand ones
374 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
375 \fullpageheight=9truein\setpage}
376 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
377 \def\contentsfile{CONTENTS} % file that gets table of contents info
378 \def\readcontents{\input \contentsfile}
379
380 \newwrite\cont
381 \output{\setbox0=\page % the first page is garbage
382 \openout\cont=\contentsfile
383 \write\cont{\catcode `\noexpand\@=11\relax} % \makeatletter
384 \global\output{\normaloutput\page\lheader\rheader}}
385 \setpage
386 \vbox to \vsize{} % the first \topmark won't be null
387
388 \def\ch{\note{The following sections were changed by the change file:}
389 \let\*=\relax}
390 \newbox\sbox % saved box preceding the index
391 \newbox\lbox % lefthand column in the index
392 \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
393 \def\page{\box255 } \normalbottom
394 \write\cont{} % ensure that the contents file isn't empty
395 \write\cont{\catcode `\noexpand\@=12\relax} % \makeatother
396 \closeout\cont % the contents information has been fully gathered
397 \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
398 \global\setbox\sbox=\page \global\pagesavedtrue \mark{\topmark}}
399 \pagesavedfalse \eject % eject the page-so-far and predecessors
400 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
401 \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
402 \hsize=.5\pagewidth \advance\hsize by -10pt
403 % column width for the index (20pt between cols)
404 \ifhint\else
405 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
406 \fi
407 \def\lr{L} % this tells whether the left or right column is next
408 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
409 \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
410 \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
411 \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
412 \message{Index:}
413 \parskip 0pt plus .5pt
414 \outer\def\:##1, ##2.{\par\hangindent2em\noindent##1:\kern1em
415 \scan##2!.} % index entry
416 \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
417 \def\[##1]{$\underline{\scan##1!}$\scan} % underlined index item
418 \ifacrohint\def\digits{\pdflink{\the\countA}\scan}
419 \else\def\digits{{\the\countA}\scan}\fi
420 \def\scan##1{\begingroup
421 \ifx!##1% exit on exclamation point
422 \else\ifx,##1,\space\aftergroup\scan % insert ,\space}\scan...
423 \else\ifx\[##1\aftergroup##1% insert }\[...
424 \else\ifx\*##1\aftergroup\lapstar\aftergroup\scan % insert }\lapstar\scan...
425 \else\ifnum`##1>`9##1\aftergroup\scan % insert #1}\scan...
426 \else\ifnum`##1<`0##1\aftergroup\scan % insert #1}\scan...
427 \else
428 \afterassignment\digits \aftergroup\countA
429 \aftergroup##1% insert }\countA=#1\digits...
430 \fi\fi\fi\fi\fi \fi
431 \endgroup}
432 \rm \rightskip0pt plus 2.5em \tolerance 10000
433 \hyphenpenalty 10000 \parindent0pt}
434 \def\fin{\par\vfill\eject % this is done when we are ending the index
435 \ifpagesaved\null\vfill\eject\fi % output a null index column
436 \if L\lr\else\null\vfill\eject\fi % finish the current page
437 \ifpdflua \makebookmarks % added in Version 4.5
438 \ifnum\pdfshellescape=1 {\let\\=\BS % count the @<named sections@>
439 \global\countNOS=\input{|grep -c -e '\\:\\X' \jobname.tex}} \fi\fi
440 \parfillskip 0pt plus 1fil
441 \def\grouptitle{NAMES OF THE SECTIONS}
442 \let\topsecno=\nullsec
443 \message{Section names:}
444 \output={\normaloutput\page\lheader\rheader}
445 \setpage
446 \def\note##1##2.{\quad{\eightrm##1~\ifacrohint{\pdfnote##2.}\else{##2}\fi.}}
447 \linepenalty=10 % try to conserve lines
448 \def\U{\note{Used in section}} % crossref for use of a section
449 \def\Us{\note{Used in sections}} % crossref for uses of a section
450 \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry
451 \ifpdf \def\outsecname{Names of the sections} \let\Xpdf\X
452 \ifpdflua \pdfdest name {NOS} fith
453 \ifnum \countNOS>0 \xdef\modno{\the\countNOS} \fi
454 \pdfoutline goto name {NOS} count -\modno {\outsecname}
455 \else \special{pdf: outline -1 << /Title (\outsecname)
456 /Dest [ @thispage /FitH @ypos ] >>}\fi
457 \def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
458 {\makeoutlinetoks##2\outlinedone}%
459 \ifpdflua \pdfoutline goto num \the\toksA \expandafter{\the\toksE}
460 \else \special{pdf: outline 0 << /Title (\the\toksE)
461 /A << /S /GoTo /D (\romannumeral\the\toksA) >> >>}\fi}
462 \fi}
463 \def\makebookmarks{\def\?##1]{[##1]}%
464 \let\Z=\writebookmarkline \readcontents\relax}
465 \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
466 \else \csname#1\endcsname \fi} % Petr Olsak's macros from texinfo.tex
467 \def\advancenumber#1{\countA=\expnumber{#1}\relax \advance\countA by1
468 \expandafter\xdef\csname#1\endcsname{\the\countA}}
469 \def\writebookmarkline#1#2#3#4{{%
470 \let\(=\let \let\)=\let \let\[=\let \let\]=\let \let\/=\let
471 \pdfoutline goto num #2{#4}}}
472 \def\con{\par\vfill\eject % finish the section names
473 % \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
474 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
475 \setpage \output={\normaloutput\page\lheader\rheader}
476 \startpdf \titletrue % prepare to output the table of contents
477 \pageno=\contentspagenumber
478 \def\grouptitle{TABLE OF CONTENTS}
479 \message{Table of contents:}
480 \ifhint\HINThome\fi% Mark the Table of contents as home page
481 \topofcontents
482 \line{\hfil Section\ifhint\else\hbox to3em{\hss Page}\fi}% No Page in HINT
483 \let\Z=\contentsline
484 \readcontents\relax % read the contents info
485 \botofcontents \end} % print the contents page(s) and terminate
486 \def\contentsline#1#2#3#4{%
487 \line{\ignorespaces#1
488 \rm\leaders\hbox to .5em{.\hfil}\hfil
489 \ \ifhint
490 \HINTlink{#2}% No page numbers in HINT
491 \HINTcontents{#1}{#2}%
492 \else\ifpdf\pdflink{#2}\else#2\fi
493 \hbox to3em{\hss#3}\fi}}
494 \def\today{\ifcase\month\or
495 January\or February\or March\or April\or May\or June\or
496 July\or August\or September\or October\or November\or December\fi
497 \space\number\day, \number\year}
498 \newcount\twodigits
499 \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
500 \multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
501 \def\gobbleone1{}
502 \def\printtwodigits{\advance\twodigits100
503 \expandafter\gobbleone\number\twodigits
504 \advance\twodigits-100 }
505 \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
506 \let\startsection=\stsec\stsec}}
507 % say `\datethis' in limbo, to get your listing timestamped before section 1
508 \def\datecontentspage{% say this in limbo to get the toc page timestamped
509 \def\botofcontents{\vfill
510 \centerline{\covernote}
511 \bigskip
512 \leftline{\sc\today\ at \hours}}} % timestamps the contents page