| 1 |
\chardef\escape=0 |
| 2 |
\chardef\letter=11 |
| 3 |
\chardef\other=12 |
| 4 |
%\chardef\active=13 % is defined in Plain already |
| 5 |
|
| 6 |
\chardef\atcode=\catcode`\@ |
| 7 |
\chardef\uscode=\catcode`\_ |
| 8 |
|
| 9 |
\catcode`\@=\letter |
| 10 |
\catcode`\_=\letter |
| 11 |
\font\tentex=cmtex10 % typewriter extended ASCII 10pt |
| 12 |
\let\ttex=\tentex % only for PLAIN with base size 10pt |
| 13 |
|
| 14 |
\def\setup_verbatim{% |
| 15 |
\def\do##1{\catcode`##1\other}\dospecials |
| 16 |
\parskip\z@skip \parindent\z@ |
| 17 |
\obeylines \obeyspaces \obeytabs \frenchspacing |
| 18 |
\ttex |
| 19 |
} |
| 20 |
|
| 21 |
\let\tab=\space |
| 22 |
\begingroup |
| 23 |
\catcode`\^^I=\active% % Attention: no tabs! |
| 24 |
\gdef\obeytabs{\catcode`\^^I=\active\def^^I{\tab}} |
| 25 |
\global\let^^I=\tab% % if an active tab appears in a \write |
| 26 |
\endgroup |
| 27 |
\let\origvert=| |
| 28 |
\chardef\vbar=`\| |
| 29 |
|
| 30 |
\catcode`\|=\active |
| 31 |
|
| 32 |
\def|{% |
| 33 |
\leavevmode |
| 34 |
\hbox\bgroup |
| 35 |
\let\par\space \setup_verbatim |
| 36 |
\let|\egroup |
| 37 |
} |
| 38 |
\newif\if@print |
| 39 |
|
| 40 |
\def\beginprog{% |
| 41 |
\endgraf |
| 42 |
\bigbreak |
| 43 |
\begingroup |
| 44 |
\setup_verbatim \catcode`\|\other |
| 45 |
\@printtrue |
| 46 |
\ignore_rest_line |
| 47 |
} |
| 48 |
\let\end_verbatim=\endgroup % internal command ! |
| 49 |
\begingroup |
| 50 |
\obeylines% % ^^M is active! ==> every line must end with % |
| 51 |
\gdef\ignore_rest_line#1^^M{\set_next_line}% |
| 52 |
\gdef\set_next_line#1^^M{\do_set{#1}}% |
| 53 |
\endgroup |
| 54 |
|
| 55 |
\def\do_set#1{% |
| 56 |
\endgraf |
| 57 |
\check_print{#1}% |
| 58 |
\if@print \indent \print_char#1\end_line\end_line |
| 59 |
\else \let\set_next_line\end_verbatim |
| 60 |
\fi |
| 61 |
\set_next_line |
| 62 |
} |
| 63 |
\let\end_line=\relax |
| 64 |
\begingroup |
| 65 |
\obeyspaces\obeytabs |
| 66 |
\gdef\check_print#1{\cut_at_tab#1^^I\end_line} |
| 67 |
\gdef\cut_at_tab#1^^I#2\end_line{\check_first_part#1 \end_line}% blank ! |
| 68 |
\gdef\check_first_part#1 #2\end_line{\do_check{#1}} |
| 69 |
\endgroup |
| 70 |
\def\do_check#1{% |
| 71 |
\def\@line{#1}% |
| 72 |
\ifx \@line\@endverbatim \@printfalse |
| 73 |
\fi |
| 74 |
} |
| 75 |
|
| 76 |
{\catcode`\|=\escape \catcode`\\=\other % | is temporary escape char |
| 77 |
|gdef|@endverbatim{\endprog} % sample line |
| 78 |
} % here \endgroup can't be used |
| 79 |
\newcount\char_count \char_count\@ne |
| 80 |
|
| 81 |
\def\print_char#1#2\end_line{% |
| 82 |
\print_first_char{#1}% |
| 83 |
\print_rest_of_line{#2}% |
| 84 |
} |
| 85 |
{\obeytabs\gdef\@tab{^^I}} |
| 86 |
|
| 87 |
\def\print_first_char#1{% |
| 88 |
\def\@char{#1}% |
| 89 |
\advance \char_count\@ne |
| 90 |
\ifx \@char\@tab \print_tab |
| 91 |
\else \@char |
| 92 |
\fi |
| 93 |
} |
| 94 |
\newcount\count_mod_viii |
| 95 |
\def\mod_viii#1{% |
| 96 |
\count@ #1\relax \count_mod_viii\count@ |
| 97 |
\divide \count@ 8\relax |
| 98 |
\multiply \count@ 8\relax |
| 99 |
\advance \count_mod_viii -\count@ |
| 100 |
} |
| 101 |
\def\print_tab{% |
| 102 |
\loop \space \mod_viii\char_count |
| 103 |
\ifnum \count_mod_viii>\z@ |
| 104 |
\advance \char_count\@ne |
| 105 |
\repeat |
| 106 |
} |
| 107 |
\def\print_rest_of_line#1{% |
| 108 |
\def\@line{#1}% |
| 109 |
\ifx \@line\empty \char_count\@ne |
| 110 |
\def\next##1\end_line{\relax}% |
| 111 |
\else \let\next\print_char |
| 112 |
\fi |
| 113 |
\next#1\end_line |
| 114 |
} |
| 115 |
\newcount\sectno \sectno=\@ne |
| 116 |
\def\chap#1.{% |
| 117 |
\mark{\number\sectno} |
| 118 |
\endgraf |
| 119 |
\vfill\eject |
| 120 |
\def\rhead{\uppercase{\ignorespaces#1}} % define running headline |
| 121 |
\message{*\number\sectno} % progress report |
| 122 |
\let\Z=\let % now you can \send the control sequence \Z |
| 123 |
\edef\next{\write\cont{\Z{#1}{\number\sectno}{\the\pageno}}}\next % to contents file |
| 124 |
\noindent {\bf \number\sectno.\quad #1.}% |
| 125 |
\advance \sectno\@ne |
| 126 |
\endgraf |
| 127 |
\medskip \nobreak |
| 128 |
\everypar{% |
| 129 |
\setbox0\lastbox |
| 130 |
\global\everypar{}% |
| 131 |
}% |
| 132 |
} |
| 133 |
\def\sect{% |
| 134 |
\mark{\number\sectno} |
| 135 |
\endgraf |
| 136 |
\vskip 2pc plus 1pc minus 6dd \goodbreak |
| 137 |
\noindent {\bf \number\sectno.}\advance \sectno\@ne |
| 138 |
\quad \ignorespaces |
| 139 |
} |
| 140 |
\parskip 0pt % no stretch between paragraphs |
| 141 |
\parindent 1em % for paragraphs and for the first line of Pascal text |
| 142 |
\font\eightrm=cmr8 |
| 143 |
\font\sc=cmcsc10 % this IS a caps-and-small-caps font! |
| 144 |
\let\mainfont=\tenrm |
| 145 |
\font\titlefont=cmr7 scaled\magstep4 % title on the contents page |
| 146 |
\font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title |
| 147 |
%\font\tentex=cmtex10 % TeX extended character set (used in strings) |
| 148 |
% already defined above |
| 149 |
\fontdimen7\tentex=0pt % no extra space after punctuation |
| 150 |
\def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers |
| 151 |
\def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way |
| 152 |
\def\{\hbox{\bf#1\/}} % boldface type for reserved words |
| 153 |
\def\.#1{\hbox{\tentex % typewriter type for strings |
| 154 |
\let\\=\BS % backslash in a string |
| 155 |
\let\'=\RQ % right quote in a string |
| 156 |
\let\`=\LQ % left quote in a string |
| 157 |
\let\{=\LB % left brace in a string |
| 158 |
\let\}=\RB % right brace in a string |
| 159 |
\let\~=\TL % tilde in a string |
| 160 |
\let\ =\SP % space in a string |
| 161 |
\let\_=\UL % underline in a string |
| 162 |
\let\&=\AM % ampersand in a string |
| 163 |
#1}} |
| 164 |
\def\#{\hbox{\tt\char`\#}} % parameter sign |
| 165 |
\def\${\hbox{\tt\char`\$}} % dollar sign |
| 166 |
\def\%{\hbox{\tt\char`\%}} % percent sign |
| 167 |
\def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat |
| 168 |
% circumflex accents can be obtained from \^^D instead of \^ |
| 169 |
\def\AT!{@} % at sign for control text |
| 170 |
|
| 171 |
\chardef\AM=`\& % ampersand character in a string |
| 172 |
\chardef\BS=`\\ % backslash in a string |
| 173 |
\chardef\LB=`\{ % left brace in a string |
| 174 |
\def\LQ{{\tt\char'22}} % left quote in a string |
| 175 |
\chardef\RB=`\} % right brace in a string |
| 176 |
\def\RQ{{\tt\char'23}} % right quote in a string |
| 177 |
\def\SP{{\tt\char`\ }} % (visible) space in a string |
| 178 |
\chardef\TL=`\~ % tilde in a string |
| 179 |
\chardef\UL=`\_ % underline character in a string |
| 180 |
\newdimen\pagewidth \pagewidth=6.5in % the width of each page |
| 181 |
\newdimen\pageheight \pageheight=8.7in % the height of each page |
| 182 |
\newdimen\fullpageheight \fullpageheight=9in % page height including headlines |
| 183 |
\newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones |
| 184 |
\def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein |
| 185 |
\fullpageheight=9truein\setpage} |
| 186 |
\def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size |
| 187 |
\def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad |
| 188 |
\tensy x\mainfont\topmark} % top line on left-hand pages |
| 189 |
\def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead |
| 190 |
\qquad\mainfont\the\pageno} % top line on right-hand pages |
| 191 |
\def\page{\box255 } |
| 192 |
\def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi |
| 193 |
\shipout\vbox{ |
| 194 |
\vbox to\fullpageheight{ |
| 195 |
\iftitle\global\titlefalse |
| 196 |
\else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi |
| 197 |
\vfill#1}} % parameter #1 is the page itself |
| 198 |
\global\advance\pageno by1} |
| 199 |
|
| 200 |
\def\rhead{\.{DOCMAC} OUTPUT} % this running head is reset by starred sections |
| 201 |
\def\title{} % an optional title can be set by the user |
| 202 |
\def\contentspagenumber{0} % default page number for table of contents |
| 203 |
\newif\iftitle |
| 204 |
|
| 205 |
\def\topofcontents{\centerline{\titlefont\title} |
| 206 |
\vfill} % this material will start the table of contents page |
| 207 |
\def\botofcontents{\vfill} % this material will end the table of contents page |
| 208 |
\def\contentsfile{\jobname.toc} % file that gets table of contents info |
| 209 |
\def\readcontents{\expandafter\input \contentsfile} |
| 210 |
|
| 211 |
\newwrite\cont |
| 212 |
\output{\setbox0=\page % the first page is garbage |
| 213 |
\openout\cont=\contentsfile |
| 214 |
\global\output{\normaloutput\page\lheader\rheader}} |
| 215 |
\setpage |
| 216 |
\vbox to \vsize{} % the first \topmark won't be null |
| 217 |
|
| 218 |
\def\con{% |
| 219 |
\write\cont{} % ensure that the contents file isn't empty |
| 220 |
\closeout\cont % the contents information has been fully gathered |
| 221 |
\par\vfill\eject % finish the preceding page |
| 222 |
\rightskip 0pt \hyphenpenalty 50 \tolerance 200 |
| 223 |
\setpage |
| 224 |
\output{\normaloutput\page\lheader\rheader} |
| 225 |
\titletrue % prepare to output the table of contents |
| 226 |
\pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS} |
| 227 |
\message{Table of contents:} |
| 228 |
\topofcontents |
| 229 |
\line{\hfil Section\hbox to3em{\hss Page}} |
| 230 |
\def\Z##1##2##3{\line{\ignorespaces##1 |
| 231 |
\leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}} |
| 232 |
\readcontents\relax % read the contents info |
| 233 |
\botofcontents \end} % print the contents page(s) and terminate |
| 234 |
\let\contentspage=\con |
| 235 |
\catcode`\@=\atcode |
| 236 |
\catcode`\_=\uscode |
| 237 |
|
| 238 |
\endinput |