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