Debian Codegraph @

texmf-dist/doc/generic/midnight/loop.doc

raw
1 % loop.doc --- version 1.0 (15 April 1991)
2 % This is the documentation for loop.tex.
3 % To read this file, process it with (plain) TeX: tex loop.doc
4 % (To do that, you need manmac.tex, which has
5 % the macros for typesetting the TeXbook, as explained in appendix E.
6 % It comes free with the standard distribution of TeX.)
7 %
8 % NOTE: Processing this file with TeX will create empty files
9 % index.tex and answers.tex in your directory. And if you
10 % have a file pages.tex in your directory, TeX will probably
11 % get very confused.
12 % The manmac format will try to load a font called cmman; if
13 % TeX complains that it cannot find that font you can savely
14 % ignore that, since the font is not actually used.
15 %
16 % This file: copyright (c) 1991 Marcel van der Goot.
17 % You may redistribute this file and printed versions of it.
18 %
19 % original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex
20 % (use anonymous ftp). Also in various archives.
21 %
22 % Marcel van der Goot
23 % [email protected]
24 % Caltech 256--80
25 % Pasadena, CA 91125
26 % (818) 356--4603
27
28 % ------ definitions for manual pages:
29 % The documentation is typeset using Knuth's ``manmac'' macros, with a
30 % few additional things defined here. You are free to use or adapt these
31 % extra definitions.
32
33 \input manmac % the macros used for typesetting The TeXbook (appendix E)
34 \catcode`^=7 % manmac makes ^ active for creating an index
35 % we don't make an index, and we need ^ to be non-active
36
37 {\catcode`\^^M=12 \endlinechar=-1 % 12 = other
38 \long\gdef\manpagehead#1^^M#2^^M#3^^M^^M% tex-file, description, version
39 {\egroup % matches \bgroup in \manpage
40 \par\vfill\eject
41 \edef\rhead{\manualname: #1\unskip}%
42 \setbox1=\hbox{\titlefont #1\quad}%
43 \setbox3=\vtop{\advance\hsize by-\wd1 \parindent=0pt \raggedright
44 #2\par
45 #3\par
46 \cnotice
47 }%
48 \line{\box1\box3}%
49 \bigskip\bigskip\bigskip\noindent
50 }%
51 } % restore \catcode`\^^M
52
53 \outer\def\manpage
54 {\bgroup\catcode`\^^M=12
55 \manpagehead
56 }
57
58 \hsize=6.5in\vsize=8.9in % default plain TeX values
59 \pagewidth=\hsize \pageheight=\vsize
60
61 \def\cnotice{Copyright \copyright\ 1991 Marcel R. van der Goot}
62 \def\manualname{Midnight Macros}
63
64 % LaTeX logo, from latex.tex (except for the capital `A': manmac
65 % doesn't have a real smallcaps font)
66 \def\LaTeX{{\rm L\kern-.36em\raise.3ex\hbox{\sc A}\kern-.15em
67 T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
68
69 \tenpoint
70
71 % (end of extra definitions)
72
73 % -------------------- loop.doc:
74
75 \pageno=8 % follows gloss.doc
76
77 \manpage loop.tex
78 A simple looping construct (meta-macros).
79 Version: 1.0 (15 April 1991) (doc: 15 Apr 1991)
80
81 The macros in loop.tex are intended to help you write your own
82 macros, rather than to typeset text directly. Consequently, it is
83 assumed that you have some experience writing macros; In other words,
84 assume that this whole section is preceded by a ``dangerous bend'' symbol.
85 These macros are kept
86 simple and are not very robust: if you decide
87 to use them in a different way than described below you are
88 entirely responsible for what happens\footnote{$^1$}{Not that the
89 author assumes any responsibility even if you {\sl do\/}
90 obey the rules.}.
91
92 Loop.tex defines an alternative to plain \TeX's |\loop| construct.
93 (It can also be used with, e.g., \LaTeX.)
94 Plain \TeX's |\loop| is often awkward to use because of the
95 limited form of tests in \TeX. The new construct tries to alleviate
96 this problem by allowing a more flexible use of tests in the loop.
97 To execute a loop, you say |\Loop ... \Pool|\footnote{$^2$}{We use
98 initial capital letters to prevent confusion with plain \TeX's |\loop|.
99 Although you don't need |\loop| anymore, there may still be macros
100 that depend on it (e.g., plain \TeX's tabbing macros).}.
101 This will normally
102 execute the loop `body', i.e., the commands corresponding to the dots,
103 infinitely many times.
104 There are two special commands you can use within the loop,
105 |\Break| and |\Continue|. When a |\Break| command is
106 executed, the rest of the body is ignored, and the loop is terminated.
107 Execution of a |\Continue| command also causes the rest of the body
108 to be ignored, but then the loop is started again from the beginning.
109
110 Both |\Break| and |\Continue| must be followed by a number. This
111 number should be the number of |\if...| constructs that are terminated
112 by the command. In other words, it is the number of |\fi|'s that
113 has to be `executed' to get proper balancing of all |\if...| tests.
114 It is somewhat unfortunate that this number has to be supplied,
115 but there seems to be no way to close all |\if...| tests automatically.
116 Here is an example similar to one from the \TeX book.
117 \begintt
118 \def\yes{Yes } \def\no{No }
119 \Loop\message{Are you happy? }
120 \read-1 to\answer
121 \ifx\answer\yes \Break1
122 \else\ifx\answer\no \Continue2
123 \fi \fi
124 \message{(Please type Yes or No.)}
125 \Pool
126 \endtt
127 At the position of |\Break| the nesting level of |\if...| tests
128 is 1, at the position of |\Continue| the level is 2.
129 If you forget the number you will (usually) get a `|missing number|' error
130 message, but possibly at an unexpected point in the program. The
131 wrong number typically results in either an `|Extra \fi|' or
132 an `|\if... was incomplete|' message.
133
134 There can be any number of |\Break| and |\Continue| commands in
135 a loop, although it is wise to have at least one |\Break| command.
136 The text following any of these commands up till the |\Pool| at the
137 end of the loop must have balanced braces, and the loop body itself
138 must also have balanced braces. If this causes a problem, you
139 can use |\bgroup| and |\egroup| instead of |{| and |}|. If you
140 want to nest two loops, you will have to enclose the inner loop within
141 a group. (Incidentally, these restrictions on balancing braces and
142 nesting loops also apply to plain \TeX's |\loop| construct.)
143
144 \bye