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