Debian Codegraph @

texmf-dist/doc/bibtex/abstyles/docmac.doc

raw
1 % This is DOCMAC.DOC, Release 1 of 12 Aug 1991.
2 %---------------------------------------------------------
3 % This macro package is based on PROGDOC.DOC, which is
4 % (c) 1988 by J.Schrod. Put into the public domain.
5 % It is enhanced by incorporating some macros from WEBMAC.TEX to deal with
6 % header lines and a table of contents and offers some additional typesetting
7 % capabilities. The enhancements and changes are done by
8 % Hans-Hermann Bode ([email protected]).
9
10 %
11 % Macro package for the documentation of programs (and TeX macros)
12 % english version
13 %
14
15 % Version of the basic PROGDOC.DOC:
16 % first version (for ftp/Bitnet) (88-12-05)
17 %
18 % Release history of DOCMAC.DOC:
19 %
20 % Rel. Date Author Comment
21 % 1 12 Aug 1991 H2B First change file to PROGDOC.DOC.
22 %
23
24
25
26 % documented with itself...
27 \input docmac
28
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %
32 % local macros
33 %
34
35 \font\mc=cmr9 % for names like ASCII
36
37 \def\title{DOCMAC}
38
39
40 \def\topofcontents{\null\vfill
41 \centerline{\titlefont\title}
42 \bigskip
43 \centerline{Joachim Schrod}
44 \medskip
45 \centerline{Hans-Hermann Bode}
46 \vfill}
47
48 \def\botofcontents{\vfill
49 The macro package and the documentation was written initially by J.~Schrod
50 under the name \.{progdoc}. H.-H.~Bode enhanced the package with some stuff
51 from \.{webmac} and completed the documentation with material from the
52 ``\.{WEB} User Manual''; this makes up the chapter on
53 ``Formatting''---besides some minor changes in the remainder.
54 \par}
55
56 \def\WEB{{\tt WEB\/}}
57 \def\LaTeX{{\rm L\kern-.36em\raise.3ex\hbox{\sc a}\kern-.15em\TeX}}
58
59 %
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61
62
63
64
65
66 \chap Introduction.
67
68 \WEB{} systems allow the documentation of programs by supporting the
69 separation in program fragments which can be collected and rearranged
70 afterwards. This allows {\it top-down\/} programming as well as the
71 {\it bottom-up\/} design of programs. Each program fragment can be
72 documented, usually with \TeX{}. A disadvantadge is that \WEB{}
73 actually exists only for a few programming languages (Pascal, C,
74 Modula-2). Besides, building up \WEB{} systems for ``exotic''
75 programming languages like \TeX{} is very difficult.
76
77 This macro package was built to allow good documentation for programs
78 in languages for which \WEB{} doesn't exist. It separates a program
79 text in sections that can be documented. All sections, collected
80 sequentially, will result in the complete program. In every section
81 begin and end of the program part are marked with |\beginprog| and
82 |\endprog|, this program part will be formatted as it is input
83 (``verbatim'').
84
85 The separation of the sections is done in this version (which is based
86 on Plain~\TeX{}) by the macros |\chap| and |\sect|. But this can be
87 changed easily, e.g.\ for preparing the documentation with \LaTeX{}.
88 Then the last section group of this macro package must be omitted and
89 the rest must be realized as a style option.
90
91 In the documentation part of a section text pieces, e.g.\ names of
92 variables, can be inserted verbatim to demonstrate the connection to
93 the program text. These parts are included in vertical bars
94 (`{\tt\vbar}') while the vertical bar itself can be obtained by
95 |\origvert|.
96
97 This macro package does not offer the creation of an index because it is not
98 known which syntactical tokens the language has that should be mentioned in
99 an index. If you want a table of contents, just say |\contentspage| at the
100 end of your document (you need not put a |\bye| after that, |\contentspage|
101 does this for you). Some remarks about future enhancements which should be
102 done urgently are set in slanted type.
103
104
105 \sect We have to realize three parts: (1)~the formatting of rather
106 small verbatim texts in a line, (2)~the formatting of larger parts of
107 program and (3)~the document structuring elements for the separation
108 of the sections. Before we start we declare some shorthands for
109 category codes.
110
111 By declaring the at sign~(`|@|') as well as the underscore~`(|_|)' as
112 letters we can use them in our macros.
113 {\tolerance=10000
114 (I agree with D.~Knuth that |\identifier_several_words_long| is much
115 better readable than |\IdentifierSeveralWordsLong| and both are better
116 than |\pr@@@s|.)
117 With the at sign we can use the ``private'' Plain macros and with the
118 underscore we can make our own macros more readable. But as we have
119 to restore these category codes at the end of this macro file we store
120 their former values in the control sequences |\atcode| and |\uscode|.
121 This method is better than the usage of a group because not all macros
122 have to be defined global this way.
123 \par}
124
125 \beginprog
126 \chardef\escape=0
127 \chardef\letter=11
128 \chardef\other=12
129 %\chardef\active=13 % is defined in Plain already
130
131 \chardef\atcode=\catcode`\@
132 \chardef\uscode=\catcode`\_
133
134 \catcode`\@=\letter
135 \catcode`\_=\letter
136 \endprog
137
138
139
140
141 \chap Local Verbatim Formatting.
142
143 The main point of every verbatim formatting is the switching of the
144 character codes of all characters that have a special \TeX{} meaning.
145 This can be done with the control sequence |\dospecials| that applies
146 the control sequence |\do| to all special characters. Additionally,
147 every line is regarded as a paragraph without indentation. Between
148 two paragraphs, i.e.\ between two lines, no extra space is set.
149 Finally all blanks and tabular characters shall be obeyed and the
150 inter word space after sentence terminators shall not be enlarged.
151 The activation of the tabular characters with |\obeytabs| is
152 equivalent to |\obeyspaces| in {\tt plain.tex\/}.
153
154 Verbatim texts are set in monospace, we use (like in \WEB{}) the
155 character set with the extended {\mc ASCII}. For \LaTeX{} we would
156 have to add here |\ttex| to all size modifications like |\xpt|,
157 |\xiipt|, etc.
158
159 \beginprog
160 \font\tentex=cmtex10 % typewriter extended ASCII 10pt
161 \let\ttex=\tentex % only for PLAIN with base size 10pt
162
163 \def\setup_verbatim{%
164 \def\do##1{\catcode`##1\other}\dospecials
165 \parskip\z@skip \parindent\z@
166 \obeylines \obeyspaces \obeytabs \frenchspacing
167 \ttex
168 }
169
170 \let\tab=\space
171 \begingroup
172 \catcode`\^^I=\active% % Attention: no tabs!
173 \gdef\obeytabs{\catcode`\^^I=\active\def^^I{\tab}}
174 \global\let^^I=\tab% % if an active tab appears in a \write
175 \endgroup
176 \endprog
177
178 \sect After having saved the old meaning of `{\tt\vbar}' in
179 |\origvert| and after declaring |\vbar| as a synonym for the character
180 that has the code of a vertical bar in the actual font, the vertical
181 bar can be made active. Then we call |\setup_verbatim|. But the
182 newline characters shall not be processed, they shall be regarded like
183 blank space. This can be reached by defining |\par| as |\space|.
184
185 The next vertical bar in the input closes the group which becomes an
186 (unbreakable) |\hbox| then. The old meanings of the special
187 characters and of the vertical bar are restored and \TeX{} is in
188 normal (horizontal) mode again.
189
190 \beginprog
191 \let\origvert=|
192 \chardef\vbar=`\|
193
194 \catcode`\|=\active
195
196 \def|{%
197 \leavevmode
198 \hbox\bgroup
199 \let\par\space \setup_verbatim
200 \let|\egroup
201 }
202 \endprog
203
204
205
206
207 \chap Program Fragments in Verbatim.
208
209 We need macros to format the program fragments without any
210 linebreaking. Such a text area shall start with the macro
211 |\beginprog| and end with |\endprog|. The macro |\endprog| must stand
212 at the very beginning of a line and must be followed by white space
213 (blank, tab or newline character). After |\beginprog| as well as
214 after |\endprog| the rest of the line is ignored.
215
216 Two demands must be regarded: There should be no length restrictions
217 for the processed text, and the tabular characters should be expanded
218 so that this macro works on PC's and on VAXes, too.
219
220
221 \sect The implementation method is quite simple: We read the next
222 line, test, wether the end is reached (by comparing with |\endprog|)
223 and otherwise set the character actually read. Every character is
224 inspected and tabular characters are expanded.
225
226 Wether a line is set or wether the end of the processed area is
227 reached is indicated by the switch |\if@print|. At the beginning of
228 the |\beginprog| macro most settings are done with |\setup_verbatim|
229 (the vertical bar must be handled separately) and the rest of the line
230 is ignored. As everything is done within a group, the end of the
231 verbatim text can be processed by simply closing this group.
232
233 For the user it looks as if |\endprog| terminates the processing, but
234 it just serves for the identification of the end, the true processing
235 is done with the internal macro |\end_verbatim|.
236
237 \beginprog
238 \newif\if@print
239
240 \def\beginprog{%
241 \endgraf
242 \bigbreak
243 \begingroup
244 \setup_verbatim \catcode`\|\other
245 \@printtrue
246 \ignore_rest_line
247 }
248 \let\end_verbatim=\endgroup % internal command !
249 \endprog
250
251
252 \sect The first line is ignored, all the other lines are identified
253 with |\set_next_line| and processed with |\do_set|. This separation
254 in identification and processing allows that the line end character is
255 active in the definition only for a short time.
256
257 When a line is to be formatted, we first check with |\check_print|
258 wether it contains |\endprog|, otherwise it is printed with
259 |\print_char|. The printing must be done for every character
260 individually because we want to check for tabular characters; the
261 exact algorithm is described below. Here we just have to note that
262 |\print_char| is used with two parameters of which the second one is
263 finished with the token |\end_line|. The first parameter is the first
264 character of the line, the second parameter is the rest of the line.
265 If the line is empty, the argument of |\do_set| is empty, too; so the
266 activation of |\print_char| must be finished with two |\end_line|.
267 Then the first |\end_line| is the first argument for |\print_char| and
268 the second argument is empty. But if the line did contain something,
269 the second |\end_line| is evaluated, for this case it is defined as
270 |\relax|.
271
272 At last we call |\set_next_line| again to format the next line. If
273 the end is reached, i.e.\ if a line with |\endprog| was found,
274 |\set_next_line| is redefined as |\relax|. This can be done because
275 the original meaning is restored while closing the group with
276 |\end_verbatim|.
277
278 \beginprog
279 \begingroup
280 \obeylines% % ^^M is active! ==> every line must end with %
281 \gdef\ignore_rest_line#1^^M{\set_next_line}%
282 \gdef\set_next_line#1^^M{\do_set{#1}}%
283 \endgroup
284
285 \def\do_set#1{%
286 \endgraf
287 \check_print{#1}%
288 \if@print \indent \print_char#1\end_line\end_line
289 \else \let\set_next_line\end_verbatim
290 \fi
291 \set_next_line
292 }
293 \let\end_line=\relax
294 \endprog
295
296
297 \sect Before we look at the problem of formatting a line, we declare
298 |\check_print| that checks the end of the verbatim mode. We have to
299 do two things: we must split everything in front of the first blank
300 or tabular character and compare for identity with |\endprog|. The
301 splitting is easy because the line which is our first argument
302 contains blanks and tabulators as active characters. First we call
303 |\cut_at_tab| that demands a tabular character as separator for its
304 two pramenters so that everything in the line in front of the first
305 tabulator is part of the first parameter. If there is no tabular
306 character in the line, we append one so that the second parameter is
307 empty. The same trick is used to separate the part in front of the
308 first blank character from the resulting first part.
309
310 The check is done with |\do_check|. We use a separate macro here so
311 that we can indent it (in the following definition blanks are active!)
312
313 \beginprog
314 \begingroup
315 \obeyspaces\obeytabs
316 \gdef\check_print#1{\cut_at_tab#1^^I\end_line}
317 \gdef\cut_at_tab#1^^I#2\end_line{\check_first_part#1 \end_line}% blank !
318 \gdef\check_first_part#1 #2\end_line{\do_check{#1}}
319 \endgroup
320 \endprog
321
322
323 \sect |\do_check| compares the line with a sample line that is
324 available in |\@endverbatim|. During the definition of
325 |\@endverbatim| it must be cared for that the escape character `|\|'
326 is a printable character: A comparison with |\ifx| demands identical
327 category codes. As a temporary escape character we use the vertical
328 bar.
329
330 \beginprog
331 \def\do_check#1{%
332 \def\@line{#1}%
333 \ifx \@line\@endverbatim \@printfalse
334 \fi
335 }
336
337 {\catcode`\|=\escape \catcode`\\=\other % | is temporary escape char
338 |gdef|@endverbatim{\endprog} % sample line
339 } % here \endgroup can't be used
340 \endprog
341
342
343 \sect Now we can set a line: we start with the first character,
344 followed by the rest of the line. Each character is counted in
345 |\char_count|. At the beginning of a line |\char_count| is~1, this
346 is reset at the end of the line.
347
348 \goodbreak
349
350 \beginprog
351 \newcount\char_count \char_count\@ne
352
353 \def\print_char#1#2\end_line{%
354 \print_first_char{#1}%
355 \print_rest_of_line{#2}%
356 }
357 \endprog
358
359
360 \sect For each character that is set |\char_count| is incremented.
361 If a character is a tabulator, we set with |\print_tab| the fitting
362 amount of blank characters, otherwise the character itself. We must
363 compare the character that is stored in |\@char| with a macro of which
364 the ``first-level'' expansion is an active tabulator. For this case
365 we declare |\@tab|.
366
367 \beginprog
368 {\obeytabs\gdef\@tab{^^I}}
369
370 \def\print_first_char#1{%
371 \def\@char{#1}%
372 \advance \char_count\@ne
373 \ifx \@char\@tab \print_tab
374 \else \@char
375 \fi
376 }
377 \endprog
378
379
380 \sect If we want to fill the line with blank spaces up to the next
381 column with a number that can be divided by~8, we must be able to
382 compute the column number modulo~8, but \TeX{} has no modulo operator.
383 So we define the macro |\mod_viii| that computes its argument modulo~8
384 and returns the result in the counter |\count_mod_viii|. For the
385 computation we need the temporary counter |\count@|.
386
387 \beginprog
388 \newcount\count_mod_viii
389 \def\mod_viii#1{%
390 \count@ #1\relax \count_mod_viii\count@
391 \divide \count@ 8\relax
392 \multiply \count@ 8\relax
393 \advance \count_mod_viii -\count@
394 }
395 \endprog
396
397
398 \sect Now we can declare |\print_tab|. We must remember that
399 |\char_count| was incremented already, if we set only one blank
400 character the counter keeps untouched.
401
402 \beginprog
403 \def\print_tab{%
404 \loop \space \mod_viii\char_count
405 \ifnum \count_mod_viii>\z@
406 \advance \char_count\@ne
407 \repeat
408 }
409 \endprog
410
411
412 \sect If the rest of the line is empty, we are ready. |\char_count|
413 is reset to~1 for the next line.
414
415 Inside the |\else| part of |\ifx| |\print_char| should not be used
416 directly because this costs too much storage of \TeX{}. Instead we
417 set a control sequence |\next| that is processed afterwards, depending
418 on the result of the comparison. If there is still something to set,
419 we use |\print_char| again, otherwise a syntactically similar macro
420 that expands to |\relax|.
421
422 \beginprog
423 \def\print_rest_of_line#1{%
424 \def\@line{#1}%
425 \ifx \@line\empty \char_count\@ne
426 \def\next##1\end_line{\relax}%
427 \else \let\next\print_char
428 \fi
429 \next#1\end_line
430 }
431 \endprog
432
433
434
435
436 \chap Document Structuring.
437
438 The layout of the document shall be like in \WEB{}. This can be done
439 easily in Plain. If \LaTeX{} shall be used for the document
440 preparation, this part of the macro must be eliminated. It will also
441 be better to include the program parts \LaTeX-like as an environment
442 between |\begin{prog}| and |\end{prog}| and to define control
443 sequences |\makebaractive| and |\makebarother| for the switch of the
444 special meaning of the vertical bar (`{\tt \origvert\/}') (for the
445 {\tt tabular\/} environment!)
446
447 All sections are enumerated, the number of the next section is stored
448 in the counter |\sectno|. We differenciate between main sections
449 which start a group of sections and between normal sections within a
450 group.
451
452 \beginprog
453 \newcount\sectno \sectno=\@ne
454 \endprog
455
456
457 \sect The main sections are started with the macro |\chap| that has
458 one parameter, the title of the section group. This parameter must be
459 terminated by a dot. We start a new page, typeset the title in bold
460 face and separate it from the section text with a |\medskip|. This
461 text, the documentation part of the section, is formatted without
462 paragraph indentation.
463
464 The deletion of the paragraph indentation is done with |\everypar|.
465 We do not care if |\everypar| is used for something else and delete it
466 after usage.
467
468 The section number is marked to appear {\it via\/} |\topmark| in the
469 headline, the title goes as a running head into the headline too. The
470 section number is displayed on the terminal as a progress report, and title,
471 section and page number are recorded in the contents file.
472
473 \begingroup \sl
474 The dealing with |\everypar| should not be so cruel.
475 \endgroup
476
477 \beginprog
478 \def\chap#1.{%
479 \mark{\number\sectno}
480 \endgraf
481 \vfill\eject
482 \def\rhead{\uppercase{\ignorespaces#1}} % define running headline
483 \message{*\number\sectno} % progress report
484 \let\Z=\let % now you can \send the control sequence \Z
485 \edef\next{\write\cont{\Z{#1}{\number\sectno}{\the\pageno}}}\next % to contents file
486 \noindent {\bf \number\sectno.\quad #1.}%
487 \advance \sectno\@ne
488 \endgraf
489 \medskip \nobreak
490 \everypar{%
491 \setbox0\lastbox
492 \global\everypar{}%
493 }%
494 }
495 \endprog
496
497
498 \sect Normal sections are started with |\sect|. This macro has no
499 parameter. Between two paragraphs we set 2~pica space (if possible)
500 and prefer the page breaking. Between the section number and the text
501 one quad of space is set.
502
503 \begingroup \sl
504 The page break manipulation could be more sophisticated.
505 \endgroup
506
507 \beginprog
508 \def\sect{%
509 \mark{\number\sectno}
510 \endgraf
511 \vskip 2pc plus 1pc minus 6dd \goodbreak
512 \noindent {\bf \number\sectno.}\advance \sectno\@ne
513 \quad \ignorespaces
514 }
515 \endprog
516
517
518 \chap Formatting.
519 The macros in this chapter are extracted from \.{WEBMAC.TEX}, while most of
520 the documentation is taken from Appendix~G of the ``\.{WEB} User Manual''.
521 The macros in \.{docmac} make it possible to produce a variety of formats,
522 and the purpose of this appendix is to explain some of the possibilities.
523 Displayed examples, that are included in the documentation, come out centered
524 to distinguish them from program text, which is flushleft.
525
526 \def\lpile{\def\cr{\hfill\endline}\matrix} % I [D E Knuth] only use \lpile by itself
527
528 \sect We begin the formatting part with some declarations that should make
529 look the output a little better for documenting programs.
530
531 \beginprog
532 \parskip 0pt % no stretch between paragraphs
533 \parindent 1em % for paragraphs and for the first line of Pascal text
534 \endprog
535
536 \sect Three fonts have been declared in addition to the standard fonts of
537 \.{PLAIN} format: You can say `\.{\{\\sc stuff\}}' to get {\sc stuff}
538 in small caps; and you can select the largish fonts \.{\\titlefont}
539 and \.{\\ttitlefont} in the title of your document, where \.{\\ttitlefont}
540 is a typewriter style of type.
541
542 \beginprog
543 \font\eightrm=cmr8
544 \font\sc=cmcsc10 % this IS a caps-and-small-caps font!
545 \let\mainfont=\tenrm
546 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
547 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
548 %\font\tentex=cmtex10 % TeX extended character set (used in strings)
549 % already defined above
550 \fontdimen7\tentex=0pt % no extra space after punctuation
551 \endprog
552
553 \sect You can say `\.{\\\\\{identifier\}}' to set \\{identifier} in
554 italics.
555
556 To get typewriter-like type, as when referring to `\.{WEB}', you
557 can use the `\.{\\.}' macro (e.g., `\.{\\.\{WEB\}}'). In the argument to
558 this macro you should insert an additional backslash before the symbols
559 listed below, i.e.,
560 before backslashes and dollar signs and the like.
561 A `\.{\\\ }' here will result in the visible space symbol; to get an
562 invisible space following a control sequence you can say `\.{\{\ \}}'.
563
564 \beginprog
565 \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
566 \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
567 \def\&#1{\hbox{\bf#1\/}} % boldface type for reserved words
568 \def\.#1{\hbox{\tentex % typewriter type for strings
569 \let\\=\BS % backslash in a string
570 \let\'=\RQ % right quote in a string
571 \let\`=\LQ % left quote in a string
572 \let\{=\LB % left brace in a string
573 \let\}=\RB % right brace in a string
574 \let\~=\TL % tilde in a string
575 \let\ =\SP % space in a string
576 \let\_=\UL % underline in a string
577 \let\&=\AM % ampersand in a string
578 #1}}
579 \def\#{\hbox{\tt\char`\#}} % parameter sign
580 \def\${\hbox{\tt\char`\$}} % dollar sign
581 \def\%{\hbox{\tt\char`\%}} % percent sign
582 \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
583 % circumflex accents can be obtained from \^^D instead of \^
584 \def\AT!{@} % at sign for control text
585
586 \chardef\AM=`\& % ampersand character in a string
587 \chardef\BS=`\\ % backslash in a string
588 \chardef\LB=`\{ % left brace in a string
589 \def\LQ{{\tt\char'22}} % left quote in a string
590 \chardef\RB=`\} % right brace in a string
591 \def\RQ{{\tt\char'23}} % right quote in a string
592 \def\SP{{\tt\char`\ }} % (visible) space in a string
593 \chardef\TL=`\~ % tilde in a string
594 \chardef\UL=`\_ % underline character in a string
595 \endprog
596
597 \sect The three control sequences \.{\\pagewidth}, \.{\\pageheight},
598 and \.{\\fullpageheight} can be redefined in the limbo section at the
599 beginning of your source file, to change the dimensions of each page.
600 The standard settings
601 $$\lpile{\.{\\pagewidth=6.5in}\cr
602 \.{\\pageheight=8.7in}\cr
603 \.{\\fullpageheight=9in}\cr}$$
604 were used to prepare the present report; \.{\\fullpageheight} is
605 \.{\\pageheight} plus room for the additional heading and page numbers at
606 the top of each page. If you change any of these quantities, you should
607 call the macro \.{\\setpage} immediately after making the change.
608
609 The \.{\\pageshift} macro defines an amount by which right-hand
610 pages (i.e., odd-numbered pages) are shifted right with respect to
611 left-hand (even-numbered) ones. By adjusting this amount you may be
612 able to get two-sided output in which the page numbers line up on
613 opposite sides of each sheet.
614
615 \beginprog
616 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
617 \newdimen\pageheight \pageheight=8.7in % the height of each page
618 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
619 \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
620 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
621 \fullpageheight=9truein\setpage}
622 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
623 \endprog
624
625 \sect The \.{\\title} macro will appear at the top of each page
626 in small caps. For example, this document was produced after saying
627 `\.{\\def\\title\{DOCMAC\}}'.
628
629 \beginprog
630 \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
631 \tensy x\mainfont\topmark} % top line on left-hand pages
632 \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
633 \qquad\mainfont\the\pageno} % top line on right-hand pages
634 \def\page{\box255 }
635 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
636 \shipout\vbox{
637 \vbox to\fullpageheight{
638 \iftitle\global\titlefalse
639 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
640 \vfill#1}} % parameter #1 is the page itself
641 \global\advance\pageno by1}
642
643 \def\rhead{\.{DOCMAC} OUTPUT} % this running head is reset by starred sections
644 \def\title{} % an optional title can be set by the user
645 \endprog
646
647 \sect The first page usually is assigned page number 1.
648 To start on page 16, with contents
649 on page 15, say this: `\.{\\def\\contentspagenumber\{15\}}
650 \.{\\pageno=\\contentspagenumber} \.{\\advance\\pageno by 1}'.
651
652 \beginprog
653 \def\contentspagenumber{0} % default page number for table of contents
654 \endprog
655
656 \sect The macro \.{\\iftitle} will suppress the header line if it is
657 defined by `\.{\\titletrue}'. The normal value is \.{\\titlefalse}
658 except for the table of contents; thus, the contents
659 page is usually unnumbered.
660
661 Two macros are provided to give flexibility to the table of
662 contents: \.{\\topofcontents} is invoked just before the contents
663 info is read, and \.{\\botofcontents} is invoked just after.
664 For example, you can define:
665 $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
666 \.{ { }\\titlefalse \% include headline on the contents page}\cr
667 \.{ { }\\def\\rheader\{\\mainfont Appendix D\\hfil 15\}}\cr
668 \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
669 \.{ { }\\vskip 15pt \\centerline\{(Version 4)\}{ }\\vfill\}}\cr}$$
670 Redefining \.{\\rheader}, which is the headline for right-hand pages,
671 suffices in this case to put the desired information at the top of the
672 contents page.
673
674 \beginprog
675 \newif\iftitle
676
677 \def\topofcontents{\centerline{\titlefont\title}
678 \vfill} % this material will start the table of contents page
679 \def\botofcontents{\vfill} % this material will end the table of contents page
680 \endprog
681
682 \sect Data for the table of contents is written to a file that
683 is read when |\contentspage| is called; there's one line of data
684 for every starred module. For example, when this document was being created, a
685 file \.{DOCMAC.TOC} containing
686 $$\lpile{\.{\\Z \{{ }Introduction\}\{1\}\{1\}}\cr
687 \.{\\Z \{{ }Local Verbatim Formatting\}\{3\}\{2\}}\cr}$$
688 and similar lines was created. The \.{\\topofcontents} macro could
689 redefine \.{\\Z} so that the information appears in another format.
690
691 \beginprog
692 \def\contentsfile{\jobname.toc} % file that gets table of contents info
693 \def\readcontents{\expandafter\input \contentsfile}
694
695 \newwrite\cont
696 \output{\setbox0=\page % the first page is garbage
697 \openout\cont=\contentsfile
698 \global\output{\normaloutput\page\lheader\rheader}}
699 \setpage
700 \vbox to \vsize{} % the first \topmark won't be null
701
702 \def\con{%
703 \write\cont{} % ensure that the contents file isn't empty
704 \closeout\cont % the contents information has been fully gathered
705 \par\vfill\eject % finish the preceding page
706 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
707 \setpage
708 \output{\normaloutput\page\lheader\rheader}
709 \titletrue % prepare to output the table of contents
710 \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
711 \message{Table of contents:}
712 \topofcontents
713 \line{\hfil Section\hbox to3em{\hss Page}}
714 \def\Z##1##2##3{\line{\ignorespaces##1
715 \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
716 \readcontents\relax % read the contents info
717 \botofcontents \end} % print the contents page(s) and terminate
718 \let\contentspage=\con
719 \endprog
720
721 \sect Sometimes it is necessary or desirable to divide the output of
722 \.{docmac} into subfiles that can be processed separately. For example,
723 the listing of \TeX\ runs to more than 500 pages, and that is enough to
724 exceed the capacity of many printing devices and/or their software.
725 When an extremely large job isn't cut into smaller pieces, the entire
726 process might be spoiled by a single error of some sort, making it
727 necessary to start everything over.
728
729 Here's a safe way to break a docmac'ed file into three parts:
730 Say the pieces are $\alpha$,
731 $\beta$, and $\gamma$, where each piece begins with a starred module.
732 All macros should be defined in the opening limbo section of $\alpha$,
733 and copies of this \TeX\ code should be placed at the
734 beginning of $\beta$ and of $\gamma$. In order to process the parts
735 separately, we need to take care of two things: The starting page
736 numbers of $\beta$ and $\gamma$ need to be set up properly, and
737 the table of contents data from all three runs needs to be
738 accumulated.
739
740 The \.{docmac} macros include two control sequences \.{\\contentsfile} and
741 \.{\\readcontents} that facilitate the necessary processing. We include
742 `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of~$\alpha$, we
743 include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of~$\beta$,
744 and we include `\.{\\def\\contentsfile\{CONT3\}}' in the limbo section
745 of~$\gamma$; this causes \TeX\ to write the contents data for
746 $\alpha$,~$\beta$, and~$\gamma$ into \.{CONT1.TEX}, \.{CONT2.TEX}, and
747 \.{CONT3.TEX}. Now in~$\gamma$ we say $$\.{\\def\\readcontents\{\\input CONT1
748 \\input CONT2 \\input CONT3\}};$$ this brings in the data from all three
749 pieces, in the proper order.
750
751 However, we still need to solve the page-numbering problem. One way to
752 do it is to include the following in the limbo material for $\beta$:
753 $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
754 \.{\\read -1 to \\temp \\pageno=\\temp \\advance\\pageno by 1}\cr}$$
755 Then you simply provide the necessary data when \TeX\ requests
756 it; a similar construction is used at the beginning of $\gamma$.
757
758 This method can, of course, be used to divide a docmac'ed file into
759 any number of pieces.
760
761 \sect The counter \.{\\sectno} is set to the number of the
762 module being typeset.
763
764 \sect We are finished and just have to restore the category codes.
765
766 \beginprog
767 \catcode`\@=\atcode
768 \catcode`\_=\uscode
769
770 \endinput
771 \endprog
772
773
774
775
776
777 \contentspage
778