142629Sobrien% texinfo.tex -- TeX macros to handle Texinfo files.
242629Sobrien%
342629Sobrien% Load plain if necessary, i.e., if running under initex.
438494Sobrien\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
542629Sobrien%
6174294Sobrien\def\texinfoversion{2004-09-06.16}
742629Sobrien%
8174294Sobrien% Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
9174294Sobrien% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
10174294Sobrien% Foundation, Inc.
1142629Sobrien%
1242629Sobrien% This texinfo.tex file is free software; you can redistribute it and/or
1342629Sobrien% modify it under the terms of the GNU General Public License as
1442629Sobrien% published by the Free Software Foundation; either version 2, or (at
1542629Sobrien% your option) any later version.
1642629Sobrien%
1742629Sobrien% This texinfo.tex file is distributed in the hope that it will be
1842629Sobrien% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
1942629Sobrien% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2042629Sobrien% General Public License for more details.
2142629Sobrien%
2242629Sobrien% You should have received a copy of the GNU General Public License
2342629Sobrien% along with this texinfo.tex file; see the file COPYING.  If not, write
2442629Sobrien% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
2542629Sobrien% Boston, MA 02111-1307, USA.
2642629Sobrien%
27174294Sobrien% As a special exception, when this file is read by TeX when processing
28174294Sobrien% a Texinfo source document, you may use the result without
29174294Sobrien% restriction.  (This has been our intent since Texinfo was invented.)
3042629Sobrien%
3142629Sobrien% Please try the latest version of texinfo.tex before submitting bug
3242629Sobrien% reports; you can get the latest version from:
33174294Sobrien%   http://www.gnu.org/software/texinfo/ (the Texinfo home page), or
34119679Smbr%   ftp://tug.org/tex/texinfo.tex
35174294Sobrien%     (and all CTAN mirrors, see http://www.ctan.org).
36174294Sobrien% The texinfo.tex in any given distribution could well be out
3742629Sobrien% of date, so if that's what you're using, please check.
3882794Sobrien%
3982794Sobrien% Send bug reports to bug-texinfo@gnu.org.  Please include including a
4082794Sobrien% complete document in each bug report with which we can reproduce the
4182794Sobrien% problem.  Patches are, of course, greatly appreciated.
4282794Sobrien%
4342629Sobrien% To process a Texinfo manual with TeX, it's most reliable to use the
4482794Sobrien% texi2dvi shell script that comes with the distribution.  For a simple
4582794Sobrien% manual foo.texi, however, you can get away with this:
4642629Sobrien%   tex foo.texi
4742629Sobrien%   texindex foo.??
4842629Sobrien%   tex foo.texi
4942629Sobrien%   tex foo.texi
50119679Smbr%   dvips foo.dvi -o  # or whatever; this makes foo.ps.
51119679Smbr% The extra TeX runs get the cross-reference information correct.
5242629Sobrien% Sometimes one run after texindex suffices, and sometimes you need more
5342629Sobrien% than two; texi2dvi does it as many times as necessary.
5482794Sobrien%
55174294Sobrien% It is possible to adapt texinfo.tex for other languages, to some
56174294Sobrien% extent.  You can get the existing language-specific files from the
57174294Sobrien% full Texinfo distribution.
58174294Sobrien%
59174294Sobrien% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
6038494Sobrien
61174294Sobrien
6242629Sobrien\message{Loading texinfo [version \texinfoversion]:}
6338494Sobrien
6438494Sobrien% If in a .fmt file, print the version number
6538494Sobrien% and turn on active characters that we couldn't do earlier because
6638494Sobrien% they might have appeared in the input file name.
6742629Sobrien\everyjob{\message{[Texinfo version \texinfoversion]}%
6838494Sobrien  \catcode`+=\active \catcode`\_=\active}
6938494Sobrien
70174294Sobrien\message{Basics,}
71174294Sobrien\chardef\other=12
72174294Sobrien
73174294Sobrien% We never want plain's \outer definition of \+ in Texinfo.
74174294Sobrien% For @tex, we can use \tabalign.
75174294Sobrien\let\+ = \relax
76174294Sobrien
77174294Sobrien% Save some plain tex macros whose names we will redefine.
7838494Sobrien\let\ptexb=\b
7938494Sobrien\let\ptexbullet=\bullet
8038494Sobrien\let\ptexc=\c
8138494Sobrien\let\ptexcomma=\,
8238494Sobrien\let\ptexdot=\.
8338494Sobrien\let\ptexdots=\dots
8438494Sobrien\let\ptexend=\end
8542629Sobrien\let\ptexequiv=\equiv
8642629Sobrien\let\ptexexclam=\!
87174294Sobrien\let\ptexfootnote=\footnote
88174294Sobrien\let\ptexgtr=>
89174294Sobrien\let\ptexhat=^
9038494Sobrien\let\ptexi=\i
91174294Sobrien\let\ptexindent=\indent
92174294Sobrien\let\ptexnoindent=\noindent
93174294Sobrien\let\ptexinsert=\insert
9438494Sobrien\let\ptexlbrace=\{
95174294Sobrien\let\ptexless=<
96174294Sobrien\let\ptexplus=+
9738494Sobrien\let\ptexrbrace=\}
98174294Sobrien\let\ptexslash=\/
9938494Sobrien\let\ptexstar=\*
10038494Sobrien\let\ptext=\t
10138494Sobrien
10238494Sobrien% If this character appears in an error message or help string, it
10338494Sobrien% starts a new line in the output.
10438494Sobrien\newlinechar = `^^J
10538494Sobrien
106174294Sobrien% Use TeX 3.0's \inputlineno to get the line number, for better error
107174294Sobrien% messages, but if we're using an old version of TeX, don't do anything.
108174294Sobrien%
109174294Sobrien\ifx\inputlineno\thisisundefined
110174294Sobrien  \let\linenumber = \empty % Pre-3.0.
111174294Sobrien\else
112174294Sobrien  \def\linenumber{l.\the\inputlineno:\space}
113174294Sobrien\fi
114174294Sobrien
11542629Sobrien% Set up fixed words for English if not already set.
11682794Sobrien\ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
11782794Sobrien\ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
11882794Sobrien\ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
11982794Sobrien\ifx\putwordin\undefined        \gdef\putwordin{in}\fi
12082794Sobrien\ifx\putwordIndexIsEmpty\undefined     \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
12182794Sobrien\ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
12282794Sobrien\ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
12382794Sobrien\ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
12482794Sobrien\ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
12582794Sobrien\ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
12682794Sobrien\ifx\putwordof\undefined        \gdef\putwordof{of}\fi
12782794Sobrien\ifx\putwordon\undefined        \gdef\putwordon{on}\fi
12882794Sobrien\ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
12982794Sobrien\ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
13082794Sobrien\ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
13182794Sobrien\ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
13282794Sobrien\ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
13382794Sobrien\ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
13482794Sobrien\ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
13582794Sobrien%
13682794Sobrien\ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
13782794Sobrien\ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
13882794Sobrien\ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
13982794Sobrien\ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
14082794Sobrien\ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
14182794Sobrien\ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
14282794Sobrien\ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
14382794Sobrien\ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
14482794Sobrien\ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
14582794Sobrien\ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
14682794Sobrien\ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
14782794Sobrien\ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
14882794Sobrien%
14982794Sobrien\ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
15082794Sobrien\ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
15182794Sobrien\ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
15282794Sobrien\ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
15382794Sobrien\ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
15438494Sobrien
155174294Sobrien% In some macros, we cannot use the `\? notation---the left quote is
156174294Sobrien% in some cases the escape char.
157174294Sobrien\chardef\colonChar = `\:
158174294Sobrien\chardef\commaChar = `\,
159174294Sobrien\chardef\dotChar   = `\.
160174294Sobrien\chardef\exclamChar= `\!
161174294Sobrien\chardef\questChar = `\?
162174294Sobrien\chardef\semiChar  = `\;
163174294Sobrien\chardef\underChar = `\_
164174294Sobrien
165174294Sobrien\chardef\spaceChar = `\ %
166174294Sobrien\chardef\spacecat = 10
167174294Sobrien\def\spaceisspace{\catcode\spaceChar=\spacecat}
168174294Sobrien
16938494Sobrien% Ignore a token.
17038494Sobrien%
17138494Sobrien\def\gobble#1{}
17238494Sobrien
173174294Sobrien% The following is used inside several \edef's.
174174294Sobrien\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
17538494Sobrien
176174294Sobrien% Hyphenation fixes.
177174294Sobrien\hyphenation{
178174294Sobrien  Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
179174294Sobrien  ap-pen-dix bit-map bit-maps
180174294Sobrien  data-base data-bases eshell fall-ing half-way long-est man-u-script
181174294Sobrien  man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
182174294Sobrien  par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
183174294Sobrien  spell-ing spell-ings
184174294Sobrien  stand-alone strong-est time-stamp time-stamps which-ever white-space
185174294Sobrien  wide-spread wrap-around
186174294Sobrien}
187174294Sobrien
18838494Sobrien% Margin to add to right of even pages, to left of odd pages.
189174294Sobrien\newdimen\bindingoffset
190174294Sobrien\newdimen\normaloffset
19138494Sobrien\newdimen\pagewidth \newdimen\pageheight
19238494Sobrien
193174294Sobrien% For a final copy, take out the rectangles
194174294Sobrien% that mark overfull boxes (in case you have decided
195174294Sobrien% that the text looks ok even though it passes the margin).
196174294Sobrien%
197174294Sobrien\def\finalout{\overfullrule=0pt}
198174294Sobrien
199174294Sobrien% @| inserts a changebar to the left of the current line.  It should
200174294Sobrien% surround any changed text.  This approach does *not* work if the
201174294Sobrien% change spans more than two lines of output.  To handle that, we would
202174294Sobrien% have adopt a much more difficult approach (putting marks into the main
203174294Sobrien% vertical list for the beginning and end of each change).
204174294Sobrien%
205174294Sobrien\def\|{%
206174294Sobrien  % \vadjust can only be used in horizontal mode.
207174294Sobrien  \leavevmode
208174294Sobrien  %
209174294Sobrien  % Append this vertical mode material after the current line in the output.
210174294Sobrien  \vadjust{%
211174294Sobrien    % We want to insert a rule with the height and depth of the current
212174294Sobrien    % leading; that is exactly what \strutbox is supposed to record.
213174294Sobrien    \vskip-\baselineskip
214174294Sobrien    %
215174294Sobrien    % \vadjust-items are inserted at the left edge of the type.  So
216174294Sobrien    % the \llap here moves out into the left-hand margin.
217174294Sobrien    \llap{%
218174294Sobrien      %
219174294Sobrien      % For a thicker or thinner bar, change the `1pt'.
220174294Sobrien      \vrule height\baselineskip width1pt
221174294Sobrien      %
222174294Sobrien      % This is the space between the bar and the text.
223174294Sobrien      \hskip 12pt
224174294Sobrien    }%
225174294Sobrien  }%
226174294Sobrien}
227174294Sobrien
22838494Sobrien% Sometimes it is convenient to have everything in the transcript file
22938494Sobrien% and nothing on the terminal.  We don't just call \tracingall here,
230174294Sobrien% since that produces some useless output on the terminal.  We also make
231174294Sobrien% some effort to order the tracing commands to reduce output in the log
232174294Sobrien% file; cf. trace.sty in LaTeX.
23338494Sobrien%
23438494Sobrien\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
235174294Sobrien\def\loggingall{%
236174294Sobrien  \tracingstats2
237174294Sobrien  \tracingpages1
238174294Sobrien  \tracinglostchars2  % 2 gives us more in etex
239174294Sobrien  \tracingparagraphs1
240174294Sobrien  \tracingoutput1
241174294Sobrien  \tracingmacros2
242174294Sobrien  \tracingrestores1
243174294Sobrien  \showboxbreadth\maxdimen \showboxdepth\maxdimen
244174294Sobrien  \ifx\eTeXversion\undefined\else % etex gives us more logging
245174294Sobrien    \tracingscantokens1
246174294Sobrien    \tracingifs1
247174294Sobrien    \tracinggroups1
248174294Sobrien    \tracingnesting2
249174294Sobrien    \tracingassigns1
250174294Sobrien  \fi
251174294Sobrien  \tracingcommands3  % 3 gives us more in etex
252174294Sobrien  \errorcontextlines16
25338494Sobrien}%
25438494Sobrien
25582794Sobrien% add check for \lastpenalty to plain's definitions.  If the last thing
25682794Sobrien% we did was a \nobreak, we don't want to insert more space.
257174294Sobrien%
25882794Sobrien\def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
25982794Sobrien  \removelastskip\penalty-50\smallskip\fi\fi}
26082794Sobrien\def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
26182794Sobrien  \removelastskip\penalty-100\medskip\fi\fi}
26282794Sobrien\def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
26382794Sobrien  \removelastskip\penalty-200\bigskip\fi\fi}
26482794Sobrien
26538494Sobrien% For @cropmarks command.
26638494Sobrien% Do @cropmarks to get crop marks.
26782794Sobrien%
26838494Sobrien\newif\ifcropmarks
26938494Sobrien\let\cropmarks = \cropmarkstrue
27038494Sobrien%
27138494Sobrien% Dimensions to add cropmarks at corners.
27238494Sobrien% Added by P. A. MacKay, 12 Nov. 1986
27338494Sobrien%
27442629Sobrien\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
27542629Sobrien\newdimen\cornerlong  \cornerlong=1pc
27642629Sobrien\newdimen\cornerthick \cornerthick=.3pt
27742629Sobrien\newdimen\topandbottommargin \topandbottommargin=.75in
27838494Sobrien
27938494Sobrien% Main output routine.
28038494Sobrien\chardef\PAGE = 255
28138494Sobrien\output = {\onepageout{\pagecontents\PAGE}}
28238494Sobrien
28338494Sobrien\newbox\headlinebox
28438494Sobrien\newbox\footlinebox
28538494Sobrien
28638494Sobrien% \onepageout takes a vbox as an argument.  Note that \pagecontents
28738494Sobrien% does insertions, but you have to call it yourself.
28838494Sobrien\def\onepageout#1{%
28938494Sobrien  \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
29038494Sobrien  %
29138494Sobrien  \ifodd\pageno  \advance\hoffset by \bindingoffset
29238494Sobrien  \else \advance\hoffset by -\bindingoffset\fi
29338494Sobrien  %
29438494Sobrien  % Do this outside of the \shipout so @code etc. will be expanded in
29538494Sobrien  % the headline as they should be, not taken literally (outputting ''code).
29638494Sobrien  \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}%
29738494Sobrien  \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}%
29838494Sobrien  %
29938494Sobrien  {%
30038494Sobrien    % Have to do this stuff outside the \shipout because we want it to
30138494Sobrien    % take effect in \write's, yet the group defined by the \vbox ends
30238494Sobrien    % before the \shipout runs.
30338494Sobrien    %
30438494Sobrien    \escapechar = `\\     % use backslash in output files.
30538494Sobrien    \indexdummies         % don't expand commands in the output.
30638494Sobrien    \normalturnoffactive  % \ in index entries must not stay \, e.g., if
30738494Sobrien                   % the page break happens to be in the middle of an example.
30838494Sobrien    \shipout\vbox{%
30982794Sobrien      % Do this early so pdf references go to the beginning of the page.
310174294Sobrien      \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
31182794Sobrien      %
31238494Sobrien      \ifcropmarks \vbox to \outervsize\bgroup
31338494Sobrien        \hsize = \outerhsize
31442629Sobrien        \vskip-\topandbottommargin
31542629Sobrien        \vtop to0pt{%
31642629Sobrien          \line{\ewtop\hfil\ewtop}%
31742629Sobrien          \nointerlineskip
31842629Sobrien          \line{%
31942629Sobrien            \vbox{\moveleft\cornerthick\nstop}%
32042629Sobrien            \hfill
32142629Sobrien            \vbox{\moveright\cornerthick\nstop}%
32242629Sobrien          }%
32342629Sobrien          \vss}%
32438494Sobrien        \vskip\topandbottommargin
32538494Sobrien        \line\bgroup
32638494Sobrien          \hfil % center the page within the outer (page) hsize.
32738494Sobrien          \ifodd\pageno\hskip\bindingoffset\fi
32838494Sobrien          \vbox\bgroup
32938494Sobrien      \fi
33038494Sobrien      %
33138494Sobrien      \unvbox\headlinebox
33238494Sobrien      \pagebody{#1}%
33338494Sobrien      \ifdim\ht\footlinebox > 0pt
33438494Sobrien        % Only leave this space if the footline is nonempty.
33538494Sobrien        % (We lessened \vsize for it in \oddfootingxxx.)
33638494Sobrien        % The \baselineskip=24pt in plain's \makefootline has no effect.
33738494Sobrien        \vskip 2\baselineskip
33838494Sobrien        \unvbox\footlinebox
33938494Sobrien      \fi
34038494Sobrien      %
34138494Sobrien      \ifcropmarks
34238494Sobrien          \egroup % end of \vbox\bgroup
34338494Sobrien        \hfil\egroup % end of (centering) \line\bgroup
34438494Sobrien        \vskip\topandbottommargin plus1fill minus1fill
34538494Sobrien        \boxmaxdepth = \cornerthick
34642629Sobrien        \vbox to0pt{\vss
34742629Sobrien          \line{%
34842629Sobrien            \vbox{\moveleft\cornerthick\nsbot}%
34942629Sobrien            \hfill
35042629Sobrien            \vbox{\moveright\cornerthick\nsbot}%
35142629Sobrien          }%
35242629Sobrien          \nointerlineskip
35342629Sobrien          \line{\ewbot\hfil\ewbot}%
35438494Sobrien        }%
35538494Sobrien      \egroup % \vbox from first cropmarks clause
35638494Sobrien      \fi
35738494Sobrien    }% end of \shipout\vbox
358174294Sobrien  }% end of group with \normalturnoffactive
35938494Sobrien  \advancepageno
36038494Sobrien  \ifnum\outputpenalty>-20000 \else\dosupereject\fi
36138494Sobrien}
36238494Sobrien
36338494Sobrien\newinsert\margin \dimen\margin=\maxdimen
36438494Sobrien
36538494Sobrien\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}}
36638494Sobrien{\catcode`\@ =11
36738494Sobrien\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
36838494Sobrien% marginal hacks, juha@viisa.uucp (Juha Takala)
36938494Sobrien\ifvoid\margin\else % marginal info is present
37038494Sobrien  \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
37138494Sobrien\dimen@=\dp#1 \unvbox#1
37238494Sobrien\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
37338494Sobrien\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
37438494Sobrien}
37538494Sobrien
37638494Sobrien% Here are the rules for the cropmarks.  Note that they are
37738494Sobrien% offset so that the space between them is truly \outerhsize or \outervsize
37838494Sobrien% (P. A. MacKay, 12 November, 1986)
37938494Sobrien%
38038494Sobrien\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
38138494Sobrien\def\nstop{\vbox
38238494Sobrien  {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
38338494Sobrien\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
38438494Sobrien\def\nsbot{\vbox
38538494Sobrien  {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
38638494Sobrien
38738494Sobrien% Parse an argument, then pass it to #1.  The argument is the rest of
38838494Sobrien% the input line (except we remove a trailing comment).  #1 should be a
38938494Sobrien% macro which expects an ordinary undelimited TeX argument.
39038494Sobrien%
391174294Sobrien\def\parsearg{\parseargusing{}}
392174294Sobrien\def\parseargusing#1#2{%
393174294Sobrien  \def\next{#2}%
39438494Sobrien  \begingroup
39538494Sobrien    \obeylines
396174294Sobrien    \spaceisspace
397174294Sobrien    #1%
398174294Sobrien    \parseargline\empty% Insert the \empty token, see \finishparsearg below.
39938494Sobrien}
40038494Sobrien
40138494Sobrien{\obeylines %
40238494Sobrien  \gdef\parseargline#1^^M{%
40338494Sobrien    \endgroup % End of the group started in \parsearg.
404174294Sobrien    \argremovecomment #1\comment\ArgTerm%
40538494Sobrien  }%
40638494Sobrien}
40738494Sobrien
408174294Sobrien% First remove any @comment, then any @c comment.
409174294Sobrien\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
410174294Sobrien\def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
41138494Sobrien
412174294Sobrien% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
413174294Sobrien%
414174294Sobrien% \argremovec might leave us with trailing space, e.g.,
41538494Sobrien%    @end itemize  @c foo
416174294Sobrien% This space token undergoes the same procedure and is eventually removed
417174294Sobrien% by \finishparsearg.
41838494Sobrien%
419174294Sobrien\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
420174294Sobrien\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
421174294Sobrien\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
422174294Sobrien  \def\temp{#3}%
423174294Sobrien  \ifx\temp\empty
424174294Sobrien    % We cannot use \next here, as it holds the macro to run;
425174294Sobrien    % thus we reuse \temp.
426174294Sobrien    \let\temp\finishparsearg
427174294Sobrien  \else
428174294Sobrien    \let\temp\argcheckspaces
429174294Sobrien  \fi
430174294Sobrien  % Put the space token in:
431174294Sobrien  \temp#1 #3\ArgTerm
432174294Sobrien}
433174294Sobrien
434174294Sobrien% If a _delimited_ argument is enclosed in braces, they get stripped; so
435174294Sobrien% to get _exactly_ the rest of the line, we had to prevent such situation.
436174294Sobrien% We prepended an \empty token at the very beginning and we expand it now,
437174294Sobrien% just before passing the control to \next.
438174294Sobrien% (Similarily, we have to think about #3 of \argcheckspacesY above: it is
439174294Sobrien% either the null string, or it ends with \^^M---thus there is no danger
440174294Sobrien% that a pair of braces would be stripped.
44138494Sobrien%
442174294Sobrien% But first, we have to remove the trailing space token.
443174294Sobrien%
444174294Sobrien\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}}
445174294Sobrien
446174294Sobrien% \parseargdef\foo{...}
447174294Sobrien%	is roughly equivalent to
448174294Sobrien% \def\foo{\parsearg\Xfoo}
449174294Sobrien% \def\Xfoo#1{...}
450174294Sobrien%
451174294Sobrien% Actually, I use \csname\string\foo\endcsname, ie. \\foo, as it is my
452174294Sobrien% favourite TeX trick.  --kasal, 16nov03
453174294Sobrien
454174294Sobrien\def\parseargdef#1{%
455174294Sobrien  \expandafter \doparseargdef \csname\string#1\endcsname #1%
45638494Sobrien}
457174294Sobrien\def\doparseargdef#1#2{%
458174294Sobrien  \def#2{\parsearg#1}%
459174294Sobrien  \def#1##1%
460174294Sobrien}
46138494Sobrien
462174294Sobrien% Several utility definitions with active space:
463174294Sobrien{
46438494Sobrien  \obeyspaces
465174294Sobrien  \gdef\obeyedspace{ }
46638494Sobrien
467174294Sobrien  % Make each space character in the input produce a normal interword
468174294Sobrien  % space in the output.  Don't allow a line break at this space, as this
469174294Sobrien  % is used only in environments like @example, where each line of input
470174294Sobrien  % should produce a line of output anyway.
471174294Sobrien  %
472174294Sobrien  \gdef\sepspaces{\obeyspaces\let =\tie}
47338494Sobrien
474174294Sobrien  % If an index command is used in an @example environment, any spaces
475174294Sobrien  % therein should become regular spaces in the raw index file, not the
476174294Sobrien  % expansion of \tie (\leavevmode \penalty \@M \ ).
477174294Sobrien  \gdef\unsepspaces{\let =\space}
478174294Sobrien}
479174294Sobrien
480174294Sobrien
48138494Sobrien\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
48238494Sobrien
483174294Sobrien% Define the framework for environments in texinfo.tex.  It's used like this:
484174294Sobrien%
485174294Sobrien%   \envdef\foo{...}
486174294Sobrien%   \def\Efoo{...}
487174294Sobrien%
488174294Sobrien% It's the responsibility of \envdef to insert \begingroup before the
489174294Sobrien% actual body; @end closes the group after calling \Efoo.  \envdef also
490174294Sobrien% defines \thisenv, so the current environment is known; @end checks
491174294Sobrien% whether the environment name matches.  The \checkenv macro can also be
492174294Sobrien% used to check whether the current environment is the one expected.
493174294Sobrien%
494174294Sobrien% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
495174294Sobrien% are not treated as enviroments; they don't open a group.  (The
496174294Sobrien% implementation of @end takes care not to call \endgroup in this
497174294Sobrien% special case.)
49838494Sobrien
49938494Sobrien
500174294Sobrien% At runtime, environments start with this:
501174294Sobrien\def\startenvironment#1{\begingroup\def\thisenv{#1}}
502174294Sobrien% initialize
503174294Sobrien\let\thisenv\empty
50438494Sobrien
505174294Sobrien% ... but they get defined via ``\envdef\foo{...}'':
506174294Sobrien\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
507174294Sobrien\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
50838494Sobrien
509174294Sobrien% Check whether we're in the right environment:
510174294Sobrien\def\checkenv#1{%
511174294Sobrien  \def\temp{#1}%
512174294Sobrien  \ifx\thisenv\temp
51338494Sobrien  \else
514174294Sobrien    \badenverr
51538494Sobrien  \fi
51638494Sobrien}
51738494Sobrien
518174294Sobrien% Evironment mismatch, #1 expected:
519174294Sobrien\def\badenverr{%
52038494Sobrien  \errhelp = \EMsimple
521174294Sobrien  \errmessage{This command can appear only \inenvironment\temp,
522174294Sobrien    not \inenvironment\thisenv}%
52338494Sobrien}
524174294Sobrien\def\inenvironment#1{%
525174294Sobrien  \ifx#1\empty
526174294Sobrien    out of any environment%
527174294Sobrien  \else
528174294Sobrien    in environment \expandafter\string#1%
529174294Sobrien  \fi
530174294Sobrien}
53138494Sobrien
532174294Sobrien% @end foo executes the definition of \Efoo.
533174294Sobrien% But first, it executes a specialized version of \checkenv
53438494Sobrien%
535174294Sobrien\parseargdef\end{%
536174294Sobrien  \if 1\csname iscond.#1\endcsname
537174294Sobrien  \else
538174294Sobrien    % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03
539174294Sobrien    \expandafter\checkenv\csname#1\endcsname
540174294Sobrien    \csname E#1\endcsname
541174294Sobrien    \endgroup
542174294Sobrien  \fi
54338494Sobrien}
54438494Sobrien
545174294Sobrien\newhelp\EMsimple{Press RETURN to continue.}
54638494Sobrien
54738494Sobrien
54838494Sobrien%% Simple single-character @ commands
54938494Sobrien
55038494Sobrien% @@ prints an @
55138494Sobrien% Kludge this until the fonts are right (grr).
55242629Sobrien\def\@{{\tt\char64}}
55338494Sobrien
55438494Sobrien% This is turned off because it was never documented
55538494Sobrien% and you can use @w{...} around a quote to suppress ligatures.
55638494Sobrien%% Define @` and @' to be the same as ` and '
55738494Sobrien%% but suppressing ligatures.
55838494Sobrien%\def\`{{`}}
55938494Sobrien%\def\'{{'}}
56038494Sobrien
56138494Sobrien% Used to generate quoted braces.
56242629Sobrien\def\mylbrace {{\tt\char123}}
56342629Sobrien\def\myrbrace {{\tt\char125}}
56438494Sobrien\let\{=\mylbrace
56538494Sobrien\let\}=\myrbrace
56638494Sobrien\begingroup
567174294Sobrien  % Definitions to produce \{ and \} commands for indices,
568174294Sobrien  % and @{ and @} for the aux file.
569174294Sobrien  \catcode`\{ = \other \catcode`\} = \other
57038494Sobrien  \catcode`\[ = 1 \catcode`\] = 2
571174294Sobrien  \catcode`\! = 0 \catcode`\\ = \other
572174294Sobrien  !gdef!lbracecmd[\{]%
573174294Sobrien  !gdef!rbracecmd[\}]%
574174294Sobrien  !gdef!lbraceatcmd[@{]%
575174294Sobrien  !gdef!rbraceatcmd[@}]%
576174294Sobrien!endgroup
57738494Sobrien
578174294Sobrien% @comma{} to avoid , parsing problems.
579174294Sobrien\let\comma = ,
580174294Sobrien
58138494Sobrien% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
582174294Sobrien% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
58338494Sobrien\let\, = \c
58438494Sobrien\let\dotaccent = \.
58538494Sobrien\def\ringaccent#1{{\accent23 #1}}
58638494Sobrien\let\tieaccent = \t
58738494Sobrien\let\ubaraccent = \b
58838494Sobrien\let\udotaccent = \d
58938494Sobrien
590174294Sobrien% Other special characters: @questiondown @exclamdown @ordf @ordm
591174294Sobrien% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
59238494Sobrien\def\questiondown{?`}
59338494Sobrien\def\exclamdown{!`}
594174294Sobrien\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
595174294Sobrien\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
59638494Sobrien
59738494Sobrien% Dotless i and dotless j, used for accents.
59838494Sobrien\def\imacro{i}
59938494Sobrien\def\jmacro{j}
60038494Sobrien\def\dotless#1{%
60138494Sobrien  \def\temp{#1}%
60238494Sobrien  \ifx\temp\imacro \ptexi
60338494Sobrien  \else\ifx\temp\jmacro \j
60438494Sobrien  \else \errmessage{@dotless can be used only with i or j}%
60538494Sobrien  \fi\fi
60638494Sobrien}
60738494Sobrien
608174294Sobrien% The \TeX{} logo, as in plain, but resetting the spacing so that a
609174294Sobrien% period following counts as ending a sentence.  (Idea found in latex.)
610174294Sobrien%
611174294Sobrien\edef\TeX{\TeX \spacefactor=1000 }
612174294Sobrien
613174294Sobrien% @LaTeX{} logo.  Not quite the same results as the definition in
614174294Sobrien% latex.ltx, since we use a different font for the raised A; it's most
615174294Sobrien% convenient for us to use an explicitly smaller font, rather than using
616174294Sobrien% the \scriptstyle font (since we don't reset \scriptstyle and
617174294Sobrien% \scriptscriptstyle).
618174294Sobrien%
619174294Sobrien\def\LaTeX{%
620174294Sobrien  L\kern-.36em
621174294Sobrien  {\setbox0=\hbox{T}%
622174294Sobrien   \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}%
623174294Sobrien  \kern-.15em
624174294Sobrien  \TeX
625174294Sobrien}
626174294Sobrien
62742629Sobrien% Be sure we're in horizontal mode when doing a tie, since we make space
62842629Sobrien% equivalent to this in @example-like environments. Otherwise, a space
62942629Sobrien% at the beginning of a line will start with \penalty -- and
63042629Sobrien% since \penalty is valid in vertical mode, we'd end up putting the
63142629Sobrien% penalty on the vertical list instead of in the new paragraph.
63242629Sobrien{\catcode`@ = 11
63342629Sobrien % Avoid using \@M directly, because that causes trouble
63442629Sobrien % if the definition is written into an index file.
63542629Sobrien \global\let\tiepenalty = \@M
63642629Sobrien \gdef\tie{\leavevmode\penalty\tiepenalty\ }
63742629Sobrien}
63842629Sobrien
63938494Sobrien% @: forces normal size whitespace following.
64038494Sobrien\def\:{\spacefactor=1000 }
64138494Sobrien
64238494Sobrien% @* forces a line break.
64338494Sobrien\def\*{\hfil\break\hbox{}\ignorespaces}
64438494Sobrien
645174294Sobrien% @/ allows a line break.
646174294Sobrien\let\/=\allowbreak
647174294Sobrien
64838494Sobrien% @. is an end-of-sentence period.
64938494Sobrien\def\.{.\spacefactor=3000 }
65038494Sobrien
65138494Sobrien% @! is an end-of-sentence bang.
65242629Sobrien\def\!{!\spacefactor=3000 }
65338494Sobrien
65438494Sobrien% @? is an end-of-sentence query.
65542629Sobrien\def\?{?\spacefactor=3000 }
65638494Sobrien
65738494Sobrien% @w prevents a word break.  Without the \leavevmode, @w at the
65838494Sobrien% beginning of a paragraph, when TeX is still in vertical mode, would
65938494Sobrien% produce a whole line of output instead of starting the paragraph.
66038494Sobrien\def\w#1{\leavevmode\hbox{#1}}
66138494Sobrien
66238494Sobrien% @group ... @end group forces ... to be all on one page, by enclosing
66338494Sobrien% it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
66438494Sobrien% to keep its height that of a normal line.  According to the rules for
66538494Sobrien% \topskip (p.114 of the TeXbook), the glue inserted is
66638494Sobrien% max (\topskip - \ht (first item), 0).  If that height is large,
66738494Sobrien% therefore, no glue is inserted, and the space between the headline and
66838494Sobrien% the text is small, which looks bad.
66938494Sobrien%
670174294Sobrien% Another complication is that the group might be very large.  This can
671174294Sobrien% cause the glue on the previous page to be unduly stretched, because it
672174294Sobrien% does not have much material.  In this case, it's better to add an
673174294Sobrien% explicit \vfill so that the extra space is at the bottom.  The
674174294Sobrien% threshold for doing this is if the group is more than \vfilllimit
675174294Sobrien% percent of a page (\vfilllimit can be changed inside of @tex).
676174294Sobrien%
677174294Sobrien\newbox\groupbox
678174294Sobrien\def\vfilllimit{0.7}
679174294Sobrien%
680174294Sobrien\envdef\group{%
681174294Sobrien  \ifnum\catcode`\^^M=\active \else
68238494Sobrien    \errhelp = \groupinvalidhelp
68338494Sobrien    \errmessage{@group invalid in context where filling is enabled}%
68438494Sobrien  \fi
685174294Sobrien  \startsavinginserts
68638494Sobrien  %
687174294Sobrien  \setbox\groupbox = \vtop\bgroup
68838494Sobrien    % Do @comment since we are called inside an environment such as
68938494Sobrien    % @example, where each end-of-line in the input causes an
69038494Sobrien    % end-of-line in the output.  We don't want the end-of-line after
69138494Sobrien    % the `@group' to put extra space in the output.  Since @group
69238494Sobrien    % should appear on a line by itself (according to the Texinfo
69338494Sobrien    % manual), we don't worry about eating any user text.
69438494Sobrien    \comment
69538494Sobrien}
69638494Sobrien%
697174294Sobrien% The \vtop produces a box with normal height and large depth; thus, TeX puts
698174294Sobrien% \baselineskip glue before it, and (when the next line of text is done)
699174294Sobrien% \lineskip glue after it.  Thus, space below is not quite equal to space
700174294Sobrien% above.  But it's pretty close.
701174294Sobrien\def\Egroup{%
702174294Sobrien    % To get correct interline space between the last line of the group
703174294Sobrien    % and the first line afterwards, we have to propagate \prevdepth.
704174294Sobrien    \endgraf % Not \par, as it may have been set to \lisppar.
705174294Sobrien    \global\dimen1 = \prevdepth
706174294Sobrien  \egroup           % End the \vtop.
707174294Sobrien  % \dimen0 is the vertical size of the group's box.
708174294Sobrien  \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
709174294Sobrien  % \dimen2 is how much space is left on the page (more or less).
710174294Sobrien  \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
711174294Sobrien  % if the group doesn't fit on the current page, and it's a big big
712174294Sobrien  % group, force a page break.
713174294Sobrien  \ifdim \dimen0 > \dimen2
714174294Sobrien    \ifdim \pagetotal < \vfilllimit\pageheight
715174294Sobrien      \page
716174294Sobrien    \fi
717174294Sobrien  \fi
718174294Sobrien  \box\groupbox
719174294Sobrien  \prevdepth = \dimen1
720174294Sobrien  \checkinserts
721174294Sobrien}
722174294Sobrien%
72338494Sobrien% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
72438494Sobrien% message, so this ends up printing `@group can only ...'.
72538494Sobrien%
72638494Sobrien\newhelp\groupinvalidhelp{%
72738494Sobriengroup can only be used in environments such as @example,^^J%
72838494Sobrienwhere each line of input produces a line of output.}
72938494Sobrien
73038494Sobrien% @need space-in-mils
73138494Sobrien% forces a page break if there is not space-in-mils remaining.
73238494Sobrien
73338494Sobrien\newdimen\mil  \mil=0.001in
73438494Sobrien
73538494Sobrien% Old definition--didn't work.
736174294Sobrien%\parseargdef\need{\par %
73738494Sobrien%% This method tries to make TeX break the page naturally
73838494Sobrien%% if the depth of the box does not fit.
73938494Sobrien%{\baselineskip=0pt%
74042629Sobrien%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak
74138494Sobrien%\prevdepth=-1000pt
74238494Sobrien%}}
74338494Sobrien
744174294Sobrien\parseargdef\need{%
74582794Sobrien  % Ensure vertical mode, so we don't make a big box in the middle of a
74638494Sobrien  % paragraph.
74738494Sobrien  \par
74838494Sobrien  %
74982794Sobrien  % If the @need value is less than one line space, it's useless.
75082794Sobrien  \dimen0 = #1\mil
75182794Sobrien  \dimen2 = \ht\strutbox
75282794Sobrien  \advance\dimen2 by \dp\strutbox
75382794Sobrien  \ifdim\dimen0 > \dimen2
75482794Sobrien    %
75582794Sobrien    % Do a \strut just to make the height of this box be normal, so the
75682794Sobrien    % normal leading is inserted relative to the preceding line.
75782794Sobrien    % And a page break here is fine.
75882794Sobrien    \vtop to #1\mil{\strut\vfil}%
75982794Sobrien    %
76082794Sobrien    % TeX does not even consider page breaks if a penalty added to the
76182794Sobrien    % main vertical list is 10000 or more.  But in order to see if the
76282794Sobrien    % empty box we just added fits on the page, we must make it consider
76382794Sobrien    % page breaks.  On the other hand, we don't want to actually break the
76482794Sobrien    % page after the empty box.  So we use a penalty of 9999.
76582794Sobrien    %
76682794Sobrien    % There is an extremely small chance that TeX will actually break the
76782794Sobrien    % page at this \penalty, if there are no other feasible breakpoints in
76882794Sobrien    % sight.  (If the user is using lots of big @group commands, which
76982794Sobrien    % almost-but-not-quite fill up a page, TeX will have a hard time doing
77082794Sobrien    % good page breaking, for example.)  However, I could not construct an
77182794Sobrien    % example where a page broke at this \penalty; if it happens in a real
77282794Sobrien    % document, then we can reconsider our strategy.
77382794Sobrien    \penalty9999
77482794Sobrien    %
77582794Sobrien    % Back up by the size of the box, whether we did a page break or not.
77682794Sobrien    \kern -#1\mil
77782794Sobrien    %
77882794Sobrien    % Do not allow a page break right after this kern.
77982794Sobrien    \nobreak
78082794Sobrien  \fi
78138494Sobrien}
78238494Sobrien
783174294Sobrien% @br   forces paragraph break (and is undocumented).
78438494Sobrien
78538494Sobrien\let\br = \par
78638494Sobrien
787174294Sobrien% @page forces the start of a new page.
78842629Sobrien%
78938494Sobrien\def\page{\par\vfill\supereject}
79038494Sobrien
79138494Sobrien% @exdent text....
79238494Sobrien% outputs text on separate line in roman font, starting at standard page margin
79338494Sobrien
79438494Sobrien% This records the amount of indent in the innermost environment.
79538494Sobrien% That's how much \exdent should take out.
79638494Sobrien\newskip\exdentamount
79738494Sobrien
79838494Sobrien% This defn is used inside fill environments such as @defun.
799174294Sobrien\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
80038494Sobrien
80138494Sobrien% This defn is used inside nofill environments such as @example.
802174294Sobrien\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
803174294Sobrien  \leftline{\hskip\leftskip{\rm#1}}}}
80438494Sobrien
80582794Sobrien% @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
80682794Sobrien% paragraph.  For more general purposes, use the \margin insertion
80782794Sobrien% class.  WHICH is `l' or `r'.
80882794Sobrien%
80938494Sobrien\newskip\inmarginspacing \inmarginspacing=1cm
81038494Sobrien\def\strutdepth{\dp\strutbox}
81182794Sobrien%
81282794Sobrien\def\doinmargin#1#2{\strut\vadjust{%
81382794Sobrien  \nobreak
81482794Sobrien  \kern-\strutdepth
81582794Sobrien  \vtop to \strutdepth{%
81682794Sobrien    \baselineskip=\strutdepth
81782794Sobrien    \vss
81882794Sobrien    % if you have multiple lines of stuff to put here, you'll need to
81982794Sobrien    % make the vbox yourself of the appropriate size.
82082794Sobrien    \ifx#1l%
82182794Sobrien      \llap{\ignorespaces #2\hskip\inmarginspacing}%
82282794Sobrien    \else
82382794Sobrien      \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
82482794Sobrien    \fi
82582794Sobrien    \null
82682794Sobrien  }%
82782794Sobrien}}
82882794Sobrien\def\inleftmargin{\doinmargin l}
82982794Sobrien\def\inrightmargin{\doinmargin r}
83082794Sobrien%
83182794Sobrien% @inmargin{TEXT [, RIGHT-TEXT]}
83282794Sobrien% (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
83382794Sobrien% else use TEXT for both).
834174294Sobrien%
83582794Sobrien\def\inmargin#1{\parseinmargin #1,,\finish}
83682794Sobrien\def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
837174294Sobrien  \setbox0 = \hbox{\ignorespaces #2}%
83882794Sobrien  \ifdim\wd0 > 0pt
83982794Sobrien    \def\lefttext{#1}%  have both texts
84082794Sobrien    \def\righttext{#2}%
84182794Sobrien  \else
84282794Sobrien    \def\lefttext{#1}%  have only one text
84382794Sobrien    \def\righttext{#1}%
84482794Sobrien  \fi
84582794Sobrien  %
84682794Sobrien  \ifodd\pageno
84782794Sobrien    \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
84882794Sobrien  \else
84982794Sobrien    \def\temp{\inleftmargin\lefttext}%
85082794Sobrien  \fi
85182794Sobrien  \temp
85282794Sobrien}
85338494Sobrien
85438494Sobrien% @include file    insert text of that file as input.
855174294Sobrien%
856174294Sobrien\def\include{\parseargusing\filenamecatcodes\includezzz}
857174294Sobrien\def\includezzz#1{%
858174294Sobrien  \pushthisfilestack
85938494Sobrien  \def\thisfile{#1}%
860174294Sobrien  {%
861174294Sobrien    \makevalueexpandable
862174294Sobrien    \def\temp{\input #1 }%
863174294Sobrien    \expandafter
864174294Sobrien  }\temp
865174294Sobrien  \popthisfilestack
866174294Sobrien}
867174294Sobrien\def\filenamecatcodes{%
868174294Sobrien  \catcode`\\=\other
869174294Sobrien  \catcode`~=\other
870174294Sobrien  \catcode`^=\other
871174294Sobrien  \catcode`_=\other
872174294Sobrien  \catcode`|=\other
873174294Sobrien  \catcode`<=\other
874174294Sobrien  \catcode`>=\other
875174294Sobrien  \catcode`+=\other
876174294Sobrien  \catcode`-=\other
877174294Sobrien}
87838494Sobrien
879174294Sobrien\def\pushthisfilestack{%
880174294Sobrien  \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
881174294Sobrien}
882174294Sobrien\def\pushthisfilestackX{%
883174294Sobrien  \expandafter\pushthisfilestackY\thisfile\StackTerm
884174294Sobrien}
885174294Sobrien\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
886174294Sobrien  \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
887174294Sobrien}
888174294Sobrien
889174294Sobrien\def\popthisfilestack{\errthisfilestackempty}
890174294Sobrien\def\errthisfilestackempty{\errmessage{Internal error:
891174294Sobrien  the stack of filenames is empty.}}
892174294Sobrien
89338494Sobrien\def\thisfile{}
89438494Sobrien
895174294Sobrien% @center line
896174294Sobrien% outputs that line, centered.
897174294Sobrien%
898174294Sobrien\parseargdef\center{%
899174294Sobrien  \ifhmode
900174294Sobrien    \let\next\centerH
901174294Sobrien  \else
902174294Sobrien    \let\next\centerV
903174294Sobrien  \fi
904174294Sobrien  \next{\hfil \ignorespaces#1\unskip \hfil}%
905174294Sobrien}
906174294Sobrien\def\centerH#1{%
907174294Sobrien  {%
908174294Sobrien    \hfil\break
909174294Sobrien    \advance\hsize by -\leftskip
910174294Sobrien    \advance\hsize by -\rightskip
911174294Sobrien    \line{#1}%
912174294Sobrien    \break
913174294Sobrien  }%
914174294Sobrien}
915174294Sobrien\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}}
91638494Sobrien
91738494Sobrien% @sp n   outputs n lines of vertical space
91838494Sobrien
919174294Sobrien\parseargdef\sp{\vskip #1\baselineskip}
92038494Sobrien
92138494Sobrien% @comment ...line which is ignored...
92238494Sobrien% @c is the same as @comment
92338494Sobrien% @ignore ... @end ignore  is another way to write a comment
92438494Sobrien
92542629Sobrien\def\comment{\begingroup \catcode`\^^M=\other%
92642629Sobrien\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
92742629Sobrien\commentxxx}
92842629Sobrien{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}}
92938494Sobrien
93038494Sobrien\let\c=\comment
93138494Sobrien
93282794Sobrien% @paragraphindent NCHARS
93382794Sobrien% We'll use ems for NCHARS, close enough.
934174294Sobrien% NCHARS can also be the word `asis' or `none'.
935174294Sobrien% We cannot feasibly implement @paragraphindent asis, though.
936174294Sobrien%
93782794Sobrien\def\asisword{asis} % no translation, these are keywords
93882794Sobrien\def\noneword{none}
93938494Sobrien%
940174294Sobrien\parseargdef\paragraphindent{%
94182794Sobrien  \def\temp{#1}%
94282794Sobrien  \ifx\temp\asisword
94338494Sobrien  \else
94482794Sobrien    \ifx\temp\noneword
94582794Sobrien      \defaultparindent = 0pt
94682794Sobrien    \else
94782794Sobrien      \defaultparindent = #1em
94882794Sobrien    \fi
94938494Sobrien  \fi
95082794Sobrien  \parindent = \defaultparindent
95138494Sobrien}
95238494Sobrien
95382794Sobrien% @exampleindent NCHARS
95482794Sobrien% We'll use ems for NCHARS like @paragraphindent.
95582794Sobrien% It seems @exampleindent asis isn't necessary, but
95682794Sobrien% I preserve it to make it similar to @paragraphindent.
957174294Sobrien\parseargdef\exampleindent{%
95882794Sobrien  \def\temp{#1}%
95982794Sobrien  \ifx\temp\asisword
96038494Sobrien  \else
96182794Sobrien    \ifx\temp\noneword
96282794Sobrien      \lispnarrowing = 0pt
96382794Sobrien    \else
96482794Sobrien      \lispnarrowing = #1em
96582794Sobrien    \fi
96638494Sobrien  \fi
96738494Sobrien}
96838494Sobrien
969174294Sobrien% @firstparagraphindent WORD
970174294Sobrien% If WORD is `none', then suppress indentation of the first paragraph
971174294Sobrien% after a section heading.  If WORD is `insert', then do indent at such
972174294Sobrien% paragraphs.
973174294Sobrien%
974174294Sobrien% The paragraph indentation is suppressed or not by calling
975174294Sobrien% \suppressfirstparagraphindent, which the sectioning commands do.
976174294Sobrien% We switch the definition of this back and forth according to WORD.
977174294Sobrien% By default, we suppress indentation.
978174294Sobrien%
979174294Sobrien\def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
980174294Sobrien\def\insertword{insert}
981174294Sobrien%
982174294Sobrien\parseargdef\firstparagraphindent{%
983174294Sobrien  \def\temp{#1}%
984174294Sobrien  \ifx\temp\noneword
985174294Sobrien    \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
986174294Sobrien  \else\ifx\temp\insertword
987174294Sobrien    \let\suppressfirstparagraphindent = \relax
988174294Sobrien  \else
989174294Sobrien    \errhelp = \EMsimple
990174294Sobrien    \errmessage{Unknown @firstparagraphindent option `\temp'}%
991174294Sobrien  \fi\fi
992174294Sobrien}
993174294Sobrien
994174294Sobrien% Here is how we actually suppress indentation.  Redefine \everypar to
995174294Sobrien% \kern backwards by \parindent, and then reset itself to empty.
996174294Sobrien%
997174294Sobrien% We also make \indent itself not actually do anything until the next
998174294Sobrien% paragraph.
999174294Sobrien%
1000174294Sobrien\gdef\dosuppressfirstparagraphindent{%
1001174294Sobrien  \gdef\indent{%
1002174294Sobrien    \restorefirstparagraphindent
1003174294Sobrien    \indent
1004174294Sobrien  }%
1005174294Sobrien  \gdef\noindent{%
1006174294Sobrien    \restorefirstparagraphindent
1007174294Sobrien    \noindent
1008174294Sobrien  }%
1009174294Sobrien  \global\everypar = {%
1010174294Sobrien    \kern -\parindent
1011174294Sobrien    \restorefirstparagraphindent
1012174294Sobrien  }%
1013174294Sobrien}
1014174294Sobrien
1015174294Sobrien\gdef\restorefirstparagraphindent{%
1016174294Sobrien  \global \let \indent = \ptexindent
1017174294Sobrien  \global \let \noindent = \ptexnoindent
1018174294Sobrien  \global \everypar = {}%
1019174294Sobrien}
1020174294Sobrien
1021174294Sobrien
102238494Sobrien% @asis just yields its argument.  Used with @table, for example.
102338494Sobrien%
102438494Sobrien\def\asis#1{#1}
102538494Sobrien
1026119679Smbr% @math outputs its argument in math mode.
102738494Sobrien%
1028119679Smbr% One complication: _ usually means subscripts, but it could also mean
1029119679Smbr% an actual _ character, as in @math{@var{some_variable} + 1}.  So make
1030174294Sobrien% _ active, and distinguish by seeing if the current family is \slfam,
1031174294Sobrien% which is what @var uses.
1032174294Sobrien{
1033174294Sobrien  \catcode\underChar = \active
1034174294Sobrien  \gdef\mathunderscore{%
1035174294Sobrien    \catcode\underChar=\active
1036174294Sobrien    \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
1037174294Sobrien  }
1038174294Sobrien}
1039119679Smbr% Another complication: we want \\ (and @\) to output a \ character.
1040119679Smbr% FYI, plain.tex uses \\ as a temporary control sequence (why?), but
1041119679Smbr% this is not advertised and we don't care.  Texinfo does not
1042119679Smbr% otherwise define @\.
1043174294Sobrien%
1044119679Smbr% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
1045119679Smbr\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
1046119679Smbr%
1047119679Smbr\def\math{%
1048119679Smbr  \tex
1049174294Sobrien  \mathunderscore
1050119679Smbr  \let\\ = \mathbackslash
1051174294Sobrien  \mathactive
1052174294Sobrien  $\finishmath
1053174294Sobrien}
1054174294Sobrien\def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
105538494Sobrien
1056174294Sobrien% Some active characters (such as <) are spaced differently in math.
1057174294Sobrien% We have to reset their definitions in case the @math was an argument
1058174294Sobrien% to a command which sets the catcodes (such as @item or @section).
1059174294Sobrien%
1060174294Sobrien{
1061174294Sobrien  \catcode`^ = \active
1062174294Sobrien  \catcode`< = \active
1063174294Sobrien  \catcode`> = \active
1064174294Sobrien  \catcode`+ = \active
1065174294Sobrien  \gdef\mathactive{%
1066174294Sobrien    \let^ = \ptexhat
1067174294Sobrien    \let< = \ptexless
1068174294Sobrien    \let> = \ptexgtr
1069174294Sobrien    \let+ = \ptexplus
1070174294Sobrien  }
1071174294Sobrien}
1072174294Sobrien
107338494Sobrien% @bullet and @minus need the same treatment as @math, just above.
1074174294Sobrien\def\bullet{$\ptexbullet$}
1075174294Sobrien\def\minus{$-$}
107638494Sobrien
1077174294Sobrien% @dots{} outputs an ellipsis using the current font.
1078174294Sobrien% We do .5em per period so that it has the same spacing in a typewriter
1079174294Sobrien% font as three actual period characters.
1080174294Sobrien%
1081174294Sobrien\def\dots{%
1082174294Sobrien  \leavevmode
1083174294Sobrien  \hbox to 1.5em{%
1084174294Sobrien    \hskip 0pt plus 0.25fil
1085174294Sobrien    .\hfil.\hfil.%
1086174294Sobrien    \hskip 0pt plus 0.5fil
1087174294Sobrien  }%
1088174294Sobrien}
1089174294Sobrien
1090174294Sobrien% @enddots{} is an end-of-sentence ellipsis.
1091174294Sobrien%
1092174294Sobrien\def\enddots{%
1093174294Sobrien  \dots
1094174294Sobrien  \spacefactor=3000
1095174294Sobrien}
1096174294Sobrien
1097174294Sobrien% @comma{} is so commas can be inserted into text without messing up
1098174294Sobrien% Texinfo's parsing.
1099174294Sobrien%
1100174294Sobrien\let\comma = ,
1101174294Sobrien
110238494Sobrien% @refill is a no-op.
110338494Sobrien\let\refill=\relax
110438494Sobrien
110542629Sobrien% If working on a large document in chapters, it is convenient to
110642629Sobrien% be able to disable indexing, cross-referencing, and contents, for test runs.
110742629Sobrien% This is done with @novalidate (before @setfilename).
110842629Sobrien%
110942629Sobrien\newif\iflinks \linkstrue % by default we want the aux files.
111042629Sobrien\let\novalidate = \linksfalse
111142629Sobrien
111238494Sobrien% @setfilename is done at the beginning of every texinfo file.
111338494Sobrien% So open here the files we need to have open while reading the input.
111438494Sobrien% This makes it possible to make a .fmt file for texinfo.
111538494Sobrien\def\setfilename{%
1116174294Sobrien   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
111782794Sobrien   \iflinks
1118174294Sobrien     \tryauxfile
1119174294Sobrien     % Open the new aux file.  TeX will close it automatically at exit.
1120174294Sobrien     \immediate\openout\auxfile=\jobname.aux
112142629Sobrien   \fi % \openindices needs to do some work in any case.
112238494Sobrien   \openindices
1123174294Sobrien   \let\setfilename=\comment % Ignore extra @setfilename cmds.
112438494Sobrien   %
112538494Sobrien   % If texinfo.cnf is present on the system, read it.
112638494Sobrien   % Useful for site-wide @afourpaper, etc.
112738494Sobrien   \openin 1 texinfo.cnf
1128174294Sobrien   \ifeof 1 \else \input texinfo.cnf \fi
1129174294Sobrien   \closein 1
113038494Sobrien   %
113138494Sobrien   \comment % Ignore the actual filename.
113238494Sobrien}
113338494Sobrien
113442629Sobrien% Called from \setfilename.
113582794Sobrien%
113642629Sobrien\def\openindices{%
113742629Sobrien  \newindex{cp}%
113842629Sobrien  \newcodeindex{fn}%
113942629Sobrien  \newcodeindex{vr}%
114042629Sobrien  \newcodeindex{tp}%
114142629Sobrien  \newcodeindex{ky}%
114242629Sobrien  \newcodeindex{pg}%
114342629Sobrien}
114442629Sobrien
114538494Sobrien% @bye.
114638494Sobrien\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
114738494Sobrien
114838494Sobrien
114982794Sobrien\message{pdf,}
115082794Sobrien% adobe `portable' document format
115182794Sobrien\newcount\tempnum
115282794Sobrien\newcount\lnkcount
115382794Sobrien\newtoks\filename
115482794Sobrien\newcount\filenamelength
115582794Sobrien\newcount\pgn
115682794Sobrien\newtoks\toksA
115782794Sobrien\newtoks\toksB
115882794Sobrien\newtoks\toksC
115982794Sobrien\newtoks\toksD
116082794Sobrien\newbox\boxA
116182794Sobrien\newcount\countA
116282794Sobrien\newif\ifpdf
116382794Sobrien\newif\ifpdfmakepagedest
116482794Sobrien
1165174294Sobrien% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
1166174294Sobrien% can be set).  So we test for \relax and 0 as well as \undefined,
1167174294Sobrien% borrowed from ifpdf.sty.
116882794Sobrien\ifx\pdfoutput\undefined
116982794Sobrien\else
1170174294Sobrien  \ifx\pdfoutput\relax
1171174294Sobrien  \else
1172174294Sobrien    \ifcase\pdfoutput
1173174294Sobrien    \else
1174174294Sobrien      \pdftrue
1175174294Sobrien    \fi
1176174294Sobrien  \fi
1177174294Sobrien\fi
1178174294Sobrien%
1179174294Sobrien\ifpdf
118082794Sobrien  \input pdfcolor
1181174294Sobrien  \pdfcatalog{/PageMode /UseOutlines}%
118282794Sobrien  \def\dopdfimage#1#2#3{%
118382794Sobrien    \def\imagewidth{#2}%
118482794Sobrien    \def\imageheight{#3}%
1185119679Smbr    % without \immediate, pdftex seg faults when the same image is
1186119679Smbr    % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
118782794Sobrien    \ifnum\pdftexversion < 14
1188119679Smbr      \immediate\pdfimage
118982794Sobrien    \else
1190119679Smbr      \immediate\pdfximage
119182794Sobrien    \fi
119282794Sobrien      \ifx\empty\imagewidth\else width \imagewidth \fi
119382794Sobrien      \ifx\empty\imageheight\else height \imageheight \fi
119482794Sobrien      \ifnum\pdftexversion<13
1195174294Sobrien         #1.pdf%
119682794Sobrien       \else
119782794Sobrien         {#1.pdf}%
119882794Sobrien       \fi
119982794Sobrien    \ifnum\pdftexversion < 14 \else
120082794Sobrien      \pdfrefximage \pdflastximage
120182794Sobrien    \fi}
1202174294Sobrien  \def\pdfmkdest#1{{%
1203174294Sobrien    % We have to set dummies so commands such as @code in a section title
1204174294Sobrien    % aren't expanded.
1205174294Sobrien    \atdummies
1206174294Sobrien    \normalturnoffactive
1207174294Sobrien    \pdfdest name{#1} xyz%
1208174294Sobrien  }}
1209119679Smbr  \def\pdfmkpgn#1{#1}
121082794Sobrien  \let\linkcolor = \Blue  % was Cyan, but that seems light?
121182794Sobrien  \def\endlink{\Black\pdfendlink}
121282794Sobrien  % Adding outlines to PDF; macros for calculating structure of outlines
121382794Sobrien  % come from Petr Olsak
121482794Sobrien  \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
121582794Sobrien    \else \csname#1\endcsname \fi}
121682794Sobrien  \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
1217174294Sobrien    \advance\tempnum by 1
121882794Sobrien    \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
1219174294Sobrien  %
1220174294Sobrien  % #1 is the section text.  #2 is the pdf expression for the number
1221174294Sobrien  % of subentries (or empty, for subsubsections).  #3 is the node
1222174294Sobrien  % text, which might be empty if this toc entry had no
1223174294Sobrien  % corresponding node.  #4 is the page number.
1224174294Sobrien  %
1225174294Sobrien  \def\dopdfoutline#1#2#3#4{%
1226174294Sobrien    % Generate a link to the node text if that exists; else, use the
1227174294Sobrien    % page number.  We could generate a destination for the section
1228174294Sobrien    % text in the case where a section has no node, but it doesn't
1229174294Sobrien    % seem worthwhile, since most documents are normally structured.
1230174294Sobrien    \def\pdfoutlinedest{#3}%
1231174294Sobrien    \ifx\pdfoutlinedest\empty \def\pdfoutlinedest{#4}\fi
1232174294Sobrien    %
1233174294Sobrien    \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{#1}%
1234174294Sobrien  }
1235174294Sobrien  %
1236174294Sobrien  \def\pdfmakeoutlines{%
1237174294Sobrien    \begingroup
1238174294Sobrien      % Thanh's hack / proper braces in bookmarks
123982794Sobrien      \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
124082794Sobrien      \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
124182794Sobrien      %
1242174294Sobrien      % Read toc silently, to get counts of subentries for \pdfoutline.
1243174294Sobrien      \def\numchapentry##1##2##3##4{%
1244174294Sobrien	\def\thischapnum{##2}%
1245174294Sobrien	\let\thissecnum\empty
1246174294Sobrien	\let\thissubsecnum\empty
1247174294Sobrien      }%
1248174294Sobrien      \def\numsecentry##1##2##3##4{%
1249174294Sobrien	\advancenumber{chap\thischapnum}%
1250174294Sobrien	\def\thissecnum{##2}%
1251174294Sobrien	\let\thissubsecnum\empty
1252174294Sobrien      }%
1253174294Sobrien      \def\numsubsecentry##1##2##3##4{%
1254174294Sobrien	\advancenumber{sec\thissecnum}%
1255174294Sobrien	\def\thissubsecnum{##2}%
1256174294Sobrien      }%
1257174294Sobrien      \def\numsubsubsecentry##1##2##3##4{%
1258174294Sobrien	\advancenumber{subsec\thissubsecnum}%
1259174294Sobrien      }%
1260174294Sobrien      \let\thischapnum\empty
1261174294Sobrien      \let\thissecnum\empty
1262174294Sobrien      \let\thissubsecnum\empty
1263174294Sobrien      %
1264174294Sobrien      % use \def rather than \let here because we redefine \chapentry et
1265174294Sobrien      % al. a second time, below.
1266174294Sobrien      \def\appentry{\numchapentry}%
1267174294Sobrien      \def\appsecentry{\numsecentry}%
1268174294Sobrien      \def\appsubsecentry{\numsubsecentry}%
1269174294Sobrien      \def\appsubsubsecentry{\numsubsubsecentry}%
1270174294Sobrien      \def\unnchapentry{\numchapentry}%
1271174294Sobrien      \def\unnsecentry{\numsecentry}%
1272174294Sobrien      \def\unnsubsecentry{\numsubsecentry}%
1273174294Sobrien      \def\unnsubsubsecentry{\numsubsubsecentry}%
127482794Sobrien      \input \jobname.toc
1275174294Sobrien      %
1276174294Sobrien      % Read toc second time, this time actually producing the outlines.
1277174294Sobrien      % The `-' means take the \expnumber as the absolute number of
1278174294Sobrien      % subentries, which we calculated on our first read of the .toc above.
1279174294Sobrien      %
1280174294Sobrien      % We use the node names as the destinations.
1281174294Sobrien      \def\numchapentry##1##2##3##4{%
1282174294Sobrien        \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
1283174294Sobrien      \def\numsecentry##1##2##3##4{%
1284174294Sobrien        \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
1285174294Sobrien      \def\numsubsecentry##1##2##3##4{%
1286174294Sobrien        \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
1287174294Sobrien      \def\numsubsubsecentry##1##2##3##4{% count is always zero
1288174294Sobrien        \dopdfoutline{##1}{}{##3}{##4}}%
1289174294Sobrien      %
1290174294Sobrien      % PDF outlines are displayed using system fonts, instead of
1291174294Sobrien      % document fonts.  Therefore we cannot use special characters,
1292174294Sobrien      % since the encoding is unknown.  For example, the eogonek from
1293174294Sobrien      % Latin 2 (0xea) gets translated to a | character.  Info from
1294174294Sobrien      % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
1295174294Sobrien      %
1296174294Sobrien      % xx to do this right, we have to translate 8-bit characters to
1297174294Sobrien      % their "best" equivalent, based on the @documentencoding.  Right
1298174294Sobrien      % now, I guess we'll just let the pdf reader have its way.
1299174294Sobrien      \indexnofonts
1300174294Sobrien      \turnoffactive
130182794Sobrien      \input \jobname.toc
1302174294Sobrien    \endgroup
1303174294Sobrien  }
1304174294Sobrien  %
130582794Sobrien  \def\makelinks #1,{%
130682794Sobrien    \def\params{#1}\def\E{END}%
130782794Sobrien    \ifx\params\E
130882794Sobrien      \let\nextmakelinks=\relax
130982794Sobrien    \else
131082794Sobrien      \let\nextmakelinks=\makelinks
131182794Sobrien      \ifnum\lnkcount>0,\fi
131282794Sobrien      \picknum{#1}%
1313174294Sobrien      \startlink attr{/Border [0 0 0]}
131482794Sobrien        goto name{\pdfmkpgn{\the\pgn}}%
131582794Sobrien      \linkcolor #1%
131682794Sobrien      \advance\lnkcount by 1%
131782794Sobrien      \endlink
131882794Sobrien    \fi
131982794Sobrien    \nextmakelinks
132082794Sobrien  }
132182794Sobrien  \def\picknum#1{\expandafter\pn#1}
132282794Sobrien  \def\pn#1{%
132382794Sobrien    \def\p{#1}%
132482794Sobrien    \ifx\p\lbrace
132582794Sobrien      \let\nextpn=\ppn
132682794Sobrien    \else
132782794Sobrien      \let\nextpn=\ppnn
132882794Sobrien      \def\first{#1}
132982794Sobrien    \fi
133082794Sobrien    \nextpn
133182794Sobrien  }
133282794Sobrien  \def\ppn#1{\pgn=#1\gobble}
133382794Sobrien  \def\ppnn{\pgn=\first}
133482794Sobrien  \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
133582794Sobrien  \def\skipspaces#1{\def\PP{#1}\def\D{|}%
133682794Sobrien    \ifx\PP\D\let\nextsp\relax
133782794Sobrien    \else\let\nextsp\skipspaces
133882794Sobrien      \ifx\p\space\else\addtokens{\filename}{\PP}%
133982794Sobrien        \advance\filenamelength by 1
134082794Sobrien      \fi
134182794Sobrien    \fi
134282794Sobrien    \nextsp}
134382794Sobrien  \def\getfilename#1{\filenamelength=0\expandafter\skipspaces#1|\relax}
134482794Sobrien  \ifnum\pdftexversion < 14
134582794Sobrien    \let \startlink \pdfannotlink
134682794Sobrien  \else
134782794Sobrien    \let \startlink \pdfstartlink
134882794Sobrien  \fi
134982794Sobrien  \def\pdfurl#1{%
135082794Sobrien    \begingroup
135182794Sobrien      \normalturnoffactive\def\@{@}%
1352174294Sobrien      \makevalueexpandable
135382794Sobrien      \leavevmode\Red
135482794Sobrien      \startlink attr{/Border [0 0 0]}%
135582794Sobrien        user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
135682794Sobrien    \endgroup}
135782794Sobrien  \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
135882794Sobrien  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
135982794Sobrien  \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
136082794Sobrien  \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
136182794Sobrien  \def\maketoks{%
1362174294Sobrien    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
136382794Sobrien    \ifx\first0\adn0
136482794Sobrien    \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
136582794Sobrien    \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1366174294Sobrien    \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
136782794Sobrien    \else
136882794Sobrien      \ifnum0=\countA\else\makelink\fi
136982794Sobrien      \ifx\first.\let\next=\done\else
137082794Sobrien        \let\next=\maketoks
137182794Sobrien        \addtokens{\toksB}{\the\toksD}
137282794Sobrien        \ifx\first,\addtokens{\toksB}{\space}\fi
137382794Sobrien      \fi
137482794Sobrien    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
137582794Sobrien    \next}
137682794Sobrien  \def\makelink{\addtokens{\toksB}%
137782794Sobrien    {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
137882794Sobrien  \def\pdflink#1{%
137982794Sobrien    \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
138082794Sobrien    \linkcolor #1\endlink}
138182794Sobrien  \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1382174294Sobrien\else
1383174294Sobrien  \let\pdfmkdest = \gobble
1384174294Sobrien  \let\pdfurl = \gobble
1385174294Sobrien  \let\endlink = \relax
1386174294Sobrien  \let\linkcolor = \relax
1387174294Sobrien  \let\pdfmakeoutlines = \relax
1388174294Sobrien\fi  % \ifx\pdfoutput
138982794Sobrien
139082794Sobrien
139138494Sobrien\message{fonts,}
139238494Sobrien
1393174294Sobrien% Change the current font style to #1, remembering it in \curfontstyle.
1394174294Sobrien% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
1395174294Sobrien% italics, not bold italics.
1396174294Sobrien%
1397174294Sobrien\def\setfontstyle#1{%
1398174294Sobrien  \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
1399174294Sobrien  \csname ten#1\endcsname  % change the current font
1400174294Sobrien}
1401174294Sobrien
1402174294Sobrien% Select #1 fonts with the current style.
1403174294Sobrien%
1404174294Sobrien\def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
1405174294Sobrien
1406174294Sobrien\def\rm{\fam=0 \setfontstyle{rm}}
1407174294Sobrien\def\it{\fam=\itfam \setfontstyle{it}}
1408174294Sobrien\def\sl{\fam=\slfam \setfontstyle{sl}}
1409174294Sobrien\def\bf{\fam=\bffam \setfontstyle{bf}}
1410174294Sobrien\def\tt{\fam=\ttfam \setfontstyle{tt}}
1411174294Sobrien
141242629Sobrien% Texinfo sort of supports the sans serif font style, which plain TeX does not.
1413174294Sobrien% So we set up a \sf.
141438494Sobrien\newfam\sffam
1415174294Sobrien\def\sf{\fam=\sffam \setfontstyle{sf}}
141638494Sobrien\let\li = \sf % Sometimes we call it \li, not \sf.
141738494Sobrien
1418174294Sobrien% We don't need math for this font style.
1419174294Sobrien\def\ttsl{\setfontstyle{ttsl}}
142038494Sobrien
142182794Sobrien% Default leading.
142282794Sobrien\newdimen\textleading  \textleading = 13.2pt
142382794Sobrien
142482794Sobrien% Set the baselineskip to #1, and the lineskip and strut size
142582794Sobrien% correspondingly.  There is no deep meaning behind these magic numbers
142682794Sobrien% used as factors; they just match (closely enough) what Knuth defined.
142782794Sobrien%
142882794Sobrien\def\lineskipfactor{.08333}
142982794Sobrien\def\strutheightpercent{.70833}
143082794Sobrien\def\strutdepthpercent {.29167}
143182794Sobrien%
143282794Sobrien\def\setleading#1{%
143382794Sobrien  \normalbaselineskip = #1\relax
143482794Sobrien  \normallineskip = \lineskipfactor\normalbaselineskip
143582794Sobrien  \normalbaselines
143682794Sobrien  \setbox\strutbox =\hbox{%
143782794Sobrien    \vrule width0pt height\strutheightpercent\baselineskip
143882794Sobrien                    depth \strutdepthpercent \baselineskip
143982794Sobrien  }%
144082794Sobrien}
144182794Sobrien
144238494Sobrien% Set the font macro #1 to the font named #2, adding on the
144338494Sobrien% specified font prefix (normally `cm').
144438494Sobrien% #3 is the font's design size, #4 is a scale factor
144538494Sobrien\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4}
144638494Sobrien
144738494Sobrien% Use cm as the default font prefix.
144838494Sobrien% To specify the font prefix, you must define \fontprefix
144938494Sobrien% before you read in texinfo.tex.
145038494Sobrien\ifx\fontprefix\undefined
145138494Sobrien\def\fontprefix{cm}
145238494Sobrien\fi
145338494Sobrien% Support font families that don't use the same naming scheme as CM.
145438494Sobrien\def\rmshape{r}
145538494Sobrien\def\rmbshape{bx}               %where the normal face is bold
145638494Sobrien\def\bfshape{b}
145738494Sobrien\def\bxshape{bx}
145838494Sobrien\def\ttshape{tt}
145938494Sobrien\def\ttbshape{tt}
146038494Sobrien\def\ttslshape{sltt}
146138494Sobrien\def\itshape{ti}
146238494Sobrien\def\itbshape{bxti}
146338494Sobrien\def\slshape{sl}
146438494Sobrien\def\slbshape{bxsl}
146538494Sobrien\def\sfshape{ss}
146638494Sobrien\def\sfbshape{ss}
146738494Sobrien\def\scshape{csc}
146838494Sobrien\def\scbshape{csc}
146938494Sobrien
1470174294Sobrien% Text fonts (11.2pt, magstep1).
1471119679Smbr\newcount\mainmagstep
147238494Sobrien\ifx\bigger\relax
1473119679Smbr  % not really supported.
1474174294Sobrien  \mainmagstep=\magstep1
1475119679Smbr  \setfont\textrm\rmshape{12}{1000}
1476119679Smbr  \setfont\texttt\ttshape{12}{1000}
147738494Sobrien\else
1478119679Smbr  \mainmagstep=\magstephalf
1479119679Smbr  \setfont\textrm\rmshape{10}{\mainmagstep}
1480119679Smbr  \setfont\texttt\ttshape{10}{\mainmagstep}
148138494Sobrien\fi
148238494Sobrien\setfont\textbf\bfshape{10}{\mainmagstep}
148338494Sobrien\setfont\textit\itshape{10}{\mainmagstep}
148438494Sobrien\setfont\textsl\slshape{10}{\mainmagstep}
148538494Sobrien\setfont\textsf\sfshape{10}{\mainmagstep}
148638494Sobrien\setfont\textsc\scshape{10}{\mainmagstep}
148738494Sobrien\setfont\textttsl\ttslshape{10}{\mainmagstep}
148838494Sobrien\font\texti=cmmi10 scaled \mainmagstep
148938494Sobrien\font\textsy=cmsy10 scaled \mainmagstep
149038494Sobrien
1491174294Sobrien% A few fonts for @defun names and args.
1492174294Sobrien\setfont\defbf\bfshape{10}{\magstep1}
149338494Sobrien\setfont\deftt\ttshape{10}{\magstep1}
1494174294Sobrien\setfont\defttsl\ttslshape{10}{\magstep1}
1495174294Sobrien\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf}
149638494Sobrien
149782794Sobrien% Fonts for indices, footnotes, small examples (9pt).
149882794Sobrien\setfont\smallrm\rmshape{9}{1000}
149982794Sobrien\setfont\smalltt\ttshape{9}{1000}
150082794Sobrien\setfont\smallbf\bfshape{10}{900}
150182794Sobrien\setfont\smallit\itshape{9}{1000}
150282794Sobrien\setfont\smallsl\slshape{9}{1000}
150382794Sobrien\setfont\smallsf\sfshape{9}{1000}
150482794Sobrien\setfont\smallsc\scshape{10}{900}
150582794Sobrien\setfont\smallttsl\ttslshape{10}{900}
150682794Sobrien\font\smalli=cmmi9
150782794Sobrien\font\smallsy=cmsy9
150838494Sobrien
150982794Sobrien% Fonts for small examples (8pt).
151082794Sobrien\setfont\smallerrm\rmshape{8}{1000}
151182794Sobrien\setfont\smallertt\ttshape{8}{1000}
151282794Sobrien\setfont\smallerbf\bfshape{10}{800}
151382794Sobrien\setfont\smallerit\itshape{8}{1000}
151482794Sobrien\setfont\smallersl\slshape{8}{1000}
151582794Sobrien\setfont\smallersf\sfshape{8}{1000}
151682794Sobrien\setfont\smallersc\scshape{10}{800}
151782794Sobrien\setfont\smallerttsl\ttslshape{10}{800}
151882794Sobrien\font\smalleri=cmmi8
151982794Sobrien\font\smallersy=cmsy8
152082794Sobrien
1521174294Sobrien% Fonts for title page (20.4pt):
152238494Sobrien\setfont\titlerm\rmbshape{12}{\magstep3}
152338494Sobrien\setfont\titleit\itbshape{10}{\magstep4}
152438494Sobrien\setfont\titlesl\slbshape{10}{\magstep4}
152538494Sobrien\setfont\titlett\ttbshape{12}{\magstep3}
152638494Sobrien\setfont\titlettsl\ttslshape{10}{\magstep4}
152738494Sobrien\setfont\titlesf\sfbshape{17}{\magstep1}
152838494Sobrien\let\titlebf=\titlerm
152938494Sobrien\setfont\titlesc\scbshape{10}{\magstep4}
153038494Sobrien\font\titlei=cmmi12 scaled \magstep3
153138494Sobrien\font\titlesy=cmsy10 scaled \magstep4
153238494Sobrien\def\authorrm{\secrm}
1533174294Sobrien\def\authortt{\sectt}
153438494Sobrien
153538494Sobrien% Chapter (and unnumbered) fonts (17.28pt).
153638494Sobrien\setfont\chaprm\rmbshape{12}{\magstep2}
153738494Sobrien\setfont\chapit\itbshape{10}{\magstep3}
153838494Sobrien\setfont\chapsl\slbshape{10}{\magstep3}
153938494Sobrien\setfont\chaptt\ttbshape{12}{\magstep2}
154038494Sobrien\setfont\chapttsl\ttslshape{10}{\magstep3}
154138494Sobrien\setfont\chapsf\sfbshape{17}{1000}
154238494Sobrien\let\chapbf=\chaprm
154338494Sobrien\setfont\chapsc\scbshape{10}{\magstep3}
154438494Sobrien\font\chapi=cmmi12 scaled \magstep2
154538494Sobrien\font\chapsy=cmsy10 scaled \magstep3
154638494Sobrien
154738494Sobrien% Section fonts (14.4pt).
154838494Sobrien\setfont\secrm\rmbshape{12}{\magstep1}
154938494Sobrien\setfont\secit\itbshape{10}{\magstep2}
155038494Sobrien\setfont\secsl\slbshape{10}{\magstep2}
155138494Sobrien\setfont\sectt\ttbshape{12}{\magstep1}
155238494Sobrien\setfont\secttsl\ttslshape{10}{\magstep2}
155338494Sobrien\setfont\secsf\sfbshape{12}{\magstep1}
155438494Sobrien\let\secbf\secrm
155538494Sobrien\setfont\secsc\scbshape{10}{\magstep2}
155638494Sobrien\font\seci=cmmi12 scaled \magstep1
155738494Sobrien\font\secsy=cmsy10 scaled \magstep2
155838494Sobrien
155938494Sobrien% Subsection fonts (13.15pt).
156038494Sobrien\setfont\ssecrm\rmbshape{12}{\magstephalf}
156138494Sobrien\setfont\ssecit\itbshape{10}{1315}
156238494Sobrien\setfont\ssecsl\slbshape{10}{1315}
156338494Sobrien\setfont\ssectt\ttbshape{12}{\magstephalf}
156438494Sobrien\setfont\ssecttsl\ttslshape{10}{1315}
156538494Sobrien\setfont\ssecsf\sfbshape{12}{\magstephalf}
156638494Sobrien\let\ssecbf\ssecrm
1567174294Sobrien\setfont\ssecsc\scbshape{10}{1315}
156838494Sobrien\font\sseci=cmmi12 scaled \magstephalf
156938494Sobrien\font\ssecsy=cmsy10 scaled 1315
157038494Sobrien
1571174294Sobrien% Reduced fonts for @acro in text (10pt).
1572174294Sobrien\setfont\reducedrm\rmshape{10}{1000}
1573174294Sobrien\setfont\reducedtt\ttshape{10}{1000}
1574174294Sobrien\setfont\reducedbf\bfshape{10}{1000}
1575174294Sobrien\setfont\reducedit\itshape{10}{1000}
1576174294Sobrien\setfont\reducedsl\slshape{10}{1000}
1577174294Sobrien\setfont\reducedsf\sfshape{10}{1000}
1578174294Sobrien\setfont\reducedsc\scshape{10}{1000}
1579174294Sobrien\setfont\reducedttsl\ttslshape{10}{1000}
1580174294Sobrien\font\reducedi=cmmi10
1581174294Sobrien\font\reducedsy=cmsy10
1582174294Sobrien
158338494Sobrien% In order for the font changes to affect most math symbols and letters,
158438494Sobrien% we have to define the \textfont of the standard families.  Since
1585119679Smbr% texinfo doesn't allow for producing subscripts and superscripts except
1586119679Smbr% in the main text, we don't bother to reset \scriptfont and
1587119679Smbr% \scriptscriptfont (which would also require loading a lot more fonts).
158838494Sobrien%
158938494Sobrien\def\resetmathfonts{%
1590119679Smbr  \textfont0=\tenrm \textfont1=\teni \textfont2=\tensy
1591119679Smbr  \textfont\itfam=\tenit \textfont\slfam=\tensl \textfont\bffam=\tenbf
1592119679Smbr  \textfont\ttfam=\tentt \textfont\sffam=\tensf
159338494Sobrien}
159438494Sobrien
159538494Sobrien% The font-changing commands redefine the meanings of \tenSTYLE, instead
1596174294Sobrien% of just \STYLE.  We do this because \STYLE needs to also set the
1597174294Sobrien% current \fam for math mode.  Our \STYLE (e.g., \rm) commands hardwire
1598174294Sobrien% \tenSTYLE to set the current font.
1599174294Sobrien%
1600174294Sobrien% Each font-changing command also sets the names \lsize (one size lower)
1601174294Sobrien% and \lllsize (three sizes lower).  These relative commands are used in
1602174294Sobrien% the LaTeX logo and acronyms.
1603174294Sobrien%
1604174294Sobrien% This all needs generalizing, badly.
1605174294Sobrien%
160638494Sobrien\def\textfonts{%
160738494Sobrien  \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
160838494Sobrien  \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
1609174294Sobrien  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
1610174294Sobrien  \let\tenttsl=\textttsl
1611174294Sobrien  \def\lsize{reduced}\def\lllsize{smaller}%
161282794Sobrien  \resetmathfonts \setleading{\textleading}}
161338494Sobrien\def\titlefonts{%
161438494Sobrien  \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
161538494Sobrien  \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
161638494Sobrien  \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
161738494Sobrien  \let\tenttsl=\titlettsl
1618174294Sobrien  \def\lsize{chap}\def\lllsize{subsec}%
161938494Sobrien  \resetmathfonts \setleading{25pt}}
162042629Sobrien\def\titlefont#1{{\titlefonts\rm #1}}
162138494Sobrien\def\chapfonts{%
162238494Sobrien  \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
162338494Sobrien  \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
162438494Sobrien  \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
1625174294Sobrien  \def\lsize{sec}\def\lllsize{text}%
162638494Sobrien  \resetmathfonts \setleading{19pt}}
162738494Sobrien\def\secfonts{%
162838494Sobrien  \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
162938494Sobrien  \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
1630174294Sobrien  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
1631174294Sobrien  \let\tenttsl=\secttsl
1632174294Sobrien  \def\lsize{subsec}\def\lllsize{reduced}%
163338494Sobrien  \resetmathfonts \setleading{16pt}}
163438494Sobrien\def\subsecfonts{%
163538494Sobrien  \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
163638494Sobrien  \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
1637174294Sobrien  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
1638174294Sobrien  \let\tenttsl=\ssecttsl
1639174294Sobrien  \def\lsize{text}\def\lllsize{small}%
164038494Sobrien  \resetmathfonts \setleading{15pt}}
1641174294Sobrien\let\subsubsecfonts = \subsecfonts
1642174294Sobrien\def\reducedfonts{%
1643174294Sobrien  \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
1644174294Sobrien  \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
1645174294Sobrien  \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
1646174294Sobrien  \let\tenttsl=\reducedttsl
1647174294Sobrien  \def\lsize{small}\def\lllsize{smaller}%
1648174294Sobrien  \resetmathfonts \setleading{10.5pt}}
164982794Sobrien\def\smallfonts{%
165082794Sobrien  \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
165182794Sobrien  \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
165282794Sobrien  \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
165382794Sobrien  \let\tenttsl=\smallttsl
1654174294Sobrien  \def\lsize{smaller}\def\lllsize{smaller}%
165582794Sobrien  \resetmathfonts \setleading{10.5pt}}
165682794Sobrien\def\smallerfonts{%
165782794Sobrien  \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
165882794Sobrien  \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
165982794Sobrien  \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
166082794Sobrien  \let\tenttsl=\smallerttsl
1661174294Sobrien  \def\lsize{smaller}\def\lllsize{smaller}%
166282794Sobrien  \resetmathfonts \setleading{9.5pt}}
166338494Sobrien
1664174294Sobrien% Set the fonts to use with the @small... environments.
1665174294Sobrien\let\smallexamplefonts = \smallfonts
1666174294Sobrien
1667174294Sobrien% About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
1668174294Sobrien% can fit this many characters:
1669174294Sobrien%   8.5x11=86   smallbook=72  a4=90  a5=69
1670174294Sobrien% If we use \scriptfonts (8pt), then we can fit this many characters:
1671174294Sobrien%   8.5x11=90+  smallbook=80  a4=90+  a5=77
1672174294Sobrien% For me, subjectively, the few extra characters that fit aren't worth
1673174294Sobrien% the additional smallness of 8pt.  So I'm making the default 9pt.
1674174294Sobrien%
1675174294Sobrien% By the way, for comparison, here's what fits with @example (10pt):
1676174294Sobrien%   8.5x11=71  smallbook=60  a4=75  a5=58
1677174294Sobrien%
1678174294Sobrien% I wish the USA used A4 paper.
1679174294Sobrien% --karl, 24jan03.
1680174294Sobrien
1681174294Sobrien
168238494Sobrien% Set up the default fonts, so we can use them for creating boxes.
168338494Sobrien%
1684174294Sobrien\textfonts \rm
168538494Sobrien
168642629Sobrien% Define these so they can be easily changed for other fonts.
168742629Sobrien\def\angleleft{$\langle$}
168842629Sobrien\def\angleright{$\rangle$}
168942629Sobrien
169038494Sobrien% Count depth in font-changes, for error checks
169138494Sobrien\newcount\fontdepth \fontdepth=0
169238494Sobrien
169338494Sobrien% Fonts for short table of contents.
169438494Sobrien\setfont\shortcontrm\rmshape{12}{1000}
1695174294Sobrien\setfont\shortcontbf\bfshape{10}{\magstep1}  % no cmb12
169638494Sobrien\setfont\shortcontsl\slshape{12}{1000}
1697174294Sobrien\setfont\shortconttt\ttshape{12}{1000}
169838494Sobrien
169938494Sobrien%% Add scribe-like font environments, plus @l for inline lisp (usually sans
170038494Sobrien%% serif) and @ii for TeX italic
170138494Sobrien
170238494Sobrien% \smartitalic{ARG} outputs arg in italics, followed by an italic correction
170338494Sobrien% unless the following character is such as not to need one.
1704174294Sobrien\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else
1705174294Sobrien                    \ptexslash\fi\fi\fi}
1706174294Sobrien\def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx}
1707174294Sobrien\def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx}
170838494Sobrien
1709174294Sobrien% like \smartslanted except unconditionally uses \ttsl.
1710174294Sobrien% @var is set to this for defun arguments.
1711174294Sobrien\def\ttslanted#1{{\ttsl #1}\futurelet\next\smartitalicx}
1712174294Sobrien
1713174294Sobrien% like \smartslanted except unconditionally use \sl.  We never want
1714174294Sobrien% ttsl for book titles, do we?
1715174294Sobrien\def\cite#1{{\sl #1}\futurelet\next\smartitalicx}
1716174294Sobrien
171738494Sobrien\let\i=\smartitalic
1718174294Sobrien\let\slanted=\smartslanted
171942629Sobrien\let\var=\smartslanted
172042629Sobrien\let\dfn=\smartslanted
172138494Sobrien\let\emph=\smartitalic
172238494Sobrien
172338494Sobrien\def\b#1{{\bf #1}}
172438494Sobrien\let\strong=\b
172538494Sobrien
172638494Sobrien% We can't just use \exhyphenpenalty, because that only has effect at
172738494Sobrien% the end of a paragraph.  Restore normal hyphenation at the end of the
172838494Sobrien% group within which \nohyphenation is presumably called.
172938494Sobrien%
173038494Sobrien\def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
173138494Sobrien\def\restorehyphenation{\hyphenchar\font = `- }
173238494Sobrien
1733174294Sobrien% Set sfcode to normal for the chars that usually have another value.
1734174294Sobrien% Can't use plain's \frenchspacing because it uses the `\x notation, and
1735174294Sobrien% sometimes \x has an active definition that messes things up.
1736174294Sobrien%
1737174294Sobrien\catcode`@=11
1738174294Sobrien  \def\frenchspacing{%
1739174294Sobrien    \sfcode\dotChar  =\@m \sfcode\questChar=\@m \sfcode\exclamChar=\@m
1740174294Sobrien    \sfcode\colonChar=\@m \sfcode\semiChar =\@m \sfcode\commaChar =\@m
1741174294Sobrien  }
1742174294Sobrien\catcode`@=\other
1743174294Sobrien
174438494Sobrien\def\t#1{%
174538494Sobrien  {\tt \rawbackslash \frenchspacing #1}%
174638494Sobrien  \null
174738494Sobrien}
174842629Sobrien\def\samp#1{`\tclose{#1}'\null}
174982794Sobrien\setfont\keyrm\rmshape{8}{1000}
175082794Sobrien\font\keysy=cmsy9
175182794Sobrien\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
175242629Sobrien  \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
175338494Sobrien    \vbox{\hrule\kern-0.4pt
175442629Sobrien     \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
175538494Sobrien    \kern-0.4pt\hrule}%
175642629Sobrien  \kern-.06em\raise0.4pt\hbox{\angleright}}}}
175738494Sobrien% The old definition, with no lozenge:
175838494Sobrien%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null}
175938494Sobrien\def\ctrl #1{{\tt \rawbackslash \hat}#1}
176038494Sobrien
176142629Sobrien% @file, @option are the same as @samp.
176238494Sobrien\let\file=\samp
176342629Sobrien\let\option=\samp
176438494Sobrien
176538494Sobrien% @code is a modification of @t,
176638494Sobrien% which makes spaces the same size as normal in the surrounding text.
176738494Sobrien\def\tclose#1{%
176838494Sobrien  {%
176938494Sobrien    % Change normal interword space to be same as for the current font.
177038494Sobrien    \spaceskip = \fontdimen2\font
177138494Sobrien    %
177238494Sobrien    % Switch to typewriter.
177338494Sobrien    \tt
177438494Sobrien    %
177538494Sobrien    % But `\ ' produces the large typewriter interword space.
177638494Sobrien    \def\ {{\spaceskip = 0pt{} }}%
177738494Sobrien    %
177838494Sobrien    % Turn off hyphenation.
177938494Sobrien    \nohyphenation
178038494Sobrien    %
178138494Sobrien    \rawbackslash
178238494Sobrien    \frenchspacing
178338494Sobrien    #1%
178438494Sobrien  }%
178538494Sobrien  \null
178638494Sobrien}
178738494Sobrien
1788174294Sobrien% We *must* turn on hyphenation at `-' and `_' in @code.
178938494Sobrien% Otherwise, it is too hard to avoid overfull hboxes
179038494Sobrien% in the Emacs manual, the Library manual, etc.
179138494Sobrien
179238494Sobrien% Unfortunately, TeX uses one parameter (\hyphenchar) to control
179338494Sobrien% both hyphenation at - and hyphenation within words.
179438494Sobrien% We must therefore turn them both off (\tclose does that)
179538494Sobrien% and arrange explicitly to hyphenate at a dash.
179638494Sobrien%  -- rms.
179738494Sobrien{
179842629Sobrien  \catcode`\-=\active
179942629Sobrien  \catcode`\_=\active
180042629Sobrien  %
180142629Sobrien  \global\def\code{\begingroup
180242629Sobrien    \catcode`\-=\active \let-\codedash
180342629Sobrien    \catcode`\_=\active \let_\codeunder
180442629Sobrien    \codex
180542629Sobrien  }
180638494Sobrien}
180738494Sobrien
180838494Sobrien\def\realdash{-}
180938494Sobrien\def\codedash{-\discretionary{}{}{}}
1810119679Smbr\def\codeunder{%
1811119679Smbr  % this is all so @math{@code{var_name}+1} can work.  In math mode, _
1812119679Smbr  % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
1813119679Smbr  % will therefore expand the active definition of _, which is us
1814119679Smbr  % (inside @code that is), therefore an endless loop.
1815119679Smbr  \ifusingtt{\ifmmode
1816119679Smbr               \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
1817119679Smbr             \else\normalunderscore \fi
1818119679Smbr             \discretionary{}{}{}}%
1819119679Smbr            {\_}%
1820119679Smbr}
182138494Sobrien\def\codex #1{\tclose{#1}\endgroup}
182238494Sobrien
182338494Sobrien% @kbd is like @code, except that if the argument is just one @key command,
182438494Sobrien% then @kbd has no effect.
182538494Sobrien
182638494Sobrien% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
182738494Sobrien%   `example' (@kbd uses ttsl only inside of @example and friends),
182838494Sobrien%   or `code' (@kbd uses normal tty font always).
1829174294Sobrien\parseargdef\kbdinputstyle{%
183038494Sobrien  \def\arg{#1}%
183138494Sobrien  \ifx\arg\worddistinct
183238494Sobrien    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
183338494Sobrien  \else\ifx\arg\wordexample
183438494Sobrien    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
183538494Sobrien  \else\ifx\arg\wordcode
183638494Sobrien    \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
1837174294Sobrien  \else
1838174294Sobrien    \errhelp = \EMsimple
1839174294Sobrien    \errmessage{Unknown @kbdinputstyle option `\arg'}%
184038494Sobrien  \fi\fi\fi
184138494Sobrien}
184238494Sobrien\def\worddistinct{distinct}
184338494Sobrien\def\wordexample{example}
184438494Sobrien\def\wordcode{code}
184538494Sobrien
1846174294Sobrien% Default is `distinct.'
1847174294Sobrien\kbdinputstyle distinct
184838494Sobrien
184938494Sobrien\def\xkey{\key}
185038494Sobrien\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}%
185138494Sobrien\ifx\one\xkey\ifx\threex\three \key{#2}%
185238494Sobrien\else{\tclose{\kbdfont\look}}\fi
185338494Sobrien\else{\tclose{\kbdfont\look}}\fi}
185438494Sobrien
1855174294Sobrien% For @indicateurl, @env, @command quotes seem unnecessary, so use \code.
1856174294Sobrien\let\indicateurl=\code
185742629Sobrien\let\env=\code
185842629Sobrien\let\command=\code
185938494Sobrien
186082794Sobrien% @uref (abbreviation for `urlref') takes an optional (comma-separated)
186182794Sobrien% second argument specifying the text to display and an optional third
186282794Sobrien% arg as text to display instead of (rather than in addition to) the url
186382794Sobrien% itself.  First (mandatory) arg is the url.  Perhaps eventually put in
186482794Sobrien% a hypertex \special here.
186582794Sobrien%
186682794Sobrien\def\uref#1{\douref #1,,,\finish}
186782794Sobrien\def\douref#1,#2,#3,#4\finish{\begingroup
186882794Sobrien  \unsepspaces
186982794Sobrien  \pdfurl{#1}%
187082794Sobrien  \setbox0 = \hbox{\ignorespaces #3}%
187138494Sobrien  \ifdim\wd0 > 0pt
187282794Sobrien    \unhbox0 % third arg given, show only that
187338494Sobrien  \else
187482794Sobrien    \setbox0 = \hbox{\ignorespaces #2}%
187582794Sobrien    \ifdim\wd0 > 0pt
187682794Sobrien      \ifpdf
187782794Sobrien        \unhbox0             % PDF: 2nd arg given, show only it
187882794Sobrien      \else
187982794Sobrien        \unhbox0\ (\code{#1})% DVI: 2nd arg given, show both it and url
188082794Sobrien      \fi
188182794Sobrien    \else
188282794Sobrien      \code{#1}% only url given, so show it
188382794Sobrien    \fi
188438494Sobrien  \fi
188582794Sobrien  \endlink
188682794Sobrien\endgroup}
188738494Sobrien
1888174294Sobrien% @url synonym for @uref, since that's how everyone uses it.
1889174294Sobrien%
1890174294Sobrien\let\url=\uref
1891174294Sobrien
189282794Sobrien% rms does not like angle brackets --karl, 17may97.
189382794Sobrien% So now @email is just like @uref, unless we are pdf.
1894174294Sobrien%
189542629Sobrien%\def\email#1{\angleleft{\tt #1}\angleright}
189682794Sobrien\ifpdf
189782794Sobrien  \def\email#1{\doemail#1,,\finish}
189882794Sobrien  \def\doemail#1,#2,#3\finish{\begingroup
189982794Sobrien    \unsepspaces
190082794Sobrien    \pdfurl{mailto:#1}%
190182794Sobrien    \setbox0 = \hbox{\ignorespaces #2}%
190282794Sobrien    \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
190382794Sobrien    \endlink
190482794Sobrien  \endgroup}
190582794Sobrien\else
190682794Sobrien  \let\email=\uref
190782794Sobrien\fi
190838494Sobrien
190938494Sobrien% Check if we are currently using a typewriter font.  Since all the
191038494Sobrien% Computer Modern typewriter fonts have zero interword stretch (and
191138494Sobrien% shrink), and it is reasonable to expect all typewriter fonts to have
191238494Sobrien% this property, we can check that font parameter.
191338494Sobrien%
191438494Sobrien\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
191538494Sobrien
191638494Sobrien% Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
191742629Sobrien% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
191838494Sobrien%
191938494Sobrien\def\dmn#1{\thinspace #1}
192038494Sobrien
192138494Sobrien\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par}
192238494Sobrien
192338494Sobrien% @l was never documented to mean ``switch to the Lisp font'',
192438494Sobrien% and it is not used as such in any manual I can find.  We need it for
192538494Sobrien% Polish suppressed-l.  --karl, 22sep96.
192638494Sobrien%\def\l#1{{\li #1}\null}
192738494Sobrien
192842629Sobrien% Explicit font changes: @r, @sc, undocumented @ii.
192938494Sobrien\def\r#1{{\rm #1}}              % roman font
193038494Sobrien\def\sc#1{{\smallcaps#1}}       % smallcaps font
193138494Sobrien\def\ii#1{{\it #1}}             % italic font
193238494Sobrien
1933174294Sobrien% @acronym for "FBI", "NATO", and the like.
1934174294Sobrien% We print this one point size smaller, since it's intended for
1935174294Sobrien% all-uppercase.
1936174294Sobrien% 
1937174294Sobrien\def\acronym#1{\doacronym #1,,\finish}
1938174294Sobrien\def\doacronym#1,#2,#3\finish{%
1939174294Sobrien  {\selectfonts\lsize #1}%
1940174294Sobrien  \def\temp{#2}%
1941174294Sobrien  \ifx\temp\empty \else
1942174294Sobrien    \space ({\unsepspaces \ignorespaces \temp \unskip})%
1943174294Sobrien  \fi
1944174294Sobrien}
194542629Sobrien
1946174294Sobrien% @abbr for "Comput. J." and the like.
1947174294Sobrien% No font change, but don't do end-of-sentence spacing.
1948174294Sobrien% 
1949174294Sobrien\def\abbr#1{\doabbr #1,,\finish}
1950174294Sobrien\def\doabbr#1,#2,#3\finish{%
1951174294Sobrien  {\frenchspacing #1}%
1952174294Sobrien  \def\temp{#2}%
1953174294Sobrien  \ifx\temp\empty \else
1954174294Sobrien    \space ({\unsepspaces \ignorespaces \temp \unskip})%
1955174294Sobrien  \fi
1956174294Sobrien}
1957174294Sobrien
1958174294Sobrien% @pounds{} is a sterling sign, which Knuth put in the CM italic font.
1959174294Sobrien%
196038494Sobrien\def\pounds{{\it\$}}
196138494Sobrien
1962174294Sobrien% @registeredsymbol - R in a circle.  The font for the R should really
1963174294Sobrien% be smaller yet, but lllsize is the best we can do for now.
1964174294Sobrien% Adapted from the plain.tex definition of \copyright.
1965174294Sobrien%
1966174294Sobrien\def\registeredsymbol{%
1967174294Sobrien  $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
1968174294Sobrien               \hfil\crcr\Orb}}%
1969174294Sobrien    }$%
1970174294Sobrien}
197138494Sobrien
1972174294Sobrien% Laurent Siebenmann reports \Orb undefined with:
1973174294Sobrien%  Textures 1.7.7 (preloaded format=plain 93.10.14)  (68K)  16 APR 2004 02:38
1974174294Sobrien% so we'll define it if necessary.
1975174294Sobrien% 
1976174294Sobrien\ifx\Orb\undefined
1977174294Sobrien\def\Orb{\mathhexbox20D}
1978174294Sobrien\fi
1979174294Sobrien
1980174294Sobrien
198138494Sobrien\message{page headings,}
198238494Sobrien
198338494Sobrien\newskip\titlepagetopglue \titlepagetopglue = 1.5in
198438494Sobrien\newskip\titlepagebottomglue \titlepagebottomglue = 2pc
198538494Sobrien
198638494Sobrien% First the title page.  Must do @settitle before @titlepage.
198738494Sobrien\newif\ifseenauthor
198838494Sobrien\newif\iffinishedtitlepage
198938494Sobrien
199042629Sobrien% Do an implicit @contents or @shortcontents after @end titlepage if the
199182794Sobrien% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage.
199282794Sobrien%
199342629Sobrien\newif\ifsetcontentsaftertitlepage
199442629Sobrien \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue
199542629Sobrien\newif\ifsetshortcontentsaftertitlepage
199642629Sobrien \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
199742629Sobrien
1998174294Sobrien\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
199938494Sobrien        \endgroup\page\hbox{}\page}
200038494Sobrien
2001174294Sobrien\envdef\titlepage{%
2002174294Sobrien  % Open one extra group, as we want to close it in the middle of \Etitlepage.
2003174294Sobrien  \begingroup
2004174294Sobrien    \parindent=0pt \textfonts
2005174294Sobrien    % Leave some space at the very top of the page.
2006174294Sobrien    \vglue\titlepagetopglue
2007174294Sobrien    % No rule at page bottom unless we print one at the top with @title.
2008174294Sobrien    \finishedtitlepagetrue
2009174294Sobrien    %
2010174294Sobrien    % Most title ``pages'' are actually two pages long, with space
2011174294Sobrien    % at the top of the second.  We don't want the ragged left on the second.
2012174294Sobrien    \let\oldpage = \page
2013174294Sobrien    \def\page{%
201438494Sobrien      \iffinishedtitlepage\else
2015174294Sobrien	 \finishtitlepage
201638494Sobrien      \fi
201738494Sobrien      \let\page = \oldpage
2018174294Sobrien      \page
2019174294Sobrien      \null
2020174294Sobrien    }%
202138494Sobrien}
202238494Sobrien
202338494Sobrien\def\Etitlepage{%
2024174294Sobrien    \iffinishedtitlepage\else
2025174294Sobrien	\finishtitlepage
2026174294Sobrien    \fi
2027174294Sobrien    % It is important to do the page break before ending the group,
2028174294Sobrien    % because the headline and footline are only empty inside the group.
2029174294Sobrien    % If we use the new definition of \page, we always get a blank page
2030174294Sobrien    % after the title page, which we certainly don't want.
2031174294Sobrien    \oldpage
2032174294Sobrien  \endgroup
2033174294Sobrien  %
2034174294Sobrien  % Need this before the \...aftertitlepage checks so that if they are
2035174294Sobrien  % in effect the toc pages will come out with page numbers.
2036174294Sobrien  \HEADINGSon
2037174294Sobrien  %
2038174294Sobrien  % If they want short, they certainly want long too.
2039174294Sobrien  \ifsetshortcontentsaftertitlepage
2040174294Sobrien    \shortcontents
2041174294Sobrien    \contents
2042174294Sobrien    \global\let\shortcontents = \relax
2043174294Sobrien    \global\let\contents = \relax
2044174294Sobrien  \fi
2045174294Sobrien  %
2046174294Sobrien  \ifsetcontentsaftertitlepage
2047174294Sobrien    \contents
2048174294Sobrien    \global\let\contents = \relax
2049174294Sobrien    \global\let\shortcontents = \relax
2050174294Sobrien  \fi
205138494Sobrien}
205238494Sobrien
205338494Sobrien\def\finishtitlepage{%
2054174294Sobrien  \vskip4pt \hrule height 2pt width \hsize
2055174294Sobrien  \vskip\titlepagebottomglue
2056174294Sobrien  \finishedtitlepagetrue
205738494Sobrien}
205838494Sobrien
2059174294Sobrien%%% Macros to be used within @titlepage:
2060174294Sobrien
2061174294Sobrien\let\subtitlerm=\tenrm
2062174294Sobrien\def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
2063174294Sobrien
2064174294Sobrien\def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
2065174294Sobrien		\let\tt=\authortt}
2066174294Sobrien
2067174294Sobrien\parseargdef\title{%
2068174294Sobrien  \checkenv\titlepage
2069174294Sobrien  \leftline{\titlefonts\rm #1}
2070174294Sobrien  % print a rule at the page bottom also.
2071174294Sobrien  \finishedtitlepagefalse
2072174294Sobrien  \vskip4pt \hrule height 4pt width \hsize \vskip4pt
2073174294Sobrien}
2074174294Sobrien
2075174294Sobrien\parseargdef\subtitle{%
2076174294Sobrien  \checkenv\titlepage
2077174294Sobrien  {\subtitlefont \rightline{#1}}%
2078174294Sobrien}
2079174294Sobrien
2080174294Sobrien% @author should come last, but may come many times.
2081174294Sobrien% It can also be used inside @quotation.
2082174294Sobrien%
2083174294Sobrien\parseargdef\author{%
2084174294Sobrien  \def\temp{\quotation}%
2085174294Sobrien  \ifx\thisenv\temp
2086174294Sobrien    \def\quotationauthor{#1}% printed in \Equotation.
2087174294Sobrien  \else
2088174294Sobrien    \checkenv\titlepage
2089174294Sobrien    \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
2090174294Sobrien    {\authorfont \leftline{#1}}%
2091174294Sobrien  \fi
2092174294Sobrien}
2093174294Sobrien
2094174294Sobrien
209538494Sobrien%%% Set up page headings and footings.
209638494Sobrien
209738494Sobrien\let\thispage=\folio
209838494Sobrien
209942629Sobrien\newtoks\evenheadline    % headline on even pages
210042629Sobrien\newtoks\oddheadline     % headline on odd pages
210142629Sobrien\newtoks\evenfootline    % footline on even pages
210242629Sobrien\newtoks\oddfootline     % footline on odd pages
210338494Sobrien
2104174294Sobrien% Now make TeX use those variables
210538494Sobrien\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
210638494Sobrien                            \else \the\evenheadline \fi}}
210738494Sobrien\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
210838494Sobrien                            \else \the\evenfootline \fi}\HEADINGShook}
210938494Sobrien\let\HEADINGShook=\relax
211038494Sobrien
211138494Sobrien% Commands to set those variables.
211238494Sobrien% For example, this is what  @headings on  does
211338494Sobrien% @evenheading @thistitle|@thispage|@thischapter
211438494Sobrien% @oddheading @thischapter|@thispage|@thistitle
211538494Sobrien% @evenfooting @thisfile||
211638494Sobrien% @oddfooting ||@thisfile
211738494Sobrien
2118174294Sobrien
211938494Sobrien\def\evenheading{\parsearg\evenheadingxxx}
2120174294Sobrien\def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
2121174294Sobrien\def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
212238494Sobrien\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
212338494Sobrien
2124174294Sobrien\def\oddheading{\parsearg\oddheadingxxx}
2125174294Sobrien\def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
2126174294Sobrien\def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
212738494Sobrien\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
212838494Sobrien
2129174294Sobrien\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
213038494Sobrien
2131174294Sobrien\def\evenfooting{\parsearg\evenfootingxxx}
2132174294Sobrien\def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
2133174294Sobrien\def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
213438494Sobrien\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
213538494Sobrien
2136174294Sobrien\def\oddfooting{\parsearg\oddfootingxxx}
2137174294Sobrien\def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
2138174294Sobrien\def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
213938494Sobrien  \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
214038494Sobrien  %
214138494Sobrien  % Leave some space for the footline.  Hopefully ok to assume
214238494Sobrien  % @evenfooting will not be used by itself.
214338494Sobrien  \global\advance\pageheight by -\baselineskip
214438494Sobrien  \global\advance\vsize by -\baselineskip
214538494Sobrien}
214638494Sobrien
2147174294Sobrien\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
214838494Sobrien
2149174294Sobrien
215038494Sobrien% @headings double      turns headings on for double-sided printing.
215138494Sobrien% @headings single      turns headings on for single-sided printing.
215238494Sobrien% @headings off         turns them off.
215338494Sobrien% @headings on          same as @headings double, retained for compatibility.
215438494Sobrien% @headings after       turns on double-sided headings after this page.
215538494Sobrien% @headings doubleafter turns on double-sided headings after this page.
215638494Sobrien% @headings singleafter turns on single-sided headings after this page.
215738494Sobrien% By default, they are off at the start of a document,
215838494Sobrien% and turned `on' after @end titlepage.
215938494Sobrien
216038494Sobrien\def\headings #1 {\csname HEADINGS#1\endcsname}
216138494Sobrien
2162174294Sobrien\def\HEADINGSoff{%
216338494Sobrien\global\evenheadline={\hfil} \global\evenfootline={\hfil}
216438494Sobrien\global\oddheadline={\hfil} \global\oddfootline={\hfil}}
216538494Sobrien\HEADINGSoff
216638494Sobrien% When we turn headings on, set the page number to 1.
216738494Sobrien% For double-sided printing, put current file name in lower left corner,
216838494Sobrien% chapter name on inside top of right hand pages, document
216938494Sobrien% title on inside top of left hand pages, and page numbers on outside top
217038494Sobrien% edge of all pages.
2171174294Sobrien\def\HEADINGSdouble{%
217238494Sobrien\global\pageno=1
217338494Sobrien\global\evenfootline={\hfil}
217438494Sobrien\global\oddfootline={\hfil}
217538494Sobrien\global\evenheadline={\line{\folio\hfil\thistitle}}
217638494Sobrien\global\oddheadline={\line{\thischapter\hfil\folio}}
217738494Sobrien\global\let\contentsalignmacro = \chapoddpage
217838494Sobrien}
217938494Sobrien\let\contentsalignmacro = \chappager
218038494Sobrien
218138494Sobrien% For single-sided printing, chapter title goes across top left of page,
218238494Sobrien% page number on top right.
2183174294Sobrien\def\HEADINGSsingle{%
218438494Sobrien\global\pageno=1
218538494Sobrien\global\evenfootline={\hfil}
218638494Sobrien\global\oddfootline={\hfil}
218738494Sobrien\global\evenheadline={\line{\thischapter\hfil\folio}}
218838494Sobrien\global\oddheadline={\line{\thischapter\hfil\folio}}
218938494Sobrien\global\let\contentsalignmacro = \chappager
219038494Sobrien}
219138494Sobrien\def\HEADINGSon{\HEADINGSdouble}
219238494Sobrien
219338494Sobrien\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
219438494Sobrien\let\HEADINGSdoubleafter=\HEADINGSafter
219538494Sobrien\def\HEADINGSdoublex{%
219638494Sobrien\global\evenfootline={\hfil}
219738494Sobrien\global\oddfootline={\hfil}
219838494Sobrien\global\evenheadline={\line{\folio\hfil\thistitle}}
219938494Sobrien\global\oddheadline={\line{\thischapter\hfil\folio}}
220038494Sobrien\global\let\contentsalignmacro = \chapoddpage
220138494Sobrien}
220238494Sobrien
220338494Sobrien\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
220438494Sobrien\def\HEADINGSsinglex{%
220538494Sobrien\global\evenfootline={\hfil}
220638494Sobrien\global\oddfootline={\hfil}
220738494Sobrien\global\evenheadline={\line{\thischapter\hfil\folio}}
220838494Sobrien\global\oddheadline={\line{\thischapter\hfil\folio}}
220938494Sobrien\global\let\contentsalignmacro = \chappager
221038494Sobrien}
221138494Sobrien
221238494Sobrien% Subroutines used in generating headings
221382794Sobrien% This produces Day Month Year style of output.
221482794Sobrien% Only define if not already defined, in case a txi-??.tex file has set
221582794Sobrien% up a different format (e.g., txi-cs.tex does this).
221682794Sobrien\ifx\today\undefined
221782794Sobrien\def\today{%
221882794Sobrien  \number\day\space
221982794Sobrien  \ifcase\month
222082794Sobrien  \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
222182794Sobrien  \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
222282794Sobrien  \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
222382794Sobrien  \fi
222482794Sobrien  \space\number\year}
222582794Sobrien\fi
222638494Sobrien
222782794Sobrien% @settitle line...  specifies the title of the document, for headings.
222882794Sobrien% It generates no output of its own.
222982794Sobrien\def\thistitle{\putwordNoTitle}
2230174294Sobrien\def\settitle{\parsearg{\gdef\thistitle}}
223138494Sobrien
223238494Sobrien
223338494Sobrien\message{tables,}
2234174294Sobrien% Tables -- @table, @ftable, @vtable, @item(x).
223538494Sobrien
223638494Sobrien% default indentation of table text
223738494Sobrien\newdimen\tableindent \tableindent=.8in
223838494Sobrien% default indentation of @itemize and @enumerate text
223938494Sobrien\newdimen\itemindent  \itemindent=.3in
224038494Sobrien% margin between end of table item and start of table text.
224138494Sobrien\newdimen\itemmargin  \itemmargin=.1in
224238494Sobrien
224338494Sobrien% used internally for \itemindent minus \itemmargin
224438494Sobrien\newdimen\itemmax
224538494Sobrien
2246174294Sobrien% Note @table, @ftable, and @vtable define @item, @itemx, etc., with
224738494Sobrien% these defs.
224838494Sobrien% They also define \itemindex
224938494Sobrien% to index the item name in whatever manner is desired (perhaps none).
225038494Sobrien
225138494Sobrien\newif\ifitemxneedsnegativevskip
225238494Sobrien
225338494Sobrien\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
225438494Sobrien
225538494Sobrien\def\internalBitem{\smallbreak \parsearg\itemzzz}
225638494Sobrien\def\internalBitemx{\itemxpar \parsearg\itemzzz}
225738494Sobrien
225838494Sobrien\def\itemzzz #1{\begingroup %
225938494Sobrien  \advance\hsize by -\rightskip
226038494Sobrien  \advance\hsize by -\tableindent
2261174294Sobrien  \setbox0=\hbox{\itemindicate{#1}}%
226238494Sobrien  \itemindex{#1}%
226338494Sobrien  \nobreak % This prevents a break before @itemx.
226438494Sobrien  %
226538494Sobrien  % If the item text does not fit in the space we have, put it on a line
226638494Sobrien  % by itself, and do not allow a page break either before or after that
226738494Sobrien  % line.  We do not start a paragraph here because then if the next
226838494Sobrien  % command is, e.g., @kindex, the whatsit would get put into the
226938494Sobrien  % horizontal list on a line by itself, resulting in extra blank space.
227038494Sobrien  \ifdim \wd0>\itemmax
227138494Sobrien    %
227238494Sobrien    % Make this a paragraph so we get the \parskip glue and wrapping,
227338494Sobrien    % but leave it ragged-right.
227438494Sobrien    \begingroup
227538494Sobrien      \advance\leftskip by-\tableindent
227638494Sobrien      \advance\hsize by\tableindent
227738494Sobrien      \advance\rightskip by0pt plus1fil
227838494Sobrien      \leavevmode\unhbox0\par
227938494Sobrien    \endgroup
228038494Sobrien    %
228138494Sobrien    % We're going to be starting a paragraph, but we don't want the
228238494Sobrien    % \parskip glue -- logically it's part of the @item we just started.
228338494Sobrien    \nobreak \vskip-\parskip
228438494Sobrien    %
2285174294Sobrien    % Stop a page break at the \parskip glue coming up.  However, if
2286174294Sobrien    % what follows is an environment such as @example, there will be no
2287174294Sobrien    % \parskip glue; then the negative vskip we just inserted would
2288174294Sobrien    % cause the example and the item to crash together.  So we use this
2289174294Sobrien    % bizarre value of 10001 as a signal to \aboveenvbreak to insert
2290174294Sobrien    % \parskip glue after all.  Section titles are handled this way also.
2291174294Sobrien    % 
2292174294Sobrien    \penalty 10001
229338494Sobrien    \endgroup
229438494Sobrien    \itemxneedsnegativevskipfalse
229538494Sobrien  \else
229638494Sobrien    % The item text fits into the space.  Start a paragraph, so that the
229782794Sobrien    % following text (if any) will end up on the same line.
229838494Sobrien    \noindent
229942629Sobrien    % Do this with kerns and \unhbox so that if there is a footnote in
230042629Sobrien    % the item text, it can migrate to the main vertical list and
230142629Sobrien    % eventually be printed.
230242629Sobrien    \nobreak\kern-\tableindent
230342629Sobrien    \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
230442629Sobrien    \unhbox0
230542629Sobrien    \nobreak\kern\dimen0
230642629Sobrien    \endgroup
230742629Sobrien    \itemxneedsnegativevskiptrue
230838494Sobrien  \fi
230938494Sobrien}
231038494Sobrien
2311174294Sobrien\def\item{\errmessage{@item while not in a list environment}}
2312174294Sobrien\def\itemx{\errmessage{@itemx while not in a list environment}}
231338494Sobrien
231442629Sobrien% @table, @ftable, @vtable.
2315174294Sobrien\envdef\table{%
2316174294Sobrien  \let\itemindex\gobble
2317174294Sobrien  \tablex
231838494Sobrien}
2319174294Sobrien\envdef\ftable{%
2320174294Sobrien  \def\itemindex ##1{\doind {fn}{\code{##1}}}%
2321174294Sobrien  \tablex
2322174294Sobrien}
2323174294Sobrien\envdef\vtable{%
2324174294Sobrien  \def\itemindex ##1{\doind {vr}{\code{##1}}}%
2325174294Sobrien  \tablex
2326174294Sobrien}
2327174294Sobrien\def\tablex#1{%
2328174294Sobrien  \def\itemindicate{#1}%
2329174294Sobrien  \parsearg\tabley
2330174294Sobrien}
2331174294Sobrien\def\tabley#1{%
2332174294Sobrien  {%
2333174294Sobrien    \makevalueexpandable
2334174294Sobrien    \edef\temp{\noexpand\tablez #1\space\space\space}%
2335174294Sobrien    \expandafter
2336174294Sobrien  }\temp \endtablez
2337174294Sobrien}
2338174294Sobrien\def\tablez #1 #2 #3 #4\endtablez{%
2339174294Sobrien  \aboveenvbreak
2340174294Sobrien  \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
2341174294Sobrien  \ifnum 0#2>0 \tableindent=#2\mil \fi
2342174294Sobrien  \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
2343174294Sobrien  \itemmax=\tableindent
2344174294Sobrien  \advance \itemmax by -\itemmargin
2345174294Sobrien  \advance \leftskip by \tableindent
2346174294Sobrien  \exdentamount=\tableindent
2347174294Sobrien  \parindent = 0pt
2348174294Sobrien  \parskip = \smallskipamount
2349174294Sobrien  \ifdim \parskip=0pt \parskip=2pt \fi
2350174294Sobrien  \let\item = \internalBitem
2351174294Sobrien  \let\itemx = \internalBitemx
2352174294Sobrien}
2353174294Sobrien\def\Etable{\endgraf\afterenvbreak}
2354174294Sobrien\let\Eftable\Etable
2355174294Sobrien\let\Evtable\Etable
2356174294Sobrien\let\Eitemize\Etable
2357174294Sobrien\let\Eenumerate\Etable
235838494Sobrien
235938494Sobrien% This is the counter used by @enumerate, which is really @itemize
236038494Sobrien
236138494Sobrien\newcount \itemno
236238494Sobrien
2363174294Sobrien\envdef\itemize{\parsearg\doitemize}
236438494Sobrien
2365174294Sobrien\def\doitemize#1{%
2366174294Sobrien  \aboveenvbreak
2367174294Sobrien  \itemmax=\itemindent
2368174294Sobrien  \advance\itemmax by -\itemmargin
2369174294Sobrien  \advance\leftskip by \itemindent
2370174294Sobrien  \exdentamount=\itemindent
2371174294Sobrien  \parindent=0pt
2372174294Sobrien  \parskip=\smallskipamount
2373174294Sobrien  \ifdim\parskip=0pt \parskip=2pt \fi
2374174294Sobrien  \def\itemcontents{#1}%
2375174294Sobrien  % @itemize with no arg is equivalent to @itemize @bullet.
2376174294Sobrien  \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
2377174294Sobrien  \let\item=\itemizeitem
237838494Sobrien}
237938494Sobrien
2380174294Sobrien% Definition of @item while inside @itemize and @enumerate.
2381174294Sobrien%
2382174294Sobrien\def\itemizeitem{%
2383174294Sobrien  \advance\itemno by 1  % for enumerations
2384174294Sobrien  {\let\par=\endgraf \smallbreak}% reasonable place to break
2385174294Sobrien  {%
2386174294Sobrien   % If the document has an @itemize directly after a section title, a
2387174294Sobrien   % \nobreak will be last on the list, and \sectionheading will have
2388174294Sobrien   % done a \vskip-\parskip.  In that case, we don't want to zero
2389174294Sobrien   % parskip, or the item text will crash with the heading.  On the
2390174294Sobrien   % other hand, when there is normal text preceding the item (as there
2391174294Sobrien   % usually is), we do want to zero parskip, or there would be too much
2392174294Sobrien   % space.  In that case, we won't have a \nobreak before.  At least
2393174294Sobrien   % that's the theory.
2394174294Sobrien   \ifnum\lastpenalty<10000 \parskip=0in \fi
2395174294Sobrien   \noindent
2396174294Sobrien   \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
2397174294Sobrien   \vadjust{\penalty 1200}}% not good to break after first line of item.
2398174294Sobrien  \flushcr
2399174294Sobrien}
240038494Sobrien
240138494Sobrien% \splitoff TOKENS\endmark defines \first to be the first token in
240238494Sobrien% TOKENS, and \rest to be the remainder.
240338494Sobrien%
240438494Sobrien\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
240538494Sobrien
240638494Sobrien% Allow an optional argument of an uppercase letter, lowercase letter,
240738494Sobrien% or number, to specify the first label in the enumerated list.  No
240838494Sobrien% argument is the same as `1'.
240938494Sobrien%
2410174294Sobrien\envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
241138494Sobrien\def\enumeratey #1 #2\endenumeratey{%
241238494Sobrien  % If we were given no argument, pretend we were given `1'.
241338494Sobrien  \def\thearg{#1}%
241438494Sobrien  \ifx\thearg\empty \def\thearg{1}\fi
241538494Sobrien  %
241638494Sobrien  % Detect if the argument is a single token.  If so, it might be a
241738494Sobrien  % letter.  Otherwise, the only valid thing it can be is a number.
241838494Sobrien  % (We will always have one token, because of the test we just made.
241938494Sobrien  % This is a good thing, since \splitoff doesn't work given nothing at
242038494Sobrien  % all -- the first parameter is undelimited.)
242138494Sobrien  \expandafter\splitoff\thearg\endmark
242238494Sobrien  \ifx\rest\empty
242338494Sobrien    % Only one token in the argument.  It could still be anything.
242438494Sobrien    % A ``lowercase letter'' is one whose \lccode is nonzero.
242538494Sobrien    % An ``uppercase letter'' is one whose \lccode is both nonzero, and
242638494Sobrien    %   not equal to itself.
242738494Sobrien    % Otherwise, we assume it's a number.
242838494Sobrien    %
242938494Sobrien    % We need the \relax at the end of the \ifnum lines to stop TeX from
243038494Sobrien    % continuing to look for a <number>.
243138494Sobrien    %
243238494Sobrien    \ifnum\lccode\expandafter`\thearg=0\relax
243338494Sobrien      \numericenumerate % a number (we hope)
243438494Sobrien    \else
243538494Sobrien      % It's a letter.
243638494Sobrien      \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
243738494Sobrien        \lowercaseenumerate % lowercase letter
243838494Sobrien      \else
243938494Sobrien        \uppercaseenumerate % uppercase letter
244038494Sobrien      \fi
244138494Sobrien    \fi
244238494Sobrien  \else
244338494Sobrien    % Multiple tokens in the argument.  We hope it's a number.
244438494Sobrien    \numericenumerate
244538494Sobrien  \fi
244638494Sobrien}
244738494Sobrien
244838494Sobrien% An @enumerate whose labels are integers.  The starting integer is
244938494Sobrien% given in \thearg.
245038494Sobrien%
245138494Sobrien\def\numericenumerate{%
245238494Sobrien  \itemno = \thearg
245338494Sobrien  \startenumeration{\the\itemno}%
245438494Sobrien}
245538494Sobrien
245638494Sobrien% The starting (lowercase) letter is in \thearg.
245738494Sobrien\def\lowercaseenumerate{%
245838494Sobrien  \itemno = \expandafter`\thearg
245938494Sobrien  \startenumeration{%
246038494Sobrien    % Be sure we're not beyond the end of the alphabet.
246138494Sobrien    \ifnum\itemno=0
246238494Sobrien      \errmessage{No more lowercase letters in @enumerate; get a bigger
246338494Sobrien                  alphabet}%
246438494Sobrien    \fi
246538494Sobrien    \char\lccode\itemno
246638494Sobrien  }%
246738494Sobrien}
246838494Sobrien
246938494Sobrien% The starting (uppercase) letter is in \thearg.
247038494Sobrien\def\uppercaseenumerate{%
247138494Sobrien  \itemno = \expandafter`\thearg
247238494Sobrien  \startenumeration{%
247338494Sobrien    % Be sure we're not beyond the end of the alphabet.
247438494Sobrien    \ifnum\itemno=0
247538494Sobrien      \errmessage{No more uppercase letters in @enumerate; get a bigger
247638494Sobrien                  alphabet}
247738494Sobrien    \fi
247838494Sobrien    \char\uccode\itemno
247938494Sobrien  }%
248038494Sobrien}
248138494Sobrien
2482174294Sobrien% Call \doitemize, adding a period to the first argument and supplying the
248338494Sobrien% common last two arguments.  Also subtract one from the initial value in
248438494Sobrien% \itemno, since @item increments \itemno.
248538494Sobrien%
248638494Sobrien\def\startenumeration#1{%
248738494Sobrien  \advance\itemno by -1
2488174294Sobrien  \doitemize{#1.}\flushcr
248938494Sobrien}
249038494Sobrien
249138494Sobrien% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
249238494Sobrien% to @enumerate.
249338494Sobrien%
249438494Sobrien\def\alphaenumerate{\enumerate{a}}
249538494Sobrien\def\capsenumerate{\enumerate{A}}
249638494Sobrien\def\Ealphaenumerate{\Eenumerate}
249738494Sobrien\def\Ecapsenumerate{\Eenumerate}
249838494Sobrien
249938494Sobrien
250038494Sobrien% @multitable macros
250138494Sobrien% Amy Hendrickson, 8/18/94, 3/6/96
250238494Sobrien%
250338494Sobrien% @multitable ... @end multitable will make as many columns as desired.
250438494Sobrien% Contents of each column will wrap at width given in preamble.  Width
250538494Sobrien% can be specified either with sample text given in a template line,
250638494Sobrien% or in percent of \hsize, the current width of text on page.
250738494Sobrien
250838494Sobrien% Table can continue over pages but will only break between lines.
250938494Sobrien
251038494Sobrien% To make preamble:
251138494Sobrien%
251238494Sobrien% Either define widths of columns in terms of percent of \hsize:
251338494Sobrien%   @multitable @columnfractions .25 .3 .45
251438494Sobrien%   @item ...
251538494Sobrien%
251638494Sobrien%   Numbers following @columnfractions are the percent of the total
251738494Sobrien%   current hsize to be used for each column. You may use as many
251838494Sobrien%   columns as desired.
251938494Sobrien
252038494Sobrien
252138494Sobrien% Or use a template:
252238494Sobrien%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
252338494Sobrien%   @item ...
252438494Sobrien%   using the widest term desired in each column.
252538494Sobrien
252638494Sobrien% Each new table line starts with @item, each subsequent new column
252738494Sobrien% starts with @tab. Empty columns may be produced by supplying @tab's
252838494Sobrien% with nothing between them for as many times as empty columns are needed,
252938494Sobrien% ie, @tab@tab@tab will produce two empty columns.
253038494Sobrien
2531174294Sobrien% @item, @tab do not need to be on their own lines, but it will not hurt
2532174294Sobrien% if they are.
253338494Sobrien
253438494Sobrien% Sample multitable:
253538494Sobrien
253638494Sobrien%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
253738494Sobrien%   @item first col stuff @tab second col stuff @tab third col
253838494Sobrien%   @item
253938494Sobrien%   first col stuff
254038494Sobrien%   @tab
254138494Sobrien%   second col stuff
254238494Sobrien%   @tab
254338494Sobrien%   third col
254438494Sobrien%   @item first col stuff @tab second col stuff
254538494Sobrien%   @tab Many paragraphs of text may be used in any column.
254638494Sobrien%
254738494Sobrien%         They will wrap at the width determined by the template.
254838494Sobrien%   @item@tab@tab This will be in third column.
254938494Sobrien%   @end multitable
255038494Sobrien
255138494Sobrien% Default dimensions may be reset by user.
255238494Sobrien% @multitableparskip is vertical space between paragraphs in table.
255338494Sobrien% @multitableparindent is paragraph indent in table.
255438494Sobrien% @multitablecolmargin is horizontal space to be left between columns.
255538494Sobrien% @multitablelinespace is space to leave between table items, baseline
255638494Sobrien%                                                            to baseline.
255738494Sobrien%   0pt means it depends on current normal line spacing.
255842629Sobrien%
255938494Sobrien\newskip\multitableparskip
256038494Sobrien\newskip\multitableparindent
256138494Sobrien\newdimen\multitablecolspace
256238494Sobrien\newskip\multitablelinespace
256338494Sobrien\multitableparskip=0pt
256438494Sobrien\multitableparindent=6pt
256538494Sobrien\multitablecolspace=12pt
256638494Sobrien\multitablelinespace=0pt
256738494Sobrien
256838494Sobrien% Macros used to set up halign preamble:
256982794Sobrien%
257038494Sobrien\let\endsetuptable\relax
257138494Sobrien\def\xendsetuptable{\endsetuptable}
257238494Sobrien\let\columnfractions\relax
257338494Sobrien\def\xcolumnfractions{\columnfractions}
257438494Sobrien\newif\ifsetpercent
257538494Sobrien
2576174294Sobrien% #1 is the @columnfraction, usually a decimal number like .5, but might
2577174294Sobrien% be just 1.  We just use it, whatever it is.
2578174294Sobrien%
2579174294Sobrien\def\pickupwholefraction#1 {%
258082794Sobrien  \global\advance\colcount by 1
2581174294Sobrien  \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
258282794Sobrien  \setuptable
258382794Sobrien}
258438494Sobrien
258538494Sobrien\newcount\colcount
258682794Sobrien\def\setuptable#1{%
258782794Sobrien  \def\firstarg{#1}%
258882794Sobrien  \ifx\firstarg\xendsetuptable
258982794Sobrien    \let\go = \relax
259038494Sobrien  \else
259182794Sobrien    \ifx\firstarg\xcolumnfractions
259282794Sobrien      \global\setpercenttrue
259338494Sobrien    \else
259482794Sobrien      \ifsetpercent
259582794Sobrien         \let\go\pickupwholefraction
259682794Sobrien      \else
259782794Sobrien         \global\advance\colcount by 1
2598174294Sobrien         \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
2599174294Sobrien                   % separator; typically that is always in the input, anyway.
260082794Sobrien         \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
260182794Sobrien      \fi
260282794Sobrien    \fi
260382794Sobrien    \ifx\go\pickupwholefraction
260482794Sobrien      % Put the argument back for the \pickupwholefraction call, so
260582794Sobrien      % we'll always have a period there to be parsed.
260682794Sobrien      \def\go{\pickupwholefraction#1}%
260782794Sobrien    \else
260882794Sobrien      \let\go = \setuptable
260938494Sobrien    \fi%
261082794Sobrien  \fi
261182794Sobrien  \go
261282794Sobrien}
261338494Sobrien
2614174294Sobrien% multitable-only commands.
2615174294Sobrien%
2616174294Sobrien% @headitem starts a heading row, which we typeset in bold.
2617174294Sobrien% Assignments have to be global since we are inside the implicit group
2618174294Sobrien% of an alignment entry.  Note that \everycr resets \everytab.
2619174294Sobrien\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}%
2620174294Sobrien%
2621174294Sobrien% A \tab used to include \hskip1sp.  But then the space in a template
2622174294Sobrien% line is not enough.  That is bad.  So let's go back to just `&' until
2623174294Sobrien% we encounter the problem it was intended to solve again.
2624174294Sobrien%					--karl, nathan@acm.org, 20apr99.
2625174294Sobrien\def\tab{\checkenv\multitable &\the\everytab}%
262638494Sobrien
262738494Sobrien% @multitable ... @end multitable definitions:
262882794Sobrien%
2629174294Sobrien\newtoks\everytab  % insert after every tab.
2630174294Sobrien%
2631174294Sobrien\envdef\multitable{%
263242629Sobrien  \vskip\parskip
2633174294Sobrien  \startsavinginserts
2634174294Sobrien  %
2635174294Sobrien  % @item within a multitable starts a normal row.
2636174294Sobrien  % We use \def instead of \let so that if one of the multitable entries
2637174294Sobrien  % contains an @itemize, we don't choke on the \item (seen as \crcr aka
2638174294Sobrien  % \endtemplate) expanding \doitemize.
2639174294Sobrien  \def\item{\crcr}%
2640174294Sobrien  %
264142629Sobrien  \tolerance=9500
264242629Sobrien  \hbadness=9500
264342629Sobrien  \setmultitablespacing
264442629Sobrien  \parskip=\multitableparskip
264542629Sobrien  \parindent=\multitableparindent
264642629Sobrien  \overfullrule=0pt
264742629Sobrien  \global\colcount=0
264842629Sobrien  %
2649174294Sobrien  \everycr = {%
2650174294Sobrien    \noalign{%
2651174294Sobrien      \global\everytab={}%
2652174294Sobrien      \global\colcount=0 % Reset the column counter.
2653174294Sobrien      % Check for saved footnotes, etc.
2654174294Sobrien      \checkinserts
2655174294Sobrien      % Keeps underfull box messages off when table breaks over pages.
2656174294Sobrien      %\filbreak
2657174294Sobrien	% Maybe so, but it also creates really weird page breaks when the
2658174294Sobrien	% table breaks over pages. Wouldn't \vfil be better?  Wait until the
2659174294Sobrien	% problem manifests itself, so it can be fixed for real --karl.
2660174294Sobrien    }%
2661174294Sobrien  }%
2662174294Sobrien  %
2663174294Sobrien  \parsearg\domultitable
2664174294Sobrien}
2665174294Sobrien\def\domultitable#1{%
266642629Sobrien  % To parse everything between @multitable and @item:
266742629Sobrien  \setuptable#1 \endsetuptable
266842629Sobrien  %
266942629Sobrien  % This preamble sets up a generic column definition, which will
267042629Sobrien  % be used as many times as user calls for columns.
267142629Sobrien  % \vtop will set a single line and will also let text wrap and
267242629Sobrien  % continue for many paragraphs if desired.
2673174294Sobrien  \halign\bgroup &%
2674174294Sobrien    \global\advance\colcount by 1
2675174294Sobrien    \multistrut
2676174294Sobrien    \vtop{%
2677174294Sobrien      % Use the current \colcount to find the correct column width:
2678174294Sobrien      \hsize=\expandafter\csname col\the\colcount\endcsname
2679174294Sobrien      %
2680174294Sobrien      % In order to keep entries from bumping into each other
2681174294Sobrien      % we will add a \leftskip of \multitablecolspace to all columns after
2682174294Sobrien      % the first one.
2683174294Sobrien      %
2684174294Sobrien      % If a template has been used, we will add \multitablecolspace
2685174294Sobrien      % to the width of each template entry.
2686174294Sobrien      %
2687174294Sobrien      % If the user has set preamble in terms of percent of \hsize we will
2688174294Sobrien      % use that dimension as the width of the column, and the \leftskip
2689174294Sobrien      % will keep entries from bumping into each other.  Table will start at
2690174294Sobrien      % left margin and final column will justify at right margin.
2691174294Sobrien      %
2692174294Sobrien      % Make sure we don't inherit \rightskip from the outer environment.
2693174294Sobrien      \rightskip=0pt
2694174294Sobrien      \ifnum\colcount=1
2695174294Sobrien	% The first column will be indented with the surrounding text.
2696174294Sobrien	\advance\hsize by\leftskip
2697174294Sobrien      \else
2698174294Sobrien	\ifsetpercent \else
2699174294Sobrien	  % If user has not set preamble in terms of percent of \hsize
2700174294Sobrien	  % we will advance \hsize by \multitablecolspace.
2701174294Sobrien	  \advance\hsize by \multitablecolspace
2702174294Sobrien	\fi
2703174294Sobrien       % In either case we will make \leftskip=\multitablecolspace:
2704174294Sobrien      \leftskip=\multitablecolspace
2705174294Sobrien      \fi
2706174294Sobrien      % Ignoring space at the beginning and end avoids an occasional spurious
2707174294Sobrien      % blank line, when TeX decides to break the line at the space before the
2708174294Sobrien      % box from the multistrut, so the strut ends up on a line by itself.
2709174294Sobrien      % For example:
2710174294Sobrien      % @multitable @columnfractions .11 .89
2711174294Sobrien      % @item @code{#}
2712174294Sobrien      % @tab Legal holiday which is valid in major parts of the whole country.
2713174294Sobrien      % Is automatically provided with highlighting sequences respectively
2714174294Sobrien      % marking characters.
2715174294Sobrien      \noindent\ignorespaces##\unskip\multistrut
2716174294Sobrien    }\cr
271738494Sobrien}
2718174294Sobrien\def\Emultitable{%
2719174294Sobrien  \crcr
2720174294Sobrien  \egroup % end the \halign
2721174294Sobrien  \global\setpercentfalse
2722174294Sobrien}
272338494Sobrien
272438494Sobrien\def\setmultitablespacing{% test to see if user has set \multitablelinespace.
272538494Sobrien% If so, do nothing. If not, give it an appropriate dimension based on
272638494Sobrien% current baselineskip.
272738494Sobrien\ifdim\multitablelinespace=0pt
272882794Sobrien\setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
272982794Sobrien\global\advance\multitablelinespace by-\ht0
273038494Sobrien%% strut to put in table in case some entry doesn't have descenders,
273138494Sobrien%% to keep lines equally spaced
273238494Sobrien\let\multistrut = \strut
273382794Sobrien\else
273482794Sobrien%% FIXME: what is \box0 supposed to be?
273582794Sobrien\gdef\multistrut{\vrule height\multitablelinespace depth\dp0
273682794Sobrienwidth0pt\relax} \fi
273738494Sobrien%% Test to see if parskip is larger than space between lines of
273838494Sobrien%% table. If not, do nothing.
273938494Sobrien%%        If so, set to same dimension as multitablelinespace.
274038494Sobrien\ifdim\multitableparskip>\multitablelinespace
274138494Sobrien\global\multitableparskip=\multitablelinespace
274238494Sobrien\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
274338494Sobrien                                      %% than skip between lines in the table.
274438494Sobrien\fi%
274538494Sobrien\ifdim\multitableparskip=0pt
274638494Sobrien\global\multitableparskip=\multitablelinespace
274738494Sobrien\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
274838494Sobrien                                      %% than skip between lines in the table.
274938494Sobrien\fi}
275038494Sobrien
275138494Sobrien
275282794Sobrien\message{conditionals,}
275382794Sobrien
2754174294Sobrien% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
2755174294Sobrien% @ifnotxml always succeed.  They currently do nothing; we don't
2756174294Sobrien% attempt to check whether the conditionals are properly nested.  But we
2757174294Sobrien% have to remember that they are conditionals, so that @end doesn't
2758174294Sobrien% attempt to close an environment group.
275982794Sobrien%
2760174294Sobrien\def\makecond#1{%
2761174294Sobrien  \expandafter\let\csname #1\endcsname = \relax
2762174294Sobrien  \expandafter\let\csname iscond.#1\endcsname = 1
276382794Sobrien}
2764174294Sobrien\makecond{iftex}
2765174294Sobrien\makecond{ifnotdocbook}
2766174294Sobrien\makecond{ifnothtml}
2767174294Sobrien\makecond{ifnotinfo}
2768174294Sobrien\makecond{ifnotplaintext}
2769174294Sobrien\makecond{ifnotxml}
277082794Sobrien
2771174294Sobrien% Ignore @ignore, @ifhtml, @ifinfo, and the like.
277282794Sobrien%
2773174294Sobrien\def\direntry{\doignore{direntry}}
2774174294Sobrien\def\documentdescription{\doignore{documentdescription}}
2775174294Sobrien\def\docbook{\doignore{docbook}}
2776174294Sobrien\def\html{\doignore{html}}
2777174294Sobrien\def\ifdocbook{\doignore{ifdocbook}}
2778119679Smbr\def\ifhtml{\doignore{ifhtml}}
277982794Sobrien\def\ifinfo{\doignore{ifinfo}}
2780174294Sobrien\def\ifnottex{\doignore{ifnottex}}
2781119679Smbr\def\ifplaintext{\doignore{ifplaintext}}
2782174294Sobrien\def\ifxml{\doignore{ifxml}}
2783174294Sobrien\def\ignore{\doignore{ignore}}
278482794Sobrien\def\menu{\doignore{menu}}
2785174294Sobrien\def\xml{\doignore{xml}}
278682794Sobrien
2787174294Sobrien% Ignore text until a line `@end #1', keeping track of nested conditionals.
2788174294Sobrien%
2789174294Sobrien% A count to remember the depth of nesting.
2790174294Sobrien\newcount\doignorecount
279182794Sobrien
279282794Sobrien\def\doignore#1{\begingroup
2793174294Sobrien  % Scan in ``verbatim'' mode:
2794174294Sobrien  \catcode`\@ = \other
2795174294Sobrien  \catcode`\{ = \other
2796174294Sobrien  \catcode`\} = \other
279782794Sobrien  %
279882794Sobrien  % Make sure that spaces turn into tokens that match what \doignoretext wants.
2799174294Sobrien  \spaceisspace
280082794Sobrien  %
2801174294Sobrien  % Count number of #1's that we've seen.
2802174294Sobrien  \doignorecount = 0
280382794Sobrien  %
2804174294Sobrien  % Swallow text until we reach the matching `@end #1'.
2805174294Sobrien  \dodoignore{#1}%
2806174294Sobrien}
2807174294Sobrien
2808174294Sobrien{ \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
2809174294Sobrien  \obeylines %
281082794Sobrien  %
2811174294Sobrien  \gdef\dodoignore#1{%
2812174294Sobrien    % #1 contains the command name as a string, e.g., `ifinfo'.
2813174294Sobrien    %
2814174294Sobrien    % Define a command to find the next `@end #1', which must be on a line
2815174294Sobrien    % by itself.
2816174294Sobrien    \long\def\doignoretext##1^^M@end #1{\doignoretextyyy##1^^M@#1\_STOP_}%
2817174294Sobrien    % And this command to find another #1 command, at the beginning of a
2818174294Sobrien    % line.  (Otherwise, we would consider a line `@c @ifset', for
2819174294Sobrien    % example, to count as an @ifset for nesting.)
2820174294Sobrien    \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
2821174294Sobrien    %
2822174294Sobrien    % And now expand that command.
2823174294Sobrien    \obeylines %
2824174294Sobrien    \doignoretext ^^M%
2825174294Sobrien  }%
2826174294Sobrien}
2827174294Sobrien
2828174294Sobrien\def\doignoreyyy#1{%
2829174294Sobrien  \def\temp{#1}%
2830174294Sobrien  \ifx\temp\empty			% Nothing found.
2831174294Sobrien    \let\next\doignoretextzzz
2832174294Sobrien  \else					% Found a nested condition, ...
2833174294Sobrien    \advance\doignorecount by 1
2834174294Sobrien    \let\next\doignoretextyyy		% ..., look for another.
2835174294Sobrien    % If we're here, #1 ends with ^^M\ifinfo (for example).
2836119679Smbr  \fi
2837174294Sobrien  \next #1% the token \_STOP_ is present just after this macro.
283882794Sobrien}
283982794Sobrien
2840174294Sobrien% We have to swallow the remaining "\_STOP_".
284182794Sobrien%
2842174294Sobrien\def\doignoretextzzz#1{%
2843174294Sobrien  \ifnum\doignorecount = 0	% We have just found the outermost @end.
2844174294Sobrien    \let\next\enddoignore
2845174294Sobrien  \else				% Still inside a nested condition.
2846174294Sobrien    \advance\doignorecount by -1
2847174294Sobrien    \let\next\doignoretext      % Look for the next @end.
2848174294Sobrien  \fi
2849174294Sobrien  \next
285082794Sobrien}
285182794Sobrien
2852174294Sobrien% Finish off ignored text.
2853174294Sobrien\def\enddoignore{\endgroup\ignorespaces}
285482794Sobrien
285582794Sobrien
285682794Sobrien% @set VAR sets the variable VAR to an empty value.
285782794Sobrien% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
285882794Sobrien%
285982794Sobrien% Since we want to separate VAR from REST-OF-LINE (which might be
286082794Sobrien% empty), we can't just use \parsearg; we have to insert a space of our
286182794Sobrien% own to delimit the rest of the line, and then take it out again if we
2862174294Sobrien% didn't need it.
2863174294Sobrien% We rely on the fact that \parsearg sets \catcode`\ =10.
286482794Sobrien%
2865174294Sobrien\parseargdef\set{\setyyy#1 \endsetyyy}
286682794Sobrien\def\setyyy#1 #2\endsetyyy{%
2867174294Sobrien  {%
2868174294Sobrien    \makevalueexpandable
2869174294Sobrien    \def\temp{#2}%
2870174294Sobrien    \edef\next{\gdef\makecsname{SET#1}}%
2871174294Sobrien    \ifx\temp\empty
2872174294Sobrien      \next{}%
2873174294Sobrien    \else
2874174294Sobrien      \setzzz#2\endsetzzz
2875174294Sobrien    \fi
2876174294Sobrien  }%
287782794Sobrien}
2878174294Sobrien% Remove the trailing space \setxxx inserted.
2879174294Sobrien\def\setzzz#1 \endsetzzz{\next{#1}}
288082794Sobrien
288182794Sobrien% @clear VAR clears (i.e., unsets) the variable VAR.
288282794Sobrien%
2883174294Sobrien\parseargdef\clear{%
2884174294Sobrien  {%
2885174294Sobrien    \makevalueexpandable
2886174294Sobrien    \global\expandafter\let\csname SET#1\endcsname=\relax
2887174294Sobrien  }%
2888174294Sobrien}
288982794Sobrien
289082794Sobrien% @value{foo} gets the text saved in variable foo.
2891174294Sobrien\def\value{\begingroup\makevalueexpandable\valuexxx}
2892174294Sobrien\def\valuexxx#1{\expandablevalue{#1}\endgroup}
289382794Sobrien{
2894174294Sobrien  \catcode`\- = \active \catcode`\_ = \active
289582794Sobrien  %
2896174294Sobrien  \gdef\makevalueexpandable{%
2897174294Sobrien    \let\value = \expandablevalue
2898174294Sobrien    % We don't want these characters active, ...
2899174294Sobrien    \catcode`\-=\other \catcode`\_=\other
2900174294Sobrien    % ..., but we might end up with active ones in the argument if
2901174294Sobrien    % we're called from @code, as @code{@value{foo-bar_}}, though.
2902174294Sobrien    % So \let them to their normal equivalents.
2903174294Sobrien    \let-\realdash \let_\normalunderscore
2904174294Sobrien  }
290582794Sobrien}
290682794Sobrien
290782794Sobrien% We have this subroutine so that we can handle at least some @value's
2908174294Sobrien% properly in indexes (we call \makevalueexpandable in \indexdummies).
2909174294Sobrien% The command has to be fully expandable (if the variable is set), since
2910174294Sobrien% the result winds up in the index file.  This means that if the
2911174294Sobrien% variable's value contains other Texinfo commands, it's almost certain
2912174294Sobrien% it will fail (although perhaps we could fix that with sufficient work
2913174294Sobrien% to do a one-level expansion on the result, instead of complete).
291482794Sobrien%
291582794Sobrien\def\expandablevalue#1{%
291682794Sobrien  \expandafter\ifx\csname SET#1\endcsname\relax
291782794Sobrien    {[No value for ``#1'']}%
2918174294Sobrien    \message{Variable `#1', used in @value, is not set.}%
291982794Sobrien  \else
292082794Sobrien    \csname SET#1\endcsname
292182794Sobrien  \fi
292282794Sobrien}
292382794Sobrien
292482794Sobrien% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
292582794Sobrien% with @set.
292682794Sobrien%
2927174294Sobrien% To get special treatment of `@end ifset,' call \makeond and the redefine.
2928174294Sobrien%
2929174294Sobrien\makecond{ifset}
2930174294Sobrien\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
2931174294Sobrien\def\doifset#1#2{%
2932174294Sobrien  {%
2933174294Sobrien    \makevalueexpandable
2934174294Sobrien    \let\next=\empty
2935174294Sobrien    \expandafter\ifx\csname SET#2\endcsname\relax
2936174294Sobrien      #1% If not set, redefine \next.
2937174294Sobrien    \fi
2938174294Sobrien    \expandafter
2939174294Sobrien  }\next
294082794Sobrien}
2941174294Sobrien\def\ifsetfail{\doignore{ifset}}
294282794Sobrien
294382794Sobrien% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
294482794Sobrien% defined with @set, or has been undefined with @clear.
294582794Sobrien%
2946174294Sobrien% The `\else' inside the `\doifset' parameter is a trick to reuse the
2947174294Sobrien% above code: if the variable is not set, do nothing, if it is set,
2948174294Sobrien% then redefine \next to \ifclearfail.
294982794Sobrien%
2950174294Sobrien\makecond{ifclear}
2951174294Sobrien\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
2952174294Sobrien\def\ifclearfail{\doignore{ifclear}}
295382794Sobrien
2954174294Sobrien% @dircategory CATEGORY  -- specify a category of the dir file
2955174294Sobrien% which this file should belong to.  Ignore this in TeX.
2956174294Sobrien\let\dircategory=\comment
295782794Sobrien
295882794Sobrien% @defininfoenclose.
295982794Sobrien\let\definfoenclose=\comment
296082794Sobrien
296182794Sobrien
296238494Sobrien\message{indexing,}
296338494Sobrien% Index generation facilities
296438494Sobrien
296538494Sobrien% Define \newwrite to be identical to plain tex's \newwrite
296638494Sobrien% except not \outer, so it can be used within \newindex.
296738494Sobrien{\catcode`\@=11
296838494Sobrien\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}}
296938494Sobrien
297038494Sobrien% \newindex {foo} defines an index named foo.
297138494Sobrien% It automatically defines \fooindex such that
297238494Sobrien% \fooindex ...rest of line... puts an entry in the index foo.
297338494Sobrien% It also defines \fooindfile to be the number of the output channel for
297438494Sobrien% the file that accumulates this index.  The file's extension is foo.
297538494Sobrien% The name of an index should be no more than 2 characters long
297638494Sobrien% for the sake of vms.
297742629Sobrien%
297842629Sobrien\def\newindex#1{%
297942629Sobrien  \iflinks
298042629Sobrien    \expandafter\newwrite \csname#1indfile\endcsname
298142629Sobrien    \openout \csname#1indfile\endcsname \jobname.#1 % Open the file
298242629Sobrien  \fi
298342629Sobrien  \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
298442629Sobrien    \noexpand\doindex{#1}}
298538494Sobrien}
298638494Sobrien
298738494Sobrien% @defindex foo  ==  \newindex{foo}
298882794Sobrien%
298938494Sobrien\def\defindex{\parsearg\newindex}
299038494Sobrien
299138494Sobrien% Define @defcodeindex, like @defindex except put all entries in @code.
299282794Sobrien%
299382794Sobrien\def\defcodeindex{\parsearg\newcodeindex}
299482794Sobrien%
299542629Sobrien\def\newcodeindex#1{%
299642629Sobrien  \iflinks
299742629Sobrien    \expandafter\newwrite \csname#1indfile\endcsname
299842629Sobrien    \openout \csname#1indfile\endcsname \jobname.#1
299942629Sobrien  \fi
300042629Sobrien  \expandafter\xdef\csname#1index\endcsname{%
300182794Sobrien    \noexpand\docodeindex{#1}}%
300238494Sobrien}
300338494Sobrien
300438494Sobrien
300538494Sobrien% @synindex foo bar    makes index foo feed into index bar.
300638494Sobrien% Do this instead of @defindex foo if you don't want it as a separate index.
3007174294Sobrien%
300838494Sobrien% @syncodeindex foo bar   similar, but put all entries made for index foo
300938494Sobrien% inside @code.
3010174294Sobrien%
301182794Sobrien\def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
301282794Sobrien\def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
301382794Sobrien
301482794Sobrien% #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
301582794Sobrien% #3 the target index (bar).
301682794Sobrien\def\dosynindex#1#2#3{%
301782794Sobrien  % Only do \closeout if we haven't already done it, else we'll end up
301882794Sobrien  % closing the target index.
301982794Sobrien  \expandafter \ifx\csname donesynindex#2\endcsname \undefined
302082794Sobrien    % The \closeout helps reduce unnecessary open files; the limit on the
302182794Sobrien    % Acorn RISC OS is a mere 16 files.
302282794Sobrien    \expandafter\closeout\csname#2indfile\endcsname
302382794Sobrien    \expandafter\let\csname\donesynindex#2\endcsname = 1
302482794Sobrien  \fi
302582794Sobrien  % redefine \fooindfile:
302682794Sobrien  \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
302782794Sobrien  \expandafter\let\csname#2indfile\endcsname=\temp
302882794Sobrien  % redefine \fooindex:
302982794Sobrien  \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
303038494Sobrien}
303138494Sobrien
303238494Sobrien% Define \doindex, the driver for all \fooindex macros.
303338494Sobrien% Argument #1 is generated by the calling \fooindex macro,
303438494Sobrien%  and it is "foo", the name of the index.
303538494Sobrien
303638494Sobrien% \doindex just uses \parsearg; it calls \doind for the actual work.
303738494Sobrien% This is because \doind is more useful to call from other macros.
303838494Sobrien
303938494Sobrien% There is also \dosubind {index}{topic}{subtopic}
304038494Sobrien% which makes an entry in a two-level index such as the operation index.
304138494Sobrien
304238494Sobrien\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer}
304338494Sobrien\def\singleindexer #1{\doind{\indexname}{#1}}
304438494Sobrien
304538494Sobrien% like the previous two, but they put @code around the argument.
304638494Sobrien\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer}
304738494Sobrien\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}}
304838494Sobrien
3049174294Sobrien% Take care of Texinfo commands that can appear in an index entry.
3050174294Sobrien% Since there are some commands we want to expand, and others we don't,
3051174294Sobrien% we have to laboriously prevent expansion for those that we don't.
3052174294Sobrien%
305338494Sobrien\def\indexdummies{%
3054174294Sobrien  \def\@{@}% change to @@ when we switch to @ as escape char in index files.
3055174294Sobrien  \def\ {\realbackslash\space }%
3056174294Sobrien  % Need these in case \tex is in effect and \{ is a \delimiter again.
3057174294Sobrien  % But can't use \lbracecmd and \rbracecmd because texindex assumes
3058174294Sobrien  % braces and backslashes are used only as delimiters.
3059174294Sobrien  \let\{ = \mylbrace
3060174294Sobrien  \let\} = \myrbrace
3061174294Sobrien  %
3062174294Sobrien  % \definedummyword defines \#1 as \realbackslash #1\space, thus
3063174294Sobrien  % effectively preventing its expansion.  This is used only for control
3064174294Sobrien  % words, not control letters, because the \space would be incorrect
3065174294Sobrien  % for control characters, but is needed to separate the control word
3066174294Sobrien  % from whatever follows.
3067174294Sobrien  %
3068174294Sobrien  % For control letters, we have \definedummyletter, which omits the
3069174294Sobrien  % space.
3070174294Sobrien  %
3071174294Sobrien  % These can be used both for control words that take an argument and
3072174294Sobrien  % those that do not.  If it is followed by {arg} in the input, then
3073174294Sobrien  % that will dutifully get written to the index (or wherever).
3074174294Sobrien  %
3075174294Sobrien  \def\definedummyword##1{%
3076174294Sobrien    \expandafter\def\csname ##1\endcsname{\realbackslash ##1\space}%
3077174294Sobrien  }%
3078174294Sobrien  \def\definedummyletter##1{%
3079174294Sobrien    \expandafter\def\csname ##1\endcsname{\realbackslash ##1}%
3080174294Sobrien  }%
3081174294Sobrien  \let\definedummyaccent\definedummyletter
3082174294Sobrien  %
3083174294Sobrien  % Do the redefinitions.
3084174294Sobrien  \commondummies
3085174294Sobrien}
3086174294Sobrien
3087174294Sobrien% For the aux file, @ is the escape character.  So we want to redefine
3088174294Sobrien% everything using @ instead of \realbackslash.  When everything uses
3089174294Sobrien% @, this will be simpler.
3090119679Smbr%
3091174294Sobrien\def\atdummies{%
3092174294Sobrien  \def\@{@@}%
3093174294Sobrien  \def\ {@ }%
3094174294Sobrien  \let\{ = \lbraceatcmd
3095174294Sobrien  \let\} = \rbraceatcmd
3096174294Sobrien  %
3097174294Sobrien  % (See comments in \indexdummies.)
3098174294Sobrien  \def\definedummyword##1{%
3099174294Sobrien    \expandafter\def\csname ##1\endcsname{@##1\space}%
3100174294Sobrien  }%
3101174294Sobrien  \def\definedummyletter##1{%
3102174294Sobrien    \expandafter\def\csname ##1\endcsname{@##1}%
3103174294Sobrien  }%
3104174294Sobrien  \let\definedummyaccent\definedummyletter
3105174294Sobrien  %
3106174294Sobrien  % Do the redefinitions.
3107174294Sobrien  \commondummies
3108174294Sobrien}
3109174294Sobrien
3110174294Sobrien% Called from \indexdummies and \atdummies.  \definedummyword and
3111174294Sobrien% \definedummyletter must be defined first.
3112119679Smbr%
3113174294Sobrien\def\commondummies{%
3114174294Sobrien  %
3115174294Sobrien  \normalturnoffactive
3116174294Sobrien  %
3117174294Sobrien  \commondummiesnofonts
3118174294Sobrien  %
3119174294Sobrien  \definedummyletter{_}%
3120174294Sobrien  %
3121174294Sobrien  % Non-English letters.
3122174294Sobrien  \definedummyword{AA}%
3123174294Sobrien  \definedummyword{AE}%
3124174294Sobrien  \definedummyword{L}%
3125174294Sobrien  \definedummyword{OE}%
3126174294Sobrien  \definedummyword{O}%
3127174294Sobrien  \definedummyword{aa}%
3128174294Sobrien  \definedummyword{ae}%
3129174294Sobrien  \definedummyword{l}%
3130174294Sobrien  \definedummyword{oe}%
3131174294Sobrien  \definedummyword{o}%
3132174294Sobrien  \definedummyword{ss}%
3133174294Sobrien  \definedummyword{exclamdown}%
3134174294Sobrien  \definedummyword{questiondown}%
3135174294Sobrien  \definedummyword{ordf}%
3136174294Sobrien  \definedummyword{ordm}%
3137174294Sobrien  %
3138174294Sobrien  % Although these internal commands shouldn't show up, sometimes they do.
3139174294Sobrien  \definedummyword{bf}%
3140174294Sobrien  \definedummyword{gtr}%
3141174294Sobrien  \definedummyword{hat}%
3142174294Sobrien  \definedummyword{less}%
3143174294Sobrien  \definedummyword{sf}%
3144174294Sobrien  \definedummyword{sl}%
3145174294Sobrien  \definedummyword{tclose}%
3146174294Sobrien  \definedummyword{tt}%
3147174294Sobrien  %
3148174294Sobrien  \definedummyword{LaTeX}%
3149174294Sobrien  \definedummyword{TeX}%
3150174294Sobrien  %
3151174294Sobrien  % Assorted special characters.
3152174294Sobrien  \definedummyword{bullet}%
3153174294Sobrien  \definedummyword{comma}%
3154174294Sobrien  \definedummyword{copyright}%
3155174294Sobrien  \definedummyword{registeredsymbol}%
3156174294Sobrien  \definedummyword{dots}%
3157174294Sobrien  \definedummyword{enddots}%
3158174294Sobrien  \definedummyword{equiv}%
3159174294Sobrien  \definedummyword{error}%
3160174294Sobrien  \definedummyword{expansion}%
3161174294Sobrien  \definedummyword{minus}%
3162174294Sobrien  \definedummyword{pounds}%
3163174294Sobrien  \definedummyword{point}%
3164174294Sobrien  \definedummyword{print}%
3165174294Sobrien  \definedummyword{result}%
3166174294Sobrien  %
3167174294Sobrien  % Handle some cases of @value -- where it does not contain any
3168174294Sobrien  % (non-fully-expandable) commands.
3169174294Sobrien  \makevalueexpandable
3170174294Sobrien  %
3171174294Sobrien  % Normal spaces, not active ones.
3172174294Sobrien  \unsepspaces
3173174294Sobrien  %
3174174294Sobrien  % No macro expansion.
3175174294Sobrien  \turnoffmacros
3176174294Sobrien}
3177174294Sobrien
3178174294Sobrien% \commondummiesnofonts: common to \commondummies and \indexnofonts.
3179119679Smbr%
3180174294Sobrien% Better have this without active chars.
3181174294Sobrien{
3182174294Sobrien  \catcode`\~=\other
3183174294Sobrien  \gdef\commondummiesnofonts{%
3184174294Sobrien    % Control letters and accents.
3185174294Sobrien    \definedummyletter{!}%
3186174294Sobrien    \definedummyaccent{"}%
3187174294Sobrien    \definedummyaccent{'}%
3188174294Sobrien    \definedummyletter{*}%
3189174294Sobrien    \definedummyaccent{,}%
3190174294Sobrien    \definedummyletter{.}%
3191174294Sobrien    \definedummyletter{/}%
3192174294Sobrien    \definedummyletter{:}%
3193174294Sobrien    \definedummyaccent{=}%
3194174294Sobrien    \definedummyletter{?}%
3195174294Sobrien    \definedummyaccent{^}%
3196174294Sobrien    \definedummyaccent{`}%
3197174294Sobrien    \definedummyaccent{~}%
3198174294Sobrien    \definedummyword{u}%
3199174294Sobrien    \definedummyword{v}%
3200174294Sobrien    \definedummyword{H}%
3201174294Sobrien    \definedummyword{dotaccent}%
3202174294Sobrien    \definedummyword{ringaccent}%
3203174294Sobrien    \definedummyword{tieaccent}%
3204174294Sobrien    \definedummyword{ubaraccent}%
3205174294Sobrien    \definedummyword{udotaccent}%
3206174294Sobrien    \definedummyword{dotless}%
3207174294Sobrien    %
3208174294Sobrien    % Texinfo font commands.
3209174294Sobrien    \definedummyword{b}%
3210174294Sobrien    \definedummyword{i}%
3211174294Sobrien    \definedummyword{r}%
3212174294Sobrien    \definedummyword{sc}%
3213174294Sobrien    \definedummyword{t}%
3214174294Sobrien    %
3215174294Sobrien    % Commands that take arguments.
3216174294Sobrien    \definedummyword{acronym}%
3217174294Sobrien    \definedummyword{cite}%
3218174294Sobrien    \definedummyword{code}%
3219174294Sobrien    \definedummyword{command}%
3220174294Sobrien    \definedummyword{dfn}%
3221174294Sobrien    \definedummyword{emph}%
3222174294Sobrien    \definedummyword{env}%
3223174294Sobrien    \definedummyword{file}%
3224174294Sobrien    \definedummyword{kbd}%
3225174294Sobrien    \definedummyword{key}%
3226174294Sobrien    \definedummyword{math}%
3227174294Sobrien    \definedummyword{option}%
3228174294Sobrien    \definedummyword{samp}%
3229174294Sobrien    \definedummyword{strong}%
3230174294Sobrien    \definedummyword{tie}%
3231174294Sobrien    \definedummyword{uref}%
3232174294Sobrien    \definedummyword{url}%
3233174294Sobrien    \definedummyword{var}%
3234174294Sobrien    \definedummyword{verb}%
3235174294Sobrien    \definedummyword{w}%
3236174294Sobrien  }
323738494Sobrien}
323838494Sobrien
3239174294Sobrien% \indexnofonts is used when outputting the strings to sort the index
3240174294Sobrien% by, and when constructing control sequence names.  It eliminates all
3241174294Sobrien% control sequences and just writes whatever the best ASCII sort string
3242174294Sobrien% would be for a given command (usually its argument).
3243174294Sobrien%
324438494Sobrien\def\indexnofonts{%
3245174294Sobrien  % Accent commands should become @asis.
3246174294Sobrien  \def\definedummyaccent##1{%
3247174294Sobrien    \expandafter\let\csname ##1\endcsname\asis
3248174294Sobrien  }%
3249174294Sobrien  % We can just ignore other control letters.
3250174294Sobrien  \def\definedummyletter##1{%
3251174294Sobrien    \expandafter\def\csname ##1\endcsname{}%
3252174294Sobrien  }%
3253174294Sobrien  % Hopefully, all control words can become @asis.
3254174294Sobrien  \let\definedummyword\definedummyaccent
3255174294Sobrien  %
3256174294Sobrien  \commondummiesnofonts
3257174294Sobrien  %
3258174294Sobrien  % Don't no-op \tt, since it isn't a user-level command
3259174294Sobrien  % and is used in the definitions of the active chars like <, >, |, etc.
3260174294Sobrien  % Likewise with the other plain tex font commands.
3261174294Sobrien  %\let\tt=\asis
3262174294Sobrien  %
3263174294Sobrien  \def\ { }%
3264174294Sobrien  \def\@{@}%
3265174294Sobrien  % how to handle braces?
3266174294Sobrien  \def\_{\normalunderscore}%
3267174294Sobrien  %
3268174294Sobrien  % Non-English letters.
3269174294Sobrien  \def\AA{AA}%
3270174294Sobrien  \def\AE{AE}%
3271174294Sobrien  \def\L{L}%
3272174294Sobrien  \def\OE{OE}%
3273174294Sobrien  \def\O{O}%
3274174294Sobrien  \def\aa{aa}%
3275174294Sobrien  \def\ae{ae}%
3276174294Sobrien  \def\l{l}%
3277174294Sobrien  \def\oe{oe}%
3278174294Sobrien  \def\o{o}%
3279174294Sobrien  \def\ss{ss}%
3280174294Sobrien  \def\exclamdown{!}%
3281174294Sobrien  \def\questiondown{?}%
3282174294Sobrien  \def\ordf{a}%
3283174294Sobrien  \def\ordm{o}%
3284174294Sobrien  %
3285174294Sobrien  \def\LaTeX{LaTeX}%
3286174294Sobrien  \def\TeX{TeX}%
3287174294Sobrien  %
3288174294Sobrien  % Assorted special characters.
3289174294Sobrien  % (The following {} will end up in the sort string, but that's ok.)
3290174294Sobrien  \def\bullet{bullet}%
3291174294Sobrien  \def\comma{,}%
3292174294Sobrien  \def\copyright{copyright}%
3293174294Sobrien  \def\registeredsymbol{R}%
3294174294Sobrien  \def\dots{...}%
3295174294Sobrien  \def\enddots{...}%
3296174294Sobrien  \def\equiv{==}%
3297174294Sobrien  \def\error{error}%
3298174294Sobrien  \def\expansion{==>}%
3299174294Sobrien  \def\minus{-}%
3300174294Sobrien  \def\pounds{pounds}%
3301174294Sobrien  \def\point{.}%
3302174294Sobrien  \def\print{-|}%
3303174294Sobrien  \def\result{=>}%
3304174294Sobrien  %
3305174294Sobrien  % Don't write macro names.
3306174294Sobrien  \emptyusermacros
330738494Sobrien}
330838494Sobrien
330938494Sobrien\let\indexbackslash=0  %overridden during \printindex.
331042629Sobrien\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
331138494Sobrien
331242629Sobrien% Most index entries go through here, but \dosubind is the general case.
3313174294Sobrien% #1 is the index name, #2 is the entry text.
3314174294Sobrien\def\doind#1#2{\dosubind{#1}{#2}{}}
331542629Sobrien
331642629Sobrien% Workhorse for all \fooindexes.
331742629Sobrien% #1 is name of index, #2 is stuff to put there, #3 is subentry --
3318174294Sobrien% empty if called from \doind, as we usually are (the main exception
3319174294Sobrien% is with most defuns, which call us directly).
332082794Sobrien%
332142629Sobrien\def\dosubind#1#2#3{%
3322174294Sobrien  \iflinks
3323174294Sobrien  {%
3324174294Sobrien    % Store the main index entry text (including the third arg).
3325174294Sobrien    \toks0 = {#2}%
3326174294Sobrien    % If third arg is present, precede it with a space.
3327174294Sobrien    \def\thirdarg{#3}%
3328174294Sobrien    \ifx\thirdarg\empty \else
3329174294Sobrien      \toks0 = \expandafter{\the\toks0 \space #3}%
3330174294Sobrien    \fi
3331174294Sobrien    %
3332174294Sobrien    \edef\writeto{\csname#1indfile\endcsname}%
3333174294Sobrien    %
3334174294Sobrien    \ifvmode
3335174294Sobrien      \dosubindsanitize
3336174294Sobrien    \else
3337174294Sobrien      \dosubindwrite
3338174294Sobrien    \fi
3339174294Sobrien  }%
3340174294Sobrien  \fi
3341174294Sobrien}
3342174294Sobrien
3343174294Sobrien% Write the entry in \toks0 to the index file:
3344174294Sobrien%
3345174294Sobrien\def\dosubindwrite{%
334638494Sobrien  % Put the index entry in the margin if desired.
334738494Sobrien  \ifx\SETmarginindex\relax\else
3348174294Sobrien    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
334938494Sobrien  \fi
3350174294Sobrien  %
3351174294Sobrien  % Remember, we are within a group.
3352174294Sobrien  \indexdummies % Must do this here, since \bf, etc expand at this stage
3353174294Sobrien  \escapechar=`\\
3354174294Sobrien  \def\backslashcurfont{\indexbackslash}% \indexbackslash isn't defined now
3355174294Sobrien      % so it will be output as is; and it will print as backslash.
3356174294Sobrien  %
3357174294Sobrien  % Process the index entry with all font commands turned off, to
3358174294Sobrien  % get the string to sort by.
3359174294Sobrien  {\indexnofonts
3360174294Sobrien   \edef\temp{\the\toks0}% need full expansion
3361174294Sobrien   \xdef\indexsorttmp{\temp}%
336238494Sobrien  }%
3363174294Sobrien  %
3364174294Sobrien  % Set up the complete index entry, with both the sort key and
3365174294Sobrien  % the original text, including any font commands.  We write
3366174294Sobrien  % three arguments to \entry to the .?? file (four in the
3367174294Sobrien  % subentry case), texindex reduces to two when writing the .??s
3368174294Sobrien  % sorted result.
3369174294Sobrien  \edef\temp{%
3370174294Sobrien    \write\writeto{%
3371174294Sobrien      \string\entry{\indexsorttmp}{\noexpand\folio}{\the\toks0}}%
3372174294Sobrien  }%
3373174294Sobrien  \temp
337438494Sobrien}
337538494Sobrien
3376174294Sobrien% Take care of unwanted page breaks:
3377174294Sobrien%
3378174294Sobrien% If a skip is the last thing on the list now, preserve it
3379174294Sobrien% by backing up by \lastskip, doing the \write, then inserting
3380174294Sobrien% the skip again.  Otherwise, the whatsit generated by the
3381174294Sobrien% \write will make \lastskip zero.  The result is that sequences
3382174294Sobrien% like this:
3383174294Sobrien% @end defun
3384174294Sobrien% @tindex whatever
3385174294Sobrien% @defun ...
3386174294Sobrien% will have extra space inserted, because the \medbreak in the
3387174294Sobrien% start of the @defun won't see the skip inserted by the @end of
3388174294Sobrien% the previous defun.
3389174294Sobrien%
3390174294Sobrien% But don't do any of this if we're not in vertical mode.  We
3391174294Sobrien% don't want to do a \vskip and prematurely end a paragraph.
3392174294Sobrien%
3393174294Sobrien% Avoid page breaks due to these extra skips, too.
3394174294Sobrien%
3395174294Sobrien% But wait, there is a catch there:
3396174294Sobrien% We'll have to check whether \lastskip is zero skip.  \ifdim is not
3397174294Sobrien% sufficient for this purpose, as it ignores stretch and shrink parts
3398174294Sobrien% of the skip.  The only way seems to be to check the textual
3399174294Sobrien% representation of the skip.
3400174294Sobrien%
3401174294Sobrien% The following is almost like \def\zeroskipmacro{0.0pt} except that
3402174294Sobrien% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
3403174294Sobrien%
3404174294Sobrien\edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
3405174294Sobrien%
3406174294Sobrien% ..., ready, GO:
3407174294Sobrien%
3408174294Sobrien\def\dosubindsanitize{%
3409174294Sobrien  % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
3410174294Sobrien  \skip0 = \lastskip
3411174294Sobrien  \edef\lastskipmacro{\the\lastskip}%
3412174294Sobrien  \count255 = \lastpenalty
3413174294Sobrien  %
3414174294Sobrien  % If \lastskip is nonzero, that means the last item was a
3415174294Sobrien  % skip.  And since a skip is discardable, that means this
3416174294Sobrien  % -\skip0 glue we're inserting is preceded by a
3417174294Sobrien  % non-discardable item, therefore it is not a potential
3418174294Sobrien  % breakpoint, therefore no \nobreak needed.
3419174294Sobrien  \ifx\lastskipmacro\zeroskipmacro
3420174294Sobrien  \else
3421174294Sobrien    \vskip-\skip0
3422174294Sobrien  \fi
3423174294Sobrien  %
3424174294Sobrien  \dosubindwrite
3425174294Sobrien  %
3426174294Sobrien  \ifx\lastskipmacro\zeroskipmacro
3427174294Sobrien    % If \lastskip was zero, perhaps the last item was a penalty, and
3428174294Sobrien    % perhaps it was >=10000, e.g., a \nobreak.  In that case, we want
3429174294Sobrien    % to re-insert the same penalty (values >10000 are used for various
3430174294Sobrien    % signals); since we just inserted a non-discardable item, any
3431174294Sobrien    % following glue (such as a \parskip) would be a breakpoint.  For example:
3432174294Sobrien    % 
3433174294Sobrien    %   @deffn deffn-whatever
3434174294Sobrien    %   @vindex index-whatever
3435174294Sobrien    %   Description.
3436174294Sobrien    % would allow a break between the index-whatever whatsit
3437174294Sobrien    % and the "Description." paragraph.
3438174294Sobrien    \ifnum\count255>9999 \penalty\count255 \fi
3439174294Sobrien  \else
3440174294Sobrien    % On the other hand, if we had a nonzero \lastskip,
3441174294Sobrien    % this make-up glue would be preceded by a non-discardable item
3442174294Sobrien    % (the whatsit from the \write), so we must insert a \nobreak.
3443174294Sobrien    \nobreak\vskip\skip0
3444174294Sobrien  \fi
3445174294Sobrien}
3446174294Sobrien
344738494Sobrien% The index entry written in the file actually looks like
344838494Sobrien%  \entry {sortstring}{page}{topic}
344938494Sobrien% or
345038494Sobrien%  \entry {sortstring}{page}{topic}{subtopic}
345138494Sobrien% The texindex program reads in these files and writes files
345238494Sobrien% containing these kinds of lines:
345338494Sobrien%  \initial {c}
345438494Sobrien%     before the first topic whose initial is c
345538494Sobrien%  \entry {topic}{pagelist}
345638494Sobrien%     for a topic that is used without subtopics
345738494Sobrien%  \primary {topic}
345838494Sobrien%     for the beginning of a topic that is used with subtopics
345938494Sobrien%  \secondary {subtopic}{pagelist}
346038494Sobrien%     for each subtopic.
346138494Sobrien
346238494Sobrien% Define the user-accessible indexing commands
346338494Sobrien% @findex, @vindex, @kindex, @cindex.
346438494Sobrien
346538494Sobrien\def\findex {\fnindex}
346638494Sobrien\def\kindex {\kyindex}
346738494Sobrien\def\cindex {\cpindex}
346838494Sobrien\def\vindex {\vrindex}
346938494Sobrien\def\tindex {\tpindex}
347038494Sobrien\def\pindex {\pgindex}
347138494Sobrien
347238494Sobrien\def\cindexsub {\begingroup\obeylines\cindexsub}
347338494Sobrien{\obeylines %
347438494Sobrien\gdef\cindexsub "#1" #2^^M{\endgroup %
347538494Sobrien\dosubind{cp}{#2}{#1}}}
347638494Sobrien
347738494Sobrien% Define the macros used in formatting output of the sorted index material.
347838494Sobrien
347938494Sobrien% @printindex causes a particular index (the ??s file) to get printed.
348038494Sobrien% It does not print any chapter heading (usually an @unnumbered).
348138494Sobrien%
3482174294Sobrien\parseargdef\printindex{\begingroup
348338494Sobrien  \dobreak \chapheadingskip{10000}%
348438494Sobrien  %
348582794Sobrien  \smallfonts \rm
348638494Sobrien  \tolerance = 9500
3487174294Sobrien  \everypar = {}% don't want the \kern\-parindent from indentation suppression.
348838494Sobrien  %
348938494Sobrien  % See if the index file exists and is nonempty.
349042629Sobrien  % Change catcode of @ here so that if the index file contains
349142629Sobrien  % \initial {@}
349242629Sobrien  % as its first line, TeX doesn't complain about mismatched braces
349342629Sobrien  % (because it thinks @} is a control sequence).
349442629Sobrien  \catcode`\@ = 11
349538494Sobrien  \openin 1 \jobname.#1s
349638494Sobrien  \ifeof 1
349738494Sobrien    % \enddoublecolumns gets confused if there is no text in the index,
349838494Sobrien    % and it loses the chapter title and the aux file entries for the
349938494Sobrien    % index.  The easiest way to prevent this problem is to make sure
350038494Sobrien    % there is some text.
350182794Sobrien    \putwordIndexNonexistent
350238494Sobrien  \else
350338494Sobrien    %
350438494Sobrien    % If the index file exists but is empty, then \openin leaves \ifeof
350538494Sobrien    % false.  We have to make TeX try to read something from the file, so
350638494Sobrien    % it can discover if there is anything in it.
350738494Sobrien    \read 1 to \temp
350838494Sobrien    \ifeof 1
350982794Sobrien      \putwordIndexIsEmpty
351038494Sobrien    \else
351138494Sobrien      % Index files are almost Texinfo source, but we use \ as the escape
351238494Sobrien      % character.  It would be better to use @, but that's too big a change
351338494Sobrien      % to make right now.
3514174294Sobrien      \def\indexbackslash{\backslashcurfont}%
351538494Sobrien      \catcode`\\ = 0
351638494Sobrien      \escapechar = `\\
351738494Sobrien      \begindoublecolumns
351838494Sobrien      \input \jobname.#1s
351938494Sobrien      \enddoublecolumns
352038494Sobrien    \fi
352138494Sobrien  \fi
352238494Sobrien  \closein 1
352338494Sobrien\endgroup}
352438494Sobrien
352538494Sobrien% These macros are used by the sorted index file itself.
352638494Sobrien% Change them to control the appearance of the index.
352738494Sobrien
352842629Sobrien\def\initial#1{{%
352942629Sobrien  % Some minor font changes for the special characters.
353042629Sobrien  \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
353142629Sobrien  %
353242629Sobrien  % Remove any glue we may have, we'll be inserting our own.
353342629Sobrien  \removelastskip
353482794Sobrien  %
353542629Sobrien  % We like breaks before the index initials, so insert a bonus.
3536174294Sobrien  \nobreak
3537174294Sobrien  \vskip 0pt plus 3\baselineskip
3538174294Sobrien  \penalty 0
3539174294Sobrien  \vskip 0pt plus -3\baselineskip
354042629Sobrien  %
354142629Sobrien  % Typeset the initial.  Making this add up to a whole number of
354242629Sobrien  % baselineskips increases the chance of the dots lining up from column
354342629Sobrien  % to column.  It still won't often be perfect, because of the stretch
354442629Sobrien  % we need before each entry, but it's better.
354582794Sobrien  %
354642629Sobrien  % No shrink because it confuses \balancecolumns.
354742629Sobrien  \vskip 1.67\baselineskip plus .5\baselineskip
354842629Sobrien  \leftline{\secbf #1}%
354942629Sobrien  % Do our best not to break after the initial.
355042629Sobrien  \nobreak
3551174294Sobrien  \vskip .33\baselineskip plus .1\baselineskip
355242629Sobrien}}
355338494Sobrien
3554174294Sobrien% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
3555174294Sobrien% then page number (#2) flushed to the right margin.  It is used for index
3556174294Sobrien% and table of contents entries.  The paragraph is indented by \leftskip.
355738494Sobrien%
3558174294Sobrien% A straightforward implementation would start like this:
3559174294Sobrien%	\def\entry#1#2{...
3560174294Sobrien% But this frozes the catcodes in the argument, and can cause problems to
3561174294Sobrien% @code, which sets - active.  This problem was fixed by a kludge---
3562174294Sobrien% ``-'' was active throughout whole index, but this isn't really right.
3563174294Sobrien%
3564174294Sobrien% The right solution is to prevent \entry from swallowing the whole text.
3565174294Sobrien%                                 --kasal, 21nov03
3566174294Sobrien\def\entry{%
3567174294Sobrien  \begingroup
356838494Sobrien    %
3569174294Sobrien    % Start a new paragraph if necessary, so our assignments below can't
3570174294Sobrien    % affect previous text.
3571174294Sobrien    \par
357238494Sobrien    %
3573174294Sobrien    % Do not fill out the last line with white space.
3574174294Sobrien    \parfillskip = 0in
3575174294Sobrien    %
3576174294Sobrien    % No extra space above this paragraph.
3577174294Sobrien    \parskip = 0in
3578174294Sobrien    %
3579174294Sobrien    % Do not prefer a separate line ending with a hyphen to fewer lines.
3580174294Sobrien    \finalhyphendemerits = 0
3581174294Sobrien    %
3582174294Sobrien    % \hangindent is only relevant when the entry text and page number
3583174294Sobrien    % don't both fit on one line.  In that case, bob suggests starting the
3584174294Sobrien    % dots pretty far over on the line.  Unfortunately, a large
3585174294Sobrien    % indentation looks wrong when the entry text itself is broken across
3586174294Sobrien    % lines.  So we use a small indentation and put up with long leaders.
3587174294Sobrien    %
3588174294Sobrien    % \hangafter is reset to 1 (which is the value we want) at the start
3589174294Sobrien    % of each paragraph, so we need not do anything with that.
3590174294Sobrien    \hangindent = 2em
3591174294Sobrien    %
3592174294Sobrien    % When the entry text needs to be broken, just fill out the first line
3593174294Sobrien    % with blank space.
3594174294Sobrien    \rightskip = 0pt plus1fil
3595174294Sobrien    %
3596174294Sobrien    % A bit of stretch before each entry for the benefit of balancing
3597174294Sobrien    % columns.
3598174294Sobrien    \vskip 0pt plus1pt
3599174294Sobrien    %
3600174294Sobrien    % Swallow the left brace of the text (first parameter):
3601174294Sobrien    \afterassignment\doentry
3602174294Sobrien    \let\temp =
3603174294Sobrien}
3604174294Sobrien\def\doentry{%
3605174294Sobrien    \bgroup % Instead of the swallowed brace.
3606174294Sobrien      \noindent
3607174294Sobrien      \aftergroup\finishentry
3608174294Sobrien      % And now comes the text of the entry.
3609174294Sobrien}
3610174294Sobrien\def\finishentry#1{%
3611174294Sobrien    % #1 is the page number.
3612174294Sobrien    %
3613174294Sobrien    % The following is kludged to not output a line of dots in the index if
3614174294Sobrien    % there are no page numbers.  The next person who breaks this will be
3615174294Sobrien    % cursed by a Unix daemon.
3616174294Sobrien    \def\tempa{{\rm }}%
3617174294Sobrien    \def\tempb{#1}%
3618174294Sobrien    \edef\tempc{\tempa}%
3619174294Sobrien    \edef\tempd{\tempb}%
3620174294Sobrien    \ifx\tempc\tempd
3621174294Sobrien      \ %
362282794Sobrien    \else
3623174294Sobrien      %
3624174294Sobrien      % If we must, put the page number on a line of its own, and fill out
3625174294Sobrien      % this line with blank space.  (The \hfil is overwhelmed with the
3626174294Sobrien      % fill leaders glue in \indexdotfill if the page number does fit.)
3627174294Sobrien      \hfil\penalty50
3628174294Sobrien      \null\nobreak\indexdotfill % Have leaders before the page number.
3629174294Sobrien      %
3630174294Sobrien      % The `\ ' here is removed by the implicit \unskip that TeX does as
3631174294Sobrien      % part of (the primitive) \par.  Without it, a spurious underfull
3632174294Sobrien      % \hbox ensues.
3633174294Sobrien      \ifpdf
3634174294Sobrien	\pdfgettoks#1.%
3635174294Sobrien	\ \the\toksA
3636174294Sobrien      \else
3637174294Sobrien	\ #1%
3638174294Sobrien      \fi
363982794Sobrien    \fi
3640174294Sobrien    \par
3641174294Sobrien  \endgroup
3642174294Sobrien}
364338494Sobrien
364438494Sobrien% Like \dotfill except takes at least 1 em.
364538494Sobrien\def\indexdotfill{\cleaders
364638494Sobrien  \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
364738494Sobrien
364838494Sobrien\def\primary #1{\line{#1\hfil}}
364938494Sobrien
365038494Sobrien\newskip\secondaryindent \secondaryindent=0.5cm
365182794Sobrien\def\secondary#1#2{{%
365282794Sobrien  \parfillskip=0in
365382794Sobrien  \parskip=0in
365482794Sobrien  \hangindent=1in
365582794Sobrien  \hangafter=1
365682794Sobrien  \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
365782794Sobrien  \ifpdf
365882794Sobrien    \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
365982794Sobrien  \else
366082794Sobrien    #2
366182794Sobrien  \fi
366282794Sobrien  \par
366338494Sobrien}}
366438494Sobrien
366538494Sobrien% Define two-column mode, which we use to typeset indexes.
366638494Sobrien% Adapted from the TeXbook, page 416, which is to say,
366738494Sobrien% the manmac.tex format used to print the TeXbook itself.
366838494Sobrien\catcode`\@=11
366938494Sobrien
367038494Sobrien\newbox\partialpage
367138494Sobrien\newdimen\doublecolumnhsize
367238494Sobrien
367338494Sobrien\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
367438494Sobrien  % Grab any single-column material above us.
367582794Sobrien  \output = {%
367682794Sobrien    %
367738494Sobrien    % Here is a possibility not foreseen in manmac: if we accumulate a
367838494Sobrien    % whole lot of material, we might end up calling this \output
367938494Sobrien    % routine twice in a row (see the doublecol-lose test, which is
368038494Sobrien    % essentially a couple of indexes with @setchapternewpage off).  In
368182794Sobrien    % that case we just ship out what is in \partialpage with the normal
368282794Sobrien    % output routine.  Generally, \partialpage will be empty when this
368382794Sobrien    % runs and this will be a no-op.  See the indexspread.tex test case.
368482794Sobrien    \ifvoid\partialpage \else
368582794Sobrien      \onepageout{\pagecontents\partialpage}%
368682794Sobrien    \fi
368738494Sobrien    %
368882794Sobrien    \global\setbox\partialpage = \vbox{%
368982794Sobrien      % Unvbox the main output page.
369082794Sobrien      \unvbox\PAGE
369182794Sobrien      \kern-\topskip \kern\baselineskip
369282794Sobrien    }%
369382794Sobrien  }%
369482794Sobrien  \eject % run that output routine to set \partialpage
369538494Sobrien  %
369638494Sobrien  % Use the double-column output routine for subsequent pages.
369738494Sobrien  \output = {\doublecolumnout}%
369838494Sobrien  %
369938494Sobrien  % Change the page size parameters.  We could do this once outside this
370038494Sobrien  % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
370138494Sobrien  % format, but then we repeat the same computation.  Repeating a couple
370238494Sobrien  % of assignments once per index is clearly meaningless for the
370338494Sobrien  % execution time, so we may as well do it in one place.
370438494Sobrien  %
370538494Sobrien  % First we halve the line length, less a little for the gutter between
370638494Sobrien  % the columns.  We compute the gutter based on the line length, so it
370738494Sobrien  % changes automatically with the paper format.  The magic constant
370838494Sobrien  % below is chosen so that the gutter has the same value (well, +-<1pt)
370938494Sobrien  % as it did when we hard-coded it.
371038494Sobrien  %
371138494Sobrien  % We put the result in a separate register, \doublecolumhsize, so we
371238494Sobrien  % can restore it in \pagesofar, after \hsize itself has (potentially)
371338494Sobrien  % been clobbered.
371438494Sobrien  %
371538494Sobrien  \doublecolumnhsize = \hsize
371638494Sobrien    \advance\doublecolumnhsize by -.04154\hsize
371738494Sobrien    \divide\doublecolumnhsize by 2
371838494Sobrien  \hsize = \doublecolumnhsize
371938494Sobrien  %
372038494Sobrien  % Double the \vsize as well.  (We don't need a separate register here,
372138494Sobrien  % since nobody clobbers \vsize.)
372238494Sobrien  \vsize = 2\vsize
372338494Sobrien}
372442629Sobrien
372542629Sobrien% The double-column output routine for all double-column pages except
372642629Sobrien% the last.
372782794Sobrien%
372838494Sobrien\def\doublecolumnout{%
372938494Sobrien  \splittopskip=\topskip \splitmaxdepth=\maxdepth
373038494Sobrien  % Get the available space for the double columns -- the normal
373138494Sobrien  % (undoubled) page height minus any material left over from the
373238494Sobrien  % previous page.
373342629Sobrien  \dimen@ = \vsize
373442629Sobrien  \divide\dimen@ by 2
373582794Sobrien  \advance\dimen@ by -\ht\partialpage
373642629Sobrien  %
373738494Sobrien  % box0 will be the left-hand column, box2 the right.
373838494Sobrien  \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
373938494Sobrien  \onepageout\pagesofar
374038494Sobrien  \unvbox255
374138494Sobrien  \penalty\outputpenalty
374238494Sobrien}
374382794Sobrien%
374482794Sobrien% Re-output the contents of the output page -- any previous material,
374582794Sobrien% followed by the two boxes we just split, in box0 and box2.
374638494Sobrien\def\pagesofar{%
374738494Sobrien  \unvbox\partialpage
374842629Sobrien  %
374938494Sobrien  \hsize = \doublecolumnhsize
375042629Sobrien  \wd0=\hsize \wd2=\hsize
375142629Sobrien  \hbox to\pagewidth{\box0\hfil\box2}%
375238494Sobrien}
3753174294Sobrien%
375482794Sobrien% All done with double columns.
375538494Sobrien\def\enddoublecolumns{%
375642629Sobrien  \output = {%
375782794Sobrien    % Split the last of the double-column material.  Leave it on the
375842629Sobrien    % current page, no automatic page break.
375942629Sobrien    \balancecolumns
376042629Sobrien    %
376142629Sobrien    % If we end up splitting too much material for the current page,
376242629Sobrien    % though, there will be another page break right after this \output
376342629Sobrien    % invocation ends.  Having called \balancecolumns once, we do not
376442629Sobrien    % want to call it again.  Therefore, reset \output to its normal
376542629Sobrien    % definition right away.  (We hope \balancecolumns will never be
376642629Sobrien    % called on to balance too much material, but if it is, this makes
376742629Sobrien    % the output somewhat more palatable.)
376842629Sobrien    \global\output = {\onepageout{\pagecontents\PAGE}}%
376942629Sobrien  }%
377042629Sobrien  \eject
377138494Sobrien  \endgroup % started in \begindoublecolumns
377282794Sobrien  %
377382794Sobrien  % \pagegoal was set to the doubled \vsize above, since we restarted
377482794Sobrien  % the current page.  We're now back to normal single-column
377582794Sobrien  % typesetting, so reset \pagegoal to the normal \vsize (after the
377682794Sobrien  % \endgroup where \vsize got restored).
377782794Sobrien  \pagegoal = \vsize
377838494Sobrien}
377982794Sobrien%
378082794Sobrien% Called at the end of the double column material.
378138494Sobrien\def\balancecolumns{%
378242629Sobrien  \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
378338494Sobrien  \dimen@ = \ht0
378438494Sobrien  \advance\dimen@ by \topskip
378538494Sobrien  \advance\dimen@ by-\baselineskip
378642629Sobrien  \divide\dimen@ by 2 % target to split to
378742629Sobrien  %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}%
378838494Sobrien  \splittopskip = \topskip
378938494Sobrien  % Loop until we get a decent breakpoint.
379042629Sobrien  {%
379142629Sobrien    \vbadness = 10000
379242629Sobrien    \loop
379342629Sobrien      \global\setbox3 = \copy0
379442629Sobrien      \global\setbox1 = \vsplit3 to \dimen@
379542629Sobrien    \ifdim\ht3>\dimen@
379642629Sobrien      \global\advance\dimen@ by 1pt
379742629Sobrien    \repeat
379842629Sobrien  }%
379942629Sobrien  %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}%
380038494Sobrien  \setbox0=\vbox to\dimen@{\unvbox1}%
380138494Sobrien  \setbox2=\vbox to\dimen@{\unvbox3}%
380242629Sobrien  %
380338494Sobrien  \pagesofar
380438494Sobrien}
380538494Sobrien\catcode`\@ = \other
380638494Sobrien
380738494Sobrien
380838494Sobrien\message{sectioning,}
380982794Sobrien% Chapters, sections, etc.
381038494Sobrien
3811174294Sobrien% \unnumberedno is an oxymoron, of course.  But we count the unnumbered
3812174294Sobrien% sections so that we can refer to them unambiguously in the pdf
3813174294Sobrien% outlines by their "section number".  We avoid collisions with chapter
3814174294Sobrien% numbers by starting them at 10000.  (If a document ever has 10000
3815174294Sobrien% chapters, we're in trouble anyway, I'm sure.)
3816174294Sobrien\newcount\unnumberedno \unnumberedno = 10000
381738494Sobrien\newcount\chapno
381838494Sobrien\newcount\secno        \secno=0
381938494Sobrien\newcount\subsecno     \subsecno=0
382038494Sobrien\newcount\subsubsecno  \subsubsecno=0
382138494Sobrien
382238494Sobrien% This counter is funny since it counts through charcodes of letters A, B, ...
382338494Sobrien\newcount\appendixno  \appendixno = `\@
3824174294Sobrien%
382582794Sobrien% \def\appendixletter{\char\the\appendixno}
3826174294Sobrien% We do the following ugly conditional instead of the above simple
3827174294Sobrien% construct for the sake of pdftex, which needs the actual
382882794Sobrien% letter in the expansion, not just typeset.
3829174294Sobrien%
383082794Sobrien\def\appendixletter{%
383182794Sobrien  \ifnum\appendixno=`A A%
383282794Sobrien  \else\ifnum\appendixno=`B B%
383382794Sobrien  \else\ifnum\appendixno=`C C%
383482794Sobrien  \else\ifnum\appendixno=`D D%
383582794Sobrien  \else\ifnum\appendixno=`E E%
383682794Sobrien  \else\ifnum\appendixno=`F F%
383782794Sobrien  \else\ifnum\appendixno=`G G%
383882794Sobrien  \else\ifnum\appendixno=`H H%
383982794Sobrien  \else\ifnum\appendixno=`I I%
384082794Sobrien  \else\ifnum\appendixno=`J J%
384182794Sobrien  \else\ifnum\appendixno=`K K%
384282794Sobrien  \else\ifnum\appendixno=`L L%
384382794Sobrien  \else\ifnum\appendixno=`M M%
384482794Sobrien  \else\ifnum\appendixno=`N N%
384582794Sobrien  \else\ifnum\appendixno=`O O%
384682794Sobrien  \else\ifnum\appendixno=`P P%
384782794Sobrien  \else\ifnum\appendixno=`Q Q%
384882794Sobrien  \else\ifnum\appendixno=`R R%
384982794Sobrien  \else\ifnum\appendixno=`S S%
385082794Sobrien  \else\ifnum\appendixno=`T T%
385182794Sobrien  \else\ifnum\appendixno=`U U%
385282794Sobrien  \else\ifnum\appendixno=`V V%
385382794Sobrien  \else\ifnum\appendixno=`W W%
385482794Sobrien  \else\ifnum\appendixno=`X X%
385582794Sobrien  \else\ifnum\appendixno=`Y Y%
385682794Sobrien  \else\ifnum\appendixno=`Z Z%
385782794Sobrien  % The \the is necessary, despite appearances, because \appendixletter is
385882794Sobrien  % expanded while writing the .toc file.  \char\appendixno is not
385982794Sobrien  % expandable, thus it is written literally, thus all appendixes come out
386082794Sobrien  % with the same letter (or @) in the toc without it.
386182794Sobrien  \else\char\the\appendixno
386282794Sobrien  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
386382794Sobrien  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
386438494Sobrien
386538494Sobrien% Each @chapter defines this as the name of the chapter.
386642629Sobrien% page headings and footings can use it.  @section does likewise.
3867174294Sobrien% However, they are not reliable, because we don't use marks.
386842629Sobrien\def\thischapter{}
386942629Sobrien\def\thissection{}
387038494Sobrien
387138494Sobrien\newcount\absseclevel % used to calculate proper heading level
3872174294Sobrien\newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
387338494Sobrien
387438494Sobrien% @raisesections: treat @section as chapter, @subsection as section, etc.
387538494Sobrien\def\raisesections{\global\advance\secbase by -1}
387638494Sobrien\let\up=\raisesections % original BFox name
387738494Sobrien
387838494Sobrien% @lowersections: treat @chapter as section, @section as subsection, etc.
387938494Sobrien\def\lowersections{\global\advance\secbase by 1}
388038494Sobrien\let\down=\lowersections % original BFox name
388138494Sobrien
3882174294Sobrien% we only have subsub.
3883174294Sobrien\chardef\maxseclevel = 3
3884174294Sobrien%
3885174294Sobrien% A numbered section within an unnumbered changes to unnumbered too.
3886174294Sobrien% To achive this, remember the "biggest" unnum. sec. we are currently in:
3887174294Sobrien\chardef\unmlevel = \maxseclevel
3888174294Sobrien%
3889174294Sobrien% Trace whether the current chapter is an appendix or not:
3890174294Sobrien% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
3891174294Sobrien\def\chapheadtype{N}
3892174294Sobrien
3893174294Sobrien% Choose a heading macro
3894174294Sobrien% #1 is heading type
3895174294Sobrien% #2 is heading level
3896174294Sobrien% #3 is text for heading
3897174294Sobrien\def\genhead#1#2#3{%
3898174294Sobrien  % Compute the abs. sec. level:
3899174294Sobrien  \absseclevel=#2
3900174294Sobrien  \advance\absseclevel by \secbase
3901174294Sobrien  % Make sure \absseclevel doesn't fall outside the range:
3902174294Sobrien  \ifnum \absseclevel < 0
3903174294Sobrien    \absseclevel = 0
390438494Sobrien  \else
3905174294Sobrien    \ifnum \absseclevel > 3
3906174294Sobrien      \absseclevel = 3
3907174294Sobrien    \fi
390838494Sobrien  \fi
3909174294Sobrien  % The heading type:
3910174294Sobrien  \def\headtype{#1}%
3911174294Sobrien  \if \headtype U%
3912174294Sobrien    \ifnum \absseclevel < \unmlevel
3913174294Sobrien      \chardef\unmlevel = \absseclevel
3914174294Sobrien    \fi
391538494Sobrien  \else
3916174294Sobrien    % Check for appendix sections:
3917174294Sobrien    \ifnum \absseclevel = 0
3918174294Sobrien      \edef\chapheadtype{\headtype}%
3919174294Sobrien    \else
3920174294Sobrien      \if \headtype A\if \chapheadtype N%
3921174294Sobrien	\errmessage{@appendix... within a non-appendix chapter}%
3922174294Sobrien      \fi\fi
3923174294Sobrien    \fi
3924174294Sobrien    % Check for numbered within unnumbered:
3925174294Sobrien    \ifnum \absseclevel > \unmlevel
3926174294Sobrien      \def\headtype{U}%
3927174294Sobrien    \else
3928174294Sobrien      \chardef\unmlevel = 3
3929174294Sobrien    \fi
393038494Sobrien  \fi
3931174294Sobrien  % Now print the heading:
3932174294Sobrien  \if \headtype U%
3933174294Sobrien    \ifcase\absseclevel
3934174294Sobrien	\unnumberedzzz{#3}%
3935174294Sobrien    \or \unnumberedseczzz{#3}%
3936174294Sobrien    \or \unnumberedsubseczzz{#3}%
3937174294Sobrien    \or \unnumberedsubsubseczzz{#3}%
3938174294Sobrien    \fi
393938494Sobrien  \else
3940174294Sobrien    \if \headtype A%
3941174294Sobrien      \ifcase\absseclevel
3942174294Sobrien	  \appendixzzz{#3}%
3943174294Sobrien      \or \appendixsectionzzz{#3}%
3944174294Sobrien      \or \appendixsubseczzz{#3}%
3945174294Sobrien      \or \appendixsubsubseczzz{#3}%
3946174294Sobrien      \fi
3947174294Sobrien    \else
3948174294Sobrien      \ifcase\absseclevel
3949174294Sobrien	  \chapterzzz{#3}%
3950174294Sobrien      \or \seczzz{#3}%
3951174294Sobrien      \or \numberedsubseczzz{#3}%
3952174294Sobrien      \or \numberedsubsubseczzz{#3}%
3953174294Sobrien      \fi
3954174294Sobrien    \fi
395538494Sobrien  \fi
3956174294Sobrien  \suppressfirstparagraphindent
395738494Sobrien}
395838494Sobrien
3959174294Sobrien% an interface:
3960174294Sobrien\def\numhead{\genhead N}
3961174294Sobrien\def\apphead{\genhead A}
3962174294Sobrien\def\unnmhead{\genhead U}
3963174294Sobrien
3964174294Sobrien% @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
3965174294Sobrien% all lower-level sectioning counters to zero.
3966174294Sobrien%
3967174294Sobrien% Also set \chaplevelprefix, which we prepend to @float sequence numbers
3968174294Sobrien% (e.g., figures), q.v.  By default (before any chapter), that is empty.
3969174294Sobrien\let\chaplevelprefix = \empty
3970174294Sobrien%
3971174294Sobrien\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
3972174294Sobrien\def\chapterzzz#1{%
3973174294Sobrien  % section resetting is \global in case the chapter is in a group, such
3974174294Sobrien  % as an @include file.
3975174294Sobrien  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
3976174294Sobrien    \global\advance\chapno by 1
3977174294Sobrien  %
3978174294Sobrien  % Used for \float.
3979174294Sobrien  \gdef\chaplevelprefix{\the\chapno.}%
3980174294Sobrien  \resetallfloatnos
3981174294Sobrien  %
3982174294Sobrien  \message{\putwordChapter\space \the\chapno}%
3983174294Sobrien  %
3984174294Sobrien  % Write the actual heading.
3985174294Sobrien  \chapmacro{#1}{Ynumbered}{\the\chapno}%
3986174294Sobrien  %
3987174294Sobrien  % So @section and the like are numbered underneath this chapter.
3988174294Sobrien  \global\let\section = \numberedsec
3989174294Sobrien  \global\let\subsection = \numberedsubsec
3990174294Sobrien  \global\let\subsubsection = \numberedsubsubsec
399142629Sobrien}
399238494Sobrien
3993174294Sobrien\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
3994174294Sobrien\def\appendixzzz#1{%
3995174294Sobrien  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
3996174294Sobrien    \global\advance\appendixno by 1
3997174294Sobrien  \gdef\chaplevelprefix{\appendixletter.}%
3998174294Sobrien  \resetallfloatnos
3999174294Sobrien  %
4000174294Sobrien  \def\appendixnum{\putwordAppendix\space \appendixletter}%
4001174294Sobrien  \message{\appendixnum}%
4002174294Sobrien  %
4003174294Sobrien  \chapmacro{#1}{Yappendix}{\appendixletter}%
4004174294Sobrien  %
4005174294Sobrien  \global\let\section = \appendixsec
4006174294Sobrien  \global\let\subsection = \appendixsubsec
4007174294Sobrien  \global\let\subsubsection = \appendixsubsubsec
400842629Sobrien}
400938494Sobrien
4010174294Sobrien\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
4011174294Sobrien\def\unnumberedzzz#1{%
4012174294Sobrien  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
4013174294Sobrien    \global\advance\unnumberedno by 1
4014174294Sobrien  %
4015174294Sobrien  % Since an unnumbered has no number, no prefix for figures.
4016174294Sobrien  \global\let\chaplevelprefix = \empty
4017174294Sobrien  \resetallfloatnos
4018174294Sobrien  %
4019174294Sobrien  % This used to be simply \message{#1}, but TeX fully expands the
4020174294Sobrien  % argument to \message.  Therefore, if #1 contained @-commands, TeX
4021174294Sobrien  % expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
4022174294Sobrien  % expanded @cite (which turns out to cause errors because \cite is meant
4023174294Sobrien  % to be executed, not expanded).
4024174294Sobrien  %
4025174294Sobrien  % Anyway, we don't want the fully-expanded definition of @cite to appear
4026174294Sobrien  % as a result of the \message, we just want `@cite' itself.  We use
4027174294Sobrien  % \the<toks register> to achieve this: TeX expands \the<toks> only once,
4028174294Sobrien  % simply yielding the contents of <toks register>.  (We also do this for
4029174294Sobrien  % the toc entries.)
4030174294Sobrien  \toks0 = {#1}%
4031174294Sobrien  \message{(\the\toks0)}%
4032174294Sobrien  %
4033174294Sobrien  \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
4034174294Sobrien  %
4035174294Sobrien  \global\let\section = \unnumberedsec
4036174294Sobrien  \global\let\subsection = \unnumberedsubsec
4037174294Sobrien  \global\let\subsubsection = \unnumberedsubsubsec
4038174294Sobrien}
4039174294Sobrien
404038494Sobrien% @centerchap is like @unnumbered, but the heading is centered.
4041174294Sobrien\outer\parseargdef\centerchap{%
4042174294Sobrien  % Well, we could do the following in a group, but that would break
4043174294Sobrien  % an assumption that \chapmacro is called at the outermost level.
4044174294Sobrien  % Thus we are safer this way:		--kasal, 24feb04
4045174294Sobrien  \let\centerparametersmaybe = \centerparameters
4046174294Sobrien  \unnmhead0{#1}%
4047174294Sobrien  \let\centerparametersmaybe = \relax
4048174294Sobrien}
404938494Sobrien
405042629Sobrien% @top is like @unnumbered.
4051174294Sobrien\let\top\unnumbered
405242629Sobrien
405342629Sobrien% Sections.
4054174294Sobrien\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
4055174294Sobrien\def\seczzz#1{%
4056174294Sobrien  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
4057174294Sobrien  \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
405842629Sobrien}
405938494Sobrien
4060174294Sobrien\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
4061174294Sobrien\def\appendixsectionzzz#1{%
4062174294Sobrien  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
4063174294Sobrien  \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
406442629Sobrien}
4065174294Sobrien\let\appendixsec\appendixsection
406638494Sobrien
4067174294Sobrien\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
4068174294Sobrien\def\unnumberedseczzz#1{%
4069174294Sobrien  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
4070174294Sobrien  \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
407142629Sobrien}
407238494Sobrien
407342629Sobrien% Subsections.
4074174294Sobrien\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
4075174294Sobrien\def\numberedsubseczzz#1{%
4076174294Sobrien  \global\subsubsecno=0  \global\advance\subsecno by 1
4077174294Sobrien  \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
407842629Sobrien}
407938494Sobrien
4080174294Sobrien\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
4081174294Sobrien\def\appendixsubseczzz#1{%
4082174294Sobrien  \global\subsubsecno=0  \global\advance\subsecno by 1
4083174294Sobrien  \sectionheading{#1}{subsec}{Yappendix}%
4084174294Sobrien                 {\appendixletter.\the\secno.\the\subsecno}%
408542629Sobrien}
408638494Sobrien
4087174294Sobrien\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
4088174294Sobrien\def\unnumberedsubseczzz#1{%
4089174294Sobrien  \global\subsubsecno=0  \global\advance\subsecno by 1
4090174294Sobrien  \sectionheading{#1}{subsec}{Ynothing}%
4091174294Sobrien                 {\the\unnumberedno.\the\secno.\the\subsecno}%
409242629Sobrien}
409338494Sobrien
409442629Sobrien% Subsubsections.
4095174294Sobrien\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
4096174294Sobrien\def\numberedsubsubseczzz#1{%
4097174294Sobrien  \global\advance\subsubsecno by 1
4098174294Sobrien  \sectionheading{#1}{subsubsec}{Ynumbered}%
4099174294Sobrien                 {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
410042629Sobrien}
410138494Sobrien
4102174294Sobrien\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
4103174294Sobrien\def\appendixsubsubseczzz#1{%
4104174294Sobrien  \global\advance\subsubsecno by 1
4105174294Sobrien  \sectionheading{#1}{subsubsec}{Yappendix}%
4106174294Sobrien                 {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
410742629Sobrien}
410838494Sobrien
4109174294Sobrien\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
4110174294Sobrien\def\unnumberedsubsubseczzz#1{%
4111174294Sobrien  \global\advance\subsubsecno by 1
4112174294Sobrien  \sectionheading{#1}{subsubsec}{Ynothing}%
4113174294Sobrien                 {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
411442629Sobrien}
411538494Sobrien
411638494Sobrien% These macros control what the section commands do, according
411738494Sobrien% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
411838494Sobrien% Define them by default for a numbered chapter.
4119174294Sobrien\let\section = \numberedsec
4120174294Sobrien\let\subsection = \numberedsubsec
4121174294Sobrien\let\subsubsection = \numberedsubsubsec
412238494Sobrien
412338494Sobrien% Define @majorheading, @heading and @subheading
412438494Sobrien
412542629Sobrien% NOTE on use of \vbox for chapter headings, section headings, and such:
412638494Sobrien%       1) We use \vbox rather than the earlier \line to permit
412738494Sobrien%          overlong headings to fold.
412838494Sobrien%       2) \hyphenpenalty is set to 10000 because hyphenation in a
412938494Sobrien%          heading is obnoxious; this forbids it.
413038494Sobrien%       3) Likewise, headings look best if no \parindent is used, and
413138494Sobrien%          if justification is not attempted.  Hence \raggedright.
413238494Sobrien
413338494Sobrien
4134174294Sobrien\def\majorheading{%
4135174294Sobrien  {\advance\chapheadingskip by 10pt \chapbreak }%
4136174294Sobrien  \parsearg\chapheadingzzz
4137174294Sobrien}
413838494Sobrien
4139174294Sobrien\def\chapheading{\chapbreak \parsearg\chapheadingzzz}
4140174294Sobrien\def\chapheadingzzz#1{%
4141174294Sobrien  {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
4142174294Sobrien                    \parindent=0pt\raggedright
4143174294Sobrien                    \rm #1\hfill}}%
4144174294Sobrien  \bigskip \par\penalty 200\relax
4145174294Sobrien  \suppressfirstparagraphindent
4146174294Sobrien}
414738494Sobrien
414838494Sobrien% @heading, @subheading, @subsubheading.
4149174294Sobrien\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
4150174294Sobrien  \suppressfirstparagraphindent}
4151174294Sobrien\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
4152174294Sobrien  \suppressfirstparagraphindent}
4153174294Sobrien\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
4154174294Sobrien  \suppressfirstparagraphindent}
415538494Sobrien
415638494Sobrien% These macros generate a chapter, section, etc. heading only
415738494Sobrien% (including whitespace, linebreaking, etc. around it),
415838494Sobrien% given all the information in convenient, parsed form.
415938494Sobrien
416038494Sobrien%%% Args are the skip and penalty (usually negative)
416138494Sobrien\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
416238494Sobrien
416338494Sobrien%%% Define plain chapter starts, and page on/off switching for it
416438494Sobrien% Parameter controlling skip before chapter headings (if needed)
416538494Sobrien
416638494Sobrien\newskip\chapheadingskip
416738494Sobrien
416838494Sobrien\def\chapbreak{\dobreak \chapheadingskip {-4000}}
416938494Sobrien\def\chappager{\par\vfill\supereject}
417038494Sobrien\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi}
417138494Sobrien
417238494Sobrien\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname}
417338494Sobrien
417442629Sobrien\def\CHAPPAGoff{%
417538494Sobrien\global\let\contentsalignmacro = \chappager
417638494Sobrien\global\let\pchapsepmacro=\chapbreak
417738494Sobrien\global\let\pagealignmacro=\chappager}
417838494Sobrien
417942629Sobrien\def\CHAPPAGon{%
418038494Sobrien\global\let\contentsalignmacro = \chappager
418138494Sobrien\global\let\pchapsepmacro=\chappager
418238494Sobrien\global\let\pagealignmacro=\chappager
418338494Sobrien\global\def\HEADINGSon{\HEADINGSsingle}}
418438494Sobrien
4185174294Sobrien\def\CHAPPAGodd{%
418638494Sobrien\global\let\contentsalignmacro = \chapoddpage
418738494Sobrien\global\let\pchapsepmacro=\chapoddpage
418838494Sobrien\global\let\pagealignmacro=\chapoddpage
418938494Sobrien\global\def\HEADINGSon{\HEADINGSdouble}}
419038494Sobrien
419138494Sobrien\CHAPPAGon
419238494Sobrien
4193174294Sobrien% Chapter opening.
4194174294Sobrien%
4195174294Sobrien% #1 is the text, #2 is the section type (Ynumbered, Ynothing,
4196174294Sobrien% Yappendix, Yomitfromtoc), #3 the chapter number.
4197174294Sobrien%
4198174294Sobrien% To test against our argument.
4199174294Sobrien\def\Ynothingkeyword{Ynothing}
4200174294Sobrien\def\Yomitfromtockeyword{Yomitfromtoc}
4201174294Sobrien\def\Yappendixkeyword{Yappendix}
4202174294Sobrien%
4203174294Sobrien\def\chapmacro#1#2#3{%
420438494Sobrien  \pchapsepmacro
420538494Sobrien  {%
420638494Sobrien    \chapfonts \rm
4207174294Sobrien    %
4208174294Sobrien    % Have to define \thissection before calling \donoderef, because the
4209174294Sobrien    % xref code eventually uses it.  On the other hand, it has to be called
4210174294Sobrien    % after \pchapsepmacro, or the headline will change too soon.
4211174294Sobrien    \gdef\thissection{#1}%
4212174294Sobrien    \gdef\thischaptername{#1}%
4213174294Sobrien    %
4214174294Sobrien    % Only insert the separating space if we have a chapter/appendix
4215174294Sobrien    % number, and don't print the unnumbered ``number''.
4216174294Sobrien    \def\temptype{#2}%
4217174294Sobrien    \ifx\temptype\Ynothingkeyword
4218174294Sobrien      \setbox0 = \hbox{}%
4219174294Sobrien      \def\toctype{unnchap}%
4220174294Sobrien      \def\thischapter{#1}%
4221174294Sobrien    \else\ifx\temptype\Yomitfromtockeyword
4222174294Sobrien      \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
4223174294Sobrien      \def\toctype{omit}%
4224174294Sobrien      \xdef\thischapter{}%
4225174294Sobrien    \else\ifx\temptype\Yappendixkeyword
4226174294Sobrien      \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
4227174294Sobrien      \def\toctype{app}%
4228174294Sobrien      % We don't substitute the actual chapter name into \thischapter
4229174294Sobrien      % because we don't want its macros evaluated now.  And we don't
4230174294Sobrien      % use \thissection because that changes with each section.
4231174294Sobrien      %
4232174294Sobrien      \xdef\thischapter{\putwordAppendix{} \appendixletter:
4233174294Sobrien                        \noexpand\thischaptername}%
4234174294Sobrien    \else
4235174294Sobrien      \setbox0 = \hbox{#3\enspace}%
4236174294Sobrien      \def\toctype{numchap}%
4237174294Sobrien      \xdef\thischapter{\putwordChapter{} \the\chapno:
4238174294Sobrien                        \noexpand\thischaptername}%
4239174294Sobrien    \fi\fi\fi
4240174294Sobrien    %
4241174294Sobrien    % Write the toc entry for this chapter.  Must come before the
4242174294Sobrien    % \donoderef, because we include the current node name in the toc
4243174294Sobrien    % entry, and \donoderef resets it to empty.
4244174294Sobrien    \writetocentry{\toctype}{#1}{#3}%
4245174294Sobrien    %
4246174294Sobrien    % For pdftex, we have to write out the node definition (aka, make
4247174294Sobrien    % the pdfdest) after any page break, but before the actual text has
4248174294Sobrien    % been typeset.  If the destination for the pdf outline is after the
4249174294Sobrien    % text, then jumping from the outline may wind up with the text not
4250174294Sobrien    % being visible, for instance under high magnification.
4251174294Sobrien    \donoderef{#2}%
4252174294Sobrien    %
4253174294Sobrien    % Typeset the actual heading.
425438494Sobrien    \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
4255174294Sobrien          \hangindent=\wd0 \centerparametersmaybe
425638494Sobrien          \unhbox0 #1\par}%
425738494Sobrien  }%
425838494Sobrien  \nobreak\bigskip % no page break after a chapter title
425938494Sobrien  \nobreak
426038494Sobrien}
426138494Sobrien
426238494Sobrien% @centerchap -- centered and unnumbered.
426338494Sobrien\let\centerparametersmaybe = \relax
4264174294Sobrien\def\centerparameters{%
4265174294Sobrien  \advance\rightskip by 3\rightskip
4266174294Sobrien  \leftskip = \rightskip
4267174294Sobrien  \parfillskip = 0pt
4268174294Sobrien}
426938494Sobrien
427038494Sobrien
4271174294Sobrien% I don't think this chapter style is supported any more, so I'm not
4272174294Sobrien% updating it with the new noderef stuff.  We'll see.  --karl, 11aug03.
4273174294Sobrien%
4274174294Sobrien\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
4275174294Sobrien%
427638494Sobrien\def\unnchfopen #1{%
427738494Sobrien\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
427838494Sobrien                       \parindent=0pt\raggedright
427942629Sobrien                       \rm #1\hfill}}\bigskip \par\nobreak
428038494Sobrien}
428138494Sobrien\def\chfopen #1#2{\chapoddpage {\chapfonts
428238494Sobrien\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
428338494Sobrien\par\penalty 5000 %
428438494Sobrien}
428538494Sobrien\def\centerchfopen #1{%
428638494Sobrien\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
428738494Sobrien                       \parindent=0pt
428842629Sobrien                       \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
428938494Sobrien}
4290174294Sobrien\def\CHAPFopen{%
4291174294Sobrien  \global\let\chapmacro=\chfopen
4292174294Sobrien  \global\let\centerchapmacro=\centerchfopen}
429338494Sobrien
429438494Sobrien
4295174294Sobrien% Section titles.  These macros combine the section number parts and
4296174294Sobrien% call the generic \sectionheading to do the printing.
4297174294Sobrien%
429838494Sobrien\newskip\secheadingskip
4299174294Sobrien\def\secheadingbreak{\dobreak \secheadingskip{-1000}}
430038494Sobrien
430138494Sobrien% Subsection titles.
4302174294Sobrien\newskip\subsecheadingskip
4303174294Sobrien\def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
430438494Sobrien
430538494Sobrien% Subsubsection titles.
4306174294Sobrien\def\subsubsecheadingskip{\subsecheadingskip}
4307174294Sobrien\def\subsubsecheadingbreak{\subsecheadingbreak}
430838494Sobrien
430938494Sobrien
4310174294Sobrien% Print any size, any type, section title.
431138494Sobrien%
4312174294Sobrien% #1 is the text, #2 is the section level (sec/subsec/subsubsec), #3 is
4313174294Sobrien% the section type for xrefs (Ynumbered, Ynothing, Yappendix), #4 is the
4314174294Sobrien% section number.
4315174294Sobrien%
4316174294Sobrien\def\sectionheading#1#2#3#4{%
431738494Sobrien  {%
431838494Sobrien    % Switch to the right set of fonts.
4319174294Sobrien    \csname #2fonts\endcsname \rm
432038494Sobrien    %
4321174294Sobrien    % Insert space above the heading.
4322174294Sobrien    \csname #2headingbreak\endcsname
432338494Sobrien    %
4324174294Sobrien    % Only insert the space after the number if we have a section number.
4325174294Sobrien    \def\sectionlevel{#2}%
4326174294Sobrien    \def\temptype{#3}%
4327174294Sobrien    %
4328174294Sobrien    \ifx\temptype\Ynothingkeyword
4329174294Sobrien      \setbox0 = \hbox{}%
4330174294Sobrien      \def\toctype{unn}%
4331174294Sobrien      \gdef\thissection{#1}%
4332174294Sobrien    \else\ifx\temptype\Yomitfromtockeyword
4333174294Sobrien      % for @headings -- no section number, don't include in toc,
4334174294Sobrien      % and don't redefine \thissection.
4335174294Sobrien      \setbox0 = \hbox{}%
4336174294Sobrien      \def\toctype{omit}%
4337174294Sobrien      \let\sectionlevel=\empty
4338174294Sobrien    \else\ifx\temptype\Yappendixkeyword
4339174294Sobrien      \setbox0 = \hbox{#4\enspace}%
4340174294Sobrien      \def\toctype{app}%
4341174294Sobrien      \gdef\thissection{#1}%
4342174294Sobrien    \else
4343174294Sobrien      \setbox0 = \hbox{#4\enspace}%
4344174294Sobrien      \def\toctype{num}%
4345174294Sobrien      \gdef\thissection{#1}%
4346174294Sobrien    \fi\fi\fi
4347174294Sobrien    %
4348174294Sobrien    % Write the toc entry (before \donoderef).  See comments in \chfplain.
4349174294Sobrien    \writetocentry{\toctype\sectionlevel}{#1}{#4}%
4350174294Sobrien    %
4351174294Sobrien    % Write the node reference (= pdf destination for pdftex).
4352174294Sobrien    % Again, see comments in \chfplain.
4353174294Sobrien    \donoderef{#3}%
4354174294Sobrien    %
4355174294Sobrien    % Output the actual section heading.
435638494Sobrien    \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
4357174294Sobrien          \hangindent=\wd0  % zero if no section number
4358174294Sobrien          \unhbox0 #1}%
435938494Sobrien  }%
4360174294Sobrien  % Add extra space after the heading -- half of whatever came above it.
4361174294Sobrien  % Don't allow stretch, though.
4362174294Sobrien  \kern .5 \csname #2headingskip\endcsname
4363174294Sobrien  %
4364174294Sobrien  % Do not let the kern be a potential breakpoint, as it would be if it
4365174294Sobrien  % was followed by glue.
4366174294Sobrien  \nobreak
4367174294Sobrien  %
4368174294Sobrien  % We'll almost certainly start a paragraph next, so don't let that
4369174294Sobrien  % glue accumulate.  (Not a breakpoint because it's preceded by a
4370174294Sobrien  % discardable item.)
4371174294Sobrien  \vskip-\parskip
4372174294Sobrien  % 
4373174294Sobrien  % This is purely so the last item on the list is a known \penalty >
4374174294Sobrien  % 10000.  This is so \startdefun can avoid allowing breakpoints after
4375174294Sobrien  % section headings.  Otherwise, it would insert a valid breakpoint between:
4376174294Sobrien  % 
4377174294Sobrien  %   @section sec-whatever
4378174294Sobrien  %   @deffn def-whatever
4379174294Sobrien  \penalty 10001
438038494Sobrien}
438138494Sobrien
438238494Sobrien
438342629Sobrien\message{toc,}
438482794Sobrien% Table of contents.
438542629Sobrien\newwrite\tocfile
438638494Sobrien
438742629Sobrien% Write an entry to the toc file, opening it if necessary.
4388174294Sobrien% Called from @chapter, etc.
438982794Sobrien%
4390174294Sobrien% Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
4391174294Sobrien% We append the current node name (if any) and page number as additional
4392174294Sobrien% arguments for the \{chap,sec,...}entry macros which will eventually
4393174294Sobrien% read this.  The node name is used in the pdf outlines as the
4394174294Sobrien% destination to jump to.
439582794Sobrien%
4396174294Sobrien% We open the .toc file for writing here instead of at @setfilename (or
4397174294Sobrien% any other fixed time) so that @contents can be anywhere in the document.
4398174294Sobrien% But if #1 is `omit', then we don't do anything.  This is used for the
4399174294Sobrien% table of contents chapter openings themselves.
4400174294Sobrien%
440142629Sobrien\newif\iftocfileopened
4402174294Sobrien\def\omitkeyword{omit}%
4403174294Sobrien%
4404174294Sobrien\def\writetocentry#1#2#3{%
4405174294Sobrien  \edef\writetoctype{#1}%
4406174294Sobrien  \ifx\writetoctype\omitkeyword \else
4407174294Sobrien    \iftocfileopened\else
4408174294Sobrien      \immediate\openout\tocfile = \jobname.toc
4409174294Sobrien      \global\tocfileopenedtrue
4410174294Sobrien    \fi
4411174294Sobrien    %
4412174294Sobrien    \iflinks
4413174294Sobrien      \toks0 = {#2}%
4414174294Sobrien      \toks2 = \expandafter{\lastnode}%
4415174294Sobrien      \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}{#3}%
4416174294Sobrien                               {\the\toks2}{\noexpand\folio}}}%
4417174294Sobrien      \temp
4418174294Sobrien    \fi
441942629Sobrien  \fi
4420119679Smbr  %
4421174294Sobrien  % Tell \shipout to create a pdf destination on each page, if we're
4422174294Sobrien  % writing pdf.  These are used in the table of contents.  We can't
4423174294Sobrien  % just write one on every page because the title pages are numbered
4424174294Sobrien  % 1 and 2 (the page numbers aren't printed), and so are the first
4425174294Sobrien  % two pages of the document.  Thus, we'd have two destinations named
4426174294Sobrien  % `1', and two named `2'.
4427174294Sobrien  \ifpdf \global\pdfmakepagedesttrue \fi
442842629Sobrien}
442942629Sobrien
443038494Sobrien\newskip\contentsrightmargin \contentsrightmargin=1in
443142629Sobrien\newcount\savepageno
443242629Sobrien\newcount\lastnegativepageno \lastnegativepageno = -1
443342629Sobrien
4434174294Sobrien% Prepare to read what we've written to \tocfile.
443582794Sobrien%
443638494Sobrien\def\startcontents#1{%
4437174294Sobrien  % If @setchapternewpage on, and @headings double, the contents should
4438174294Sobrien  % start on an odd page, unlike chapters.  Thus, we maintain
4439174294Sobrien  % \contentsalignmacro in parallel with \pagealignmacro.
4440174294Sobrien  % From: Torbjorn Granlund <tege@matematik.su.se>
4441174294Sobrien  \contentsalignmacro
4442174294Sobrien  \immediate\closeout\tocfile
4443174294Sobrien  %
4444174294Sobrien  % Don't need to put `Contents' or `Short Contents' in the headline.
4445174294Sobrien  % It is abundantly clear what they are.
4446174294Sobrien  \def\thischapter{}%
4447174294Sobrien  \chapmacro{#1}{Yomitfromtoc}{}%
4448174294Sobrien  %
4449174294Sobrien  \savepageno = \pageno
4450174294Sobrien  \begingroup                  % Set up to handle contents files properly.
4451174294Sobrien    \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
4452174294Sobrien    % We can't do this, because then an actual ^ in a section
4453174294Sobrien    % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
4454174294Sobrien    %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
4455174294Sobrien    \raggedbottom             % Worry more about breakpoints than the bottom.
4456174294Sobrien    \advance\hsize by -\contentsrightmargin % Don't use the full line length.
4457174294Sobrien    %
4458174294Sobrien    % Roman numerals for page numbers.
4459174294Sobrien    \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
446038494Sobrien}
446138494Sobrien
446238494Sobrien
446338494Sobrien% Normal (long) toc.
446442629Sobrien\def\contents{%
4465174294Sobrien  \startcontents{\putwordTOC}%
4466174294Sobrien    \openin 1 \jobname.toc
4467174294Sobrien    \ifeof 1 \else
4468174294Sobrien      \input \jobname.toc
4469174294Sobrien    \fi
4470174294Sobrien    \vfill \eject
4471174294Sobrien    \contentsalignmacro % in case @setchapternewpage odd is in effect
4472174294Sobrien    \ifeof 1 \else
4473174294Sobrien      \pdfmakeoutlines
4474174294Sobrien    \fi
4475174294Sobrien    \closein 1
4476174294Sobrien  \endgroup
4477174294Sobrien  \lastnegativepageno = \pageno
4478174294Sobrien  \global\pageno = \savepageno
447938494Sobrien}
448038494Sobrien
448138494Sobrien% And just the chapters.
448242629Sobrien\def\summarycontents{%
4483174294Sobrien  \startcontents{\putwordShortTOC}%
4484174294Sobrien    %
4485174294Sobrien    \let\numchapentry = \shortchapentry
4486174294Sobrien    \let\appentry = \shortchapentry
4487174294Sobrien    \let\unnchapentry = \shortunnchapentry
4488174294Sobrien    % We want a true roman here for the page numbers.
4489174294Sobrien    \secfonts
4490174294Sobrien    \let\rm=\shortcontrm \let\bf=\shortcontbf
4491174294Sobrien    \let\sl=\shortcontsl \let\tt=\shortconttt
4492174294Sobrien    \rm
4493174294Sobrien    \hyphenpenalty = 10000
4494174294Sobrien    \advance\baselineskip by 1pt % Open it up a little.
4495174294Sobrien    \def\numsecentry##1##2##3##4{}
4496174294Sobrien    \let\appsecentry = \numsecentry
4497174294Sobrien    \let\unnsecentry = \numsecentry
4498174294Sobrien    \let\numsubsecentry = \numsecentry
4499174294Sobrien    \let\appsubsecentry = \numsecentry
4500174294Sobrien    \let\unnsubsecentry = \numsecentry
4501174294Sobrien    \let\numsubsubsecentry = \numsecentry
4502174294Sobrien    \let\appsubsubsecentry = \numsecentry
4503174294Sobrien    \let\unnsubsubsecentry = \numsecentry
4504174294Sobrien    \openin 1 \jobname.toc
4505174294Sobrien    \ifeof 1 \else
4506174294Sobrien      \input \jobname.toc
4507174294Sobrien    \fi
4508174294Sobrien    \closein 1
4509174294Sobrien    \vfill \eject
4510174294Sobrien    \contentsalignmacro % in case @setchapternewpage odd is in effect
4511174294Sobrien  \endgroup
4512174294Sobrien  \lastnegativepageno = \pageno
4513174294Sobrien  \global\pageno = \savepageno
451438494Sobrien}
451538494Sobrien\let\shortcontents = \summarycontents
451638494Sobrien
4517174294Sobrien% Typeset the label for a chapter or appendix for the short contents.
4518174294Sobrien% The arg is, e.g., `A' for an appendix, or `3' for a chapter.
4519174294Sobrien%
4520174294Sobrien\def\shortchaplabel#1{%
4521174294Sobrien  % This space should be enough, since a single number is .5em, and the
4522174294Sobrien  % widest letter (M) is 1em, at least in the Computer Modern fonts.
4523174294Sobrien  % But use \hss just in case.
4524174294Sobrien  % (This space doesn't include the extra space that gets added after
4525174294Sobrien  % the label; that gets put in by \shortchapentry above.)
4526174294Sobrien  %
4527174294Sobrien  % We'd like to right-justify chapter numbers, but that looks strange
4528174294Sobrien  % with appendix letters.  And right-justifying numbers and
4529174294Sobrien  % left-justifying letters looks strange when there is less than 10
4530174294Sobrien  % chapters.  Have to read the whole toc once to know how many chapters
4531174294Sobrien  % there are before deciding ...
4532174294Sobrien  \hbox to 1em{#1\hss}%
4533174294Sobrien}
453482794Sobrien
453538494Sobrien% These macros generate individual entries in the table of contents.
453638494Sobrien% The first argument is the chapter or section name.
453738494Sobrien% The last argument is the page number.
453838494Sobrien% The arguments in between are the chapter number, section number, ...
453938494Sobrien
4540119679Smbr% Chapters, in the main contents.
4541174294Sobrien\def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
4542119679Smbr%
4543119679Smbr% Chapters, in the short toc.
4544119679Smbr% See comments in \dochapentry re vbox and related settings.
4545174294Sobrien\def\shortchapentry#1#2#3#4{%
4546174294Sobrien  \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
454738494Sobrien}
454838494Sobrien
4549119679Smbr% Appendices, in the main contents.
4550174294Sobrien% Need the word Appendix, and a fixed-size box.
4551119679Smbr%
4552174294Sobrien\def\appendixbox#1{%
4553174294Sobrien  % We use M since it's probably the widest letter.
4554174294Sobrien  \setbox0 = \hbox{\putwordAppendix{} M}%
4555174294Sobrien  \hbox to \wd0{\putwordAppendix{} #1\hss}}
455682794Sobrien%
4557174294Sobrien\def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\labelspace#1}{#4}}
455838494Sobrien
4559119679Smbr% Unnumbered chapters.
4560174294Sobrien\def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
4561174294Sobrien\def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
456238494Sobrien
456338494Sobrien% Sections.
4564174294Sobrien\def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
4565174294Sobrien\let\appsecentry=\numsecentry
4566174294Sobrien\def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
456738494Sobrien
456838494Sobrien% Subsections.
4569174294Sobrien\def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
4570174294Sobrien\let\appsubsecentry=\numsubsecentry
4571174294Sobrien\def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
457238494Sobrien
457338494Sobrien% And subsubsections.
4574174294Sobrien\def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
4575174294Sobrien\let\appsubsubsecentry=\numsubsubsecentry
4576174294Sobrien\def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
457738494Sobrien
457838494Sobrien% This parameter controls the indentation of the various levels.
4579174294Sobrien% Same as \defaultparindent.
4580174294Sobrien\newdimen\tocindent \tocindent = 15pt
458138494Sobrien
458238494Sobrien% Now for the actual typesetting. In all these, #1 is the text and #2 is the
458338494Sobrien% page number.
458438494Sobrien%
458538494Sobrien% If the toc has to be broken over pages, we want it to be at chapters
458638494Sobrien% if at all possible; hence the \penalty.
458738494Sobrien\def\dochapentry#1#2{%
458838494Sobrien   \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
458938494Sobrien   \begingroup
459038494Sobrien     \chapentryfonts
459182794Sobrien     \tocentry{#1}{\dopageno\bgroup#2\egroup}%
459238494Sobrien   \endgroup
459338494Sobrien   \nobreak\vskip .25\baselineskip plus.1\baselineskip
459438494Sobrien}
459538494Sobrien
459638494Sobrien\def\dosecentry#1#2{\begingroup
459738494Sobrien  \secentryfonts \leftskip=\tocindent
459882794Sobrien  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
459938494Sobrien\endgroup}
460038494Sobrien
460138494Sobrien\def\dosubsecentry#1#2{\begingroup
460238494Sobrien  \subsecentryfonts \leftskip=2\tocindent
460382794Sobrien  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
460438494Sobrien\endgroup}
460538494Sobrien
460638494Sobrien\def\dosubsubsecentry#1#2{\begingroup
460738494Sobrien  \subsubsecentryfonts \leftskip=3\tocindent
460882794Sobrien  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
460938494Sobrien\endgroup}
461038494Sobrien
4611174294Sobrien% We use the same \entry macro as for the index entries.
4612174294Sobrien\let\tocentry = \entry
461338494Sobrien
461438494Sobrien% Space between chapter (or whatever) number and the title.
461538494Sobrien\def\labelspace{\hskip1em \relax}
461638494Sobrien
461738494Sobrien\def\dopageno#1{{\rm #1}}
461838494Sobrien\def\doshortpageno#1{{\rm #1}}
461938494Sobrien
462038494Sobrien\def\chapentryfonts{\secfonts \rm}
462138494Sobrien\def\secentryfonts{\textfonts}
4622174294Sobrien\def\subsecentryfonts{\textfonts}
4623174294Sobrien\def\subsubsecentryfonts{\textfonts}
462438494Sobrien
462538494Sobrien
462638494Sobrien\message{environments,}
462782794Sobrien% @foo ... @end foo.
462838494Sobrien
4629119679Smbr% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
4630174294Sobrien%
463138494Sobrien% Since these characters are used in examples, it should be an even number of
463238494Sobrien% \tt widths. Each \tt character is 1en, so two makes it 1em.
4633119679Smbr%
463438494Sobrien\def\point{$\star$}
463538494Sobrien\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
463638494Sobrien\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}}
463738494Sobrien\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
463838494Sobrien\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}}
463938494Sobrien
4640119679Smbr% The @error{} command.
464138494Sobrien% Adapted from the TeXbook's \boxit.
4642174294Sobrien%
4643119679Smbr\newbox\errorbox
4644119679Smbr%
464538494Sobrien{\tentt \global\dimen0 = 3em}% Width of the box.
464638494Sobrien\dimen2 = .55pt % Thickness of rules
464738494Sobrien% The text. (`r' is open on the right, `e' somewhat less so on the left.)
464838494Sobrien\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
4649119679Smbr%
4650174294Sobrien\setbox\errorbox=\hbox to \dimen0{\hfil
465138494Sobrien   \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
465238494Sobrien   \advance\hsize by -2\dimen2 % Rules.
4653174294Sobrien   \vbox{%
465438494Sobrien      \hrule height\dimen2
465538494Sobrien      \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
465638494Sobrien         \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
465738494Sobrien         \kern3pt\vrule width\dimen2}% Space to right.
465838494Sobrien      \hrule height\dimen2}
465938494Sobrien    \hfil}
4660119679Smbr%
466138494Sobrien\def\error{\leavevmode\lower.7ex\copy\errorbox}
466238494Sobrien
466338494Sobrien% @tex ... @end tex    escapes into raw Tex temporarily.
466438494Sobrien% One exception: @ is still an escape character, so that @end tex works.
466538494Sobrien% But \@ or @@ will get a plain tex @ character.
466638494Sobrien
4667174294Sobrien\envdef\tex{%
466842629Sobrien  \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
466942629Sobrien  \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
4670174294Sobrien  \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
467142629Sobrien  \catcode `\%=14
4672174294Sobrien  \catcode `\+=\other
4673174294Sobrien  \catcode `\"=\other
4674174294Sobrien  \catcode `\|=\other
4675174294Sobrien  \catcode `\<=\other
4676174294Sobrien  \catcode `\>=\other
467742629Sobrien  \escapechar=`\\
467842629Sobrien  %
467942629Sobrien  \let\b=\ptexb
468042629Sobrien  \let\bullet=\ptexbullet
468142629Sobrien  \let\c=\ptexc
468242629Sobrien  \let\,=\ptexcomma
468342629Sobrien  \let\.=\ptexdot
468442629Sobrien  \let\dots=\ptexdots
468542629Sobrien  \let\equiv=\ptexequiv
468642629Sobrien  \let\!=\ptexexclam
468742629Sobrien  \let\i=\ptexi
4688174294Sobrien  \let\indent=\ptexindent
4689174294Sobrien  \let\noindent=\ptexnoindent
469042629Sobrien  \let\{=\ptexlbrace
469142629Sobrien  \let\+=\tabalign
469242629Sobrien  \let\}=\ptexrbrace
4693174294Sobrien  \let\/=\ptexslash
469442629Sobrien  \let\*=\ptexstar
469542629Sobrien  \let\t=\ptext
469642629Sobrien  %
469742629Sobrien  \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
469842629Sobrien  \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
469942629Sobrien  \def\@{@}%
4700174294Sobrien}
4701174294Sobrien% There is no need to define \Etex.
470238494Sobrien
4703119679Smbr% Define @lisp ... @end lisp.
4704174294Sobrien% @lisp environment forms a group so it can rebind things,
4705119679Smbr% including the definition of @end lisp (which normally is erroneous).
470638494Sobrien
470738494Sobrien% Amount to narrow the margins by for @lisp.
470838494Sobrien\newskip\lispnarrowing \lispnarrowing=0.4in
470938494Sobrien
471038494Sobrien% This is the definition that ^^M gets inside @lisp, @example, and other
471138494Sobrien% such environments.  \null is better than a space, since it doesn't
471238494Sobrien% have any width.
471338494Sobrien\def\lisppar{\null\endgraf}
471438494Sobrien
471538494Sobrien% This space is always present above and below environments.
471638494Sobrien\newskip\envskipamount \envskipamount = 0pt
471738494Sobrien
471838494Sobrien% Make spacing and below environment symmetrical.  We use \parskip here
471938494Sobrien% to help in doing that, since in @example-like environments \parskip
472038494Sobrien% is reset to zero; thus the \afterenvbreak inserts no space -- but the
4721174294Sobrien% start of the next paragraph will insert \parskip.
472238494Sobrien%
472382794Sobrien\def\aboveenvbreak{{%
4724174294Sobrien  % =10000 instead of <10000 because of a special case in \itemzzz and
4725174294Sobrien  % \sectionheading, q.v.
4726174294Sobrien  \ifnum \lastpenalty=10000 \else
472782794Sobrien    \advance\envskipamount by \parskip
472882794Sobrien    \endgraf
472982794Sobrien    \ifdim\lastskip<\envskipamount
473082794Sobrien      \removelastskip
4731174294Sobrien      % it's not a good place to break if the last penalty was \nobreak
4732174294Sobrien      % or better ...
4733174294Sobrien      \ifnum\lastpenalty<10000 \penalty-50 \fi
473482794Sobrien      \vskip\envskipamount
473582794Sobrien    \fi
473682794Sobrien  \fi
473782794Sobrien}}
473838494Sobrien
473938494Sobrien\let\afterenvbreak = \aboveenvbreak
474038494Sobrien
474138494Sobrien% \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins.
474238494Sobrien\let\nonarrowing=\relax
474338494Sobrien
474442629Sobrien% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
474542629Sobrien% environment contents.
474638494Sobrien\font\circle=lcircle10
474738494Sobrien\newdimen\circthick
474838494Sobrien\newdimen\cartouter\newdimen\cartinner
474938494Sobrien\newskip\normbskip\newskip\normpskip\newskip\normlskip
475038494Sobrien\circthick=\fontdimen8\circle
475138494Sobrien%
475238494Sobrien\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
475338494Sobrien\def\ctr{{\hskip 6pt\circle\char'010}}
475438494Sobrien\def\cbl{{\circle\char'012\hskip -6pt}}
475538494Sobrien\def\cbr{{\hskip 6pt\circle\char'011}}
475638494Sobrien\def\carttop{\hbox to \cartouter{\hskip\lskip
475738494Sobrien        \ctl\leaders\hrule height\circthick\hfil\ctr
475838494Sobrien        \hskip\rskip}}
475938494Sobrien\def\cartbot{\hbox to \cartouter{\hskip\lskip
476038494Sobrien        \cbl\leaders\hrule height\circthick\hfil\cbr
476138494Sobrien        \hskip\rskip}}
476238494Sobrien%
476338494Sobrien\newskip\lskip\newskip\rskip
476438494Sobrien
4765174294Sobrien\envdef\cartouche{%
4766174294Sobrien  \ifhmode\par\fi  % can't be in the midst of a paragraph.
4767174294Sobrien  \startsavinginserts
4768174294Sobrien  \lskip=\leftskip \rskip=\rightskip
4769174294Sobrien  \leftskip=0pt\rightskip=0pt % we want these *outside*.
4770174294Sobrien  \cartinner=\hsize \advance\cartinner by-\lskip
4771174294Sobrien  \advance\cartinner by-\rskip
4772174294Sobrien  \cartouter=\hsize
4773174294Sobrien  \advance\cartouter by 18.4pt	% allow for 3pt kerns on either
4774174294Sobrien				% side, and for 6pt waste from
4775174294Sobrien				% each corner char, and rule thickness
4776174294Sobrien  \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
4777174294Sobrien  % Flag to tell @lisp, etc., not to narrow margin.
4778174294Sobrien  \let\nonarrowing=\comment
4779174294Sobrien  \vbox\bgroup
4780174294Sobrien      \baselineskip=0pt\parskip=0pt\lineskip=0pt
4781174294Sobrien      \carttop
4782174294Sobrien      \hbox\bgroup
4783174294Sobrien	  \hskip\lskip
4784174294Sobrien	  \vrule\kern3pt
4785174294Sobrien	  \vbox\bgroup
4786174294Sobrien	      \kern3pt
4787174294Sobrien	      \hsize=\cartinner
4788174294Sobrien	      \baselineskip=\normbskip
4789174294Sobrien	      \lineskip=\normlskip
4790174294Sobrien	      \parskip=\normpskip
4791174294Sobrien	      \vskip -\parskip
4792174294Sobrien	      \comment % For explanation, see the end of \def\group.
4793174294Sobrien}
479438494Sobrien\def\Ecartouche{%
4795174294Sobrien              \ifhmode\par\fi
4796174294Sobrien	      \kern3pt
4797174294Sobrien	  \egroup
4798174294Sobrien	  \kern3pt\vrule
4799174294Sobrien	  \hskip\rskip
4800174294Sobrien      \egroup
4801174294Sobrien      \cartbot
4802174294Sobrien  \egroup
4803174294Sobrien  \checkinserts
4804174294Sobrien}
480538494Sobrien
480638494Sobrien
480738494Sobrien% This macro is called at the beginning of all the @example variants,
480838494Sobrien% inside a group.
480938494Sobrien\def\nonfillstart{%
481038494Sobrien  \aboveenvbreak
481138494Sobrien  \hfuzz = 12pt % Don't be fussy
481238494Sobrien  \sepspaces % Make spaces be word-separators rather than space tokens.
481338494Sobrien  \let\par = \lisppar % don't ignore blank lines
481438494Sobrien  \obeylines % each line of input is a line of output
481538494Sobrien  \parskip = 0pt
481638494Sobrien  \parindent = 0pt
481738494Sobrien  \emergencystretch = 0pt % don't try to avoid overfull boxes
481838494Sobrien  % @cartouche defines \nonarrowing to inhibit narrowing
481938494Sobrien  % at next level down.
482038494Sobrien  \ifx\nonarrowing\relax
482138494Sobrien    \advance \leftskip by \lispnarrowing
482238494Sobrien    \exdentamount=\lispnarrowing
482338494Sobrien  \fi
4824174294Sobrien  \let\exdent=\nofillexdent
482538494Sobrien}
482638494Sobrien
4827174294Sobrien% If you want all examples etc. small: @set dispenvsize small.
4828174294Sobrien% If you want even small examples the full size: @set dispenvsize nosmall.
4829174294Sobrien% This affects the following displayed environments:
4830174294Sobrien%    @example, @display, @format, @lisp
483182794Sobrien%
4832174294Sobrien\def\smallword{small}
4833174294Sobrien\def\nosmallword{nosmall}
4834174294Sobrien\let\SETdispenvsize\relax
4835174294Sobrien\def\setnormaldispenv{%
4836174294Sobrien  \ifx\SETdispenvsize\smallword
4837174294Sobrien    \smallexamplefonts \rm
4838174294Sobrien  \fi
4839174294Sobrien}
4840174294Sobrien\def\setsmalldispenv{%
4841174294Sobrien  \ifx\SETdispenvsize\nosmallword
4842174294Sobrien  \else
4843174294Sobrien    \smallexamplefonts \rm
4844174294Sobrien  \fi
4845174294Sobrien}
4846174294Sobrien
4847174294Sobrien% We often define two environments, @foo and @smallfoo.
4848174294Sobrien% Let's do it by one command:
4849174294Sobrien\def\makedispenv #1#2{
4850174294Sobrien  \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}
4851174294Sobrien  \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}
4852174294Sobrien  \expandafter\let\csname E#1\endcsname \afterenvbreak
4853174294Sobrien  \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
4854174294Sobrien}
4855174294Sobrien
4856174294Sobrien% Define two synonyms:
4857174294Sobrien\def\maketwodispenvs #1#2#3{
4858174294Sobrien  \makedispenv{#1}{#3}
4859174294Sobrien  \makedispenv{#2}{#3}
4860174294Sobrien}
4861174294Sobrien
4862174294Sobrien% @lisp: indented, narrowed, typewriter font; @example: same as @lisp.
486338494Sobrien%
4864174294Sobrien% @smallexample and @smalllisp: use smaller fonts.
4865174294Sobrien% Originally contributed by Pavel@xerox.
4866174294Sobrien%
4867174294Sobrien\maketwodispenvs {lisp}{example}{%
486838494Sobrien  \nonfillstart
486938494Sobrien  \tt
487042629Sobrien  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
487142629Sobrien  \gobble       % eat return
487238494Sobrien}
487338494Sobrien
4874174294Sobrien% @display/@smalldisplay: same as @lisp except keep current font.
487582794Sobrien%
4876174294Sobrien\makedispenv {display}{%
4877174294Sobrien  \nonfillstart
4878174294Sobrien  \gobble
487938494Sobrien}
488038494Sobrien
4881174294Sobrien% @format/@smallformat: same as @display except don't narrow margins.
488238494Sobrien%
4883174294Sobrien\makedispenv{format}{%
4884174294Sobrien  \let\nonarrowing = t%
488538494Sobrien  \nonfillstart
488638494Sobrien  \gobble
488738494Sobrien}
488842629Sobrien
4889174294Sobrien% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
4890174294Sobrien\envdef\flushleft{%
4891174294Sobrien  \let\nonarrowing = t%
489238494Sobrien  \nonfillstart
489338494Sobrien  \gobble
489438494Sobrien}
4895174294Sobrien\let\Eflushleft = \afterenvbreak
489642629Sobrien
489742629Sobrien% @flushright.
489882794Sobrien%
4899174294Sobrien\envdef\flushright{%
4900174294Sobrien  \let\nonarrowing = t%
490138494Sobrien  \nonfillstart
490238494Sobrien  \advance\leftskip by 0pt plus 1fill
490342629Sobrien  \gobble
490442629Sobrien}
4905174294Sobrien\let\Eflushright = \afterenvbreak
490638494Sobrien
490782794Sobrien
490838494Sobrien% @quotation does normal linebreaking (hence we can't use \nonfillstart)
4909174294Sobrien% and narrows the margins.  We keep \parskip nonzero in general, since
4910174294Sobrien% we're doing normal filling.  So, when using \aboveenvbreak and
4911174294Sobrien% \afterenvbreak, temporarily make \parskip 0.
491238494Sobrien%
4913174294Sobrien\envdef\quotation{%
491438494Sobrien  {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
491538494Sobrien  \parindent=0pt
491638494Sobrien  %
491738494Sobrien  % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
491838494Sobrien  \ifx\nonarrowing\relax
491938494Sobrien    \advance\leftskip by \lispnarrowing
492038494Sobrien    \advance\rightskip by \lispnarrowing
492138494Sobrien    \exdentamount = \lispnarrowing
492238494Sobrien    \let\nonarrowing = \relax
492338494Sobrien  \fi
4924174294Sobrien  \parsearg\quotationlabel
492538494Sobrien}
492638494Sobrien
4927174294Sobrien% We have retained a nonzero parskip for the environment, since we're
4928174294Sobrien% doing normal filling.
4929174294Sobrien%
4930174294Sobrien\def\Equotation{%
4931174294Sobrien  \par
4932174294Sobrien  \ifx\quotationauthor\undefined\else
4933174294Sobrien    % indent a bit.
4934174294Sobrien    \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
4935174294Sobrien  \fi
4936174294Sobrien  {\parskip=0pt \afterenvbreak}%
4937174294Sobrien}
493842629Sobrien
4939174294Sobrien% If we're given an argument, typeset it in bold with a colon after.
4940174294Sobrien\def\quotationlabel#1{%
4941174294Sobrien  \def\temp{#1}%
4942174294Sobrien  \ifx\temp\empty \else
4943174294Sobrien    {\bf #1: }%
4944174294Sobrien  \fi
4945174294Sobrien}
4946174294Sobrien
4947174294Sobrien
494882794Sobrien% LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
4949174294Sobrien% If we want to allow any <char> as delimiter,
495082794Sobrien% we need the curly braces so that makeinfo sees the @verb command, eg:
495182794Sobrien% `@verbx...x' would look like the '@verbx' command.  --janneke@gnu.org
495282794Sobrien%
495382794Sobrien% [Knuth]: Donald Ervin Knuth, 1996.  The TeXbook.
495482794Sobrien%
4955174294Sobrien% [Knuth] p.344; only we need to do the other characters Texinfo sets
4956174294Sobrien% active too.  Otherwise, they get lost as the first character on a
4957174294Sobrien% verbatim line.
495882794Sobrien\def\dospecials{%
4959174294Sobrien  \do\ \do\\\do\{\do\}\do\$\do\&%
4960174294Sobrien  \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
4961174294Sobrien  \do\<\do\>\do\|\do\@\do+\do\"%
4962174294Sobrien}
496382794Sobrien%
496482794Sobrien% [Knuth] p. 380
496582794Sobrien\def\uncatcodespecials{%
4966174294Sobrien  \def\do##1{\catcode`##1=\other}\dospecials}
496782794Sobrien%
496882794Sobrien% [Knuth] pp. 380,381,391
496982794Sobrien% Disable Spanish ligatures ?` and !` of \tt font
497082794Sobrien\begingroup
497182794Sobrien  \catcode`\`=\active\gdef`{\relax\lq}
497282794Sobrien\endgroup
497382794Sobrien%
497482794Sobrien% Setup for the @verb command.
497582794Sobrien%
497682794Sobrien% Eight spaces for a tab
497782794Sobrien\begingroup
497882794Sobrien  \catcode`\^^I=\active
497982794Sobrien  \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
498082794Sobrien\endgroup
498182794Sobrien%
498282794Sobrien\def\setupverb{%
498382794Sobrien  \tt  % easiest (and conventionally used) font for verbatim
498482794Sobrien  \def\par{\leavevmode\endgraf}%
498582794Sobrien  \catcode`\`=\active
498682794Sobrien  \tabeightspaces
498782794Sobrien  % Respect line breaks,
498882794Sobrien  % print special symbols as themselves, and
498982794Sobrien  % make each space count
499082794Sobrien  % must do in this order:
499182794Sobrien  \obeylines \uncatcodespecials \sepspaces
499282794Sobrien}
499382794Sobrien
499482794Sobrien% Setup for the @verbatim environment
499582794Sobrien%
499682794Sobrien% Real tab expansion
499782794Sobrien\newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
499882794Sobrien%
499982794Sobrien\def\starttabbox{\setbox0=\hbox\bgroup}
500082794Sobrien\begingroup
500182794Sobrien  \catcode`\^^I=\active
500282794Sobrien  \gdef\tabexpand{%
500382794Sobrien    \catcode`\^^I=\active
500482794Sobrien    \def^^I{\leavevmode\egroup
500582794Sobrien      \dimen0=\wd0 % the width so far, or since the previous tab
500682794Sobrien      \divide\dimen0 by\tabw
500782794Sobrien      \multiply\dimen0 by\tabw % compute previous multiple of \tabw
500882794Sobrien      \advance\dimen0 by\tabw  % advance to next multiple of \tabw
500982794Sobrien      \wd0=\dimen0 \box0 \starttabbox
501082794Sobrien    }%
501182794Sobrien  }
501282794Sobrien\endgroup
501382794Sobrien\def\setupverbatim{%
5014174294Sobrien  \nonfillstart
5015174294Sobrien  \advance\leftskip by -\defbodyindent
501682794Sobrien  % Easiest (and conventionally used) font for verbatim
501782794Sobrien  \tt
501882794Sobrien  \def\par{\leavevmode\egroup\box0\endgraf}%
501982794Sobrien  \catcode`\`=\active
502082794Sobrien  \tabexpand
502182794Sobrien  % Respect line breaks,
502282794Sobrien  % print special symbols as themselves, and
502382794Sobrien  % make each space count
502482794Sobrien  % must do in this order:
502582794Sobrien  \obeylines \uncatcodespecials \sepspaces
502682794Sobrien  \everypar{\starttabbox}%
502782794Sobrien}
502882794Sobrien
5029174294Sobrien% Do the @verb magic: verbatim text is quoted by unique
5030174294Sobrien% delimiter characters.  Before first delimiter expect a
503182794Sobrien% right brace, after last delimiter expect closing brace:
503282794Sobrien%
503382794Sobrien%    \def\doverb'{'<char>#1<char>'}'{#1}
503482794Sobrien%
503582794Sobrien% [Knuth] p. 382; only eat outer {}
503682794Sobrien\begingroup
5037174294Sobrien  \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
503882794Sobrien  \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
503982794Sobrien\endgroup
504082794Sobrien%
504182794Sobrien\def\verb{\begingroup\setupverb\doverb}
504282794Sobrien%
504382794Sobrien%
504482794Sobrien% Do the @verbatim magic: define the macro \doverbatim so that
504582794Sobrien% the (first) argument ends when '@end verbatim' is reached, ie:
504682794Sobrien%
504782794Sobrien%     \def\doverbatim#1@end verbatim{#1}
504882794Sobrien%
5049174294Sobrien% For Texinfo it's a lot easier than for LaTeX,
505082794Sobrien% because texinfo's \verbatim doesn't stop at '\end{verbatim}':
5051174294Sobrien% we need not redefine '\', '{' and '}'.
505282794Sobrien%
505382794Sobrien% Inspired by LaTeX's verbatim command set [latex.ltx]
5054174294Sobrien%
505582794Sobrien\begingroup
505682794Sobrien  \catcode`\ =\active
5057174294Sobrien  \obeylines %
5058174294Sobrien  % ignore everything up to the first ^^M, that's the newline at the end
5059174294Sobrien  % of the @verbatim input line itself.  Otherwise we get an extra blank
5060174294Sobrien  % line in the output.
5061174294Sobrien  \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
5062174294Sobrien  % We really want {...\end verbatim} in the body of the macro, but
5063174294Sobrien  % without the active space; thus we have to use \xdef and \gobble.
506482794Sobrien\endgroup
506582794Sobrien%
5066174294Sobrien\envdef\verbatim{%
5067174294Sobrien    \setupverbatim\doverbatim
506882794Sobrien}
5069174294Sobrien\let\Everbatim = \afterenvbreak
507082794Sobrien
5071174294Sobrien
507282794Sobrien% @verbatiminclude FILE - insert text of file in verbatim environment.
507382794Sobrien%
5074174294Sobrien\def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
507582794Sobrien%
507682794Sobrien\def\doverbatiminclude#1{%
5077174294Sobrien  {%
5078174294Sobrien    \makevalueexpandable
5079174294Sobrien    \setupverbatim
5080174294Sobrien    \input #1
5081174294Sobrien    \afterenvbreak
5082174294Sobrien  }%
508382794Sobrien}
508482794Sobrien
5085119679Smbr% @copying ... @end copying.
5086119679Smbr% Save the text away for @insertcopying later.
5087119679Smbr%
5088174294Sobrien% We save the uninterpreted tokens, rather than creating a box.
5089174294Sobrien% Saving the text in a box would be much easier, but then all the
5090174294Sobrien% typesetting commands (@smallbook, font changes, etc.) have to be done
5091174294Sobrien% beforehand -- and a) we want @copying to be done first in the source
5092174294Sobrien% file; b) letting users define the frontmatter in as flexible order as
5093174294Sobrien% possible is very desirable.
5094174294Sobrien%
5095174294Sobrien\def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
5096174294Sobrien\def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
5097174294Sobrien%
5098174294Sobrien\def\insertcopying{%
5099174294Sobrien  \begingroup
5100174294Sobrien    \parindent = 0pt  % paragraph indentation looks wrong on title page
5101174294Sobrien    \scanexp\copyingtext
5102174294Sobrien  \endgroup
5103119679Smbr}
510482794Sobrien
510538494Sobrien\message{defuns,}
510682794Sobrien% @defun etc.
510782794Sobrien
510838494Sobrien\newskip\defbodyindent \defbodyindent=.4in
510938494Sobrien\newskip\defargsindent \defargsindent=50pt
511038494Sobrien\newskip\deflastargmargin \deflastargmargin=18pt
511138494Sobrien
5112174294Sobrien% Start the processing of @deffn:
5113174294Sobrien\def\startdefun{%
5114174294Sobrien  \ifnum\lastpenalty<10000
5115174294Sobrien    \medbreak
5116174294Sobrien  \else
5117174294Sobrien    % If there are two @def commands in a row, we'll have a \nobreak,
5118174294Sobrien    % which is there to keep the function description together with its
5119174294Sobrien    % header.  But if there's nothing but headers, we need to allow a
5120174294Sobrien    % break somewhere.  Check specifically for penalty 10002, inserted
5121174294Sobrien    % by \defargscommonending, instead of 10000, since the sectioning
5122174294Sobrien    % commands also insert a nobreak penalty, and we don't want to allow
5123174294Sobrien    % a break between a section heading and a defun.
5124174294Sobrien    % 
5125174294Sobrien    \ifnum\lastpenalty=10002 \penalty2000 \fi
5126174294Sobrien    %
5127174294Sobrien    % Similarly, after a section heading, do not allow a break.
5128174294Sobrien    % But do insert the glue.
5129174294Sobrien    \medskip  % preceded by discardable penalty, so not a breakpoint
5130174294Sobrien  \fi
5131119679Smbr  %
5132119679Smbr  \parindent=0in
5133119679Smbr  \advance\leftskip by \defbodyindent
5134119679Smbr  \exdentamount=\defbodyindent
5135119679Smbr}
513638494Sobrien
5137174294Sobrien\def\dodefunx#1{%
5138174294Sobrien  % First, check whether we are in the right environment:
5139174294Sobrien  \checkenv#1%
5140174294Sobrien  %
5141174294Sobrien  % As above, allow line break if we have multiple x headers in a row.
5142174294Sobrien  % It's not a great place, though.
5143174294Sobrien  \ifnum\lastpenalty=10002 \penalty3000 \fi
5144174294Sobrien  %
5145174294Sobrien  % And now, it's time to reuse the body of the original defun:
5146174294Sobrien  \expandafter\gobbledefun#1%
5147119679Smbr}
5148174294Sobrien\def\gobbledefun#1\startdefun{}
514938494Sobrien
5150174294Sobrien% \printdefunline \deffnheader{text}
515182794Sobrien%
5152174294Sobrien\def\printdefunline#1#2{%
5153174294Sobrien  \begingroup
5154174294Sobrien    % call \deffnheader:
5155174294Sobrien    #1#2 \endheader
5156174294Sobrien    % common ending:
5157174294Sobrien    \interlinepenalty = 10000
5158174294Sobrien    \advance\rightskip by 0pt plus 1fil
5159174294Sobrien    \endgraf
5160174294Sobrien    \nobreak\vskip -\parskip
5161174294Sobrien    \penalty 10002  % signal to \startdefun and \dodefunx
5162174294Sobrien    % Some of the @defun-type tags do not enable magic parentheses,
5163174294Sobrien    % rendering the following check redundant.  But we don't optimize.
5164174294Sobrien    \checkparencounts
5165174294Sobrien  \endgroup
5166119679Smbr}
516738494Sobrien
5168174294Sobrien\def\Edefun{\endgraf\medbreak}
516982794Sobrien
5170174294Sobrien% \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
5171174294Sobrien% the only thing remainnig is to define \deffnheader.
517238494Sobrien%
5173174294Sobrien\def\makedefun#1{%
5174174294Sobrien  \expandafter\let\csname E#1\endcsname = \Edefun
5175174294Sobrien  \edef\temp{\noexpand\domakedefun
5176174294Sobrien    \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
5177174294Sobrien  \temp
517838494Sobrien}
517938494Sobrien
5180174294Sobrien% \domakedefun \deffn \deffnx \deffnheader
518138494Sobrien%
5182174294Sobrien% Define \deffn and \deffnx, without parameters.
5183174294Sobrien% \deffnheader has to be defined explicitly.
518438494Sobrien%
5185174294Sobrien\def\domakedefun#1#2#3{%
5186174294Sobrien  \envdef#1{%
5187174294Sobrien    \startdefun
5188174294Sobrien    \parseargusing\activeparens{\printdefunline#3}%
5189174294Sobrien  }%
5190174294Sobrien  \def#2{\dodefunx#1}%
5191174294Sobrien  \def#3%
519238494Sobrien}
519338494Sobrien
5194174294Sobrien%%% Untyped functions:
519538494Sobrien
5196174294Sobrien% @deffn category name args
5197174294Sobrien\makedefun{deffn}{\deffngeneral{}}
519838494Sobrien
5199174294Sobrien% @deffn category class name args
5200174294Sobrien\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
520138494Sobrien
5202174294Sobrien% \defopon {category on}class name args
5203174294Sobrien\def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
520438494Sobrien
5205174294Sobrien% \deffngeneral {subind}category name args
5206174294Sobrien%
5207174294Sobrien\def\deffngeneral#1#2 #3 #4\endheader{%
5208174294Sobrien  % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
5209174294Sobrien  \dosubind{fn}{\code{#3}}{#1}%
5210174294Sobrien  \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
521138494Sobrien}
521238494Sobrien
5213174294Sobrien%%% Typed functions:
521438494Sobrien
5215174294Sobrien% @deftypefn category type name args
5216174294Sobrien\makedefun{deftypefn}{\deftypefngeneral{}}
521738494Sobrien
5218174294Sobrien% @deftypeop category class type name args
5219174294Sobrien\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
522038494Sobrien
5221174294Sobrien% \deftypeopon {category on}class type name args
5222174294Sobrien\def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
522338494Sobrien
5224174294Sobrien% \deftypefngeneral {subind}category type name args
5225174294Sobrien%
5226174294Sobrien\def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
5227174294Sobrien  \dosubind{fn}{\code{#4}}{#1}%
5228174294Sobrien  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
522938494Sobrien}
523038494Sobrien
5231174294Sobrien%%% Typed variables:
523238494Sobrien
5233174294Sobrien% @deftypevr category type var args
5234174294Sobrien\makedefun{deftypevr}{\deftypecvgeneral{}}
523538494Sobrien
5236174294Sobrien% @deftypecv category class type var args
5237174294Sobrien\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
523838494Sobrien
5239174294Sobrien% \deftypecvof {category of}class type var args
5240174294Sobrien\def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
524138494Sobrien
5242174294Sobrien% \deftypecvgeneral {subind}category type var args
5243174294Sobrien%
5244174294Sobrien\def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
5245174294Sobrien  \dosubind{vr}{\code{#4}}{#1}%
5246174294Sobrien  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
524738494Sobrien}
524838494Sobrien
5249174294Sobrien%%% Untyped variables:
525038494Sobrien
5251174294Sobrien% @defvr category var args
5252174294Sobrien\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
525338494Sobrien
5254174294Sobrien% @defcv category class var args
5255174294Sobrien\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
525638494Sobrien
5257174294Sobrien% \defcvof {category of}class var args
5258174294Sobrien\def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
525938494Sobrien
5260174294Sobrien%%% Type:
5261174294Sobrien% @deftp category name args
5262174294Sobrien\makedefun{deftp}#1 #2 #3\endheader{%
5263174294Sobrien  \doind{tp}{\code{#2}}%
5264174294Sobrien  \defname{#1}{}{#2}\defunargs{#3\unskip}%
526538494Sobrien}
526638494Sobrien
5267174294Sobrien% Remaining @defun-like shortcuts:
5268174294Sobrien\makedefun{defun}{\deffnheader{\putwordDeffunc} }
5269174294Sobrien\makedefun{defmac}{\deffnheader{\putwordDefmac} }
5270174294Sobrien\makedefun{defspec}{\deffnheader{\putwordDefspec} }
5271174294Sobrien\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
5272174294Sobrien\makedefun{defvar}{\defvrheader{\putwordDefvar} }
5273174294Sobrien\makedefun{defopt}{\defvrheader{\putwordDefopt} }
5274174294Sobrien\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
5275174294Sobrien\makedefun{defmethod}{\defopon\putwordMethodon}
5276174294Sobrien\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
5277174294Sobrien\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
5278174294Sobrien\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
527938494Sobrien
5280174294Sobrien% \defname, which formats the name of the @def (not the args).
5281174294Sobrien% #1 is the category, such as "Function".
5282174294Sobrien% #2 is the return type, if any.
5283174294Sobrien% #3 is the function name.
528482794Sobrien%
5285174294Sobrien% We are followed by (but not passed) the arguments, if any.
528682794Sobrien%
5287174294Sobrien\def\defname#1#2#3{%
5288174294Sobrien  % Get the values of \leftskip and \rightskip as they were outside the @def...
5289174294Sobrien  \advance\leftskip by -\defbodyindent
5290174294Sobrien  %
5291174294Sobrien  % How we'll format the type name.  Putting it in brackets helps
5292174294Sobrien  % distinguish it from the body text that may end up on the next line
5293174294Sobrien  % just below it.
5294174294Sobrien  \def\temp{#1}%
5295174294Sobrien  \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
5296174294Sobrien  %
5297174294Sobrien  % Figure out line sizes for the paragraph shape.
5298174294Sobrien  % The first line needs space for \box0; but if \rightskip is nonzero,
5299174294Sobrien  % we need only space for the part of \box0 which exceeds it:
5300174294Sobrien  \dimen0=\hsize  \advance\dimen0 by -\wd0  \advance\dimen0 by \rightskip
5301174294Sobrien  % The continuations:
5302174294Sobrien  \dimen2=\hsize  \advance\dimen2 by -\defargsindent
5303174294Sobrien  % (plain.tex says that \dimen1 should be used only as global.)
5304174294Sobrien  \parshape 2 0in \dimen0 \defargsindent \dimen2
5305174294Sobrien  %
5306174294Sobrien  % Put the type name to the right margin.
5307174294Sobrien  \noindent
5308174294Sobrien  \hbox to 0pt{%
5309174294Sobrien    \hfil\box0 \kern-\hsize
5310174294Sobrien    % \hsize has to be shortened this way:
5311174294Sobrien    \kern\leftskip
5312174294Sobrien    % Intentionally do not respect \rightskip, since we need the space.
5313174294Sobrien  }%
5314174294Sobrien  %
5315174294Sobrien  % Allow all lines to be underfull without complaint:
5316174294Sobrien  \tolerance=10000 \hbadness=10000
5317174294Sobrien  \exdentamount=\defbodyindent
5318174294Sobrien  {%
5319174294Sobrien    % defun fonts. We use typewriter by default (used to be bold) because:
5320174294Sobrien    % . we're printing identifiers, they should be in tt in principle.
5321174294Sobrien    % . in languages with many accents, such as Czech or French, it's
5322174294Sobrien    %   common to leave accents off identifiers.  The result looks ok in
5323174294Sobrien    %   tt, but exceedingly strange in rm.
5324174294Sobrien    % . we don't want -- and --- to be treated as ligatures.
5325174294Sobrien    % . this still does not fix the ?` and !` ligatures, but so far no
5326174294Sobrien    %   one has made identifiers using them :).
5327174294Sobrien    \df \tt
5328174294Sobrien    \def\temp{#2}% return value type
5329174294Sobrien    \ifx\temp\empty\else \tclose{\temp} \fi
5330174294Sobrien    #3% output function name
5331174294Sobrien  }%
5332174294Sobrien  {\rm\enskip}% hskip 0.5 em of \tenrm
5333174294Sobrien  %
5334174294Sobrien  \boldbrax
5335174294Sobrien  % arguments will be output next, if any.
533638494Sobrien}
533738494Sobrien
5338174294Sobrien% Print arguments in slanted roman (not ttsl), inconsistently with using
5339174294Sobrien% tt for the name.  This is because literal text is sometimes needed in
5340174294Sobrien% the argument list (groff manual), and ttsl and tt are not very
5341174294Sobrien% distinguishable.  Prevent hyphenation at `-' chars.
534238494Sobrien%
5343174294Sobrien\def\defunargs#1{%
5344174294Sobrien  % use sl by default (not ttsl),
5345174294Sobrien  % tt for the names.
5346174294Sobrien  \df \sl \hyphenchar\font=0
5347174294Sobrien  %
5348174294Sobrien  % On the other hand, if an argument has two dashes (for instance), we
5349174294Sobrien  % want a way to get ttsl.  Let's try @var for that.
5350174294Sobrien  \let\var=\ttslanted
5351174294Sobrien  #1%
5352174294Sobrien  \sl\hyphenchar\font=45
535382794Sobrien}
535482794Sobrien
5355174294Sobrien% We want ()&[] to print specially on the defun line.
535682794Sobrien%
5357174294Sobrien\def\activeparens{%
5358174294Sobrien  \catcode`\(=\active \catcode`\)=\active
5359174294Sobrien  \catcode`\[=\active \catcode`\]=\active
5360174294Sobrien  \catcode`\&=\active
536138494Sobrien}
536238494Sobrien
5363174294Sobrien% Make control sequences which act like normal parenthesis chars.
5364174294Sobrien\let\lparen = ( \let\rparen = )
536582794Sobrien
5366174294Sobrien% Be sure that we always have a definition for `(', etc.  For example,
5367174294Sobrien% if the fn name has parens in it, \boldbrax will not be in effect yet,
5368174294Sobrien% so TeX would otherwise complain about undefined control sequence.
5369174294Sobrien{
5370174294Sobrien  \activeparens
5371174294Sobrien  \global\let(=\lparen \global\let)=\rparen
5372174294Sobrien  \global\let[=\lbrack \global\let]=\rbrack
5373174294Sobrien  \global\let& = \&
5374174294Sobrien
5375174294Sobrien  \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
5376174294Sobrien  \gdef\magicamp{\let&=\amprm}
537738494Sobrien}
537838494Sobrien
5379174294Sobrien\newcount\parencount
538038494Sobrien
5381174294Sobrien% If we encounter &foo, then turn on ()-hacking afterwards
5382174294Sobrien\newif\ifampseen
5383174294Sobrien\def\amprm#1 {\ampseentrue{\bf\&#1 }}
538438494Sobrien
5385174294Sobrien\def\parenfont{%
5386174294Sobrien  \ifampseen
5387174294Sobrien    % At the first level, print parens in roman,
5388174294Sobrien    % otherwise use the default font.
5389174294Sobrien    \ifnum \parencount=1 \rm \fi
5390174294Sobrien  \else
5391174294Sobrien    % The \sf parens (in \boldbrax) actually are a little bolder than
5392174294Sobrien    % the contained text.  This is especially needed for [ and ] .
5393174294Sobrien    \sf
5394174294Sobrien  \fi
539538494Sobrien}
5396174294Sobrien\def\infirstlevel#1{%
5397174294Sobrien  \ifampseen
5398174294Sobrien    \ifnum\parencount=1
5399174294Sobrien      #1%
5400174294Sobrien    \fi
5401174294Sobrien  \fi
5402174294Sobrien}
5403174294Sobrien\def\bfafterword#1 {#1 \bf}
540438494Sobrien
5405174294Sobrien\def\opnr{%
5406174294Sobrien  \global\advance\parencount by 1
5407174294Sobrien  {\parenfont(}%
5408174294Sobrien  \infirstlevel \bfafterword
540938494Sobrien}
5410174294Sobrien\def\clnr{%
5411174294Sobrien  {\parenfont)}%
5412174294Sobrien  \infirstlevel \sl
5413174294Sobrien  \global\advance\parencount by -1
5414174294Sobrien}
541538494Sobrien
5416174294Sobrien\newcount\brackcount
5417174294Sobrien\def\lbrb{%
5418174294Sobrien  \global\advance\brackcount by 1
5419174294Sobrien  {\bf[}%
542038494Sobrien}
5421174294Sobrien\def\rbrb{%
5422174294Sobrien  {\bf]}%
5423174294Sobrien  \global\advance\brackcount by -1
5424174294Sobrien}
542538494Sobrien
5426174294Sobrien\def\checkparencounts{%
5427174294Sobrien  \ifnum\parencount=0 \else \badparencount \fi
5428174294Sobrien  \ifnum\brackcount=0 \else \badbrackcount \fi
542938494Sobrien}
5430174294Sobrien\def\badparencount{%
5431174294Sobrien  \errmessage{Unbalanced parentheses in @def}%
5432174294Sobrien  \global\parencount=0
5433174294Sobrien}
5434174294Sobrien\def\badbrackcount{%
5435174294Sobrien  \errmessage{Unbalanced square braces in @def}%
5436174294Sobrien  \global\brackcount=0
5437174294Sobrien}
543838494Sobrien
543938494Sobrien
544042629Sobrien\message{macros,}
544142629Sobrien% @macro.
544238494Sobrien
544382794Sobrien% To do this right we need a feature of e-TeX, \scantokens,
544442629Sobrien% which we arrange to emulate with a temporary file in ordinary TeX.
544542629Sobrien\ifx\eTeXversion\undefined
5446174294Sobrien  \newwrite\macscribble
5447174294Sobrien  \def\scantokens#1{%
5448174294Sobrien    \toks0={#1}%
5449174294Sobrien    \immediate\openout\macscribble=\jobname.tmp
5450174294Sobrien    \immediate\write\macscribble{\the\toks0}%
5451174294Sobrien    \immediate\closeout\macscribble
5452174294Sobrien    \input \jobname.tmp
5453174294Sobrien  }
545442629Sobrien\fi
545542629Sobrien
5456174294Sobrien\def\scanmacro#1{%
5457174294Sobrien  \begingroup
5458174294Sobrien    \newlinechar`\^^M
5459174294Sobrien    \let\xeatspaces\eatspaces
5460174294Sobrien    % Undo catcode changes of \startcontents and \doprintindex
5461174294Sobrien    % When called from @insertcopying or (short)caption, we need active
5462174294Sobrien    % backslash to get it printed correctly.  Previously, we had
5463174294Sobrien    % \catcode`\\=\other instead.  We'll see whether a problem appears
5464174294Sobrien    % with macro expansion.				--kasal, 19aug04
5465174294Sobrien    \catcode`\@=0 \catcode`\\=\active \escapechar=`\@
5466174294Sobrien    % ... and \example
5467174294Sobrien    \spaceisspace
5468174294Sobrien    %
5469174294Sobrien    % Append \endinput to make sure that TeX does not see the ending newline.
5470174294Sobrien    %
5471174294Sobrien    % I've verified that it is necessary both for e-TeX and for ordinary TeX
5472174294Sobrien    %							--kasal, 29nov03
5473174294Sobrien    \scantokens{#1\endinput}%
5474174294Sobrien  \endgroup
5475174294Sobrien}
5476174294Sobrien
5477174294Sobrien\def\scanexp#1{%
5478174294Sobrien  \edef\temp{\noexpand\scanmacro{#1}}%
5479174294Sobrien  \temp
5480174294Sobrien}
5481174294Sobrien
548242629Sobrien\newcount\paramno   % Count of parameters
548342629Sobrien\newtoks\macname    % Macro name
548442629Sobrien\newif\ifrecursive  % Is it recursive?
548582794Sobrien\def\macrolist{}    % List of all defined macros in the form
548682794Sobrien                    % \do\macro1\do\macro2...
548742629Sobrien
548842629Sobrien% Utility routines.
5489174294Sobrien% This does \let #1 = #2, with \csnames; that is,
5490174294Sobrien%   \let \csname#1\endcsname = \csname#2\endcsname
5491174294Sobrien% (except of course we have to play expansion games).
5492174294Sobrien% 
549342629Sobrien\def\cslet#1#2{%
5494174294Sobrien  \expandafter\let
5495174294Sobrien  \csname#1\expandafter\endcsname
5496174294Sobrien  \csname#2\endcsname
5497174294Sobrien}
549842629Sobrien
549942629Sobrien% Trim leading and trailing spaces off a string.
550042629Sobrien% Concepts from aro-bend problem 15 (see CTAN).
550142629Sobrien{\catcode`\@=11
550242629Sobrien\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
550342629Sobrien\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
550442629Sobrien\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
550542629Sobrien\def\unbrace#1{#1}
550642629Sobrien\unbrace{\gdef\trim@@@ #1 } #2@{#1}
550742629Sobrien}
550842629Sobrien
550942629Sobrien% Trim a single trailing ^^M off a string.
5510174294Sobrien{\catcode`\^^M=\other \catcode`\Q=3%
551142629Sobrien\gdef\eatcr #1{\eatcra #1Q^^MQ}%
551242629Sobrien\gdef\eatcra#1^^MQ{\eatcrb#1Q}%
551342629Sobrien\gdef\eatcrb#1Q#2Q{#1}%
551442629Sobrien}
551542629Sobrien
551642629Sobrien% Macro bodies are absorbed as an argument in a context where
551742629Sobrien% all characters are catcode 10, 11 or 12, except \ which is active
551842629Sobrien% (as in normal texinfo). It is necessary to change the definition of \.
551942629Sobrien
552082794Sobrien% It's necessary to have hard CRs when the macro is executed. This is
552182794Sobrien% done by  making ^^M (\endlinechar) catcode 12 when reading the macro
552242629Sobrien% body, and then making it the \newlinechar in \scanmacro.
552342629Sobrien
5524174294Sobrien\def\scanctxt{%
5525174294Sobrien  \catcode`\"=\other
5526174294Sobrien  \catcode`\+=\other
5527174294Sobrien  \catcode`\<=\other
5528174294Sobrien  \catcode`\>=\other
5529174294Sobrien  \catcode`\@=\other
5530174294Sobrien  \catcode`\^=\other
5531174294Sobrien  \catcode`\_=\other
5532174294Sobrien  \catcode`\|=\other
5533174294Sobrien  \catcode`\~=\other
5534174294Sobrien}
5535174294Sobrien
5536174294Sobrien\def\scanargctxt{%
5537174294Sobrien  \scanctxt
5538174294Sobrien  \catcode`\\=\other
5539174294Sobrien  \catcode`\^^M=\other
5540174294Sobrien}
5541174294Sobrien
554242629Sobrien\def\macrobodyctxt{%
5543174294Sobrien  \scanctxt
5544174294Sobrien  \catcode`\{=\other
5545174294Sobrien  \catcode`\}=\other
5546174294Sobrien  \catcode`\^^M=\other
5547174294Sobrien  \usembodybackslash
5548174294Sobrien}
554942629Sobrien
555042629Sobrien\def\macroargctxt{%
5551174294Sobrien  \scanctxt
5552174294Sobrien  \catcode`\\=\other
5553174294Sobrien}
555442629Sobrien
555542629Sobrien% \mbodybackslash is the definition of \ in @macro bodies.
555682794Sobrien% It maps \foo\ => \csname macarg.foo\endcsname => #N
555742629Sobrien% where N is the macro parameter number.
555842629Sobrien% We define \csname macarg.\endcsname to be \realbackslash, so
555942629Sobrien% \\ in macro replacement text gets you a backslash.
556042629Sobrien
556142629Sobrien{\catcode`@=0 @catcode`@\=@active
556242629Sobrien @gdef@usembodybackslash{@let\=@mbodybackslash}
556342629Sobrien @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
556442629Sobrien}
556542629Sobrien\expandafter\def\csname macarg.\endcsname{\realbackslash}
556642629Sobrien
556742629Sobrien\def\macro{\recursivefalse\parsearg\macroxxx}
556842629Sobrien\def\rmacro{\recursivetrue\parsearg\macroxxx}
556942629Sobrien
557042629Sobrien\def\macroxxx#1{%
557142629Sobrien  \getargs{#1}%           now \macname is the macname and \argl the arglist
557242629Sobrien  \ifx\argl\empty       % no arguments
557342629Sobrien     \paramno=0%
557442629Sobrien  \else
557582794Sobrien     \expandafter\parsemargdef \argl;%
557642629Sobrien  \fi
557782794Sobrien  \if1\csname ismacro.\the\macname\endcsname
557882794Sobrien     \message{Warning: redefining \the\macname}%
557942629Sobrien  \else
558082794Sobrien     \expandafter\ifx\csname \the\macname\endcsname \relax
5581119679Smbr     \else \errmessage{Macro name \the\macname\space already defined}\fi
558282794Sobrien     \global\cslet{macsave.\the\macname}{\the\macname}%
558382794Sobrien     \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
558482794Sobrien     % Add the macroname to \macrolist
558582794Sobrien     \toks0 = \expandafter{\macrolist\do}%
558682794Sobrien     \xdef\macrolist{\the\toks0
558782794Sobrien       \expandafter\noexpand\csname\the\macname\endcsname}%
558842629Sobrien  \fi
558942629Sobrien  \begingroup \macrobodyctxt
559042629Sobrien  \ifrecursive \expandafter\parsermacbody
559182794Sobrien  \else \expandafter\parsemacbody
559242629Sobrien  \fi}
559342629Sobrien
5594174294Sobrien\parseargdef\unmacro{%
559582794Sobrien  \if1\csname ismacro.#1\endcsname
559682794Sobrien    \global\cslet{#1}{macsave.#1}%
559782794Sobrien    \global\expandafter\let \csname ismacro.#1\endcsname=0%
5598174294Sobrien    % Remove the macro name from \macrolist:
559982794Sobrien    \begingroup
5600174294Sobrien      \expandafter\let\csname#1\endcsname \relax
5601174294Sobrien      \let\do\unmacrodo
5602174294Sobrien      \xdef\macrolist{\macrolist}%
560382794Sobrien    \endgroup
560442629Sobrien  \else
560582794Sobrien    \errmessage{Macro #1 not defined}%
560642629Sobrien  \fi
560742629Sobrien}
560842629Sobrien
5609174294Sobrien% Called by \do from \dounmacro on each macro.  The idea is to omit any
5610174294Sobrien% macro definitions that have been changed to \relax.
5611174294Sobrien%
5612174294Sobrien\def\unmacrodo#1{%
5613174294Sobrien  \ifx#1\relax
5614174294Sobrien    % remove this
5615174294Sobrien  \else
5616174294Sobrien    \noexpand\do \noexpand #1%
5617174294Sobrien  \fi
5618174294Sobrien}
5619174294Sobrien
562042629Sobrien% This makes use of the obscure feature that if the last token of a
562142629Sobrien% <parameter list> is #, then the preceding argument is delimited by
562242629Sobrien% an opening brace, and that opening brace is not consumed.
562342629Sobrien\def\getargs#1{\getargsxxx#1{}}
562442629Sobrien\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
562542629Sobrien\def\getmacname #1 #2\relax{\macname={#1}}
562642629Sobrien\def\getmacargs#1{\def\argl{#1}}
562742629Sobrien
562842629Sobrien% Parse the optional {params} list.  Set up \paramno and \paramlist
562942629Sobrien% so \defmacro knows what to do.  Define \macarg.blah for each blah
563042629Sobrien% in the params list, to be ##N where N is the position in that list.
563142629Sobrien% That gets used by \mbodybackslash (above).
563242629Sobrien
563342629Sobrien% We need to get `macro parameter char #' into several definitions.
563442629Sobrien% The technique used is stolen from LaTeX:  let \hash be something
563542629Sobrien% unexpandable, insert that wherever you need a #, and then redefine
563642629Sobrien% it to # just before using the token list produced.
563742629Sobrien%
563842629Sobrien% The same technique is used to protect \eatspaces till just before
563942629Sobrien% the macro is used.
564042629Sobrien
564142629Sobrien\def\parsemargdef#1;{\paramno=0\def\paramlist{}%
564242629Sobrien        \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,}
564342629Sobrien\def\parsemargdefxxx#1,{%
564442629Sobrien  \if#1;\let\next=\relax
564542629Sobrien  \else \let\next=\parsemargdefxxx
564642629Sobrien    \advance\paramno by 1%
564742629Sobrien    \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
564842629Sobrien        {\xeatspaces{\hash\the\paramno}}%
564942629Sobrien    \edef\paramlist{\paramlist\hash\the\paramno,}%
565042629Sobrien  \fi\next}
565142629Sobrien
565242629Sobrien% These two commands read recursive and nonrecursive macro bodies.
565342629Sobrien% (They're different since rec and nonrec macros end differently.)
565442629Sobrien
565542629Sobrien\long\def\parsemacbody#1@end macro%
565642629Sobrien{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
565742629Sobrien\long\def\parsermacbody#1@end rmacro%
565842629Sobrien{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
565942629Sobrien
566042629Sobrien% This defines the macro itself. There are six cases: recursive and
566142629Sobrien% nonrecursive macros of zero, one, and many arguments.
566242629Sobrien% Much magic with \expandafter here.
566342629Sobrien% \xdef is used so that macro definitions will survive the file
566442629Sobrien% they're defined in; @include reads the file inside a group.
566542629Sobrien\def\defmacro{%
566642629Sobrien  \let\hash=##% convert placeholders to macro parameter chars
566742629Sobrien  \ifrecursive
566842629Sobrien    \ifcase\paramno
566942629Sobrien    % 0
567042629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
567142629Sobrien        \noexpand\scanmacro{\temp}}%
567242629Sobrien    \or % 1
567342629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
567442629Sobrien         \bgroup\noexpand\macroargctxt
567582794Sobrien         \noexpand\braceorline
567682794Sobrien         \expandafter\noexpand\csname\the\macname xxx\endcsname}%
567742629Sobrien      \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
567842629Sobrien         \egroup\noexpand\scanmacro{\temp}}%
567942629Sobrien    \else % many
568042629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
568142629Sobrien         \bgroup\noexpand\macroargctxt
568282794Sobrien         \noexpand\csname\the\macname xx\endcsname}%
568342629Sobrien      \expandafter\xdef\csname\the\macname xx\endcsname##1{%
568482794Sobrien          \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
568542629Sobrien      \expandafter\expandafter
568642629Sobrien      \expandafter\xdef
568742629Sobrien      \expandafter\expandafter
568882794Sobrien        \csname\the\macname xxx\endcsname
568942629Sobrien          \paramlist{\egroup\noexpand\scanmacro{\temp}}%
569042629Sobrien    \fi
569142629Sobrien  \else
569242629Sobrien    \ifcase\paramno
569342629Sobrien    % 0
569442629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
569542629Sobrien        \noexpand\norecurse{\the\macname}%
569642629Sobrien        \noexpand\scanmacro{\temp}\egroup}%
569742629Sobrien    \or % 1
569842629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
569942629Sobrien         \bgroup\noexpand\macroargctxt
570082794Sobrien         \noexpand\braceorline
570182794Sobrien         \expandafter\noexpand\csname\the\macname xxx\endcsname}%
570242629Sobrien      \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
570342629Sobrien        \egroup
570442629Sobrien        \noexpand\norecurse{\the\macname}%
570542629Sobrien        \noexpand\scanmacro{\temp}\egroup}%
570642629Sobrien    \else % many
570742629Sobrien      \expandafter\xdef\csname\the\macname\endcsname{%
570842629Sobrien         \bgroup\noexpand\macroargctxt
570982794Sobrien         \expandafter\noexpand\csname\the\macname xx\endcsname}%
571042629Sobrien      \expandafter\xdef\csname\the\macname xx\endcsname##1{%
571182794Sobrien          \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
571242629Sobrien      \expandafter\expandafter
571342629Sobrien      \expandafter\xdef
571442629Sobrien      \expandafter\expandafter
571542629Sobrien      \csname\the\macname xxx\endcsname
571642629Sobrien      \paramlist{%
571742629Sobrien          \egroup
571842629Sobrien          \noexpand\norecurse{\the\macname}%
571942629Sobrien          \noexpand\scanmacro{\temp}\egroup}%
572042629Sobrien    \fi
572142629Sobrien  \fi}
572242629Sobrien
572342629Sobrien\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
572442629Sobrien
572542629Sobrien% \braceorline decides whether the next nonwhitespace character is a
572642629Sobrien% {.  If so it reads up to the closing }, if not, it reads the whole
572742629Sobrien% line.  Whatever was read is then fed to the next control sequence
572842629Sobrien% as an argument (by \parsebrace or \parsearg)
572942629Sobrien\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx}
573042629Sobrien\def\braceorlinexxx{%
573142629Sobrien  \ifx\nchar\bgroup\else
573282794Sobrien    \expandafter\parsearg
573342629Sobrien  \fi \next}
573442629Sobrien
5735174294Sobrien% We want to disable all macros during \shipout so that they are not
573682794Sobrien% expanded by \write.
573782794Sobrien\def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
573882794Sobrien  \edef\next{\macrolist}\expandafter\endgroup\next}
573942629Sobrien
5740174294Sobrien% For \indexnofonts, we need to get rid of all macros, leaving only the
5741174294Sobrien% arguments (if present).  Of course this is not nearly correct, but it
5742174294Sobrien% is the best we can do for now.  makeinfo does not expand macros in the
5743174294Sobrien% argument to @deffn, which ends up writing an index entry, and texindex
5744174294Sobrien% isn't prepared for an index sort entry that starts with \.
5745174294Sobrien% 
5746174294Sobrien% Since macro invocations are followed by braces, we can just redefine them
5747174294Sobrien% to take a single TeX argument.  The case of a macro invocation that
5748174294Sobrien% goes to end-of-line is not handled.
5749174294Sobrien% 
5750174294Sobrien\def\emptyusermacros{\begingroup
5751174294Sobrien  \def\do##1{\let\noexpand##1=\noexpand\asis}%
5752174294Sobrien  \edef\next{\macrolist}\expandafter\endgroup\next}
575382794Sobrien
5754174294Sobrien
575582794Sobrien% @alias.
575682794Sobrien% We need some trickery to remove the optional spaces around the equal
575782794Sobrien% sign.  Just make them active and then expand them all to nothing.
5758174294Sobrien\def\alias{\parseargusing\obeyspaces\aliasxxx}
575982794Sobrien\def\aliasxxx #1{\aliasyyy#1\relax}
5760174294Sobrien\def\aliasyyy #1=#2\relax{%
5761174294Sobrien  {%
5762174294Sobrien    \expandafter\let\obeyedspace=\empty
5763174294Sobrien    \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
5764174294Sobrien  }%
5765174294Sobrien  \next
5766174294Sobrien}
576782794Sobrien
576882794Sobrien
576942629Sobrien\message{cross references,}
577082794Sobrien
577142629Sobrien\newwrite\auxfile
577242629Sobrien
577342629Sobrien\newif\ifhavexrefs    % True if xref values are known.
577438494Sobrien\newif\ifwarnedxrefs  % True if we warned once that they aren't known.
577538494Sobrien
577642629Sobrien% @inforef is relatively simple.
577738494Sobrien\def\inforef #1{\inforefzzz #1,,,,**}
577838494Sobrien\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
577938494Sobrien  node \samp{\ignorespaces#1{}}}
578038494Sobrien
5781174294Sobrien% @node's only job in TeX is to define \lastnode, which is used in
5782174294Sobrien% cross-references.  The @node line might or might not have commas, and
5783174294Sobrien% might or might not have spaces before the first comma, like:
5784174294Sobrien% @node foo , bar , ...
5785174294Sobrien% We don't want such trailing spaces in the node name.
5786174294Sobrien%
5787174294Sobrien\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
5788174294Sobrien%
5789174294Sobrien% also remove a trailing comma, in case of something like this:
5790174294Sobrien% @node Help-Cross,  ,  , Cross-refs
5791174294Sobrien\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
5792174294Sobrien\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
5793174294Sobrien
579442629Sobrien\let\nwnode=\node
5795174294Sobrien\let\lastnode=\empty
579638494Sobrien
5797174294Sobrien% Write a cross-reference definition for the current node.  #1 is the
5798174294Sobrien% type (Ynumbered, Yappendix, Ynothing).
5799174294Sobrien%
5800174294Sobrien\def\donoderef#1{%
5801174294Sobrien  \ifx\lastnode\empty\else
5802174294Sobrien    \setref{\lastnode}{#1}%
5803174294Sobrien    \global\let\lastnode=\empty
580442629Sobrien  \fi
580542629Sobrien}
580638494Sobrien
580742629Sobrien% @anchor{NAME} -- define xref target at arbitrary point.
580882794Sobrien%
580982794Sobrien\newcount\savesfregister
5810174294Sobrien%
5811174294Sobrien\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
5812174294Sobrien\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
5813174294Sobrien\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
581438494Sobrien
5815174294Sobrien% \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
5816174294Sobrien% anchor), which consists of three parts:
5817174294Sobrien% 1) NAME-title - the current sectioning name taken from \thissection,
5818174294Sobrien%                 or the anchor name.
5819174294Sobrien% 2) NAME-snt   - section number and type, passed as the SNT arg, or
5820174294Sobrien%                 empty for anchors.
5821174294Sobrien% 3) NAME-pg    - the page number.
582282794Sobrien%
5823174294Sobrien% This is called from \donoderef, \anchor, and \dofloat.  In the case of
5824174294Sobrien% floats, there is an additional part, which is not written here:
5825174294Sobrien% 4) NAME-lof   - the text as it should appear in a @listoffloats.
5826174294Sobrien%
5827174294Sobrien\def\setref#1#2{%
582882794Sobrien  \pdfmkdest{#1}%
5829174294Sobrien  \iflinks
5830174294Sobrien    {%
5831174294Sobrien      \atdummies  % preserve commands, but don't expand them
5832174294Sobrien      \turnoffactive
5833174294Sobrien      \otherbackslash
5834174294Sobrien      \edef\writexrdef##1##2{%
5835174294Sobrien	\write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
5836174294Sobrien	  ##1}{##2}}% these are parameters of \writexrdef
5837174294Sobrien      }%
5838174294Sobrien      \toks0 = \expandafter{\thissection}%
5839174294Sobrien      \immediate \writexrdef{title}{\the\toks0 }%
5840174294Sobrien      \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
5841174294Sobrien      \writexrdef{pg}{\folio}% will be written later, during \shipout
5842174294Sobrien    }%
5843174294Sobrien  \fi
5844174294Sobrien}
584542629Sobrien
584642629Sobrien% @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
584742629Sobrien% the node name, #2 the name of the Info cross-reference, #3 the printed
584842629Sobrien% node name, #4 the name of the Info file, #5 the name of the printed
584942629Sobrien% manual.  All but the node name can be omitted.
585038494Sobrien%
585138494Sobrien\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
585238494Sobrien\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
585338494Sobrien\def\ref#1{\xrefX[#1,,,,,,,]}
585438494Sobrien\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
585582794Sobrien  \unsepspaces
585638494Sobrien  \def\printedmanual{\ignorespaces #5}%
5857174294Sobrien  \def\printedrefname{\ignorespaces #3}%
5858174294Sobrien  \setbox1=\hbox{\printedmanual\unskip}%
5859174294Sobrien  \setbox0=\hbox{\printedrefname\unskip}%
586038494Sobrien  \ifdim \wd0 = 0pt
586138494Sobrien    % No printed node name was explicitly given.
586238494Sobrien    \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
586338494Sobrien      % Use the node name inside the square brackets.
5864174294Sobrien      \def\printedrefname{\ignorespaces #1}%
586538494Sobrien    \else
586638494Sobrien      % Use the actual chapter/section title appear inside
586738494Sobrien      % the square brackets.  Use the real section title if we have it.
586842629Sobrien      \ifdim \wd1 > 0pt
586938494Sobrien        % It is in another manual, so we don't have it.
5870174294Sobrien        \def\printedrefname{\ignorespaces #1}%
587138494Sobrien      \else
587238494Sobrien        \ifhavexrefs
587338494Sobrien          % We know the real title if we have the xref values.
5874174294Sobrien          \def\printedrefname{\refx{#1-title}{}}%
587538494Sobrien        \else
587638494Sobrien          % Otherwise just copy the Info node name.
5877174294Sobrien          \def\printedrefname{\ignorespaces #1}%
587838494Sobrien        \fi%
587938494Sobrien      \fi
588038494Sobrien    \fi
588138494Sobrien  \fi
588238494Sobrien  %
5883174294Sobrien  % Make link in pdf output.
588482794Sobrien  \ifpdf
588582794Sobrien    \leavevmode
588682794Sobrien    \getfilename{#4}%
5887174294Sobrien    {\turnoffactive \otherbackslash
588882794Sobrien     \ifnum\filenamelength>0
588982794Sobrien       \startlink attr{/Border [0 0 0]}%
589082794Sobrien         goto file{\the\filename.pdf} name{#1}%
589182794Sobrien     \else
589282794Sobrien       \startlink attr{/Border [0 0 0]}%
5893174294Sobrien         goto name{\pdfmkpgn{#1}}%
589482794Sobrien     \fi
589582794Sobrien    }%
589682794Sobrien    \linkcolor
589782794Sobrien  \fi
589882794Sobrien  %
5899174294Sobrien  % Float references are printed completely differently: "Figure 1.2"
5900174294Sobrien  % instead of "[somenode], p.3".  We distinguish them by the
5901174294Sobrien  % LABEL-title being set to a magic string.
5902174294Sobrien  {%
5903174294Sobrien    % Have to otherify everything special to allow the \csname to
5904174294Sobrien    % include an _ in the xref name, etc.
5905174294Sobrien    \indexnofonts
5906174294Sobrien    \turnoffactive
5907174294Sobrien    \otherbackslash
5908174294Sobrien    \expandafter\global\expandafter\let\expandafter\Xthisreftitle
5909174294Sobrien      \csname XR#1-title\endcsname
5910174294Sobrien  }%
5911174294Sobrien  \iffloat\Xthisreftitle
5912174294Sobrien    % If the user specified the print name (third arg) to the ref,
5913174294Sobrien    % print it instead of our usual "Figure 1.2".
5914174294Sobrien    \ifdim\wd0 = 0pt
5915174294Sobrien      \refx{#1-snt}%
5916174294Sobrien    \else
5917174294Sobrien      \printedrefname
5918174294Sobrien    \fi
5919174294Sobrien    %
5920174294Sobrien    % if the user also gave the printed manual name (fifth arg), append
5921174294Sobrien    % "in MANUALNAME".
5922174294Sobrien    \ifdim \wd1 > 0pt
5923174294Sobrien      \space \putwordin{} \cite{\printedmanual}%
5924174294Sobrien    \fi
592538494Sobrien  \else
5926174294Sobrien    % node/anchor (non-float) references.
5927174294Sobrien    %
5928174294Sobrien    % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
5929174294Sobrien    % insert empty discretionaries after hyphens, which means that it will
5930174294Sobrien    % not find a line break at a hyphen in a node names.  Since some manuals
5931174294Sobrien    % are best written with fairly long node names, containing hyphens, this
5932174294Sobrien    % is a loss.  Therefore, we give the text of the node name again, so it
5933174294Sobrien    % is as if TeX is seeing it for the first time.
5934174294Sobrien    \ifdim \wd1 > 0pt
5935174294Sobrien      \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
5936174294Sobrien    \else
5937174294Sobrien      % _ (for example) has to be the character _ for the purposes of the
5938174294Sobrien      % control sequence corresponding to the node, but it has to expand
5939174294Sobrien      % into the usual \leavevmode...\vrule stuff for purposes of
5940174294Sobrien      % printing. So we \turnoffactive for the \refx-snt, back on for the
5941174294Sobrien      % printing, back off for the \refx-pg.
5942174294Sobrien      {\turnoffactive \otherbackslash
5943174294Sobrien       % Only output a following space if the -snt ref is nonempty; for
5944174294Sobrien       % @unnumbered and @anchor, it won't be.
5945174294Sobrien       \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
5946174294Sobrien       \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
5947174294Sobrien      }%
5948174294Sobrien      % output the `[mynode]' via a macro so it can be overridden.
5949174294Sobrien      \xrefprintnodename\printedrefname
5950174294Sobrien      %
5951174294Sobrien      % But we always want a comma and a space:
5952174294Sobrien      ,\space
5953174294Sobrien      %
5954174294Sobrien      % output the `page 3'.
5955174294Sobrien      \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
5956174294Sobrien    \fi
595738494Sobrien  \fi
595882794Sobrien  \endlink
595938494Sobrien\endgroup}
596038494Sobrien
5961174294Sobrien% This macro is called from \xrefX for the `[nodename]' part of xref
5962174294Sobrien% output.  It's a separate macro only so it can be changed more easily,
5963174294Sobrien% since square brackets don't work well in some documents.  Particularly
5964174294Sobrien% one that Bob is working on :).
5965174294Sobrien%
5966174294Sobrien\def\xrefprintnodename#1{[#1]}
596738494Sobrien
5968174294Sobrien% Things referred to by \setref.
5969174294Sobrien%
5970174294Sobrien\def\Ynothing{}
5971174294Sobrien\def\Yomitfromtoc{}
5972174294Sobrien\def\Ynumbered{%
5973174294Sobrien  \ifnum\secno=0
5974174294Sobrien    \putwordChapter@tie \the\chapno
5975174294Sobrien  \else \ifnum\subsecno=0
5976174294Sobrien    \putwordSection@tie \the\chapno.\the\secno
5977174294Sobrien  \else \ifnum\subsubsecno=0
5978174294Sobrien    \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
5979174294Sobrien  \else
5980174294Sobrien    \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
5981174294Sobrien  \fi\fi\fi
598242629Sobrien}
5983174294Sobrien\def\Yappendix{%
5984174294Sobrien  \ifnum\secno=0
5985174294Sobrien     \putwordAppendix@tie @char\the\appendixno{}%
5986174294Sobrien  \else \ifnum\subsecno=0
5987174294Sobrien     \putwordSection@tie @char\the\appendixno.\the\secno
5988174294Sobrien  \else \ifnum\subsubsecno=0
5989174294Sobrien    \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
5990174294Sobrien  \else
5991174294Sobrien    \putwordSection@tie
5992174294Sobrien      @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
5993174294Sobrien  \fi\fi\fi
5994174294Sobrien}
599538494Sobrien
599638494Sobrien% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
599738494Sobrien% If its value is nonempty, SUFFIX is output afterward.
5998174294Sobrien%
599938494Sobrien\def\refx#1#2{%
6000174294Sobrien  {%
6001174294Sobrien    \indexnofonts
6002174294Sobrien    \otherbackslash
6003174294Sobrien    \expandafter\global\expandafter\let\expandafter\thisrefX
6004174294Sobrien      \csname XR#1\endcsname
6005174294Sobrien  }%
6006174294Sobrien  \ifx\thisrefX\relax
600738494Sobrien    % If not defined, say something at least.
600842629Sobrien    \angleleft un\-de\-fined\angleright
600942629Sobrien    \iflinks
601042629Sobrien      \ifhavexrefs
601142629Sobrien        \message{\linenumber Undefined cross reference `#1'.}%
601242629Sobrien      \else
601342629Sobrien        \ifwarnedxrefs\else
601442629Sobrien          \global\warnedxrefstrue
601542629Sobrien          \message{Cross reference values unknown; you must run TeX again.}%
601642629Sobrien        \fi
601738494Sobrien      \fi
601838494Sobrien    \fi
601938494Sobrien  \else
602038494Sobrien    % It's defined, so just use it.
6021174294Sobrien    \thisrefX
602238494Sobrien  \fi
602338494Sobrien  #2% Output the suffix in any case.
602438494Sobrien}
602538494Sobrien
6026174294Sobrien% This is the macro invoked by entries in the aux file.  Usually it's
6027174294Sobrien% just a \def (we prepend XR to the control sequence name to avoid
6028174294Sobrien% collisions).  But if this is a float type, we have more work to do.
602982794Sobrien%
6030174294Sobrien\def\xrdef#1#2{%
6031174294Sobrien  \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value.
6032174294Sobrien  %
6033174294Sobrien  % Was that xref control sequence that we just defined for a float?
6034174294Sobrien  \expandafter\iffloat\csname XR#1\endcsname
6035174294Sobrien    % it was a float, and we have the (safe) float type in \iffloattype.
6036174294Sobrien    \expandafter\let\expandafter\floatlist
6037174294Sobrien      \csname floatlist\iffloattype\endcsname
6038174294Sobrien    %
6039174294Sobrien    % Is this the first time we've seen this float type?
6040174294Sobrien    \expandafter\ifx\floatlist\relax
6041174294Sobrien      \toks0 = {\do}% yes, so just \do
6042174294Sobrien    \else
6043174294Sobrien      % had it before, so preserve previous elements in list.
6044174294Sobrien      \toks0 = \expandafter{\floatlist\do}%
6045174294Sobrien    \fi
6046174294Sobrien    %
6047174294Sobrien    % Remember this xref in the control sequence \floatlistFLOATTYPE,
6048174294Sobrien    % for later use in \listoffloats.
6049174294Sobrien    \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}%
6050174294Sobrien  \fi
605142629Sobrien}
605238494Sobrien
605338494Sobrien% Read the last existing aux file, if any.  No error if none exists.
6054174294Sobrien%
6055174294Sobrien\def\tryauxfile{%
6056174294Sobrien  \openin 1 \jobname.aux
6057174294Sobrien  \ifeof 1 \else
6058174294Sobrien    \readauxfile
6059174294Sobrien    \global\havexrefstrue
6060174294Sobrien  \fi
6061174294Sobrien  \closein 1
6062174294Sobrien}
6063174294Sobrien
606438494Sobrien\def\readauxfile{\begingroup
606538494Sobrien  \catcode`\^^@=\other
606638494Sobrien  \catcode`\^^A=\other
606738494Sobrien  \catcode`\^^B=\other
606838494Sobrien  \catcode`\^^C=\other
606938494Sobrien  \catcode`\^^D=\other
607038494Sobrien  \catcode`\^^E=\other
607138494Sobrien  \catcode`\^^F=\other
607238494Sobrien  \catcode`\^^G=\other
607338494Sobrien  \catcode`\^^H=\other
607438494Sobrien  \catcode`\^^K=\other
607538494Sobrien  \catcode`\^^L=\other
607638494Sobrien  \catcode`\^^N=\other
607738494Sobrien  \catcode`\^^P=\other
607838494Sobrien  \catcode`\^^Q=\other
607938494Sobrien  \catcode`\^^R=\other
608038494Sobrien  \catcode`\^^S=\other
608138494Sobrien  \catcode`\^^T=\other
608238494Sobrien  \catcode`\^^U=\other
608338494Sobrien  \catcode`\^^V=\other
608438494Sobrien  \catcode`\^^W=\other
608538494Sobrien  \catcode`\^^X=\other
608638494Sobrien  \catcode`\^^Z=\other
608738494Sobrien  \catcode`\^^[=\other
608838494Sobrien  \catcode`\^^\=\other
608938494Sobrien  \catcode`\^^]=\other
609038494Sobrien  \catcode`\^^^=\other
609138494Sobrien  \catcode`\^^_=\other
6092174294Sobrien  % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
609338494Sobrien  % in xref tags, i.e., node names.  But since ^^e4 notation isn't
609438494Sobrien  % supported in the main text, it doesn't seem desirable.  Furthermore,
609538494Sobrien  % that is not enough: for node names that actually contain a ^
609638494Sobrien  % character, we would end up writing a line like this: 'xrdef {'hat
609738494Sobrien  % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
609838494Sobrien  % argument, and \hat is not an expandable control sequence.  It could
609938494Sobrien  % all be worked out, but why?  Either we support ^^ or we don't.
610038494Sobrien  %
610138494Sobrien  % The other change necessary for this was to define \auxhat:
610238494Sobrien  % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
610338494Sobrien  % and then to call \auxhat in \setq.
610438494Sobrien  %
6105174294Sobrien  \catcode`\^=\other
6106174294Sobrien  %
6107174294Sobrien  % Special characters.  Should be turned off anyway, but...
610838494Sobrien  \catcode`\~=\other
610938494Sobrien  \catcode`\[=\other
611038494Sobrien  \catcode`\]=\other
611138494Sobrien  \catcode`\"=\other
611238494Sobrien  \catcode`\_=\other
611338494Sobrien  \catcode`\|=\other
611438494Sobrien  \catcode`\<=\other
611538494Sobrien  \catcode`\>=\other
611638494Sobrien  \catcode`\$=\other
611738494Sobrien  \catcode`\#=\other
611838494Sobrien  \catcode`\&=\other
6119174294Sobrien  \catcode`\%=\other
612042629Sobrien  \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
6121174294Sobrien  %
6122174294Sobrien  % This is to support \ in node names and titles, since the \
6123174294Sobrien  % characters end up in a \csname.  It's easier than
6124174294Sobrien  % leaving it active and making its active definition an actual \
6125174294Sobrien  % character.  What I don't understand is why it works in the *value*
6126174294Sobrien  % of the xrdef.  Seems like it should be a catcode12 \, and that
6127174294Sobrien  % should not typeset properly.  But it works, so I'm moving on for
6128174294Sobrien  % now.  --karl, 15jan04.
6129174294Sobrien  \catcode`\\=\other
6130174294Sobrien  %
6131174294Sobrien  % Make the characters 128-255 be printing characters.
613238494Sobrien  {%
613338494Sobrien    \count 1=128
613438494Sobrien    \def\loop{%
613538494Sobrien      \catcode\count 1=\other
613638494Sobrien      \advance\count 1 by 1
613738494Sobrien      \ifnum \count 1<256 \loop \fi
613838494Sobrien    }%
613938494Sobrien  }%
6140174294Sobrien  %
6141174294Sobrien  % @ is our escape character in .aux files, and we need braces.
614238494Sobrien  \catcode`\{=1
614338494Sobrien  \catcode`\}=2
6144174294Sobrien  \catcode`\@=0
614538494Sobrien  %
6146174294Sobrien  \input \jobname.aux
614738494Sobrien\endgroup}
614838494Sobrien
614938494Sobrien
6150174294Sobrien\message{insertions,}
6151174294Sobrien% including footnotes.
615238494Sobrien
615338494Sobrien\newcount \footnoteno
615438494Sobrien
615538494Sobrien% The trailing space in the following definition for supereject is
615638494Sobrien% vital for proper filling; pages come out unaligned when you do a
615738494Sobrien% pagealignmacro call if that space before the closing brace is
615838494Sobrien% removed. (Generally, numeric constants should always be followed by a
615938494Sobrien% space to prevent strange expansion errors.)
616038494Sobrien\def\supereject{\par\penalty -20000\footnoteno =0 }
616138494Sobrien
616238494Sobrien% @footnotestyle is meaningful for info output only.
616338494Sobrien\let\footnotestyle=\comment
616438494Sobrien
616538494Sobrien{\catcode `\@=11
616638494Sobrien%
616738494Sobrien% Auto-number footnotes.  Otherwise like plain.
616838494Sobrien\gdef\footnote{%
6169174294Sobrien  \let\indent=\ptexindent
6170174294Sobrien  \let\noindent=\ptexnoindent
617138494Sobrien  \global\advance\footnoteno by \@ne
617238494Sobrien  \edef\thisfootno{$^{\the\footnoteno}$}%
617338494Sobrien  %
617438494Sobrien  % In case the footnote comes at the end of a sentence, preserve the
617538494Sobrien  % extra spacing after we do the footnote number.
617638494Sobrien  \let\@sf\empty
6177174294Sobrien  \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
617838494Sobrien  %
617938494Sobrien  % Remove inadvertent blank space before typesetting the footnote number.
618038494Sobrien  \unskip
618138494Sobrien  \thisfootno\@sf
6182174294Sobrien  \dofootnote
618338494Sobrien}%
618438494Sobrien
618538494Sobrien% Don't bother with the trickery in plain.tex to not require the
618638494Sobrien% footnote text as a parameter.  Our footnotes don't need to be so general.
618738494Sobrien%
6188174294Sobrien% Oh yes, they do; otherwise, @ifset (and anything else that uses
6189174294Sobrien% \parseargline) fails inside footnotes because the tokens are fixed when
619038494Sobrien% the footnote is read.  --karl, 16nov96.
619138494Sobrien%
6192174294Sobrien\gdef\dofootnote{%
6193174294Sobrien  \insert\footins\bgroup
619438494Sobrien  % We want to typeset this text as a normal paragraph, even if the
619538494Sobrien  % footnote reference occurs in (for example) a display environment.
619638494Sobrien  % So reset some parameters.
6197174294Sobrien  \hsize=\pagewidth
619838494Sobrien  \interlinepenalty\interfootnotelinepenalty
619938494Sobrien  \splittopskip\ht\strutbox % top baseline for broken footnotes
620038494Sobrien  \splitmaxdepth\dp\strutbox
620138494Sobrien  \floatingpenalty\@MM
620238494Sobrien  \leftskip\z@skip
620338494Sobrien  \rightskip\z@skip
620438494Sobrien  \spaceskip\z@skip
620538494Sobrien  \xspaceskip\z@skip
620638494Sobrien  \parindent\defaultparindent
620738494Sobrien  %
620882794Sobrien  \smallfonts \rm
620982794Sobrien  %
6210119679Smbr  % Because we use hanging indentation in footnotes, a @noindent appears
6211119679Smbr  % to exdent this text, so make it be a no-op.  makeinfo does not use
6212119679Smbr  % hanging indentation so @noindent can still be needed within footnote
6213119679Smbr  % text after an @example or the like (not that this is good style).
6214119679Smbr  \let\noindent = \relax
6215119679Smbr  %
6216119679Smbr  % Hang the footnote text off the number.  Use \everypar in case the
6217119679Smbr  % footnote extends for more than one paragraph.
6218119679Smbr  \everypar = {\hang}%
621938494Sobrien  \textindent{\thisfootno}%
622038494Sobrien  %
622138494Sobrien  % Don't crash into the line above the footnote text.  Since this
622238494Sobrien  % expands into a box, it must come within the paragraph, lest it
622338494Sobrien  % provide a place where TeX can split the footnote.
622438494Sobrien  \footstrut
622538494Sobrien  \futurelet\next\fo@t
622638494Sobrien}
622738494Sobrien}%end \catcode `\@=11
622838494Sobrien
6229174294Sobrien% In case a @footnote appears in a vbox, save the footnote text and create
6230174294Sobrien% the real \insert just after the vbox finished.  Otherwise, the insertion
6231174294Sobrien% would be lost.
6232174294Sobrien% Similarily, if a @footnote appears inside an alignment, save the footnote
6233174294Sobrien% text to a box and make the \insert when a row of the table is finished.
6234174294Sobrien% And the same can be done for other insert classes.  --kasal, 16nov03.
6235174294Sobrien
6236174294Sobrien% Replace the \insert primitive by a cheating macro.
6237174294Sobrien% Deeper inside, just make sure that the saved insertions are not spilled
6238174294Sobrien% out prematurely.
623938494Sobrien%
6240174294Sobrien\def\startsavinginserts{%
6241174294Sobrien  \ifx \insert\ptexinsert
6242174294Sobrien    \let\insert\saveinsert
6243174294Sobrien  \else
6244174294Sobrien    \let\checkinserts\relax
6245174294Sobrien  \fi
624638494Sobrien}
624738494Sobrien
6248174294Sobrien% This \insert replacement works for both \insert\footins{foo} and
6249174294Sobrien% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
625038494Sobrien%
6251174294Sobrien\def\saveinsert#1{%
6252174294Sobrien  \edef\next{\noexpand\savetobox \makeSAVEname#1}%
6253174294Sobrien  \afterassignment\next
6254174294Sobrien  % swallow the left brace
6255174294Sobrien  \let\temp =
6256174294Sobrien}
6257174294Sobrien\def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
6258174294Sobrien\def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
625938494Sobrien
6260174294Sobrien\def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
6261174294Sobrien
6262174294Sobrien\def\placesaveins#1{%
6263174294Sobrien  \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
6264174294Sobrien    {\box#1}%
6265174294Sobrien}
6266174294Sobrien
6267174294Sobrien% eat @SAVE -- beware, all of them have catcode \other:
6268174294Sobrien{
6269174294Sobrien  \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials  %  ;-)
6270174294Sobrien  \gdef\gobblesave @SAVE{}
6271174294Sobrien}
6272174294Sobrien
6273174294Sobrien% initialization:
6274174294Sobrien\def\newsaveins #1{%
6275174294Sobrien  \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
6276174294Sobrien  \next
6277174294Sobrien}
6278174294Sobrien\def\newsaveinsX #1{%
6279174294Sobrien  \csname newbox\endcsname #1%
6280174294Sobrien  \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
6281174294Sobrien    \checksaveins #1}%
6282174294Sobrien}
6283174294Sobrien
6284174294Sobrien% initialize:
6285174294Sobrien\let\checkinserts\empty
6286174294Sobrien\newsaveins\footins
6287174294Sobrien\newsaveins\margin
6288174294Sobrien
6289174294Sobrien
629038494Sobrien% @image.  We use the macros from epsf.tex to support this.
629138494Sobrien% If epsf.tex is not installed and @image is used, we complain.
629282794Sobrien%
629338494Sobrien% Check for and read epsf.tex up front.  If we read it only at @image
629438494Sobrien% time, we might be inside a group, and then its definitions would get
629538494Sobrien% undone and the next image would fail.
629642629Sobrien\openin 1 = epsf.tex
629738494Sobrien\ifeof 1 \else
6298174294Sobrien  % Do not bother showing banner with epsf.tex v2.7k (available in
6299174294Sobrien  % doc/epsf.tex and on ctan).
630042629Sobrien  \def\epsfannounce{\toks0 = }%
630138494Sobrien  \input epsf.tex
630238494Sobrien\fi
6303174294Sobrien\closein 1
630438494Sobrien%
630582794Sobrien% We will only complain once about lack of epsf.tex.
630638494Sobrien\newif\ifwarnednoepsf
630738494Sobrien\newhelp\noepsfhelp{epsf.tex must be installed for images to
630838494Sobrien  work.  It is also included in the Texinfo distribution, or you can get
630982794Sobrien  it from ftp://tug.org/tex/epsf.tex.}
631038494Sobrien%
631138494Sobrien\def\image#1{%
631238494Sobrien  \ifx\epsfbox\undefined
631338494Sobrien    \ifwarnednoepsf \else
631438494Sobrien      \errhelp = \noepsfhelp
631538494Sobrien      \errmessage{epsf.tex not found, images will be ignored}%
631638494Sobrien      \global\warnednoepsftrue
631738494Sobrien    \fi
631838494Sobrien  \else
6319119679Smbr    \imagexxx #1,,,,,\finish
632038494Sobrien  \fi
632138494Sobrien}
632238494Sobrien%
632338494Sobrien% Arguments to @image:
632438494Sobrien% #1 is (mandatory) image filename; we tack on .eps extension.
632538494Sobrien% #2 is (optional) width, #3 is (optional) height.
632682794Sobrien% #4 is (ignored optional) html alt text.
632782794Sobrien% #5 is (ignored optional) extension.
632882794Sobrien% #6 is just the usual extra ignored arg for parsing this stuff.
6329119679Smbr\newif\ifimagevmode
6330119679Smbr\def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
6331119679Smbr  \catcode`\^^M = 5     % in case we're inside an example
6332119679Smbr  \normalturnoffactive  % allow _ et al. in names
6333119679Smbr  % If the image is by itself, center it.
6334119679Smbr  \ifvmode
6335119679Smbr    \imagevmodetrue
6336119679Smbr    \nobreak\bigskip
6337119679Smbr    % Usually we'll have text after the image which will insert
6338119679Smbr    % \parskip glue, so insert it here too to equalize the space
6339174294Sobrien    % above and below.
6340119679Smbr    \nobreak\vskip\parskip
6341119679Smbr    \nobreak
6342119679Smbr    \line\bgroup\hss
6343119679Smbr  \fi
6344119679Smbr  %
6345119679Smbr  % Output the image.
634682794Sobrien  \ifpdf
6347119679Smbr    \dopdfimage{#1}{#2}{#3}%
634842629Sobrien  \else
634982794Sobrien    % \epsfbox itself resets \epsf?size at each figure.
635082794Sobrien    \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
635182794Sobrien    \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
6352119679Smbr    \epsfbox{#1.eps}%
635342629Sobrien  \fi
6354119679Smbr  %
6355119679Smbr  \ifimagevmode \hss \egroup \bigbreak \fi  % space after the image
6356119679Smbr\endgroup}
635738494Sobrien
635838494Sobrien
6359174294Sobrien% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
6360174294Sobrien% etc.  We don't actually implement floating yet, we always include the
6361174294Sobrien% float "here".  But it seemed the best name for the future.
6362174294Sobrien%
6363174294Sobrien\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
6364174294Sobrien
6365174294Sobrien% There may be a space before second and/or third parameter; delete it.
6366174294Sobrien\def\eatcommaspace#1, {#1,}
6367174294Sobrien
6368174294Sobrien% #1 is the optional FLOATTYPE, the text label for this float, typically
6369174294Sobrien% "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
6370174294Sobrien% this float will not be numbered and cannot be referred to.
6371174294Sobrien%
6372174294Sobrien% #2 is the optional xref label.  Also must be present for the float to
6373174294Sobrien% be referable.
6374174294Sobrien%
6375174294Sobrien% #3 is the optional positioning argument; for now, it is ignored.  It
6376174294Sobrien% will somehow specify the positions allowed to float to (here, top, bottom).
6377174294Sobrien%
6378174294Sobrien% We keep a separate counter for each FLOATTYPE, which we reset at each
6379174294Sobrien% chapter-level command.
6380174294Sobrien\let\resetallfloatnos=\empty
6381174294Sobrien%
6382174294Sobrien\def\dofloat#1,#2,#3,#4\finish{%
6383174294Sobrien  \let\thiscaption=\empty
6384174294Sobrien  \let\thisshortcaption=\empty
6385174294Sobrien  %
6386174294Sobrien  % don't lose footnotes inside @float.
6387174294Sobrien  %
6388174294Sobrien  % BEWARE: when the floats start float, we have to issue warning whenever an
6389174294Sobrien  % insert appears inside a float which could possibly float. --kasal, 26may04
6390174294Sobrien  %
6391174294Sobrien  \startsavinginserts
6392174294Sobrien  %
6393174294Sobrien  % We can't be used inside a paragraph.
6394174294Sobrien  \par
6395174294Sobrien  %
6396174294Sobrien  \vtop\bgroup
6397174294Sobrien    \def\floattype{#1}%
6398174294Sobrien    \def\floatlabel{#2}%
6399174294Sobrien    \def\floatloc{#3}% we do nothing with this yet.
6400174294Sobrien    %
6401174294Sobrien    \ifx\floattype\empty
6402174294Sobrien      \let\safefloattype=\empty
6403174294Sobrien    \else
6404174294Sobrien      {%
6405174294Sobrien        % the floattype might have accents or other special characters,
6406174294Sobrien        % but we need to use it in a control sequence name.
6407174294Sobrien        \indexnofonts
6408174294Sobrien        \turnoffactive
6409174294Sobrien        \xdef\safefloattype{\floattype}%
6410174294Sobrien      }%
6411174294Sobrien    \fi
6412174294Sobrien    %
6413174294Sobrien    % If label is given but no type, we handle that as the empty type.
6414174294Sobrien    \ifx\floatlabel\empty \else
6415174294Sobrien      % We want each FLOATTYPE to be numbered separately (Figure 1,
6416174294Sobrien      % Table 1, Figure 2, ...).  (And if no label, no number.)
6417174294Sobrien      %
6418174294Sobrien      \expandafter\getfloatno\csname\safefloattype floatno\endcsname
6419174294Sobrien      \global\advance\floatno by 1
6420174294Sobrien      %
6421174294Sobrien      {%
6422174294Sobrien        % This magic value for \thissection is output by \setref as the
6423174294Sobrien        % XREFLABEL-title value.  \xrefX uses it to distinguish float
6424174294Sobrien        % labels (which have a completely different output format) from
6425174294Sobrien        % node and anchor labels.  And \xrdef uses it to construct the
6426174294Sobrien        % lists of floats.
6427174294Sobrien        %
6428174294Sobrien        \edef\thissection{\floatmagic=\safefloattype}%
6429174294Sobrien        \setref{\floatlabel}{Yfloat}%
6430174294Sobrien      }%
6431174294Sobrien    \fi
6432174294Sobrien    %
6433174294Sobrien    % start with \parskip glue, I guess.
6434174294Sobrien    \vskip\parskip
6435174294Sobrien    %
6436174294Sobrien    % Don't suppress indentation if a float happens to start a section.
6437174294Sobrien    \restorefirstparagraphindent
6438174294Sobrien}
6439174294Sobrien
6440174294Sobrien% we have these possibilities:
6441174294Sobrien% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
6442174294Sobrien% @float Foo,lbl & no caption:    Foo 1.1
6443174294Sobrien% @float Foo & @caption{Cap}:     Foo: Cap
6444174294Sobrien% @float Foo & no caption:        Foo
6445174294Sobrien% @float ,lbl & Caption{Cap}:     1.1: Cap
6446174294Sobrien% @float ,lbl & no caption:       1.1
6447174294Sobrien% @float & @caption{Cap}:         Cap
6448174294Sobrien% @float & no caption:
6449174294Sobrien%
6450174294Sobrien\def\Efloat{%
6451174294Sobrien    \let\floatident = \empty
6452174294Sobrien    %
6453174294Sobrien    % In all cases, if we have a float type, it comes first.
6454174294Sobrien    \ifx\floattype\empty \else \def\floatident{\floattype}\fi
6455174294Sobrien    %
6456174294Sobrien    % If we have an xref label, the number comes next.
6457174294Sobrien    \ifx\floatlabel\empty \else
6458174294Sobrien      \ifx\floattype\empty \else % if also had float type, need tie first.
6459174294Sobrien        \appendtomacro\floatident{\tie}%
6460174294Sobrien      \fi
6461174294Sobrien      % the number.
6462174294Sobrien      \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
6463174294Sobrien    \fi
6464174294Sobrien    %
6465174294Sobrien    % Start the printed caption with what we've constructed in
6466174294Sobrien    % \floatident, but keep it separate; we need \floatident again.
6467174294Sobrien    \let\captionline = \floatident
6468174294Sobrien    %
6469174294Sobrien    \ifx\thiscaption\empty \else
6470174294Sobrien      \ifx\floatident\empty \else
6471174294Sobrien	\appendtomacro\captionline{: }% had ident, so need a colon between
6472174294Sobrien      \fi
6473174294Sobrien      %
6474174294Sobrien      % caption text.
6475174294Sobrien      \appendtomacro\captionline{\scanexp\thiscaption}%
6476174294Sobrien    \fi
6477174294Sobrien    %
6478174294Sobrien    % If we have anything to print, print it, with space before.
6479174294Sobrien    % Eventually this needs to become an \insert.
6480174294Sobrien    \ifx\captionline\empty \else
6481174294Sobrien      \vskip.5\parskip
6482174294Sobrien      \captionline
6483174294Sobrien      %
6484174294Sobrien      % Space below caption.
6485174294Sobrien      \vskip\parskip
6486174294Sobrien    \fi
6487174294Sobrien    %
6488174294Sobrien    % If have an xref label, write the list of floats info.  Do this
6489174294Sobrien    % after the caption, to avoid chance of it being a breakpoint.
6490174294Sobrien    \ifx\floatlabel\empty \else
6491174294Sobrien      % Write the text that goes in the lof to the aux file as
6492174294Sobrien      % \floatlabel-lof.  Besides \floatident, we include the short
6493174294Sobrien      % caption if specified, else the full caption if specified, else nothing.
6494174294Sobrien      {%
6495174294Sobrien        \atdummies \turnoffactive \otherbackslash
6496174294Sobrien        % since we read the caption text in the macro world, where ^^M
6497174294Sobrien        % is turned into a normal character, we have to scan it back, so
6498174294Sobrien        % we don't write the literal three characters "^^M" into the aux file.
6499174294Sobrien	\scanexp{%
6500174294Sobrien	  \xdef\noexpand\gtemp{%
6501174294Sobrien	    \ifx\thisshortcaption\empty
6502174294Sobrien	      \thiscaption
6503174294Sobrien	    \else
6504174294Sobrien	      \thisshortcaption
6505174294Sobrien	    \fi
6506174294Sobrien	  }%
6507174294Sobrien	}%
6508174294Sobrien        \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
6509174294Sobrien	  \ifx\gtemp\empty \else : \gtemp \fi}}%
6510174294Sobrien      }%
6511174294Sobrien    \fi
6512174294Sobrien  \egroup  % end of \vtop
6513174294Sobrien  %
6514174294Sobrien  % place the captured inserts
6515174294Sobrien  %
6516174294Sobrien  % BEWARE: when the floats start float, we have to issue warning whenever an
6517174294Sobrien  % insert appears inside a float which could possibly float. --kasal, 26may04
6518174294Sobrien  %
6519174294Sobrien  \checkinserts
6520174294Sobrien}
6521174294Sobrien
6522174294Sobrien% Append the tokens #2 to the definition of macro #1, not expanding either.
6523174294Sobrien%
6524174294Sobrien\def\appendtomacro#1#2{%
6525174294Sobrien  \expandafter\def\expandafter#1\expandafter{#1#2}%
6526174294Sobrien}
6527174294Sobrien
6528174294Sobrien% @caption, @shortcaption
6529174294Sobrien%
6530174294Sobrien\def\caption{\docaption\thiscaption}
6531174294Sobrien\def\shortcaption{\docaption\thisshortcaption}
6532174294Sobrien\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
6533174294Sobrien\def\defcaption#1#2{\egroup \def#1{#2}}
6534174294Sobrien
6535174294Sobrien% The parameter is the control sequence identifying the counter we are
6536174294Sobrien% going to use.  Create it if it doesn't exist and assign it to \floatno.
6537174294Sobrien\def\getfloatno#1{%
6538174294Sobrien  \ifx#1\relax
6539174294Sobrien      % Haven't seen this figure type before.
6540174294Sobrien      \csname newcount\endcsname #1%
6541174294Sobrien      %
6542174294Sobrien      % Remember to reset this floatno at the next chap.
6543174294Sobrien      \expandafter\gdef\expandafter\resetallfloatnos
6544174294Sobrien        \expandafter{\resetallfloatnos #1=0 }%
6545174294Sobrien  \fi
6546174294Sobrien  \let\floatno#1%
6547174294Sobrien}
6548174294Sobrien
6549174294Sobrien% \setref calls this to get the XREFLABEL-snt value.  We want an @xref
6550174294Sobrien% to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
6551174294Sobrien% first read the @float command.
6552174294Sobrien%
6553174294Sobrien\def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
6554174294Sobrien
6555174294Sobrien% Magic string used for the XREFLABEL-title value, so \xrefX can
6556174294Sobrien% distinguish floats from other xref types.
6557174294Sobrien\def\floatmagic{!!float!!}
6558174294Sobrien
6559174294Sobrien% #1 is the control sequence we are passed; we expand into a conditional
6560174294Sobrien% which is true if #1 represents a float ref.  That is, the magic
6561174294Sobrien% \thissection value which we \setref above.
6562174294Sobrien%
6563174294Sobrien\def\iffloat#1{\expandafter\doiffloat#1==\finish}
6564174294Sobrien%
6565174294Sobrien% #1 is (maybe) the \floatmagic string.  If so, #2 will be the
6566174294Sobrien% (safe) float type for this float.  We set \iffloattype to #2.
6567174294Sobrien%
6568174294Sobrien\def\doiffloat#1=#2=#3\finish{%
6569174294Sobrien  \def\temp{#1}%
6570174294Sobrien  \def\iffloattype{#2}%
6571174294Sobrien  \ifx\temp\floatmagic
6572174294Sobrien}
6573174294Sobrien
6574174294Sobrien% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
6575174294Sobrien%
6576174294Sobrien\parseargdef\listoffloats{%
6577174294Sobrien  \def\floattype{#1}% floattype
6578174294Sobrien  {%
6579174294Sobrien    % the floattype might have accents or other special characters,
6580174294Sobrien    % but we need to use it in a control sequence name.
6581174294Sobrien    \indexnofonts
6582174294Sobrien    \turnoffactive
6583174294Sobrien    \xdef\safefloattype{\floattype}%
6584174294Sobrien  }%
6585174294Sobrien  %
6586174294Sobrien  % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
6587174294Sobrien  \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
6588174294Sobrien    \ifhavexrefs
6589174294Sobrien      % if the user said @listoffloats foo but never @float foo.
6590174294Sobrien      \message{\linenumber No `\safefloattype' floats to list.}%
6591174294Sobrien    \fi
6592174294Sobrien  \else
6593174294Sobrien    \begingroup
6594174294Sobrien      \leftskip=\tocindent  % indent these entries like a toc
6595174294Sobrien      \let\do=\listoffloatsdo
6596174294Sobrien      \csname floatlist\safefloattype\endcsname
6597174294Sobrien    \endgroup
6598174294Sobrien  \fi
6599174294Sobrien}
6600174294Sobrien
6601174294Sobrien% This is called on each entry in a list of floats.  We're passed the
6602174294Sobrien% xref label, in the form LABEL-title, which is how we save it in the
6603174294Sobrien% aux file.  We strip off the -title and look up \XRLABEL-lof, which
6604174294Sobrien% has the text we're supposed to typeset here.
6605174294Sobrien%
6606174294Sobrien% Figures without xref labels will not be included in the list (since
6607174294Sobrien% they won't appear in the aux file).
6608174294Sobrien%
6609174294Sobrien\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
6610174294Sobrien\def\listoffloatsdoentry#1-title\finish{{%
6611174294Sobrien  % Can't fully expand XR#1-lof because it can contain anything.  Just
6612174294Sobrien  % pass the control sequence.  On the other hand, XR#1-pg is just the
6613174294Sobrien  % page number, and we want to fully expand that so we can get a link
6614174294Sobrien  % in pdf output.
6615174294Sobrien  \toksA = \expandafter{\csname XR#1-lof\endcsname}%
6616174294Sobrien  %
6617174294Sobrien  % use the same \entry macro we use to generate the TOC and index.
6618174294Sobrien  \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
6619174294Sobrien  \writeentry
6620174294Sobrien}}
6621174294Sobrien
662282794Sobrien\message{localization,}
662382794Sobrien% and i18n.
662438494Sobrien
662582794Sobrien% @documentlanguage is usually given very early, just after
662682794Sobrien% @setfilename.  If done too late, it may not override everything
662782794Sobrien% properly.  Single argument is the language abbreviation.
662882794Sobrien% It would be nice if we could set up a hyphenation file here.
662982794Sobrien%
6630174294Sobrien\parseargdef\documentlanguage{%
663182794Sobrien  \tex % read txi-??.tex file in plain TeX.
6632174294Sobrien    % Read the file if it exists.
6633174294Sobrien    \openin 1 txi-#1.tex
6634174294Sobrien    \ifeof 1
6635174294Sobrien      \errhelp = \nolanghelp
6636174294Sobrien      \errmessage{Cannot read language file txi-#1.tex}%
6637174294Sobrien    \else
6638174294Sobrien      \input txi-#1.tex
6639174294Sobrien    \fi
6640174294Sobrien    \closein 1
664182794Sobrien  \endgroup
664282794Sobrien}
664382794Sobrien\newhelp\nolanghelp{The given language definition file cannot be found or
664482794Sobrienis empty.  Maybe you need to install it?  In the current directory
664582794Sobrienshould work if nowhere else does.}
664682794Sobrien
664782794Sobrien
664882794Sobrien% @documentencoding should change something in TeX eventually, most
664982794Sobrien% likely, but for now just recognize it.
665082794Sobrien\let\documentencoding = \comment
665182794Sobrien
665282794Sobrien
665382794Sobrien% Page size parameters.
665482794Sobrien%
665538494Sobrien\newdimen\defaultparindent \defaultparindent = 15pt
665638494Sobrien
665738494Sobrien\chapheadingskip = 15pt plus 4pt minus 2pt
665838494Sobrien\secheadingskip = 12pt plus 3pt minus 2pt
665938494Sobrien\subsecheadingskip = 9pt plus 2pt minus 2pt
666038494Sobrien
666138494Sobrien% Prevent underfull vbox error messages.
666242629Sobrien\vbadness = 10000
666338494Sobrien
666442629Sobrien% Don't be so finicky about underfull hboxes, either.
666542629Sobrien\hbadness = 2000
666642629Sobrien
666738494Sobrien% Following George Bush, just get rid of widows and orphans.
666838494Sobrien\widowpenalty=10000
666938494Sobrien\clubpenalty=10000
667038494Sobrien
667138494Sobrien% Use TeX 3.0's \emergencystretch to help line breaking, but if we're
667238494Sobrien% using an old version of TeX, don't do anything.  We want the amount of
667338494Sobrien% stretch added to depend on the line length, hence the dependence on
667482794Sobrien% \hsize.  We call this whenever the paper size is set.
667538494Sobrien%
667642629Sobrien\def\setemergencystretch{%
667742629Sobrien  \ifx\emergencystretch\thisisundefined
667842629Sobrien    % Allow us to assign to \emergencystretch anyway.
667942629Sobrien    \def\emergencystretch{\dimen0}%
668042629Sobrien  \else
668182794Sobrien    \emergencystretch = .15\hsize
668242629Sobrien  \fi
668342629Sobrien}
668438494Sobrien
668542629Sobrien% Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
6686174294Sobrien% 4) hoffset; 5) binding offset; 6) topskip; 7) physical page height; 8)
6687174294Sobrien% physical page width.
668842629Sobrien%
6689174294Sobrien% We also call \setleading{\textleading}, so the caller should define
6690174294Sobrien% \textleading.  The caller should also set \parskip.
6691174294Sobrien%
6692174294Sobrien\def\internalpagesizes#1#2#3#4#5#6#7#8{%
669342629Sobrien  \voffset = #3\relax
669442629Sobrien  \topskip = #6\relax
669542629Sobrien  \splittopskip = \topskip
669638494Sobrien  %
669742629Sobrien  \vsize = #1\relax
669842629Sobrien  \advance\vsize by \topskip
669942629Sobrien  \outervsize = \vsize
670042629Sobrien  \advance\outervsize by 2\topandbottommargin
670142629Sobrien  \pageheight = \vsize
670238494Sobrien  %
670342629Sobrien  \hsize = #2\relax
670442629Sobrien  \outerhsize = \hsize
670542629Sobrien  \advance\outerhsize by 0.5in
670642629Sobrien  \pagewidth = \hsize
670738494Sobrien  %
670842629Sobrien  \normaloffset = #4\relax
670942629Sobrien  \bindingoffset = #5\relax
671042629Sobrien  %
6711174294Sobrien  \ifpdf
6712174294Sobrien    \pdfpageheight #7\relax
6713174294Sobrien    \pdfpagewidth #8\relax
6714174294Sobrien  \fi
6715174294Sobrien  %
671682794Sobrien  \setleading{\textleading}
671782794Sobrien  %
671842629Sobrien  \parindent = \defaultparindent
671942629Sobrien  \setemergencystretch
672038494Sobrien}
672138494Sobrien
672242629Sobrien% @letterpaper (the default).
672342629Sobrien\def\letterpaper{{\globaldefs = 1
672442629Sobrien  \parskip = 3pt plus 2pt minus 1pt
672582794Sobrien  \textleading = 13.2pt
672642629Sobrien  %
672742629Sobrien  % If page is nothing but text, make it come out even.
6728174294Sobrien  \internalpagesizes{46\baselineskip}{6in}%
6729174294Sobrien                    {\voffset}{.25in}%
6730174294Sobrien                    {\bindingoffset}{36pt}%
6731174294Sobrien                    {11in}{8.5in}%
673242629Sobrien}}
673342629Sobrien
673442629Sobrien% Use @smallbook to reset parameters for 7x9.5 (or so) format.
673542629Sobrien\def\smallbook{{\globaldefs = 1
673642629Sobrien  \parskip = 2pt plus 1pt
673782794Sobrien  \textleading = 12pt
673842629Sobrien  %
6739174294Sobrien  \internalpagesizes{7.5in}{5in}%
6740174294Sobrien                    {\voffset}{.25in}%
6741174294Sobrien                    {\bindingoffset}{16pt}%
6742174294Sobrien                    {9.25in}{7in}%
674342629Sobrien  %
674442629Sobrien  \lispnarrowing = 0.3in
674542629Sobrien  \tolerance = 700
674642629Sobrien  \hfuzz = 1pt
674742629Sobrien  \contentsrightmargin = 0pt
674842629Sobrien  \defbodyindent = .5cm
674942629Sobrien}}
675042629Sobrien
675138494Sobrien% Use @afourpaper to print on European A4 paper.
675242629Sobrien\def\afourpaper{{\globaldefs = 1
675342629Sobrien  \parskip = 3pt plus 2pt minus 1pt
6754174294Sobrien  \textleading = 13.2pt
675542629Sobrien  %
6756174294Sobrien  % Double-side printing via postscript on Laserjet 4050
6757174294Sobrien  % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
6758174294Sobrien  % To change the settings for a different printer or situation, adjust
6759174294Sobrien  % \normaloffset until the front-side and back-side texts align.  Then
6760174294Sobrien  % do the same for \bindingoffset.  You can set these for testing in
6761174294Sobrien  % your texinfo source file like this:
6762174294Sobrien  % @tex
6763174294Sobrien  % \global\normaloffset = -6mm
6764174294Sobrien  % \global\bindingoffset = 10mm
6765174294Sobrien  % @end tex
6766174294Sobrien  \internalpagesizes{51\baselineskip}{160mm}
6767174294Sobrien                    {\voffset}{\hoffset}%
6768174294Sobrien                    {\bindingoffset}{44pt}%
6769174294Sobrien                    {297mm}{210mm}%
677042629Sobrien  %
677142629Sobrien  \tolerance = 700
677242629Sobrien  \hfuzz = 1pt
6773174294Sobrien  \contentsrightmargin = 0pt
6774174294Sobrien  \defbodyindent = 5mm
677542629Sobrien}}
677638494Sobrien
677782794Sobrien% Use @afivepaper to print on European A5 paper.
677882794Sobrien% From romildo@urano.iceb.ufop.br, 2 July 2000.
677982794Sobrien% He also recommends making @example and @lisp be small.
678082794Sobrien\def\afivepaper{{\globaldefs = 1
678182794Sobrien  \parskip = 2pt plus 1pt minus 0.1pt
678282794Sobrien  \textleading = 12.5pt
678382794Sobrien  %
6784174294Sobrien  \internalpagesizes{160mm}{120mm}%
6785174294Sobrien                    {\voffset}{\hoffset}%
6786174294Sobrien                    {\bindingoffset}{8pt}%
6787174294Sobrien                    {210mm}{148mm}%
678882794Sobrien  %
678982794Sobrien  \lispnarrowing = 0.2in
679082794Sobrien  \tolerance = 800
679182794Sobrien  \hfuzz = 1.2pt
6792174294Sobrien  \contentsrightmargin = 0pt
679382794Sobrien  \defbodyindent = 2mm
679482794Sobrien  \tableindent = 12mm
679582794Sobrien}}
679682794Sobrien
6797174294Sobrien% A specific text layout, 24x15cm overall, intended for A4 paper.
679842629Sobrien\def\afourlatex{{\globaldefs = 1
679942629Sobrien  \afourpaper
6800174294Sobrien  \internalpagesizes{237mm}{150mm}%
6801174294Sobrien                    {\voffset}{4.6mm}%
6802174294Sobrien                    {\bindingoffset}{7mm}%
6803174294Sobrien                    {297mm}{210mm}%
6804119679Smbr  %
6805174294Sobrien  % Must explicitly reset to 0 because we call \afourpaper.
6806119679Smbr  \globaldefs = 0
680742629Sobrien}}
680838494Sobrien
6809174294Sobrien% Use @afourwide to print on A4 paper in landscape format.
6810174294Sobrien\def\afourwide{{\globaldefs = 1
681142629Sobrien  \afourpaper
6812174294Sobrien  \internalpagesizes{241mm}{165mm}%
6813174294Sobrien                    {\voffset}{-2.95mm}%
6814174294Sobrien                    {\bindingoffset}{7mm}%
6815174294Sobrien                    {297mm}{210mm}%
6816174294Sobrien  \globaldefs = 0
6817174294Sobrien}}
681838494Sobrien
681942629Sobrien% @pagesizes TEXTHEIGHT[,TEXTWIDTH]
682042629Sobrien% Perhaps we should allow setting the margins, \topskip, \parskip,
682142629Sobrien% and/or leading, also. Or perhaps we should compute them somehow.
682282794Sobrien%
6823174294Sobrien\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
682442629Sobrien\def\pagesizesyyy#1,#2,#3\finish{{%
682542629Sobrien  \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
682642629Sobrien  \globaldefs = 1
682742629Sobrien  %
682842629Sobrien  \parskip = 3pt plus 2pt minus 1pt
682982794Sobrien  \setleading{\textleading}%
683042629Sobrien  %
6831174294Sobrien  \dimen0 = #1
6832174294Sobrien  \advance\dimen0 by \voffset
6833174294Sobrien  %
6834174294Sobrien  \dimen2 = \hsize
6835174294Sobrien  \advance\dimen2 by \normaloffset
6836174294Sobrien  %
6837174294Sobrien  \internalpagesizes{#1}{\hsize}%
6838174294Sobrien                    {\voffset}{\normaloffset}%
6839174294Sobrien                    {\bindingoffset}{44pt}%
6840174294Sobrien                    {\dimen0}{\dimen2}%
684142629Sobrien}}
684238494Sobrien
684342629Sobrien% Set default to letter.
684482794Sobrien%
684542629Sobrien\letterpaper
684638494Sobrien
684782794Sobrien
684842629Sobrien\message{and turning on texinfo input format.}
684938494Sobrien
685038494Sobrien% Define macros to output various characters with catcode for normal text.
685138494Sobrien\catcode`\"=\other
685238494Sobrien\catcode`\~=\other
685338494Sobrien\catcode`\^=\other
685438494Sobrien\catcode`\_=\other
685538494Sobrien\catcode`\|=\other
685638494Sobrien\catcode`\<=\other
685738494Sobrien\catcode`\>=\other
685838494Sobrien\catcode`\+=\other
685982794Sobrien\catcode`\$=\other
686038494Sobrien\def\normaldoublequote{"}
686138494Sobrien\def\normaltilde{~}
686238494Sobrien\def\normalcaret{^}
686338494Sobrien\def\normalunderscore{_}
686438494Sobrien\def\normalverticalbar{|}
686538494Sobrien\def\normalless{<}
686638494Sobrien\def\normalgreater{>}
686738494Sobrien\def\normalplus{+}
6868119679Smbr\def\normaldollar{$}%$ font-lock fix
686938494Sobrien
6870174294Sobrien% This macro is used to make a character print one way in \tt
6871174294Sobrien% (where it can probably be output as-is), and another way in other fonts,
687238494Sobrien% where something hairier probably needs to be done.
687338494Sobrien%
687438494Sobrien% #1 is what to print if we are indeed using \tt; #2 is what to print
687538494Sobrien% otherwise.  Since all the Computer Modern typewriter fonts have zero
687638494Sobrien% interword stretch (and shrink), and it is reasonable to expect all
687738494Sobrien% typewriter fonts to have this, we can check that font parameter.
687838494Sobrien%
687982794Sobrien\def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
688038494Sobrien
688182794Sobrien% Same as above, but check for italic font.  Actually this also catches
688282794Sobrien% non-italic slanted fonts since it is impossible to distinguish them from
688382794Sobrien% italic fonts.  But since this is only used by $ and it uses \sl anyway
688482794Sobrien% this is not a problem.
688582794Sobrien\def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
688682794Sobrien
688738494Sobrien% Turn off all special characters except @
688838494Sobrien% (and those which the user can use as if they were ordinary).
688938494Sobrien% Most of these we simply print from the \tt font, but for some, we can
689038494Sobrien% use math or other variants that look better in normal text.
689138494Sobrien
689238494Sobrien\catcode`\"=\active
689342629Sobrien\def\activedoublequote{{\tt\char34}}
689438494Sobrien\let"=\activedoublequote
689538494Sobrien\catcode`\~=\active
689642629Sobrien\def~{{\tt\char126}}
689738494Sobrien\chardef\hat=`\^
689838494Sobrien\catcode`\^=\active
689938494Sobrien\def^{{\tt \hat}}
690038494Sobrien
690138494Sobrien\catcode`\_=\active
690238494Sobrien\def_{\ifusingtt\normalunderscore\_}
690338494Sobrien% Subroutine for the previous macro.
6904174294Sobrien\def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
690538494Sobrien
690638494Sobrien\catcode`\|=\active
690742629Sobrien\def|{{\tt\char124}}
690838494Sobrien\chardef \less=`\<
690938494Sobrien\catcode`\<=\active
691038494Sobrien\def<{{\tt \less}}
691138494Sobrien\chardef \gtr=`\>
691238494Sobrien\catcode`\>=\active
691338494Sobrien\def>{{\tt \gtr}}
691438494Sobrien\catcode`\+=\active
691538494Sobrien\def+{{\tt \char 43}}
691682794Sobrien\catcode`\$=\active
6917119679Smbr\def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
691838494Sobrien
691938494Sobrien% If a .fmt file is being used, characters that might appear in a file
692038494Sobrien% name cannot be active until we have parsed the command line.
692138494Sobrien% So turn them off again, and have \everyjob (or @setfilename) turn them on.
692238494Sobrien% \otherifyactive is called near the end of this file.
692338494Sobrien\def\otherifyactive{\catcode`+=\other \catcode`\_=\other}
692438494Sobrien
692538494Sobrien\catcode`\@=0
692638494Sobrien
6927174294Sobrien% \backslashcurfont outputs one backslash character in current font,
6928174294Sobrien% as in \char`\\.
6929174294Sobrien\global\chardef\backslashcurfont=`\\
6930174294Sobrien\global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
693138494Sobrien
6932174294Sobrien% \rawbackslash defines an active \ to do \backslashcurfont.
6933174294Sobrien% \otherbackslash defines an active \ to be a literal `\' character with
6934174294Sobrien% catcode other.
693538494Sobrien{\catcode`\\=\active
6936174294Sobrien @gdef@rawbackslash{@let\=@backslashcurfont}
6937174294Sobrien @gdef@otherbackslash{@let\=@realbackslash}
6938174294Sobrien}
693938494Sobrien
6940174294Sobrien% \realbackslash is an actual character `\' with catcode other.
6941174294Sobrien{\catcode`\\=\other @gdef@realbackslash{\}}
6942174294Sobrien
694338494Sobrien% \normalbackslash outputs one backslash in fixed width font.
6944174294Sobrien\def\normalbackslash{{\tt\backslashcurfont}}
694538494Sobrien
694638494Sobrien\catcode`\\=\active
694738494Sobrien
694838494Sobrien% Used sometimes to turn off (effectively) the active characters
694938494Sobrien% even after parsing them.
6950174294Sobrien@def@turnoffactive{%
6951174294Sobrien  @let"=@normaldoublequote
6952174294Sobrien  @let\=@realbackslash
6953174294Sobrien  @let~=@normaltilde
6954174294Sobrien  @let^=@normalcaret
6955174294Sobrien  @let_=@normalunderscore
6956174294Sobrien  @let|=@normalverticalbar
6957174294Sobrien  @let<=@normalless
6958174294Sobrien  @let>=@normalgreater
6959174294Sobrien  @let+=@normalplus
6960174294Sobrien  @let$=@normaldollar %$ font-lock fix
6961174294Sobrien  @unsepspaces
6962174294Sobrien}
696338494Sobrien
6964174294Sobrien% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
6965174294Sobrien% the literal character `\'.  (Thus, \ is not expandable when this is in
6966174294Sobrien% effect.)
6967174294Sobrien%
6968174294Sobrien@def@normalturnoffactive{@turnoffactive @let\=@normalbackslash}
696938494Sobrien
697038494Sobrien% Make _ and + \other characters, temporarily.
697138494Sobrien% This is canceled by @fixbackslash.
697238494Sobrien@otherifyactive
697338494Sobrien
697438494Sobrien% If a .fmt file is being used, we don't want the `\input texinfo' to show up.
697538494Sobrien% That is what \eatinput is for; after that, the `\' should revert to printing
697638494Sobrien% a backslash.
697738494Sobrien%
697838494Sobrien@gdef@eatinput input texinfo{@fixbackslash}
697938494Sobrien@global@let\ = @eatinput
698038494Sobrien
698138494Sobrien% On the other hand, perhaps the file did not have a `\input texinfo'. Then
698238494Sobrien% the first `\{ in the file would cause an error. This macro tries to fix
698338494Sobrien% that, assuming it is called before the first `\' could plausibly occur.
698438494Sobrien% Also back turn on active characters that might appear in the input
698538494Sobrien% file name, in case not using a pre-dumped format.
698638494Sobrien%
698782794Sobrien@gdef@fixbackslash{%
698882794Sobrien  @ifx\@eatinput @let\ = @normalbackslash @fi
698982794Sobrien  @catcode`+=@active
699082794Sobrien  @catcode`@_=@active
699182794Sobrien}
699238494Sobrien
699382794Sobrien% Say @foo, not \foo, in error messages.
699482794Sobrien@escapechar = `@@
699538494Sobrien
6996174294Sobrien% These look ok in all fonts, so just make them not special.
699782794Sobrien@catcode`@& = @other
699882794Sobrien@catcode`@# = @other
699982794Sobrien@catcode`@% = @other
700082794Sobrien
700138494Sobrien
700238494Sobrien@c Local variables:
700342629Sobrien@c eval: (add-hook 'write-file-hooks 'time-stamp)
700438494Sobrien@c page-delimiter: "^\\\\message"
700542629Sobrien@c time-stamp-start: "def\\\\texinfoversion{"
700682794Sobrien@c time-stamp-format: "%:y-%02m-%02d.%02H"
700742629Sobrien@c time-stamp-end: "}"
700838494Sobrien@c End:
7009174294Sobrien
7010174294Sobrien@c vim:sw=2:
7011174294Sobrien
7012174294Sobrien@ignore
7013174294Sobrien   arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
7014174294Sobrien@end ignore
7015