Debian Codegraph @

texk/web2c/doc/webman.tex

raw
1 % WEB user manual -- last updated by D E Knuth on 4 Dec 89
2 \input webmac
3 \parskip 0pt plus 1pt
4 \def\RA{\char'31 } % right arrow
5 \def\hang{\hangindent 4em\ignorespaces}
6 \font\ninerm=cmr9
7 \font\ninett=cmtt9
8 \font\eighttt=cmtt8
9 \let\mc=\ninerm % medium caps for names like SAIL
10 \def\PASCAL{Pascal}
11 \font\quoterm=cmssq8
12 \font\quoteit=cmssqi8
13 \def\pb{\.{|...|}}
14 \def\lpile{\def\cr{\hfill\endline}\matrix} % I only use \lpile by itself
15
16 \outer\def\section #1.{\penalty-50\vskip 12pt plus 3pt minus 3pt
17 \noindent{\bf #1.}\quad\ignorespaces}
18
19 \def\lheader{\mainfont\the\pageno\hfill\sc\runninghead\hfill}
20 \def\rheader{\hfill\sc\runninghead\hfill\mainfont\the\pageno}
21 \def\runninghead{{\tentt WEB} USER MANUAL}
22
23 % This verbatim mode assumes that no ? appears in the text being copied.
24 \def\verbatim{\begingroup
25 \def\do##1{\catcode`##1=12 } \dospecials
26 \parskip 0pt \parindent 0pt
27 \catcode`\ =13 \catcode`\^^M=13
28 \tt \catcode`\?=0 \verbatimdefs \verbatimgobble}
29 {\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }} %
30 \gdef\verbatimgobble#1^^M{}}
31 \centerline{\titlefont The {\ttitlefont WEB} System
32 of Structured Documentation}
33
34 \vskip 15pt plus 3pt minus 3pt
35 \noindent This memo describes how to write programs in the
36 \.{WEB} language; and it also includes the full \.{WEB} documentation for
37 \.{WEAVE} and \.{TANGLE}, the programs that read \.{WEB} input and produce
38 \TeX\ and \PASCAL\ output, respectively. The philosophy behind \.{WEB} is
39 that an experienced system programmer, who wants to provide the best
40 possible documentation of software products, needs two things
41 simultaneously: a language like \TeX\ for formatting, and a language like
42 \PASCAL\ for programming. Neither type of language can provide the best
43 documentation by itself. But when both are appropriately combined, we
44 obtain a system that is much more useful than either language separately.
45
46 The structure of a software program may be thought of as a ``web'' that is
47 made up of many interconnected pieces. To document such a program, we want
48 to explain each individual part of the web and how it relates to its
49 neighbors. The typographic tools provided by \TeX\ give us an opportunity
50 to explain the local structure of each part by making that structure
51 visible, and the programming tools provided by \PASCAL\ make it possible
52 for us to specify the algorithms formally and unambiguously. By combining
53 the two, we can develop a style of programming that maximizes our ability
54 to perceive the structure of a complex piece of software, and at the same
55 time the documented programs can be mechanically translated into a working
56 software system that matches the documentation.
57
58 Since \.{WEB} is an experimental system developed for internal use within
59 the \TeX\ project at Stanford, this report is rather terse, and it assumes
60 that the reader is an experienced programmer who is highly motivated to
61 read a detailed description of \.{WEB}'s rules. Furthermore, even if a
62 less terse manual were to be written, the reader would have to be warned
63 in advance that \.{WEB} is not for beginners and it never will be: The
64 user of \.{WEB} must be familiar with both \TeX\ and \PASCAL. When one
65 writes a \.{WEB} description of a software system, it is possible to make
66 mistakes by breaking the rules of \.{WEB} and/or the rules of \TeX\ and/or
67 the rules of \PASCAL. In practice, all three types of errors will occur,
68 and you will get different error messages from the different language
69 processors. In compensation for the sophisticated expertise needed to cope
70 with such a variety of languages, however, experience has shown that
71 reliable software can be created quite rapidly by working entirely in
72 \.{WEB} from the beginning; and the documentation of such programs seems
73 to be better than the documentation obtained by any other known method.
74 Thus, \.{WEB} users need to be highly qualified, but they can get some
75 satisfaction and perhaps even a special feeling of accomplishment when
76 they have successfully created a software system with this method.
77
78 To use \.{WEB}, you prepare a file called \.{COB.WEB} (say), and then you
79 apply a system program called \.{WEAVE} to this file, obtaining an output
80 file called \.{COB.TEX}. When \TeX\ processes \.{COB.TEX}, your output
81 will be a ``pretty printed'' version of \.{COB.WEB} that takes appropriate
82 care of typographic details like page layout and the use of indentation,
83 italics, boldface, etc.; this output will contain extensive cross-index
84 information that is gathered automatically. You can also submit the same
85 file \.{COB.WEB} to another system program called \.{TANGLE}, which will
86 produce a file \.{COB.PAS} that contains the \PASCAL\ code of your \.{COB}
87 program. The \PASCAL\ compiler will convert \.{COB.PAS} into
88 machine-language instructions corresponding to the algorithms that were so
89 nicely formatted by \.{WEAVE} and \TeX. Finally, you can (and should)
90 delete the files \.{COB.TEX} and \.{COB.PAS}, because \.{COB.WEB} contains
91 the definitive source code. Examples of the behavior of \.{WEAVE} and
92 \.{TANGLE} are appended to this manual.
93
94 Besides providing a documentation tool, \.{WEB} enhances the \PASCAL\
95 language by providing a rudimentary macro capability together with the
96 ability to permute pieces of the program text, so that a large system can
97 be understood entirely in terms of small modules and their local
98 interrelationships. The \.{TANGLE} program is so named because it takes a
99 given web and moves the modules from their web structure into the order
100 required by \PASCAL; the advantage of programming in \.{WEB} is that the
101 algorithms can be expressed in ``untangled'' form, with each module
102 explained separately. The \.{WEAVE} program is so named because it takes
103 a given web and intertwines the \TeX\ and \PASCAL\ portions contained in
104 each module, then it knits the whole fabric into a structured document.
105 (Get it? Wow.) Perhaps there is some deep connection here with the fact
106 that the German word for ``weave'' is ``{\it web\/}'', and the
107 corresponding Latin imperative is ``{\it texe\/}''!
108
109 It is impossible to list all of the related work that has influenced the
110 design of \.{WEB}, but the key contributions should be mentioned
111 here.\quad (1)~Myrtle Kellington, as executive editor for ACM
112 publications, developed excellent typographic standards for the
113 typesetting of Algol programs during the 1960s, based on the original
114 designs of Peter Naur; the subtlety and quality of this influential work
115 can be appreciated only by people who have seen what happens when other
116 printers try to typeset Algol without the advice of ACM's copy
117 editors.\quad(2)~Bill McKeeman introduced a program intended to automate
118 some of this task [Algorithm 268, ``Algol~60 reference language editor,''
119 {\sl CACM \bf8} (1965), 667--668]; and a considerable flowering of such
120 programs has occurred in recent years [see especially Derek Oppen,
121 ``Prettyprinting,'' {\sl ACM TOPLAS \bf2} (1980), 465--483; G.~A. Rose and
122 J. Welsh, ``Formatted programming languages,'' {\sl SOFTWARE Practice
123 \char`\&\ Exper.\ \bf11} (1981), 651--669].\quad(3)~The top-down style of
124 exposition encouraged by \.{WEB} was of course chiefly influenced by Edsger
125 Dijkstra's essays on structured programming in the late 1960s. The less
126 well known work of Pierre-Arnoul de Marneffe [``Holon programming: A
127 survey,'' Univ.\ de Liege, Service Informatique, Liege, Belgium, 1973; 135
128 pp.\null] also had a significant influence on the author as \.{WEB} was
129 being formulated.\quad(4)~Edwin Towster has proposed a similar style of
130 documentation in which the programmer is supposed to specify the relevant
131 data structure environment in the name of each submodule [``A convention
132 for explicit declaration of environments and top-down refinement of
133 data,'' {\sl IEEE Trans.\ on Software Eng.\ \bf SE--5} (1979), 374--386];
134 this requirement seems to make the documentation a bit too verbose,
135 although experience with \.{WEB} has shown that any unusual control
136 structure or data structure should definitely be incorporated into the
137 module names on psychological grounds.\quad(5)~Discussions with Luis
138 Trabb~Pardo in the spring of 1979 were extremely helpful for setting up a
139 prototype version of \.{WEB} that was called \.{DOC}.\quad (6)~Ignacio
140 Zabala's extensive experience with \.{DOC}, in which he created a full
141 implementation of \TeX\ in \PASCAL\ that was successfully transported to
142 many different computers, was of immense value while \.{WEB} was taking
143 its present form.\quad(7)~David~R. Fuchs made several crucial suggestions
144 about how to make \.{WEB} more portable; he and Arthur~L. Samuel
145 coordinated the initial installations of \.{WEB} on dozens of computer
146 systems, making changes to the code so that it would be acceptable to
147 a wide variety of \PASCAL\ compilers.\quad(8)~The name \.{WEB} itself
148 was chosen in honor of my wife's mother, Wilda Ernestine Bates.
149
150 The appendices to this report contain complete \.{WEB} programs for the
151 \.{WEAVE} and \.{TANGLE} processors. A study of these examples, together
152 with an attempt to write \.{WEB} programs by yourself, is the best way
153 to understand why \.{WEB} has come to be like it is.
154 \section General rules.
155 A \.{WEB} file is a long string of text that has been divided into
156 individual lines. The exact line boundaries are not terribly crucial, and
157 a programmer can pretty much chop up the \.{WEB} file in whatever way seems
158 to look best as the file is being edited; but string constants and control
159 texts must end on the same line on which they begin, since this convention
160 helps to keep errors from propagating. The end of a line means
161 the same thing as a blank space.
162
163 Two kinds of material go into \.{WEB} files: \TeX\ text and \PASCAL\ text.
164 A programmer writing in \.{WEB} should be thinking both of the
165 documentation and of the \PASCAL\ program that he or she is creating;
166 i.e., the programmer should be instinctively aware of the different
167 actions that \.{WEAVE} and \.{TANGLE} will perform on the \.{WEB} file.
168 \TeX\ text is essentially copied without change by \.{WEAVE}, and it is
169 entirely deleted by \.{TANGLE}, since the \TeX\ text is ``pure
170 documentation.'' \PASCAL\ text, on the other hand, is formatted by
171 \.{WEAVE} and it is shuffled around by \.{TANGLE}, according to rules that
172 will become clear later. For now the important point to keep in mind is
173 that there are two kinds of text. Writing \.{WEB} programs is something
174 like writing \TeX\ documents, but with an additional ``\PASCAL\ mode''
175 that is added to \TeX's horizontal mode, vertical mode, and math mode.
176
177 A \.{WEB} file is built up from units called {\sl modules\/} that are more
178 or less self-contained. Each module has three parts:
179
180 \yskip\item{1)} A \TeX\ part, containing explanatory material about what
181 is going on in the module.
182
183 \item{2)} A definition part, containing macro definitions that serve as
184 abbreviations for \PASCAL\ constructions that would be less comprehensible
185 if written out in full each time.
186
187 \item{3)} A \PASCAL\ part, containing a piece of the program that
188 \.{TANGLE} will produce. This \PASCAL\ code should ideally be about a
189 dozen lines long, so that it is easily comprehensible as a unit and so
190 that its structure is readily perceived.
191
192 \yskip\noindent The three parts of each module must appear in this order;
193 i.e., the \TeX\ commentary must come first, then the definitions, and
194 finally the \PASCAL\ code. Any of the parts may be empty.
195
196 \eject % page break inserted Dec 88
197
198 A module begins with the pair of symbols `\.{@\ }' or `\.{@*}', where
199 `\.{\ }' denotes a blank space. A module ends
200 at the beginning of the next module (i.e., at the next
201 `\.{@\ }' or `\.{@*}'), or at the end of the file, whichever comes first.
202 The \.{WEB} file may also contain material that is not part of any module
203 at all, namely the text (if any) that occurs before the first module.
204 Such text is said to be ``in limbo''; it is ignored by \.{TANGLE}
205 and copied essentially verbatim by \.{WEAVE}, so its function is to
206 provide any additional formatting instructions that may be desired in the
207 \TeX\ output. Indeed, it is customary to begin a \.{WEB} file with
208 \TeX\ code in limbo that loads special fonts, defines special macros,
209 changes the page sizes, and/or produces a title page.
210
211 Modules are numbered consecutively, starting with 1; these numbers appear
212 at the beginning of each module of the \TeX\ documentation, and they appear
213 as bracketed comments at the beginning of the code generated by that
214 module in the \PASCAL\ program.
215
216 Fortunately, you never mention these numbers yourself when you are writing
217 in \.{WEB}. You just say `\.{@\ }' or `\.{@*}' at the beginning of each
218 new module, and the numbers are supplied automatically by \.{WEAVE} and
219 \.{TANGLE}. As far as you are concerned, a module has a
220 {\sl name\/} instead of a number; such a name is specified by writing
221 `\.{@<}' followed by \TeX\ text followed by `\.{@>}'. When \.{WEAVE}
222 outputs a module name, it replaces the `\.{@<}' and `\.{@>}' by
223 angle brackets and inserts the module number in small type. Thus, when you
224 read the output of \.{WEAVE} it is easy to locate any module that is
225 referred to in another module.
226
227 For expository purposes, a module name should be a good description of the
228 contents of that module; i.e., it should stand for the abstraction
229 represented by the module. Then the module can be ``plugged into'' one or
230 more other modules in such a way
231 that unimportant details of its inner workings
232 are suppressed. A module name therefore ought to be long enough to convey
233 the necessary meaning. Unfortunately, however, it is laborious to type
234 such long names over and over again, and it is also difficult to specify a
235 long name twice in exactly the same way so that \.{WEAVE} and \.{TANGLE}
236 will be able to match the names to the modules. To ameliorate this difficulty,
237 \.{WEAVE} and \.{TANGLE} let you abbreviate a module name
238 after its first appearance in the \.{WEB} file; you can type simply
239 `\.{@<$\alpha$...@>}', where $\alpha$ is any string that is a prefix of
240 exactly one module name appearing in the file. For example, `\.{@<Clear
241 the arrays@>}' can be abbreviated to `\.{@<Clear...@>}' if no other module
242 name begins with the five letters `\.{Clear}'. Module names must otherwise
243 match character for character, except that consecutive blank spaces and/or
244 tab marks are treated as equivalent to single spaces, and such spaces are
245 deleted at the beginning and end of the name. Thus, `\.{@< Clear { }the
246 arrays @>}' will also match the name in the previous example.
247
248 We have said that a module begins with `\.{@\ }' or `\.{@*}', but we
249 didn't say how it gets divided up into a \TeX\ part, a definition part,
250 and a \PASCAL\ part. The definition part begins with the first appearance
251 of `\.{@d}' or `\.{@f}' in the module, and the \PASCAL\ part begins with
252 the first appearance of `\.{@p}' or `\.{@<}'. The latter option `\.{@<}'
253 stands for the beginning of a module name, which is the name of the module
254 itself. An equals sign (\.=) must follow the `\.{@>}' at the end of this
255 module name; you are saying, in effect, that the module name stands for
256 the \PASCAL\ text that follows, so you say `$\langle\,$module
257 name$\,\rangle=\null$\PASCAL\ text'. Alternatively, if the \PASCAL\ part
258 begins with `\.{@p}' instead of a module name, the current module is said
259 to be {\sl unnamed}. Note that module names cannot appear in the
260 definition part of a module, because the first `\.{@<}' in a module
261 signals the beginning of its \PASCAL\ part. But any number of module names
262 might appear in the \PASCAL\ part, once it has started.
263
264 The general idea of \.{TANGLE} is to make a \PASCAL\ program out of these
265 modules in the following way: First all the \PASCAL\ parts of unnamed
266 modules are copied down, in order; this constitutes the initial
267 approximation $T_0$ to the text of the program. (There should be at least
268 one unnamed module, otherwise there will be no program.) Then all module
269 names that appear in the initial text $T_0$ are replaced by the \PASCAL\
270 parts of the corresponding modules, and this substitution process
271 continues until no module names remain. Then all defined macros are
272 replaced by their equivalents, according to certain rules that are
273 explained later. The resulting \PASCAL\ code is ``sanitized'' so that it
274 will be acceptable to an average garden-variety \PASCAL\ compiler; i.e.,
275 lowercase letters are converted to uppercase, long identifiers are
276 chopped, and the lines of the output file are constrained to be at most 72
277 characters long. All comments will have been removed from this \PASCAL\
278 program except for the meta-comments delimited by `\.{@\{}' and
279 `\.{@\}}', as explained below, and except for the module-number comments
280 that point to the source location where each piece of the program text
281 originated in the \.{WEB} file.
282
283 If the same name has been given to more than one module, the \PASCAL\ text
284 for that name is obtained by putting together all of the \PASCAL\ parts in
285 the corresponding modules. This feature is useful, for example, in a
286 module named `Global variables in the outer block', since one can then
287 declare global variables in whatever modules those variables are
288 introduced. When several modules have the same name, \.{WEAVE} assigns the
289 first module number as the number corresponding to that name, and it
290 inserts a note at the bottom of that module telling the reader to `See
291 also sections so-and-so'; this footnote gives the numbers of all the other
292 modules having the same name as the present one. The \PASCAL\ text
293 corresponding to a module is usually formatted by \.{WEAVE} so that the
294 output has an equivalence sign in place of the equals sign in the \.{WEB}
295 file; i.e., the output says `$\langle\,$module
296 name$\,\rangle\equiv\null$\PASCAL\ text'. However, in the case of the second
297 and subsequent appearances of a module with the same name, this `$\equiv$'
298 sign is replaced by `$\mathrel+\equiv$', as an indication that the \PASCAL\
299 text that follows is being appended to the \PASCAL\ text of another
300 module.
301
302 The general idea of \.{WEAVE} is to make a \.{TEX} file from the \.{WEB}
303 file in the following way: The first line of the \.{TEX} file will be
304 `\.{\\input webmac}'; this will cause \TeX\ to read in the macros that
305 define \.{WEB}'s documentation conventions. The next lines of the file
306 will be copied from whatever \TeX\ text is in limbo before the first
307 module. Then comes the output for each module in turn, possibly
308 interspersed with end-of-page marks. Finally, \.{WEAVE} will generate a
309 cross-reference index that lists each module number in which each \PASCAL\
310 identifier appears, and it will also generate an alphabetized list
311 of the module names, as well as a table of contents that
312 shows the page and module numbers for each ``starred'' module.
313
314 What is a ``starred'' module, you ask? A module that begins with `\.{@*}'
315 instead of `\.{@\ }' is slightly special in that it denotes a new major
316 group of modules. The `\.{@*}' should be followed by the title of this
317 group, followed by a period. Such modules will always start on a new page
318 in the \TeX\ output, and the group title will appear as a running headline
319 on all subsequent pages until the next starred module. The title will also
320 appear in the table of contents, and in boldface type at the beginning of
321 its module. Caution: Do not use \TeX\ control sequences in such titles,
322 unless you know that the \.{webmac} macros will do the right thing with
323 them. The reason is that these titles are converted to uppercase when
324 they appear as running heads, and they are converted to boldface when they
325 appear at the beginning of their modules, and they are also written out to
326 a table-of-contents file used for temporary storage while \TeX\ is
327 working; whatever control sequences you use must be meaningful in all
328 three of these modes.
329
330 The \TeX\ output produced by \.{WEAVE} for each module consists of
331 the following: First comes the module number (e.g., `\.{\\M123.}'
332 at the beginning of module 123, except that `\.{\\N}' appears in place of
333 `\.{\\M}' at the beginning of a starred module). Then comes the
334 \TeX\ part of the module, copied almost verbatim except as noted
335 below. Then comes the definition part and the \PASCAL\ part, formatted
336 so that there will be a little extra space between them if both are
337 nonempty. The definition and \PASCAL\ parts are obtained by inserting
338 a bunch of funny looking \TeX\ macros into the \PASCAL\ program; these
339 macros handle typographic details about fonts and proper math spacing,
340 as well as line breaks and indentation.
341
342 When you are typing \TeX\ text, you will probably want to make frequent
343 reference to variables and other quantities in your \PASCAL\ code, and you
344 will want those variables to have the same typographic treatment
345 when they appear in your text as when they appear in your
346 program. Therefore the \.{WEB} language allows you to get the effect of
347 \PASCAL\ editing within \TeX\ text, if you place `\.|' marks before and
348 after the \PASCAL\ material. For example, suppose you want to say something
349 like this:
350 $$\hbox{The characters are placed into \\{buffer}, which is a
351 \&{packed} \&{array} $[1\to\|n]$ \&{of} \\{char}.}$$
352 The \TeX\ text would look like this in your \.{WEB} file:
353 $$\.{The characters are placed into |buffer|, which is a |packed
354 array [1..n] of char|.}$$
355 And \.{WEAVE} translates this into something you are glad you didn't have
356 to type:
357 $$\lpile{\.{The characters are placed into \\\\\{buffer\},}\cr
358 \.{which is a \\\&\{packed\}{ }\\\&\{array\}{ }\$
359 [1\\to\\|n]\${ }\\\&\{of\}{ }\\\\\{char\}.}\cr}$$
360 Incidentally, the cross-reference index that \.{WEAVE} would make, in
361 the presence of a comment like this, would include
362 the current module number as one of the index entries for \\{buffer}
363 \vadjust{\eject}% page break inserted Dec 88
364 and \\{char}, even though \\{buffer} and \\{char}
365 might not appear in the \PASCAL\ part of
366 this module. Thus, the index covers references to identifiers in
367 the explanatory comments as well as in the program itself; you will
368 soon learn to appreciate this feature. However, the identifiers
369 \&{packed} and \&{array} and \|n\ and \&{of\/} would not be indexed,
370 because \.{WEAVE} does not make index entries for reserved words or
371 single-letter identifiers. Such identifiers are felt to be so ubiquitous
372 that it would be pointless to mention every place where they occur.
373
374 Speaking of identifiers, the author of \.{WEB} thinks that
375 \\{IdentifiersSeveralWordsLong} look terribly ugly when they mix
376 uppercase and lowercase letters. He recommends that
377 \\{identifiers\_several\_words\_long} be written with underline characters
378 to get a much better effect. The actual identifiers sent to the \PASCAL\
379 compiler by \.{TANGLE} will have such underlines removed, and \.{TANGLE}
380 will check to make sure that two different identifiers do not become
381 identical when this happens. (In fact, \.{TANGLE} even checks that
382 the first seven characters of identifiers are unique, when lowercase
383 letters have been converted to uppercase; the number seven in this
384 constraint is more strict than \PASCAL's eight, and it can
385 be changed if desired.) The \.{WEAVE} processor will properly
386 alphabetize identifiers that have embedded underlines
387 when it makes the index.
388
389 Although a module begins with \TeX\ text and ends with \PASCAL\ text, we
390 have noted that the dividing line isn't sharp, since \PASCAL\ text can be
391 included in \TeX\ text if it is enclosed in `\pb'. Conversely, \TeX\ text
392 also appears frequently within \PASCAL\ text, because everything in
393 comments (i.e., between left and right braces) is treated as \TeX\ text.
394 Furthermore, a module name consists of \TeX\ text; thus, a \.{WEB} file
395 typically involves constructions like `\.{if} \.x \.= \.0 \.{then}
396 \.{@<Empty} \.{the} \.{|buffer|} \.{array@>}' where we go back and forth
397 between \PASCAL\ and \TeX\ conventions in a natural way.
398 \section Macros.
399 A \.{WEB} programmer can define three kinds of macros to make the programs
400 shorter and more readable:
401
402 \yskip\hang`\.{@d} \\{identifier} \.= \\{constant}' defines a {\sl numeric\/}
403 macro, allowing \.{TANGLE} to do rudimentary arithmetic.
404
405 \yskip\hang`\.{@d} \\{identifier} \.{==} \PASCAL\ text' defines a {\sl
406 simple\/} macro, where the identifier will be replaced by the \PASCAL\ text
407 when \.{TANGLE} produces its output.
408
409 \yskip\hang`\.{@d} \\{identifier}\.{(\#) ==} \PASCAL\ text' defines a
410 {\sl parametric\/} macro, where the identifier will be replaced by the \PASCAL\
411 text and where occurrences of \.{\#} in that \PASCAL\ text will be
412 replaced by an argument.
413
414 \yskip\noindent In all three cases, the identifier must have length greater
415 than one; it must not be a single letter.
416
417 Numeric macros are subject to the following restrictions:\quad
418 (1)~The identifier must
419 be making its first appearance in the \.{WEB} file;
420 a numeric macro must be defined before it is used.\quad
421 (2)~The right-hand side of the numeric definition must be made entirely from
422 integer constants, numeric macros, preprocessed strings (see below), and
423 plus~signs or minus signs. No other operations or symbols are allowed,
424 not even parentheses, except that \PASCAL-like comments (enclosed in
425 braces) can appear. Indeed, comments are recommended, since it is usually
426 wise to give a brief explanation of the significance of each identifier as
427 it is defined.\quad
428 (3)~The numeric value must be less than $2^{15}=32768$ in absolute value.
429 (For larger values, you can use `\.{==}' in place of~`\.=', thus making use
430 of a simple macro instead of a numeric one. Note, however, that simple
431 macros sometimes have a different effect. For example, consider the three
432 definitions `\.{@d n1=2 @d n2=2+n1 @d n3==2+n1}'; then `\.{x-n2}' will
433 expand into `\.{x-4}', while `\.{x-n3}' will expand into `\.{x-2+2}' which
434 is quite different! It is wise to include parentheses in non-numeric
435 macros, e.g., `\.{@d n3==(2+n1)}', to avoid such errors.)
436
437 When constants are connected by plus signs or minus
438 signs in a \PASCAL\ program, \.{TANGLE} does the arithmetic before putting
439 the constant into the output file. Therefore it is permissible to say, for
440 example, `\&{array} $[0\,.\,.\,\\{size}-1]$' if \\{size} has been declared
441 as a macro; note that \PASCAL\ doesn't allow this kind of compile-time
442 arithmetic if \\{size} is a \&{constant} quantity in the program. Another
443 use of \.{TANGLE}'s arithmetic is to make \&{case} statement labels such
444 as `$\\{flag}+1$' legitimate. Of course, it is improper to change \.{2+2}
445 into \.4 without looking at the surrounding context; many counterexamples
446 exist, such as the phrases `\.{-2+2}', `\.{x/2+2}', and `\.{2+2E5}'. The
447 program for \.{TANGLE}, in the appendix, gives precise details about this
448 conversion, which \.{TANGLE} does only when it is safe.
449
450 The right-hand sides of simple and parametric macros
451 are required to have balanced parentheses, and the \PASCAL\ texts of
452 modules must have balanced parentheses too. Therefore when the argument
453 to a para\-metric macro appears in parentheses, both parentheses
454 will belong to the same \PASCAL\ text.
455
456 The appendices to this report contain hundreds of typical examples of the
457 usefulness of \.{WEB} macros, so it is not necessary to dwell on the
458 subject here. However, the reader should know that \.{WEB}'s apparently
459 primitive macro capabilities can actually do a lot of rather surprising
460 things. Here is a construction that sheds further light on what is
461 possible: After making the definitions
462 $$\catcode`\#=12
463 \lpile{\.{@d two\_cases(#)==case j of 1:#(1); 2:#(2); end}\cr
464 \.{@d reset\_file(#)==reset(input\_file@\&#)}\cr}$$
465 one can write `\.{two\_cases(reset\_file)}' and the resulting \PASCAL\
466 output will be
467 $$\.{case j of 1:reset(input\_file1); 2:reset(input\_file2); end}$$
468 (but in uppercase letters and with \.\_'s removed).
469 The `\.{@\&}' operation used here joins together two adjacent tokens
470 into a single token, as explained later; otherwise the \PASCAL\ file would
471 contain a space between \.{input\_file} and the digit that followed it.
472 This trick can be used to provide the effect of an array of files, if you
473 are unfortunate enough to have a \PASCAL\ compiler that doesn't allow such
474 arrays. Incidentally, the cross-reference index made by \.{WEAVE} from
475 this example would contain the identifier \\{input\_file} but it would not
476 contain \\{input\_file1} or \\{input\_file2}. Furthermore, \.{TANGLE}
477 would not catch the error that \.{INPUTFILE1} and \.{INPUTFILE2} both
478 begin with the same nine letters; one should be more careful when using
479 `\.{@\&}'! But such aspects of the construction in this trick are
480 peripheral to our main point, which is that a parametric macro name without
481 arguments can be used as an argument to another parametric macro.
482
483 Although \.{WEB}'s macros are allowed to have at most one parameter, the
484 following example shows that this is not as much of a restriction as it
485 may seem at first. Let \\{amac} and \\{bmac} be any parametric macros, and
486 suppose that we want to get the effect of
487 $$\catcode`\#=12
488 \.{@d cmac(#1,#2) == amac(#1) bmac(#2)}$$
489 which \.{WEB} doesn't permit. The solution is to make the definitions
490 $$\catcode`\#=12
491 \lpile{\.{@d cmac(#) == amac(#) dmac}\cr
492 \.{@d dmac(#) == bmac(#)}\cr}$$
493 and then to say `\.{cmac(x)(y)}'.
494
495 There is one restriction in the generality of \.{WEB}'s parametric
496 macros, however: the argument to a para\-metric macro must not come from
497 the expansion of a macro that has not already been ``started.'' For
498 example, here is one of the things \.{WEB} cannot handle:
499 $$\catcode`\#=12
500 \lpile{\.{@d arg == (p)}\cr
501 \.{@d identity(#) == #}\cr
502 \.{@p identity arg}\cr}$$
503 In this case \.{TANGLE} will complain that the \.{identity} macro is not
504 followed by an argument in parentheses.
505
506 The \.{WEB} language has another feature that is somewhat similar to a
507 numeric macro. A {\sl preprocessed string\/} is a string that is like
508 a \PASCAL\ string but delimited by double-quote marks (\.") instead of
509 single-quotes. Double-quote marks inside of such strings are indicated by
510 giving two double-quotes in a row. If a preprocessed string is
511 of length one (e.g., \.{"A"} or \.{""""}), it will be treated by \.{TANGLE}
512 as equivalent to the corresponding ASCII-code integer (e.g., \.{65} or
513 \.{34}). And if a preprocessed string is not of length one, it will be
514 converted into an integer equal to 256 or more. A {\sl string pool\/}
515 containing all such strings will be written out by the \.{TANGLE}
516 processor; this string pool file consists of string 256, then string 257,
517 etc., where each string is followed by an end-of-line and prefixed by two
518 decimal digits that define its length. Thus, for example, the empty string
519 \.{""} would be represented in the string pool file by a line containing
520 the two characters `\.{00}', while the string \.{"""String"""} would be
521 represented by `\.{08"String"}'. A given string appears at most once in
522 the string pool; the use of such a pool makes it easier to cope with
523 \PASCAL's restrictions on string manipulation. The string pool ends with
524 `\.{*nnnnnnnnn}', where \.{nnnnnnnnn} is a decimal number
525 called the {\sl string pool check sum}. If any string changes, the check
526 sum almost surely changes too; thus, the `\.{@\$}' feature
527 described below makes it possible for a program to assure itself that it
528 is reading its own string pool.
529
530 Here is a simple example that combines numeric macros with preprocessed
531 strings of length one:
532 $$\lpile{\.{@d upper\_case\_Y = "Y"}\cr
533 \.{@d case\_difference = -"y"+upper\_case\_Y}\cr}$$
534 The result is to define
535 $\\{upper\_case\_Y}=89$, $\\{case\_difference}=-32$.
536 \section Control codes.
537 We have seen several magic uses of `\.{@}' signs in \.{WEB} files, and it
538 is time to make a systematic study of
539 these special features. A \.{WEB} {\sl control code\/}
540 is a two-character combination of which the first is `\.@'.
541
542 Here is a complete list of the legal control codes. The letters $L$, $T$,
543 $P$, $M$, $C$, and/or $S$ following each code indicate whether or not that
544 code is allowable in limbo, in \TeX\ text, in \PASCAL\ text, in module
545 names, in comments, and/or in strings. A bar over such a letter means
546 that the control code terminates the present part of the \.{WEB} file; for
547 example, $\overline L$ means that this control code ends the limbo material
548 before the first module.
549
550 \def\@#1[#2] {\yskip\hangindent 2em\noindent\.{@#1\unskip
551 \spacefactor1000{ }}$[#2]$\quad}
552 \def\oP{\overline P}
553 \def\oT{\overline T\mskip1mu}
554
555 \@@ [C,L,M,P,S,T] A double \.@ denotes the single character `\.@'. This is
556 the only control code that is legal in limbo, in comments, and in strings.
557
558 \@\ [\overline L,\oP,\oT] This denotes the beginning of a new
559 (unstarred) module. A tab mark or end-of-line (carriage return)
560 is equivalent to a space when it follows an \.@ sign.
561
562 \@* [\overline L,\oP,\oT] This denotes the beginning of a new starred
563 module, i.e., a module that begins a new major group. The title of the new
564 group should appear after the \.{@*}, followed by a period. As explained
565 above, \TeX\ control sequences should be avoided in such titles unless
566 they are quite simple. When \.{WEAVE} and \.{TANGLE} read a \.{@*}, they
567 print an asterisk on the terminal
568 followed by the current module number, so that the user
569 can see some indication of progress. The very first module should be starred.
570
571 \@d [\oP,\oT] Macro definitions begin with \.{@d} (or \.{@D}), followed by
572 the \PASCAL\ text for one of the three kinds of macros, as explained
573 earlier.
574
575 \@f [\oP,\oT] Format definitions begin with \.{@f} (or \.{@F}); they cause
576 \.{WEAVE} to treat identifiers in a special way when they appear in
577 \PASCAL\ text. The general form of a format definition is `\.{@f} \|l \.{==}
578 \|r', followed by an optional comment enclosed in braces, where \|l and \|r
579 are identifiers; \.{WEAVE} will subsequently treat identifier \|l as it
580 currently treats \|r. This feature allows a \.{WEB} programmer to invent
581 new reserved words and/or to unreserve some of \PASCAL's reserved
582 identifiers. The definition part of each module consists of any number of
583 macro definitions (beginning with \.{@d}) and format definitions (beginning
584 with \.{@f}), intermixed in any order.
585
586 \@p [\oP,\oT] The \PASCAL\ part of an unnamed module begins with \.{@p}
587 (or \.{@P}). This causes \.{TANGLE} to append the following \PASCAL\ code
588 to the initial program text $T_0$ as explained above. The \.{WEAVE}
589 processor does not cause a `\.{@p}' to appear explicitly in the \TeX\
590 output, so if you are creating a \.{WEB} file based on a \TeX-printed
591 \.{WEB} documentation you have to remember to insert \.{@p} in the
592 appropriate places of the unnamed modules.
593
594 \@< [P,\oT] A module name begins with \.{@<} followed by \TeX\ text followed
595 by \.{@>}; the \TeX\ text should not contain any \.{WEB} control codes
596 except \.{@@}, unless these control codes appear in \PASCAL\ text that
597 is delimited by \pb. The module name may be abbreviated, after its first
598 appearance in a \.{WEB} file, by giving any unique prefix followed by \.{...},
599 where the three dots immediately precede the closing \.{@>}. No module name
600 should be a prefix of another. Module names may not appear in \PASCAL\
601 text that is enclosed in \pb, nor may they appear in the definition part
602 of a module (since the appearance of a module name ends the definition
603 part and begins the \PASCAL\ part).
604
605 \@\' [P,T] This denotes an octal constant, to be formed from the
606 succeeding digits. For example, if the \.{WEB} file contains `\.{@\'100}',
607 the \.{TANGLE} processor will treat this an equivalent to `\.{64}';
608 the constant will be formatted as ``\O{100}'' in the \TeX\ output
609 produced via \.{WEAVE}. You should use octal notation only for positive
610 constants; don't try to get, e.g., $-1$ by saying `\.{@\'777777777777}'.
611
612 \@" [P,T] A hexadecimal constant; `\.{@"D0D0}' tangles to \.{53456} and
613 weaves to `\H{D0D0}'.
614
615 \@\$ [P] This denotes the string pool check sum.
616
617 \@\{ [P] The beginning of a ``meta comment,'' i.e., a comment
618 that is supposed to appear in the \PASCAL\ code, is indicated by
619 \.{@\{} in the \.{WEB} file. Such delimiters can be used as
620 isolated symbols in macros or modules, but they should be properly nested
621 in the final \PASCAL\ program. The \.{TANGLE} processor will convert
622 `\.{@\{}' into `\.\{' in the \PASCAL\ output file, unless
623 the output is already part of a meta-comment; in the latter case
624 `\.{@\{}' is converted into `\.[', since \PASCAL\ does not allow
625 nested comments. The \.{WEAVE} processor outputs `\.{@\{}'.
626 Incidentally, module numbers are automatically inserted
627 as meta-comments into the \PASCAL\ program, in order to help correlate the
628 outputs of \.{WEAVE} and \.{TANGLE} (see Appendix~C\null). Meta-comments
629 can be used to put conditional text into a \PASCAL\ program; this helps to
630 overcome one of the limitations of \.{WEB}, since the simple macro
631 processing routines of \.{TANGLE} do not include the dynamic evaluation of
632 boolean expressions.
633
634 \@\} [P] The end of a ``meta comment'' is indicated by `\.{@\}}'; this is
635 converted either into `\.\}' or `\.{]}' in the \PASCAL\ output, according
636 to the conventions explained for \.{@\{} above.
637 The \.{WEAVE} processor outputs `\.{@\}}'.
638
639 \@\& [P] The \.{@\&} operation causes whatever is on its left to be
640 adjacent to whatever is on its right, in the \PASCAL\ output. No spaces or
641 line breaks will separate these two items. However, the thing on the left
642 should not be a semicolon, since a line break might occur after a semicolon.
643
644 \@\^ [P,T] The ``control text'' that follows, up to the next
645 `\.{@>}', will be entered into the index together with the identifiers of
646 the \PASCAL\ program; this text will appear in roman type. For example, to
647 put the phrase ``system dependencies'' into the index, you can type
648 `\.{@\^system dependencies@>}' in each module
649 that you want to index as system dependent. A control text, like a string,
650 must end on the same line of the \.{WEB} file as it began. Furthermore,
651 no \.{WEB} control codes are allowed in a control text, not even
652 \.{@@}. (If you need an \.{@} sign you can get around this restriction by
653 typing `\.{\\AT!}'.)
654
655 \@. [P,T] The ``control text'' that follows will be entered into the index
656 in \.{typewriter} \.{type}; see the rules for `\.{@\^}', which is analogous.
657
658 \@: [P,T] The ``control text'' that follows will be entered into the index
659 in a format controlled by the \TeX\ macro `\.{\\9}', which the user
660 should define as desired; see the rules for `\.{@\^}', which is analogous.
661
662 \@t [P] The ``control text'' that follows, up to the next `\.{@>}', will
663 be put into a \TeX\ \.{\\hbox} and formatted along with the neighboring
664 \PASCAL\ program. This text is ignored by \.{TANGLE}, but it can be used
665 for various purposes within \.{WEAVE}. For example, you can make comments
666 that mix \PASCAL\ and classical mathematics, as in `$\\{size}<2^{15}$', by
667 typing `\.{|size < @t\$2\^\{15\}\$@>|}'. A control text must end on the
668 same line of the \.{WEB} file as it began, and it may not contain any
669 \.{WEB} control codes.
670
671 \@= [P] The ``control text'' that follows, up to the next `\.{@>}', will
672 be passed verbatim to the \PASCAL\ program.
673
674 \@\\ [P] Force end-of-line here in the \PASCAL\ program file.
675
676 \@! [P,T] The module number in an index entry will be underlined if `\.{@!}'
677 immediately precedes the identifier or control text being indexed. This
678 convention is used to distinguish the modules where an identifier is
679 defined, or where it is explained in some special way, from the modules
680 where it is used. A~reserved word or an identifier of length one will not
681 be indexed except for underlined entries. An `\.{@!}' is implicitly inserted
682 by \.{WEAVE} just after the reserved words \&{function}, \&{procedure},
683 \&{program}, and \&{var}, and just after \.{@d} and \.{@f}. But you should
684 insert your own `\.{@!}' before the definitions of types, constants,
685 variables, parameters, and components of records and enumerated types that
686 are not covered by this implicit convention, if you want to improve the
687 quality of the index that you get.
688
689 \@? [P,T] This cancels an implicit (or explicit) `\.{@!}', so that the next
690 index entry will not be underlined.
691
692 \@, [P] This control code inserts a thin space in \.{WEAVE}'s output; it is
693 ignored by \.{TANGLE}. Sometimes you need this extra space if you are using
694 macros in an unusual way, e.g., if two identifiers are adjacent.
695
696 \@/ [P] This control code causes a line break to occur within a \PASCAL\
697 program formatted by \.{WEAVE}; it is ignored by \.{TANGLE}. Line breaks
698 are chosen automatically by \TeX\ according to a scheme that works 99\%\
699 of the time, but sometimes you will prefer to force a line break so that
700 the program is segmented according to logical rather than visual criteria.
701 Caution: `\.{@/}' should be used only after statements or clauses, not in
702 the middle of an expression; use \.{@|} in the middle of expressions, in
703 order to keep \.{WEAVE}'s parser happy.
704
705 \@| [P] This control code specifies an optional line break in the midst of
706 an expression. For example, if you have a long condition between \&{if} and
707 \&{then}, or a long expression on the right-hand side of an assignment
708 statement, you can use `\.{@|}' to specify breakpoints more logical than
709 the ones that \TeX\ might choose on visual grounds.
710
711 \@\# [P] This control code forces a line break, like \.{@/} does,
712 and it also causes a little extra white space to appear between the lines at
713 this break. You might use it, for example, between procedure definitions or
714 between groups of macro definitions that are logically separate but within
715 the same module.
716
717 \@+ [P] This control code cancels a line break that might otherwise be
718 inserted by \.{WEAVE}, e.g., before the word `\&{else}', if you want to
719 put a short if-then-else construction on a single line. It is ignored by
720 \.{TANGLE}.
721
722 \@; [P] This control code is treated like a semicolon, for formatting
723 purposes, except that it is invisible. You can use it, for example, after
724 a module name when the \PASCAL\ text represented by that module name ends
725 with a semicolon.
726
727 \yskip\noindent
728 The last six control codes (namely `\.{@,}', `\.{@/}', `\.{@|}',
729 `\.{@\#}', `\.{@+}', and `\.{@;}') have no effect on the \PASCAL\
730 program output by \.{TANGLE}; they merely help to improve the readability
731 of the \TeX-formatted \PASCAL\ that is output by \.{WEAVE}, in unusual
732 circumstances. \.{WEAVE}'s built-in formatting method is fairly good, but
733 it is incapable of handling all possible cases, because it must deal with
734 fragments of text involving macros and module names; these fragments do
735 not necessarily obey \PASCAL's syntax. Although \.{WEB} allows you to
736 override the automatic formatting, your best strategy is not to worry
737 about such things until you have seen what \.{WEAVE} produces automatically,
738 since you will probably need to make only a few corrections when you are
739 touching up your documentation.
740
741 Because of the rules by which every module is broken into three parts,
742 the control codes `\.{@d}', `\.{@f}', and `\.{@p}' are not allowed to occur
743 once the \PASCAL\ part of a module has begun.
744 \section Additional features and caveats.
745
746 1. The character pairs `\.{(*}', `\.{*)}', `\.{(.}', and `\.{.)}' are
747 converted automatically in \PASCAL\ text as though they were
748 `\.{@\{}', `\.{@\}}', `\.[', and `\.]', respectively, except
749 of course in strings. Furthermore in certain installations of \.{WEB} that
750 {\def\\#1#2{`{\tentex\char'#1#2}'}%
751 have an extended character set, the characters \\32, \\34, \\35, \\30,
752 \\36, \\04, \\37, \\05, and \\06}
753 can be typed as abbreviations for
754 `\.{<>}', `\.{<=}', `\.{>=}', `\.{:=}', `\.{==}', `\.{and}', `\.{or}',
755 `\.{not}', and `\.{in}', respectively. However, the latter abbreviations
756 are not used in the standard versions of \.{WEAVE.WEB} and \.{TANGLE.WEB}
757 that are distributed to people who are installing \.{WEB} on other
758 computers, and the programs are designed to produce only standard ASCII
759 characters as output if the input consists entirely of ASCII characters.
760
761 2. If you have an extended character set, all of the characters listed
762 in Appendix C of {\sl The \TeX book\/} can be used in strings. But you should
763 stick to standard ASCII characters if you want to write programs that will
764 be useful to all the poor souls out there who don't have extended
765 character sets.
766
767 3. The \TeX\ file output by \.{WEAVE} is broken into lines having at most
768 80 characters each. The algorithm that does this line breaking is unaware
769 of \TeX's convention about comments following `\.\%' signs on a line. When
770 \TeX\ text is being copied, the existing line breaks are copied as well,
771 so there is no problem with `\.\%' signs unless the original \.{WEB} file
772 contains a line more than eighty characters long or a line with \PASCAL\
773 text in \pb\ that expands to more than eighty characters long. Such lines
774 should not have `\.\%' signs.
775
776 4. \PASCAL\ text is translated by a ``bottom up'' procedure that
777 identifies each token as a ``part of speech'' and combines parts of speech
778 into larger and larger phrases as much as possible according to a special
779 grammar that is explained in the documentation of \.{WEAVE}. It is easy to
780 learn the translation scheme for simple constructions like single
781 identifiers and short expressions, just by looking at a few examples of
782 what \.{WEAVE} does, but the general mechanism is somewhat complex because
783 it must handle much more than \PASCAL\ itself. Furthermore the output
784 contains embedded codes that cause \TeX\ to indent and break lines as
785 necessary, depending on the fonts used and the desired page width. For
786 best results it is wise to adhere to the following restrictions:
787
788 \yskip\itemitem{a)}Comments in \PASCAL\ text should appear only after
789 statements or clauses; i.e., after semicolons, after reserved words like
790 \&{then} and \&{do}, or before reserved words like \&{end} and \&{else}.
791 Otherwise \.{WEAVE}'s parsing method may well get mixed up.
792
793 \itemitem{b)}Don't enclose long \PASCAL\ texts in \pb, since the
794 indentation and line breaking codes are omitted when the \pb\ text is
795 translated from \PASCAL\ to \TeX. Stick to simple expressions or
796 statements.
797
798 \yskip
799 5. Comments and module names are not permitted in \pb\ text. After a `\.|'
800 signals the change from \TeX\ text to \PASCAL\ text, the next `\.|' that is
801 not part of a string or control text ends the \PASCAL\ text.
802
803 6. A comment must have properly nested occurrences of left and right
804 braces, otherwise \.{WEAVE} and \.{TANGLE} will not know where the comment
805 ends. However, the character pairs `\.{\\\{}' and `\.{\\\}}' do not count
806 as left and right braces in comments, and the character pair `\.{\\|}'
807 does not count as a delimiter that begins \PASCAL\ text. (The actual rule
808 is that a character after `\.\\' is ignored; hence in `\.{\\\\\{}' the
809 left brace {\sl does\/} count.) At present, \.{TANGLE} and \.{WEAVE} treat
810 comments in slightly different ways, and it is necessary to satisfy both
811 conventions: \.{TANGLE} ignores `\.|' characters entirely, while \.{WEAVE}
812 uses them to switch between \TeX\ text and \PASCAL\ text. Therefore, a
813 comment that includes a brace in a string in \pb---e.g., `\.{\{{ }look at
814 this |"\{"| \}}'---will be handled correctly by \.{WEAVE}, but \.{TANGLE}
815 will think there is an unmatched left brace. In order to satisfy both
816 processors, one can write `\.{\{{ }look at this \\leftbrace\\{ }\}}', after
817 setting up `\.{\\def\\leftbrace\{|"\{"|\}}'.
818
819 7. Reserved words of \PASCAL\ must appear entirely in lowercase letters
820 in the \.{WEB} file; otherwise their special nature will not be recognized
821 by \.{WEAVE}. You could, for example, have a macro named \\{END} and it
822 would not be confused with \PASCAL's \&{end}.
823
824 However, you may not want to capitalize macro names just to distinguish them
825 from other identifiers. Here is a way to unreserve \PASCAL's reserved word
826 `\&{type}' and to substitute another word `\&{mtype}' in the \.{WEB} file.
827 $$\vbox{\halign{\tt #\hfil\cr
828 @d type(\char'43) == mem[\char'43].t\cr
829 @d mtype == t \char'100\char'46{} y \char'100\char'46{} p
830 \char'100\char'46{} e\cr
831 @f mtype == type\cr
832 @f type == true\cr}}$$
833 In the output of \.{TANGLE}, the macro \.{mtype} now produces `\.{TYPE}'
834 and the macro \.{type(x)} now produces `\.{MEM[X].T}'. In the output of
835 \.{WEAVE}, these same inputs produce \&{mtype} and \\{type}(\|x),
836 respectively.
837
838 8. The \.{@f} feature allows you to define one identifier to act like
839 another, and these format definitions are carried out sequentially, as the
840 example above indicates. However, a given identifier has only one printed format
841 throughout the entire document (and this format will even be used before
842 the \.{@f} that defines it). The reason is that \.{WEAVE} operates in two
843 passes; it processes \.{@f}'s and cross-references on the first pass and
844 it does the output on the second.
845
846 9. You may want some \.{@f} formatting that doesn't correspond to any
847 existing reserved word. In that case, \.{WEAVE} could be extended in a
848 fairly obvious way to include new ``reserved words'' in its vocabulary.
849 The identifier `\&{xclause}' has in fact been included already as a
850 reserved word, so that it can be used to format the `\&{loop}' macro,
851 where `\&{loop}' is defined to be equivalent to `\&{while \\{true} do}'.
852
853 10. Sometimes it is desirable to insert spacing into \PASCAL\ code that is
854 more general than the thin space provided by `\.{@,}'. The \.{@t} feature
855 can be used for this purpose; e.g., `\.{@t\\hskip 1in@>}' will
856 leave one inch of blank space. Furthermore, `\.{@t\\4@>}' can be
857 used to backspace by one unit of indentation, since the control sequence
858 \.{\\4} is defined in \.{webmac} to be such a backspace. (This
859 control sequence is used, for example, at the beginning of lines that
860 contain labeled statements, so that the label will stick out a little at
861 the left.)
862
863 11. \.{WEAVE} and \.{TANGLE} are designed to work with two input files,
864 called \\{web\_file} and \\{change\_file}, where \\{change\_file} contains
865 data that overrides selected portions of \\{web\_file}. The resulting merged
866 text is actually what has been called the \.{WEB} file elsewhere in this
867 report.
868
869 Here's how it works: The change file consists of zero or more ``changes,''
870 where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%
871 new lines$\rangle$\.{@z}'. The special control codes \.{@x}, \.{@y}, \.{@z},
872 which are allowed only in change files, must appear at the beginning of a line;
873 the remainder of such a line is ignored.
874 The $\langle$old lines$\rangle$ represent material that exactly matches
875 consecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$
876 represent zero or more lines that are supposed to replace the old. Whenever
877 the first ``old line'' of a change is found to match a line in the
878 \\{web\_file}, all the other lines in that change must match too.
879
880 Between changes, before the first change, and after the last change,
881 the change file can have any number of lines that do not begin with
882 `\.{@x}', `\.{@y}', or~`\.{@z}'. Such lines are bypassed and not used for
883 matching purposes.
884
885 This dual-input feature is useful when working with a master \.{WEB} file
886 that has been received from elsewhere (e.g., \.{TANGLE.WEB} or
887 \.{WEAVE.WEB} or \.{TEX.WEB}), when changes are desirable to customize the
888 program for your local computer system. You will be able to debug your
889 system-dependent changes without clobbering the master web file; and once
890 your changes are working, you will be able to incorporate them readily
891 into new releases of the master web file that you might receive from time
892 to time.
893 \section Appendices.
894 The basic ideas of \.{WEB} can be understood most easily by looking at
895 examples of ``real'' programs. Appendix~A shows the \.{WEB} input that
896 generated modules 55--59 of the \.{WEAVE} program; Appendix~B shows the
897 corresponding \TeX\ code output by \.{WEAVE}; and Appendix~C shows excerpts
898 from the corresponding \PASCAL\ code output by \.{TANGLE}.
899
900 The complete webs for \.{WEAVE} and \.{TANGLE} appear as the bulk of this
901 report, in Appendices D and~E. The reader should first compare Appendix~A
902 to the corresponding portion of Appendix~D; then the same material should
903 be compared to Appendices B and~C. Finally, if time permits, the reader may
904 enjoy studying the complete programs in Appendices D and~E, since \.{WEAVE}
905 and \.{TANGLE} contain several interesting aspects, and since an attempt
906 has been made in these appendices to evolve a style of programming that
907 makes good use of the \.{WEB} language.
908
909 Finally, Appendix F is the `\.{webmac}' file that sets \TeX\ up to accept
910 the output of \.{WEAVE}; Appendix~G discusses how to use some of its macros
911 to vary the output formats; and Appendix~H discusses what needs to be done
912 when \.{WEAVE} and \.{TANGLE} are installed in a new operating environment.
913 \section Performance statistics.
914 The programs in Appendices D and E will optionally keep statistics on
915 how much memory they require. Here is what they once printed out when
916 processing themselves:
917
918 \def\pstat#1#2#3
919 #4{\yskip\noindent\.{#1} applied to \.{#2} (cpu time #3 sec)\par
920 \halign{\quad\tt##\hfil\cr#4}}
921
922 \pstat{TANGLE}{TANGLE}{15}
923 {Memory usage statistics:\cr
924 456 names, 215 replacement texts;\cr
925 3396+3361 bytes, 6685+7329+5805 tokens.\cr}
926
927 \pstat{TANGLE}{WEAVE}{30}
928 {Memory usage statistics:\cr
929 692 names, 339 replacement texts;\cr
930 4576+4294 bytes, 10184+9875+9150 tokens.\cr}
931
932 \pstat{WEAVE}{TANGLE}{45}
933 {Memory usage statistics: 478 names, 2045 cross references, 4159+3729 bytes;\cr
934 parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
935 sorting required 34 levels.\cr}
936
937 \pstat{WEAVE}{WEAVE}{65}
938 {Memory usage statistics: 737 names, 3306 cross references, 4896+4962 bytes;\cr
939 parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
940 sorting required 73 levels.\cr}
941
942 \yskip\noindent The cpu time for \PASCAL\ to process \.{TANGLE.PAS} was
943 approximately 13 seconds, and \.{WEAVE.PAS} took approximately 26 seconds;
944 thus the tangling time was slightly more than the compiling time. The cpu
945 time for \TeX\ to process \.{TANGLE.TEX} was approximately 500 seconds,
946 and \.{WEAVE.TEX} took approximately 750 seconds (i.e., about 7
947 seconds per printed page, where these pages are substantially larger than
948 the pages in a normal book). All cpu times quoted are for a DECsystem-10.
949
950 \def\K{{\mc K}}
951 The file \.{TANGLE.WEB} is about 125\K\ characters long; \.{TANGLE}
952 reduces it to a file \.{TANGLE.PAS} whose size is about 42\K\ characters,
953 while \.{WEAVE} expands it to a file \.{TANGLE.TEX} of about 185\K\null.
954 The corresponding file sizes for \.{WEAVE.WEB}, \.{WEAVE.PAS}, and
955 \.{WEAVE.TEX} are 180\K, 89\K, and 265\K.
956
957 The much larger file \.{TEX.WEB} led to the following numbers:
958
959 \pstat{TANGLE}{TEX}{110}
960 {Memory usage statistics:\cr
961 3750 names, 1768 replacement texts;\cr
962 41895+41053 bytes, 42378+45074+41091 tokens.\cr}
963
964 \pstat{WEAVE}{TEX}{270}
965 {Memory usage statistics: 3412 names, 19699 cross references,
966 37900+40232 bytes;\cr
967 parsing required 685 scraps, 1303 texts, 3784 tokens, 104 levels;\cr
968 sorting required 52 levels.\cr}
969
970 \yskip\noindent
971 \PASCAL\ did \.{TEX.PAS} in about 75 seconds; \TeX\ did \.{TEX.TEX}
972 in about 3600.
973 % Here is a quotation that could not really be omitted
974
975 \vfill
976
977 {\baselineskip9pt
978 \halign to\hsize{\hfil\quoteit#\tabskip 0pt plus 100pt&
979 \hfil\quoteit#\tabskip 0pt\cr
980 O, what a tangled web we weave&
981 O, what a tangled WEB we weave\cr
982 When first we practise to deceive!&
983 When \TeX\ we practise to conceive!\cr
984 \noalign{\vskip 2pt}
985 \quoterm ---SIR WALTER SCOTT, {\quoteit Marmion} 6:17 (1808)&
986 \quoterm ---RICHARD PALAIS (1982)\cr
987 }}
988 \eject
989 \def\runninghead{APPENDIX A --- {\tentt WEB} FILE FORMAT}
990 \section Appendix A.
991 This excerpt from \.{WEAVE.WEB} produced modules 55--59 in Appendix~D.
992 Note that some of the lines are indented to show the program structure.
993 The indentation is ignored by \.{WEAVE} and \.{TANGLE}, but users find
994 that \.{WEB} files are quite readable if they have some such indentation.
995
996 \vskip 6pt
997 \begingroup \def\tt{\eighttt} \baselineskip9pt
998 % Note to myself: I had to remove SAIL characters from the file here!
999 % Also tabs replaced by double-space. The changes were made in WEAVE source.
1000 \verbatim
1001 @* Searching for identifiers.
1002 The hash table described above is updated by the |id_lookup| procedure,
1003 which finds a given identifier and returns a pointer to its index in
1004 |byte_start|. The identifier is supposed to match character by character
1005 and it is also supposed to have a given |ilk| code; the same name may be
1006 present more than once if it is supposed to appear in the index with
1007 different typesetting conventions.
1008 If the identifier was not already present, it is inserted into the table.
1009
1010 Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
1011 to let |id_lookup| search for an identifier that is present in the |buffer|
1012 array. Two other global variables specify its position in the buffer: the
1013 first character is |buffer[id_first]|, and the last is |buffer[id_loc-1]|.
1014
1015 @<Glob...@>=
1016 @!id_first:0..long_buf_size; {where the current identifier begins in the buffer}
1017 @!id_loc:0..long_buf_size; {just after the current identifier in the buffer}
1018 @#
1019 @!hash:array [0..hash_size] of sixteen_bits; {heads of hash lists}
1020
1021 @ Initially all the hash lists are empty.
1022
1023 @<Local variables for init...@>=
1024 @!h:0..hash_size; {index into hash-head array}
1025
1026 @ @<Set init...@>=
1027 for h:=0 to hash_size-1 do hash[h]:=0;
1028
1029 @ Here now is the main procedure for finding identifiers (and index
1030 entries). The parameter |t| is set to the desired |ilk| code. The
1031 identifier must either have |ilk=t|, or we must have
1032 |t=normal| and the identifier must be a reserved word.
1033
1034 @p function id_lookup(@!t:eight_bits):name_pointer; {finds current identifier}
1035 label found;
1036 var i:0..long_buf_size; {index into |buffer|}
1037 @!h:0..hash_size; {hash code}
1038 @!k:0..max_bytes; {index into |byte_mem|}
1039 @!w:0..ww-1; {row of |byte_mem|}
1040 @!l:0..long_buf_size; {length of the given identifier}
1041 @!p:name_pointer; {where the identifier is being sought}
1042 begin l:=id_loc-id_first; {compute the length}
1043 @<Compute the hash code |h|@>;
1044 @<Compute the name location |p|@>;
1045 if p=name_ptr then @<Enter a new name into the table at position |p|@>;
1046 id_lookup:=p;
1047 end;
1048
1049 @ A simple hash code is used: If the sequence of
1050 ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
1051 $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,|hash_size|.$$
1052
1053 @<Compute the hash...@>=
1054 h:=buffer[id_first]; i:=id_first+1;
1055 while i<id_loc do
1056 begin h:=(h+h+buffer[i]) mod hash_size; incr(i);
1057 end
1058 ?endgroup % end of verbatim mode
1059 \endgroup
1060 \vfill\eject
1061 \def\runninghead{APPENDIX B --- TRANSLATION BY {\tentt WEAVE}}
1062 \section Appendix B.
1063 This excerpt from \.{WEAVE.TEX} corresponds to Appendix A.
1064
1065 % I've inserted \vfill's here at the blank lines, to squeeze this on one page!
1066 \begingroup \def\tt{\eighttt} \baselineskip9pt
1067 \verbatim
1068 ?vfill?verbatimgobble
1069 \N55. Searching for identifiers.
1070 The hash table described above is updated by the \\{id\_lookup} procedure,
1071 which finds a given identifier and returns a pointer to its index in
1072 \\{byte\_start}. The identifier is supposed to match character by character
1073 and it is also supposed to have a given \\{ilk} code; the same name may be
1074 present more than once if it is supposed to appear in the index with
1075 different typesetting conventions.
1076 If the identifier was not already present, it is inserted into the table.
1077 ?vfill?verbatimgobble
1078 Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
1079 to let \\{id\_lookup} search for an identifier that is present in the %
1080 \\{buffer}
1081 array. Two other global variables specify its position in the buffer: the
1082 first character is $\\{buffer}[\\{id\_first}]$, and the last is $\\{buffer}[%
1083 \\{id\_loc}-1]$.
1084 ?vfill?verbatimgobble
1085 \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
1086 \4\\{id\_first}: \37$0\to\\{long\_buf\_size}$;\C{where the current identifier
1087 begins in the buffer}\6
1088 \4\\{id\_loc}: \37$0\to\\{long\_buf\_size}$;\C{just after the current
1089 identifier in the buffer}\7
1090 \4\\{hash}: \37\&{array} $[0\to\\{hash\_size}]$ \1\&{of}\5
1091 \\{sixteen\_bits};\C{heads of hash lists}\2\par
1092 \fi
1093 ?vfill?verbatimgobble
1094 \M56. Initially all the hash lists are empty.
1095 ?vfill?verbatimgobble
1096 \Y\P$\4\X16:Local variables for initialization\X\mathrel{+}\S$\6
1097 \4\|h: \37$0\to\\{hash\_size}$;\C{index into hash-head array}\par
1098 \fi
1099 ?vfill?verbatimgobble
1100 \M57. \P$\X10:Set initial values\X\mathrel{+}\S$\6
1101 \&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
1102 $\\{hash}[\|h]\K0$;\2\par
1103 \fi
1104 ?vfill?verbatimgobble
1105 \M58. Here now is the main procedure for finding identifiers (and index
1106 entries). The parameter \|t is set to the desired \\{ilk} code. The
1107 identifier must either have $\\{ilk}=\|t$, or we must have
1108 $\|t=\\{normal}$ and the identifier must be a reserved word.
1109 ?vfill?verbatimgobble
1110 \Y\P\4\&{function}\1\ \37$\\{id\_lookup}(\|t:\\{eight\_bits})$: \37\\{name%
1111 \_pointer};\C{finds current identifier}\6
1112 \4\&{label} \37\\{found};\6
1113 \4\&{var} \37\|i: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
1114 \|h: \37$0\to\\{hash\_size}$;\C{hash code}\6
1115 \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
1116 \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
1117 \|l: \37$0\to\\{long\_buf\_size}$;\C{length of the given identifier}\6
1118 \|p: \37\\{name\_pointer};\C{where the identifier is being sought}\2\6
1119 \&{begin} \37$\|l\K\\{id\_loc}-\\{id\_first}$;\C{compute the length}\6
1120 \X59:Compute the hash code \|h\X;\6
1121 \X60:Compute the name location \|p\X;\6
1122 \&{if} $\|p=\\{name\_ptr}$ \1\&{then}\5
1123 \X62:Enter a new name into the table at position \|p\X;\2\6
1124 $\\{id\_lookup}\K\|p$;\6
1125 \&{end};\par
1126 \fi
1127 ?vfill?verbatimgobble
1128 \M59. A simple hash code is used: If the sequence of
1129 ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
1130 $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,\\{hash\_size}.$$
1131 ?vfill?verbatimgobble
1132 \Y\P$\4\X59:Compute the hash code \|h\X\S$\6
1133 $\|h\K\\{buffer}[\\{id\_first}]$;\5
1134 $\|i\K\\{id\_first}+1$;\6
1135 \&{while} $\|i<\\{id\_loc}$ \1\&{do}\6
1136 \&{begin} \37$\|h\K(\|h+\|h+\\{buffer}[\|i])\mathbin{\&{mod}}\\{hash\_size}$;\5
1137 $\\{incr}(\|i)$;\6
1138 \&{end}\2\par
1139 \U section~58.\fi
1140 ?endgroup
1141 \endgroup
1142 \eject
1143 \def\runninghead{APPENDIX C --- TRANSLATION BY {\tentt TANGLE}}
1144 \section Appendix C.
1145 The \.{TANGLE} processor converts \.{WEAVE.WEB} into a syntactically
1146 correct (but not very pretty) \PASCAL\ program \.{WEAVE.PAS}.
1147 The first three and last two lines of output are shown here, together with the
1148 lines of code generated by modules 55--62 and the environments of
1149 those lines. There are 1559 lines in all; the notation
1150 `\.. \\. \\.' stands for portions that are not shown.
1151
1152 Note that, for example, the code corresponding to
1153 module 55 begins with `\.{\{55:\}}' and ends with `\.{\{:55\}}';
1154 the code from modules 59--62 has been tangled into the code from module 58.
1155
1156 \vskip6pt
1157 \verbatim
1158 {2:}{4:}{$C-,A+,D-}{[$C+,D+]}{:4}
1159 PROGRAM WEAVE(WEBFILE,CHANGEFILE,TEXFILE);LABEL 9999;CONST{8:}
1160 MAXBYTES=45000;MAXNAMES=5000;MAXMODULES=2000;HASHSIZE=353;BUFSIZE=100;
1161 . . .
1162 TOKPTR:0..MAXTOKS;{MAXTOKPTR,MAXTXTPTR:0..MAXTOKS;}{:53}{55:}
1163 IDFIRST:0..LONGBUFSIZE;IDLOC:0..LONGBUFSIZE;
1164 HASH:ARRAY[0..HASHSIZE]OF SIXTEENBITS;{:55}{63:}CURNAME:NAMEPOINTER;
1165 . . .
1166 PROCEDURE INITIALIZE;VAR{16:}I:0..127;{:16}{40:}WI:0..1;{:40}{56:}
1167 H:0..HASHSIZE;{:56}{247:}C:ASCIICODE;{:247}BEGIN{10:}HISTORY:=0;{:10}
1168 . . .
1169 TOKPTR:=1;TEXTPTR:=1;TOKSTART[0]:=1;TOKSTART[1]:=1;{MAXTOKPTR:=1;
1170 MAXTXTPTR:=1;}{:54}{57:}FOR H:=0 TO HASHSIZE-1 DO HASH[H]:=0;{:57}{94:}
1171 SCANNINGHEX:=FALSE;{:94}{102:}MODTEXT[0]:=32;{:102}{124:}OUTPTR:=1;
1172 . . .
1173 IF R=0 THEN XREF[P]:=XREFPTR ELSE XMEM[R].XLINKFIELD:=XREFPTR;END;{:51}
1174 {58:}FUNCTION IDLOOKUP(T:EIGHTBITS):NAMEPOINTER;LABEL 31;
1175 VAR I:0..LONGBUFSIZE;H:0..HASHSIZE;K:0..MAXBYTES;W:0..1;
1176 L:0..LONGBUFSIZE;P:NAMEPOINTER;BEGIN L:=IDLOC-IDFIRST;{59:}
1177 H:=BUFFER[IDFIRST];I:=IDFIRST+1;
1178 WHILE I<IDLOC DO BEGIN H:=(H+H+BUFFER[I])MOD HASHSIZE;I:=I+1;END{:59};
1179 {60:}P:=HASH[H];
1180 WHILE P<>0 DO BEGIN IF(BYTESTART[P+2]-BYTESTART[P]=L)AND((ILK[P]=T)OR((T
1181 =0)AND(ILK[P]>3)))THEN{61:}BEGIN I:=IDFIRST;K:=BYTESTART[P];W:=P MOD 2;
1182 WHILE(I<IDLOC)AND(BUFFER[I]=BYTEMEM[W,K])DO BEGIN I:=I+1;K:=K+1;END;
1183 IF I=IDLOC THEN GOTO 31;END{:61};P:=LINK[P];END;P:=NAMEPTR;
1184 LINK[P]:=HASH[H];HASH[H]:=P;31:{:60};IF P=NAMEPTR THEN{62:}
1185 BEGIN W:=NAMEPTR MOD 2;
1186 IF BYTEPTR[W]+L>MAXBYTES THEN BEGIN WRITELN(TERMOUT);
1187 WRITE(TERMOUT,'! Sorry, ','byte memory',' capacity exceeded');ERROR;
1188 HISTORY:=3;JUMPOUT;END;
1189 IF NAMEPTR+2>MAXNAMES THEN BEGIN WRITELN(TERMOUT);
1190 WRITE(TERMOUT,'! Sorry, ','name',' capacity exceeded');ERROR;HISTORY:=3;
1191 JUMPOUT;END;I:=IDFIRST;K:=BYTEPTR[W];
1192 WHILE I<IDLOC DO BEGIN BYTEMEM[W,K]:=BUFFER[I];K:=K+1;I:=I+1;END;
1193 BYTEPTR[W]:=K;BYTESTART[NAMEPTR+2]:=K;NAMEPTR:=NAMEPTR+1;ILK[P]:=T;
1194 XREF[P]:=0;END{:62};IDLOOKUP:=P;END;{:58}{66:}
1195 FUNCTION MODLOOKUP(L:SIXTEENBITS):NAMEPOINTER;LABEL 31;VAR C:0..4;
1196 . . .
1197 WRITE(TERMOUT,'(That was a fatal error, my friend.)');END;END{:263};
1198 END.{:261}
1199 ?endgroup
1200 \vfill\eject
1201 \pageno=200 % take account of the page numbers for App's D and E.
1202 \def\runninghead{APPENDIX F --- MACROS FOR FORMATTING}
1203 \section Appendix F: The \.{webmac.tex} file.
1204 This is the file that extends ``plain \TeX'' format in order to support the
1205 features needed by the output of \.{WEAVE}.
1206
1207 \vskip6pt
1208 \verbatim
1209 % standard macros for WEB listings (in addition to PLAIN.TEX)
1210 \xdef\fmtversion{\fmtversion+WEBMAC4.0} % identifies current set of macros
1211 \parskip 0pt % no stretch between paragraphs
1212 \parindent 1em % for paragraphs and for the first line of Pascal text
1213
1214 \font\eightrm=cmr8 \let\sc=\eightrm % NOT a caps-and-small-caps font!
1215 \let\mainfont=\tenrm
1216 \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
1217 \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
1218 \font\tentex=cmtex10 % TeX extended character set (used in strings)
1219
1220 \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
1221 \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
1222 \def\&#1{\hbox{\bf#1\/}} % boldface type for reserved words
1223 \def\.#1{\hbox{\tentex % typewriter type for strings
1224 \let\\=\BS % backslash in a string
1225 \let\'=\RQ % right quote in a string
1226 \let\`=\LQ % left quote in a string
1227 \let\{=\LB % left brace in a string
1228 \let\}=\RB % right brace in a string
1229 \let\~=\TL % tilde in a string
1230 \let\ =\SP % space in a string
1231 \let\_=\UL % underline in a string
1232 \let\&=\AM % ampersand in a string
1233 #1}}
1234 \def\#{\hbox{\tt\char`\#}} % parameter sign
1235 \def\${\hbox{\tt\char`\$}} % dollar sign
1236 \def\%{\hbox{\tt\char`\%}} % percent sign
1237 \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
1238 % circumflex accents can be obtained from \^^D instead of \^
1239 \def\AT!{@} % at sign for control text
1240
1241 \chardef\AM=`\& % ampersand character in a string
1242 \chardef\BS=`\\ % backslash in a string
1243 \chardef\LB=`\{ % left brace in a string
1244 \def\LQ{{\tt\char'22}} % left quote in a string
1245 \chardef\RB=`\} % right brace in a string
1246 \def\RQ{{\tt\char'23}} % right quote in a string
1247 \def\SP{{\tt\char`\ }} % (visible) space in a string
1248 \chardef\TL=`\~ % tilde in a string
1249 \chardef\UL=`\_ % underline character in a string
1250
1251 \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
1252 \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
1253
1254 \newcount\ind % current indentation in ems
1255 \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
1256 \def\2{\global\advance\ind by-1} % indent one less notch
1257 \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
1258 \def\4{\copy\bak} % backspace one notch
1259 \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
1260 \def\6{\ifmmode\else\par % forced break
1261 \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
1262 \def\7{\Y\6} % forced break and a little extra space
1263
1264 \let\yskip=\smallskip
1265 \def\to{\mathrel{.\,.}} % double dot, used only in math mode
1266 \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
1267 \def\lapstar{\rlap{*}}
1268 \def\startsection{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
1269 \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
1270 \def\A{\note{See also section}} % crossref for doubly defined section name
1271 \def\As{\note{See also sections}} % crossref for multiply defined section name
1272 \def\B{\mathopen{\.{@\{}}} % begin controlled comment
1273 \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % Pascal comments
1274 \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
1275 \def\D{\defin{define}} % macro definition
1276 \def\E{\cdot10^} % exponent in floating point constant
1277 \def\ET{ and~} % conjunction between two section numbers
1278 \def\ETs{, and~} % conjunction between the last two of several section numbers
1279 \def\F{\defin{format}} % format definition
1280 \let\G=\ge % greater than or equal sign
1281 \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
1282 \let\I=\ne % unequal sign
1283 \def\J{\.{@\&}} % TANGLE's join operation
1284 \let\K=\gets % left arrow
1285 \let\L=\le % less than or equal sign
1286 \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
1287 \vskip12ptminus3pt\startsection\ignorespaces}
1288 \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
1289 \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
1290 \message{*\modno} % progress report
1291 \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
1292 \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
1293 \def\MN#1.{\par % common code for \M, \N
1294 {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}
1295 \ifx\modno\modstar \onmaybe \else\ontrue \fi \mark{\modno}}
1296 \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
1297 \def\P{\rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
1298 \sfcode`;=3000
1299 \pretolerance 10000
1300 \hyphenpenalty 10000 \exhyphenpenalty 10000
1301 \global\ind=2 \1\ \unskip}
1302 \def\Q{\rightskip=0pt % get out of Pascal mode
1303 \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
1304 \let\R=\lnot % logical not
1305 \let\S=\equiv % equivalence sign
1306 \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
1307 \def\U{\note{This code is used in section}} % crossref for use of a section
1308 \def\Us{\note{This code is used in sections}} % crossref for uses of a section
1309 \let\V=\lor % logical or
1310 \let\W=\land % logical and
1311 \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
1312 \XX$\langle\,$#2{\eightrm\kern.5em#1}$\,\rangle$\XX}
1313 \def\Y{\par\yskip}
1314 \let\Z=\let % now you can \send the control sequence \Z
1315 \def\){\hbox{\.{@\$}}} % sign for string pool check sum
1316 \def\]{\hbox{\.{@\\}}} % sign for forced line break
1317 \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
1318 \hbox{\strut\kern2pt\.{#1}\kern2pt}}
1319 \hrule}\vrule}\kern2pt} % verbatim string
1320 \let\~=\ignorespaces
1321 \let\*=*
1322
1323 \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
1324 \newif\ifon \newif\iftitle \newif\ifpagesaved
1325 \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
1326 \tensy x\mainfont\topmark} % top line on left-hand pages
1327 \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
1328 \qquad\mainfont\the\pageno} % top line on right-hand pages
1329 \def\page{\box255 }
1330 \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
1331 \shipout\vbox{
1332 \vbox to\fullpageheight{
1333 \iftitle\global\titlefalse
1334 \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
1335 \vfill#1}} % parameter #1 is the page itself
1336 \global\advance\pageno by1}
1337
1338 \def\rhead{\.{WEB} OUTPUT} % this running head is reset by starred sections
1339 \def\title{} % an optional title can be set by the user
1340 \def\topofcontents{\centerline{\titlefont\title}
1341 \vfill} % this material will start the table of contents page
1342 \def\botofcontents{\vfill} % this material will end the table of contents page
1343 \def\contentspagenumber{0} % default page number for table of contents
1344 \newdimen\pagewidth \pagewidth=6.5in % the width of each page
1345 \newdimen\pageheight \pageheight=8.7in % the height of each page
1346 \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
1347 \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
1348 \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
1349 \fullpageheight=9truein\setpage}
1350 \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
1351 \def\contentsfile{CONTENTS} % file that gets table of contents info
1352 \def\readcontents{\input CONTENTS}
1353
1354 \newwrite\cont
1355 \output{\setbox0=\page % the first page is garbage
1356 \openout\cont=\contentsfile
1357 \global\output{\normaloutput\page\lheader\rheader}}
1358 \setpage
1359 \vbox to \vsize{} % the first \topmark won't be null
1360
1361 \def\ch{\note{The following sections were changed by the change file:}
1362 \let\*=\relax}
1363 \newbox\sbox % saved box preceding the index
1364 \newbox\lbox % lefthand column in the index
1365 \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
1366 \write\cont{} % ensure that the contents file isn't empty
1367 \closeout\cont % the contents information has been fully gathered
1368 \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
1369 \global\setbox\sbox=\page \global\pagesavedtrue}
1370 \pagesavedfalse \eject % eject the page-so-far and predecessors
1371 \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
1372 \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
1373 \hsize=.5\pagewidth \advance\hsize by -10pt
1374 % column width for the index (20pt between cols)
1375 \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
1376 \def\lr{L} % this tells whether the left or right column is next
1377 \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
1378 \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
1379 \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
1380 \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
1381 \message{Index:}
1382 \parskip 0pt plus .5pt
1383 \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
1384 \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
1385 \def\[##1]{$\underline{##1}$} % underlined index item
1386 \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
1387 \hyphenpenalty 10000 \parindent0pt}
1388 \def\fin{\par\vfill\eject % this is done when we are ending the index
1389 \ifpagesaved\null\vfill\eject\fi % output a null index column
1390 \if L\lr\else\null\vfill\eject\fi % finish the current page
1391 \parfillskip 0pt plus 1fil
1392 \def\rhead{NAMES OF THE SECTIONS}
1393 \message{Section names:}
1394 \output{\normaloutput\page\lheader\rheader}
1395 \setpage
1396 \def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\eightrm##1 ##2.}}
1397 \linepenalty=10 % try to conserve lines
1398 \def\U{\note{Used in section}} % crossref for use of a section
1399 \def\Us{\note{Used in sections}} % crossref for uses of a section
1400 \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry}
1401 \def\con{\par\vfill\eject % finish the section names
1402 \rightskip 0pt \hyphenpenalty 50 \tolerance 200
1403 \setpage
1404 \output{\normaloutput\page\lheader\rheader}
1405 \titletrue % prepare to output the table of contents
1406 \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
1407 \message{Table of contents:}
1408 \topofcontents
1409 \line{\hfil Section\hbox to3em{\hss Page}}
1410 \def\Z##1##2##3{\line{\ignorespaces##1
1411 \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
1412 \readcontents\relax % read the contents info
1413 \botofcontents \end} % print the contents page(s) and terminate
1414 ?endgroup
1415 \vfill\eject
1416 \def\runninghead{APPENDIX G --- NOTES ON FORMATTING}
1417 \section Appendix G: How to use \.{WEB} macros.
1418 The macros in \.{webmac} make it possible to produce a variety of formats
1419 without editing the output of \.{WEAVE}, and the purpose of this appendix
1420 is to explain some of the possibilities.
1421
1422 \def\point#1.{\yskip\indent#1.\quad\ignorespaces}
1423
1424 \point 1. Three fonts have been declared in addition to the standard fonts of
1425 \.{PLAIN} format: You can say `\.{\{\\sc STUFF\}}' to get {\sc STUFF}
1426 in small caps; and you can select the largish fonts \.{\\titlefont}
1427 and \.{\\ttitlefont} in the title of your document, where \.{\\ttitlefont}
1428 is a typewriter style of type.
1429
1430 \point 2. When you mention an identifier in \TeX\ text, you normally call
1431 it `\.{|identifier|}'. But you can also say `\.{\\\\\{identifier\}}'. The
1432 output will look the same in both cases, but the second alternative
1433 doesn't put \\{identifier} into the index, since
1434 it bypasses \.{WEAVE}'s translation from \PASCAL\ mode.
1435
1436 \point 3. To get typewriter-like type, as when referring to `\.{WEB}', you
1437 can use the `\.{\\.}' macro (e.g., `\.{\\.\{WEB\}}'). In the argument to
1438 this macro you should insert an additional backslash before the symbols
1439 listed as `special string characters' in the index to \.{WEAVE}, i.e.,
1440 before backslashes and dollar signs and the like.
1441 A `\.{\\\ }' here will result in the visible space symbol; to get an
1442 invisible space following a control sequence you can say `\.{\{\ \}}'.
1443
1444 \point 4. The three control sequences \.{\\pagewidth}, \.{\\pageheight},
1445 and \.{\\fullpageheight} can be redefined in the limbo section at the
1446 beginning of your \.{WEB} file, to change the dimensions of each page.
1447 The standard settings
1448 $$\lpile{\.{\\pagewidth=6.5in}\cr
1449 \.{\\pageheight=8.7in}\cr
1450 \.{\\fullpageheight=9in}\cr}$$
1451 were used to prepare the present report; \.{\\fullpageheight} is
1452 \.{\\pageheight} plus room for the additional heading and page numbers at
1453 the top of each page. If you change any of these quantities, you should
1454 call the macro \.{\\setpage} immediately after making the change.
1455
1456 \point 5. The \.{\\pageshift} macro defines an amount by which right-hand
1457 pages (i.e., odd-numbered pages) are shifted right with respect to
1458 left-hand (even-numbered) ones. By adjusting this amount you may be
1459 able to get two-sided output in which the page numbers line up on
1460 opposite sides of each sheet.
1461
1462 \point 6. The \.{\\title} macro will appear at the top of each page
1463 in small caps. For example, Appendix~D was produced after saying
1464 `\.{\\def\\title\{WEAVE\}}'.
1465
1466 \point 7. The first page usually is assigned page number 1.
1467 To start on page 16, with contents
1468 on page 15, say this: `\.{\\def\\contentspagenumber\{15\}}
1469 \.{\\pageno=\\contentspagenumber} \.{\\advance\\pageno by 1}'. (Appendix~D
1470 was generated that way.)
1471
1472 \point 8. The macro \.{\\iftitle} will suppress the header line if it is
1473 defined by `\.{\\titletrue}'. The normal value is \.{\\titlefalse}
1474 except for the table of contents; thus, the contents
1475 page is usually unnumbered.
1476
1477 Two macros are provided to give flexibility to the table of
1478 contents: \.{\\topofcontents} is invoked just before the contents
1479 info is read, and \.{\\botofcontents} is invoked just after.
1480 For example, Appendix~D was produced with the following definitions:
1481 $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
1482 \.{ { }\\titlefalse \% include headline on the contents page}\cr
1483 \.{ { }\\def\\rheader\{\\mainfont Appendix D\\hfil 15\}}\cr
1484 \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
1485 \.{ { }\\vskip 15pt \\centerline\{(Version 4)\}{ }\\vfill\}}\cr}$$
1486 Redefining \.{\\rheader}, which is the headline for right-hand pages,
1487 suffices in this case to put the desired information at the top of the
1488 contents page.
1489
1490 \point 9. Data for the table of contents is written to a file that
1491 is read after the indexes have been \TeX ed; there's one line of data
1492 for every starred module. For example, when Appendix~D was being generated,
1493 a file \.{CONTENTS.TEX} containing
1494 $$\lpile{\.{\\Z \{{ }Introduction\}\{1\}\{16\}}\cr
1495 \.{\\Z \{{ }The character set\}\{11\}\{19\}}\cr}$$
1496 and similar lines was created. The \.{\\topofcontents} macro could
1497 redefine \.{\\Z} so that the information appears in another format.
1498
1499 \point 10. Sometimes it is necessary or desirable to divide the output of
1500 \.{WEAVE} into subfiles that can be processed separately. For example,
1501 the listing of \TeX\ runs to more than 500 pages, and that is enough to
1502 exceed the capacity of many printing devices and/or their software.
1503 When an extremely large job isn't cut into smaller pieces, the entire
1504 process might be spoiled by a single error of some sort, making it
1505 necessary to start everything over.
1506
1507 Here's a safe way to break a woven file into three parts:
1508 Say the pieces are $\alpha$,
1509 $\beta$, and $\gamma$, where each piece begins with a starred module.
1510 All macros should be defined in the opening limbo section of $\alpha$,
1511 and copies of this \TeX\ code should be placed at the
1512 beginning of $\beta$ and of $\gamma$. In order to process the parts
1513 separately, we need to take care of two things: The starting page
1514 numbers of $\beta$ and $\gamma$ need to be set up properly, and
1515 the table of contents data from all three runs needs to be
1516 accumulated.
1517
1518 The \.{webmac} macros include two control sequences \.{\\contentsfile} and
1519 \.{\\readcontents} that facilitate the necessary processing. We include
1520 `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of $\alpha$, and
1521 we include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of
1522 $\beta$; this causes \TeX\ to write the contents data for $\alpha$ and $\beta$
1523 into \.{CONT1.TEX} and \.{CONT2.TEX}. Now in $\gamma$ we say
1524 $$\.{\\def\\readcontents\{\\input CONT1 \\input CONT2 \\input CONTENTS\}};$$
1525 this brings in the data from all three pieces, in the proper order.
1526
1527 However, we still need to solve the page-numbering problem. One way to
1528 do it is to include the following in the limbo material for $\beta$:
1529 $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
1530 \.{\\read -1 to \\temp \\pageno=\\temp \\advance\\pageno by 1}\cr}$$
1531 Then you simply provide the necessary data when \TeX\ requests
1532 it; a similar construction is used at the beginning of $\gamma$.
1533
1534 This method can, of course, be used to divide a woven file into
1535 any number of pieces.
1536
1537 \point 11. Sometimes it is nice to include things in the index that are
1538 typeset in a special way. For example, we might want to have an
1539 index entry for `\TeX'. \.{WEAVE} provides two simple ways to
1540 typeset an index entry (unless the entry is an identifier or a reserved word):
1541 `\.{@\^}' gives roman type, and `\.{@.}' gives typewriter type.
1542 But if we try to typeset `\TeX' in roman type by saying, e.g.,
1543 `\.{@\^\\TeX@>}', the backslash character gets in the way,
1544 and this entry wouldn't appear in the index with the T's.
1545
1546 The solution is to use the `\.{@:}' feature, declaring a macro that
1547 simply removes a sort key as follows:
1548 $$\.{\\def\\9\#1\{\}}$$
1549 Now you can say, e.g., `\.{@:TeX\}\{\\TeX@>}' in your \.{WEB} file; \.{WEAVE}
1550 puts it into the index alphabetically, based on the sort key, and
1551 produces the macro call `\.{\\9\{TeX\}\{\\TeX\}}' which will ensure that
1552 the sort key isn't printed.
1553
1554 A similar idea can be used to insert hidden material into module
1555 names so that they are alphabetized in whatever way you might wish.
1556 Some people call these tricks ``special refinements''; others call
1557 them ``kludges''.
1558
1559 \point 12. The control sequence \.{\\modno} is set to the number of the
1560 module being typeset.
1561
1562 \point 13. If you want to list only the modules that have changed,
1563 together with the index, put the command `\.{\\let\\maybe=\\iffalse}' in
1564 the limbo section before the first module of your \.{WEB} file. It's
1565 customary to make this the first change in your change file.
1566
1567 \point 14. To get output in languages other than English, redefine the
1568 macros \.{\\A}, \.{\\As}, \.{\\ET}, \.{\\ETs}, \.{\\U}, \.{\\Us},
1569 \.{\\ch}, \.{\\fin}, and \.{\\con}. \.{WEAVE} itself need not be changed.
1570
1571 \vfill\eject
1572 \def\runninghead{APPENDIX H --- GETTING STARTED}
1573 \section Appendix H: Installing the \.{WEB} system.
1574 Suppose you want to use the \.{WEB} programs on your computer, and suppose
1575 that you can't simply borrow them from somebody else who has the same
1576 kind of machine. Here's what to do:
1577
1578 \yskip
1579 \def\step(#1){\par\hangindent 2em\noindent\hbox to 2em{\hfil(#1) }\ignorespaces}
1580 \step(1) Get a tape that contains the files \.{WEAVE.WEB}, \.{TANGLE.WEB},
1581 \.{TANGLE.PAS}, and \.{WEBMAC.TEX}. The tape will probably also contain an
1582 example change file \.{TANGLE.CH}.
1583 \step(2) Look at the sections of \.{TANGLE} that are listed under ``system
1584 dependencies'' in the index of Appendix~E above, and figure out what changes
1585 (if any) will be needed for your system.
1586 \step(3) Make a change file \.{TANGLE.CH} that contains the changes of~(2);
1587 do not change your copy of \.{TANGLE.WEB}, leave it intact. (The
1588 rules for change files are explained at the end of the manual just before
1589 the appendices; you may want to look at the example change file that
1590 arrived with your copy of \.{TANGLE.WEB}. It's also a good idea to
1591 define all the ``switches'' like \&{debug} and \&{gubed} to be null in your
1592 first change files; then you can sure that your compiler will handle
1593 all of the code.)
1594 \step(4) Make the changes of (2) in your copy of \.{TANGLE.PAS}. (If these
1595 changes are extensive, you might be better off finding some computer
1596 that already has \.{TANGLE} running, and making the new \.{TANGLE.PAS}
1597 from \.{TANGLE.WEB} and your \.{TANGLE.CH}.)
1598 \step(5) Use your \PASCAL\ compiler to convert your copy of \.{TANGLE.PAS}
1599 to a running program \.{TANGLE}.
1600 \step(6) Check your changes as follows: Run \.{TANGLE} on \.{TANGLE.WEB}
1601 and your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}'$; make a running
1602 program $\.{TANGLE}'$ by applying \PASCAL\ to
1603 $\.{TANGLE.PAS}'$; run $\.{TANGLE}'$ on \.{TANGLE.WEB} and
1604 your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}''$; and check
1605 that $\.{TANGLE.PAS}''$ is identical to
1606 $\.{TANGLE.PAS}'$. Once this test has been passed, you have got a
1607 working \.{TANGLE} program.
1608 \step(7) Make a change file \.{WEAVE.CH} analogous to (3), but this time
1609 consider the system-dependent parts of \.{WEAVE} that are listed in
1610 the index to Appendix~D.
1611 \step(8) Run \.{TANGLE} on \.{WEAVE.WEB} and your \.{WEAVE.CH}, obtaining
1612 \.{WEAVE.PAS}.
1613 \step(9) Use \PASCAL\ on \.{WEAVE.PAS} to make a running \.{WEAVE} program.
1614 \step(10) Run \.{WEAVE} on \.{TANGLE.WEB} and \.{TANGLE.CH} to produce
1615 \.{TANGLE.TEX}.
1616 \step(11) Run \TeX\ on \.{TANGLE.TEX}, obtaining a listing analogous to
1617 Appendix~E. This listing will incorporate your changes.
1618 \step(12) Run \.{WEAVE} on \.{WEAVE.WEB} and your \.{WEAVE.CH} to produce
1619 \.{WEAVE.TEX}.
1620 \step(13) Run \TeX\ on \.{WEAVE.TEX}, obtaining a listing analogous to
1621 Appendix~D that incorporates your changes.
1622
1623 \yskip\noindent
1624 This description assumes that you already have a working \TeX82 system.
1625 But what if you don't have \TeX82? Then you start with a tape that also
1626 contains \.{TEX.WEB} and \.{plain.tex}, and you refer to a hardcopy
1627 listing of the \TeX82 program corresponding to \.{TEX.WEB}. Between steps
1628 (10) and (11) you do the following:
1629
1630 \yskip
1631 \def\substep(10.#1){\par\hangindent 4em\noindent
1632 \hbox to 4em{\hfil(10.#1) }\ignorespaces}
1633 \substep(10.1) Make a change file \.{TEX.CH} to fix the system dependent
1634 portions of \.{TEX.WEB}, in a manner analogous to step~(2). Since \TeX\ is
1635 a much more complex program than \.{WEAVE} or \.{TANGLE}, there are more
1636 system-dependent features to think about, but by now you will be good at
1637 making such modifications. Do not make any changes to \.{TEX.WEB}.
1638 \substep(10.2) Make an almost-copy of your \.{TEX.CH} called \.{INITEX.CH};
1639 this one will have the `\&{init}' and `\&{tini}' macros redefined in order
1640 to make the initialization version of \TeX. It also might have smaller
1641 font memory and dynamic memory areas, since \.{INITEX} doesn't need as
1642 much memory for such things; by setting the memory smaller in \.{INITEX},
1643 you guarantee that the production system will have a ``cushion.''
1644 \substep(10.3) Run \.{TANGLE} on \.{TEX.WEB} and \.{INITEX.CH}, obtaining
1645 \.{INITEX.PAS} and \.{TEX.POOL}.
1646 \substep(10.4) Run \PASCAL\ on \.{INITEX.PAS}, obtaining \.{INITEX}.
1647 \substep(10.5) Run \.{INITEX} on \.{TEX.POOL}, during which run you type
1648 `\.{plain}' and `\.{\\dump}'. This will produce a file \.{plain.fmt}
1649 containing the data needed to initialize \TeX's memory.
1650 \substep(10.6) Run \.{TANGLE} on \.{TEX.WEB} and the \.{TEX.CH} of (10.1),
1651 obtaining \.{TEX.PAS}.
1652 \substep(10.7) Run \PASCAL\ on \.{TEX.PAS}, obtaining \.{VIRTEX}.
1653 \substep(10.8) If your operating system supports programs whose core images
1654 have been saved, run \.{VIRTEX}, type `\.{\&plain}', then save the core image
1655 and call it \TeX. Otherwise, \.{VIRTEX} will be your \TeX, and it will
1656 read `\.{plain.fmt}' (or some other \.{fmt} file) each time you run.
1657
1658 \yskip
1659 This 21-step process may seem long, but it is actually an oversimplification,
1660 since you also need fonts and a way to print the device-independent files
1661 that \TeX\ spews out. On the other hand, the total number of steps is not
1662 quite so large when you consider that \.{TANGLE}-followed-by-\PASCAL\ and
1663 \.{WEAVE}-followed-by-\TeX\ may be regarded as single operations.
1664
1665 If you have only the present report, not a tape, you will have to prepare
1666 files \.{WEAVE.WEB} and \.{TANGLE.WEB} by hand, typing them into the
1667 computer by following Appendices D and E. Then you have to simulate the
1668 behavior of \.{TANGLE} by converting \.{TANGLE.WEB} manually into
1669 \.{TANGLE.PAS}; with a good text editor this takes about six hours. Then
1670 you have to correct errors that were made in all this hand work; but still
1671 the whole project is not impossibly difficult, because in fact the entire
1672 development of \.{WEAVE} and \.{TANGLE} (including the writing of the
1673 programs and this manual) took less than two months of work.
1674 \vfill\end