Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/bensch/texinfo.tex @ 1829

Last change on this file since 1829 was 1814, checked in by bensch, 21 years ago

orxonox/brnaches/bensch: added autoproject configuration

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