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