source: rtems/doc/texinfo/texinfo.tex @ 3dacf35

4.104.114.84.95
Last change on this file since 3dacf35 was 3dacf35, checked in by Joel Sherrill <joel.sherrill@…>, on May 28, 2000 at 6:27:31 PM

Change linkcolor to Blue from Cyan per patch from Trevin Beattie
<trevin@…> obtained from bug-texinfo mailing list.

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