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