source: git/doc/texinfo.tex @ f5a734

spielwiese
Last change on this file since f5a734 was f36635, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* merged in changes from 1-2-3 git-svn-id: file:///usr/local/Singular/svn/trunk@3207 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 184.2 KB
Line 
1% texinfo.tex -- TeX macros to handle Texinfo files.
2%
3% Load plain if necessary, i.e., if running under initex.
4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
5%
6\def\texinfoversion{1999-02-21.16}%
7%
8% Copyright (C) 1985, 86, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
9% Free Software Foundation, Inc.
10%
11% This texinfo.tex file is free software; you can redistribute it and/or
12% modify it under the terms of the GNU General Public License as
13% published by the Free Software Foundation; either version 2, or (at
14% your option) any later version.
15%
16% This texinfo.tex file is distributed in the hope that it will be
17% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19% General Public License for more details.
20%
21% You should have received a copy of the GNU General Public License
22% along with this texinfo.tex file; see the file COPYING.  If not, write
23% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24% Boston, MA 02111-1307, USA.
25%
26% In other words, you are welcome to use, share and improve this program.
27% You are forbidden to forbid anyone else to use, share and improve
28% what you give them.   Help stamp out software-hoarding!
29%
30% Please try the latest version of texinfo.tex before submitting bug
31% reports; you can get the latest version from:
32%   ftp://ftp.gnu.org/pub/gnu/texinfo.tex
33%   (and all GNU mirrors, see http://www.gnu.org/order/ftp.html)
34%   ftp://tug.org/tex/texinfo.tex
35%   ftp://ctan.org/macros/texinfo/texinfo.tex
36%   (and all CTAN mirrors, finger ctan@ctan.org for a list).
37%   /home/gd/gnu/doc/texinfo.tex on the GNU machines.
38% The texinfo.tex in any given Texinfo distribution could well be out
39% of date, so if that's what you're using, please check.
40% There is a small home page for Texinfo at http://texinfo.org/.
41%
42% Send bug reports to bug-texinfo@gnu.org.  Please include including a
43% complete document in each bug report with which we can reproduce the
44% problem.  Patches are, of course, greatly appreciated.
45%
46% To process a Texinfo manual with TeX, it's most reliable to use the
47% texi2dvi shell script that comes with the distribution.  For a simple
48% manual foo.texi, however, you can get away with this:
49%   tex foo.texi
50%   texindex foo.??
51%   tex foo.texi
52%   tex foo.texi
53%   dvips foo.dvi -o # or whatever, to process the dvi file; this makes foo.ps.
54% The extra runs of TeX get the cross-reference information correct.
55% Sometimes one run after texindex suffices, and sometimes you need more
56% than two; texi2dvi does it as many times as necessary.
57%
58% It is possible to adapt texinfo.tex for other languages.  You can get
59% the existing language-specific files from ftp://ftp.gnu.org/gnu/texinfo/.
60
61\message{Loading texinfo [version \texinfoversion]:}
62
63% If in a .fmt file, print the version number
64% and turn on active characters that we couldn't do earlier because
65% they might have appeared in the input file name.
66\everyjob{\message{[Texinfo version \texinfoversion]}%
67  \catcode`+=\active \catcode`\_=\active}
68
69% Save some parts of plain tex whose names we will redefine.
70
71\let\ptexb=\b
72\let\ptexbullet=\bullet
73\let\ptexc=\c
74\let\ptexcomma=\,
75\let\ptexdot=\.
76\let\ptexdots=\dots
77\let\ptexend=\end
78\let\ptexequiv=\equiv
79\let\ptexexclam=\!
80\let\ptexi=\i
81\let\ptexlbrace=\{
82\let\ptexrbrace=\}
83\let\ptexstar=\*
84\let\ptext=\t
85
86% We never want plain's outer \+ definition in Texinfo.
87% For @tex, we can use \tabalign.
88\let\+ = \relax
89
90
91\message{Basics,}
92\chardef\other=12
93
94% If this character appears in an error message or help string, it
95% starts a new line in the output.
96\newlinechar = `^^J
97
98% Set up fixed words for English if not already set.
99\ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
100\ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
101\ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
102\ifx\putwordIndexIsEmpty\undefined     \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
103\ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
104\ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
105\ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
106\ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
107\ifx\putwordof\undefined        \gdef\putwordof{of}\fi
108\ifx\putwordon\undefined        \gdef\putwordon{on}\fi
109\ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
110\ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
111\ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
112\ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
113\ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
114\ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
115\ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
116%
117\ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
118\ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
119\ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
120\ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
121\ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
122\ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
123\ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
124\ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
125\ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
126\ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
127\ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
128\ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
129%
130\ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
131\ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
132\ifx\putwordDefivar\undefined   \gdef\putwordDefivar{Instance Variable}\fi
133\ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
134\ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
135\ifx\putwordDeftypevar\undefined\gdef\putwordDeftypevar{Variable}\fi
136\ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
137\ifx\putwordDeftypefun\undefined\gdef\putwordDeftypefun{Function}\fi
138
139% Ignore a token.
140%
141\def\gobble#1{}
142
143\hyphenation{ap-pen-dix}
144\hyphenation{mini-buf-fer mini-buf-fers}
145\hyphenation{eshell}
146\hyphenation{white-space}
147
148% Margin to add to right of even pages, to left of odd pages.
149\newdimen \bindingoffset
150\newdimen \normaloffset
151\newdimen\pagewidth \newdimen\pageheight
152
153% Sometimes it is convenient to have everything in the transcript file
154% and nothing on the terminal.  We don't just call \tracingall here,
155% since that produces some useless output on the terminal.
156%
157\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
158\ifx\eTeXversion\undefined
159\def\loggingall{\tracingcommands2 \tracingstats2
160   \tracingpages1 \tracingoutput1 \tracinglostchars1
161   \tracingmacros2 \tracingparagraphs1 \tracingrestores1
162   \showboxbreadth\maxdimen\showboxdepth\maxdimen
163}%
164\else
165\def\loggingall{\tracingcommands3 \tracingstats2
166   \tracingpages1 \tracingoutput1 \tracinglostchars1
167   \tracingmacros2 \tracingparagraphs1 \tracingrestores1
168   \tracingscantokens1 \tracingassigns1 \tracingifs1
169   \tracinggroups1 \tracingnesting2
170   \showboxbreadth\maxdimen\showboxdepth\maxdimen
171}%
172\fi
173
174% For @cropmarks command.
175% Do @cropmarks to get crop marks.
176%
177\newif\ifcropmarks
178\let\cropmarks = \cropmarkstrue
179%
180% Dimensions to add cropmarks at corners.
181% Added by P. A. MacKay, 12 Nov. 1986
182%
183\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
184\newdimen\cornerlong  \cornerlong=1pc
185\newdimen\cornerthick \cornerthick=.3pt
186\newdimen\topandbottommargin \topandbottommargin=.75in
187
188% Main output routine.
189\chardef\PAGE = 255
190\output = {\onepageout{\pagecontents\PAGE}}
191
192\newbox\headlinebox
193\newbox\footlinebox
194
195% \onepageout takes a vbox as an argument.  Note that \pagecontents
196% does insertions, but you have to call it yourself.
197\def\onepageout#1{%
198  \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
199  %
200  \ifodd\pageno  \advance\hoffset by \bindingoffset
201  \else \advance\hoffset by -\bindingoffset\fi
202  %
203  % Do this outside of the \shipout so @code etc. will be expanded in
204  % the headline as they should be, not taken literally (outputting ''code).
205  \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}%
206  \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}%
207  %
208  {%
209    % Have to do this stuff outside the \shipout because we want it to
210    % take effect in \write's, yet the group defined by the \vbox ends
211    % before the \shipout runs.
212    %
213    \escapechar = `\\     % use backslash in output files.
214    \indexdummies         % don't expand commands in the output.
215    \normalturnoffactive  % \ in index entries must not stay \, e.g., if
216                   % the page break happens to be in the middle of an example.
217    \shipout\vbox{%
218      \ifcropmarks \vbox to \outervsize\bgroup
219        \hsize = \outerhsize
220        \vskip-\topandbottommargin
221        \vtop to0pt{%
222          \line{\ewtop\hfil\ewtop}%
223          \nointerlineskip
224          \line{%
225            \vbox{\moveleft\cornerthick\nstop}%
226            \hfill
227            \vbox{\moveright\cornerthick\nstop}%
228          }%
229          \vss}%
230        \vskip\topandbottommargin
231        \line\bgroup
232          \hfil % center the page within the outer (page) hsize.
233          \ifodd\pageno\hskip\bindingoffset\fi
234          \vbox\bgroup
235      \fi
236      %
237      \unvbox\headlinebox
238      \pagebody{#1}%
239      \ifdim\ht\footlinebox > 0pt
240        % Only leave this space if the footline is nonempty.
241        % (We lessened \vsize for it in \oddfootingxxx.)
242        % The \baselineskip=24pt in plain's \makefootline has no effect.
243        \vskip 2\baselineskip
244        \unvbox\footlinebox
245      \fi
246      %
247      \ifcropmarks
248          \egroup % end of \vbox\bgroup
249        \hfil\egroup % end of (centering) \line\bgroup
250        \vskip\topandbottommargin plus1fill minus1fill
251        \boxmaxdepth = \cornerthick
252        \vbox to0pt{\vss
253          \line{%
254            \vbox{\moveleft\cornerthick\nsbot}%
255            \hfill
256            \vbox{\moveright\cornerthick\nsbot}%
257          }%
258          \nointerlineskip
259          \line{\ewbot\hfil\ewbot}%
260        }%
261      \egroup % \vbox from first cropmarks clause
262      \fi
263    }% end of \shipout\vbox
264  }% end of group with \turnoffactive
265  \advancepageno
266  \ifnum\outputpenalty>-20000 \else\dosupereject\fi
267}
268
269\newinsert\margin \dimen\margin=\maxdimen
270
271\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}}
272{\catcode`\@ =11
273\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
274% marginal hacks, juha@viisa.uucp (Juha Takala)
275\ifvoid\margin\else % marginal info is present
276  \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
277\dimen@=\dp#1 \unvbox#1
278\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
279\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
280}
281
282% Here are the rules for the cropmarks.  Note that they are
283% offset so that the space between them is truly \outerhsize or \outervsize
284% (P. A. MacKay, 12 November, 1986)
285%
286\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
287\def\nstop{\vbox
288  {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
289\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
290\def\nsbot{\vbox
291  {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
292
293% Parse an argument, then pass it to #1.  The argument is the rest of
294% the input line (except we remove a trailing comment).  #1 should be a
295% macro which expects an ordinary undelimited TeX argument.
296%
297\def\parsearg#1{%
298  \let\next = #1%
299  \begingroup
300    \obeylines
301    \futurelet\temp\parseargx
302}
303
304% If the next token is an obeyed space (from an @example environment or
305% the like), remove it and recurse.  Otherwise, we're done.
306\def\parseargx{%
307  % \obeyedspace is defined far below, after the definition of \sepspaces.
308  \ifx\obeyedspace\temp
309    \expandafter\parseargdiscardspace
310  \else
311    \expandafter\parseargline
312  \fi
313}
314
315% Remove a single space (as the delimiter token to the macro call).
316{\obeyspaces %
317 \gdef\parseargdiscardspace {\futurelet\temp\parseargx}}
318
319{\obeylines %
320  \gdef\parseargline#1^^M{%
321    \endgroup % End of the group started in \parsearg.
322    %
323    % First remove any @c comment, then any @comment.
324    % Result of each macro is put in \toks0.
325    \argremovec #1\c\relax %
326    \expandafter\argremovecomment \the\toks0 \comment\relax %
327    %
328    % Call the caller's macro, saved as \next in \parsearg.
329    \expandafter\next\expandafter{\the\toks0}%
330  }%
331}
332
333% Since all \c{,omment} does is throw away the argument, we can let TeX
334% do that for us.  The \relax here is matched by the \relax in the call
335% in \parseargline; it could be more or less anything, its purpose is
336% just to delimit the argument to the \c.
337\def\argremovec#1\c#2\relax{\toks0 = {#1}}
338\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}}
339
340% \argremovec{,omment} might leave us with trailing spaces, though; e.g.,
341%    @end itemize  @c foo
342% will have two active spaces as part of the argument with the
343% `itemize'.  Here we remove all active spaces from #1, and assign the
344% result to \toks0.
345%
346% This loses if there are any *other* active characters besides spaces
347% in the argument -- _ ^ +, for example -- since they get expanded.
348% Fortunately, Texinfo does not define any such commands.  (If it ever
349% does, the catcode of the characters in questionwill have to be changed
350% here.)  But this means we cannot call \removeactivespaces as part of
351% \argremovec{,omment}, since @c uses \parsearg, and thus the argument
352% that \parsearg gets might well have any character at all in it.
353%
354\def\removeactivespaces#1{%
355  \begingroup
356    \ignoreactivespaces
357    \edef\temp{#1}%
358    \global\toks0 = \expandafter{\temp}%
359  \endgroup
360}
361
362% Change the active space to expand to nothing.
363%
364\begingroup
365  \obeyspaces
366  \gdef\ignoreactivespaces{\obeyspaces\let =\empty}
367\endgroup
368
369
370\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
371
372%% These are used to keep @begin/@end levels from running away
373%% Call \inENV within environments (after a \begingroup)
374\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
375\def\ENVcheck{%
376\ifENV\errmessage{Still within an environment; press RETURN to continue}
377\endgroup\fi} % This is not perfect, but it should reduce lossage
378
379% @begin foo  is the same as @foo, for now.
380\newhelp\EMsimple{Press RETURN to continue.}
381
382\outer\def\begin{\parsearg\beginxxx}
383
384\def\beginxxx #1{%
385\expandafter\ifx\csname #1\endcsname\relax
386{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else
387\csname #1\endcsname\fi}
388
389% @end foo executes the definition of \Efoo.
390%
391\def\end{\parsearg\endxxx}
392\def\endxxx #1{%
393  \removeactivespaces{#1}%
394  \edef\endthing{\the\toks0}%
395  %
396  \expandafter\ifx\csname E\endthing\endcsname\relax
397    \expandafter\ifx\csname \endthing\endcsname\relax
398      % There's no \foo, i.e., no ``environment'' foo.
399      \errhelp = \EMsimple
400      \errmessage{Undefined command `@end \endthing'}%
401    \else
402      \unmatchedenderror\endthing
403    \fi
404  \else
405    % Everything's ok; the right environment has been started.
406    \csname E\endthing\endcsname
407  \fi
408}
409
410% There is an environment #1, but it hasn't been started.  Give an error.
411%
412\def\unmatchedenderror#1{%
413  \errhelp = \EMsimple
414  \errmessage{This `@end #1' doesn't have a matching `@#1'}%
415}
416
417% Define the control sequence \E#1 to give an unmatched @end error.
418%
419\def\defineunmatchedend#1{%
420  \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
421}
422
423
424% Single-spacing is done by various environments (specifically, in
425% \nonfillstart and \quotations).
426\newskip\singlespaceskip \singlespaceskip = 12.5pt
427\def\singlespace{%
428  % Why was this kern here?  It messes up equalizing space above and below
429  % environments.  --karl, 6may93
430  %{\advance \baselineskip by -\singlespaceskip
431  %\kern \baselineskip}%
432  \setleading \singlespaceskip
433}
434
435%% Simple single-character @ commands
436
437% @@ prints an @
438% Kludge this until the fonts are right (grr).
439\def\@{{\tt\char64}}
440
441% This is turned off because it was never documented
442% and you can use @w{...} around a quote to suppress ligatures.
443%% Define @` and @' to be the same as ` and '
444%% but suppressing ligatures.
445%\def\`{{`}}
446%\def\'{{'}}
447
448% Used to generate quoted braces.
449\def\mylbrace {{\tt\char123}}
450\def\myrbrace {{\tt\char125}}
451\let\{=\mylbrace
452\let\}=\myrbrace
453\begingroup
454  % Definitions to produce actual \{ & \} command in an index.
455  \catcode`\{ = 12 \catcode`\} = 12
456  \catcode`\[ = 1 \catcode`\] = 2
457  \catcode`\@ = 0 \catcode`\\ = 12
458  @gdef@lbracecmd[\{]%
459  @gdef@rbracecmd[\}]%
460@endgroup
461
462% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
463% Others are defined by plain TeX: @` @' @" @^ @~ @= @v @H.
464\let\, = \c
465\let\dotaccent = \.
466\def\ringaccent#1{{\accent23 #1}}
467\let\tieaccent = \t
468\let\ubaraccent = \b
469\let\udotaccent = \d
470
471% Other special characters: @questiondown @exclamdown
472% Plain TeX defines: @AA @AE @O @OE @L (and lowercase versions) @ss.
473\def\questiondown{?`}
474\def\exclamdown{!`}
475
476% Dotless i and dotless j, used for accents.
477\def\imacro{i}
478\def\jmacro{j}
479\def\dotless#1{%
480  \def\temp{#1}%
481  \ifx\temp\imacro \ptexi
482  \else\ifx\temp\jmacro \j
483  \else \errmessage{@dotless can be used only with i or j}%
484  \fi\fi
485}
486
487% Be sure we're in horizontal mode when doing a tie, since we make space
488% equivalent to this in @example-like environments. Otherwise, a space
489% at the beginning of a line will start with \penalty -- and
490% since \penalty is valid in vertical mode, we'd end up putting the
491% penalty on the vertical list instead of in the new paragraph.
492{\catcode`@ = 11
493 % Avoid using \@M directly, because that causes trouble
494 % if the definition is written into an index file.
495 \global\let\tiepenalty = \@M
496 \gdef\tie{\leavevmode\penalty\tiepenalty\ }
497}
498
499% @: forces normal size whitespace following.
500\def\:{\spacefactor=1000 }
501
502% @* forces a line break.
503\def\*{\hfil\break\hbox{}\ignorespaces}
504
505% @. is an end-of-sentence period.
506\def\.{.\spacefactor=3000 }
507
508% @! is an end-of-sentence bang.
509\def\!{!\spacefactor=3000 }
510
511% @? is an end-of-sentence query.
512\def\?{?\spacefactor=3000 }
513
514% @w prevents a word break.  Without the \leavevmode, @w at the
515% beginning of a paragraph, when TeX is still in vertical mode, would
516% produce a whole line of output instead of starting the paragraph.
517\def\w#1{\leavevmode\hbox{#1}}
518
519% @group ... @end group forces ... to be all on one page, by enclosing
520% it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
521% to keep its height that of a normal line.  According to the rules for
522% \topskip (p.114 of the TeXbook), the glue inserted is
523% max (\topskip - \ht (first item), 0).  If that height is large,
524% therefore, no glue is inserted, and the space between the headline and
525% the text is small, which looks bad.
526%
527\def\group{\begingroup
528  \ifnum\catcode13=\active \else
529    \errhelp = \groupinvalidhelp
530    \errmessage{@group invalid in context where filling is enabled}%
531  \fi
532  %
533  % The \vtop we start below produces a box with normal height and large
534  % depth; thus, TeX puts \baselineskip glue before it, and (when the
535  % next line of text is done) \lineskip glue after it.  (See p.82 of
536  % the TeXbook.)  Thus, space below is not quite equal to space
537  % above.  But it's pretty close.
538  \def\Egroup{%
539    \egroup           % End the \vtop.
540    \endgroup         % End the \group.
541  }%
542  %
543  \vtop\bgroup
544    % We have to put a strut on the last line in case the @group is in
545    % the midst of an example, rather than completely enclosing it.
546    % Otherwise, the interline space between the last line of the group
547    % and the first line afterwards is too small.  But we can't put the
548    % strut in \Egroup, since there it would be on a line by itself.
549    % Hence this just inserts a strut at the beginning of each line.
550    \everypar = {\strut}%
551    %
552    % Since we have a strut on every line, we don't need any of TeX's
553    % normal interline spacing.
554    \offinterlineskip
555    %
556    % OK, but now we have to do something about blank
557    % lines in the input in @example-like environments, which normally
558    % just turn into \lisppar, which will insert no space now that we've
559    % turned off the interline space.  Simplest is to make them be an
560    % empty paragraph.
561    \ifx\par\lisppar
562      \edef\par{\leavevmode \par}%
563      %
564      % Reset ^^M's definition to new definition of \par.
565      \obeylines
566    \fi
567    %
568    % Do @comment since we are called inside an environment such as
569    % @example, where each end-of-line in the input causes an
570    % end-of-line in the output.  We don't want the end-of-line after
571    % the `@group' to put extra space in the output.  Since @group
572    % should appear on a line by itself (according to the Texinfo
573    % manual), we don't worry about eating any user text.
574    \comment
575}
576%
577% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
578% message, so this ends up printing `@group can only ...'.
579%
580\newhelp\groupinvalidhelp{%
581group can only be used in environments such as @example,^^J%
582where each line of input produces a line of output.}
583
584% @need space-in-mils
585% forces a page break if there is not space-in-mils remaining.
586
587\newdimen\mil  \mil=0.001in
588
589\def\need{\parsearg\needx}
590
591% Old definition--didn't work.
592%\def\needx #1{\par %
593%% This method tries to make TeX break the page naturally
594%% if the depth of the box does not fit.
595%{\baselineskip=0pt%
596%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak
597%\prevdepth=-1000pt
598%}}
599
600\def\needx#1{%
601  % Go into vertical mode, so we don't make a big box in the middle of a
602  % paragraph.
603  \par
604  %
605  % Don't add any leading before our big empty box, but allow a page
606  % break, since the best break might be right here.
607  \allowbreak
608  \nointerlineskip
609  \vtop to #1\mil{\vfil}%
610  %
611  % TeX does not even consider page breaks if a penalty added to the
612  % main vertical list is 10000 or more.  But in order to see if the
613  % empty box we just added fits on the page, we must make it consider
614  % page breaks.  On the other hand, we don't want to actually break the
615  % page after the empty box.  So we use a penalty of 9999.
616  %
617  % There is an extremely small chance that TeX will actually break the
618  % page at this \penalty, if there are no other feasible breakpoints in
619  % sight.  (If the user is using lots of big @group commands, which
620  % almost-but-not-quite fill up a page, TeX will have a hard time doing
621  % good page breaking, for example.)  However, I could not construct an
622  % example where a page broke at this \penalty; if it happens in a real
623  % document, then we can reconsider our strategy.
624  \penalty9999
625  %
626  % Back up by the size of the box, whether we did a page break or not.
627  \kern -#1\mil
628  %
629  % Do not allow a page break right after this kern.
630  \nobreak
631}
632
633% @br   forces paragraph break
634
635\let\br = \par
636
637% @dots{} output an ellipsis using the current font.
638% We do .5em per period so that it has the same spacing in a typewriter
639% font as three actual period characters.
640%
641\def\dots{%
642  \leavevmode
643  \hbox to 1.5em{%
644    \hskip 0pt plus 0.25fil minus 0.25fil
645    .\hss.\hss.%
646    \hskip 0pt plus 0.5fil minus 0.5fil
647  }%
648}
649
650% @enddots{} is an end-of-sentence ellipsis.
651%
652\def\enddots{%
653  \leavevmode
654  \hbox to 2em{%
655    \hskip 0pt plus 0.25fil minus 0.25fil
656    .\hss.\hss.\hss.%
657    \hskip 0pt plus 0.5fil minus 0.5fil
658  }%
659  \spacefactor=3000
660}
661
662
663% @page    forces the start of a new page
664%
665\def\page{\par\vfill\supereject}
666
667% @exdent text....
668% outputs text on separate line in roman font, starting at standard page margin
669
670% This records the amount of indent in the innermost environment.
671% That's how much \exdent should take out.
672\newskip\exdentamount
673
674% This defn is used inside fill environments such as @defun.
675\def\exdent{\parsearg\exdentyyy}
676\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}}
677
678% This defn is used inside nofill environments such as @example.
679\def\nofillexdent{\parsearg\nofillexdentyyy}
680\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount
681\leftline{\hskip\leftskip{\rm#1}}}}
682
683% @inmargin{TEXT} puts TEXT in the margin next to the current paragraph.
684
685\def\inmargin#1{%
686\strut\vadjust{\nobreak\kern-\strutdepth
687  \vtop to \strutdepth{\baselineskip\strutdepth\vss
688  \llap{\rightskip=\inmarginspacing \vbox{\noindent #1}}\null}}}
689\newskip\inmarginspacing \inmarginspacing=1cm
690\def\strutdepth{\dp\strutbox}
691
692%\hbox{{\rm#1}}\hfil\break}}
693
694% @include file    insert text of that file as input.
695% Allow normal characters that  we make active in the argument (a file name).
696\def\include{\begingroup
697  \catcode`\\=12
698  \catcode`~=12
699  \catcode`^=12
700  \catcode`_=12
701  \catcode`|=12
702  \catcode`<=12
703  \catcode`>=12
704  \catcode`+=12
705  \parsearg\includezzz}
706% Restore active chars for included file.
707\def\includezzz#1{\endgroup\begingroup
708  % Read the included file in a group so nested @include's work.
709  \def\thisfile{#1}%
710  \input\thisfile
711\endgroup}
712
713\def\thisfile{}
714
715% @center line   outputs that line, centered
716
717\def\center{\parsearg\centerzzz}
718\def\centerzzz #1{{\advance\hsize by -\leftskip
719\advance\hsize by -\rightskip
720\centerline{#1}}}
721
722% @sp n   outputs n lines of vertical space
723
724\def\sp{\parsearg\spxxx}
725\def\spxxx #1{\vskip #1\baselineskip}
726
727% @comment ...line which is ignored...
728% @c is the same as @comment
729% @ignore ... @end ignore  is another way to write a comment
730
731\def\comment{\begingroup \catcode`\^^M=\other%
732\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
733\commentxxx}
734{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}}
735
736\let\c=\comment
737
738% @paragraphindent NCHARS
739% We'll use ems for NCHARS, close enough.
740% We cannot implement @paragraphindent asis, though.
741%
742\def\asisword{asis} % no translation, these are keywords
743\def\noneword{none}
744%
745\def\paragraphindent{\parsearg\doparagraphindent}
746\def\doparagraphindent#1{%
747  \def\temp{#1}%
748  \ifx\temp\asisword
749  \else
750    \ifx\temp\noneword
751      \defaultparindent = 0pt
752    \else
753      \defaultparindent = #1em
754    \fi
755  \fi
756  \parindent = \defaultparindent
757}
758
759% @asis just yields its argument.  Used with @table, for example.
760%
761\def\asis#1{#1}
762
763% @math means output in math mode.
764% We don't use $'s directly in the definition of \math because control
765% sequences like \math are expanded when the toc file is written.  Then,
766% we read the toc file back, the $'s will be normal characters (as they
767% should be, according to the definition of Texinfo).  So we must use a
768% control sequence to switch into and out of math mode.
769%
770% This isn't quite enough for @math to work properly in indices, but it
771% seems unlikely it will ever be needed there.
772%
773\let\implicitmath = $
774\def\math#1{\implicitmath #1\implicitmath}
775
776% @bullet and @minus need the same treatment as @math, just above.
777\def\bullet{\implicitmath\ptexbullet\implicitmath}
778\def\minus{\implicitmath-\implicitmath}
779
780% @refill is a no-op.
781\let\refill=\relax
782
783% If working on a large document in chapters, it is convenient to
784% be able to disable indexing, cross-referencing, and contents, for test runs.
785% This is done with @novalidate (before @setfilename).
786%
787\newif\iflinks \linkstrue % by default we want the aux files.
788\let\novalidate = \linksfalse
789
790% @setfilename is done at the beginning of every texinfo file.
791% So open here the files we need to have open while reading the input.
792% This makes it possible to make a .fmt file for texinfo.
793\def\setfilename{%
794   \iflinks
795     \readauxfile
796   \fi % \openindices needs to do some work in any case.
797   \openindices
798   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
799   \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
800   %
801   % If texinfo.cnf is present on the system, read it.
802   % Useful for site-wide @afourpaper, etc.
803   % Just to be on the safe side, close the input stream before the \input.
804   \openin 1 texinfo.cnf
805   \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
806   \closein1
807   \temp
808   %
809   \comment % Ignore the actual filename.
810}
811
812% Called from \setfilename.
813%
814\def\openindices{%
815  \newindex{cp}%
816  \newcodeindex{fn}%
817  \newcodeindex{vr}%
818  \newcodeindex{tp}%
819  \newcodeindex{ky}%
820  \newcodeindex{pg}%
821}
822
823% @bye.
824\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
825
826
827\message{fonts,}
828% Font-change commands.
829
830% Texinfo sort of supports the sans serif font style, which plain TeX does not.
831% So we set up a \sf analogous to plain's \rm, etc.
832\newfam\sffam
833\def\sf{\fam=\sffam \tensf}
834\let\li = \sf % Sometimes we call it \li, not \sf.
835
836% We don't need math for this one.
837\def\ttsl{\tenttsl}
838
839% Use Computer Modern fonts at \magstephalf (11pt).
840\newcount\mainmagstep
841\mainmagstep=\magstephalf
842
843% Set the font macro #1 to the font named #2, adding on the
844% specified font prefix (normally `cm').
845% #3 is the font's design size, #4 is a scale factor
846\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4}
847
848% Use cm as the default font prefix.
849% To specify the font prefix, you must define \fontprefix
850% before you read in texinfo.tex.
851\ifx\fontprefix\undefined
852\def\fontprefix{cm}
853\fi
854% Support font families that don't use the same naming scheme as CM.
855\def\rmshape{r}
856\def\rmbshape{bx}               %where the normal face is bold
857\def\bfshape{b}
858\def\bxshape{bx}
859\def\ttshape{tt}
860\def\ttbshape{tt}
861\def\ttslshape{sltt}
862\def\itshape{ti}
863\def\itbshape{bxti}
864\def\slshape{sl}
865\def\slbshape{bxsl}
866\def\sfshape{ss}
867\def\sfbshape{ss}
868\def\scshape{csc}
869\def\scbshape{csc}
870
871\ifx\bigger\relax
872\let\mainmagstep=\magstep1
873\setfont\textrm\rmshape{12}{1000}
874\setfont\texttt\ttshape{12}{1000}
875\else
876\setfont\textrm\rmshape{10}{\mainmagstep}
877\setfont\texttt\ttshape{10}{\mainmagstep}
878\fi
879% Instead of cmb10, you many want to use cmbx10.
880% cmbx10 is a prettier font on its own, but cmb10
881% looks better when embedded in a line with cmr10.
882\setfont\textbf\bfshape{10}{\mainmagstep}
883\setfont\textit\itshape{10}{\mainmagstep}
884\setfont\textsl\slshape{10}{\mainmagstep}
885\setfont\textsf\sfshape{10}{\mainmagstep}
886\setfont\textsc\scshape{10}{\mainmagstep}
887\setfont\textttsl\ttslshape{10}{\mainmagstep}
888\font\texti=cmmi10 scaled \mainmagstep
889\font\textsy=cmsy10 scaled \mainmagstep
890
891% A few fonts for @defun, etc.
892\setfont\defbf\bxshape{10}{\magstep1} %was 1314
893\setfont\deftt\ttshape{10}{\magstep1}
894\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf}
895
896% Fonts for indices and small examples (9pt).
897% We actually use the slanted font rather than the italic,
898% because texinfo normally uses the slanted fonts for that.
899% Do not make many font distinctions in general in the index, since they
900% aren't very useful.
901\setfont\ninett\ttshape{9}{1000}
902\setfont\ninettsl\ttslshape{10}{900}
903\setfont\indrm\rmshape{9}{1000}
904\setfont\indit\itshape{9}{1000}
905\setfont\indsl\slshape{9}{1000}
906\let\indtt=\ninett
907\let\indttsl=\ninettsl
908\let\indsf=\indrm
909\let\indbf=\indrm
910\setfont\indsc\scshape{10}{900}
911\font\indi=cmmi9
912\font\indsy=cmsy9
913
914% Fonts for title page:
915\setfont\titlerm\rmbshape{12}{\magstep3}
916\setfont\titleit\itbshape{10}{\magstep4}
917\setfont\titlesl\slbshape{10}{\magstep4}
918\setfont\titlett\ttbshape{12}{\magstep3}
919\setfont\titlettsl\ttslshape{10}{\magstep4}
920\setfont\titlesf\sfbshape{17}{\magstep1}
921\let\titlebf=\titlerm
922\setfont\titlesc\scbshape{10}{\magstep4}
923\font\titlei=cmmi12 scaled \magstep3
924\font\titlesy=cmsy10 scaled \magstep4
925\def\authorrm{\secrm}
926
927% Chapter (and unnumbered) fonts (17.28pt).
928\setfont\chaprm\rmbshape{12}{\magstep2}
929\setfont\chapit\itbshape{10}{\magstep3}
930\setfont\chapsl\slbshape{10}{\magstep3}
931\setfont\chaptt\ttbshape{12}{\magstep2}
932\setfont\chapttsl\ttslshape{10}{\magstep3}
933\setfont\chapsf\sfbshape{17}{1000}
934\let\chapbf=\chaprm
935\setfont\chapsc\scbshape{10}{\magstep3}
936\font\chapi=cmmi12 scaled \magstep2
937\font\chapsy=cmsy10 scaled \magstep3
938
939% Section fonts (14.4pt).
940\setfont\secrm\rmbshape{12}{\magstep1}
941\setfont\secit\itbshape{10}{\magstep2}
942\setfont\secsl\slbshape{10}{\magstep2}
943\setfont\sectt\ttbshape{12}{\magstep1}
944\setfont\secttsl\ttslshape{10}{\magstep2}
945\setfont\secsf\sfbshape{12}{\magstep1}
946\let\secbf\secrm
947\setfont\secsc\scbshape{10}{\magstep2}
948\font\seci=cmmi12 scaled \magstep1
949\font\secsy=cmsy10 scaled \magstep2
950
951% \setfont\ssecrm\bxshape{10}{\magstep1}    % This size an font looked bad.
952% \setfont\ssecit\itshape{10}{\magstep1}    % The letters were too crowded.
953% \setfont\ssecsl\slshape{10}{\magstep1}
954% \setfont\ssectt\ttshape{10}{\magstep1}
955% \setfont\ssecsf\sfshape{10}{\magstep1}
956
957%\setfont\ssecrm\bfshape{10}{1315}      % Note the use of cmb rather than cmbx.
958%\setfont\ssecit\itshape{10}{1315}      % Also, the size is a little larger than
959%\setfont\ssecsl\slshape{10}{1315}      % being scaled magstep1.
960%\setfont\ssectt\ttshape{10}{1315}
961%\setfont\ssecsf\sfshape{10}{1315}
962
963%\let\ssecbf=\ssecrm
964
965% Subsection fonts (13.15pt).
966\setfont\ssecrm\rmbshape{12}{\magstephalf}
967\setfont\ssecit\itbshape{10}{1315}
968\setfont\ssecsl\slbshape{10}{1315}
969\setfont\ssectt\ttbshape{12}{\magstephalf}
970\setfont\ssecttsl\ttslshape{10}{1315}
971\setfont\ssecsf\sfbshape{12}{\magstephalf}
972\let\ssecbf\ssecrm
973\setfont\ssecsc\scbshape{10}{\magstep1}
974\font\sseci=cmmi12 scaled \magstephalf
975\font\ssecsy=cmsy10 scaled 1315
976% The smallcaps and symbol fonts should actually be scaled \magstep1.5,
977% but that is not a standard magnification.
978
979% In order for the font changes to affect most math symbols and letters,
980% we have to define the \textfont of the standard families.  Since
981% texinfo doesn't allow for producing subscripts and superscripts, we
982% don't bother to reset \scriptfont and \scriptscriptfont (which would
983% also require loading a lot more fonts).
984%
985\def\resetmathfonts{%
986  \textfont0 = \tenrm \textfont1 = \teni \textfont2 = \tensy
987  \textfont\itfam = \tenit \textfont\slfam = \tensl \textfont\bffam = \tenbf
988  \textfont\ttfam = \tentt \textfont\sffam = \tensf
989}
990
991
992% The font-changing commands redefine the meanings of \tenSTYLE, instead
993% of just \STYLE.  We do this so that font changes will continue to work
994% in math mode, where it is the current \fam that is relevant in most
995% cases, not the current font.  Plain TeX does \def\bf{\fam=\bffam
996% \tenbf}, for example.  By redefining \tenbf, we obviate the need to
997% redefine \bf itself.
998\def\textfonts{%
999  \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
1000  \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
1001  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
1002  \resetmathfonts}
1003\def\titlefonts{%
1004  \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
1005  \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
1006  \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
1007  \let\tenttsl=\titlettsl
1008  \resetmathfonts \setleading{25pt}}
1009\def\titlefont#1{{\titlefonts\rm #1}}
1010\def\chapfonts{%
1011  \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
1012  \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
1013  \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
1014  \resetmathfonts \setleading{19pt}}
1015\def\secfonts{%
1016  \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
1017  \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
1018  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
1019  \resetmathfonts \setleading{16pt}}
1020\def\subsecfonts{%
1021  \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
1022  \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
1023  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
1024  \resetmathfonts \setleading{15pt}}
1025\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
1026\def\indexfonts{%
1027  \let\tenrm=\indrm \let\tenit=\indit \let\tensl=\indsl
1028  \let\tenbf=\indbf \let\tentt=\indtt \let\smallcaps=\indsc
1029  \let\tensf=\indsf \let\teni=\indi \let\tensy=\indsy \let\tenttsl=\indttsl
1030  \resetmathfonts \setleading{12pt}}
1031
1032% Set up the default fonts, so we can use them for creating boxes.
1033%
1034\textfonts
1035
1036% Define these so they can be easily changed for other fonts.
1037\def\angleleft{$\langle$}
1038\def\angleright{$\rangle$}
1039
1040% Count depth in font-changes, for error checks
1041\newcount\fontdepth \fontdepth=0
1042
1043% Fonts for short table of contents.
1044\setfont\shortcontrm\rmshape{12}{1000}
1045\setfont\shortcontbf\bxshape{12}{1000}
1046\setfont\shortcontsl\slshape{12}{1000}
1047
1048%% Add scribe-like font environments, plus @l for inline lisp (usually sans
1049%% serif) and @ii for TeX italic
1050
1051% \smartitalic{ARG} outputs arg in italics, followed by an italic correction
1052% unless the following character is such as not to need one.
1053\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else\/\fi\fi\fi}
1054\def\smartslanted#1{{\sl #1}\futurelet\next\smartitalicx}
1055\def\smartitalic#1{{\it #1}\futurelet\next\smartitalicx}
1056
1057\let\i=\smartitalic
1058\let\var=\smartslanted
1059\let\dfn=\smartslanted
1060\let\emph=\smartitalic
1061\let\cite=\smartslanted
1062
1063\def\b#1{{\bf #1}}
1064\let\strong=\b
1065
1066% We can't just use \exhyphenpenalty, because that only has effect at
1067% the end of a paragraph.  Restore normal hyphenation at the end of the
1068% group within which \nohyphenation is presumably called.
1069%
1070\def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
1071\def\restorehyphenation{\hyphenchar\font = `- }
1072
1073\def\t#1{%
1074  {\tt \rawbackslash \frenchspacing #1}%
1075  \null
1076}
1077\let\ttfont=\t
1078\def\samp#1{`\tclose{#1}'\null}
1079\setfont\smallrm\rmshape{8}{1000}
1080\font\smallsy=cmsy9
1081\def\key#1{{\smallrm\textfont2=\smallsy \leavevmode\hbox{%
1082  \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
1083    \vbox{\hrule\kern-0.4pt
1084     \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
1085    \kern-0.4pt\hrule}%
1086  \kern-.06em\raise0.4pt\hbox{\angleright}}}}
1087% The old definition, with no lozenge:
1088%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null}
1089\def\ctrl #1{{\tt \rawbackslash \hat}#1}
1090
1091% @file, @option are the same as @samp.
1092\let\file=\samp
1093\let\option=\samp
1094
1095% @code is a modification of @t,
1096% which makes spaces the same size as normal in the surrounding text.
1097\def\tclose#1{%
1098  {%
1099    % Change normal interword space to be same as for the current font.
1100    \spaceskip = \fontdimen2\font
1101    %
1102    % Switch to typewriter.
1103    \tt
1104    %
1105    % But `\ ' produces the large typewriter interword space.
1106    \def\ {{\spaceskip = 0pt{} }}%
1107    %
1108    % Turn off hyphenation.
1109    \nohyphenation
1110    %
1111    \rawbackslash
1112    \frenchspacing
1113    #1%
1114  }%
1115  \null
1116}
1117
1118% We *must* turn on hyphenation at `-' and `_' in \code.
1119% Otherwise, it is too hard to avoid overfull hboxes
1120% in the Emacs manual, the Library manual, etc.
1121
1122% Unfortunately, TeX uses one parameter (\hyphenchar) to control
1123% both hyphenation at - and hyphenation within words.
1124% We must therefore turn them both off (\tclose does that)
1125% and arrange explicitly to hyphenate at a dash.
1126%  -- rms.
1127{
1128  \catcode`\-=\active
1129  \catcode`\_=\active
1130  %
1131  \global\def\code{\begingroup
1132    \catcode`\-=\active \let-\codedash
1133    \catcode`\_=\active \let_\codeunder
1134    \codex
1135  }
1136  %
1137  % If we end up with any active - characters when handling the index,
1138  % just treat them as a normal -.
1139  \global\def\indexbreaks{\catcode`\-=\active \let-\realdash}
1140}
1141
1142\def\realdash{-}
1143\def\codedash{-\discretionary{}{}{}}
1144\def\codeunder{\ifusingtt{\normalunderscore\discretionary{}{}{}}{\_}}
1145\def\codex #1{\tclose{#1}\endgroup}
1146
1147%\let\exp=\tclose  %Was temporary
1148
1149% @kbd is like @code, except that if the argument is just one @key command,
1150% then @kbd has no effect.
1151
1152% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
1153%   `example' (@kbd uses ttsl only inside of @example and friends),
1154%   or `code' (@kbd uses normal tty font always).
1155\def\kbdinputstyle{\parsearg\kbdinputstylexxx}
1156\def\kbdinputstylexxx#1{%
1157  \def\arg{#1}%
1158  \ifx\arg\worddistinct
1159    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
1160  \else\ifx\arg\wordexample
1161    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
1162  \else\ifx\arg\wordcode
1163    \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
1164  \fi\fi\fi
1165}
1166\def\worddistinct{distinct}
1167\def\wordexample{example}
1168\def\wordcode{code}
1169
1170% Default is kbdinputdistinct.  (Too much of a hassle to call the macro,
1171% the catcodes are wrong for parsearg to work.)
1172\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}
1173
1174\def\xkey{\key}
1175\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}%
1176\ifx\one\xkey\ifx\threex\three \key{#2}%
1177\else{\tclose{\kbdfont\look}}\fi
1178\else{\tclose{\kbdfont\look}}\fi}
1179
1180% For @url, @env, @command quotes seem unnecessary, so use \code.
1181\let\url=\code
1182\let\env=\code
1183\let\command=\code
1184
1185% @uref (abbreviation for `urlref') takes an optional (comma-separated)
1186% second argument specifying the text to display and an optional third
1187% arg as text to display instead of (rather than in addition to) the url
1188% itself.  First (mandatory) arg is the url.  Perhaps eventually put in
1189% a hypertex \special here.
1190%
1191\def\uref#1{\douref #1,,,\finish}
1192\def\douref#1,#2,#3,#4\finish{%
1193  \setbox0 = \hbox{\ignorespaces #3}%
1194  \ifdim\wd0 > 0pt
1195    \unhbox0 % third arg given, show only that
1196  \else
1197    \setbox0 = \hbox{\ignorespaces #2}%
1198    \ifdim\wd0 > 0pt
1199      \unhbox0\ (\code{#1})% second arg given, show both it and url
1200    \else
1201      \code{#1}% only url given, so show it
1202    \fi
1203  \fi
1204}
1205
1206% rms does not like the angle brackets --karl, 17may97.
1207% So now @email is just like @uref.
1208%\def\email#1{\angleleft{\tt #1}\angleright}
1209\let\email=\uref
1210
1211% Check if we are currently using a typewriter font.  Since all the
1212% Computer Modern typewriter fonts have zero interword stretch (and
1213% shrink), and it is reasonable to expect all typewriter fonts to have
1214% this property, we can check that font parameter.
1215%
1216\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
1217
1218% Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
1219% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
1220%
1221\def\dmn#1{\thinspace #1}
1222
1223\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par}
1224
1225% @l was never documented to mean ``switch to the Lisp font'',
1226% and it is not used as such in any manual I can find.  We need it for
1227% Polish suppressed-l.  --karl, 22sep96.
1228%\def\l#1{{\li #1}\null}
1229
1230% Explicit font changes: @r, @sc, undocumented @ii.
1231\def\r#1{{\rm #1}}              % roman font
1232\def\sc#1{{\smallcaps#1}}       % smallcaps font
1233\def\ii#1{{\it #1}}             % italic font
1234
1235% @acronym downcases the argument and prints in smallcaps.
1236\def\acronym#1{{\smallcaps \lowercase{#1}}}
1237
1238% @pounds{} is a sterling sign.
1239\def\pounds{{\it\$}}
1240
1241
1242\message{page headings,}
1243
1244\newskip\titlepagetopglue \titlepagetopglue = 1.5in
1245\newskip\titlepagebottomglue \titlepagebottomglue = 2pc
1246
1247% First the title page.  Must do @settitle before @titlepage.
1248\newif\ifseenauthor
1249\newif\iffinishedtitlepage
1250
1251% Do an implicit @contents or @shortcontents after @end titlepage if the
1252% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage.
1253%
1254\newif\ifsetcontentsaftertitlepage
1255 \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue
1256\newif\ifsetshortcontentsaftertitlepage
1257 \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
1258
1259\def\shorttitlepage{\parsearg\shorttitlepagezzz}
1260\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
1261        \endgroup\page\hbox{}\page}
1262
1263\def\titlepage{\begingroup \parindent=0pt \textfonts
1264   \let\subtitlerm=\tenrm
1265   \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}%
1266   %
1267   \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines}%
1268   %
1269   % Leave some space at the very top of the page.
1270   \vglue\titlepagetopglue
1271   %
1272   % Now you can print the title using @title.
1273   \def\title{\parsearg\titlezzz}%
1274   \def\titlezzz##1{\leftline{\titlefonts\rm ##1}
1275                    % print a rule at the page bottom also.
1276                    \finishedtitlepagefalse
1277                    \vskip4pt \hrule height 4pt width \hsize \vskip4pt}%
1278   % No rule at page bottom unless we print one at the top with @title.
1279   \finishedtitlepagetrue
1280   %
1281   % Now you can put text using @subtitle.
1282   \def\subtitle{\parsearg\subtitlezzz}%
1283   \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}%
1284   %
1285   % @author should come last, but may come many times.
1286   \def\author{\parsearg\authorzzz}%
1287   \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
1288      {\authorfont \leftline{##1}}}%
1289   %
1290   % Most title ``pages'' are actually two pages long, with space
1291   % at the top of the second.  We don't want the ragged left on the second.
1292   \let\oldpage = \page
1293   \def\page{%
1294      \iffinishedtitlepage\else
1295         \finishtitlepage
1296      \fi
1297      \oldpage
1298      \let\page = \oldpage
1299      \hbox{}}%
1300%   \def\page{\oldpage \hbox{}}
1301}
1302
1303\def\Etitlepage{%
1304   \iffinishedtitlepage\else
1305      \finishtitlepage
1306   \fi
1307   % It is important to do the page break before ending the group,
1308   % because the headline and footline are only empty inside the group.
1309   % If we use the new definition of \page, we always get a blank page
1310   % after the title page, which we certainly don't want.
1311   \oldpage
1312   \endgroup
1313   %
1314   % If they want short, they certainly want long too.
1315   \ifsetshortcontentsaftertitlepage
1316     \shortcontents
1317     \contents
1318     \global\let\shortcontents = \relax
1319     \global\let\contents = \relax
1320   \fi
1321   %
1322   \ifsetcontentsaftertitlepage
1323     \contents
1324     \global\let\contents = \relax
1325     \global\let\shortcontents = \relax
1326   \fi
1327   %
1328   \HEADINGSon
1329}
1330
1331\def\finishtitlepage{%
1332   \vskip4pt \hrule height 2pt width \hsize
1333   \vskip\titlepagebottomglue
1334   \finishedtitlepagetrue
1335}
1336
1337%%% Set up page headings and footings.
1338
1339\let\thispage=\folio
1340
1341\newtoks\evenheadline    % headline on even pages
1342\newtoks\oddheadline     % headline on odd pages
1343\newtoks\evenfootline    % footline on even pages
1344\newtoks\oddfootline     % footline on odd pages
1345
1346% Now make Tex use those variables
1347\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
1348                            \else \the\evenheadline \fi}}
1349\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
1350                            \else \the\evenfootline \fi}\HEADINGShook}
1351\let\HEADINGShook=\relax
1352
1353% Commands to set those variables.
1354% For example, this is what  @headings on  does
1355% @evenheading @thistitle|@thispage|@thischapter
1356% @oddheading @thischapter|@thispage|@thistitle
1357% @evenfooting @thisfile||
1358% @oddfooting ||@thisfile
1359
1360\def\evenheading{\parsearg\evenheadingxxx}
1361\def\oddheading{\parsearg\oddheadingxxx}
1362\def\everyheading{\parsearg\everyheadingxxx}
1363
1364\def\evenfooting{\parsearg\evenfootingxxx}
1365\def\oddfooting{\parsearg\oddfootingxxx}
1366\def\everyfooting{\parsearg\everyfootingxxx}
1367
1368{\catcode`\@=0 %
1369
1370\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish}
1371\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{%
1372\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
1373
1374\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish}
1375\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{%
1376\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
1377
1378\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
1379
1380\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish}
1381\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{%
1382\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
1383
1384\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish}
1385\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{%
1386  \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
1387  %
1388  % Leave some space for the footline.  Hopefully ok to assume
1389  % @evenfooting will not be used by itself.
1390  \global\advance\pageheight by -\baselineskip
1391  \global\advance\vsize by -\baselineskip
1392}
1393
1394\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}}
1395%
1396}% unbind the catcode of @.
1397
1398% @headings double      turns headings on for double-sided printing.
1399% @headings single      turns headings on for single-sided printing.
1400% @headings off         turns them off.
1401% @headings on          same as @headings double, retained for compatibility.
1402% @headings after       turns on double-sided headings after this page.
1403% @headings doubleafter turns on double-sided headings after this page.
1404% @headings singleafter turns on single-sided headings after this page.
1405% By default, they are off at the start of a document,
1406% and turned `on' after @end titlepage.
1407
1408\def\headings #1 {\csname HEADINGS#1\endcsname}
1409
1410\def\HEADINGSoff{
1411\global\evenheadline={\hfil} \global\evenfootline={\hfil}
1412\global\oddheadline={\hfil} \global\oddfootline={\hfil}}
1413\HEADINGSoff
1414% When we turn headings on, set the page number to 1.
1415% For double-sided printing, put current file name in lower left corner,
1416% chapter name on inside top of right hand pages, document
1417% title on inside top of left hand pages, and page numbers on outside top
1418% edge of all pages.
1419\def\HEADINGSdouble{
1420\global\pageno=1
1421\global\evenfootline={\hfil}
1422\global\oddfootline={\hfil}
1423\global\evenheadline={\line{\folio\hfil\thistitle}}
1424\global\oddheadline={\line{\thischapter\hfil\folio}}
1425\global\let\contentsalignmacro = \chapoddpage
1426}
1427\let\contentsalignmacro = \chappager
1428
1429% For single-sided printing, chapter title goes across top left of page,
1430% page number on top right.
1431\def\HEADINGSsingle{
1432\global\pageno=1
1433\global\evenfootline={\hfil}
1434\global\oddfootline={\hfil}
1435\global\evenheadline={\line{\thischapter\hfil\folio}}
1436\global\oddheadline={\line{\thischapter\hfil\folio}}
1437\global\let\contentsalignmacro = \chappager
1438}
1439\def\HEADINGSon{\HEADINGSdouble}
1440
1441\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
1442\let\HEADINGSdoubleafter=\HEADINGSafter
1443\def\HEADINGSdoublex{%
1444\global\evenfootline={\hfil}
1445\global\oddfootline={\hfil}
1446\global\evenheadline={\line{\folio\hfil\thistitle}}
1447\global\oddheadline={\line{\thischapter\hfil\folio}}
1448\global\let\contentsalignmacro = \chapoddpage
1449}
1450
1451\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
1452\def\HEADINGSsinglex{%
1453\global\evenfootline={\hfil}
1454\global\oddfootline={\hfil}
1455\global\evenheadline={\line{\thischapter\hfil\folio}}
1456\global\oddheadline={\line{\thischapter\hfil\folio}}
1457\global\let\contentsalignmacro = \chappager
1458}
1459
1460% Subroutines used in generating headings
1461% Produces Day Month Year style of output.
1462\def\today{%
1463  \number\day\space
1464  \ifcase\month
1465  \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
1466  \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
1467  \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
1468  \fi
1469  \space\number\year}
1470
1471% @settitle line...  specifies the title of the document, for headings.
1472% It generates no output of its own.
1473\def\thistitle{\putwordNoTitle}
1474\def\settitle{\parsearg\settitlezzz}
1475\def\settitlezzz #1{\gdef\thistitle{#1}}
1476
1477
1478\message{tables,}
1479% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x).
1480
1481% default indentation of table text
1482\newdimen\tableindent \tableindent=.8in
1483% default indentation of @itemize and @enumerate text
1484\newdimen\itemindent  \itemindent=.3in
1485% margin between end of table item and start of table text.
1486\newdimen\itemmargin  \itemmargin=.1in
1487
1488% used internally for \itemindent minus \itemmargin
1489\newdimen\itemmax
1490
1491% Note @table, @vtable, and @vtable define @item, @itemx, etc., with
1492% these defs.
1493% They also define \itemindex
1494% to index the item name in whatever manner is desired (perhaps none).
1495
1496\newif\ifitemxneedsnegativevskip
1497
1498\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
1499
1500\def\internalBitem{\smallbreak \parsearg\itemzzz}
1501\def\internalBitemx{\itemxpar \parsearg\itemzzz}
1502
1503\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz}
1504\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz}
1505
1506\def\internalBkitem{\smallbreak \parsearg\kitemzzz}
1507\def\internalBkitemx{\itemxpar \parsearg\kitemzzz}
1508
1509\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}%
1510                 \itemzzz {#1}}
1511
1512\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}%
1513                 \itemzzz {#1}}
1514
1515\def\itemzzz #1{\begingroup %
1516  \advance\hsize by -\rightskip
1517  \advance\hsize by -\tableindent
1518  \setbox0=\hbox{\itemfont{#1}}%
1519  \itemindex{#1}%
1520  \nobreak % This prevents a break before @itemx.
1521  %
1522  % If the item text does not fit in the space we have, put it on a line
1523  % by itself, and do not allow a page break either before or after that
1524  % line.  We do not start a paragraph here because then if the next
1525  % command is, e.g., @kindex, the whatsit would get put into the
1526  % horizontal list on a line by itself, resulting in extra blank space.
1527  \ifdim \wd0>\itemmax
1528    %
1529    % Make this a paragraph so we get the \parskip glue and wrapping,
1530    % but leave it ragged-right.
1531    \begingroup
1532      \advance\leftskip by-\tableindent
1533      \advance\hsize by\tableindent
1534      \advance\rightskip by0pt plus1fil
1535      \leavevmode\unhbox0\par
1536    \endgroup
1537    %
1538    % We're going to be starting a paragraph, but we don't want the
1539    % \parskip glue -- logically it's part of the @item we just started.
1540    \nobreak \vskip-\parskip
1541    %
1542    % Stop a page break at the \parskip glue coming up.  Unfortunately
1543    % we can't prevent a possible page break at the following
1544    % \baselineskip glue.
1545    \nobreak
1546    \endgroup
1547    \itemxneedsnegativevskipfalse
1548  \else
1549    % The item text fits into the space.  Start a paragraph, so that the
1550    % following text (if any) will end up on the same line.
1551    \noindent
1552    % Do this with kerns and \unhbox so that if there is a footnote in
1553    % the item text, it can migrate to the main vertical list and
1554    % eventually be printed.
1555    \nobreak\kern-\tableindent
1556    \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
1557    \unhbox0
1558    \nobreak\kern\dimen0
1559    \endgroup
1560    \itemxneedsnegativevskiptrue
1561  \fi
1562}
1563
1564\def\item{\errmessage{@item while not in a table}}
1565\def\itemx{\errmessage{@itemx while not in a table}}
1566\def\kitem{\errmessage{@kitem while not in a table}}
1567\def\kitemx{\errmessage{@kitemx while not in a table}}
1568\def\xitem{\errmessage{@xitem while not in a table}}
1569\def\xitemx{\errmessage{@xitemx while not in a table}}
1570
1571% Contains a kludge to get @end[description] to work.
1572\def\description{\tablez{\dontindex}{1}{}{}{}{}}
1573
1574% @table, @ftable, @vtable.
1575\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex}
1576{\obeylines\obeyspaces%
1577\gdef\tablex #1^^M{%
1578\tabley\dontindex#1        \endtabley}}
1579
1580\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex}
1581{\obeylines\obeyspaces%
1582\gdef\ftablex #1^^M{%
1583\tabley\fnitemindex#1        \endtabley
1584\def\Eftable{\endgraf\afterenvbreak\endgroup}%
1585\let\Etable=\relax}}
1586
1587\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex}
1588{\obeylines\obeyspaces%
1589\gdef\vtablex #1^^M{%
1590\tabley\vritemindex#1        \endtabley
1591\def\Evtable{\endgraf\afterenvbreak\endgroup}%
1592\let\Etable=\relax}}
1593
1594\def\dontindex #1{}
1595\def\fnitemindex #1{\doind {fn}{\code{#1}}}%
1596\def\vritemindex #1{\doind {vr}{\code{#1}}}%
1597
1598{\obeyspaces %
1599\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup%
1600\tablez{#1}{#2}{#3}{#4}{#5}{#6}}}
1601
1602\def\tablez #1#2#3#4#5#6{%
1603\aboveenvbreak %
1604\begingroup %
1605\def\Edescription{\Etable}% Necessary kludge.
1606\let\itemindex=#1%
1607\ifnum 0#3>0 \advance \leftskip by #3\mil \fi %
1608\ifnum 0#4>0 \tableindent=#4\mil \fi %
1609\ifnum 0#5>0 \advance \rightskip by #5\mil \fi %
1610\def\itemfont{#2}%
1611\itemmax=\tableindent %
1612\advance \itemmax by -\itemmargin %
1613\advance \leftskip by \tableindent %
1614\exdentamount=\tableindent
1615\parindent = 0pt
1616\parskip = \smallskipamount
1617\ifdim \parskip=0pt \parskip=2pt \fi%
1618\def\Etable{\endgraf\afterenvbreak\endgroup}%
1619\let\item = \internalBitem %
1620\let\itemx = \internalBitemx %
1621\let\kitem = \internalBkitem %
1622\let\kitemx = \internalBkitemx %
1623\let\xitem = \internalBxitem %
1624\let\xitemx = \internalBxitemx %
1625}
1626
1627% This is the counter used by @enumerate, which is really @itemize
1628
1629\newcount \itemno
1630
1631\def\itemize{\parsearg\itemizezzz}
1632
1633\def\itemizezzz #1{%
1634  \begingroup % ended by the @end itemize
1635  \itemizey {#1}{\Eitemize}
1636}
1637
1638\def\itemizey #1#2{%
1639\aboveenvbreak %
1640\itemmax=\itemindent %
1641\advance \itemmax by -\itemmargin %
1642\advance \leftskip by \itemindent %
1643\exdentamount=\itemindent
1644\parindent = 0pt %
1645\parskip = \smallskipamount %
1646\ifdim \parskip=0pt \parskip=2pt \fi%
1647\def#2{\endgraf\afterenvbreak\endgroup}%
1648\def\itemcontents{#1}%
1649\let\item=\itemizeitem}
1650
1651% Set sfcode to normal for the chars that usually have another value.
1652% These are `.?!:;,'
1653\def\frenchspacing{\sfcode46=1000 \sfcode63=1000 \sfcode33=1000
1654  \sfcode58=1000 \sfcode59=1000 \sfcode44=1000 }
1655
1656% \splitoff TOKENS\endmark defines \first to be the first token in
1657% TOKENS, and \rest to be the remainder.
1658%
1659\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
1660
1661% Allow an optional argument of an uppercase letter, lowercase letter,
1662% or number, to specify the first label in the enumerated list.  No
1663% argument is the same as `1'.
1664%
1665\def\enumerate{\parsearg\enumeratezzz}
1666\def\enumeratezzz #1{\enumeratey #1  \endenumeratey}
1667\def\enumeratey #1 #2\endenumeratey{%
1668  \begingroup % ended by the @end enumerate
1669  %
1670  % If we were given no argument, pretend we were given `1'.
1671  \def\thearg{#1}%
1672  \ifx\thearg\empty \def\thearg{1}\fi
1673  %
1674  % Detect if the argument is a single token.  If so, it might be a
1675  % letter.  Otherwise, the only valid thing it can be is a number.
1676  % (We will always have one token, because of the test we just made.
1677  % This is a good thing, since \splitoff doesn't work given nothing at
1678  % all -- the first parameter is undelimited.)
1679  \expandafter\splitoff\thearg\endmark
1680  \ifx\rest\empty
1681    % Only one token in the argument.  It could still be anything.
1682    % A ``lowercase letter'' is one whose \lccode is nonzero.
1683    % An ``uppercase letter'' is one whose \lccode is both nonzero, and
1684    %   not equal to itself.
1685    % Otherwise, we assume it's a number.
1686    %
1687    % We need the \relax at the end of the \ifnum lines to stop TeX from
1688    % continuing to look for a <number>.
1689    %
1690    \ifnum\lccode\expandafter`\thearg=0\relax
1691      \numericenumerate % a number (we hope)
1692    \else
1693      % It's a letter.
1694      \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
1695        \lowercaseenumerate % lowercase letter
1696      \else
1697        \uppercaseenumerate % uppercase letter
1698      \fi
1699    \fi
1700  \else
1701    % Multiple tokens in the argument.  We hope it's a number.
1702    \numericenumerate
1703  \fi
1704}
1705
1706% An @enumerate whose labels are integers.  The starting integer is
1707% given in \thearg.
1708%
1709\def\numericenumerate{%
1710  \itemno = \thearg
1711  \startenumeration{\the\itemno}%
1712}
1713
1714% The starting (lowercase) letter is in \thearg.
1715\def\lowercaseenumerate{%
1716  \itemno = \expandafter`\thearg
1717  \startenumeration{%
1718    % Be sure we're not beyond the end of the alphabet.
1719    \ifnum\itemno=0
1720      \errmessage{No more lowercase letters in @enumerate; get a bigger
1721                  alphabet}%
1722    \fi
1723    \char\lccode\itemno
1724  }%
1725}
1726
1727% The starting (uppercase) letter is in \thearg.
1728\def\uppercaseenumerate{%
1729  \itemno = \expandafter`\thearg
1730  \startenumeration{%
1731    % Be sure we're not beyond the end of the alphabet.
1732    \ifnum\itemno=0
1733      \errmessage{No more uppercase letters in @enumerate; get a bigger
1734                  alphabet}
1735    \fi
1736    \char\uccode\itemno
1737  }%
1738}
1739
1740% Call itemizey, adding a period to the first argument and supplying the
1741% common last two arguments.  Also subtract one from the initial value in
1742% \itemno, since @item increments \itemno.
1743%
1744\def\startenumeration#1{%
1745  \advance\itemno by -1
1746  \itemizey{#1.}\Eenumerate\flushcr
1747}
1748
1749% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
1750% to @enumerate.
1751%
1752\def\alphaenumerate{\enumerate{a}}
1753\def\capsenumerate{\enumerate{A}}
1754\def\Ealphaenumerate{\Eenumerate}
1755\def\Ecapsenumerate{\Eenumerate}
1756
1757% Definition of @item while inside @itemize.
1758
1759\def\itemizeitem{%
1760\advance\itemno by 1
1761{\let\par=\endgraf \smallbreak}%
1762\ifhmode \errmessage{In hmode at itemizeitem}\fi
1763{\parskip=0in \hskip 0pt
1764\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
1765\vadjust{\penalty 1200}}%
1766\flushcr}
1767
1768% @multitable macros
1769% Amy Hendrickson, 8/18/94, 3/6/96
1770%
1771% @multitable ... @end multitable will make as many columns as desired.
1772% Contents of each column will wrap at width given in preamble.  Width
1773% can be specified either with sample text given in a template line,
1774% or in percent of \hsize, the current width of text on page.
1775
1776% Table can continue over pages but will only break between lines.
1777
1778% To make preamble:
1779%
1780% Either define widths of columns in terms of percent of \hsize:
1781%   @multitable @columnfractions .25 .3 .45
1782%   @item ...
1783%
1784%   Numbers following @columnfractions are the percent of the total
1785%   current hsize to be used for each column. You may use as many
1786%   columns as desired.
1787
1788
1789% Or use a template:
1790%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
1791%   @item ...
1792%   using the widest term desired in each column.
1793%
1794% For those who want to use more than one line's worth of words in
1795% the preamble, break the line within one argument and it
1796% will parse correctly, i.e.,
1797%
1798%     @multitable {Column 1 template} {Column 2 template} {Column 3
1799%      template}
1800% Not:
1801%     @multitable {Column 1 template} {Column 2 template}
1802%      {Column 3 template}
1803
1804% Each new table line starts with @item, each subsequent new column
1805% starts with @tab. Empty columns may be produced by supplying @tab's
1806% with nothing between them for as many times as empty columns are needed,
1807% ie, @tab@tab@tab will produce two empty columns.
1808
1809% @item, @tab, @multitable or @end multitable do not need to be on their
1810% own lines, but it will not hurt if they are.
1811
1812% Sample multitable:
1813
1814%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
1815%   @item first col stuff @tab second col stuff @tab third col
1816%   @item
1817%   first col stuff
1818%   @tab
1819%   second col stuff
1820%   @tab
1821%   third col
1822%   @item first col stuff @tab second col stuff
1823%   @tab Many paragraphs of text may be used in any column.
1824%
1825%         They will wrap at the width determined by the template.
1826%   @item@tab@tab This will be in third column.
1827%   @end multitable
1828
1829% Default dimensions may be reset by user.
1830% @multitableparskip is vertical space between paragraphs in table.
1831% @multitableparindent is paragraph indent in table.
1832% @multitablecolmargin is horizontal space to be left between columns.
1833% @multitablelinespace is space to leave between table items, baseline
1834%                                                            to baseline.
1835%   0pt means it depends on current normal line spacing.
1836%
1837\newskip\multitableparskip
1838\newskip\multitableparindent
1839\newdimen\multitablecolspace
1840\newskip\multitablelinespace
1841\multitableparskip=0pt
1842\multitableparindent=6pt
1843\multitablecolspace=12pt
1844\multitablelinespace=0pt
1845
1846% Macros used to set up halign preamble:
1847%
1848\let\endsetuptable\relax
1849\def\xendsetuptable{\endsetuptable}
1850\let\columnfractions\relax
1851\def\xcolumnfractions{\columnfractions}
1852\newif\ifsetpercent
1853
1854% #1 is the part of the @columnfraction before the decimal point, which
1855% is presumably either 0 or the empty string (but we don't check, we
1856% just throw it away).  #2 is the decimal part, which we use as the
1857% percent of \hsize for this column.
1858\def\pickupwholefraction#1.#2 {%
1859  \global\advance\colcount by 1
1860  \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
1861  \setuptable
1862}
1863
1864\newcount\colcount
1865\def\setuptable#1{%
1866  \def\firstarg{#1}%
1867  \ifx\firstarg\xendsetuptable
1868    \let\go = \relax
1869  \else
1870    \ifx\firstarg\xcolumnfractions
1871      \global\setpercenttrue
1872    \else
1873      \ifsetpercent
1874         \let\go\pickupwholefraction
1875      \else
1876         \global\advance\colcount by 1
1877         \setbox0=\hbox{#1\unskip }% Add a normal word space as a separator;
1878                            % typically that is always in the input, anyway.
1879         \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
1880      \fi
1881    \fi
1882    \ifx\go\pickupwholefraction
1883      % Put the argument back for the \pickupwholefraction call, so
1884      % we'll always have a period there to be parsed.
1885      \def\go{\pickupwholefraction#1}%
1886    \else
1887      \let\go = \setuptable
1888    \fi%
1889  \fi
1890  \go
1891}
1892
1893% multitable syntax
1894\def\tab{&\hskip1sp\relax} % 2/2/96
1895                           % tiny skip here makes sure this column space is
1896                           % maintained, even if it is never used.
1897
1898% @multitable ... @end multitable definitions:
1899%
1900\def\multitable{\parsearg\dotable}
1901\def\dotable#1{\bgroup
1902  \vskip\parskip
1903  \let\item\crcr
1904  \tolerance=9500
1905  \hbadness=9500
1906  \setmultitablespacing
1907  \parskip=\multitableparskip
1908  \parindent=\multitableparindent
1909  \overfullrule=0pt
1910  \global\colcount=0
1911  \def\Emultitable{\global\setpercentfalse\cr\egroup\egroup}%
1912  %
1913  % To parse everything between @multitable and @item:
1914  \setuptable#1 \endsetuptable
1915  %
1916  % \everycr will reset column counter, \colcount, at the end of
1917  % each line. Every column entry will cause \colcount to advance by one.
1918  % The table preamble
1919  % looks at the current \colcount to find the correct column width.
1920  \everycr{\noalign{%
1921  %
1922  % \filbreak%% keeps underfull box messages off when table breaks over pages.
1923  % Maybe so, but it also creates really weird page breaks when the table
1924  % breaks over pages. Wouldn't \vfil be better?  Wait until the problem
1925  % manifests itself, so it can be fixed for real --karl.
1926    \global\colcount=0\relax}}%
1927  %
1928  % This preamble sets up a generic column definition, which will
1929  % be used as many times as user calls for columns.
1930  % \vtop will set a single line and will also let text wrap and
1931  % continue for many paragraphs if desired.
1932  \halign\bgroup&\global\advance\colcount by 1\relax
1933    \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
1934  %
1935  % In order to keep entries from bumping into each other
1936  % we will add a \leftskip of \multitablecolspace to all columns after
1937  % the first one.
1938  %
1939  % If a template has been used, we will add \multitablecolspace
1940  % to the width of each template entry.
1941  %
1942  % If the user has set preamble in terms of percent of \hsize we will
1943  % use that dimension as the width of the column, and the \leftskip
1944  % will keep entries from bumping into each other.  Table will start at
1945  % left margin and final column will justify at right margin.
1946  %
1947  % Make sure we don't inherit \rightskip from the outer environment.
1948  \rightskip=0pt
1949  \ifnum\colcount=1
1950    % The first column will be indented with the surrounding text.
1951    \advance\hsize by\leftskip
1952  \else
1953    \ifsetpercent \else
1954      % If user has not set preamble in terms of percent of \hsize
1955      % we will advance \hsize by \multitablecolspace.
1956      \advance\hsize by \multitablecolspace
1957    \fi
1958   % In either case we will make \leftskip=\multitablecolspace:
1959  \leftskip=\multitablecolspace
1960  \fi
1961  % Ignoring space at the beginning and end avoids an occasional spurious
1962  % blank line, when TeX decides to break the line at the space before the
1963  % box from the multistrut, so the strut ends up on a line by itself.
1964  % For example:
1965  % @multitable @columnfractions .11 .89
1966  % @item @code{#}
1967  % @tab Legal holiday which is valid in major parts of the whole country.
1968  % Is automatically provided with highlighting sequences respectively marking
1969  % characters.
1970  \noindent\ignorespaces##\unskip\multistrut}\cr
1971}
1972
1973\def\setmultitablespacing{% test to see if user has set \multitablelinespace.
1974% If so, do nothing. If not, give it an appropriate dimension based on
1975% current baselineskip.
1976\ifdim\multitablelinespace=0pt
1977%% strut to put in table in case some entry doesn't have descenders,
1978%% to keep lines equally spaced
1979\let\multistrut = \strut
1980%% Test to see if parskip is larger than space between lines of
1981%% table. If not, do nothing.
1982%%        If so, set to same dimension as multitablelinespace.
1983\else
1984\gdef\multistrut{\vrule height\multitablelinespace depth\dp0
1985width0pt\relax} \fi
1986\ifdim\multitableparskip>\multitablelinespace
1987\global\multitableparskip=\multitablelinespace
1988\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
1989                                      %% than skip between lines in the table.
1990\fi%
1991\ifdim\multitableparskip=0pt
1992\global\multitableparskip=\multitablelinespace
1993\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
1994                                      %% than skip between lines in the table.
1995\fi}
1996
1997
1998\message{conditionals,}
1999% Prevent errors for section commands.
2000% Used in @ignore and in failing conditionals.
2001\def\ignoresections{%
2002  \let\chapter=\relax
2003  \let\unnumbered=\relax
2004  \let\top=\relax
2005  \let\unnumberedsec=\relax
2006  \let\unnumberedsection=\relax
2007  \let\unnumberedsubsec=\relax
2008  \let\unnumberedsubsection=\relax
2009  \let\unnumberedsubsubsec=\relax
2010  \let\unnumberedsubsubsection=\relax
2011  \let\section=\relax
2012  \let\subsec=\relax
2013  \let\subsubsec=\relax
2014  \let\subsection=\relax
2015  \let\subsubsection=\relax
2016  \let\appendix=\relax
2017  \let\appendixsec=\relax
2018  \let\appendixsection=\relax
2019  \let\appendixsubsec=\relax
2020  \let\appendixsubsection=\relax
2021  \let\appendixsubsubsec=\relax
2022  \let\appendixsubsubsection=\relax
2023  \let\contents=\relax
2024  \let\smallbook=\relax
2025  \let\titlepage=\relax
2026}
2027
2028% Used in nested conditionals, where we have to parse the Texinfo source
2029% and so want to turn off most commands, in case they are used
2030% incorrectly.
2031%
2032\def\ignoremorecommands{%
2033  \let\defcodeindex = \relax
2034  \let\defcv = \relax
2035  \let\deffn = \relax
2036  \let\deffnx = \relax
2037  \let\defindex = \relax
2038  \let\defivar = \relax
2039  \let\defmac = \relax
2040  \let\defmethod = \relax
2041  \let\defop = \relax
2042  \let\defopt = \relax
2043  \let\defspec = \relax
2044  \let\deftp = \relax
2045  \let\deftypefn = \relax
2046  \let\deftypefun = \relax
2047  \let\deftypevar = \relax
2048  \let\deftypevr = \relax
2049  \let\defun = \relax
2050  \let\defvar = \relax
2051  \let\defvr = \relax
2052  \let\ref = \relax
2053  \let\xref = \relax
2054  \let\printindex = \relax
2055  \let\pxref = \relax
2056  \let\settitle = \relax
2057  \let\setchapternewpage = \relax
2058  \let\setchapterstyle = \relax
2059  \let\everyheading = \relax
2060  \let\evenheading = \relax
2061  \let\oddheading = \relax
2062  \let\everyfooting = \relax
2063  \let\evenfooting = \relax
2064  \let\oddfooting = \relax
2065  \let\headings = \relax
2066  \let\include = \relax
2067  \let\lowersections = \relax
2068  \let\down = \relax
2069  \let\raisesections = \relax
2070  \let\up = \relax
2071  \let\set = \relax
2072  \let\clear = \relax
2073  \let\item = \relax
2074}
2075
2076% Ignore @ignore ... @end ignore.
2077%
2078\def\ignore{\doignore{ignore}}
2079
2080% Ignore @ifinfo, @ifhtml, @ifnottex, @html, @menu, and @direntry text.
2081%
2082\def\ifinfo{\doignore{ifinfo}}
2083\def\ifhtml{\doignore{ifhtml}}
2084\def\ifnottex{\doignore{ifnottex}}
2085\def\html{\doignore{html}}
2086\def\menu{\doignore{menu}}
2087\def\direntry{\doignore{direntry}}
2088
2089% @dircategory CATEGORY  -- specify a category of the dir file
2090% which this file should belong to.  Ignore this in TeX.
2091\let\dircategory = \comment
2092
2093% Ignore text until a line `@end #1'.
2094%
2095\def\doignore#1{\begingroup
2096  % Don't complain about control sequences we have declared \outer.
2097  \ignoresections
2098  %
2099  % Define a command to swallow text until we reach `@end #1'.
2100  % This @ is a catcode 12 token (that is the normal catcode of @ in
2101  % this texinfo.tex file).  We change the catcode of @ below to match.
2102  \long\def\doignoretext##1@end #1{\enddoignore}%
2103  %
2104  % Make sure that spaces turn into tokens that match what \doignoretext wants.
2105  \catcode32 = 10
2106  %
2107  % Ignore braces, too, so mismatched braces don't cause trouble.
2108  \catcode`\{ = 9
2109  \catcode`\} = 9
2110  %
2111  % We must not have @c interpreted as a control sequence.
2112  \catcode`\@ = 12
2113  %
2114  % Make the letter c a comment character so that the rest of the line
2115  % will be ignored. This way, the document can have (for example)
2116  %   @c @end ifinfo
2117  % and the @end ifinfo will be properly ignored.
2118  % (We've just changed @ to catcode 12.)
2119  \catcode`\c = 14
2120  %
2121  % And now expand that command.
2122  \doignoretext
2123}
2124
2125% What we do to finish off ignored text.
2126%
2127\def\enddoignore{\endgroup\ignorespaces}%
2128
2129\newif\ifwarnedobs\warnedobsfalse
2130\def\obstexwarn{%
2131  \ifwarnedobs\relax\else
2132  % We need to warn folks that they may have trouble with TeX 3.0.
2133  % This uses \immediate\write16 rather than \message to get newlines.
2134    \immediate\write16{}
2135    \immediate\write16{WARNING: for users of Unix TeX 3.0!}
2136    \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).}
2137    \immediate\write16{If you are running another version of TeX, relax.}
2138    \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.}
2139    \immediate\write16{  Then upgrade your TeX installation if you can.}
2140    \immediate\write16(See ftp://ftp.gnu.org/pub/gnu/TeX.README.)}
2141    \immediate\write16{If you are stuck with version 3.0, run the}
2142    \immediate\write16{  script ``tex3patch'' from the Texinfo distribution}
2143    \immediate\write16{  to use a workaround.}
2144    \immediate\write16{}
2145    \global\warnedobstrue
2146    \fi
2147}
2148
2149% **In TeX 3.0, setting text in \nullfont hangs tex.  For a
2150% workaround (which requires the file ``dummy.tfm'' to be installed),
2151% uncomment the following line:
2152%%%%%\font\nullfont=dummy\let\obstexwarn=\relax
2153
2154% Ignore text, except that we keep track of conditional commands for
2155% purposes of nesting, up to an `@end #1' command.
2156%
2157\def\nestedignore#1{%
2158  \obstexwarn
2159  % We must actually expand the ignored text to look for the @end
2160  % command, so that nested ignore constructs work.  Thus, we put the
2161  % text into a \vbox and then do nothing with the result.  To minimize
2162  % the change of memory overflow, we follow the approach outlined on
2163  % page 401 of the TeXbook: make the current font be a dummy font.
2164  %
2165  \setbox0 = \vbox\bgroup
2166    % Don't complain about control sequences we have declared \outer.
2167    \ignoresections
2168    %
2169    % Define `@end #1' to end the box, which will in turn undefine the
2170    % @end command again.
2171    \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}%
2172    %
2173    % We are going to be parsing Texinfo commands.  Most cause no
2174    % trouble when they are used incorrectly, but some commands do
2175    % complicated argument parsing or otherwise get confused, so we
2176    % undefine them.
2177    %
2178    % We can't do anything about stray @-signs, unfortunately;
2179    % they'll produce `undefined control sequence' errors.
2180    \ignoremorecommands
2181    %
2182    % Set the current font to be \nullfont, a TeX primitive, and define
2183    % all the font commands to also use \nullfont.  We don't use
2184    % dummy.tfm, as suggested in the TeXbook, because not all sites
2185    % might have that installed.  Therefore, math mode will still
2186    % produce output, but that should be an extremely small amount of
2187    % stuff compared to the main input.
2188    %
2189    \nullfont
2190    \let\tenrm = \nullfont  \let\tenit = \nullfont  \let\tensl = \nullfont
2191    \let\tenbf = \nullfont  \let\tentt = \nullfont  \let\smallcaps = \nullfont
2192    \let\tensf = \nullfont
2193    % Similarly for index fonts (mostly for their use in
2194    % smallexample)
2195    \let\indrm = \nullfont  \let\indit = \nullfont  \let\indsl = \nullfont
2196    \let\indbf = \nullfont  \let\indtt = \nullfont  \let\indsc = \nullfont
2197    \let\indsf = \nullfont
2198    %
2199    % Don't complain when characters are missing from the fonts.
2200    \tracinglostchars = 0
2201    %
2202    % Don't bother to do space factor calculations.
2203    \frenchspacing
2204    %
2205    % Don't report underfull hboxes.
2206    \hbadness = 10000
2207    %
2208    % Do minimal line-breaking.
2209    \pretolerance = 10000
2210    %
2211    % Do not execute instructions in @tex
2212    \def\tex{\doignore{tex}}%
2213    % Do not execute macro definitions.
2214    % `c' is a comment character, so the word `macro' will get cut off.
2215    \def\macro{\doignore{ma}}%
2216}
2217
2218% @set VAR sets the variable VAR to an empty value.
2219% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
2220%
2221% Since we want to separate VAR from REST-OF-LINE (which might be
2222% empty), we can't just use \parsearg; we have to insert a space of our
2223% own to delimit the rest of the line, and then take it out again if we
2224% didn't need it.  Make sure the catcode of space is correct to avoid
2225% losing inside @example, for instance.
2226%
2227\def\set{\begingroup\catcode` =10
2228  \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR.
2229  \parsearg\setxxx}
2230\def\setxxx#1{\setyyy#1 \endsetyyy}
2231\def\setyyy#1 #2\endsetyyy{%
2232  \def\temp{#2}%
2233  \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
2234  \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
2235  \fi
2236  \endgroup
2237}
2238% Can't use \xdef to pre-expand #2 and save some time, since \temp or
2239% \next or other control sequences that we've defined might get us into
2240% an infinite loop. Consider `@set foo @cite{bar}'.
2241\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}}
2242
2243% @clear VAR clears (i.e., unsets) the variable VAR.
2244%
2245\def\clear{\parsearg\clearxxx}
2246\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax}
2247
2248% @value{foo} gets the text saved in variable foo.
2249{
2250  \catcode`\_ = \active
2251  %
2252  % We might end up with active _ or - characters in the argument if
2253  % we're called from @code, as @code{@value{foo-bar_}}.  So \let any
2254  % such active characters to their normal equivalents.
2255  \gdef\value{\begingroup
2256    \catcode`\-=12 \catcode`\_=12
2257    \indexbreaks \let_\normalunderscore
2258    \valuexxx}
2259}
2260\def\valuexxx#1{\expandablevalue{#1}\endgroup}
2261
2262% We have this subroutine so that we can handle at least some @value's
2263% properly in indexes (we \let\value to this in \indexdummies).  Ones
2264% whose names contain - or _ still won't work, but we can't do anything
2265% about that.  The command has to be fully expandable, since the result
2266% winds up in the index file.  This means that if the variable's value
2267% contains other Texinfo commands, it's almost certain it will fail
2268% (although perhaps we could fix that with sufficient work to do a
2269% one-level expansion on the result, instead of complete).
2270%
2271\def\expandablevalue#1{%
2272  \expandafter\ifx\csname SET#1\endcsname\relax
2273    {[No value for ``#1'']}%
2274  \else
2275    \csname SET#1\endcsname
2276  \fi
2277}
2278
2279% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
2280% with @set.
2281%
2282\def\ifset{\parsearg\ifsetxxx}
2283\def\ifsetxxx #1{%
2284  \expandafter\ifx\csname SET#1\endcsname\relax
2285    \expandafter\ifsetfail
2286  \else
2287    \expandafter\ifsetsucceed
2288  \fi
2289}
2290\def\ifsetsucceed{\conditionalsucceed{ifset}}
2291\def\ifsetfail{\nestedignore{ifset}}
2292\defineunmatchedend{ifset}
2293
2294% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
2295% defined with @set, or has been undefined with @clear.
2296%
2297\def\ifclear{\parsearg\ifclearxxx}
2298\def\ifclearxxx #1{%
2299  \expandafter\ifx\csname SET#1\endcsname\relax
2300    \expandafter\ifclearsucceed
2301  \else
2302    \expandafter\ifclearfail
2303  \fi
2304}
2305\def\ifclearsucceed{\conditionalsucceed{ifclear}}
2306\def\ifclearfail{\nestedignore{ifclear}}
2307\defineunmatchedend{ifclear}
2308
2309% @iftex, @ifnothtml, @ifnotinfo always succeed; we read the text
2310% following, through the first @end iftex (etc.).  Make `@end iftex'
2311% (etc.) valid only after an @iftex.
2312%
2313\def\iftex{\conditionalsucceed{iftex}}
2314\def\ifnothtml{\conditionalsucceed{ifnothtml}}
2315\def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
2316\defineunmatchedend{iftex}
2317\defineunmatchedend{ifnothtml}
2318\defineunmatchedend{ifnotinfo}
2319
2320% We can't just want to start a group at @iftex (for example) and end it
2321% at @end iftex, since then @set commands inside the conditional have no
2322% effect (they'd get reverted at the end of the group).  So we must
2323% define \Eiftex to redefine itself to be its previous value.  (We can't
2324% just define it to fail again with an ``unmatched end'' error, since
2325% the @ifset might be nested.)
2326%
2327\def\conditionalsucceed#1{%
2328  \edef\temp{%
2329    % Remember the current value of \E#1.
2330    \let\nece{prevE#1} = \nece{E#1}%
2331    %
2332    % At the `@end #1', redefine \E#1 to be its previous value.
2333    \def\nece{E#1}{\let\nece{E#1} = \nece{prevE#1}}%
2334  }%
2335  \temp
2336}
2337
2338% We need to expand lots of \csname's, but we don't want to expand the
2339% control sequences after we've constructed them.
2340%
2341\def\nece#1{\expandafter\noexpand\csname#1\endcsname}
2342
2343% @defininfoenclose.
2344\let\definfoenclose=\comment
2345
2346
2347\message{indexing,}
2348% Index generation facilities
2349
2350% Define \newwrite to be identical to plain tex's \newwrite
2351% except not \outer, so it can be used within \newindex.
2352{\catcode`\@=11
2353\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}}
2354
2355% \newindex {foo} defines an index named foo.
2356% It automatically defines \fooindex such that
2357% \fooindex ...rest of line... puts an entry in the index foo.
2358% It also defines \fooindfile to be the number of the output channel for
2359% the file that accumulates this index.  The file's extension is foo.
2360% The name of an index should be no more than 2 characters long
2361% for the sake of vms.
2362%
2363\def\newindex#1{%
2364  \iflinks
2365    \expandafter\newwrite \csname#1indfile\endcsname
2366    \openout \csname#1indfile\endcsname \jobname.#1 % Open the file
2367  \fi
2368  \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
2369    \noexpand\doindex{#1}}
2370}
2371
2372% @defindex foo  ==  \newindex{foo}
2373
2374\def\defindex{\parsearg\newindex}
2375
2376% Define @defcodeindex, like @defindex except put all entries in @code.
2377
2378\def\newcodeindex#1{%
2379  \iflinks
2380    \expandafter\newwrite \csname#1indfile\endcsname
2381    \openout \csname#1indfile\endcsname \jobname.#1
2382  \fi
2383  \expandafter\xdef\csname#1index\endcsname{%
2384    \noexpand\docodeindex{#1}}
2385}
2386
2387\def\defcodeindex{\parsearg\newcodeindex}
2388
2389% @synindex foo bar    makes index foo feed into index bar.
2390% Do this instead of @defindex foo if you don't want it as a separate index.
2391% The \closeout helps reduce unnecessary open files; the limit on the
2392% Acorn RISC OS is a mere 16 files.
2393\def\synindex#1 #2 {%
2394  \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname
2395  \expandafter\closeout\csname#1indfile\endcsname
2396  \expandafter\let\csname#1indfile\endcsname=\synindexfoo
2397  \expandafter\xdef\csname#1index\endcsname{% define \xxxindex
2398    \noexpand\doindex{#2}}%
2399}
2400
2401% @syncodeindex foo bar   similar, but put all entries made for index foo
2402% inside @code.
2403\def\syncodeindex#1 #2 {%
2404  \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname
2405  \expandafter\closeout\csname#1indfile\endcsname
2406  \expandafter\let\csname#1indfile\endcsname=\synindexfoo
2407  \expandafter\xdef\csname#1index\endcsname{% define \xxxindex
2408    \noexpand\docodeindex{#2}}%
2409}
2410
2411% Define \doindex, the driver for all \fooindex macros.
2412% Argument #1 is generated by the calling \fooindex macro,
2413%  and it is "foo", the name of the index.
2414
2415% \doindex just uses \parsearg; it calls \doind for the actual work.
2416% This is because \doind is more useful to call from other macros.
2417
2418% There is also \dosubind {index}{topic}{subtopic}
2419% which makes an entry in a two-level index such as the operation index.
2420
2421\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer}
2422\def\singleindexer #1{\doind{\indexname}{#1}}
2423
2424% like the previous two, but they put @code around the argument.
2425\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer}
2426\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}}
2427
2428\def\indexdummies{%
2429\def\ { }%
2430% Take care of the plain tex accent commands.
2431\def\"{\realbackslash "}%
2432\def\`{\realbackslash `}%
2433\def\'{\realbackslash '}%
2434\def\^{\realbackslash ^}%
2435\def\~{\realbackslash ~}%
2436\def\={\realbackslash =}%
2437\def\b{\realbackslash b}%
2438\def\c{\realbackslash c}%
2439\def\d{\realbackslash d}%
2440\def\u{\realbackslash u}%
2441\def\v{\realbackslash v}%
2442\def\H{\realbackslash H}%
2443% Take care of the plain tex special European modified letters.
2444\def\oe{\realbackslash oe}%
2445\def\ae{\realbackslash ae}%
2446\def\aa{\realbackslash aa}%
2447\def\OE{\realbackslash OE}%
2448\def\AE{\realbackslash AE}%
2449\def\AA{\realbackslash AA}%
2450\def\o{\realbackslash o}%
2451\def\O{\realbackslash O}%
2452\def\l{\realbackslash l}%
2453\def\L{\realbackslash L}%
2454\def\ss{\realbackslash ss}%
2455% Take care of texinfo commands likely to appear in an index entry.
2456% (Must be a way to avoid doing expansion at all, and thus not have to
2457% laboriously list every single command here.)
2458\def\@{@}% will be @@ when we switch to @ as escape char.
2459% Need these in case \tex is in effect and \{ is a \delimiter again.
2460% But can't use \lbracecmd and \rbracecmd because texindex assumes
2461% braces and backslashes are used only as delimiters.
2462\let\{ = \mylbrace
2463\let\} = \myrbrace
2464\def\_{{\realbackslash _}}%
2465\def\w{\realbackslash w }%
2466\def\bf{\realbackslash bf }%
2467%\def\rm{\realbackslash rm }%
2468\def\sl{\realbackslash sl }%
2469\def\sf{\realbackslash sf}%
2470\def\tt{\realbackslash tt}%
2471\def\gtr{\realbackslash gtr}%
2472\def\less{\realbackslash less}%
2473\def\hat{\realbackslash hat}%
2474\def\TeX{\realbackslash TeX}%
2475\def\dots{\realbackslash dots }%
2476\def\result{\realbackslash result}%
2477\def\equiv{\realbackslash equiv}%
2478\def\expansion{\realbackslash expansion}%
2479\def\print{\realbackslash print}%
2480\def\error{\realbackslash error}%
2481\def\point{\realbackslash point}%
2482\def\copyright{\realbackslash copyright}%
2483\def\tclose##1{\realbackslash tclose {##1}}%
2484\def\code##1{\realbackslash code {##1}}%
2485\def\uref##1{\realbackslash uref {##1}}%
2486\def\url##1{\realbackslash url {##1}}%
2487\def\env##1{\realbackslash env {##1}}%
2488\def\command##1{\realbackslash command {##1}}%
2489\def\option##1{\realbackslash option {##1}}%
2490\def\dotless##1{\realbackslash dotless {##1}}%
2491\def\samp##1{\realbackslash samp {##1}}%
2492\def\,##1{\realbackslash ,{##1}}%
2493\def\t##1{\realbackslash t {##1}}%
2494\def\r##1{\realbackslash r {##1}}%
2495\def\i##1{\realbackslash i {##1}}%
2496\def\b##1{\realbackslash b {##1}}%
2497\def\sc##1{\realbackslash sc {##1}}%
2498\def\cite##1{\realbackslash cite {##1}}%
2499\def\key##1{\realbackslash key {##1}}%
2500\def\file##1{\realbackslash file {##1}}%
2501\def\var##1{\realbackslash var {##1}}%
2502\def\kbd##1{\realbackslash kbd {##1}}%
2503\def\dfn##1{\realbackslash dfn {##1}}%
2504\def\emph##1{\realbackslash emph {##1}}%
2505\def\acronym##1{\realbackslash acronym {##1}}%
2506%
2507% Handle some cases of @value -- where the variable name does not
2508% contain - or _, and the value does not contain any
2509% (non-fully-expandable) commands.
2510\let\value = \expandablevalue
2511%
2512\unsepspaces
2513% Turn off macro expansion
2514\turnoffmacros
2515}
2516
2517% If an index command is used in an @example environment, any spaces
2518% therein should become regular spaces in the raw index file, not the
2519% expansion of \tie (\\leavevmode \penalty \@M \ ).
2520{\obeyspaces
2521 \gdef\unsepspaces{\obeyspaces\let =\space}}
2522
2523% \indexnofonts no-ops all font-change commands.
2524% This is used when outputting the strings to sort the index by.
2525\def\indexdummyfont#1{#1}
2526\def\indexdummytex{TeX}
2527\def\indexdummydots{...}
2528
2529\def\indexnofonts{%
2530% Just ignore accents.
2531\let\,=\indexdummyfont
2532\let\"=\indexdummyfont
2533\let\`=\indexdummyfont
2534\let\'=\indexdummyfont
2535\let\^=\indexdummyfont
2536\let\~=\indexdummyfont
2537\let\==\indexdummyfont
2538\let\b=\indexdummyfont
2539\let\c=\indexdummyfont
2540\let\d=\indexdummyfont
2541\let\u=\indexdummyfont
2542\let\v=\indexdummyfont
2543\let\H=\indexdummyfont
2544\let\dotless=\indexdummyfont
2545% Take care of the plain tex special European modified letters.
2546\def\oe{oe}%
2547\def\ae{ae}%
2548\def\aa{aa}%
2549\def\OE{OE}%
2550\def\AE{AE}%
2551\def\AA{AA}%
2552\def\o{o}%
2553\def\O{O}%
2554\def\l{l}%
2555\def\L{L}%
2556\def\ss{ss}%
2557\let\w=\indexdummyfont
2558\let\t=\indexdummyfont
2559\let\r=\indexdummyfont
2560\let\i=\indexdummyfont
2561\let\b=\indexdummyfont
2562\let\emph=\indexdummyfont
2563\let\strong=\indexdummyfont
2564\let\cite=\indexdummyfont
2565\let\sc=\indexdummyfont
2566%Don't no-op \tt, since it isn't a user-level command
2567% and is used in the definitions of the active chars like <, >, |...
2568%\let\tt=\indexdummyfont
2569\let\tclose=\indexdummyfont
2570\let\code=\indexdummyfont
2571\let\url=\indexdummyfont
2572\let\uref=\indexdummyfont
2573\let\env=\indexdummyfont
2574\let\command=\indexdummyfont
2575\let\option=\indexdummyfont
2576\let\file=\indexdummyfont
2577\let\samp=\indexdummyfont
2578\let\kbd=\indexdummyfont
2579\let\key=\indexdummyfont
2580\let\var=\indexdummyfont
2581\let\TeX=\indexdummytex
2582\let\dots=\indexdummydots
2583\def\@{@}%
2584}
2585
2586% To define \realbackslash, we must make \ not be an escape.
2587% We must first make another character (@) an escape
2588% so we do not become unable to do a definition.
2589
2590{\catcode`\@=0 \catcode`\\=\other
2591 @gdef@realbackslash{\}}
2592
2593\let\indexbackslash=0  %overridden during \printindex.
2594\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
2595
2596% For \ifx comparisons.
2597\def\emptymacro{\empty}
2598
2599% Most index entries go through here, but \dosubind is the general case.
2600%
2601\def\doind#1#2{\dosubind{#1}{#2}\empty}
2602
2603% Workhorse for all \fooindexes.
2604% #1 is name of index, #2 is stuff to put there, #3 is subentry --
2605% \empty if called from \doind, as we usually are.  The main exception
2606% is with defuns, which call us directly.
2607%
2608\def\dosubind#1#2#3{%
2609  % Put the index entry in the margin if desired.
2610  \ifx\SETmarginindex\relax\else
2611    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}%
2612  \fi
2613  {%
2614    \count255=\lastpenalty
2615    {%
2616      \indexdummies % Must do this here, since \bf, etc expand at this stage
2617      \escapechar=`\\
2618      {%
2619        \let\folio = 0% We will expand all macros now EXCEPT \folio.
2620        \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
2621        % so it will be output as is; and it will print as backslash.
2622        %
2623        \def\thirdarg{#3}%
2624        %
2625        % If third arg is present, precede it with space in sort key.
2626        \ifx\thirdarg\emptymacro
2627          \let\subentry = \empty
2628        \else
2629          \def\subentry{ #3}%
2630        \fi
2631        %
2632        % First process the index entry with all font commands turned
2633        % off to get the string to sort by.
2634        {\indexnofonts \xdef\indexsorttmp{#2\subentry}}%
2635        %
2636        % Now the real index entry with the fonts.
2637        \toks0 = {#2}%
2638        %
2639        % If third (subentry) arg is present, add it to the index
2640        % string.  And include a space.
2641        \ifx\thirdarg\emptymacro \else
2642          \toks0 = \expandafter{\the\toks0 \space #3}%
2643        \fi
2644        %
2645        % Set up the complete index entry, with both the sort key
2646        % and the original text, including any font commands.  We write
2647        % three arguments to \entry to the .?? file, texindex reduces to
2648        % two when writing the .??s sorted result.
2649        \edef\temp{%
2650          \write\csname#1indfile\endcsname{%
2651            \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}%
2652        }%
2653        %
2654        % If a skip is the last thing on the list now, preserve it
2655        % by backing up by \lastskip, doing the \write, then inserting
2656        % the skip again.  Otherwise, the whatsit generated by the
2657        % \write will make \lastskip zero.  The result is that sequences
2658        % like this:
2659        % @end defun
2660        % @tindex whatever
2661        % @defun ...
2662        % will have extra space inserted, because the \medbreak in the
2663        % start of the @defun won't see the skip inserted by the @end of
2664        % the previous defun.
2665        %
2666        % But don't do any of this if we're not in vertical mode.  We
2667        % don't want to do a \vskip and prematurely end a paragraph.
2668        %
2669        % Avoid page breaks due to these extra skips, too.
2670        %
2671        \iflinks
2672          \ifvmode
2673            \skip0 = \lastskip
2674            \ifdim\lastskip = 0pt \else \nobreak\vskip-\lastskip \fi
2675          \fi
2676          %
2677          \temp % do the write
2678          %
2679          %
2680          \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi
2681        \fi
2682      }%
2683    }%
2684    \penalty\count255
2685  }%
2686}
2687
2688% The index entry written in the file actually looks like
2689%  \entry {sortstring}{page}{topic}
2690% or
2691%  \entry {sortstring}{page}{topic}{subtopic}
2692% The texindex program reads in these files and writes files
2693% containing these kinds of lines:
2694%  \initial {c}
2695%     before the first topic whose initial is c
2696%  \entry {topic}{pagelist}
2697%     for a topic that is used without subtopics
2698%  \primary {topic}
2699%     for the beginning of a topic that is used with subtopics
2700%  \secondary {subtopic}{pagelist}
2701%     for each subtopic.
2702
2703% Define the user-accessible indexing commands
2704% @findex, @vindex, @kindex, @cindex.
2705
2706\def\findex {\fnindex}
2707\def\kindex {\kyindex}
2708\def\cindex {\cpindex}
2709\def\vindex {\vrindex}
2710\def\tindex {\tpindex}
2711\def\pindex {\pgindex}
2712
2713\def\cindexsub {\begingroup\obeylines\cindexsub}
2714{\obeylines %
2715\gdef\cindexsub "#1" #2^^M{\endgroup %
2716\dosubind{cp}{#2}{#1}}}
2717
2718% Define the macros used in formatting output of the sorted index material.
2719
2720% @printindex causes a particular index (the ??s file) to get printed.
2721% It does not print any chapter heading (usually an @unnumbered).
2722%
2723\def\printindex{\parsearg\doprintindex}
2724\def\doprintindex#1{\begingroup
2725  \dobreak \chapheadingskip{10000}%
2726  %
2727  \indexfonts \rm
2728  \tolerance = 9500
2729  \indexbreaks
2730  %
2731  % See if the index file exists and is nonempty.
2732  % Change catcode of @ here so that if the index file contains
2733  % \initial {@}
2734  % as its first line, TeX doesn't complain about mismatched braces
2735  % (because it thinks @} is a control sequence).
2736  \catcode`\@ = 11
2737  \openin 1 \jobname.#1s
2738  \ifeof 1
2739    % \enddoublecolumns gets confused if there is no text in the index,
2740    % and it loses the chapter title and the aux file entries for the
2741    % index.  The easiest way to prevent this problem is to make sure
2742    % there is some text.
2743    \putwordIndexNonexistent
2744  \else
2745    %
2746    % If the index file exists but is empty, then \openin leaves \ifeof
2747    % false.  We have to make TeX try to read something from the file, so
2748    % it can discover if there is anything in it.
2749    \read 1 to \temp
2750    \ifeof 1
2751      \putwordIndexIsEmpty
2752    \else
2753      % Index files are almost Texinfo source, but we use \ as the escape
2754      % character.  It would be better to use @, but that's too big a change
2755      % to make right now.
2756      \def\indexbackslash{\rawbackslashxx}%
2757      \catcode`\\ = 0
2758      \escapechar = `\\
2759      \begindoublecolumns
2760      \input \jobname.#1s
2761      \enddoublecolumns
2762    \fi
2763  \fi
2764  \closein 1
2765\endgroup}
2766
2767% These macros are used by the sorted index file itself.
2768% Change them to control the appearance of the index.
2769
2770\def\initial#1{{%
2771  % Some minor font changes for the special characters.
2772  \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
2773  %
2774  % Remove any glue we may have, we'll be inserting our own.
2775  \removelastskip
2776  %
2777  % We like breaks before the index initials, so insert a bonus.
2778  \penalty -300
2779  %
2780  % Typeset the initial.  Making this add up to a whole number of
2781  % baselineskips increases the chance of the dots lining up from column
2782  % to column.  It still won't often be perfect, because of the stretch
2783  % we need before each entry, but it's better.
2784  %
2785  % No shrink because it confuses \balancecolumns.
2786  \vskip 1.67\baselineskip plus .5\baselineskip
2787  \leftline{\secbf #1}%
2788  \vskip .33\baselineskip plus .1\baselineskip
2789  %
2790  % Do our best not to break after the initial.
2791  \nobreak
2792}}
2793
2794% This typesets a paragraph consisting of #1, dot leaders, and then #2
2795% flush to the right margin.  It is used for index and table of contents
2796% entries.  The paragraph is indented by \leftskip.
2797%
2798\def\entry#1#2{\begingroup
2799  %
2800  % Start a new paragraph if necessary, so our assignments below can't
2801  % affect previous text.
2802  \par
2803  %
2804  % Do not fill out the last line with white space.
2805  \parfillskip = 0in
2806  %
2807  % No extra space above this paragraph.
2808  \parskip = 0in
2809  %
2810  % Do not prefer a separate line ending with a hyphen to fewer lines.
2811  \finalhyphendemerits = 0
2812  %
2813  % \hangindent is only relevant when the entry text and page number
2814  % don't both fit on one line.  In that case, bob suggests starting the
2815  % dots pretty far over on the line.  Unfortunately, a large
2816  % indentation looks wrong when the entry text itself is broken across
2817  % lines.  So we use a small indentation and put up with long leaders.
2818  %
2819  % \hangafter is reset to 1 (which is the value we want) at the start
2820  % of each paragraph, so we need not do anything with that.
2821  \hangindent = 2em
2822  %
2823  % When the entry text needs to be broken, just fill out the first line
2824  % with blank space.
2825  \rightskip = 0pt plus1fil
2826  %
2827  % A bit of stretch before each entry for the benefit of balancing columns.
2828  \vskip 0pt plus1pt
2829  %
2830  % Start a ``paragraph'' for the index entry so the line breaking
2831  % parameters we've set above will have an effect.
2832  \noindent
2833  %
2834  % Insert the text of the index entry.  TeX will do line-breaking on it.
2835  #1%
2836  % The following is kludged to not output a line of dots in the index if
2837  % there are no page numbers.  The next person who breaks this will be
2838  % cursed by a Unix daemon.
2839  \def\tempa{{\rm }}%
2840  \def\tempb{#2}%
2841  \edef\tempc{\tempa}%
2842  \edef\tempd{\tempb}%
2843  \ifx\tempc\tempd\ \else%
2844    %
2845    % If we must, put the page number on a line of its own, and fill out
2846    % this line with blank space.  (The \hfil is overwhelmed with the
2847    % fill leaders glue in \indexdotfill if the page number does fit.)
2848    \hfil\penalty50
2849    \null\nobreak\indexdotfill % Have leaders before the page number.
2850    %
2851    % The `\ ' here is removed by the implicit \unskip that TeX does as
2852    % part of (the primitive) \par.  Without it, a spurious underfull
2853    % \hbox ensues.
2854    \ #2% The page number ends the paragraph.
2855  \fi%
2856  \par
2857\endgroup}
2858
2859% Like \dotfill except takes at least 1 em.
2860\def\indexdotfill{\cleaders
2861  \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
2862
2863\def\primary #1{\line{#1\hfil}}
2864
2865\newskip\secondaryindent \secondaryindent=0.5cm
2866
2867\def\secondary #1#2{
2868{\parfillskip=0in \parskip=0in
2869\hangindent =1in \hangafter=1
2870\noindent\hskip\secondaryindent\hbox{#1}\indexdotfill #2\par
2871}}
2872
2873% Define two-column mode, which we use to typeset indexes.
2874% Adapted from the TeXbook, page 416, which is to say,
2875% the manmac.tex format used to print the TeXbook itself.
2876\catcode`\@=11
2877
2878\newbox\partialpage
2879\newdimen\doublecolumnhsize
2880
2881\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
2882  % Grab any single-column material above us.
2883  \output = {%
2884    %
2885    % Here is a possibility not foreseen in manmac: if we accumulate a
2886    % whole lot of material, we might end up calling this \output
2887    % routine twice in a row (see the doublecol-lose test, which is
2888    % essentially a couple of indexes with @setchapternewpage off).  In
2889    % that case we just ship out what is in \partialpage with the normal
2890    % output routine.  Generally, \partialpage will be empty when this
2891    % runs and this will be a no-op.  See the indexspread.tex test case.
2892    \ifvoid\partialpage \else
2893      \onepageout{\pagecontents\partialpage}%
2894    \fi
2895    %
2896    \global\setbox\partialpage = \vbox{%
2897      % Unvbox the main output page.
2898      \unvbox\PAGE
2899      \kern-\topskip \kern\baselineskip
2900    }%
2901  }%
2902  \eject % run that output routine to set \partialpage
2903  %
2904  % Use the double-column output routine for subsequent pages.
2905  \output = {\doublecolumnout}%
2906  %
2907  % Change the page size parameters.  We could do this once outside this
2908  % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
2909  % format, but then we repeat the same computation.  Repeating a couple
2910  % of assignments once per index is clearly meaningless for the
2911  % execution time, so we may as well do it in one place.
2912  %
2913  % First we halve the line length, less a little for the gutter between
2914  % the columns.  We compute the gutter based on the line length, so it
2915  % changes automatically with the paper format.  The magic constant
2916  % below is chosen so that the gutter has the same value (well, +-<1pt)
2917  % as it did when we hard-coded it.
2918  %
2919  % We put the result in a separate register, \doublecolumhsize, so we
2920  % can restore it in \pagesofar, after \hsize itself has (potentially)
2921  % been clobbered.
2922  %
2923  \doublecolumnhsize = \hsize
2924    \advance\doublecolumnhsize by -.04154\hsize
2925    \divide\doublecolumnhsize by 2
2926  \hsize = \doublecolumnhsize
2927  %
2928  % Double the \vsize as well.  (We don't need a separate register here,
2929  % since nobody clobbers \vsize.)
2930  \advance\vsize by -\ht\partialpage
2931  \vsize = 2\vsize
2932}
2933
2934% The double-column output routine for all double-column pages except
2935% the last.
2936%
2937\def\doublecolumnout{%
2938  \splittopskip=\topskip \splitmaxdepth=\maxdepth
2939  % Get the available space for the double columns -- the normal
2940  % (undoubled) page height minus any material left over from the
2941  % previous page.
2942  \dimen@ = \vsize
2943  \divide\dimen@ by 2
2944  %
2945  % box0 will be the left-hand column, box2 the right.
2946  \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
2947  \onepageout\pagesofar
2948  \unvbox255
2949  \penalty\outputpenalty
2950}
2951\def\pagesofar{%
2952  % Re-output the contents of the output page -- any previous material,
2953  % followed by the two boxes we just split, in box0 and box2.
2954  \unvbox\partialpage
2955  %
2956  \hsize = \doublecolumnhsize
2957  \wd0=\hsize \wd2=\hsize
2958  \hbox to\pagewidth{\box0\hfil\box2}%
2959}
2960\def\enddoublecolumns{%
2961  \output = {%
2962    % Split the last of the double-column material.  Leave it on the
2963    % current page, no automatic page break.
2964    \balancecolumns
2965    %
2966    % If we end up splitting too much material for the current page,
2967    % though, there will be another page break right after this \output
2968    % invocation ends.  Having called \balancecolumns once, we do not
2969    % want to call it again.  Therefore, reset \output to its normal
2970    % definition right away.  (We hope \balancecolumns will never be
2971    % called on to balance too much material, but if it is, this makes
2972    % the output somewhat more palatable.)
2973    \global\output = {\onepageout{\pagecontents\PAGE}}%
2974  }%
2975  \eject
2976  \endgroup % started in \begindoublecolumns
2977  %
2978  % \pagegoal was set to the doubled \vsize above, since we restarted
2979  % the current page.  We're now back to normal single-column
2980  % typesetting, so reset \pagegoal to the normal \vsize (after the
2981  % \endgroup where \vsize got restored).
2982  \pagegoal = \vsize
2983}
2984\def\balancecolumns{%
2985  % Called at the end of the double column material.
2986  \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
2987  \dimen@ = \ht0
2988  \advance\dimen@ by \topskip
2989  \advance\dimen@ by-\baselineskip
2990  \divide\dimen@ by 2 % target to split to
2991  %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}%
2992  \splittopskip = \topskip
2993  % Loop until we get a decent breakpoint.
2994  {%
2995    \vbadness = 10000
2996    \loop
2997      \global\setbox3 = \copy0
2998      \global\setbox1 = \vsplit3 to \dimen@
2999    \ifdim\ht3>\dimen@
3000      \global\advance\dimen@ by 1pt
3001    \repeat
3002  }%
3003  %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}%
3004  \setbox0=\vbox to\dimen@{\unvbox1}%
3005  \setbox2=\vbox to\dimen@{\unvbox3}%
3006  %
3007  \pagesofar
3008}
3009\catcode`\@ = \other
3010
3011
3012\message{sectioning,}
3013% Define chapters, sections, etc.
3014
3015\newcount\chapno
3016\newcount\secno        \secno=0
3017\newcount\subsecno     \subsecno=0
3018\newcount\subsubsecno  \subsubsecno=0
3019
3020% This counter is funny since it counts through charcodes of letters A, B, ...
3021\newcount\appendixno  \appendixno = `\@
3022\def\appendixletter{\char\the\appendixno}
3023
3024% Each @chapter defines this as the name of the chapter.
3025% page headings and footings can use it.  @section does likewise.
3026\def\thischapter{}
3027\def\thissection{}
3028
3029\newcount\absseclevel % used to calculate proper heading level
3030\newcount\secbase\secbase=0 % @raise/lowersections modify this count
3031
3032% @raisesections: treat @section as chapter, @subsection as section, etc.
3033\def\raisesections{\global\advance\secbase by -1}
3034\let\up=\raisesections % original BFox name
3035
3036% @lowersections: treat @chapter as section, @section as subsection, etc.
3037\def\lowersections{\global\advance\secbase by 1}
3038\let\down=\lowersections % original BFox name
3039
3040% Choose a numbered-heading macro
3041% #1 is heading level if unmodified by @raisesections or @lowersections
3042% #2 is text for heading
3043\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
3044\ifcase\absseclevel
3045  \chapterzzz{#2}
3046\or
3047  \seczzz{#2}
3048\or
3049  \numberedsubseczzz{#2}
3050\or
3051  \numberedsubsubseczzz{#2}
3052\else
3053  \ifnum \absseclevel<0
3054    \chapterzzz{#2}
3055  \else
3056    \numberedsubsubseczzz{#2}
3057  \fi
3058\fi
3059}
3060
3061% like \numhead, but chooses appendix heading levels
3062\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
3063\ifcase\absseclevel
3064  \appendixzzz{#2}
3065\or
3066  \appendixsectionzzz{#2}
3067\or
3068  \appendixsubseczzz{#2}
3069\or
3070  \appendixsubsubseczzz{#2}
3071\else
3072  \ifnum \absseclevel<0
3073    \appendixzzz{#2}
3074  \else
3075    \appendixsubsubseczzz{#2}
3076  \fi
3077\fi
3078}
3079
3080% like \numhead, but chooses numberless heading levels
3081\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
3082\ifcase\absseclevel
3083  \unnumberedzzz{#2}
3084\or
3085  \unnumberedseczzz{#2}
3086\or
3087  \unnumberedsubseczzz{#2}
3088\or
3089  \unnumberedsubsubseczzz{#2}
3090\else
3091  \ifnum \absseclevel<0
3092    \unnumberedzzz{#2}
3093  \else
3094    \unnumberedsubsubseczzz{#2}
3095  \fi
3096\fi
3097}
3098
3099% @chapter, @appendix, @unnumbered.
3100\def\thischaptername{No Chapter Title}
3101\outer\def\chapter{\parsearg\chapteryyy}
3102\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz
3103\def\chapterzzz #1{%
3104\secno=0 \subsecno=0 \subsubsecno=0
3105\global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}%
3106\chapmacro {#1}{\the\chapno}%
3107\gdef\thissection{#1}%
3108\gdef\thischaptername{#1}%
3109% We don't substitute the actual chapter name into \thischapter
3110% because we don't want its macros evaluated now.
3111\xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}%
3112\toks0 = {#1}%
3113\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}%
3114                                  {\the\chapno}}}%
3115\temp
3116\donoderef
3117\global\let\section = \numberedsec
3118\global\let\subsection = \numberedsubsec
3119\global\let\subsubsection = \numberedsubsubsec
3120}
3121
3122\outer\def\appendix{\parsearg\appendixyyy}
3123\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz
3124\def\appendixzzz #1{%
3125\secno=0 \subsecno=0 \subsubsecno=0
3126\global\advance \appendixno by 1
3127\message{\putwordAppendix\space \appendixletter}%
3128\chapmacro {#1}{\putwordAppendix{} \appendixletter}%
3129\gdef\thissection{#1}%
3130\gdef\thischaptername{#1}%
3131\xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}%
3132\toks0 = {#1}%
3133\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}%
3134                       {\putwordAppendix{} \appendixletter}}}%
3135\temp
3136\appendixnoderef
3137\global\let\section = \appendixsec
3138\global\let\subsection = \appendixsubsec
3139\global\let\subsubsection = \appendixsubsubsec
3140}
3141
3142% @centerchap is like @unnumbered, but the heading is centered.
3143\outer\def\centerchap{\parsearg\centerchapyyy}
3144\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}}
3145
3146% @top is like @unnumbered.
3147\outer\def\top{\parsearg\unnumberedyyy}
3148
3149\outer\def\unnumbered{\parsearg\unnumberedyyy}
3150\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
3151\def\unnumberedzzz #1{%
3152\secno=0 \subsecno=0 \subsubsecno=0
3153%
3154% This used to be simply \message{#1}, but TeX fully expands the
3155% argument to \message.  Therefore, if #1 contained @-commands, TeX
3156% expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
3157% expanded @cite (which turns out to cause errors because \cite is meant
3158% to be executed, not expanded).
3159%
3160% Anyway, we don't want the fully-expanded definition of @cite to appear
3161% as a result of the \message, we just want `@cite' itself.  We use
3162% \the<toks register> to achieve this: TeX expands \the<toks> only once,
3163% simply yielding the contents of <toks register>.  (We also do this for
3164% the toc entries.)
3165\toks0 = {#1}\message{(\the\toks0)}%
3166%
3167\unnumbchapmacro {#1}%
3168\gdef\thischapter{#1}\gdef\thissection{#1}%
3169\toks0 = {#1}%
3170\edef\temp{\noexpand\writetocentry{\realbackslash unnumbchapentry{\the\toks0}}}%
3171\temp
3172\unnumbnoderef
3173\global\let\section = \unnumberedsec
3174\global\let\subsection = \unnumberedsubsec
3175\global\let\subsubsection = \unnumberedsubsubsec
3176}
3177
3178% Sections.
3179\outer\def\numberedsec{\parsearg\secyyy}
3180\def\secyyy #1{\numhead1{#1}} % normally calls seczzz
3181\def\seczzz #1{%
3182\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
3183\gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}%
3184\toks0 = {#1}%
3185\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}%
3186                                  {\the\chapno}{\the\secno}}}%
3187\temp
3188\donoderef
3189\nobreak
3190}
3191
3192\outer\def\appendixsection{\parsearg\appendixsecyyy}
3193\outer\def\appendixsec{\parsearg\appendixsecyyy}
3194\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz
3195\def\appendixsectionzzz #1{%
3196\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
3197\gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}%
3198\toks0 = {#1}%
3199\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}%
3200                                  {\appendixletter}{\the\secno}}}%
3201\temp
3202\appendixnoderef
3203\nobreak
3204}
3205
3206\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy}
3207\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz
3208\def\unnumberedseczzz #1{%
3209\plainsecheading {#1}\gdef\thissection{#1}%
3210\toks0 = {#1}%
3211\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsecentry{\the\toks0}}}%
3212\temp
3213\unnumbnoderef
3214\nobreak
3215}
3216
3217% Subsections.
3218\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy}
3219\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz
3220\def\numberedsubseczzz #1{%
3221\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
3222\subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
3223\toks0 = {#1}%
3224\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}%
3225                                    {\the\chapno}{\the\secno}{\the\subsecno}}}%
3226\temp
3227\donoderef
3228\nobreak
3229}
3230
3231\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy}
3232\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz
3233\def\appendixsubseczzz #1{%
3234\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
3235\subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}%
3236\toks0 = {#1}%
3237\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}%
3238                                {\appendixletter}{\the\secno}{\the\subsecno}}}%
3239\temp
3240\appendixnoderef
3241\nobreak
3242}
3243
3244\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy}
3245\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
3246\def\unnumberedsubseczzz #1{%
3247\plainsubsecheading {#1}\gdef\thissection{#1}%
3248\toks0 = {#1}%
3249\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsecentry%
3250                                    {\the\toks0}}}%
3251\temp
3252\unnumbnoderef
3253\nobreak
3254}
3255
3256% Subsubsections.
3257\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy}
3258\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz
3259\def\numberedsubsubseczzz #1{%
3260\gdef\thissection{#1}\global\advance \subsubsecno by 1 %
3261\subsubsecheading {#1}
3262  {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
3263\toks0 = {#1}%
3264\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}%
3265  {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}%
3266\temp
3267\donoderef
3268\nobreak
3269}
3270
3271\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy}
3272\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz
3273\def\appendixsubsubseczzz #1{%
3274\gdef\thissection{#1}\global\advance \subsubsecno by 1 %
3275\subsubsecheading {#1}
3276  {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
3277\toks0 = {#1}%
3278\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}%
3279  {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}%
3280\temp
3281\appendixnoderef
3282\nobreak
3283}
3284
3285\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy}
3286\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
3287\def\unnumberedsubsubseczzz #1{%
3288\plainsubsubsecheading {#1}\gdef\thissection{#1}%
3289\toks0 = {#1}%
3290\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsubsecentry%
3291                                    {\the\toks0}}}%
3292\temp
3293\unnumbnoderef
3294\nobreak
3295}
3296
3297% These are variants which are not "outer", so they can appear in @ifinfo.
3298% Actually, they should now be obsolete; ordinary section commands should work.
3299\def\infotop{\parsearg\unnumberedzzz}
3300\def\infounnumbered{\parsearg\unnumberedzzz}
3301\def\infounnumberedsec{\parsearg\unnumberedseczzz}
3302\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
3303\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
3304
3305\def\infoappendix{\parsearg\appendixzzz}
3306\def\infoappendixsec{\parsearg\appendixseczzz}
3307\def\infoappendixsubsec{\parsearg\appendixsubseczzz}
3308\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
3309
3310\def\infochapter{\parsearg\chapterzzz}
3311\def\infosection{\parsearg\sectionzzz}
3312\def\infosubsection{\parsearg\subsectionzzz}
3313\def\infosubsubsection{\parsearg\subsubsectionzzz}
3314
3315% These macros control what the section commands do, according
3316% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
3317% Define them by default for a numbered chapter.
3318\global\let\section = \numberedsec
3319\global\let\subsection = \numberedsubsec
3320\global\let\subsubsection = \numberedsubsubsec
3321
3322% Define @majorheading, @heading and @subheading
3323
3324% NOTE on use of \vbox for chapter headings, section headings, and such:
3325%       1) We use \vbox rather than the earlier \line to permit
3326%          overlong headings to fold.
3327%       2) \hyphenpenalty is set to 10000 because hyphenation in a
3328%          heading is obnoxious; this forbids it.
3329%       3) Likewise, headings look best if no \parindent is used, and
3330%          if justification is not attempted.  Hence \raggedright.
3331
3332
3333\def\majorheading{\parsearg\majorheadingzzz}
3334\def\majorheadingzzz #1{%
3335{\advance\chapheadingskip by 10pt \chapbreak }%
3336{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
3337                  \parindent=0pt\raggedright
3338                  \rm #1\hfill}}\bigskip \par\penalty 200}
3339
3340\def\chapheading{\parsearg\chapheadingzzz}
3341\def\chapheadingzzz #1{\chapbreak %
3342{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
3343                  \parindent=0pt\raggedright
3344                  \rm #1\hfill}}\bigskip \par\penalty 200}
3345
3346% @heading, @subheading, @subsubheading.
3347\def\heading{\parsearg\plainsecheading}
3348\def\subheading{\parsearg\plainsubsecheading}
3349\def\subsubheading{\parsearg\plainsubsubsecheading}
3350
3351% These macros generate a chapter, section, etc. heading only
3352% (including whitespace, linebreaking, etc. around it),
3353% given all the information in convenient, parsed form.
3354
3355%%% Args are the skip and penalty (usually negative)
3356\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
3357
3358\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
3359
3360%%% Define plain chapter starts, and page on/off switching for it
3361% Parameter controlling skip before chapter headings (if needed)
3362
3363\newskip\chapheadingskip
3364
3365\def\chapbreak{\dobreak \chapheadingskip {-4000}}
3366\def\chappager{\par\vfill\supereject}
3367\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi}
3368
3369\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname}
3370
3371\def\CHAPPAGoff{%
3372\global\let\contentsalignmacro = \chappager
3373\global\let\pchapsepmacro=\chapbreak
3374\global\let\pagealignmacro=\chappager}
3375
3376\def\CHAPPAGon{%
3377\global\let\contentsalignmacro = \chappager
3378\global\let\pchapsepmacro=\chappager
3379\global\let\pagealignmacro=\chappager
3380\global\def\HEADINGSon{\HEADINGSsingle}}
3381
3382\def\CHAPPAGodd{
3383\global\let\contentsalignmacro = \chapoddpage
3384\global\let\pchapsepmacro=\chapoddpage
3385\global\let\pagealignmacro=\chapoddpage
3386\global\def\HEADINGSon{\HEADINGSdouble}}
3387
3388\CHAPPAGon
3389
3390\def\CHAPFplain{
3391\global\let\chapmacro=\chfplain
3392\global\let\unnumbchapmacro=\unnchfplain
3393\global\let\centerchapmacro=\centerchfplain}
3394
3395% Plain chapter opening.
3396% #1 is the text, #2 the chapter number or empty if unnumbered.
3397\def\chfplain#1#2{%
3398  \pchapsepmacro
3399  {%
3400    \chapfonts \rm
3401    \def\chapnum{#2}%
3402    \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}%
3403    \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
3404          \hangindent = \wd0 \centerparametersmaybe
3405          \unhbox0 #1\par}%
3406  }%
3407  \nobreak\bigskip % no page break after a chapter title
3408  \nobreak
3409}
3410
3411% Plain opening for unnumbered.
3412\def\unnchfplain#1{\chfplain{#1}{}}
3413
3414% @centerchap -- centered and unnumbered.
3415\let\centerparametersmaybe = \relax
3416\def\centerchfplain#1{{%
3417  \def\centerparametersmaybe{%
3418    \advance\rightskip by 3\rightskip
3419    \leftskip = \rightskip
3420    \parfillskip = 0pt
3421  }%
3422  \chfplain{#1}{}%
3423}}
3424
3425\CHAPFplain % The default
3426
3427\def\unnchfopen #1{%
3428\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
3429                       \parindent=0pt\raggedright
3430                       \rm #1\hfill}}\bigskip \par\nobreak
3431}
3432
3433\def\chfopen #1#2{\chapoddpage {\chapfonts
3434\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
3435\par\penalty 5000 %
3436}
3437
3438\def\centerchfopen #1{%
3439\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
3440                       \parindent=0pt
3441                       \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
3442}
3443
3444\def\CHAPFopen{
3445\global\let\chapmacro=\chfopen
3446\global\let\unnumbchapmacro=\unnchfopen
3447\global\let\centerchapmacro=\centerchfopen}
3448
3449
3450% Section titles.
3451\newskip\secheadingskip
3452\def\secheadingbreak{\dobreak \secheadingskip {-1000}}
3453\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}}
3454\def\plainsecheading#1{\sectionheading{sec}{}{#1}}
3455
3456% Subsection titles.
3457\newskip \subsecheadingskip
3458\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}}
3459\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}}
3460\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}}
3461
3462% Subsubsection titles.
3463\let\subsubsecheadingskip = \subsecheadingskip
3464\let\subsubsecheadingbreak = \subsecheadingbreak
3465\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}}
3466\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}}
3467
3468
3469% Print any size section title.
3470%
3471% #1 is the section type (sec/subsec/subsubsec), #2 is the section
3472% number (maybe empty), #3 the text.
3473\def\sectionheading#1#2#3{%
3474  {%
3475    \expandafter\advance\csname #1headingskip\endcsname by \parskip
3476    \csname #1headingbreak\endcsname
3477  }%
3478  {%
3479    % Switch to the right set of fonts.
3480    \csname #1fonts\endcsname \rm
3481    %
3482    % Only insert the separating space if we have a section number.
3483    \def\secnum{#2}%
3484    \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}%
3485    %
3486    \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
3487          \hangindent = \wd0 % zero if no section number
3488          \unhbox0 #3}%
3489  }%
3490  \ifdim\parskip<10pt \nobreak\kern10pt\nobreak\kern-\parskip\fi \nobreak
3491}
3492
3493
3494\message{toc,}
3495\newwrite\tocfile
3496
3497% Write an entry to the toc file, opening it if necessary.
3498% Called from @chapter, etc.  We supply {\folio} at the end of the
3499% argument, which will end up as the last argument to the \...entry macro.
3500%
3501% We open the .toc file here instead of at @setfilename or any other
3502% given time so that @contents can be put in the document anywhere.
3503%
3504\newif\iftocfileopened
3505\def\writetocentry#1{%
3506  \iftocfileopened\else
3507    \immediate\openout\tocfile = \jobname.toc
3508    \global\tocfileopenedtrue
3509  \fi
3510  \iflinks \write\tocfile{#1{\folio}}\fi
3511}
3512
3513\newskip\contentsrightmargin \contentsrightmargin=1in
3514\newcount\savepageno
3515\newcount\lastnegativepageno \lastnegativepageno = -1
3516
3517% Finish up the main text and prepare to read what we've written
3518% to \tocfile.
3519%
3520\def\startcontents#1{%
3521   % If @setchapternewpage on, and @headings double, the contents should
3522   % start on an odd page, unlike chapters.  Thus, we maintain
3523   % \contentsalignmacro in parallel with \pagealignmacro.
3524   % From: Torbjorn Granlund <tege@matematik.su.se>
3525   \contentsalignmacro
3526   \immediate\closeout\tocfile
3527   %
3528   % Don't need to put `Contents' or `Short Contents' in the headline.
3529   % It is abundantly clear what they are.
3530   \unnumbchapmacro{#1}\def\thischapter{}%
3531   \savepageno = \pageno
3532   \begingroup                  % Set up to handle contents files properly.
3533      \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
3534      % We can't do this, because then an actual ^ in a section
3535      % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
3536      %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
3537      \raggedbottom             % Worry more about breakpoints than the bottom.
3538      \advance\hsize by -\contentsrightmargin % Don't use the full line length.
3539      %
3540      % Roman numerals for page numbers.
3541      \ifnum \pageno>0 \pageno = \lastnegativepageno \fi
3542}
3543
3544
3545% Normal (long) toc.
3546\def\contents{%
3547   \startcontents{\putwordTOC}%
3548     \openin 1 \jobname.toc
3549     \ifeof 1 \else
3550       \closein 1
3551       \input \jobname.toc
3552     \fi
3553     \vfill \eject
3554     \contentsalignmacro % in case @setchapternewpage odd is in effect
3555   \endgroup
3556   \lastnegativepageno = \pageno
3557   \pageno = \savepageno
3558}
3559
3560% And just the chapters.
3561\def\summarycontents{%
3562   \startcontents{\putwordShortTOC}%
3563      %
3564      \let\chapentry = \shortchapentry
3565      \let\unnumbchapentry = \shortunnumberedentry
3566      % We want a true roman here for the page numbers.
3567      \secfonts
3568      \let\rm=\shortcontrm \let\bf=\shortcontbf \let\sl=\shortcontsl
3569      \rm
3570      \hyphenpenalty = 10000
3571      \advance\baselineskip by 1pt % Open it up a little.
3572      \def\secentry ##1##2##3##4{}
3573      \def\unnumbsecentry ##1##2{}
3574      \def\subsecentry ##1##2##3##4##5{}
3575      \def\unnumbsubsecentry ##1##2{}
3576      \def\subsubsecentry ##1##2##3##4##5##6{}
3577      \def\unnumbsubsubsecentry ##1##2{}
3578      \openin 1 \jobname.toc
3579      \ifeof 1 \else
3580        \closein 1
3581        \input \jobname.toc
3582      \fi
3583     \vfill \eject
3584     \contentsalignmacro % in case @setchapternewpage odd is in effect
3585   \endgroup
3586   \lastnegativepageno = \pageno
3587   \pageno = \savepageno
3588}
3589\let\shortcontents = \summarycontents
3590
3591% These macros generate individual entries in the table of contents.
3592% The first argument is the chapter or section name.
3593% The last argument is the page number.
3594% The arguments in between are the chapter number, section number, ...
3595
3596% Chapter-level things, for both the long and short contents.
3597\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}}
3598
3599% See comments in \dochapentry re vbox and related settings
3600\def\shortchapentry#1#2#3{%
3601  \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno{#3}}%
3602}
3603
3604% Typeset the label for a chapter or appendix for the short contents.
3605% The arg is, e.g. `Appendix A' for an appendix, or `3' for a chapter.
3606% We could simplify the code here by writing out an \appendixentry
3607% command in the toc file for appendices, instead of using \chapentry
3608% for both, but it doesn't seem worth it.
3609\setbox0 = \hbox{\shortcontrm \putwordAppendix }
3610\newdimen\shortappendixwidth \shortappendixwidth = \wd0
3611
3612\def\shortchaplabel#1{%
3613  % We typeset #1 in a box of constant width, regardless of the text of
3614  % #1, so the chapter titles will come out aligned.
3615  \setbox0 = \hbox{#1}%
3616  \dimen0 = \ifdim\wd0 > \shortappendixwidth \shortappendixwidth \else 0pt \fi
3617  %
3618  % This space should be plenty, since a single number is .5em, and the
3619  % widest letter (M) is 1em, at least in the Computer Modern fonts.
3620  % (This space doesn't include the extra space that gets added after
3621  % the label; that gets put in by \shortchapentry above.)
3622  \advance\dimen0 by 1.1em
3623  \hbox to \dimen0{#1\hfil}%
3624}
3625
3626\def\unnumbchapentry#1#2{\dochapentry{#1}{#2}}
3627\def\shortunnumberedentry#1#2{\tocentry{#1}{\doshortpageno{#2}}}
3628
3629% Sections.
3630\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}}
3631\def\unnumbsecentry#1#2{\dosecentry{#1}{#2}}
3632
3633% Subsections.
3634\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}}
3635\def\unnumbsubsecentry#1#2{\dosubsecentry{#1}{#2}}
3636
3637% And subsubsections.
3638\def\subsubsecentry#1#2#3#4#5#6{%
3639  \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}}
3640\def\unnumbsubsubsecentry#1#2{\dosubsubsecentry{#1}{#2}}
3641
3642% This parameter controls the indentation of the various levels.
3643\newdimen\tocindent \tocindent = 3pc
3644
3645% Now for the actual typesetting. In all these, #1 is the text and #2 is the
3646% page number.
3647%
3648% If the toc has to be broken over pages, we want it to be at chapters
3649% if at all possible; hence the \penalty.
3650\def\dochapentry#1#2{%
3651   \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
3652   \begingroup
3653     \chapentryfonts
3654     \tocentry{#1}{\dopageno{#2}}%
3655   \endgroup
3656   \nobreak\vskip .25\baselineskip plus.1\baselineskip
3657}
3658
3659\def\dosecentry#1#2{\begingroup
3660  \secentryfonts \leftskip=\tocindent
3661  \tocentry{#1}{\dopageno{#2}}%
3662\endgroup}
3663
3664\def\dosubsecentry#1#2{\begingroup
3665  \subsecentryfonts \leftskip=2\tocindent
3666  \tocentry{#1}{\dopageno{#2}}%
3667\endgroup}
3668
3669\def\dosubsubsecentry#1#2{\begingroup
3670  \subsubsecentryfonts \leftskip=3\tocindent
3671  \tocentry{#1}{\dopageno{#2}}%
3672\endgroup}
3673
3674% Final typesetting of a toc entry; we use the same \entry macro as for
3675% the index entries, but we want to suppress hyphenation here.  (We
3676% can't do that in the \entry macro, since index entries might consist
3677% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.)
3678\def\tocentry#1#2{\begingroup
3679  \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks
3680  % Do not use \turnoffactive in these arguments.  Since the toc is
3681  % typeset in cmr, so characters such as _ would come out wrong; we
3682  % have to do the usual translation tricks.
3683  \entry{#1}{#2}%
3684\endgroup}
3685
3686% Space between chapter (or whatever) number and the title.
3687\def\labelspace{\hskip1em \relax}
3688
3689\def\dopageno#1{{\rm #1}}
3690\def\doshortpageno#1{{\rm #1}}
3691
3692\def\chapentryfonts{\secfonts \rm}
3693\def\secentryfonts{\textfonts}
3694\let\subsecentryfonts = \textfonts
3695\let\subsubsecentryfonts = \textfonts
3696
3697
3698\message{environments,}
3699
3700% Since these characters are used in examples, it should be an even number of
3701% \tt widths. Each \tt character is 1en, so two makes it 1em.
3702% Furthermore, these definitions must come after we define our fonts.
3703\newbox\dblarrowbox    \newbox\longdblarrowbox
3704\newbox\pushcharbox    \newbox\bullbox
3705\newbox\equivbox       \newbox\errorbox
3706
3707%{\tentt
3708%\global\setbox\dblarrowbox = \hbox to 1em{\hfil$\Rightarrow$\hfil}
3709%\global\setbox\longdblarrowbox = \hbox to 1em{\hfil$\mapsto$\hfil}
3710%\global\setbox\pushcharbox = \hbox to 1em{\hfil$\dashv$\hfil}
3711%\global\setbox\equivbox = \hbox to 1em{\hfil$\ptexequiv$\hfil}
3712% Adapted from the manmac format (p.420 of TeXbook)
3713%\global\setbox\bullbox = \hbox to 1em{\kern.15em\vrule height .75ex width .85ex
3714%                                      depth .1ex\hfil}
3715%}
3716
3717% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
3718\def\point{$\star$}
3719\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
3720\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}}
3721\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
3722\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}}
3723
3724% Adapted from the TeXbook's \boxit.
3725{\tentt \global\dimen0 = 3em}% Width of the box.
3726\dimen2 = .55pt % Thickness of rules
3727% The text. (`r' is open on the right, `e' somewhat less so on the left.)
3728\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
3729
3730\global\setbox\errorbox=\hbox to \dimen0{\hfil
3731   \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
3732   \advance\hsize by -2\dimen2 % Rules.
3733   \vbox{
3734      \hrule height\dimen2
3735      \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
3736         \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
3737         \kern3pt\vrule width\dimen2}% Space to right.
3738      \hrule height\dimen2}
3739    \hfil}
3740
3741% The @error{} command.
3742\def\error{\leavevmode\lower.7ex\copy\errorbox}
3743
3744% @tex ... @end tex    escapes into raw Tex temporarily.
3745% One exception: @ is still an escape character, so that @end tex works.
3746% But \@ or @@ will get a plain tex @ character.
3747
3748\def\tex{\begingroup
3749  \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
3750  \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
3751  \catcode `\^=7 \catcode `\_=8 \catcode `\~=13 \let~=\tie
3752  \catcode `\%=14
3753  \catcode 43=12 % plus
3754  \catcode`\"=12
3755  \catcode`\==12
3756  \catcode`\|=12
3757  \catcode`\<=12
3758  \catcode`\>=12
3759  \escapechar=`\\
3760  %
3761  \let\b=\ptexb
3762  \let\bullet=\ptexbullet
3763  \let\c=\ptexc
3764  \let\,=\ptexcomma
3765  \let\.=\ptexdot
3766  \let\dots=\ptexdots
3767  \let\equiv=\ptexequiv
3768  \let\!=\ptexexclam
3769  \let\i=\ptexi
3770  \let\{=\ptexlbrace
3771  \let\+=\tabalign
3772  \let\}=\ptexrbrace
3773  \let\*=\ptexstar
3774  \let\t=\ptext
3775  %
3776  \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
3777  \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
3778  \def\@{@}%
3779\let\Etex=\endgroup}
3780
3781% Define @lisp ... @endlisp.
3782% @lisp does a \begingroup so it can rebind things,
3783% including the definition of @endlisp (which normally is erroneous).
3784
3785% Amount to narrow the margins by for @lisp.
3786\newskip\lispnarrowing \lispnarrowing=0.4in
3787
3788% This is the definition that ^^M gets inside @lisp, @example, and other
3789% such environments.  \null is better than a space, since it doesn't
3790% have any width.
3791\def\lisppar{\null\endgraf}
3792
3793% Make each space character in the input produce a normal interword
3794% space in the output.  Don't allow a line break at this space, as this
3795% is used only in environments like @example, where each line of input
3796% should produce a line of output anyway.
3797%
3798{\obeyspaces %
3799\gdef\sepspaces{\obeyspaces\let =\tie}}
3800
3801% Define \obeyedspace to be our active space, whatever it is.  This is
3802% for use in \parsearg.
3803{\sepspaces%
3804\global\let\obeyedspace= }
3805
3806% This space is always present above and below environments.
3807\newskip\envskipamount \envskipamount = 0pt
3808
3809% Make spacing and below environment symmetrical.  We use \parskip here
3810% to help in doing that, since in @example-like environments \parskip
3811% is reset to zero; thus the \afterenvbreak inserts no space -- but the
3812% start of the next paragraph will insert \parskip
3813%
3814\def\aboveenvbreak{{\advance\envskipamount by \parskip
3815\endgraf \ifdim\lastskip<\envskipamount
3816\removelastskip \penalty-50 \vskip\envskipamount \fi}}
3817
3818\let\afterenvbreak = \aboveenvbreak
3819
3820% \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins.
3821\let\nonarrowing=\relax
3822
3823% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
3824% environment contents.
3825\font\circle=lcircle10
3826\newdimen\circthick
3827\newdimen\cartouter\newdimen\cartinner
3828\newskip\normbskip\newskip\normpskip\newskip\normlskip
3829\circthick=\fontdimen8\circle
3830%
3831\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
3832\def\ctr{{\hskip 6pt\circle\char'010}}
3833\def\cbl{{\circle\char'012\hskip -6pt}}
3834\def\cbr{{\hskip 6pt\circle\char'011}}
3835\def\carttop{\hbox to \cartouter{\hskip\lskip
3836        \ctl\leaders\hrule height\circthick\hfil\ctr
3837        \hskip\rskip}}
3838\def\cartbot{\hbox to \cartouter{\hskip\lskip
3839        \cbl\leaders\hrule height\circthick\hfil\cbr
3840        \hskip\rskip}}
3841%
3842\newskip\lskip\newskip\rskip
3843
3844\long\def\cartouche{%
3845\begingroup
3846        \lskip=\leftskip \rskip=\rightskip
3847        \leftskip=0pt\rightskip=0pt %we want these *outside*.
3848        \cartinner=\hsize \advance\cartinner by-\lskip
3849                          \advance\cartinner by-\rskip
3850        \cartouter=\hsize
3851        \advance\cartouter by 18.4pt % allow for 3pt kerns on either
3852%                                    side, and for 6pt waste from
3853%                                    each corner char, and rule thickness
3854        \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
3855        % Flag to tell @lisp, etc., not to narrow margin.
3856        \let\nonarrowing=\comment
3857        \vbox\bgroup
3858                \baselineskip=0pt\parskip=0pt\lineskip=0pt
3859                \carttop
3860                \hbox\bgroup
3861                        \hskip\lskip
3862                        \vrule\kern3pt
3863                        \vbox\bgroup
3864                                \hsize=\cartinner
3865                                \kern3pt
3866                                \begingroup
3867                                        \baselineskip=\normbskip
3868                                        \lineskip=\normlskip
3869                                        \parskip=\normpskip
3870                                        \vskip -\parskip
3871\def\Ecartouche{%
3872                                \endgroup
3873                                \kern3pt
3874                        \egroup
3875                        \kern3pt\vrule
3876                        \hskip\rskip
3877                \egroup
3878                \cartbot
3879        \egroup
3880\endgroup
3881}}
3882
3883
3884% This macro is called at the beginning of all the @example variants,
3885% inside a group.
3886\def\nonfillstart{%
3887  \aboveenvbreak
3888  \inENV % This group ends at the end of the body
3889  \hfuzz = 12pt % Don't be fussy
3890  \sepspaces % Make spaces be word-separators rather than space tokens.
3891  \singlespace
3892  \let\par = \lisppar % don't ignore blank lines
3893  \obeylines % each line of input is a line of output
3894  \parskip = 0pt
3895  \parindent = 0pt
3896  \emergencystretch = 0pt % don't try to avoid overfull boxes
3897  % @cartouche defines \nonarrowing to inhibit narrowing
3898  % at next level down.
3899  \ifx\nonarrowing\relax
3900    \advance \leftskip by \lispnarrowing
3901    \exdentamount=\lispnarrowing
3902    \let\exdent=\nofillexdent
3903    \let\nonarrowing=\relax
3904  \fi
3905}
3906
3907% Define the \E... control sequence only if we are inside the particular
3908% environment, so the error checking in \end will work.
3909%
3910% To end an @example-like environment, we first end the paragraph (via
3911% \afterenvbreak's vertical glue), and then the group.  That way we keep
3912% the zero \parskip that the environments set -- \parskip glue will be
3913% inserted at the beginning of the next paragraph in the document, after
3914% the environment.
3915%
3916\def\nonfillfinish{\afterenvbreak\endgroup}
3917
3918% @lisp: indented, narrowed, typewriter font.
3919\def\lisp{\begingroup
3920  \nonfillstart
3921  \let\Elisp = \nonfillfinish
3922  \tt
3923  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
3924  \gobble       % eat return
3925}
3926
3927% @example: Same as @lisp.
3928\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
3929
3930% @small... is usually equivalent to the non-small (@smallbook
3931% redefines).  We must call \example (or whatever) last in the
3932% definition, since it reads the return following the @example (or
3933% whatever) command.
3934%
3935% This actually allows (for example) @end display inside an
3936% @smalldisplay.  Too bad, but makeinfo will catch the error anyway.
3937%
3938\def\smalldisplay{\begingroup\def\Esmalldisplay{\nonfillfinish\endgroup}\display}
3939\def\smallexample{\begingroup\def\Esmallexample{\nonfillfinish\endgroup}\lisp}
3940\def\smallformat{\begingroup\def\Esmallformat{\nonfillfinish\endgroup}\format}
3941\def\smalllisp{\begingroup\def\Esmalllisp{\nonfillfinish\endgroup}\lisp}
3942
3943% Real @smallexample and @smalllisp (when @smallbook): use smaller fonts.
3944% Originally contributed by Pavel@xerox.
3945\def\smalllispx{\begingroup
3946  \def\Esmalllisp{\nonfillfinish\endgroup}%
3947  \def\Esmallexample{\nonfillfinish\endgroup}%
3948  \indexfonts
3949  \lisp
3950}
3951
3952% @display: same as @lisp except keep current font.
3953%
3954\def\display{\begingroup
3955  \nonfillstart
3956  \let\Edisplay = \nonfillfinish
3957  \gobble
3958}
3959
3960% @smalldisplay (when @smallbook): @display plus smaller fonts.
3961%
3962\def\smalldisplayx{\begingroup
3963  \def\Esmalldisplay{\nonfillfinish\endgroup}%
3964  \indexfonts \rm
3965  \display
3966}
3967
3968% @format: same as @display except don't narrow margins.
3969%
3970\def\format{\begingroup
3971  \let\nonarrowing = t
3972  \nonfillstart
3973  \let\Eformat = \nonfillfinish
3974  \gobble
3975}
3976
3977% @smallformat (when @smallbook): @format plus smaller fonts.
3978%
3979\def\smallformatx{\begingroup
3980  \def\Esmallformat{\nonfillfinish\endgroup}%
3981  \indexfonts \rm
3982  \format
3983}
3984
3985% @flushleft (same as @format).
3986%
3987\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
3988
3989% @flushright.
3990%
3991\def\flushright{\begingroup
3992  \let\nonarrowing = t
3993  \nonfillstart
3994  \let\Eflushright = \nonfillfinish
3995  \advance\leftskip by 0pt plus 1fill
3996  \gobble
3997}
3998
3999% @quotation does normal linebreaking (hence we can't use \nonfillstart)
4000% and narrows the margins.
4001%
4002\def\quotation{%
4003  \begingroup\inENV %This group ends at the end of the @quotation body
4004  {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
4005  \singlespace
4006  \parindent=0pt
4007  % We have retained a nonzero parskip for the environment, since we're
4008  % doing normal filling. So to avoid extra space below the environment...
4009  \def\Equotation{\parskip = 0pt \nonfillfinish}%
4010  %
4011  % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
4012  \ifx\nonarrowing\relax
4013    \advance\leftskip by \lispnarrowing
4014    \advance\rightskip by \lispnarrowing
4015    \exdentamount = \lispnarrowing
4016    \let\nonarrowing = \relax
4017  \fi
4018}
4019
4020
4021\message{defuns,}
4022% Define formatter for defuns
4023% First, allow user to change definition object font (\df) internally
4024\def\setdeffont #1 {\csname DEF#1\endcsname}
4025
4026\newskip\defbodyindent \defbodyindent=.4in
4027\newskip\defargsindent \defargsindent=50pt
4028\newskip\deftypemargin \deftypemargin=12pt
4029\newskip\deflastargmargin \deflastargmargin=18pt
4030
4031\newcount\parencount
4032% define \functionparens, which makes ( and ) and & do special things.
4033% \functionparens affects the group it is contained in.
4034\def\activeparens{%
4035\catcode`\(=\active \catcode`\)=\active \catcode`\&=\active
4036\catcode`\[=\active \catcode`\]=\active}
4037
4038% Make control sequences which act like normal parenthesis chars.
4039\let\lparen = ( \let\rparen = )
4040
4041{\activeparens % Now, smart parens don't turn on until &foo (see \amprm)
4042
4043% Be sure that we always have a definition for `(', etc.  For example,
4044% if the fn name has parens in it, \boldbrax will not be in effect yet,
4045% so TeX would otherwise complain about undefined control sequence.
4046\global\let(=\lparen \global\let)=\rparen
4047\global\let[=\lbrack \global\let]=\rbrack
4048
4049\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 }
4050\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
4051% This is used to turn on special parens
4052% but make & act ordinary (given that it's active).
4053\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr}
4054
4055% Definitions of (, ) and & used in args for functions.
4056% This is the definition of ( outside of all parentheses.
4057\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested
4058  \global\advance\parencount by 1
4059}
4060%
4061% This is the definition of ( when already inside a level of parens.
4062\gdef\opnested{\char`\(\global\advance\parencount by 1 }
4063%
4064\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0.
4065  % also in that case restore the outer-level definition of (.
4066  \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi
4067  \global\advance \parencount by -1 }
4068% If we encounter &foo, then turn on ()-hacking afterwards
4069\gdef\amprm#1 {{\rm\&#1}\let(=\oprm \let)=\clrm\ }
4070%
4071\gdef\normalparens{\boldbrax\let&=\ampnr}
4072} % End of definition inside \activeparens
4073%% These parens (in \boldbrax) actually are a little bolder than the
4074%% contained text.  This is especially needed for [ and ]
4075\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 }
4076\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 }
4077\def\ampnr{\&}
4078\def\lbrb{{\bf\char`\[}}
4079\def\rbrb{{\bf\char`\]}}
4080
4081% First, defname, which formats the header line itself.
4082% #1 should be the function name.
4083% #2 should be the type of definition, such as "Function".
4084
4085\def\defname #1#2{%
4086% Get the values of \leftskip and \rightskip as they were
4087% outside the @def...
4088\dimen2=\leftskip
4089\advance\dimen2 by -\defbodyindent
4090\noindent
4091\setbox0=\hbox{\hskip \deflastargmargin{\rm #2}\hskip \deftypemargin}%
4092\dimen0=\hsize \advance \dimen0 by -\wd0 % compute size for first line
4093\dimen1=\hsize \advance \dimen1 by -\defargsindent %size for continuations
4094\parshape 2 0in \dimen0 \defargsindent \dimen1
4095% Now output arg 2 ("Function" or some such)
4096% ending at \deftypemargin from the right margin,
4097% but stuck inside a box of width 0 so it does not interfere with linebreaking
4098{% Adjust \hsize to exclude the ambient margins,
4099% so that \rightline will obey them.
4100\advance \hsize by -\dimen2
4101\rlap{\rightline{{\rm #2}\hskip -1.25pc }}}%
4102% Make all lines underfull and no complaints:
4103\tolerance=10000 \hbadness=10000
4104\advance\leftskip by -\defbodyindent
4105\exdentamount=\defbodyindent
4106{\df #1}\enskip        % Generate function name
4107}
4108
4109% Actually process the body of a definition
4110% #1 should be the terminating control sequence, such as \Edefun.
4111% #2 should be the "another name" control sequence, such as \defunx.
4112% #3 should be the control sequence that actually processes the header,
4113%    such as \defunheader.
4114
4115\def\defparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody
4116\medbreak %
4117% Define the end token that this defining construct specifies
4118% so that it will exit this group.
4119\def#1{\endgraf\endgroup\medbreak}%
4120\def#2{\begingroup\obeylines\activeparens\spacesplit#3}%
4121\parindent=0in
4122\advance\leftskip by \defbodyindent
4123\exdentamount=\defbodyindent
4124\begingroup %
4125\catcode 61=\active % 61 is `='
4126\obeylines\activeparens\spacesplit#3}
4127
4128% #1 is the \E... control sequence to end the definition (which we define).
4129% #2 is the \...x control sequence for consecutive fns (which we define).
4130% #3 is the control sequence to call to resume processing.
4131% #4, delimited by the space, is the class name.
4132%
4133\def\defmethparsebody#1#2#3#4 {\begingroup\inENV %
4134\medbreak %
4135% Define the end token that this defining construct specifies
4136% so that it will exit this group.
4137\def#1{\endgraf\endgroup\medbreak}%
4138\def#2##1 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}}}%
4139\parindent=0in
4140\advance\leftskip by \defbodyindent
4141\exdentamount=\defbodyindent
4142\begingroup\obeylines\activeparens\spacesplit{#3{#4}}}
4143
4144% @deftypemethod has an extra argument that nothing else does.  Sigh.
4145% #1 is the \E... control sequence to end the definition (which we define).
4146% #2 is the \...x control sequence for consecutive fns (which we define).
4147% #3 is the control sequence to call to resume processing.
4148% #4, delimited by the space, is the class name.
4149% #5 is the method's return type.
4150%
4151\def\deftypemethparsebody#1#2#3#4 #5 {\begingroup\inENV %
4152\medbreak %
4153% Define the end token that this defining construct specifies
4154% so that it will exit this group.
4155\def#1{\endgraf\endgroup\medbreak}%
4156\def#2##1 ##2 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}{##2}}}%
4157\parindent=0in
4158\advance\leftskip by \defbodyindent
4159\exdentamount=\defbodyindent
4160\begingroup\obeylines\activeparens\spacesplit{#3{#4}{#5}}}
4161
4162\def\defopparsebody #1#2#3#4#5 {\begingroup\inENV %
4163\medbreak %
4164% Define the end token that this defining construct specifies
4165% so that it will exit this group.
4166\def#1{\endgraf\endgroup\medbreak}%
4167\def#2##1 ##2 {\def#4{##1}%
4168\begingroup\obeylines\activeparens\spacesplit{#3{##2}}}%
4169\parindent=0in
4170\advance\leftskip by \defbodyindent
4171\exdentamount=\defbodyindent
4172\begingroup\obeylines\activeparens\spacesplit{#3{#5}}}
4173
4174% These parsing functions are similar to the preceding ones
4175% except that they do not make parens into active characters.
4176% These are used for "variables" since they have no arguments.
4177
4178\def\defvarparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody
4179\medbreak %
4180% Define the end token that this defining construct specifies
4181% so that it will exit this group.
4182\def#1{\endgraf\endgroup\medbreak}%
4183\def#2{\begingroup\obeylines\spacesplit#3}%
4184\parindent=0in
4185\advance\leftskip by \defbodyindent
4186\exdentamount=\defbodyindent
4187\begingroup %
4188\catcode 61=\active %
4189\obeylines\spacesplit#3}
4190
4191% This is used for \def{tp,vr}parsebody.  It could probably be used for
4192% some of the others, too, with some judicious conditionals.
4193%
4194\def\parsebodycommon#1#2#3{%
4195  \begingroup\inENV %
4196  \medbreak %
4197  % Define the end token that this defining construct specifies
4198  % so that it will exit this group.
4199  \def#1{\endgraf\endgroup\medbreak}%
4200  \def#2##1 {\begingroup\obeylines\spacesplit{#3{##1}}}%
4201  \parindent=0in
4202  \advance\leftskip by \defbodyindent
4203  \exdentamount=\defbodyindent
4204  \begingroup\obeylines
4205}
4206
4207\def\defvrparsebody#1#2#3#4 {%
4208  \parsebodycommon{#1}{#2}{#3}%
4209  \spacesplit{#3{#4}}%
4210}
4211
4212% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the
4213% type is just `struct', because we lose the braces in `{struct
4214% termios}' when \spacesplit reads its undelimited argument.  Sigh.
4215% \let\deftpparsebody=\defvrparsebody
4216%
4217% So, to get around this, we put \empty in with the type name.  That
4218% way, TeX won't find exactly `{...}' as an undelimited argument, and
4219% won't strip off the braces.
4220%
4221\def\deftpparsebody #1#2#3#4 {%
4222  \parsebodycommon{#1}{#2}{#3}%
4223  \spacesplit{\parsetpheaderline{#3{#4}}}\empty
4224}
4225
4226% Fine, but then we have to eventually remove the \empty *and* the
4227% braces (if any).  That's what this does.
4228%
4229\def\removeemptybraces\empty#1\relax{#1}
4230
4231% After \spacesplit has done its work, this is called -- #1 is the final
4232% thing to call, #2 the type name (which starts with \empty), and #3
4233% (which might be empty) the arguments.
4234%
4235\def\parsetpheaderline#1#2#3{%
4236  #1{\removeemptybraces#2\relax}{#3}%
4237}%
4238
4239\def\defopvarparsebody #1#2#3#4#5 {\begingroup\inENV %
4240\medbreak %
4241% Define the end token that this defining construct specifies
4242% so that it will exit this group.
4243\def#1{\endgraf\endgroup\medbreak}%
4244\def#2##1 ##2 {\def#4{##1}%
4245\begingroup\obeylines\spacesplit{#3{##2}}}%
4246\parindent=0in
4247\advance\leftskip by \defbodyindent
4248\exdentamount=\defbodyindent
4249\begingroup\obeylines\spacesplit{#3{#5}}}
4250
4251% Split up #2 at the first space token.
4252% call #1 with two arguments:
4253%  the first is all of #2 before the space token,
4254%  the second is all of #2 after that space token.
4255% If #2 contains no space token, all of it is passed as the first arg
4256% and the second is passed as empty.
4257
4258{\obeylines
4259\gdef\spacesplit#1#2^^M{\endgroup\spacesplitfoo{#1}#2 \relax\spacesplitfoo}%
4260\long\gdef\spacesplitfoo#1#2 #3#4\spacesplitfoo{%
4261\ifx\relax #3%
4262#1{#2}{}\else #1{#2}{#3#4}\fi}}
4263
4264% So much for the things common to all kinds of definitions.
4265
4266% Define @defun.
4267
4268% First, define the processing that is wanted for arguments of \defun
4269% Use this to expand the args and terminate the paragraph they make up
4270
4271\def\defunargs #1{\functionparens \sl
4272% Expand, preventing hyphenation at `-' chars.
4273% Note that groups don't affect changes in \hyphenchar.
4274\hyphenchar\tensl=0
4275#1%
4276\hyphenchar\tensl=45
4277\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi%
4278\interlinepenalty=10000
4279\advance\rightskip by 0pt plus 1fil
4280\endgraf\nobreak\vskip -\parskip\nobreak
4281}
4282
4283\def\deftypefunargs #1{%
4284% Expand, preventing hyphenation at `-' chars.
4285% Note that groups don't affect changes in \hyphenchar.
4286% Use \boldbraxnoamp, not \functionparens, so that & is not special.
4287\boldbraxnoamp
4288\tclose{#1}% avoid \code because of side effects on active chars
4289\interlinepenalty=10000
4290\advance\rightskip by 0pt plus 1fil
4291\endgraf\nobreak\vskip -\parskip\nobreak
4292}
4293
4294% Do complete processing of one @defun or @defunx line already parsed.
4295
4296% @deffn Command forward-char nchars
4297
4298\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader}
4299
4300\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}%
4301\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup %
4302\catcode 61=\other % Turn off change made in \defparsebody
4303}
4304
4305% @defun == @deffn Function
4306
4307\def\defun{\defparsebody\Edefun\defunx\defunheader}
4308
4309\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
4310\begingroup\defname {#1}{\putwordDeffunc}%
4311\defunargs {#2}\endgroup %
4312\catcode 61=\other % Turn off change made in \defparsebody
4313}
4314
4315% @deftypefun int foobar (int @var{foo}, float @var{bar})
4316
4317\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader}
4318
4319% #1 is the data type.  #2 is the name and args.
4320\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax}
4321% #1 is the data type, #2 the name, #3 the args.
4322\def\deftypefunheaderx #1#2 #3\relax{%
4323\doind {fn}{\code{#2}}% Make entry in function index
4324\begingroup\defname {\defheaderxcond#1\relax$$$#2}{\putwordDeftypefun}%
4325\deftypefunargs {#3}\endgroup %
4326\catcode 61=\other % Turn off change made in \defparsebody
4327}
4328
4329% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar})
4330
4331\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader}
4332
4333% \defheaderxcond#1\relax$$$
4334% puts #1 in @code, followed by a space, but does nothing if #1 is null.
4335\def\defheaderxcond#1#2$$${\ifx#1\relax\else\code{#1#2} \fi}
4336
4337% #1 is the classification.  #2 is the data type.  #3 is the name and args.
4338\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax}
4339% #1 is the classification, #2 the data type, #3 the name, #4 the args.
4340\def\deftypefnheaderx #1#2#3 #4\relax{%
4341\doind {fn}{\code{#3}}% Make entry in function index
4342\begingroup
4343\normalparens % notably, turn off `&' magic, which prevents
4344%               at least some C++ text from working
4345\defname {\defheaderxcond#2\relax$$$#3}{#1}%
4346\deftypefunargs {#4}\endgroup %
4347\catcode 61=\other % Turn off change made in \defparsebody
4348}
4349
4350% @defmac == @deffn Macro
4351
4352\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader}
4353
4354\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
4355\begingroup\defname {#1}{\putwordDefmac}%
4356\defunargs {#2}\endgroup %
4357\catcode 61=\other % Turn off change made in \defparsebody
4358}
4359
4360% @defspec == @deffn Special Form
4361
4362\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader}
4363
4364\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
4365\begingroup\defname {#1}{\putwordDefspec}%
4366\defunargs {#2}\endgroup %
4367\catcode 61=\other % Turn off change made in \defparsebody
4368}
4369
4370% This definition is run if you use @defunx
4371% anywhere other than immediately after a @defun or @defunx.
4372
4373\def\deffnx #1 {\errmessage{@deffnx in invalid context}}
4374\def\defunx #1 {\errmessage{@defunx in invalid context}}
4375\def\defmacx #1 {\errmessage{@defmacx in invalid context}}
4376\def\defspecx #1 {\errmessage{@defspecx in invalid context}}
4377\def\deftypefnx #1 {\errmessage{@deftypefnx in invalid context}}
4378\def\deftypemethodx #1 {\errmessage{@deftypemethodx in invalid context}}
4379\def\deftypefunx #1 {\errmessage{@deftypefunx in invalid context}}
4380
4381% @defmethod, and so on
4382
4383% @defop CATEGORY CLASS OPERATION ARG...
4384
4385\def\defop #1 {\def\defoptype{#1}%
4386\defopparsebody\Edefop\defopx\defopheader\defoptype}
4387
4388\def\defopheader #1#2#3{%
4389\dosubind {fn}{\code{#2}}{\putwordon\ #1}% Make entry in function index
4390\begingroup\defname {#2}{\defoptype{}\putwordon\ #1}%
4391\defunargs {#3}\endgroup %
4392}
4393
4394% @deftypemethod CLASS RETURN-TYPE METHOD ARG...
4395%
4396\def\deftypemethod{%
4397  \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader}
4398%
4399% #1 is the class name, #2 the data type, #3 the method name, #4 the args.
4400\def\deftypemethodheader#1#2#3#4{%
4401  \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
4402  \begingroup
4403    \defname{\defheaderxcond#2\relax$$$#3}{\putwordMethodon\ \code{#1}}%
4404    \deftypefunargs{#4}%
4405  \endgroup
4406}
4407
4408% @defmethod == @defop Method
4409%
4410\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader}
4411%
4412% #1 is the class name, #2 the method name, #3 the args.
4413\def\defmethodheader#1#2#3{%
4414  \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index
4415  \begingroup
4416    \defname{#2}{\putwordMethodon\ \code{#1}}%
4417    \defunargs{#3}%
4418  \endgroup
4419}
4420
4421% @defcv {Class Option} foo-class foo-flag
4422
4423\def\defcv #1 {\def\defcvtype{#1}%
4424\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype}
4425
4426\def\defcvarheader #1#2#3{%
4427\dosubind {vr}{\code{#2}}{\putwordof\ #1}% Make entry in var index
4428\begingroup\defname {#2}{\defcvtype\ \putwordof\ #1}%
4429\defvarargs {#3}\endgroup %
4430}
4431
4432% @defivar == @defcv {Instance Variable}
4433
4434\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader}
4435
4436\def\defivarheader #1#2#3{%
4437\dosubind {vr}{\code{#2}}{\putwordof\ #1}% Make entry in var index
4438\begingroup\defname {#2}{\putwordDefivar\ \putwordof\ #1}%
4439\defvarargs {#3}\endgroup %
4440}
4441
4442% These definitions are run if you use @defmethodx, etc.,
4443% anywhere other than immediately after a @defmethod, etc.
4444
4445\def\defopx #1 {\errmessage{@defopx in invalid context}}
4446\def\defmethodx #1 {\errmessage{@defmethodx in invalid context}}
4447\def\defcvx #1 {\errmessage{@defcvx in invalid context}}
4448\def\defivarx #1 {\errmessage{@defivarx in invalid context}}
4449
4450% Now @defvar
4451
4452% First, define the processing that is wanted for arguments of @defvar.
4453% This is actually simple: just print them in roman.
4454% This must expand the args and terminate the paragraph they make up
4455\def\defvarargs #1{\normalparens #1%
4456\interlinepenalty=10000
4457\endgraf\nobreak\vskip -\parskip\nobreak}
4458
4459% @defvr Counter foo-count
4460
4461\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader}
4462
4463\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}%
4464\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup}
4465
4466% @defvar == @defvr Variable
4467
4468\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader}
4469
4470\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
4471\begingroup\defname {#1}{\putwordDefvar}%
4472\defvarargs {#2}\endgroup %
4473}
4474
4475% @defopt == @defvr {User Option}
4476
4477\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader}
4478
4479\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
4480\begingroup\defname {#1}{\putwordDefopt}%
4481\defvarargs {#2}\endgroup %
4482}
4483
4484% @deftypevar int foobar
4485
4486\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader}
4487
4488% #1 is the data type.  #2 is the name, perhaps followed by text that
4489% is actually part of the data type, which should not be put into the index.
4490\def\deftypevarheader #1#2{%
4491\dovarind#2 \relax% Make entry in variables index
4492\begingroup\defname {\defheaderxcond#1\relax$$$#2}{\putwordDeftypevar}%
4493\interlinepenalty=10000
4494\endgraf\nobreak\vskip -\parskip\nobreak
4495\endgroup}
4496\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}}
4497
4498% @deftypevr {Global Flag} int enable
4499
4500\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader}
4501
4502\def\deftypevrheader #1#2#3{\dovarind#3 \relax%
4503\begingroup\defname {\defheaderxcond#2\relax$$$#3}{#1}
4504\interlinepenalty=10000
4505\endgraf\nobreak\vskip -\parskip\nobreak
4506\endgroup}
4507
4508% This definition is run if you use @defvarx
4509% anywhere other than immediately after a @defvar or @defvarx.
4510
4511\def\defvrx #1 {\errmessage{@defvrx in invalid context}}
4512\def\defvarx #1 {\errmessage{@defvarx in invalid context}}
4513\def\defoptx #1 {\errmessage{@defoptx in invalid context}}
4514\def\deftypevarx #1 {\errmessage{@deftypevarx in invalid context}}
4515\def\deftypevrx #1 {\errmessage{@deftypevrx in invalid context}}
4516
4517% Now define @deftp
4518% Args are printed in bold, a slight difference from @defvar.
4519
4520\def\deftpargs #1{\bf \defvarargs{#1}}
4521
4522% @deftp Class window height width ...
4523
4524\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader}
4525
4526\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}%
4527\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup}
4528
4529% This definition is run if you use @deftpx, etc
4530% anywhere other than immediately after a @deftp, etc.
4531
4532\def\deftpx #1 {\errmessage{@deftpx in invalid context}}
4533
4534
4535\message{macros,}
4536% @macro.
4537
4538% To do this right we need a feature of e-TeX, \scantokens,
4539% which we arrange to emulate with a temporary file in ordinary TeX.
4540\ifx\eTeXversion\undefined
4541 \newwrite\macscribble
4542 \def\scanmacro#1{%
4543   \begingroup \newlinechar`\^^M
4544   % Undo catcode changes of \startcontents and \doprintindex
4545   \catcode`\@=0 \catcode`\\=12 \escapechar=`\@
4546   % Append \endinput to make sure that TeX does not see the ending newline.
4547   \toks0={#1\endinput}%
4548   \immediate\openout\macscribble=\jobname.tmp
4549   \immediate\write\macscribble{\the\toks0}%
4550   \immediate\closeout\macscribble
4551   \let\xeatspaces\eatspaces
4552   \input \jobname.tmp
4553   \endgroup
4554}
4555\else
4556\def\scanmacro#1{%
4557\begingroup \newlinechar`\^^M
4558% Undo catcode changes of \startcontents and \doprintindex
4559\catcode`\@=0 \catcode`\\=12 \escapechar=`\@
4560\let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup}
4561\fi
4562
4563\newcount\paramno   % Count of parameters
4564\newtoks\macname    % Macro name
4565\newif\ifrecursive  % Is it recursive?
4566\def\macrolist{}    % List of all defined macros in the form
4567                    % \do\macro1\do\macro2...
4568
4569% Utility routines.
4570% Thisdoes \let #1 = #2, except with \csnames.
4571\def\cslet#1#2{%
4572\expandafter\expandafter
4573\expandafter\let
4574\expandafter\expandafter
4575\csname#1\endcsname
4576\csname#2\endcsname}
4577
4578% Trim leading and trailing spaces off a string.
4579% Concepts from aro-bend problem 15 (see CTAN).
4580{\catcode`\@=11
4581\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
4582\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
4583\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
4584\def\unbrace#1{#1}
4585\unbrace{\gdef\trim@@@ #1 } #2@{#1}
4586}
4587
4588% Trim a single trailing ^^M off a string.
4589{\catcode`\^^M=12\catcode`\Q=3%
4590\gdef\eatcr #1{\eatcra #1Q^^MQ}%
4591\gdef\eatcra#1^^MQ{\eatcrb#1Q}%
4592\gdef\eatcrb#1Q#2Q{#1}%
4593}
4594
4595% Macro bodies are absorbed as an argument in a context where
4596% all characters are catcode 10, 11 or 12, except \ which is active
4597% (as in normal texinfo). It is necessary to change the definition of \.
4598
4599% It's necessary to have hard CRs when the macro is executed. This is
4600% done by  making ^^M (\endlinechar) catcode 12 when reading the macro
4601% body, and then making it the \newlinechar in \scanmacro.
4602
4603\def\macrobodyctxt{%
4604  \catcode`\~=12
4605  \catcode`\^=12
4606  \catcode`\_=12
4607  \catcode`\|=12
4608  \catcode`\<=12
4609  \catcode`\>=12
4610  \catcode`\+=12
4611  \catcode`\{=12
4612  \catcode`\}=12
4613  \catcode`\@=12
4614  \catcode`\^^M=12
4615  \usembodybackslash}
4616
4617\def\macroargctxt{%
4618  \catcode`\~=12
4619  \catcode`\^=12
4620  \catcode`\_=12
4621  \catcode`\|=12
4622  \catcode`\<=12
4623  \catcode`\>=12
4624  \catcode`\+=12
4625  \catcode`\@=12
4626  \catcode`\\=12}
4627
4628% \mbodybackslash is the definition of \ in @macro bodies.
4629% It maps \foo\ => \csname macarg.foo\endcsname => #N
4630% where N is the macro parameter number.
4631% We define \csname macarg.\endcsname to be \realbackslash, so
4632% \\ in macro replacement text gets you a backslash.
4633
4634{\catcode`@=0 @catcode`@\=@active
4635 @gdef@usembodybackslash{@let\=@mbodybackslash}
4636 @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
4637}
4638\expandafter\def\csname macarg.\endcsname{\realbackslash}
4639
4640\def\macro{\recursivefalse\parsearg\macroxxx}
4641\def\rmacro{\recursivetrue\parsearg\macroxxx}
4642
4643\def\macroxxx#1{%
4644  \getargs{#1}%           now \macname is the macname and \argl the arglist
4645  \ifx\argl\empty       % no arguments
4646     \paramno=0%
4647  \else
4648     \expandafter\parsemargdef \argl;%
4649  \fi
4650  \if1\csname ismacro.\the\macname\endcsname
4651     \message{Warning: redefining \the\macname}%
4652  \else
4653     \expandafter\ifx\csname \the\macname\endcsname \relax
4654     \else \errmessage{The name \the\macname\space is reserved}\fi
4655     \global\cslet{macsave.\the\macname}{\the\macname}%
4656     \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
4657     % Add the macroname to \macrolist
4658     \toks0 = \expandafter{\macrolist\do}%
4659     \xdef\macrolist{\the\toks0
4660       \expandafter\noexpand\csname\the\macname\endcsname}%
4661  \fi
4662  \begingroup \macrobodyctxt
4663  \ifrecursive \expandafter\parsermacbody
4664  \else \expandafter\parsemacbody
4665  \fi}
4666
4667\def\unmacro{\parsearg\unmacroxxx}
4668\def\unmacroxxx#1{%
4669  \if1\csname ismacro.#1\endcsname
4670    \global\cslet{#1}{macsave.#1}%
4671    \global\expandafter\let \csname ismacro.#1\endcsname=0%
4672    % Remove the macro name from \macrolist
4673    \begingroup
4674      \edef\tempa{\expandafter\noexpand\csname#1\endcsname}%
4675      \def\do##1{%
4676        \def\tempb{##1}%
4677        \ifx\tempa\tempb
4678          % remove this
4679        \else
4680          \toks0 = \expandafter{\newmacrolist\do}%
4681          \edef\newmacrolist{\the\toks0\expandafter\noexpand\tempa}%
4682        \fi}%
4683      \def\newmacrolist{}%
4684      % Execute macro list to define \newmacrolist
4685      \macrolist
4686      \global\let\macrolist\newmacrolist
4687    \endgroup
4688  \else
4689    \errmessage{Macro #1 not defined}%
4690  \fi
4691}
4692
4693% This makes use of the obscure feature that if the last token of a
4694% <parameter list> is #, then the preceding argument is delimited by
4695% an opening brace, and that opening brace is not consumed.
4696\def\getargs#1{\getargsxxx#1{}}
4697\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
4698\def\getmacname #1 #2\relax{\macname={#1}}
4699\def\getmacargs#1{\def\argl{#1}}
4700
4701% Parse the optional {params} list.  Set up \paramno and \paramlist
4702% so \defmacro knows what to do.  Define \macarg.blah for each blah
4703% in the params list, to be ##N where N is the position in that list.
4704% That gets used by \mbodybackslash (above).
4705
4706% We need to get `macro parameter char #' into several definitions.
4707% The technique used is stolen from LaTeX:  let \hash be something
4708% unexpandable, insert that wherever you need a #, and then redefine
4709% it to # just before using the token list produced.
4710%
4711% The same technique is used to protect \eatspaces till just before
4712% the macro is used.
4713
4714\def\parsemargdef#1;{\paramno=0\def\paramlist{}%
4715        \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,}
4716\def\parsemargdefxxx#1,{%
4717  \if#1;\let\next=\relax
4718  \else \let\next=\parsemargdefxxx
4719    \advance\paramno by 1%
4720    \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
4721        {\xeatspaces{\hash\the\paramno}}%
4722    \edef\paramlist{\paramlist\hash\the\paramno,}%
4723  \fi\next}
4724
4725% These two commands read recursive and nonrecursive macro bodies.
4726% (They're different since rec and nonrec macros end differently.)
4727
4728\long\def\parsemacbody#1@end macro%
4729{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
4730\long\def\parsermacbody#1@end rmacro%
4731{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
4732
4733% This defines the macro itself. There are six cases: recursive and
4734% nonrecursive macros of zero, one, and many arguments.
4735% Much magic with \expandafter here.
4736% \xdef is used so that macro definitions will survive the file
4737% they're defined in; @include reads the file inside a group.
4738\def\defmacro{%
4739  \let\hash=##% convert placeholders to macro parameter chars
4740  \ifrecursive
4741    \ifcase\paramno
4742    % 0
4743      \expandafter\xdef\csname\the\macname\endcsname{%
4744        \noexpand\scanmacro{\temp}}%
4745    \or % 1
4746      \expandafter\xdef\csname\the\macname\endcsname{%
4747         \bgroup\noexpand\macroargctxt
4748         \noexpand\braceorline
4749         \expandafter\noexpand\csname\the\macname xxx\endcsname}%
4750      \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
4751         \egroup\noexpand\scanmacro{\temp}}%
4752    \else % many
4753      \expandafter\xdef\csname\the\macname\endcsname{%
4754         \bgroup\noexpand\macroargctxt
4755         \noexpand\csname\the\macname xx\endcsname}%
4756      \expandafter\xdef\csname\the\macname xx\endcsname##1{%
4757          \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
4758      \expandafter\expandafter
4759      \expandafter\xdef
4760      \expandafter\expandafter
4761        \csname\the\macname xxx\endcsname
4762          \paramlist{\egroup\noexpand\scanmacro{\temp}}%
4763    \fi
4764  \else
4765    \ifcase\paramno
4766    % 0
4767      \expandafter\xdef\csname\the\macname\endcsname{%
4768        \noexpand\norecurse{\the\macname}%
4769        \noexpand\scanmacro{\temp}\egroup}%
4770    \or % 1
4771      \expandafter\xdef\csname\the\macname\endcsname{%
4772         \bgroup\noexpand\macroargctxt
4773         \noexpand\braceorline
4774         \expandafter\noexpand\csname\the\macname xxx\endcsname}%
4775      \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
4776        \egroup
4777        \noexpand\norecurse{\the\macname}%
4778        \noexpand\scanmacro{\temp}\egroup}%
4779    \else % many
4780      \expandafter\xdef\csname\the\macname\endcsname{%
4781         \bgroup\noexpand\macroargctxt
4782         \expandafter\noexpand\csname\the\macname xx\endcsname}%
4783      \expandafter\xdef\csname\the\macname xx\endcsname##1{%
4784          \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
4785      \expandafter\expandafter
4786      \expandafter\xdef
4787      \expandafter\expandafter
4788      \csname\the\macname xxx\endcsname
4789      \paramlist{%
4790          \egroup
4791          \noexpand\norecurse{\the\macname}%
4792          \noexpand\scanmacro{\temp}\egroup}%
4793    \fi
4794  \fi}
4795
4796\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
4797
4798% \braceorline decides whether the next nonwhitespace character is a
4799% {.  If so it reads up to the closing }, if not, it reads the whole
4800% line.  Whatever was read is then fed to the next control sequence
4801% as an argument (by \parsebrace or \parsearg)
4802\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx}
4803\def\braceorlinexxx{%
4804  \ifx\nchar\bgroup\else
4805    \expandafter\parsearg
4806  \fi \next}
4807
4808% We mant to disable all macros during \shipout so that they are not
4809% expanded by \write.
4810\def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
4811  \edef\next{\macrolist}\expandafter\endgroup\next}
4812
4813
4814% @alias.
4815\def\alias#1=#2{\gdef#1{#2}}
4816
4817
4818\message{cross references,}
4819\newwrite\auxfile
4820
4821\newif\ifhavexrefs    % True if xref values are known.
4822\newif\ifwarnedxrefs  % True if we warned once that they aren't known.
4823
4824% @inforef is relatively simple.
4825\def\inforef #1{\inforefzzz #1,,,,**}
4826\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
4827  node \samp{\ignorespaces#1{}}}
4828
4829% @node's job is to define \lastnode.
4830\def\node{\ENVcheck\parsearg\nodezzz}
4831\def\nodezzz#1{\nodexxx [#1,]}
4832\def\nodexxx[#1,#2]{\gdef\lastnode{#1}}
4833\let\nwnode=\node
4834\let\lastnode=\relax
4835
4836% The sectioning commands (@chapter, etc.) call these.
4837\def\donoderef{%
4838  \ifx\lastnode\relax\else
4839    \expandafter\expandafter\expandafter\setref{\lastnode}%
4840      {Ysectionnumberandtype}%
4841    \global\let\lastnode=\relax
4842  \fi
4843}
4844\def\unnumbnoderef{%
4845  \ifx\lastnode\relax\else
4846    \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}%
4847    \global\let\lastnode=\relax
4848  \fi
4849}
4850\def\appendixnoderef{%
4851  \ifx\lastnode\relax\else
4852    \expandafter\expandafter\expandafter\setref{\lastnode}%
4853      {Yappendixletterandtype}%
4854    \global\let\lastnode=\relax
4855  \fi
4856}
4857
4858
4859% @anchor{NAME} -- define xref target at arbitrary point.
4860%
4861\def\anchor#1{\setref{#1}{Ynothing}}
4862
4863
4864% \setref{NAME}{SNT} defines a cross-reference point NAME, namely
4865% NAME-title, NAME-pg, and NAME-SNT.  Called from \foonoderef.  We have
4866% to set \indexdummies so commands such as @code in a section title
4867% aren't expanded.  It would be nicer not to expand the titles in the
4868% first place, but there's so many layers that that is hard to do.
4869%
4870\def\setref#1#2{{%
4871  \indexdummies
4872  \dosetq{#1-title}{Ytitle}%
4873  \dosetq{#1-pg}{Ypagenumber}%
4874  \dosetq{#1-snt}{#2}%
4875}}
4876
4877% @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
4878% the node name, #2 the name of the Info cross-reference, #3 the printed
4879% node name, #4 the name of the Info file, #5 the name of the printed
4880% manual.  All but the node name can be omitted.
4881%
4882\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
4883\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
4884\def\ref#1{\xrefX[#1,,,,,,,]}
4885\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
4886  \def\printedmanual{\ignorespaces #5}%
4887  \def\printednodename{\ignorespaces #3}%
4888  \setbox1=\hbox{\printedmanual}%
4889  \setbox0=\hbox{\printednodename}%
4890  \ifdim \wd0 = 0pt
4891    % No printed node name was explicitly given.
4892    \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
4893      % Use the node name inside the square brackets.
4894      \def\printednodename{\ignorespaces #1}%
4895    \else
4896      % Use the actual chapter/section title appear inside
4897      % the square brackets.  Use the real section title if we have it.
4898      \ifdim \wd1 > 0pt
4899        % It is in another manual, so we don't have it.
4900        \def\printednodename{\ignorespaces #1}%
4901      \else
4902        \ifhavexrefs
4903          % We know the real title if we have the xref values.
4904          \def\printednodename{\refx{#1-title}{}}%
4905        \else
4906          % Otherwise just copy the Info node name.
4907          \def\printednodename{\ignorespaces #1}%
4908        \fi%
4909      \fi
4910    \fi
4911  \fi
4912  %
4913  % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
4914  % insert empty discretionaries after hyphens, which means that it will
4915  % not find a line break at a hyphen in a node names.  Since some manuals
4916  % are best written with fairly long node names, containing hyphens, this
4917  % is a loss.  Therefore, we give the text of the node name again, so it
4918  % is as if TeX is seeing it for the first time.
4919  \ifdim \wd1 > 0pt
4920    \putwordsection{} ``\printednodename'' in \cite{\printedmanual}%
4921  \else
4922    % _ (for example) has to be the character _ for the purposes of the
4923    % control sequence corresponding to the node, but it has to expand
4924    % into the usual \leavevmode...\vrule stuff for purposes of
4925    % printing. So we \turnoffactive for the \refx-snt, back on for the
4926    % printing, back off for the \refx-pg.
4927    {\normalturnoffactive
4928     % Only output a following space if the -snt ref is nonempty; for
4929     % @unnumbered and @anchor, it won't be.
4930     \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
4931     \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
4932    }%
4933    % [mynode],
4934    [\printednodename],\space
4935    % page 3
4936    \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
4937  \fi
4938\endgroup}
4939
4940% \dosetq is the interface for calls from other macros
4941
4942% Use \normalturnoffactive so that punctuation chars such as underscore
4943% and backslash work in node names.  (\turnoffactive doesn't do \.)
4944\def\dosetq#1#2{%
4945  {\let\folio=0
4946   \normalturnoffactive
4947   \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}%
4948   \iflinks
4949     \next
4950   \fi
4951  }%
4952}
4953
4954% \internalsetq {foo}{page} expands into
4955% CHARACTERS 'xrdef {foo}{...expansion of \Ypage...}
4956% When the aux file is read, ' is the escape character
4957
4958\def\internalsetq #1#2{'xrdef {#1}{\csname #2\endcsname}}
4959
4960% Things to be expanded by \internalsetq
4961
4962\def\Ypagenumber{\folio}
4963
4964\def\Ytitle{\thissection}
4965
4966\def\Ynothing{}
4967
4968\def\Ysectionnumberandtype{%
4969\ifnum\secno=0 \putwordChapter\xreftie\the\chapno %
4970\else \ifnum \subsecno=0 \putwordSection\xreftie\the\chapno.\the\secno %
4971\else \ifnum \subsubsecno=0 %
4972\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno %
4973\else %
4974\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno %
4975\fi \fi \fi }
4976
4977\def\Yappendixletterandtype{%
4978\ifnum\secno=0 \putwordAppendix\xreftie'char\the\appendixno{}%
4979\else \ifnum \subsecno=0 \putwordSection\xreftie'char\the\appendixno.\the\secno %
4980\else \ifnum \subsubsecno=0 %
4981\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno %
4982\else %
4983\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno %
4984\fi \fi \fi }
4985
4986\gdef\xreftie{'tie}
4987
4988% Use TeX 3.0's \inputlineno to get the line number, for better error
4989% messages, but if we're using an old version of TeX, don't do anything.
4990%
4991\ifx\inputlineno\thisisundefined
4992  \let\linenumber = \empty % Non-3.0.
4993\else
4994  \def\linenumber{\the\inputlineno:\space}
4995\fi
4996
4997% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
4998% If its value is nonempty, SUFFIX is output afterward.
4999
5000\def\refx#1#2{%
5001  \expandafter\ifx\csname X#1\endcsname\relax
5002    % If not defined, say something at least.
5003    \angleleft un\-de\-fined\angleright
5004    \iflinks
5005      \ifhavexrefs
5006        \message{\linenumber Undefined cross reference `#1'.}%
5007      \else
5008        \ifwarnedxrefs\else
5009          \global\warnedxrefstrue
5010          \message{Cross reference values unknown; you must run TeX again.}%
5011        \fi
5012      \fi
5013    \fi
5014  \else
5015    % It's defined, so just use it.
5016    \csname X#1\endcsname
5017  \fi
5018  #2% Output the suffix in any case.
5019}
5020
5021% This is the macro invoked by entries in the aux file.
5022%
5023\def\xrdef#1{\begingroup
5024  % Reenable \ as an escape while reading the second argument.
5025  \catcode`\\ = 0
5026  \afterassignment\endgroup
5027  \expandafter\gdef\csname X#1\endcsname
5028}
5029
5030% Read the last existing aux file, if any.  No error if none exists.
5031\def\readauxfile{\begingroup
5032  \catcode`\^^@=\other
5033  \catcode`\^^A=\other
5034  \catcode`\^^B=\other
5035  \catcode`\^^C=\other
5036  \catcode`\^^D=\other
5037  \catcode`\^^E=\other
5038  \catcode`\^^F=\other
5039  \catcode`\^^G=\other
5040  \catcode`\^^H=\other
5041  \catcode`\^^K=\other
5042  \catcode`\^^L=\other
5043  \catcode`\^^N=\other
5044  \catcode`\^^P=\other
5045  \catcode`\^^Q=\other
5046  \catcode`\^^R=\other
5047  \catcode`\^^S=\other
5048  \catcode`\^^T=\other
5049  \catcode`\^^U=\other
5050  \catcode`\^^V=\other
5051  \catcode`\^^W=\other
5052  \catcode`\^^X=\other
5053  \catcode`\^^Z=\other
5054  \catcode`\^^[=\other
5055  \catcode`\^^\=\other
5056  \catcode`\^^]=\other
5057  \catcode`\^^^=\other
5058  \catcode`\^^_=\other
5059  \catcode`\@=\other
5060  \catcode`\^=\other
5061  % It was suggested to define this as 7, which would allow ^^e4 etc.
5062  % in xref tags, i.e., node names.  But since ^^e4 notation isn't
5063  % supported in the main text, it doesn't seem desirable.  Furthermore,
5064  % that is not enough: for node names that actually contain a ^
5065  % character, we would end up writing a line like this: 'xrdef {'hat
5066  % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
5067  % argument, and \hat is not an expandable control sequence.  It could
5068  % all be worked out, but why?  Either we support ^^ or we don't.
5069  %
5070  % The other change necessary for this was to define \auxhat:
5071  % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
5072  % and then to call \auxhat in \setq.
5073  %
5074  \catcode`\~=\other
5075  \catcode`\[=\other
5076  \catcode`\]=\other
5077  \catcode`\"=\other
5078  \catcode`\_=\other
5079  \catcode`\|=\other
5080  \catcode`\<=\other
5081  \catcode`\>=\other
5082  \catcode`\$=\other
5083  \catcode`\#=\other
5084  \catcode`\&=\other
5085  \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
5086  % Make the characters 128-255 be printing characters
5087  {%
5088    \count 1=128
5089    \def\loop{%
5090      \catcode\count 1=\other
5091      \advance\count 1 by 1
5092      \ifnum \count 1<256 \loop \fi
5093    }%
5094  }%
5095  % The aux file uses ' as the escape (for now).
5096  % Turn off \ as an escape so we do not lose on
5097  % entries which were dumped with control sequences in their names.
5098  % For example, 'xrdef {$\leq $-fun}{page ...} made by @defun ^^
5099  % Reference to such entries still does not work the way one would wish,
5100  % but at least they do not bomb out when the aux file is read in.
5101  \catcode`\{=1
5102  \catcode`\}=2
5103  \catcode`\%=\other
5104  \catcode`\'=0
5105  \catcode`\\=\other
5106  %
5107  \openin 1 \jobname.aux
5108  \ifeof 1 \else
5109    \closein 1
5110    \input \jobname.aux
5111    \global\havexrefstrue
5112    \global\warnedobstrue
5113  \fi
5114  % Open the new aux file.  TeX will close it automatically at exit.
5115  \openout\auxfile=\jobname.aux
5116\endgroup}
5117
5118
5119% Footnotes.
5120
5121\newcount \footnoteno
5122
5123% The trailing space in the following definition for supereject is
5124% vital for proper filling; pages come out unaligned when you do a
5125% pagealignmacro call if that space before the closing brace is
5126% removed. (Generally, numeric constants should always be followed by a
5127% space to prevent strange expansion errors.)
5128\def\supereject{\par\penalty -20000\footnoteno =0 }
5129
5130% @footnotestyle is meaningful for info output only.
5131\let\footnotestyle=\comment
5132
5133\let\ptexfootnote=\footnote
5134
5135{\catcode `\@=11
5136%
5137% Auto-number footnotes.  Otherwise like plain.
5138\gdef\footnote{%
5139  \global\advance\footnoteno by \@ne
5140  \edef\thisfootno{$^{\the\footnoteno}$}%
5141  %
5142  % In case the footnote comes at the end of a sentence, preserve the
5143  % extra spacing after we do the footnote number.
5144  \let\@sf\empty
5145  \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi
5146  %
5147  % Remove inadvertent blank space before typesetting the footnote number.
5148  \unskip
5149  \thisfootno\@sf
5150  \footnotezzz
5151}%
5152
5153% Don't bother with the trickery in plain.tex to not require the
5154% footnote text as a parameter.  Our footnotes don't need to be so general.
5155%
5156% Oh yes, they do; otherwise, @ifset and anything else that uses
5157% \parseargline fail inside footnotes because the tokens are fixed when
5158% the footnote is read.  --karl, 16nov96.
5159%
5160\long\gdef\footnotezzz{\insert\footins\bgroup
5161  % We want to typeset this text as a normal paragraph, even if the
5162  % footnote reference occurs in (for example) a display environment.
5163  % So reset some parameters.
5164  \interlinepenalty\interfootnotelinepenalty
5165  \splittopskip\ht\strutbox % top baseline for broken footnotes
5166  \splitmaxdepth\dp\strutbox
5167  \floatingpenalty\@MM
5168  \leftskip\z@skip
5169  \rightskip\z@skip
5170  \spaceskip\z@skip
5171  \xspaceskip\z@skip
5172  \parindent\defaultparindent
5173  %
5174  % Hang the footnote text off the number.
5175  \hang
5176  \textindent{\thisfootno}%
5177  %
5178  % Don't crash into the line above the footnote text.  Since this
5179  % expands into a box, it must come within the paragraph, lest it
5180  % provide a place where TeX can split the footnote.
5181  \footstrut
5182  \futurelet\next\fo@t
5183}
5184\def\fo@t{\ifcat\bgroup\noexpand\next \let\next\f@@t
5185  \else\let\next\f@t\fi \next}
5186\def\f@@t{\bgroup\aftergroup\@foot\let\next}
5187\def\f@t#1{#1\@foot}
5188\def\@foot{\strut\egroup}
5189
5190}%end \catcode `\@=11
5191
5192% Set the baselineskip to #1, and the lineskip and strut size
5193% correspondingly.  There is no deep meaning behind these magic numbers
5194% used as factors; they just match (closely enough) what Knuth defined.
5195%
5196\def\lineskipfactor{.08333}
5197\def\strutheightpercent{.70833}
5198\def\strutdepthpercent {.29167}
5199%
5200\def\setleading#1{%
5201  \normalbaselineskip = #1\relax
5202  \normallineskip = \lineskipfactor\normalbaselineskip
5203  \normalbaselines
5204  \setbox\strutbox =\hbox{%
5205    \vrule width0pt height\strutheightpercent\baselineskip
5206                    depth \strutdepthpercent \baselineskip
5207  }%
5208}
5209
5210% @| inserts a changebar to the left of the current line.  It should
5211% surround any changed text.  This approach does *not* work if the
5212% change spans more than two lines of output.  To handle that, we would
5213% have adopt a much more difficult approach (putting marks into the main
5214% vertical list for the beginning and end of each change).
5215%
5216\def\|{%
5217  % \vadjust can only be used in horizontal mode.
5218  \leavevmode
5219  %
5220  % Append this vertical mode material after the current line in the output.
5221  \vadjust{%
5222    % We want to insert a rule with the height and depth of the current
5223    % leading; that is exactly what \strutbox is supposed to record.
5224    \vskip-\baselineskip
5225    %
5226    % \vadjust-items are inserted at the left edge of the type.  So
5227    % the \llap here moves out into the left-hand margin.
5228    \llap{%
5229      %
5230      % For a thicker or thinner bar, change the `1pt'.
5231      \vrule height\baselineskip width1pt
5232      %
5233      % This is the space between the bar and the text.
5234      \hskip 12pt
5235    }%
5236  }%
5237}
5238
5239% For a final copy, take out the rectangles
5240% that mark overfull boxes (in case you have decided
5241% that the text looks ok even though it passes the margin).
5242%
5243\def\finalout{\overfullrule=0pt}
5244
5245% @image.  We use the macros from epsf.tex to support this.
5246% If epsf.tex is not installed and @image is used, we complain.
5247%
5248% Check for and read epsf.tex up front.  If we read it only at @image
5249% time, we might be inside a group, and then its definitions would get
5250% undone and the next image would fail.
5251\openin 1 = epsf.tex
5252\ifeof 1 \else
5253  \closein 1
5254  % Do not bother showing banner with post-v2.7 epsf.tex (available in
5255  % doc/epsf.tex until it shows up on ctan).
5256  \def\epsfannounce{\toks0 = }%
5257  \input epsf.tex
5258\fi
5259%
5260\newif\ifwarnednoepsf
5261\newhelp\noepsfhelp{epsf.tex must be installed for images to
5262  work.  It is also included in the Texinfo distribution, or you can get
5263  it from ftp://tug.org/tex/epsf.tex.}
5264%
5265% Only complain once about lack of epsf.tex.
5266\def\image#1{%
5267  \ifx\pdfoutput\undefined
5268    \ifx\epsfbox\undefined
5269      \ifwarnednoepsf \else
5270        \errhelp = \noepsfhelp
5271        \errmessage{epsf.tex not found, images will be ignored}%
5272        \global\warnednoepsftrue
5273      \fi
5274    \else
5275      \imagexxx #1,,,\finish
5276    \fi
5277  \else
5278    \centerline{\pdfimage #1.pdf}%
5279  \fi
5280}
5281%
5282% Arguments to @image:
5283% #1 is (mandatory) image filename; we tack on .eps extension.
5284% #2 is (optional) width, #3 is (optional) height.
5285% #4 is just the usual extra ignored arg for parsing this stuff.
5286\def\imagexxx#1,#2,#3,#4\finish{%
5287  % \epsfbox itself resets \epsf?size at each figure.
5288  \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
5289  \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
5290  % If the image is by itself, center it.
5291  \ifvmode
5292    \nobreak\medskip
5293    \nobreak
5294    \centerline{\epsfbox{#1.eps}}%
5295    \bigbreak
5296  \else
5297    % In the middle of a paragraph, no extra space.
5298    \epsfbox{#1.eps}%
5299  \fi
5300}
5301
5302
5303\message{localization,}
5304
5305% @documentlanguage is usually given very early, just after
5306% @setfilename.  If done too late, it may not override everything
5307% properly.  Single argument is the language abbreviation.
5308% It would be nice if we could set up a hyphenation file here.
5309%
5310\def\documentlanguage{\parsearg\dodocumentlanguage}
5311\def\dodocumentlanguage#1{%
5312  \tex % read txi-??.tex file in plain TeX.
5313  % Read the file if it exists.
5314  \openin 1 txi-#1.tex
5315  \ifeof1
5316    \errhelp = \nolanghelp
5317    \errmessage{Cannot read language file txi-#1.tex}%
5318    \let\temp = \relax
5319  \else
5320    \def\temp{\input txi-#1.tex }%
5321  \fi
5322  \temp
5323  \endgroup
5324}
5325\newhelp\nolanghelp{The given language definition file cannot be found or
5326is empty.  Maybe you need to install it?  In the current directory
5327should work if nowhere else does.}
5328
5329
5330% @documentencoding should change something in TeX eventually, most
5331% likely, but for now just recognize it.
5332\let\documentencoding = \comment
5333
5334
5335% Page size parameters.
5336%
5337\newdimen\defaultparindent \defaultparindent = 15pt
5338
5339\chapheadingskip = 15pt plus 4pt minus 2pt
5340\secheadingskip = 12pt plus 3pt minus 2pt
5341\subsecheadingskip = 9pt plus 2pt minus 2pt
5342
5343% Prevent underfull vbox error messages.
5344\vbadness = 10000
5345
5346% Don't be so finicky about underfull hboxes, either.
5347\hbadness = 2000
5348
5349% Following George Bush, just get rid of widows and orphans.
5350\widowpenalty=10000
5351\clubpenalty=10000
5352
5353% Use TeX 3.0's \emergencystretch to help line breaking, but if we're
5354% using an old version of TeX, don't do anything.  We want the amount of
5355% stretch added to depend on the line length, hence the dependence on
5356% \hsize.  We call this whenever the paper size is set.
5357%
5358\def\setemergencystretch{%
5359  \ifx\emergencystretch\thisisundefined
5360    % Allow us to assign to \emergencystretch anyway.
5361    \def\emergencystretch{\dimen0}%
5362  \else
5363    \emergencystretch = \hsize
5364    \divide\emergencystretch by 40
5365  \fi
5366}
5367
5368% Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
5369% 4) hoffset; 5) binding offset; 6) topskip.  Then whoever calls us can
5370% set \parskip and call \setleading for \baselineskip.
5371%
5372\def\internalpagesizes#1#2#3#4#5#6{%
5373  \voffset = #3\relax
5374  \topskip = #6\relax
5375  \splittopskip = \topskip
5376  %
5377  \vsize = #1\relax
5378  \advance\vsize by \topskip
5379  \outervsize = \vsize
5380  \advance\outervsize by 2\topandbottommargin
5381  \pageheight = \vsize
5382  %
5383  \hsize = #2\relax
5384  \outerhsize = \hsize
5385  \advance\outerhsize by 0.5in
5386  \pagewidth = \hsize
5387  %
5388  \normaloffset = #4\relax
5389  \bindingoffset = #5\relax
5390  %
5391  \parindent = \defaultparindent
5392  \setemergencystretch
5393}
5394
5395% @letterpaper (the default).
5396\def\letterpaper{{\globaldefs = 1
5397  \parskip = 3pt plus 2pt minus 1pt
5398  \setleading{13.2pt}%
5399  %
5400  % If page is nothing but text, make it come out even.
5401  \internalpagesizes{46\baselineskip}{6in}{\voffset}{.25in}{\bindingoffset}{36pt}%
5402}}
5403
5404% Use @smallbook to reset parameters for 7x9.5 (or so) format.
5405\def\smallbook{{\globaldefs = 1
5406  \parskip = 2pt plus 1pt
5407  \setleading{12pt}%
5408  %
5409  \internalpagesizes{7.5in}{5.in}{\voffset}{.25in}{\bindingoffset}{16pt}%
5410  %
5411  \lispnarrowing = 0.3in
5412  \tolerance = 700
5413  \hfuzz = 1pt
5414  \contentsrightmargin = 0pt
5415  \deftypemargin = 0pt
5416  \defbodyindent = .5cm
5417  %
5418  \let\smalldisplay = \smalldisplayx
5419  \let\smallexample = \smalllispx
5420  \let\smallformat = \smallformatx
5421  \let\smalllisp = \smalllispx
5422}}
5423
5424% Use @afourpaper to print on European A4 paper.
5425\def\afourpaper{{\globaldefs = 1
5426  \setleading{12pt}%
5427  \parskip = 3pt plus 2pt minus 1pt
5428  %
5429  \internalpagesizes{53\baselineskip}{160mm}{\voffset}{4mm}{\bindingoffset}{44pt}%
5430  %
5431  \tolerance = 700
5432  \hfuzz = 1pt
5433}}
5434
5435% A specific text layout, 24x15cm overall, intended for A4 paper.  Top margin
5436% 29mm, hence bottom margin 28mm, nominal side margin 3cm.
5437\def\afourlatex{{\globaldefs = 1
5438  \setleading{13.6pt}%
5439  %
5440  \afourpaper
5441  \internalpagesizes{237mm}{150mm}{3.6mm}{3.6mm}{3mm}{7mm}%
5442  %
5443  \globaldefs = 0
5444}}
5445
5446% Use @afourwide to print on European A4 paper in wide format.
5447\def\afourwide{%
5448  \afourpaper
5449  \internalpagesizes{9.5in}{6.5in}{\hoffset}{\normaloffset}{\bindingoffset}{7mm}%
5450  %
5451  \globaldefs = 0
5452}
5453
5454% @pagesizes TEXTHEIGHT[,TEXTWIDTH]
5455% Perhaps we should allow setting the margins, \topskip, \parskip,
5456% and/or leading, also. Or perhaps we should compute them somehow.
5457%
5458\def\pagesizes{\parsearg\pagesizesxxx}
5459\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish}
5460\def\pagesizesyyy#1,#2,#3\finish{{%
5461  \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
5462  \globaldefs = 1
5463  %
5464  \parskip = 3pt plus 2pt minus 1pt
5465  \setleading{13.2pt}%
5466  %
5467  \internalpagesizes{#1}{\hsize}{\voffset}{\normaloffset}{\bindingoffset}{44pt}%
5468}}
5469
5470% Set default to letter.
5471%
5472\letterpaper
5473
5474\message{and turning on texinfo input format.}
5475
5476% Define macros to output various characters with catcode for normal text.
5477\catcode`\"=\other
5478\catcode`\~=\other
5479\catcode`\^=\other
5480\catcode`\_=\other
5481\catcode`\|=\other
5482\catcode`\<=\other
5483\catcode`\>=\other
5484\catcode`\+=\other
5485\def\normaldoublequote{"}
5486\def\normaltilde{~}
5487\def\normalcaret{^}
5488\def\normalunderscore{_}
5489\def\normalverticalbar{|}
5490\def\normalless{<}
5491\def\normalgreater{>}
5492\def\normalplus{+}
5493
5494% This macro is used to make a character print one way in ttfont
5495% where it can probably just be output, and another way in other fonts,
5496% where something hairier probably needs to be done.
5497%
5498% #1 is what to print if we are indeed using \tt; #2 is what to print
5499% otherwise.  Since all the Computer Modern typewriter fonts have zero
5500% interword stretch (and shrink), and it is reasonable to expect all
5501% typewriter fonts to have this, we can check that font parameter.
5502%
5503\def\ifusingtt#1#2{\ifdim \fontdimen3\the\font=0pt #1\else #2\fi}
5504
5505% Turn off all special characters except @
5506% (and those which the user can use as if they were ordinary).
5507% Most of these we simply print from the \tt font, but for some, we can
5508% use math or other variants that look better in normal text.
5509
5510\catcode`\"=\active
5511\def\activedoublequote{{\tt\char34}}
5512\let"=\activedoublequote
5513\catcode`\~=\active
5514\def~{{\tt\char126}}
5515\chardef\hat=`\^
5516\catcode`\^=\active
5517\def^{{\tt \hat}}
5518
5519\catcode`\_=\active
5520\def_{\ifusingtt\normalunderscore\_}
5521% Subroutine for the previous macro.
5522\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em height.1ex}}
5523
5524\catcode`\|=\active
5525\def|{{\tt\char124}}
5526\chardef \less=`\<
5527\catcode`\<=\active
5528\def<{{\tt \less}}
5529\chardef \gtr=`\>
5530\catcode`\>=\active
5531\def>{{\tt \gtr}}
5532\catcode`\+=\active
5533\def+{{\tt \char 43}}
5534%\catcode 27=\active
5535%\def^^[{$\diamondsuit$}
5536
5537% Set up an active definition for =, but don't enable it most of the time.
5538{\catcode`\==\active
5539\global\def={{\tt \char 61}}}
5540
5541\catcode`+=\active
5542\catcode`\_=\active
5543
5544% If a .fmt file is being used, characters that might appear in a file
5545% name cannot be active until we have parsed the command line.
5546% So turn them off again, and have \everyjob (or @setfilename) turn them on.
5547% \otherifyactive is called near the end of this file.
5548\def\otherifyactive{\catcode`+=\other \catcode`\_=\other}
5549
5550\catcode`\@=0
5551
5552% \rawbackslashxx output one backslash character in current font
5553\global\chardef\rawbackslashxx=`\\
5554%{\catcode`\\=\other
5555%@gdef@rawbackslashxx{\}}
5556
5557% \rawbackslash redefines \ as input to do \rawbackslashxx.
5558{\catcode`\\=\active
5559@gdef@rawbackslash{@let\=@rawbackslashxx }}
5560
5561% \normalbackslash outputs one backslash in fixed width font.
5562\def\normalbackslash{{\tt\rawbackslashxx}}
5563
5564% Say @foo, not \foo, in error messages.
5565\escapechar=`\@
5566
5567% \catcode 17=0   % Define control-q
5568\catcode`\\=\active
5569
5570% Used sometimes to turn off (effectively) the active characters
5571% even after parsing them.
5572@def@turnoffactive{@let"=@normaldoublequote
5573@let\=@realbackslash
5574@let~=@normaltilde
5575@let^=@normalcaret
5576@let_=@normalunderscore
5577@let|=@normalverticalbar
5578@let<=@normalless
5579@let>=@normalgreater
5580@let+=@normalplus}
5581
5582@def@normalturnoffactive{@let"=@normaldoublequote
5583@let\=@normalbackslash
5584@let~=@normaltilde
5585@let^=@normalcaret
5586@let_=@normalunderscore
5587@let|=@normalverticalbar
5588@let<=@normalless
5589@let>=@normalgreater
5590@let+=@normalplus}
5591
5592% Make _ and + \other characters, temporarily.
5593% This is canceled by @fixbackslash.
5594@otherifyactive
5595
5596% If a .fmt file is being used, we don't want the `\input texinfo' to show up.
5597% That is what \eatinput is for; after that, the `\' should revert to printing
5598% a backslash.
5599%
5600@gdef@eatinput input texinfo{@fixbackslash}
5601@global@let\ = @eatinput
5602
5603% On the other hand, perhaps the file did not have a `\input texinfo'. Then
5604% the first `\{ in the file would cause an error. This macro tries to fix
5605% that, assuming it is called before the first `\' could plausibly occur.
5606% Also back turn on active characters that might appear in the input
5607% file name, in case not using a pre-dumped format.
5608%
5609@gdef@fixbackslash{@ifx\@eatinput @let\ = @normalbackslash @fi
5610  @catcode`+=@active @catcode`@_=@active}
5611
5612% These look ok in all fonts, so just make them not special.  The @rm below
5613% makes sure that the current font starts out as the newly loaded cmr10
5614@catcode`@$=@other @catcode`@%=@other @catcode`@&=@other @catcode`@#=@other
5615
5616@textfonts
5617@rm
5618
5619@c Local variables:
5620@c eval: (add-hook 'write-file-hooks 'time-stamp)
5621@c page-delimiter: "^\\\\message"
5622@c time-stamp-start: "def\\\\texinfoversion{"
5623@c time-stamp-format: "%:y-%02m-%02d.%H"
5624@c time-stamp-end: "}"
5625@c End:
Note: See TracBrowser for help on using the repository browser.