Debian Codegraph @

texmf-dist/tex/plain/cweb-old/pdfcwebmac.tex

raw
1 % standard macros for CWEB listings (in addition to plain.tex)
2 % Version 3.1 --- September 1994
3 % Modified for use with "pdftex" by Andreas Scherer, April 1997
4 \ifx\documentstyle\undefined\else\endinput\fi % LaTeX will use other macros
5 \xdef\fmtversion{\fmtversion+HyperCWEB3.1}
6
7 \let\:=\. % preserve a way to get the dot accent
8 % (all other accents will still work as usual)
9
10 \parskip 0pt % no stretch between paragraphs
11 \parindent 1em % for paragraphs and for the first line of C text
12
13 \font\ninerm=cmr9
14 \let\mc=\ninerm % medium caps
15 \def\CEE/{{\mc C\spacefactor1000}}
16 \def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
17 \def\TEX/{\TeX}
18 \def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
19 \def\Cee{\CEE/} % for backward compatibility
20 \def\9#1{}
21 \font\eightrm=cmr8
22 \let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
23 \let\mainfont=\tenrm
24 \let\cmntfont\tenrm
25 %\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
26 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
27 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
28 \font\tentex=cmtex10 % TeX extended character set (used in strings)
29 \fontdimen7\tentex=0pt % no double space after sentences
30
31 \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
32 \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
33 \def\&#1{\leavevmode\hbox{\bf
34 \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
35 #1\/\kern.05em}} % boldface type for reserved words
36 \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
37 \let\\=\BS % backslash in a string
38 \let\{=\LB % left brace in a string
39 \let\}=\RB % right brace in a string
40 \let\~=\TL % tilde in a string
41 \let\ =\SP % space in a string
42 \let\_=\UL % underline in a string
43 \let\&=\AM % ampersand in a string
44 \let\^=\CF % circumflex in a string
45 #1\kern.05em}}
46 \def\){\discretionary{\hbox{\tentex\BS}}{}{}}
47 \def\AT{@} % at sign for control text (not needed in versions >= 2.9)
48 \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
49 \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
50 tangles as \tentex "#2"\egroup\par}
51 \def\noATL#1 #2 {}
52 \def\noatl{\let\ATL=\noATL} % suppress output from @l
53 \def\ATH{\X\kern-.5em:Preprocessor definitions\X}
54 \let\PB=\relax % hook for program brackets |...| in TeX part or section name
55
56 \chardef\AM=`\& % ampersand character in a string
57 \chardef\BS=`\\ % backslash in a string
58 \chardef\LB=`\{ % left brace in a string
59 \chardef\RB=`\} % right brace in a string
60 \def\SP{{\tt\char`\ }} % (visible) space in a string
61 \chardef\TL=`\~ % tilde in a string
62 \chardef\UL=`\_ % underline character in a string
63 \chardef\CF=`\^ % circumflex character in a string
64
65 \newbox\PPbox % symbol for ++
66 \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
67 \def\PP{\copy\PPbox}
68 \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
69 \kern-1pt\char0}\kern.5pt}
70 \def\MM{\copy\MMbox}
71 \newbox\MGbox % symbol for ->
72 \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
73 \def\MG{\copy\MGbox}
74 \def\MRL#1{\mathrel{\let\K==#1}}
75 %\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
76 \let\GG=\gg
77 \let\LL=\ll
78 \let\NULL=\Lambda
79 \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
80 \let\OR=\mid % bitwise or
81 \let\XOR=\oplus % bitwise exclusive or
82 \def\CM{{\sim}} % bitwise complement
83 \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
84 \def\MOD{\mathbin{\copy\MODbox}}
85 \def\DC{\kern.1em{::}\kern.1em} % symbol for ::
86 \def\PA{\mathbin{.*}} % symbol for .*
87 \def\MGA{\mathbin{\MG*}} % symbol for ->*
88 \def\this{\&{this}}
89
90 \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
91 \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
92
93 \newcount\ind % current indentation in ems
94 \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
95 \def\2{\global\advance\ind by-1} % indent one less notch
96 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
97 \def\4{\copy\bak} % backspace one notch
98 \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
99 \def\6{\ifmmode\else\par % forced break
100 \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
101 \def\7{\Y\6} % forced break and a little extra space
102 \def\8{\hskip-\ind em\hskip 2em} % no indentation
103
104 \newcount\gdepth % depth of current major group, plus one
105 \newcount\secpagedepth
106 \secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
107 \newtoks\gtitle % title of current major group
108 \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
109 \let\yskip=\smallskip
110 \def\?{\mathrel?}
111
112 % Some changes for pdftex
113 %\def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
114 \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~\pdfnote#2..\par}}
115 \pdfoutput=1
116 \pdfcompresslevel=9
117 \input pdfcolor
118
119 \newtoks\toksA
120 \newtoks\toksB
121 \newtoks\toksC
122 \newtoks\toksD
123 \newcount\countA
124 \countA=0
125 \def\pdfnote#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
126 \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
127 \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
128 \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
129 \def\maketoks{%
130 \expandafter\poptoks\the\toksA|ENDTOKS|
131 \ifx\first0\adn0
132 \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
133 \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
134 \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
135 \else
136 \ifnum0=\countA\else\makenote\fi
137 \ifx\first.\let\next=\done\else
138 \let\next=\maketoks
139 \addtokens{\toksB}{\the\toksD}
140 \ifx\first,\addtokens{\toksB}{\space}\fi
141 \fi
142 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
143 \next
144 }
145 \def\n#1{\pdfannotlink attr{/Border [0 0 0]} goto num #1
146 \BlueGreen #1\Black\pdfendlink}
147 \def\makenote{\addtokens{\toksB}%
148 {\noexpand\n{\the\toksC}}\toksC={}\global\countA=0}
149 \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
150 % End of pdftex changes
151
152 \def\lapstar{\rlap{*}}
153
154 % Some changes for pdftex
155 %\def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
156 % \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
157 % \noindent{\let\*=\lapstar\bf\secstar.\quad}}
158 \def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
159 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
160 \noindent{\let\*=\lapstar\bf\secstar.\quad}%
161 {\let\*=\empty\pdfdest num \secstar fitbh}}
162 % End of pdftex changes
163
164 \let\startsection=\stsec
165 \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
166 \def\A{\note{See also section}} % xref for doubly defined section name
167 \def\As{\note{See also sections}} % xref for multiply defined section name
168 \def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
169 \sfcode`;=3000
170 \pretolerance 10000
171 \hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
172 \exhyphenpenalty 10000
173 \global\ind=2 \1\ \unskip}
174 \def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
175 \let\SHC\C % "// short comments" treated like "/* ordinary comments */"
176 %\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
177 %\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
178 \def\D{\defin{\#define}} % macro definition
179 \let\E=\equiv % equivalence sign
180 \def\ET{ and~} % conjunction between two section numbers
181 \def\ETs{, and~} % conjunction between the last two of several section numbers
182 \def\F{\defin{format}} % format definition
183 \let\G=\ge % greater than or equal sign
184 % \H is long Hungarian umlaut accent
185 \let\I=\ne % unequal sign
186 \def\J{\.{@\&}} % TANGLE's join operation
187 \let\K== % assignment operator
188 %\let\K=\leftarrow % "honest" alternative to standard assignment operator
189 % \L is Polish letter suppressed-L
190 \outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
191 \vskip\intersecskip\startsection\ignorespaces}
192 \outer\def\N#1#2#3.{\gdepth=#1\gtitle={#3}\MN{#2}% beginning of starred section
193 \ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
194 \else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
195 \message{*\secno} % progress report
196 \edef\next{\write\cont{\ZZ{#3}{#1}{\secno}% write to contents file
197 {\noexpand\the\pageno}}}\next % \ZZ{title}{depth}{sec}{page}
198 \ifon\startsection{\bf#3.\quad}\ignorespaces}
199 \def\MN#1{\par % common code for \M, \N
200 {\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
201 \ifx\secno\secstar \onmaybe \else\ontrue \fi
202 \mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
203 % each \mark is {section reference or null}{depth plus 1}{group title}
204 % \O is Scandinavian letter O-with-slash
205 % \P is paragraph sign
206 \def\Q{\note{This code is cited in section}} % xref for mention of a section
207 \def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
208 \let\R=\lnot % logical not
209 % \S is section sign
210 \def\T#1{\leavevmode % octal, hex or decimal constant
211 \hbox{$\def\?{\kern.2em}%
212 \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant
213 \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
214 \let\~=\oct \let\^=\hex {#1}$}}
215 \def\U{\note{This code is used in section}} % xref for use of a section
216 \def\Us{\note{This code is used in sections}} % xref for uses of a section
217 \let\V=\lor % logical or
218 \let\W=\land % logical and
219
220 % Some changes for pdftex
221 %\def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
222 % \XX$\langle\,${#2\eightrm\kern.5em#1}$\,\rangle$\XX}
223 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
224 \XX$\langle\,${#2\eightrm\kern.5em\pdfnote#1.}$\,\rangle$\XX}
225 % End of pdftex changes
226
227 \def\Y{\par\yskip}
228 \let\Z=\le
229 \let\ZZ=\let % now you can \write the control sequence \ZZ
230 \let\*=*
231
232 %\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
233 %\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
234 \def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
235 \def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
236 \def\vb#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
237 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
238 \hrule}\vrule\kern2pt}} % verbatim string
239
240 \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
241 \newif\ifon \newif\iftitle \newif\ifpagesaved
242
243 \def\lheader{\mainfont\the\pageno\eightrm\qquad\grouptitle\hfill\title\qquad
244 \mainfont\topsecno} % top line on left-hand pages
245 \def\rheader{\mainfont\topsecno\eightrm\qquad\title\hfill\grouptitle
246 \qquad\mainfont\the\pageno} % top line on right-hand pages
247 \def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
248 \takethree\topmark}}
249 \def\topsecno{\expandafter\takeone\topmark}
250 \def\takeone#1#2#3{#1}
251 \def\taketwo#1#2#3{#2}
252 \def\takethree#1#2#3{#3}
253 \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
254
255 \let\page=\pagebody \raggedbottom
256 % \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
257 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
258 \shipout\vbox{
259 \vbox to\fullpageheight{
260 \iftitle\global\titlefalse
261 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
262 \vfill#1}} % parameter #1 is the page itself
263 \global\advance\pageno by1}
264
265 \gtitle={\.{CWEB} output} % this running head is reset by starred sections
266 \mark{\noexpand\nullsec0{\the\gtitle}}
267 \def\title{\expandafter\uppercase\expandafter{\jobname}}
268 \def\topofcontents{\centerline{\titlefont\title}\vskip.7in
269 \vfill} % this material will start the table of contents page
270 \def\botofcontents{\vfill
271 \centerline{\covernote}} % this material will end the table of contents page
272 \def\covernote{}
273 \def\contentspagenumber{0} % default page number for table of contents
274 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
275 \newdimen\pageheight \pageheight=8.7in % the height of each page
276 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
277 \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
278 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
279 \fullpageheight=9truein\setpage}
280 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
281 \def\contentsfile{\jobname.toc} % file that gets table of contents info
282 \def\readcontents{\input \contentsfile}
283 \def\readindex{\input \jobname.idx}
284 \def\readsections{\input \jobname.scn}
285
286 \newwrite\cont
287 \output{\setbox0=\page % the first page is garbage
288 \openout\cont=\contentsfile
289 \write\cont{\catcode `\noexpand\@=11\relax} % \makeatletter
290 \global\output{\normaloutput\page\lheader\rheader}}
291 \setpage
292 \vbox to \vsize{} % the first \topmark won't be null
293
294 \def\ch{\note{The following sections were changed by the change file:}
295 \let\*=\relax}
296 \newbox\sbox % saved box preceding the index
297 \newbox\lbox % lefthand column in the index
298 \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
299 \def\page{\box255 } \normalbottom
300 \write\cont{} % ensure that the contents file isn't empty
301 \write\cont{\catcode `\noexpand\@=12\relax} % \makeatother
302 \closeout\cont % the contents information has been fully gathered
303 \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
304 \global\setbox\sbox=\page \global\pagesavedtrue}
305 \pagesavedfalse \eject % eject the page-so-far and predecessors
306 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
307 \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
308 \hsize=.5\pagewidth \advance\hsize by -10pt
309 % column width for the index (20pt between cols)
310 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
311 \def\lr{L} % this tells whether the left or right column is next
312 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
313 \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
314 \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
315 \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
316 \message{Index:}
317 \parskip 0pt plus .5pt
318 %
319 % Some changes for pdftex
320 % \outer\def\I##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
321 \outer\def\I##1, {\par\hangindent2em\noindent##1:\kern1em\pdfnote} % index entry
322 % End of pdftex changes
323 %
324 \def\[##1]{$\underline{##1}$} % underlined index item
325 \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
326 \hyphenpenalty 10000 \parindent0pt
327 \readindex}
328 \def\fin{\par\vfill\eject % this is done when we are ending the index
329 \ifpagesaved\null\vfill\eject\fi % output a null index column
330 \if L\lr\else\null\vfill\eject\fi % finish the current page
331 \parfillskip 0pt plus 1fil
332 \def\grouptitle{NAMES OF THE SECTIONS}
333 \let\topsecno=\nullsec
334 \message{Section names:}
335 \output={\normaloutput\page\lheader\rheader}
336 \setpage
337 %
338 % Some changes for pdftex
339 % \def\note##1##2.{\quad{\eightrm##1~##2.}}
340 \def\note##1##2.{\quad{\eightrm##1~\pdfnote##2..}}
341 % End of pdftex changes
342 %
343 \def\Q{\note{Cited in section}} % crossref for mention of a section
344 \def\Qs{\note{Cited in sections}} % crossref for mentions of a section
345 \def\U{\note{Used in section}} % crossref for use of a section
346 \def\Us{\note{Used in sections}} % crossref for uses of a section
347 \def\I{\par\hangindent 2em}\let\*=*
348 \readsections}
349 \def\con{\par\vfill\eject % finish the section names
350 % \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
351 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
352 \setpage \output={\normaloutput\page\lheader\rheader}
353 \titletrue % prepare to output the table of contents
354 \pageno=\contentspagenumber
355 \def\grouptitle{TABLE OF CONTENTS}
356 \message{Table of contents:}
357 \topofcontents
358 \line{\hfil Section\hbox to3em{\hss Page}}
359 \let\ZZ=\contentsline
360 \readcontents\relax % read the contents info
361 \botofcontents \end} % print the contents page(s) and terminate
362 %
363 % Some changes for pdftex
364 %\def\contentsline#1#2#3#4{\ifnum#2=0 \smallbreak\fi
365 % \line{\consetup{#2}#1
366 % \rm\leaders\hbox to .5em{.\hfil}\hfil\ #3\hbox to3em{\hss#4}}}
367 \def\contentsline#1#2#3#4{\ifnum#2=0 \smallbreak\fi
368 \line{\consetup{#2}\pdfoutline goto num #3{#1}
369 \pdfannotlink attr{/Border [0 0 0]} goto num #3
370 \BlueGreen #1 \rm\leaders\hbox to .5em{.\hfil}\hfil\ #3\pdfendlink
371 \Black\hbox to3em{\hss#4}}}
372 \pdfcatalog pagemode{/UseOutlines}
373 % End of pdftex changes
374 %
375 \def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
376 \or % depth 0 (@*)
377 \or \hskip2em % depth 1 (@*1)
378 \or \hskip4em % depth 2 (@*2)
379 \or \hskip6em % depth 3 (@*3)
380 \or \hskip8em % depth 4 (@*4)
381 \or \hskip10em % depth 5 (@*5)
382 \else \hskip12em \fi} % depth 6 or more
383 \def\noinx{\let\inx=\end} % no indexes or table of contents
384 \def\nosecs{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
385 % no index of section names or table of contents
386 \def\nocon{\let\con=\end} % no table of contents
387 \def\today{\ifcase\month\or
388 January\or February\or March\or April\or May\or June\or
389 July\or August\or September\or October\or November\or December\fi
390 \space\number\day, \number\year}
391 \newcount\twodigits
392 \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
393 \multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
394 \def\gobbleone1{}
395 \def\printtwodigits{\advance\twodigits100
396 \expandafter\gobbleone\number\twodigits
397 \advance\twodigits-100 }
398 \def\TeX{{\ifmmode\it\fi
399 \leavevmode\hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
400 \def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
401 \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
402 \let\startsection=\stsec\stsec}}
403 % say `\datethis' in limbo, to get your listing timestamped before section 1
404 \def\datecontentspage{%
405 \def\topofcontents{\leftline{\sc\today\ at \hours}\bigskip
406 \centerline{\titlefont\title}\vfill}} % timestamps the contents page