home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d551 / cweb.lha / CWeb / cweb2.lzh / cweb / cwebmac.tex < prev    next >
Text File  |  1990-12-14  |  11KB  |  248 lines

  1. % standard macros for WEB listings (in addition to PLAIN.TEX)
  2. % $Revision: 2.0$ % Don Knuth, July 1990
  3.  
  4. \parskip 0pt % no stretch between paragraphs
  5. \parindent 1em % for paragraphs and for the first line of C text
  6.  
  7. \font\ninerm=cmr9
  8. \let\mc=\ninerm % medium caps
  9. \def\Cee{{\mc C}}
  10. \def\UNIX{{\mc UNIX}}
  11. \font\eightrm=cmr8
  12. \let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
  13. \let\mainfont=\tenrm
  14. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  15. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  16. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  17. \fontdimen7\tentex=0pt % no double space after sentences
  18.  
  19. \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  20. \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
  21. \def\{\leavevmode\hbox{\bf
  22.   \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
  23.   #1\/\kern.05em}} % boldface type for reserved words
  24. \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
  25.   \let\\=\BS % backslash in a string
  26.   \let\{=\LB % left brace in a string
  27.   \let\}=\RB % right brace in a string
  28.   \let\~=\TL % tilde in a string
  29.   \let\ =\SP % space in a string
  30.   \let\_=\UL % underline in a string
  31.   \let\&=\AM % ampersand in a string
  32.   \let\^=\CF % circumflex in a string
  33.   #1}}
  34. \def\){\discretionary{\hbox{\tentex\BS}}{}{}}
  35. \def\AT{@} % at sign for control text
  36.  
  37. \chardef\AM=`\& % ampersand character in a string
  38. \chardef\BS=`\\ % backslash in a string
  39. \chardef\LB=`\{ % left brace in a string
  40. \chardef\RB=`\} % right brace in a string
  41. \def\SP{{\tt\char`\ }} % (visible) space in a string
  42. \chardef\TL=`\~ % tilde in a string
  43. \chardef\UL=`\_ % underline character in a string
  44. \chardef\CF=`\^ % circumflex character in a string
  45.  
  46. \newbox\PPbox % symbol for ++
  47. \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
  48. \def\PP{\copy\PPbox}
  49. \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
  50.  \kern-1pt\char0}\kern.5pt}
  51. \def\MM{\copy\MMbox}
  52. \newbox\MGbox % symbol for ->
  53. \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
  54. \def\MG{\copy\MGbox}
  55. \let\GG=\gg
  56. \let\LL=\ll
  57. \let\NULL=\Lambda
  58. \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
  59. \let\OR=\mid % bitwise or
  60. \let\XOR=\oplus % bitwise exclusive or
  61. \def\CM{{\sim}} % bitwise complement
  62. \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
  63. \def\MOD{\mathbin{\copy\MODbox}}
  64.  
  65. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  66. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  67.  
  68. \newcount\ind % current indentation in ems
  69. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  70. \def\2{\global\advance\ind by-1} % indent one less notch
  71. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  72. \def\4{\copy\bak} % backspace one notch
  73. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  74. \def\6{\ifmmode\else\par % forced break
  75.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  76. \def\7{\Y\6} % forced break and a little extra space
  77. \def\8{\hskip-\ind em\hskip 2em} % no indentation
  78.  
  79. \let\yskip=\smallskip
  80. \def\?{\mathrel?}
  81. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
  82. \def\lapstar{\rlap{*}}
  83. \def\stsec{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
  84. \let\startsection=\stsec
  85. \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
  86. \def\A{\note{See also section}} % xref for doubly defined section name
  87. \def\As{\note{See also sections}} % xref for multiply defined section name
  88. %\def\B{\mathopen{\.{@/\ast}}} % begin controlled comment
  89. \def\C#1{\5\5\quad$/\ast\,$#1$\,\ast/$}
  90. \def\D{\defin{\#define}} % macro definition
  91. \def\ET{ and~} % conjunction between two section numbers
  92. \def\ETs{, and~} % conjunction between the last two of several section numbers
  93. \def\F{\defin{format}} % format definition
  94. \let\G=\ge % greater than or equal sign
  95. \let\I=\ne % unequal sign
  96. \def\J{\.{@\&}} % TANGLE's join operation
  97. \let\K== % can be changed to left arrow, if desired
  98. \let\L=\le % less than or equal sign
  99. \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
  100.   \vskip12ptminus3pt\startsection\ignorespaces}
  101. \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
  102.   \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
  103.   \message{*\modno} % progress report
  104.   \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
  105.   \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
  106. \def\MN#1.{\par % common code for \M, \N
  107.   {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}
  108.   \ifx\modno\modstar \onmaybe \else\ontrue \fi \mark{\modno}}
  109. \def\O#1{\leavevmode % octal, hex or decimal constant
  110.   \hbox{${\def\?{\kern.2em}%
  111.   \def\${\ell}% long constant
  112.   \def\_{\cdot 10^{\aftergroup}}% power of ten
  113.   \def\~{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}}% octal
  114.   \def\^{\hbox{\rm\char"7D\tt\aftergroup}}#1}$}}% double quotes for hex constant
  115. \def\P{\rightskip=0pt plus 100pt minus 10pt % go into C mode
  116.   \sfcode`;=3000
  117.   \pretolerance 10000
  118.   \hyphenpenalty 9999 % so strings can be broken (a discretionary \ is inserted)
  119.   \exhyphenpenalty 10000
  120.   \global\ind=2 \1\ \unskip}
  121. \def\Q{\rightskip=0pt % get out of C mode
  122.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
  123. \let\R=\lnot % logical not
  124. \let\S=\equiv % equivalence sign
  125. %\def\T{\mathclose{\.{@\ast/}}} % terminate controlled comment
  126. \def\U{\note{This code is used in section}} % xref for use of a section
  127. \def\Us{\note{This code is used in sections}} % xref for uses of a section
  128. \let\V=\lor % logical or
  129. \let\W=\land % logical and
  130. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  131.   \XX$\langle\,${#2\eightrm\kern.5em#1}$\,\rangle$\XX}
  132. \def\Y{\par\yskip}
  133. \let\Z=\let % now you can \send the control sequence \Z
  134. \def\=#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
  135.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  136.       \hrule}\vrule\kern2pt}} % verbatim string
  137. \let\*=*
  138.  
  139. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  140. \newif\ifon \newif\iftitle \newif\ifpagesaved
  141. \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
  142.   \tensy x\mainfont\topmark} % top line on left-hand pages
  143. \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
  144.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  145. \def\page{\box255 }
  146. \def\normaloutput#1#2#3{\shipout\vbox{
  147.   \ifodd\pageno\hoffset=\pageshift\fi
  148.   \vbox to\fullpageheight{
  149.   \iftitle\global\titlefalse
  150.   \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  151.   \vfill#1}} % parameter #1 is the page itself
  152.   \global\advance\pageno by1}
  153.  
  154. \def\rhead{\.{CWEB} OUTPUT} % this running head is reset by starred sections
  155. \def\title{} % an optional title can be set by the user
  156. \def\topofcontents{\centerline{\titlefont\title}
  157.   \vfill} % this material will start the table of contents page
  158. \def\botofcontents{\vfill} % this material will end the table of contents page
  159. \def\contentspagenumber{0} % default page number for table of contents
  160. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  161. \newdimen\pageheight \pageheight=8.7in % the height of each page
  162. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  163. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  164. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  165.   \fullpageheight=9truein\setpage}
  166. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  167. \def\contentsfile{\jobname.toc} % file that gets table of contents info
  168. \def\readcontents{\input \jobname.toc}
  169.  
  170. \newwrite\cont
  171. \output{\setbox0=\page % the first page is garbage
  172.   \openout\cont=\contentsfile
  173.        \write\cont{\catcode `\noexpand\@=11\relax}   % \makeatletter
  174.   \global\output{\normaloutput\page\lheader\rheader}}
  175. \setpage
  176. \vbox to \vsize{} % the first \topmark won't be null
  177.  
  178. \def\ch{\note{The following sections were changed by the change file:}
  179.   \let\*=\relax}
  180. \newbox\sbox % saved box preceding the index
  181. \newbox\lbox % lefthand column in the index
  182. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  183.   \write\cont{} % ensure that the contents file isn't empty
  184.        \write\cont{\catcode `\noexpand\@=12\relax}   % \makeatother
  185.   \closeout\cont % the contents information has been fully gathered
  186.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  187.     \global\setbox\sbox=\page \global\pagesavedtrue}
  188.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  189.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  190.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  191.   \hsize=.5\pagewidth \advance\hsize by -10pt
  192.     % column width for the index (20pt between cols)
  193.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  194.   \def\lr{L} % this tells whether the left or right column is next
  195.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  196.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  197.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  198.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  199.   \message{Index:}
  200.   \parskip 0pt plus .5pt
  201.   \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  202.   \def\[##1]{$\underline{##1}$} % underlined index item
  203.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  204.   \hyphenpenalty 10000 \parindent0pt}
  205. \def\fin{\par\vfill\eject % this is done when we are ending the index
  206.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  207.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  208.   \parfillskip 0pt plus 1fil
  209.   \def\rhead{NAMES OF THE SECTIONS}
  210.   \message{Section names:}
  211.   \output{\normaloutput\page\lheader\rheader}
  212.   \setpage
  213.   \def\note##1##2.{\quad{\eightrm##1~##2.}}
  214.   \def\U{\note{Used in section}} % crossref for use of a section
  215.   \def\Us{\note{Used in sections}} % crossref for uses of a section
  216.   \def\:{\par\hangindent 2em}\let\*=*}
  217. \def\con{\par\vfill\eject % finish the section names
  218.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  219.   \setpage
  220.   \output{\normaloutput\page\lheader\rheader}
  221.   \titletrue % prepare to output the table of contents
  222.   \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
  223.   \message{Table of contents:}
  224.   \topofcontents
  225.   \line{\hfil Section\hbox to3em{\hss Page}}
  226.   \def\Z##1##2##3{\line{\ignorespaces##1
  227.     \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
  228.   \readcontents\relax % read the contents info
  229.   \botofcontents \end} % print the contents page(s) and terminate
  230. \def\noinx{\let\inx=\end} % no indexes or table of contents
  231. \def\nomods{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
  232.     % no index of module names or table of contents
  233. \def\nocon{\let\con=\end} % no table of contents
  234. \def\today{\ifcase\month\or
  235.   January\or February\or March\or April\or May\or June\or
  236.   July\or August\or September\or October\or November\or December\fi
  237.   \space\number\day, \number\year}
  238. \newcount\twodigits
  239. \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
  240.   \multiply\twodigits by-60 \advance\twodigits by\time \printtwodigits}
  241. \def\gobbleone1{}
  242. \def\printtwodigits{\advance\twodigits100
  243.   \expandafter\gobbleone\number\twodigits
  244.   \advance\twodigits-100 }
  245. \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
  246.   \let\startsection=\stsec\stsec}}
  247.   % say `\datethis' in limbo, to get your listing timestamped
  248.