Debian Codegraph @

texmf-dist/tex/plain/knuth-lib/webmac.tex

raw
1 % standard macros for WEB listings (in addition to PLAIN.TEX)
2 \xdef\fmtversion{\fmtversion+WEBMAC4.2} % identifies current set of macros
3 \parskip 0pt % no stretch between paragraphs
4 \parindent 1em % for paragraphs and for the first line of Pascal text
5
6 \font\eightrm=cmr8 \let\sc=\eightrm % NOT a caps-and-small-caps font!
7 \let\mainfont=\tenrm
8 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
9 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
10 \font\tentex=cmtex10 % TeX extended character set (used in strings)
11 \fontdimen7\tentex=0pt % no extra space after punctuation
12
13 \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
14 \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
15 \def\&#1{\hbox{\bf#1\/}} % boldface type for reserved words
16 \def\.#1{\hbox{\tentex % typewriter type for strings
17 \let\\=\BS % backslash in a string
18 \let\'=\RQ % right quote in a string
19 \let\`=\LQ % left quote in a string
20 \let\{=\LB % left brace in a string
21 \let\}=\RB % right brace in a string
22 \let\~=\TL % tilde in a string
23 \let\ =\SP % space in a string
24 \let\_=\UL % underline in a string
25 \let\&=\AM % ampersand in a string
26 #1}}
27 \def\#{\hbox{\tt\char`\#}} % parameter sign
28 \def\${\hbox{\tt\char`\$}} % dollar sign
29 \def\%{\hbox{\tt\char`\%}} % percent sign
30 \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
31 % circumflex accents can be obtained from \^^D instead of \^
32 \def\AT!{@} % at sign for control text
33
34 \chardef\AM=`\& % ampersand character in a string
35 \chardef\BS=`\\ % backslash in a string
36 \chardef\LB=`\{ % left brace in a string
37 \def\LQ{{\tt\char'22}} % left quote in a string
38 \chardef\RB=`\} % right brace in a string
39 \def\RQ{{\tt\char'23}} % right quote in a string
40 \def\SP{{\tt\char`\ }} % (visible) space in a string
41 \chardef\TL=`\~ % tilde in a string
42 \chardef\UL=`\_ % underline character in a string
43
44 \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
45 \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
46
47 \newcount\ind % current indentation in ems
48 \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
49 \def\2{\global\advance\ind by-1} % indent one less notch
50 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
51 \def\4{\copy\bak} % backspace one notch
52 \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
53 \def\6{\ifmmode\else\par % forced break
54 \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
55 \def\7{\Y\6} % forced break and a little extra space
56
57 \let\yskip=\smallskip
58 \def\to{\mathrel{.\,.}} % double dot, used only in math mode
59 \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
60 \def\lapstar{\rlap{*}}
61 \def\startsection{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
62 \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
63 \def\A{\note{See also section}} % crossref for doubly defined section name
64 \def\As{\note{See also sections}} % crossref for multiply defined section name
65 \def\B{\mathopen{\.{@\{}}} % begin controlled comment
66 \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % Pascal comments
67 \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
68 \def\D{\defin{define}} % macro definition
69 \def\E{\cdot10^} % exponent in floating point constant
70 \def\ET{ and~} % conjunction between two section numbers
71 \def\ETs{, and~} % conjunction between the last two of several section numbers
72 \def\F{\defin{format}} % format definition
73 \let\G=\ge % greater than or equal sign
74 \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
75 \let\I=\ne % unequal sign
76 \def\J{\.{@\&}} % TANGLE's join operation
77 \let\K=\gets % left arrow
78 \let\L=\le % less than or equal sign
79 \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
80 \vskip12ptminus3pt\startsection\ignorespaces}
81 \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
82 \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
83 \message{*\modno} % progress report
84 \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
85 \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
86 \def\MN#1.{\par % common code for \M, \N
87 {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}% remove \* from section name
88 \ifx\modno\modstar \onmaybe \else\ontrue \fi
89 \mark{{{\tensy x}\modno}{\rhead}}}
90 % each \mark is {section reference or null}{group title}
91 \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
92 \def\P{\rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
93 \sfcode`;=3000
94 \pretolerance 10000
95 \hyphenpenalty 10000 \exhyphenpenalty 10000
96 \global\ind=2 \1\ \unskip}
97 \def\Q{\rightskip=0pt % get out of Pascal mode
98 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
99 \let\R=\lnot % logical not
100 \let\S=\equiv % equivalence sign
101 \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
102 \def\U{\note{This code is used in section}} % crossref for use of a section
103 \def\Us{\note{This code is used in sections}} % crossref for uses of a section
104 \let\V=\lor % logical or
105 \let\W=\land % logical and
106 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
107 \XX$\langle\,$#2{\eightrm\kern.5em#1}$\,\rangle$\XX}
108 \def\Y{\par\yskip}
109 \let\Z=\let % now you can \send the control sequence \Z
110 \def\){\hbox{\.{@\$}}} % sign for string pool check sum
111 \def\]{\hbox{\.{@\\}}} % sign for forced line break
112 \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
113 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
114 \hrule}\vrule}\kern2pt} % verbatim string
115 \let\~=\ignorespaces
116 \let\*=*
117
118 \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
119 \newif\ifon \newif\iftitle \newif\ifpagesaved
120 \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead
121 \hfill\title\qquad\mainfont\topsecno} % top line on left-hand pages
122 \def\rheader{\mainfont\topsecno\eightrm\qquad\title\hfill
123 \rhead\qquad\mainfont\the\pageno} % top line on right-hand pages
124 \def\topsecno{\expandafter\takeone\topmark}
125 \def\takeone#1#2{#1}
126 \def\taketwo#1#2{#2}
127 \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
128 \def\page{\box255 }
129 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
130 \shipout\vbox{
131 \vbox to\fullpageheight{
132 \iftitle\global\titlefalse
133 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
134 \vfill#1}} % parameter #1 is the page itself
135 \global\advance\pageno by1}
136
137 \def\rhead{\.{WEB} OUTPUT} % this running head is reset by starred sections
138 \mark{\noexpand\nullsec{\rhead}}
139 \def\title{} % an optional title can be set by the user
140 \def\topofcontents{\centerline{\titlefont\title}
141 \vfill} % this material will start the table of contents page
142 \def\botofcontents{\vfill} % this material will end the table of contents page
143 \def\contentspagenumber{0} % default page number for table of contents
144 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
145 \newdimen\pageheight \pageheight=8.7in % the height of each page
146 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
147 \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
148 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
149 \fullpageheight=9truein\setpage}
150 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
151 \def\contentsfile{CONTENTS} % file that gets table of contents info
152 \def\readcontents{\input CONTENTS}
153
154 \newwrite\cont
155 \output{\setbox0=\page % the first page is garbage
156 \openout\cont=\contentsfile
157 \global\output{\normaloutput\page\lheader\rheader}}
158 \setpage
159 \vbox to \vsize{} % the first \topmark won't be null
160
161 \def\ch{\note{The following sections were changed by the change file:}
162 \let\*=\relax}
163 \newbox\sbox % saved box preceding the index
164 \newbox\lbox % lefthand column in the index
165 \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
166 \write\cont{} % ensure that the contents file isn't empty
167 \closeout\cont % the contents information has been fully gathered
168 \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
169 \global\setbox\sbox=\page \global\pagesavedtrue}
170 \pagesavedfalse \eject % eject the page-so-far and predecessors
171 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
172 \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
173 \hsize=.5\pagewidth \advance\hsize by -10pt
174 % column width for the index (20pt between cols)
175 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
176 \def\lr{L} % this tells whether the left or right column is next
177 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
178 \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
179 \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
180 \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
181 \message{Index:}
182 \parskip 0pt plus .5pt
183 \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
184 \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
185 \def\[##1]{$\underline{##1}$} % underlined index item
186 \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
187 \hyphenpenalty 10000 \parindent0pt}
188 \def\fin{\par\vfill\eject % this is done when we are ending the index
189 \ifpagesaved\null\vfill\eject\fi % output a null index column
190 \if L\lr\else\null\vfill\eject\fi % finish the current page
191 \parfillskip 0pt plus 1fil
192 \def\rhead{NAMES OF THE SECTIONS}
193 \let\topsecno=\nullsec
194 \message{Section names:}
195 \output{\normaloutput\page\lheader\rheader}
196 \setpage
197 \def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\eightrm##1~##2.}}
198 \linepenalty=10 % try to conserve lines
199 \def\U{\note{Used in section}} % crossref for use of a section
200 \def\Us{\note{Used in sections}} % crossref for uses of a section
201 \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry}
202 \def\con{\par\vfill\eject % finish the section names
203 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
204 \setpage
205 \output{\normaloutput\page\lheader\rheader}
206 \titletrue % prepare to output the table of contents
207 \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
208 \message{Table of contents:}
209 \topofcontents
210 \line{\hfil Section\hbox to3em{\hss Page}}
211 \def\Z##1##2##3{\line{\ignorespaces##1
212 \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
213 \readcontents\relax % read the contents info
214 \botofcontents \end} % print the contents page(s) and terminate