1% texinfo.tex -- TeX macros to handle Texinfo files.
2%
3% Load plain if necessary, i.e., if running under initex.
4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
5%
6\def\texinfoversion{2019-03-03.15}
7
8%
9% Copyright 1985, 1986, 1988, 1990-2019 Free Software Foundation, Inc.
10%
11% This texinfo.tex file is free software: you can redistribute it and/or
12% modify it under the terms of the GNU General Public License as
13% published by the Free Software Foundation, either version 3 of the
14% License, or (at your option) any later version.
15%
16% This texinfo.tex file is distributed in the hope that it will be
17% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19% General Public License for more details.
20%
21% You should have received a copy of the GNU General Public License
22% along with this program.  If not, see <https://www.gnu.org/licenses/>.
23%
24% As a special exception, when this file is read by TeX when processing
25% a Texinfo source document, you may use the result without
26% restriction. This Exception is an additional permission under section 7
27% of the GNU General Public License, version 3 ("GPLv3").
28%
29% Please try the latest version of texinfo.tex before submitting bug
30% reports; you can get the latest version from:
31%   https://ftp.gnu.org/gnu/texinfo/ (the Texinfo release area), or
32%   https://ftpmirror.gnu.org/texinfo/ (same, via a mirror), or
33%   https://www.gnu.org/software/texinfo/ (the Texinfo home page)
34% The texinfo.tex in any given distribution could well be out
35% of date, so if that's what you're using, please check.
36%
37% Send bug reports to bug-texinfo@gnu.org.  Please include including a
38% complete document in each bug report with which we can reproduce the
39% problem.  Patches are, of course, greatly appreciated.
40%
41% To process a Texinfo manual with TeX, it's most reliable to use the
42% texi2dvi shell script that comes with the distribution.  For a simple
43% manual foo.texi, however, you can get away with this:
44%   tex foo.texi
45%   texindex foo.??
46%   tex foo.texi
47%   tex foo.texi
48%   dvips foo.dvi -o  # or whatever; this makes foo.ps.
49% The extra TeX runs get the cross-reference information correct.
50% Sometimes one run after texindex suffices, and sometimes you need more
51% than two; texi2dvi does it as many times as necessary.
52%
53% It is possible to adapt texinfo.tex for other languages, to some
54% extent.  You can get the existing language-specific files from the
55% full Texinfo distribution.
56%
57% The GNU Texinfo home page is https://www.gnu.org/software/texinfo.
58
59
60\message{Loading texinfo [version \texinfoversion]:}
61
62% If in a .fmt file, print the version number
63% and turn on active characters that we couldn't do earlier because
64% they might have appeared in the input file name.
65\everyjob{\message{[Texinfo version \texinfoversion]}%
66  \catcode`+=\active \catcode`\_=\active}
67
68% LaTeX's \typeout.  This ensures that the messages it is used for
69% are identical in format to the corresponding ones from latex/pdflatex.
70\def\typeout{\immediate\write17}%
71
72\chardef\other=12
73
74% We never want plain's \outer definition of \+ in Texinfo.
75% For @tex, we can use \tabalign.
76\let\+ = \relax
77
78% Save some plain tex macros whose names we will redefine.
79\let\ptexb=\b
80\let\ptexbullet=\bullet
81\let\ptexc=\c
82\let\ptexcomma=\,
83\let\ptexdot=\.
84\let\ptexdots=\dots
85\let\ptexend=\end
86\let\ptexequiv=\equiv
87\let\ptexexclam=\!
88\let\ptexfootnote=\footnote
89\let\ptexgtr=>
90\let\ptexhat=^
91\let\ptexi=\i
92\let\ptexindent=\indent
93\let\ptexinsert=\insert
94\let\ptexlbrace=\{
95\let\ptexless=<
96\let\ptexnewwrite\newwrite
97\let\ptexnoindent=\noindent
98\let\ptexplus=+
99\let\ptexraggedright=\raggedright
100\let\ptexrbrace=\}
101\let\ptexslash=\/
102\let\ptexsp=\sp
103\let\ptexstar=\*
104\let\ptexsup=\sup
105\let\ptext=\t
106\let\ptextop=\top
107{\catcode`\'=\active \global\let\ptexquoteright'}% active in plain's math mode
108
109% If this character appears in an error message or help string, it
110% starts a new line in the output.
111\newlinechar = `^^J
112
113% Use TeX 3.0's \inputlineno to get the line number, for better error
114% messages, but if we're using an old version of TeX, don't do anything.
115%
116\ifx\inputlineno\thisisundefined
117  \let\linenumber = \empty % Pre-3.0.
118\else
119  \def\linenumber{l.\the\inputlineno:\space}
120\fi
121
122% Set up fixed words for English if not already set.
123\ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
124\ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
125\ifx\putworderror\undefined     \gdef\putworderror{error}\fi
126\ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
127\ifx\putwordin\undefined        \gdef\putwordin{in}\fi
128\ifx\putwordIndexIsEmpty\undefined       \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
129\ifx\putwordIndexNonexistent\undefined   \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
130\ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
131\ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
132\ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
133\ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
134\ifx\putwordof\undefined        \gdef\putwordof{of}\fi
135\ifx\putwordon\undefined        \gdef\putwordon{on}\fi
136\ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
137\ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
138\ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
139\ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
140\ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
141\ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
142\ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
143%
144\ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
145\ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
146\ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
147\ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
148\ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
149\ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
150\ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
151\ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
152\ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
153\ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
154\ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
155\ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
156%
157\ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
158\ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
159\ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
160\ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
161\ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
162
163% Give the space character the catcode for a space.
164\def\spaceisspace{\catcode`\ =10\relax}
165
166% Likewise for ^^M, the end of line character.
167\def\endlineisspace{\catcode13=10\relax}
168
169\chardef\dashChar  = `\-
170\chardef\slashChar = `\/
171\chardef\underChar = `\_
172
173% Ignore a token.
174%
175\def\gobble#1{}
176
177% The following is used inside several \edef's.
178\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
179
180% Hyphenation fixes.
181\hyphenation{
182  Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
183  ap-pen-dix bit-map bit-maps
184  data-base data-bases eshell fall-ing half-way long-est man-u-script
185  man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
186  par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
187  spell-ing spell-ings
188  stand-alone strong-est time-stamp time-stamps which-ever white-space
189  wide-spread wrap-around
190}
191
192% Sometimes it is convenient to have everything in the transcript file
193% and nothing on the terminal.  We don't just call \tracingall here,
194% since that produces some useless output on the terminal.  We also make
195% some effort to order the tracing commands to reduce output in the log
196% file; cf. trace.sty in LaTeX.
197%
198\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
199\def\loggingall{%
200  \tracingstats2
201  \tracingpages1
202  \tracinglostchars2  % 2 gives us more in etex
203  \tracingparagraphs1
204  \tracingoutput1
205  \tracingmacros2
206  \tracingrestores1
207  \showboxbreadth\maxdimen \showboxdepth\maxdimen
208  \ifx\eTeXversion\thisisundefined\else % etex gives us more logging
209    \tracingscantokens1
210    \tracingifs1
211    \tracinggroups1
212    \tracingnesting2
213    \tracingassigns1
214  \fi
215  \tracingcommands3  % 3 gives us more in etex
216  \errorcontextlines16
217}%
218
219% @errormsg{MSG}.  Do the index-like expansions on MSG, but if things
220% aren't perfect, it's not the end of the world, being an error message,
221% after all.
222%
223\def\errormsg{\begingroup \indexnofonts \doerrormsg}
224\def\doerrormsg#1{\errmessage{#1}}
225
226% add check for \lastpenalty to plain's definitions.  If the last thing
227% we did was a \nobreak, we don't want to insert more space.
228%
229\def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
230  \removelastskip\penalty-50\smallskip\fi\fi}
231\def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
232  \removelastskip\penalty-100\medskip\fi\fi}
233\def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
234  \removelastskip\penalty-200\bigskip\fi\fi}
235
236% Output routine
237%
238
239% For a final copy, take out the rectangles
240% that mark overfull boxes (in case you have decided
241% that the text looks ok even though it passes the margin).
242%
243\def\finalout{\overfullrule=0pt }
244
245\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
246\newdimen\topandbottommargin \topandbottommargin=.75in
247
248% Output a mark which sets \thischapter, \thissection and \thiscolor.
249% We dump everything together because we only have one kind of mark.
250% This works because we only use \botmark / \topmark, not \firstmark.
251%
252% A mark contains a subexpression of the \ifcase ... \fi construct.
253% \get*marks macros below extract the needed part using \ifcase.
254%
255% Another complication is to let the user choose whether \thischapter
256% (\thissection) refers to the chapter (section) in effect at the top
257% of a page, or that at the bottom of a page.
258
259% \domark is called twice inside \chapmacro, to add one
260% mark before the section break, and one after.
261%   In the second call \prevchapterdefs is the same as \currentchapterdefs,
262% and \prevsectiondefs is the same as \currentsectiondefs.
263%   Then if the page is not broken at the mark, some of the previous
264% section appears on the page, and we can get the name of this section
265% from \firstmark for @everyheadingmarks top.
266%   @everyheadingmarks bottom uses \botmark.
267%
268% See page 260 of The TeXbook.
269\def\domark{%
270  \toks0=\expandafter{\currentchapterdefs}%
271  \toks2=\expandafter{\currentsectiondefs}%
272  \toks4=\expandafter{\prevchapterdefs}%
273  \toks6=\expandafter{\prevsectiondefs}%
274  \toks8=\expandafter{\currentcolordefs}%
275  \mark{%
276                   \the\toks0 \the\toks2  % 0: marks for @everyheadingmarks top
277      \noexpand\or \the\toks4 \the\toks6  % 1: for @everyheadingmarks bottom
278    \noexpand\else \the\toks8             % 2: color marks
279  }%
280}
281
282% \gettopheadingmarks, \getbottomheadingmarks,
283% \getcolormarks - extract needed part of mark.
284%
285% \topmark doesn't work for the very first chapter (after the title
286% page or the contents), so we use \firstmark there -- this gets us
287% the mark with the chapter defs, unless the user sneaks in, e.g.,
288% @setcolor (or @url, or @link, etc.) between @contents and the very
289% first @chapter.
290\def\gettopheadingmarks{%
291  \ifcase0\the\savedtopmark\fi
292  \ifx\thischapter\empty \ifcase0\firstmark\fi \fi
293}
294\def\getbottomheadingmarks{\ifcase1\botmark\fi}
295\def\getcolormarks{\ifcase2\the\savedtopmark\fi}
296
297% Avoid "undefined control sequence" errors.
298\def\currentchapterdefs{}
299\def\currentsectiondefs{}
300\def\currentsection{}
301\def\prevchapterdefs{}
302\def\prevsectiondefs{}
303\def\currentcolordefs{}
304
305% Margin to add to right of even pages, to left of odd pages.
306\newdimen\bindingoffset
307\newdimen\normaloffset
308\newdimen\txipagewidth \newdimen\txipageheight
309
310% Main output routine.
311%
312\chardef\PAGE = 255
313\newtoks\defaultoutput
314\defaultoutput = {\savetopmark\onepageout{\pagecontents\PAGE}}
315\output=\expandafter{\the\defaultoutput}
316
317\newbox\headlinebox
318\newbox\footlinebox
319
320% When outputting the double column layout for indices, an output routine
321% is run several times, which hides the original value of \topmark.  This
322% can lead to a page heading being output and duplicating the chapter heading
323% of the index.  Hence, save the contents of \topmark at the beginning of
324% the output routine.  The saved contents are valid until we actually
325% \shipout a page.
326%
327% (We used to run a short output routine to actually set \topmark and
328% \firstmark to the right values, but if this was called with an empty page
329% containing whatsits for writing index entries, the whatsits would be thrown
330% away and the index auxiliary file would remain empty.)
331%
332\newtoks\savedtopmark
333\newif\iftopmarksaved
334\topmarksavedtrue
335\def\savetopmark{%
336  \iftopmarksaved\else
337    \global\savedtopmark=\expandafter{\topmark}%
338    \global\topmarksavedtrue
339  \fi
340}
341
342% \onepageout takes a vbox as an argument.
343% \shipout a vbox for a single page, adding an optional header, footer
344% and footnote.  This also causes index entries for this page to be written
345% to the auxiliary files.
346%
347\def\onepageout#1{%
348  \hoffset=\normaloffset
349  %
350  \ifodd\pageno  \advance\hoffset by \bindingoffset
351  \else \advance\hoffset by -\bindingoffset\fi
352  %
353  % Retrieve the information for the headings from the marks in the page,
354  % and call Plain TeX's \makeheadline and \makefootline, which use the
355  % values in \headline and \footline.
356  %
357  % This is used to check if we are on the first page of a chapter.
358  \ifcase1\the\savedtopmark\fi
359  \let\prevchaptername\thischaptername
360  \ifcase0\firstmark\fi
361  \let\curchaptername\thischaptername
362  %
363  \ifodd\pageno \getoddheadingmarks \else \getevenheadingmarks \fi
364  %
365  \ifx\curchaptername\prevchaptername
366    \let\thischapterheading\thischapter
367  \else
368    % \thischapterheading is the same as \thischapter except it is blank
369    % for the first page of a chapter.  This is to prevent the chapter name
370    % being shown twice.
371    \def\thischapterheading{}%
372  \fi
373  %
374  % Common context changes for both heading and footing.
375  % Do this outside of the \shipout so @code etc. will be expanded in
376  % the headline as they should be, not taken literally (outputting ''code).
377  \def\commmonheadfootline{\let\hsize=\txipagewidth \texinfochars}
378  %
379  \global\setbox\headlinebox = \vbox{\commmonheadfootline \makeheadline}%
380  %
381  \ifodd\pageno \getoddfootingmarks \else \getevenfootingmarks \fi
382  \global\setbox\footlinebox = \vbox{\commmonheadfootline \makefootline}%
383  %
384  {%
385    % Set context for writing to auxiliary files like index files.
386    % Have to do this stuff outside the \shipout because we want it to
387    % take effect in \write's, yet the group defined by the \vbox ends
388    % before the \shipout runs.
389    %
390    \indexdummies         % don't expand commands in the output.
391    \normalturnoffactive  % \ in index entries must not stay \, e.g., if
392               % the page break happens to be in the middle of an example.
393               % We don't want .vr (or whatever) entries like this:
394               % \entry{{\indexbackslash }acronym}{32}{\code {\acronym}}
395               % "\acronym" won't work when it's read back in;
396               % it needs to be
397               % {\code {{\backslashcurfont }acronym}
398    \shipout\vbox{%
399      % Do this early so pdf references go to the beginning of the page.
400      \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
401      %
402      \unvbox\headlinebox
403      \pagebody{#1}%
404      \ifdim\ht\footlinebox > 0pt
405        % Only leave this space if the footline is nonempty.
406        % (We lessened \vsize for it in \oddfootingyyy.)
407        % The \baselineskip=24pt in plain's \makefootline has no effect.
408        \vskip 24pt
409        \unvbox\footlinebox
410      \fi
411      %
412    }%
413  }%
414  \global\topmarksavedfalse
415  \advancepageno
416  \ifnum\outputpenalty>-20000 \else\dosupereject\fi
417}
418
419\newinsert\margin \dimen\margin=\maxdimen
420
421% Main part of page, including any footnotes
422\def\pagebody#1{\vbox to\txipageheight{\boxmaxdepth=\maxdepth #1}}
423{\catcode`\@ =11
424\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
425% marginal hacks, juha@viisa.uucp (Juha Takala)
426\ifvoid\margin\else % marginal info is present
427  \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
428\dimen@=\dp#1\relax \unvbox#1\relax
429\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
430\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
431}
432
433
434% Argument parsing
435
436% Parse an argument, then pass it to #1.  The argument is the rest of
437% the input line (except we remove a trailing comment).  #1 should be a
438% macro which expects an ordinary undelimited TeX argument.
439% For example, \def\foo{\parsearg\fooxxx}.
440%
441\def\parsearg{\parseargusing{}}
442\def\parseargusing#1#2{%
443  \def\argtorun{#2}%
444  \begingroup
445    \obeylines
446    \spaceisspace
447    #1%
448    \parseargline\empty% Insert the \empty token, see \finishparsearg below.
449}
450
451{\obeylines %
452  \gdef\parseargline#1^^M{%
453    \endgroup % End of the group started in \parsearg.
454    \argremovecomment #1\comment\ArgTerm%
455  }%
456}
457
458% First remove any @comment, then any @c comment.  Also remove a @texinfoc
459% comment (see \scanmacro for details).  Pass the result on to \argcheckspaces.
460\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
461\def\argremovec#1\c#2\ArgTerm{\argremovetexinfoc #1\texinfoc\ArgTerm}
462\def\argremovetexinfoc#1\texinfoc#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
463
464% Each occurrence of `\^^M' or `<space>\^^M' is replaced by a single space.
465%
466% \argremovec might leave us with trailing space, e.g.,
467%    @end itemize  @c foo
468% This space token undergoes the same procedure and is eventually removed
469% by \finishparsearg.
470%
471\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
472\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
473\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
474  \def\temp{#3}%
475  \ifx\temp\empty
476    % Do not use \next, perhaps the caller of \parsearg uses it; reuse \temp:
477    \let\temp\finishparsearg
478  \else
479    \let\temp\argcheckspaces
480  \fi
481  % Put the space token in:
482  \temp#1 #3\ArgTerm
483}
484
485% If a _delimited_ argument is enclosed in braces, they get stripped; so
486% to get _exactly_ the rest of the line, we had to prevent such situation.
487% We prepended an \empty token at the very beginning and we expand it now,
488% just before passing the control to \argtorun.
489% (Similarly, we have to think about #3 of \argcheckspacesY above: it is
490% either the null string, or it ends with \^^M---thus there is no danger
491% that a pair of braces would be stripped.
492%
493% But first, we have to remove the trailing space token.
494%
495\def\finishparsearg#1 \ArgTerm{\expandafter\argtorun\expandafter{#1}}
496
497
498% \parseargdef - define a command taking an argument on the line
499%
500% \parseargdef\foo{...}
501%	is roughly equivalent to
502% \def\foo{\parsearg\Xfoo}
503% \def\Xfoo#1{...}
504\def\parseargdef#1{%
505  \expandafter \doparseargdef \csname\string#1\endcsname #1%
506}
507\def\doparseargdef#1#2{%
508  \def#2{\parsearg#1}%
509  \def#1##1%
510}
511
512% Several utility definitions with active space:
513{
514  \obeyspaces
515  \gdef\obeyedspace{ }
516
517  % Make each space character in the input produce a normal interword
518  % space in the output.  Don't allow a line break at this space, as this
519  % is used only in environments like @example, where each line of input
520  % should produce a line of output anyway.
521  %
522  \gdef\sepspaces{\obeyspaces\let =\tie}
523
524  % If an index command is used in an @example environment, any spaces
525  % therein should become regular spaces in the raw index file, not the
526  % expansion of \tie (\leavevmode \penalty \@M \ ).
527  \gdef\unsepspaces{\let =\space}
528}
529
530
531\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
532
533% Define the framework for environments in texinfo.tex.  It's used like this:
534%
535%   \envdef\foo{...}
536%   \def\Efoo{...}
537%
538% It's the responsibility of \envdef to insert \begingroup before the
539% actual body; @end closes the group after calling \Efoo.  \envdef also
540% defines \thisenv, so the current environment is known; @end checks
541% whether the environment name matches.  The \checkenv macro can also be
542% used to check whether the current environment is the one expected.
543%
544% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
545% are not treated as environments; they don't open a group.  (The
546% implementation of @end takes care not to call \endgroup in this
547% special case.)
548
549
550% At run-time, environments start with this:
551\def\startenvironment#1{\begingroup\def\thisenv{#1}}
552% initialize
553\let\thisenv\empty
554
555% ... but they get defined via ``\envdef\foo{...}'':
556\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
557\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
558
559% Check whether we're in the right environment:
560\def\checkenv#1{%
561  \def\temp{#1}%
562  \ifx\thisenv\temp
563  \else
564    \badenverr
565  \fi
566}
567
568% Environment mismatch, #1 expected:
569\def\badenverr{%
570  \errhelp = \EMsimple
571  \errmessage{This command can appear only \inenvironment\temp,
572    not \inenvironment\thisenv}%
573}
574\def\inenvironment#1{%
575  \ifx#1\empty
576    outside of any environment%
577  \else
578    in environment \expandafter\string#1%
579  \fi
580}
581
582% @end foo executes the definition of \Efoo.
583% But first, it executes a specialized version of \checkenv
584%
585\parseargdef\end{%
586  \if 1\csname iscond.#1\endcsname
587  \else
588    % The general wording of \badenverr may not be ideal.
589    \expandafter\checkenv\csname#1\endcsname
590    \csname E#1\endcsname
591    \endgroup
592  \fi
593}
594
595\newhelp\EMsimple{Press RETURN to continue.}
596
597
598% Be sure we're in horizontal mode when doing a tie, since we make space
599% equivalent to this in @example-like environments. Otherwise, a space
600% at the beginning of a line will start with \penalty -- and
601% since \penalty is valid in vertical mode, we'd end up putting the
602% penalty on the vertical list instead of in the new paragraph.
603{\catcode`@ = 11
604 % Avoid using \@M directly, because that causes trouble
605 % if the definition is written into an index file.
606 \global\let\tiepenalty = \@M
607 \gdef\tie{\leavevmode\penalty\tiepenalty\ }
608}
609
610% @: forces normal size whitespace following.
611\def\:{\spacefactor=1000 }
612
613% @* forces a line break.
614\def\*{\unskip\hfil\break\hbox{}\ignorespaces}
615
616% @/ allows a line break.
617\let\/=\allowbreak
618
619% @. is an end-of-sentence period.
620\def\.{.\spacefactor=\endofsentencespacefactor\space}
621
622% @! is an end-of-sentence bang.
623\def\!{!\spacefactor=\endofsentencespacefactor\space}
624
625% @? is an end-of-sentence query.
626\def\?{?\spacefactor=\endofsentencespacefactor\space}
627
628% @frenchspacing on|off  says whether to put extra space after punctuation.
629%
630\def\onword{on}
631\def\offword{off}
632%
633\parseargdef\frenchspacing{%
634  \def\temp{#1}%
635  \ifx\temp\onword \plainfrenchspacing
636  \else\ifx\temp\offword \plainnonfrenchspacing
637  \else
638    \errhelp = \EMsimple
639    \errmessage{Unknown @frenchspacing option `\temp', must be on|off}%
640  \fi\fi
641}
642
643% @w prevents a word break.  Without the \leavevmode, @w at the
644% beginning of a paragraph, when TeX is still in vertical mode, would
645% produce a whole line of output instead of starting the paragraph.
646\def\w#1{\leavevmode\hbox{#1}}
647
648% @group ... @end group forces ... to be all on one page, by enclosing
649% it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
650% to keep its height that of a normal line.  According to the rules for
651% \topskip (p.114 of the TeXbook), the glue inserted is
652% max (\topskip - \ht (first item), 0).  If that height is large,
653% therefore, no glue is inserted, and the space between the headline and
654% the text is small, which looks bad.
655%
656% Another complication is that the group might be very large.  This can
657% cause the glue on the previous page to be unduly stretched, because it
658% does not have much material.  In this case, it's better to add an
659% explicit \vfill so that the extra space is at the bottom.  The
660% threshold for doing this is if the group is more than \vfilllimit
661% percent of a page (\vfilllimit can be changed inside of @tex).
662%
663\newbox\groupbox
664\def\vfilllimit{0.7}
665%
666\envdef\group{%
667  \ifnum\catcode`\^^M=\active \else
668    \errhelp = \groupinvalidhelp
669    \errmessage{@group invalid in context where filling is enabled}%
670  \fi
671  \startsavinginserts
672  %
673  \setbox\groupbox = \vtop\bgroup
674    % Do @comment since we are called inside an environment such as
675    % @example, where each end-of-line in the input causes an
676    % end-of-line in the output.  We don't want the end-of-line after
677    % the `@group' to put extra space in the output.  Since @group
678    % should appear on a line by itself (according to the Texinfo
679    % manual), we don't worry about eating any user text.
680    \comment
681}
682%
683% The \vtop produces a box with normal height and large depth; thus, TeX puts
684% \baselineskip glue before it, and (when the next line of text is done)
685% \lineskip glue after it.  Thus, space below is not quite equal to space
686% above.  But it's pretty close.
687\def\Egroup{%
688    % To get correct interline space between the last line of the group
689    % and the first line afterwards, we have to propagate \prevdepth.
690    \endgraf % Not \par, as it may have been set to \lisppar.
691    \global\dimen1 = \prevdepth
692  \egroup           % End the \vtop.
693  \addgroupbox
694  \prevdepth = \dimen1
695  \checkinserts
696}
697
698\def\addgroupbox{
699  % \dimen0 is the vertical size of the group's box.
700  \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
701  % \dimen2 is how much space is left on the page (more or less).
702  \dimen2 = \txipageheight   \advance\dimen2 by -\pagetotal
703  % if the group doesn't fit on the current page, and it's a big big
704  % group, force a page break.
705  \ifdim \dimen0 > \dimen2
706    \ifdim \pagetotal < \vfilllimit\txipageheight
707      \page
708    \fi
709  \fi
710  \box\groupbox
711}
712
713%
714% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
715% message, so this ends up printing `@group can only ...'.
716%
717\newhelp\groupinvalidhelp{%
718group can only be used in environments such as @example,^^J%
719where each line of input produces a line of output.}
720
721% @need space-in-mils
722% forces a page break if there is not space-in-mils remaining.
723
724\newdimen\mil  \mil=0.001in
725
726\parseargdef\need{%
727  % Ensure vertical mode, so we don't make a big box in the middle of a
728  % paragraph.
729  \par
730  %
731  % If the @need value is less than one line space, it's useless.
732  \dimen0 = #1\mil
733  \dimen2 = \ht\strutbox
734  \advance\dimen2 by \dp\strutbox
735  \ifdim\dimen0 > \dimen2
736    %
737    % Do a \strut just to make the height of this box be normal, so the
738    % normal leading is inserted relative to the preceding line.
739    % And a page break here is fine.
740    \vtop to #1\mil{\strut\vfil}%
741    %
742    % TeX does not even consider page breaks if a penalty added to the
743    % main vertical list is 10000 or more.  But in order to see if the
744    % empty box we just added fits on the page, we must make it consider
745    % page breaks.  On the other hand, we don't want to actually break the
746    % page after the empty box.  So we use a penalty of 9999.
747    %
748    % There is an extremely small chance that TeX will actually break the
749    % page at this \penalty, if there are no other feasible breakpoints in
750    % sight.  (If the user is using lots of big @group commands, which
751    % almost-but-not-quite fill up a page, TeX will have a hard time doing
752    % good page breaking, for example.)  However, I could not construct an
753    % example where a page broke at this \penalty; if it happens in a real
754    % document, then we can reconsider our strategy.
755    \penalty9999
756    %
757    % Back up by the size of the box, whether we did a page break or not.
758    \kern -#1\mil
759    %
760    % Do not allow a page break right after this kern.
761    \nobreak
762  \fi
763}
764
765% @br   forces paragraph break (and is undocumented).
766
767\let\br = \par
768
769% @page forces the start of a new page.
770%
771\def\page{\par\vfill\supereject}
772
773% @exdent text....
774% outputs text on separate line in roman font, starting at standard page margin
775
776% This records the amount of indent in the innermost environment.
777% That's how much \exdent should take out.
778\newskip\exdentamount
779
780% This defn is used inside fill environments such as @defun.
781\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
782
783% This defn is used inside nofill environments such as @example.
784\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
785  \leftline{\hskip\leftskip{\rm#1}}}}
786
787% @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
788% paragraph.  For more general purposes, use the \margin insertion
789% class.  WHICH is `l' or `r'.  Not documented, written for gawk manual.
790%
791\newskip\inmarginspacing \inmarginspacing=1cm
792\def\strutdepth{\dp\strutbox}
793%
794\def\doinmargin#1#2{\strut\vadjust{%
795  \nobreak
796  \kern-\strutdepth
797  \vtop to \strutdepth{%
798    \baselineskip=\strutdepth
799    \vss
800    % if you have multiple lines of stuff to put here, you'll need to
801    % make the vbox yourself of the appropriate size.
802    \ifx#1l%
803      \llap{\ignorespaces #2\hskip\inmarginspacing}%
804    \else
805      \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
806    \fi
807    \null
808  }%
809}}
810\def\inleftmargin{\doinmargin l}
811\def\inrightmargin{\doinmargin r}
812%
813% @inmargin{TEXT [, RIGHT-TEXT]}
814% (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
815% else use TEXT for both).
816%
817\def\inmargin#1{\parseinmargin #1,,\finish}
818\def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
819  \setbox0 = \hbox{\ignorespaces #2}%
820  \ifdim\wd0 > 0pt
821    \def\lefttext{#1}%  have both texts
822    \def\righttext{#2}%
823  \else
824    \def\lefttext{#1}%  have only one text
825    \def\righttext{#1}%
826  \fi
827  %
828  \ifodd\pageno
829    \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
830  \else
831    \def\temp{\inleftmargin\lefttext}%
832  \fi
833  \temp
834}
835
836% @include FILE -- \input text of FILE.
837%
838\def\include{\parseargusing\filenamecatcodes\includezzz}
839\def\includezzz#1{%
840  \pushthisfilestack
841  \def\thisfile{#1}%
842  {%
843    \makevalueexpandable  % we want to expand any @value in FILE.
844    \turnoffactive        % and allow special characters in the expansion
845    \indexnofonts         % Allow `@@' and other weird things in file names.
846    \wlog{texinfo.tex: doing @include of #1^^J}%
847    \edef\temp{\noexpand\input #1 }%
848    %
849    % This trickery is to read FILE outside of a group, in case it makes
850    % definitions, etc.
851    \expandafter
852  }\temp
853  \popthisfilestack
854}
855\def\filenamecatcodes{%
856  \catcode`\\=\other
857  \catcode`~=\other
858  \catcode`^=\other
859  \catcode`_=\other
860  \catcode`|=\other
861  \catcode`<=\other
862  \catcode`>=\other
863  \catcode`+=\other
864  \catcode`-=\other
865  \catcode`\`=\other
866  \catcode`\'=\other
867}
868
869\def\pushthisfilestack{%
870  \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
871}
872\def\pushthisfilestackX{%
873  \expandafter\pushthisfilestackY\thisfile\StackTerm
874}
875\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
876  \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
877}
878
879\def\popthisfilestack{\errthisfilestackempty}
880\def\errthisfilestackempty{\errmessage{Internal error:
881  the stack of filenames is empty.}}
882%
883\def\thisfile{}
884
885% @center line
886% outputs that line, centered.
887%
888\parseargdef\center{%
889  \ifhmode
890    \let\centersub\centerH
891  \else
892    \let\centersub\centerV
893  \fi
894  \centersub{\hfil \ignorespaces#1\unskip \hfil}%
895  \let\centersub\relax % don't let the definition persist, just in case
896}
897\def\centerH#1{{%
898  \hfil\break
899  \advance\hsize by -\leftskip
900  \advance\hsize by -\rightskip
901  \line{#1}%
902  \break
903}}
904%
905\newcount\centerpenalty
906\def\centerV#1{%
907  % The idea here is the same as in \startdefun, \cartouche, etc.: if
908  % @center is the first thing after a section heading, we need to wipe
909  % out the negative parskip inserted by \sectionheading, but still
910  % prevent a page break here.
911  \centerpenalty = \lastpenalty
912  \ifnum\centerpenalty>10000 \vskip\parskip \fi
913  \ifnum\centerpenalty>9999 \penalty\centerpenalty \fi
914  \line{\kern\leftskip #1\kern\rightskip}%
915}
916
917% @sp n   outputs n lines of vertical space
918%
919\parseargdef\sp{\vskip #1\baselineskip}
920
921% @comment ...line which is ignored...
922% @c is the same as @comment
923% @ignore ... @end ignore  is another way to write a comment
924
925
926\def\c{\begingroup \catcode`\^^M=\active%
927\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
928\cxxx}
929{\catcode`\^^M=\active \gdef\cxxx#1^^M{\endgroup}}
930%
931\let\comment\c
932
933% @paragraphindent NCHARS
934% We'll use ems for NCHARS, close enough.
935% NCHARS can also be the word `asis' or `none'.
936% We cannot feasibly implement @paragraphindent asis, though.
937%
938\def\asisword{asis} % no translation, these are keywords
939\def\noneword{none}
940%
941\parseargdef\paragraphindent{%
942  \def\temp{#1}%
943  \ifx\temp\asisword
944  \else
945    \ifx\temp\noneword
946      \defaultparindent = 0pt
947    \else
948      \defaultparindent = #1em
949    \fi
950  \fi
951  \parindent = \defaultparindent
952}
953
954% @exampleindent NCHARS
955% We'll use ems for NCHARS like @paragraphindent.
956% It seems @exampleindent asis isn't necessary, but
957% I preserve it to make it similar to @paragraphindent.
958\parseargdef\exampleindent{%
959  \def\temp{#1}%
960  \ifx\temp\asisword
961  \else
962    \ifx\temp\noneword
963      \lispnarrowing = 0pt
964    \else
965      \lispnarrowing = #1em
966    \fi
967  \fi
968}
969
970% @firstparagraphindent WORD
971% If WORD is `none', then suppress indentation of the first paragraph
972% after a section heading.  If WORD is `insert', then do indent at such
973% paragraphs.
974%
975% The paragraph indentation is suppressed or not by calling
976% \suppressfirstparagraphindent, which the sectioning commands do.
977% We switch the definition of this back and forth according to WORD.
978% By default, we suppress indentation.
979%
980\def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
981\def\insertword{insert}
982%
983\parseargdef\firstparagraphindent{%
984  \def\temp{#1}%
985  \ifx\temp\noneword
986    \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
987  \else\ifx\temp\insertword
988    \let\suppressfirstparagraphindent = \relax
989  \else
990    \errhelp = \EMsimple
991    \errmessage{Unknown @firstparagraphindent option `\temp'}%
992  \fi\fi
993}
994
995% Here is how we actually suppress indentation.  Redefine \everypar to
996% \kern backwards by \parindent, and then reset itself to empty.
997%
998% We also make \indent itself not actually do anything until the next
999% paragraph.
1000%
1001\gdef\dosuppressfirstparagraphindent{%
1002  \gdef\indent  {\restorefirstparagraphindent \indent}%
1003  \gdef\noindent{\restorefirstparagraphindent \noindent}%
1004  \global\everypar = {\kern -\parindent \restorefirstparagraphindent}%
1005}
1006%
1007\gdef\restorefirstparagraphindent{%
1008  \global\let\indent = \ptexindent
1009  \global\let\noindent = \ptexnoindent
1010  \global\everypar = {}%
1011}
1012
1013
1014% @refill is a no-op.
1015\let\refill=\relax
1016
1017% @setfilename INFO-FILENAME - ignored
1018\let\setfilename=\comment
1019
1020% @bye.
1021\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
1022
1023
1024\message{pdf,}
1025% adobe `portable' document format
1026\newcount\tempnum
1027\newcount\lnkcount
1028\newtoks\filename
1029\newcount\filenamelength
1030\newcount\pgn
1031\newtoks\toksA
1032\newtoks\toksB
1033\newtoks\toksC
1034\newtoks\toksD
1035\newbox\boxA
1036\newbox\boxB
1037\newcount\countA
1038\newif\ifpdf
1039\newif\ifpdfmakepagedest
1040
1041%
1042% For LuaTeX
1043%
1044
1045\newif\iftxiuseunicodedestname
1046\txiuseunicodedestnamefalse % For pdfTeX etc.
1047
1048\ifx\luatexversion\thisisundefined
1049\else
1050  % Use Unicode destination names
1051  \txiuseunicodedestnametrue
1052  % Escape PDF strings with converting UTF-16 from UTF-8
1053  \begingroup
1054    \catcode`\%=12
1055    \directlua{
1056      function UTF16oct(str)
1057        tex.sprint(string.char(0x5c) .. '376' .. string.char(0x5c) .. '377')
1058        for c in string.utfvalues(str) do
1059          if c < 0x10000 then
1060            tex.sprint(
1061              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
1062                            string.char(0x5c) .. string.char(0x25) .. '03o',
1063                            (c / 256), (c % 256)))
1064          else
1065            c = c - 0x10000
1066            local c_hi = c / 1024 + 0xd800
1067            local c_lo = c % 1024 + 0xdc00
1068            tex.sprint(
1069              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
1070                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
1071                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
1072                            string.char(0x5c) .. string.char(0x25) .. '03o',
1073                            (c_hi / 256), (c_hi % 256),
1074                            (c_lo / 256), (c_lo % 256)))
1075          end
1076        end
1077      end
1078    }
1079  \endgroup
1080  \def\pdfescapestrutfsixteen#1{\directlua{UTF16oct('\luaescapestring{#1}')}}
1081  % Escape PDF strings without converting
1082  \begingroup
1083    \directlua{
1084      function PDFescstr(str)
1085        for c in string.bytes(str) do
1086          if c <= 0x20 or c >= 0x80 or c == 0x28 or c == 0x29 or c == 0x5c then
1087            tex.sprint(
1088              string.format(string.char(0x5c) .. string.char(0x25) .. '03o',
1089                            c))
1090          else
1091            tex.sprint(string.char(c))
1092          end
1093        end
1094      end
1095    }
1096  \endgroup
1097  \def\pdfescapestring#1{\directlua{PDFescstr('\luaescapestring{#1}')}}
1098  \ifnum\luatexversion>84
1099    % For LuaTeX >= 0.85
1100    \def\pdfdest{\pdfextension dest}
1101    \let\pdfoutput\outputmode
1102    \def\pdfliteral{\pdfextension literal}
1103    \def\pdfcatalog{\pdfextension catalog}
1104    \def\pdftexversion{\numexpr\pdffeedback version\relax}
1105    \let\pdfximage\saveimageresource
1106    \let\pdfrefximage\useimageresource
1107    \let\pdflastximage\lastsavedimageresourceindex
1108    \def\pdfendlink{\pdfextension endlink\relax}
1109    \def\pdfoutline{\pdfextension outline}
1110    \def\pdfstartlink{\pdfextension startlink}
1111    \def\pdffontattr{\pdfextension fontattr}
1112    \def\pdfobj{\pdfextension obj}
1113    \def\pdflastobj{\numexpr\pdffeedback lastobj\relax}
1114    \let\pdfpagewidth\pagewidth
1115    \let\pdfpageheight\pageheight
1116    \edef\pdfhorigin{\pdfvariable horigin}
1117    \edef\pdfvorigin{\pdfvariable vorigin}
1118  \fi
1119\fi
1120
1121% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
1122% can be set).  So we test for \relax and 0 as well as being undefined.
1123\ifx\pdfoutput\thisisundefined
1124\else
1125  \ifx\pdfoutput\relax
1126  \else
1127    \ifcase\pdfoutput
1128    \else
1129      \pdftrue
1130    \fi
1131  \fi
1132\fi
1133
1134% PDF uses PostScript string constants for the names of xref targets,
1135% for display in the outlines, and in other places.  Thus, we have to
1136% double any backslashes.  Otherwise, a name like "\node" will be
1137% interpreted as a newline (\n), followed by o, d, e.  Not good.
1138%
1139% See http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html and
1140% related messages.  The final outcome is that it is up to the TeX user
1141% to double the backslashes and otherwise make the string valid, so
1142% that's what we do.  pdftex 1.30.0 (ca.2005) introduced a primitive to
1143% do this reliably, so we use it.
1144
1145% #1 is a control sequence in which to do the replacements,
1146% which we \xdef.
1147\def\txiescapepdf#1{%
1148  \ifx\pdfescapestring\thisisundefined
1149    % No primitive available; should we give a warning or log?
1150    % Many times it won't matter.
1151    \xdef#1{#1}%
1152  \else
1153    % The expandable \pdfescapestring primitive escapes parentheses,
1154    % backslashes, and other special chars.
1155    \xdef#1{\pdfescapestring{#1}}%
1156  \fi
1157}
1158\def\txiescapepdfutfsixteen#1{%
1159  \ifx\pdfescapestrutfsixteen\thisisundefined
1160    % No UTF-16 converting macro available.
1161    \txiescapepdf{#1}%
1162  \else
1163    \xdef#1{\pdfescapestrutfsixteen{#1}}%
1164  \fi
1165}
1166
1167\newhelp\nopdfimagehelp{Texinfo supports .png, .jpg, .jpeg, and .pdf images
1168with PDF output, and none of those formats could be found.  (.eps cannot
1169be supported due to the design of the PDF format; use regular TeX (DVI
1170output) for that.)}
1171
1172\ifpdf
1173  %
1174  % Color manipulation macros using ideas from pdfcolor.tex,
1175  % except using rgb instead of cmyk; the latter is said to render as a
1176  % very dark gray on-screen and a very dark halftone in print, instead
1177  % of actual black. The dark red here is dark enough to print on paper as
1178  % nearly black, but still distinguishable for online viewing.  We use
1179  % black by default, though.
1180  \def\rgbDarkRed{0.50 0.09 0.12}
1181  \def\rgbBlack{0 0 0}
1182  %
1183  % rg sets the color for filling (usual text, etc.);
1184  % RG sets the color for stroking (thin rules, e.g., normal _'s).
1185  \def\pdfsetcolor#1{\pdfliteral{#1 rg  #1 RG}}
1186  %
1187  % Set color, and create a mark which defines \thiscolor accordingly,
1188  % so that \makeheadline knows which color to restore.
1189  \def\setcolor#1{%
1190    \xdef\currentcolordefs{\gdef\noexpand\thiscolor{#1}}%
1191    \domark
1192    \pdfsetcolor{#1}%
1193  }
1194  %
1195  \def\maincolor{\rgbBlack}
1196  \pdfsetcolor{\maincolor}
1197  \edef\thiscolor{\maincolor}
1198  \def\currentcolordefs{}
1199  %
1200  \def\makefootline{%
1201    \baselineskip24pt
1202    \line{\pdfsetcolor{\maincolor}\the\footline}%
1203  }
1204  %
1205  \def\makeheadline{%
1206    \vbox to 0pt{%
1207      \vskip-22.5pt
1208      \line{%
1209        \vbox to8.5pt{}%
1210        % Extract \thiscolor definition from the marks.
1211        \getcolormarks
1212        % Typeset the headline with \maincolor, then restore the color.
1213        \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
1214      }%
1215      \vss
1216    }%
1217    \nointerlineskip
1218  }
1219  %
1220  %
1221  \pdfcatalog{/PageMode /UseOutlines}
1222  %
1223  % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1224  \def\dopdfimage#1#2#3{%
1225    \def\pdfimagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1226    \def\pdfimageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1227    %
1228    % pdftex (and the PDF format) support .pdf, .png, .jpg (among
1229    % others).  Let's try in that order, PDF first since if
1230    % someone has a scalable image, presumably better to use that than a
1231    % bitmap.
1232    \let\pdfimgext=\empty
1233    \begingroup
1234      \openin 1 #1.pdf \ifeof 1
1235        \openin 1 #1.PDF \ifeof 1
1236          \openin 1 #1.png \ifeof 1
1237            \openin 1 #1.jpg \ifeof 1
1238              \openin 1 #1.jpeg \ifeof 1
1239                \openin 1 #1.JPG \ifeof 1
1240                  \errhelp = \nopdfimagehelp
1241                  \errmessage{Could not find image file #1 for pdf}%
1242                \else \gdef\pdfimgext{JPG}%
1243                \fi
1244              \else \gdef\pdfimgext{jpeg}%
1245              \fi
1246            \else \gdef\pdfimgext{jpg}%
1247            \fi
1248          \else \gdef\pdfimgext{png}%
1249          \fi
1250        \else \gdef\pdfimgext{PDF}%
1251        \fi
1252      \else \gdef\pdfimgext{pdf}%
1253      \fi
1254      \closein 1
1255    \endgroup
1256    %
1257    % without \immediate, ancient pdftex seg faults when the same image is
1258    % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
1259    \ifnum\pdftexversion < 14
1260      \immediate\pdfimage
1261    \else
1262      \immediate\pdfximage
1263    \fi
1264      \ifdim \wd0 >0pt width \pdfimagewidth \fi
1265      \ifdim \wd2 >0pt height \pdfimageheight \fi
1266      \ifnum\pdftexversion<13
1267         #1.\pdfimgext
1268       \else
1269         {#1.\pdfimgext}%
1270       \fi
1271    \ifnum\pdftexversion < 14 \else
1272      \pdfrefximage \pdflastximage
1273    \fi}
1274  %
1275  \def\setpdfdestname#1{{%
1276    % We have to set dummies so commands such as @code, and characters
1277    % such as \, aren't expanded when present in a section title.
1278    \indexnofonts
1279    \makevalueexpandable
1280    \turnoffactive
1281    \iftxiuseunicodedestname
1282      \ifx \declaredencoding \latone
1283        % Pass through Latin-1 characters.
1284        % LuaTeX with byte wise I/O converts Latin-1 characters to Unicode.
1285      \else
1286        \ifx \declaredencoding \utfeight
1287          % Pass through Unicode characters.
1288        \else
1289          % Use ASCII approximations in destination names.
1290          \passthroughcharsfalse
1291        \fi
1292      \fi
1293    \else
1294      % Use ASCII approximations in destination names.
1295      \passthroughcharsfalse
1296    \fi
1297    \def\pdfdestname{#1}%
1298    \txiescapepdf\pdfdestname
1299  }}
1300  %
1301  \def\setpdfoutlinetext#1{{%
1302    \indexnofonts
1303    \makevalueexpandable
1304    \turnoffactive
1305    \ifx \declaredencoding \latone
1306      % The PDF format can use an extended form of Latin-1 in bookmark
1307      % strings.  See Appendix D of the PDF Reference, Sixth Edition, for
1308      % the "PDFDocEncoding".
1309      \passthroughcharstrue
1310      % Pass through Latin-1 characters.
1311      %   LuaTeX: Convert to Unicode
1312      %   pdfTeX: Use Latin-1 as PDFDocEncoding
1313      \def\pdfoutlinetext{#1}%
1314    \else
1315      \ifx \declaredencoding \utfeight
1316        \ifx\luatexversion\thisisundefined
1317          % For pdfTeX  with UTF-8.
1318          % TODO: the PDF format can use UTF-16 in bookmark strings,
1319          % but the code for this isn't done yet.
1320          % Use ASCII approximations.
1321          \passthroughcharsfalse
1322          \def\pdfoutlinetext{#1}%
1323        \else
1324          % For LuaTeX with UTF-8.
1325          % Pass through Unicode characters for title texts.
1326          \passthroughcharstrue
1327          \def\pdfoutlinetext{#1}%
1328        \fi
1329      \else
1330        % For non-Latin-1 or non-UTF-8 encodings.
1331        % Use ASCII approximations.
1332        \passthroughcharsfalse
1333        \def\pdfoutlinetext{#1}%
1334      \fi
1335    \fi
1336    % LuaTeX: Convert to UTF-16
1337    % pdfTeX: Use Latin-1 as PDFDocEncoding
1338    \txiescapepdfutfsixteen\pdfoutlinetext
1339  }}
1340  %
1341  \def\pdfmkdest#1{%
1342    \setpdfdestname{#1}%
1343    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1344  }
1345  %
1346  % used to mark target names; must be expandable.
1347  \def\pdfmkpgn#1{#1}
1348  %
1349  % by default, use black for everything.
1350  \def\urlcolor{\rgbBlack}
1351  \def\linkcolor{\rgbBlack}
1352  \def\endlink{\setcolor{\maincolor}\pdfendlink}
1353  %
1354  % Adding outlines to PDF; macros for calculating structure of outlines
1355  % come from Petr Olsak
1356  \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
1357    \else \csname#1\endcsname \fi}
1358  \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
1359    \advance\tempnum by 1
1360    \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
1361  %
1362  % #1 is the section text, which is what will be displayed in the
1363  % outline by the pdf viewer.  #2 is the pdf expression for the number
1364  % of subentries (or empty, for subsubsections).  #3 is the node text,
1365  % which might be empty if this toc entry had no corresponding node.
1366  % #4 is the page number
1367  %
1368  \def\dopdfoutline#1#2#3#4{%
1369    % Generate a link to the node text if that exists; else, use the
1370    % page number.  We could generate a destination for the section
1371    % text in the case where a section has no node, but it doesn't
1372    % seem worth the trouble, since most documents are normally structured.
1373    \setpdfoutlinetext{#1}
1374    \setpdfdestname{#3}
1375    \ifx\pdfdestname\empty
1376      \def\pdfdestname{#4}%
1377    \fi
1378    %
1379    \pdfoutline goto name{\pdfmkpgn{\pdfdestname}}#2{\pdfoutlinetext}%
1380  }
1381  %
1382  \def\pdfmakeoutlines{%
1383    \begingroup
1384      % Read toc silently, to get counts of subentries for \pdfoutline.
1385      \def\partentry##1##2##3##4{}% ignore parts in the outlines
1386      \def\numchapentry##1##2##3##4{%
1387	\def\thischapnum{##2}%
1388	\def\thissecnum{0}%
1389	\def\thissubsecnum{0}%
1390      }%
1391      \def\numsecentry##1##2##3##4{%
1392	\advancenumber{chap\thischapnum}%
1393	\def\thissecnum{##2}%
1394	\def\thissubsecnum{0}%
1395      }%
1396      \def\numsubsecentry##1##2##3##4{%
1397	\advancenumber{sec\thissecnum}%
1398	\def\thissubsecnum{##2}%
1399      }%
1400      \def\numsubsubsecentry##1##2##3##4{%
1401	\advancenumber{subsec\thissubsecnum}%
1402      }%
1403      \def\thischapnum{0}%
1404      \def\thissecnum{0}%
1405      \def\thissubsecnum{0}%
1406      %
1407      % use \def rather than \let here because we redefine \chapentry et
1408      % al. a second time, below.
1409      \def\appentry{\numchapentry}%
1410      \def\appsecentry{\numsecentry}%
1411      \def\appsubsecentry{\numsubsecentry}%
1412      \def\appsubsubsecentry{\numsubsubsecentry}%
1413      \def\unnchapentry{\numchapentry}%
1414      \def\unnsecentry{\numsecentry}%
1415      \def\unnsubsecentry{\numsubsecentry}%
1416      \def\unnsubsubsecentry{\numsubsubsecentry}%
1417      \readdatafile{toc}%
1418      %
1419      % Read toc second time, this time actually producing the outlines.
1420      % The `-' means take the \expnumber as the absolute number of
1421      % subentries, which we calculated on our first read of the .toc above.
1422      %
1423      % We use the node names as the destinations.
1424      \def\numchapentry##1##2##3##4{%
1425        \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
1426      \def\numsecentry##1##2##3##4{%
1427        \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
1428      \def\numsubsecentry##1##2##3##4{%
1429        \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
1430      \def\numsubsubsecentry##1##2##3##4{% count is always zero
1431        \dopdfoutline{##1}{}{##3}{##4}}%
1432      %
1433      % PDF outlines are displayed using system fonts, instead of
1434      % document fonts.  Therefore we cannot use special characters,
1435      % since the encoding is unknown.  For example, the eogonek from
1436      % Latin 2 (0xea) gets translated to a | character.  Info from
1437      % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
1438      %
1439      % TODO this right, we have to translate 8-bit characters to
1440      % their "best" equivalent, based on the @documentencoding.  Too
1441      % much work for too little return.  Just use the ASCII equivalents
1442      % we use for the index sort strings.
1443      %
1444      \indexnofonts
1445      \setupdatafile
1446      % We can have normal brace characters in the PDF outlines, unlike
1447      % Texinfo index files.  So set that up.
1448      \def\{{\lbracecharliteral}%
1449      \def\}{\rbracecharliteral}%
1450      \catcode`\\=\active \otherbackslash
1451      \input \tocreadfilename
1452    \endgroup
1453  }
1454  {\catcode`[=1 \catcode`]=2
1455   \catcode`{=\other \catcode`}=\other
1456   \gdef\lbracecharliteral[{]%
1457   \gdef\rbracecharliteral[}]%
1458  ]
1459  %
1460  \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1461    \ifx\PP\D\let\nextsp\relax
1462    \else\let\nextsp\skipspaces
1463      \addtokens{\filename}{\PP}%
1464      \advance\filenamelength by 1
1465    \fi
1466    \nextsp}
1467  \def\getfilename#1{%
1468    \filenamelength=0
1469    % If we don't expand the argument now, \skipspaces will get
1470    % snagged on things like "@value{foo}".
1471    \edef\temp{#1}%
1472    \expandafter\skipspaces\temp|\relax
1473  }
1474  \ifnum\pdftexversion < 14
1475    \let \startlink \pdfannotlink
1476  \else
1477    \let \startlink \pdfstartlink
1478  \fi
1479  % make a live url in pdf output.
1480  \def\pdfurl#1{%
1481    \begingroup
1482      % it seems we really need yet another set of dummies; have not
1483      % tried to figure out what each command should do in the context
1484      % of @url.  for now, just make @/ a no-op, that's the only one
1485      % people have actually reported a problem with.
1486      %
1487      \normalturnoffactive
1488      \def\@{@}%
1489      \let\/=\empty
1490      \makevalueexpandable
1491      % do we want to go so far as to use \indexnofonts instead of just
1492      % special-casing \var here?
1493      \def\var##1{##1}%
1494      %
1495      \leavevmode\setcolor{\urlcolor}%
1496      \startlink attr{/Border [0 0 0]}%
1497        user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
1498    \endgroup}
1499  % \pdfgettoks - Surround page numbers in #1 with @pdflink.  #1 may
1500  % be a simple number, or a list of numbers in the case of an index
1501  % entry.
1502  \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1503  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1504  \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1505  \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1506  \def\maketoks{%
1507    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1508    \ifx\first0\adn0
1509    \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1510    \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1511    \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1512    \else
1513      \ifnum0=\countA\else\makelink\fi
1514      \ifx\first.\let\next=\done\else
1515        \let\next=\maketoks
1516        \addtokens{\toksB}{\the\toksD}
1517        \ifx\first,\addtokens{\toksB}{\space}\fi
1518      \fi
1519    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1520    \next}
1521  \def\makelink{\addtokens{\toksB}%
1522    {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1523  \def\pdflink#1{%
1524    \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
1525    \setcolor{\linkcolor}#1\endlink}
1526  \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1527\else
1528  % non-pdf mode
1529  \let\pdfmkdest = \gobble
1530  \let\pdfurl = \gobble
1531  \let\endlink = \relax
1532  \let\setcolor = \gobble
1533  \let\pdfsetcolor = \gobble
1534  \let\pdfmakeoutlines = \relax
1535\fi  % \ifx\pdfoutput
1536
1537%
1538% For XeTeX
1539%
1540\ifx\XeTeXrevision\thisisundefined
1541\else
1542  %
1543  % XeTeX version check
1544  %
1545  \ifnum\strcmp{\the\XeTeXversion\XeTeXrevision}{0.99996}>-1
1546    % TeX Live 2016 contains XeTeX 0.99996 and xdvipdfmx 20160307.
1547    % It can use the `dvipdfmx:config' special (from TeX Live SVN r40941).
1548    % For avoiding PDF destination name replacement, we use this special
1549    % instead of xdvipdfmx's command line option `-C 0x0010'.
1550    \special{dvipdfmx:config C 0x0010}
1551    % XeTeX 0.99995+ comes with xdvipdfmx 20160307+.
1552    % It can handle Unicode destination names for PDF.
1553    \txiuseunicodedestnametrue
1554  \else
1555    % XeTeX < 0.99996 (TeX Live < 2016) cannot use the
1556    % `dvipdfmx:config' special.
1557    % So for avoiding PDF destination name replacement,
1558    % xdvipdfmx's command line option `-C 0x0010' is necessary.
1559    %
1560    % XeTeX < 0.99995 can not handle Unicode destination names for PDF
1561    % because xdvipdfmx 20150315 has a UTF-16 conversion issue.
1562    % It is fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1563    \txiuseunicodedestnamefalse
1564  \fi
1565  %
1566  % Color support
1567  %
1568  \def\rgbDarkRed{0.50 0.09 0.12}
1569  \def\rgbBlack{0 0 0}
1570  %
1571  \def\pdfsetcolor#1{\special{pdf:scolor [#1]}}
1572  %
1573  % Set color, and create a mark which defines \thiscolor accordingly,
1574  % so that \makeheadline knows which color to restore.
1575  \def\setcolor#1{%
1576    \xdef\currentcolordefs{\gdef\noexpand\thiscolor{#1}}%
1577    \domark
1578    \pdfsetcolor{#1}%
1579  }
1580  %
1581  \def\maincolor{\rgbBlack}
1582  \pdfsetcolor{\maincolor}
1583  \edef\thiscolor{\maincolor}
1584  \def\currentcolordefs{}
1585  %
1586  \def\makefootline{%
1587    \baselineskip24pt
1588    \line{\pdfsetcolor{\maincolor}\the\footline}%
1589  }
1590  %
1591  \def\makeheadline{%
1592    \vbox to 0pt{%
1593      \vskip-22.5pt
1594      \line{%
1595        \vbox to8.5pt{}%
1596        % Extract \thiscolor definition from the marks.
1597        \getcolormarks
1598        % Typeset the headline with \maincolor, then restore the color.
1599        \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
1600      }%
1601      \vss
1602    }%
1603    \nointerlineskip
1604  }
1605  %
1606  % PDF outline support
1607  %
1608  % Emulate pdfTeX primitive
1609  \def\pdfdest name#1 xyz{%
1610    \special{pdf:dest (#1) [@thispage /XYZ @xpos @ypos null]}%
1611  }
1612  %
1613  \def\setpdfdestname#1{{%
1614    % We have to set dummies so commands such as @code, and characters
1615    % such as \, aren't expanded when present in a section title.
1616    \indexnofonts
1617    \makevalueexpandable
1618    \turnoffactive
1619    \iftxiuseunicodedestname
1620      % Pass through Unicode characters.
1621    \else
1622      % Use ASCII approximations in destination names.
1623      \passthroughcharsfalse
1624    \fi
1625    \def\pdfdestname{#1}%
1626    \txiescapepdf\pdfdestname
1627  }}
1628  %
1629  \def\setpdfoutlinetext#1{{%
1630    \turnoffactive
1631    % Always use Unicode characters in title texts.
1632    \def\pdfoutlinetext{#1}%
1633    % For XeTeX, xdvipdfmx converts to UTF-16.
1634    % So we do not convert.
1635    \txiescapepdf\pdfoutlinetext
1636  }}
1637  %
1638  \def\pdfmkdest#1{%
1639    \setpdfdestname{#1}%
1640    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1641  }
1642  %
1643  % by default, use black for everything.
1644  \def\urlcolor{\rgbBlack}
1645  \def\linkcolor{\rgbBlack}
1646  \def\endlink{\setcolor{\maincolor}\pdfendlink}
1647  %
1648  \def\dopdfoutline#1#2#3#4{%
1649    \setpdfoutlinetext{#1}
1650    \setpdfdestname{#3}
1651    \ifx\pdfdestname\empty
1652      \def\pdfdestname{#4}%
1653    \fi
1654    %
1655    \special{pdf:out [-] #2 << /Title (\pdfoutlinetext) /A
1656      << /S /GoTo /D (\pdfdestname) >> >> }%
1657  }
1658  %
1659  \def\pdfmakeoutlines{%
1660    \begingroup
1661      %
1662      % For XeTeX, counts of subentries are not necessary.
1663      % Therefore, we read toc only once.
1664      %
1665      % We use node names as destinations.
1666      \def\partentry##1##2##3##4{}% ignore parts in the outlines
1667      \def\numchapentry##1##2##3##4{%
1668        \dopdfoutline{##1}{1}{##3}{##4}}%
1669      \def\numsecentry##1##2##3##4{%
1670        \dopdfoutline{##1}{2}{##3}{##4}}%
1671      \def\numsubsecentry##1##2##3##4{%
1672        \dopdfoutline{##1}{3}{##3}{##4}}%
1673      \def\numsubsubsecentry##1##2##3##4{%
1674        \dopdfoutline{##1}{4}{##3}{##4}}%
1675      %
1676      \let\appentry\numchapentry%
1677      \let\appsecentry\numsecentry%
1678      \let\appsubsecentry\numsubsecentry%
1679      \let\appsubsubsecentry\numsubsubsecentry%
1680      \let\unnchapentry\numchapentry%
1681      \let\unnsecentry\numsecentry%
1682      \let\unnsubsecentry\numsubsecentry%
1683      \let\unnsubsubsecentry\numsubsubsecentry%
1684      %
1685      % For XeTeX, xdvipdfmx converts strings to UTF-16.
1686      % Therefore, the encoding and the language may not be considered.
1687      %
1688      \indexnofonts
1689      \setupdatafile
1690      % We can have normal brace characters in the PDF outlines, unlike
1691      % Texinfo index files.  So set that up.
1692      \def\{{\lbracecharliteral}%
1693      \def\}{\rbracecharliteral}%
1694      \catcode`\\=\active \otherbackslash
1695      \input \tocreadfilename
1696    \endgroup
1697  }
1698  {\catcode`[=1 \catcode`]=2
1699   \catcode`{=\other \catcode`}=\other
1700   \gdef\lbracecharliteral[{]%
1701   \gdef\rbracecharliteral[}]%
1702  ]
1703
1704  \special{pdf:docview << /PageMode /UseOutlines >> }
1705  % ``\special{pdf:tounicode ...}'' is not necessary
1706  % because xdvipdfmx converts strings from UTF-8 to UTF-16 without it.
1707  % However, due to a UTF-16 conversion issue of xdvipdfmx 20150315,
1708  % ``\special{pdf:dest ...}'' cannot handle non-ASCII strings.
1709  % It is fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1710%
1711  \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1712    \ifx\PP\D\let\nextsp\relax
1713    \else\let\nextsp\skipspaces
1714      \addtokens{\filename}{\PP}%
1715      \advance\filenamelength by 1
1716    \fi
1717    \nextsp}
1718  \def\getfilename#1{%
1719    \filenamelength=0
1720    % If we don't expand the argument now, \skipspaces will get
1721    % snagged on things like "@value{foo}".
1722    \edef\temp{#1}%
1723    \expandafter\skipspaces\temp|\relax
1724  }
1725  % make a live url in pdf output.
1726  \def\pdfurl#1{%
1727    \begingroup
1728      % it seems we really need yet another set of dummies; have not
1729      % tried to figure out what each command should do in the context
1730      % of @url.  for now, just make @/ a no-op, that's the only one
1731      % people have actually reported a problem with.
1732      %
1733      \normalturnoffactive
1734      \def\@{@}%
1735      \let\/=\empty
1736      \makevalueexpandable
1737      % do we want to go so far as to use \indexnofonts instead of just
1738      % special-casing \var here?
1739      \def\var##1{##1}%
1740      %
1741      \leavevmode\setcolor{\urlcolor}%
1742      \special{pdf:bann << /Border [0 0 0]
1743        /Subtype /Link /A << /S /URI /URI (#1) >> >>}%
1744    \endgroup}
1745  \def\endlink{\setcolor{\maincolor}\special{pdf:eann}}
1746  \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1747  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1748  \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1749  \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1750  \def\maketoks{%
1751    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1752    \ifx\first0\adn0
1753    \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1754    \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1755    \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1756    \else
1757      \ifnum0=\countA\else\makelink\fi
1758      \ifx\first.\let\next=\done\else
1759        \let\next=\maketoks
1760        \addtokens{\toksB}{\the\toksD}
1761        \ifx\first,\addtokens{\toksB}{\space}\fi
1762      \fi
1763    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1764    \next}
1765  \def\makelink{\addtokens{\toksB}%
1766    {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1767  \def\pdflink#1{%
1768    \special{pdf:bann << /Border [0 0 0]
1769      /Type /Annot /Subtype /Link /A << /S /GoTo /D (#1) >> >>}%
1770    \setcolor{\linkcolor}#1\endlink}
1771  \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1772%
1773  %
1774  % @image support
1775  %
1776  % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1777  \def\doxeteximage#1#2#3{%
1778    \def\xeteximagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1779    \def\xeteximageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1780    %
1781    % XeTeX (and the PDF format) supports .pdf, .png, .jpg (among
1782    % others).  Let's try in that order, PDF first since if
1783    % someone has a scalable image, presumably better to use that than a
1784    % bitmap.
1785    \let\xeteximgext=\empty
1786    \begingroup
1787      \openin 1 #1.pdf \ifeof 1
1788        \openin 1 #1.PDF \ifeof 1
1789          \openin 1 #1.png \ifeof 1
1790            \openin 1 #1.jpg \ifeof 1
1791              \openin 1 #1.jpeg \ifeof 1
1792                \openin 1 #1.JPG \ifeof 1
1793                  \errmessage{Could not find image file #1 for XeTeX}%
1794                \else \gdef\xeteximgext{JPG}%
1795                \fi
1796              \else \gdef\xeteximgext{jpeg}%
1797              \fi
1798            \else \gdef\xeteximgext{jpg}%
1799            \fi
1800          \else \gdef\xeteximgext{png}%
1801          \fi
1802        \else \gdef\xeteximgext{PDF}%
1803        \fi
1804      \else \gdef\xeteximgext{pdf}%
1805      \fi
1806      \closein 1
1807    \endgroup
1808    %
1809    \def\xetexpdfext{pdf}%
1810    \ifx\xeteximgext\xetexpdfext
1811      \XeTeXpdffile "#1".\xeteximgext ""
1812    \else
1813      \def\xetexpdfext{PDF}%
1814      \ifx\xeteximgext\xetexpdfext
1815        \XeTeXpdffile "#1".\xeteximgext ""
1816      \else
1817        \XeTeXpicfile "#1".\xeteximgext ""
1818      \fi
1819    \fi
1820    \ifdim \wd0 >0pt width \xeteximagewidth \fi
1821    \ifdim \wd2 >0pt height \xeteximageheight \fi \relax
1822  }
1823\fi
1824
1825
1826%
1827\message{fonts,}
1828
1829% Set the baselineskip to #1, and the lineskip and strut size
1830% correspondingly.  There is no deep meaning behind these magic numbers
1831% used as factors; they just match (closely enough) what Knuth defined.
1832%
1833\def\lineskipfactor{.08333}
1834\def\strutheightpercent{.70833}
1835\def\strutdepthpercent {.29167}
1836%
1837% can get a sort of poor man's double spacing by redefining this.
1838\def\baselinefactor{1}
1839%
1840\newdimen\textleading
1841\def\setleading#1{%
1842  \dimen0 = #1\relax
1843  \normalbaselineskip = \baselinefactor\dimen0
1844  \normallineskip = \lineskipfactor\normalbaselineskip
1845  \normalbaselines
1846  \setbox\strutbox =\hbox{%
1847    \vrule width0pt height\strutheightpercent\baselineskip
1848                    depth \strutdepthpercent \baselineskip
1849  }%
1850}
1851
1852% PDF CMaps.  See also LaTeX's t1.cmap.
1853%
1854% do nothing with this by default.
1855\expandafter\let\csname cmapOT1\endcsname\gobble
1856\expandafter\let\csname cmapOT1IT\endcsname\gobble
1857\expandafter\let\csname cmapOT1TT\endcsname\gobble
1858
1859% if we are producing pdf, and we have \pdffontattr, then define cmaps.
1860% (\pdffontattr was introduced many years ago, but people still run
1861% older pdftex's; it's easy to conditionalize, so we do.)
1862\ifpdf \ifx\pdffontattr\thisisundefined \else
1863  \begingroup
1864    \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1865    \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1866%%DocumentNeededResources: ProcSet (CIDInit)
1867%%IncludeResource: ProcSet (CIDInit)
1868%%BeginResource: CMap (TeX-OT1-0)
1869%%Title: (TeX-OT1-0 TeX OT1 0)
1870%%Version: 1.000
1871%%EndComments
1872/CIDInit /ProcSet findresource begin
187312 dict begin
1874begincmap
1875/CIDSystemInfo
1876<< /Registry (TeX)
1877/Ordering (OT1)
1878/Supplement 0
1879>> def
1880/CMapName /TeX-OT1-0 def
1881/CMapType 2 def
18821 begincodespacerange
1883<00> <7F>
1884endcodespacerange
18858 beginbfrange
1886<00> <01> <0393>
1887<09> <0A> <03A8>
1888<23> <26> <0023>
1889<28> <3B> <0028>
1890<3F> <5B> <003F>
1891<5D> <5E> <005D>
1892<61> <7A> <0061>
1893<7B> <7C> <2013>
1894endbfrange
189540 beginbfchar
1896<02> <0398>
1897<03> <039B>
1898<04> <039E>
1899<05> <03A0>
1900<06> <03A3>
1901<07> <03D2>
1902<08> <03A6>
1903<0B> <00660066>
1904<0C> <00660069>
1905<0D> <0066006C>
1906<0E> <006600660069>
1907<0F> <00660066006C>
1908<10> <0131>
1909<11> <0237>
1910<12> <0060>
1911<13> <00B4>
1912<14> <02C7>
1913<15> <02D8>
1914<16> <00AF>
1915<17> <02DA>
1916<18> <00B8>
1917<19> <00DF>
1918<1A> <00E6>
1919<1B> <0153>
1920<1C> <00F8>
1921<1D> <00C6>
1922<1E> <0152>
1923<1F> <00D8>
1924<21> <0021>
1925<22> <201D>
1926<27> <2019>
1927<3C> <00A1>
1928<3D> <003D>
1929<3E> <00BF>
1930<5C> <201C>
1931<5F> <02D9>
1932<60> <2018>
1933<7D> <02DD>
1934<7E> <007E>
1935<7F> <00A8>
1936endbfchar
1937endcmap
1938CMapName currentdict /CMap defineresource pop
1939end
1940end
1941%%EndResource
1942%%EOF
1943    }\endgroup
1944  \expandafter\edef\csname cmapOT1\endcsname#1{%
1945    \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
1946  }%
1947%
1948% \cmapOT1IT
1949  \begingroup
1950    \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1951    \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1952%%DocumentNeededResources: ProcSet (CIDInit)
1953%%IncludeResource: ProcSet (CIDInit)
1954%%BeginResource: CMap (TeX-OT1IT-0)
1955%%Title: (TeX-OT1IT-0 TeX OT1IT 0)
1956%%Version: 1.000
1957%%EndComments
1958/CIDInit /ProcSet findresource begin
195912 dict begin
1960begincmap
1961/CIDSystemInfo
1962<< /Registry (TeX)
1963/Ordering (OT1IT)
1964/Supplement 0
1965>> def
1966/CMapName /TeX-OT1IT-0 def
1967/CMapType 2 def
19681 begincodespacerange
1969<00> <7F>
1970endcodespacerange
19718 beginbfrange
1972<00> <01> <0393>
1973<09> <0A> <03A8>
1974<25> <26> <0025>
1975<28> <3B> <0028>
1976<3F> <5B> <003F>
1977<5D> <5E> <005D>
1978<61> <7A> <0061>
1979<7B> <7C> <2013>
1980endbfrange
198142 beginbfchar
1982<02> <0398>
1983<03> <039B>
1984<04> <039E>
1985<05> <03A0>
1986<06> <03A3>
1987<07> <03D2>
1988<08> <03A6>
1989<0B> <00660066>
1990<0C> <00660069>
1991<0D> <0066006C>
1992<0E> <006600660069>
1993<0F> <00660066006C>
1994<10> <0131>
1995<11> <0237>
1996<12> <0060>
1997<13> <00B4>
1998<14> <02C7>
1999<15> <02D8>
2000<16> <00AF>
2001<17> <02DA>
2002<18> <00B8>
2003<19> <00DF>
2004<1A> <00E6>
2005<1B> <0153>
2006<1C> <00F8>
2007<1D> <00C6>
2008<1E> <0152>
2009<1F> <00D8>
2010<21> <0021>
2011<22> <201D>
2012<23> <0023>
2013<24> <00A3>
2014<27> <2019>
2015<3C> <00A1>
2016<3D> <003D>
2017<3E> <00BF>
2018<5C> <201C>
2019<5F> <02D9>
2020<60> <2018>
2021<7D> <02DD>
2022<7E> <007E>
2023<7F> <00A8>
2024endbfchar
2025endcmap
2026CMapName currentdict /CMap defineresource pop
2027end
2028end
2029%%EndResource
2030%%EOF
2031    }\endgroup
2032  \expandafter\edef\csname cmapOT1IT\endcsname#1{%
2033    \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
2034  }%
2035%
2036% \cmapOT1TT
2037  \begingroup
2038    \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
2039    \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
2040%%DocumentNeededResources: ProcSet (CIDInit)
2041%%IncludeResource: ProcSet (CIDInit)
2042%%BeginResource: CMap (TeX-OT1TT-0)
2043%%Title: (TeX-OT1TT-0 TeX OT1TT 0)
2044%%Version: 1.000
2045%%EndComments
2046/CIDInit /ProcSet findresource begin
204712 dict begin
2048begincmap
2049/CIDSystemInfo
2050<< /Registry (TeX)
2051/Ordering (OT1TT)
2052/Supplement 0
2053>> def
2054/CMapName /TeX-OT1TT-0 def
2055/CMapType 2 def
20561 begincodespacerange
2057<00> <7F>
2058endcodespacerange
20595 beginbfrange
2060<00> <01> <0393>
2061<09> <0A> <03A8>
2062<21> <26> <0021>
2063<28> <5F> <0028>
2064<61> <7E> <0061>
2065endbfrange
206632 beginbfchar
2067<02> <0398>
2068<03> <039B>
2069<04> <039E>
2070<05> <03A0>
2071<06> <03A3>
2072<07> <03D2>
2073<08> <03A6>
2074<0B> <2191>
2075<0C> <2193>
2076<0D> <0027>
2077<0E> <00A1>
2078<0F> <00BF>
2079<10> <0131>
2080<11> <0237>
2081<12> <0060>
2082<13> <00B4>
2083<14> <02C7>
2084<15> <02D8>
2085<16> <00AF>
2086<17> <02DA>
2087<18> <00B8>
2088<19> <00DF>
2089<1A> <00E6>
2090<1B> <0153>
2091<1C> <00F8>
2092<1D> <00C6>
2093<1E> <0152>
2094<1F> <00D8>
2095<20> <2423>
2096<27> <2019>
2097<60> <2018>
2098<7F> <00A8>
2099endbfchar
2100endcmap
2101CMapName currentdict /CMap defineresource pop
2102end
2103end
2104%%EndResource
2105%%EOF
2106    }\endgroup
2107  \expandafter\edef\csname cmapOT1TT\endcsname#1{%
2108    \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
2109  }%
2110\fi\fi
2111
2112
2113% Set the font macro #1 to the font named \fontprefix#2.
2114% #3 is the font's design size, #4 is a scale factor, #5 is the CMap
2115% encoding (only OT1, OT1IT and OT1TT are allowed, or empty to omit).
2116% Example:
2117% #1 = \textrm
2118% #2 = \rmshape
2119% #3 = 10
2120% #4 = \mainmagstep
2121% #5 = OT1
2122%
2123\def\setfont#1#2#3#4#5{%
2124  \font#1=\fontprefix#2#3 scaled #4
2125  \csname cmap#5\endcsname#1%
2126}
2127% This is what gets called when #5 of \setfont is empty.
2128\let\cmap\gobble
2129%
2130% (end of cmaps)
2131
2132% Use cm as the default font prefix.
2133% To specify the font prefix, you must define \fontprefix
2134% before you read in texinfo.tex.
2135\ifx\fontprefix\thisisundefined
2136\def\fontprefix{cm}
2137\fi
2138% Support font families that don't use the same naming scheme as CM.
2139\def\rmshape{r}
2140\def\rmbshape{bx}               % where the normal face is bold
2141\def\bfshape{b}
2142\def\bxshape{bx}
2143\def\ttshape{tt}
2144\def\ttbshape{tt}
2145\def\ttslshape{sltt}
2146\def\itshape{ti}
2147\def\itbshape{bxti}
2148\def\slshape{sl}
2149\def\slbshape{bxsl}
2150\def\sfshape{ss}
2151\def\sfbshape{ss}
2152\def\scshape{csc}
2153\def\scbshape{csc}
2154
2155% Definitions for a main text size of 11pt.  (The default in Texinfo.)
2156%
2157\def\definetextfontsizexi{%
2158% Text fonts (11.2pt, magstep1).
2159\def\textnominalsize{11pt}
2160\edef\mainmagstep{\magstephalf}
2161\setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2162\setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2163\setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2164\setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2165\setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2166\setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2167\setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2168\setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2169\font\texti=cmmi10 scaled \mainmagstep
2170\font\textsy=cmsy10 scaled \mainmagstep
2171\def\textecsize{1095}
2172
2173% A few fonts for @defun names and args.
2174\setfont\defbf\bfshape{10}{\magstep1}{OT1}
2175\setfont\deftt\ttshape{10}{\magstep1}{OT1TT}
2176\setfont\defsl\slshape{10}{\magstep1}{OT1TT}
2177\setfont\defttsl\ttslshape{10}{\magstep1}{OT1TT}
2178\def\df{\let\ttfont=\deftt \let\bffont = \defbf
2179\let\ttslfont=\defttsl \let\slfont=\defsl \bf}
2180
2181% Fonts for indices, footnotes, small examples (9pt).
2182\def\smallnominalsize{9pt}
2183\setfont\smallrm\rmshape{9}{1000}{OT1}
2184\setfont\smalltt\ttshape{9}{1000}{OT1TT}
2185\setfont\smallbf\bfshape{10}{900}{OT1}
2186\setfont\smallit\itshape{9}{1000}{OT1IT}
2187\setfont\smallsl\slshape{9}{1000}{OT1}
2188\setfont\smallsf\sfshape{9}{1000}{OT1}
2189\setfont\smallsc\scshape{10}{900}{OT1}
2190\setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2191\font\smalli=cmmi9
2192\font\smallsy=cmsy9
2193\def\smallecsize{0900}
2194
2195% Fonts for small examples (8pt).
2196\def\smallernominalsize{8pt}
2197\setfont\smallerrm\rmshape{8}{1000}{OT1}
2198\setfont\smallertt\ttshape{8}{1000}{OT1TT}
2199\setfont\smallerbf\bfshape{10}{800}{OT1}
2200\setfont\smallerit\itshape{8}{1000}{OT1IT}
2201\setfont\smallersl\slshape{8}{1000}{OT1}
2202\setfont\smallersf\sfshape{8}{1000}{OT1}
2203\setfont\smallersc\scshape{10}{800}{OT1}
2204\setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2205\font\smalleri=cmmi8
2206\font\smallersy=cmsy8
2207\def\smallerecsize{0800}
2208
2209% Fonts for math mode superscripts (7pt).
2210\def\sevennominalsize{7pt}
2211\setfont\sevenrm\rmshape{7}{1000}{OT1}
2212\setfont\seventt\ttshape{10}{700}{OT1TT}
2213\setfont\sevenbf\bfshape{10}{700}{OT1}
2214\setfont\sevenit\itshape{7}{1000}{OT1IT}
2215\setfont\sevensl\slshape{10}{700}{OT1}
2216\setfont\sevensf\sfshape{10}{700}{OT1}
2217\setfont\sevensc\scshape{10}{700}{OT1}
2218\setfont\seventtsl\ttslshape{10}{700}{OT1TT}
2219\font\seveni=cmmi7
2220\font\sevensy=cmsy7
2221\def\sevenecsize{0700}
2222
2223% Fonts for title page (20.4pt):
2224\def\titlenominalsize{20pt}
2225\setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2226\setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2227\setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2228\setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2229\setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2230\setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2231\let\titlebf=\titlerm
2232\setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2233\font\titlei=cmmi12 scaled \magstep3
2234\font\titlesy=cmsy10 scaled \magstep4
2235\def\titleecsize{2074}
2236
2237% Chapter (and unnumbered) fonts (17.28pt).
2238\def\chapnominalsize{17pt}
2239\setfont\chaprm\rmbshape{12}{\magstep2}{OT1}
2240\setfont\chapit\itbshape{10}{\magstep3}{OT1IT}
2241\setfont\chapsl\slbshape{10}{\magstep3}{OT1}
2242\setfont\chaptt\ttbshape{12}{\magstep2}{OT1TT}
2243\setfont\chapttsl\ttslshape{10}{\magstep3}{OT1TT}
2244\setfont\chapsf\sfbshape{17}{1000}{OT1}
2245\let\chapbf=\chaprm
2246\setfont\chapsc\scbshape{10}{\magstep3}{OT1}
2247\font\chapi=cmmi12 scaled \magstep2
2248\font\chapsy=cmsy10 scaled \magstep3
2249\def\chapecsize{1728}
2250
2251% Section fonts (14.4pt).
2252\def\secnominalsize{14pt}
2253\setfont\secrm\rmbshape{12}{\magstep1}{OT1}
2254\setfont\secrmnotbold\rmshape{12}{\magstep1}{OT1}
2255\setfont\secit\itbshape{10}{\magstep2}{OT1IT}
2256\setfont\secsl\slbshape{10}{\magstep2}{OT1}
2257\setfont\sectt\ttbshape{12}{\magstep1}{OT1TT}
2258\setfont\secttsl\ttslshape{10}{\magstep2}{OT1TT}
2259\setfont\secsf\sfbshape{12}{\magstep1}{OT1}
2260\let\secbf\secrm
2261\setfont\secsc\scbshape{10}{\magstep2}{OT1}
2262\font\seci=cmmi12 scaled \magstep1
2263\font\secsy=cmsy10 scaled \magstep2
2264\def\sececsize{1440}
2265
2266% Subsection fonts (13.15pt).
2267\def\ssecnominalsize{13pt}
2268\setfont\ssecrm\rmbshape{12}{\magstephalf}{OT1}
2269\setfont\ssecit\itbshape{10}{1315}{OT1IT}
2270\setfont\ssecsl\slbshape{10}{1315}{OT1}
2271\setfont\ssectt\ttbshape{12}{\magstephalf}{OT1TT}
2272\setfont\ssecttsl\ttslshape{10}{1315}{OT1TT}
2273\setfont\ssecsf\sfbshape{12}{\magstephalf}{OT1}
2274\let\ssecbf\ssecrm
2275\setfont\ssecsc\scbshape{10}{1315}{OT1}
2276\font\sseci=cmmi12 scaled \magstephalf
2277\font\ssecsy=cmsy10 scaled 1315
2278\def\ssececsize{1200}
2279
2280% Reduced fonts for @acronym in text (10pt).
2281\def\reducednominalsize{10pt}
2282\setfont\reducedrm\rmshape{10}{1000}{OT1}
2283\setfont\reducedtt\ttshape{10}{1000}{OT1TT}
2284\setfont\reducedbf\bfshape{10}{1000}{OT1}
2285\setfont\reducedit\itshape{10}{1000}{OT1IT}
2286\setfont\reducedsl\slshape{10}{1000}{OT1}
2287\setfont\reducedsf\sfshape{10}{1000}{OT1}
2288\setfont\reducedsc\scshape{10}{1000}{OT1}
2289\setfont\reducedttsl\ttslshape{10}{1000}{OT1TT}
2290\font\reducedi=cmmi10
2291\font\reducedsy=cmsy10
2292\def\reducedecsize{1000}
2293
2294\textleading = 13.2pt % line spacing for 11pt CM
2295\textfonts            % reset the current fonts
2296\rm
2297} % end of 11pt text font size definitions, \definetextfontsizexi
2298
2299
2300% Definitions to make the main text be 10pt Computer Modern, with
2301% section, chapter, etc., sizes following suit.  This is for the GNU
2302% Press printing of the Emacs 22 manual.  Maybe other manuals in the
2303% future.  Used with @smallbook, which sets the leading to 12pt.
2304%
2305\def\definetextfontsizex{%
2306% Text fonts (10pt).
2307\def\textnominalsize{10pt}
2308\edef\mainmagstep{1000}
2309\setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2310\setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2311\setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2312\setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2313\setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2314\setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2315\setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2316\setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2317\font\texti=cmmi10 scaled \mainmagstep
2318\font\textsy=cmsy10 scaled \mainmagstep
2319\def\textecsize{1000}
2320
2321% A few fonts for @defun names and args.
2322\setfont\defbf\bfshape{10}{\magstephalf}{OT1}
2323\setfont\deftt\ttshape{10}{\magstephalf}{OT1TT}
2324\setfont\defsl\slshape{10}{\magstephalf}{OT1TT}
2325\setfont\defttsl\ttslshape{10}{\magstephalf}{OT1TT}
2326\def\df{\let\ttfont=\deftt \let\bffont = \defbf
2327\let\slfont=\defsl \let\ttslfont=\defttsl \bf}
2328
2329% Fonts for indices, footnotes, small examples (9pt).
2330\def\smallnominalsize{9pt}
2331\setfont\smallrm\rmshape{9}{1000}{OT1}
2332\setfont\smalltt\ttshape{9}{1000}{OT1TT}
2333\setfont\smallbf\bfshape{10}{900}{OT1}
2334\setfont\smallit\itshape{9}{1000}{OT1IT}
2335\setfont\smallsl\slshape{9}{1000}{OT1}
2336\setfont\smallsf\sfshape{9}{1000}{OT1}
2337\setfont\smallsc\scshape{10}{900}{OT1}
2338\setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2339\font\smalli=cmmi9
2340\font\smallsy=cmsy9
2341\def\smallecsize{0900}
2342
2343% Fonts for small examples (8pt).
2344\def\smallernominalsize{8pt}
2345\setfont\smallerrm\rmshape{8}{1000}{OT1}
2346\setfont\smallertt\ttshape{8}{1000}{OT1TT}
2347\setfont\smallerbf\bfshape{10}{800}{OT1}
2348\setfont\smallerit\itshape{8}{1000}{OT1IT}
2349\setfont\smallersl\slshape{8}{1000}{OT1}
2350\setfont\smallersf\sfshape{8}{1000}{OT1}
2351\setfont\smallersc\scshape{10}{800}{OT1}
2352\setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2353\font\smalleri=cmmi8
2354\font\smallersy=cmsy8
2355\def\smallerecsize{0800}
2356
2357% Fonts for math mode superscripts (7pt).
2358\def\sevennominalsize{7pt}
2359\setfont\sevenrm\rmshape{7}{1000}{OT1}
2360\setfont\seventt\ttshape{10}{700}{OT1TT}
2361\setfont\sevenbf\bfshape{10}{700}{OT1}
2362\setfont\sevenit\itshape{7}{1000}{OT1IT}
2363\setfont\sevensl\slshape{10}{700}{OT1}
2364\setfont\sevensf\sfshape{10}{700}{OT1}
2365\setfont\sevensc\scshape{10}{700}{OT1}
2366\setfont\seventtsl\ttslshape{10}{700}{OT1TT}
2367\font\seveni=cmmi7
2368\font\sevensy=cmsy7
2369\def\sevenecsize{0700}
2370
2371% Fonts for title page (20.4pt):
2372\def\titlenominalsize{20pt}
2373\setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2374\setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2375\setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2376\setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2377\setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2378\setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2379\let\titlebf=\titlerm
2380\setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2381\font\titlei=cmmi12 scaled \magstep3
2382\font\titlesy=cmsy10 scaled \magstep4
2383\def\titleecsize{2074}
2384
2385% Chapter fonts (14.4pt).
2386\def\chapnominalsize{14pt}
2387\setfont\chaprm\rmbshape{12}{\magstep1}{OT1}
2388\setfont\chapit\itbshape{10}{\magstep2}{OT1IT}
2389\setfont\chapsl\slbshape{10}{\magstep2}{OT1}
2390\setfont\chaptt\ttbshape{12}{\magstep1}{OT1TT}
2391\setfont\chapttsl\ttslshape{10}{\magstep2}{OT1TT}
2392\setfont\chapsf\sfbshape{12}{\magstep1}{OT1}
2393\let\chapbf\chaprm
2394\setfont\chapsc\scbshape{10}{\magstep2}{OT1}
2395\font\chapi=cmmi12 scaled \magstep1
2396\font\chapsy=cmsy10 scaled \magstep2
2397\def\chapecsize{1440}
2398
2399% Section fonts (12pt).
2400\def\secnominalsize{12pt}
2401\setfont\secrm\rmbshape{12}{1000}{OT1}
2402\setfont\secit\itbshape{10}{\magstep1}{OT1IT}
2403\setfont\secsl\slbshape{10}{\magstep1}{OT1}
2404\setfont\sectt\ttbshape{12}{1000}{OT1TT}
2405\setfont\secttsl\ttslshape{10}{\magstep1}{OT1TT}
2406\setfont\secsf\sfbshape{12}{1000}{OT1}
2407\let\secbf\secrm
2408\setfont\secsc\scbshape{10}{\magstep1}{OT1}
2409\font\seci=cmmi12
2410\font\secsy=cmsy10 scaled \magstep1
2411\def\sececsize{1200}
2412
2413% Subsection fonts (10pt).
2414\def\ssecnominalsize{10pt}
2415\setfont\ssecrm\rmbshape{10}{1000}{OT1}
2416\setfont\ssecit\itbshape{10}{1000}{OT1IT}
2417\setfont\ssecsl\slbshape{10}{1000}{OT1}
2418\setfont\ssectt\ttbshape{10}{1000}{OT1TT}
2419\setfont\ssecttsl\ttslshape{10}{1000}{OT1TT}
2420\setfont\ssecsf\sfbshape{10}{1000}{OT1}
2421\let\ssecbf\ssecrm
2422\setfont\ssecsc\scbshape{10}{1000}{OT1}
2423\font\sseci=cmmi10
2424\font\ssecsy=cmsy10
2425\def\ssececsize{1000}
2426
2427% Reduced fonts for @acronym in text (9pt).
2428\def\reducednominalsize{9pt}
2429\setfont\reducedrm\rmshape{9}{1000}{OT1}
2430\setfont\reducedtt\ttshape{9}{1000}{OT1TT}
2431\setfont\reducedbf\bfshape{10}{900}{OT1}
2432\setfont\reducedit\itshape{9}{1000}{OT1IT}
2433\setfont\reducedsl\slshape{9}{1000}{OT1}
2434\setfont\reducedsf\sfshape{9}{1000}{OT1}
2435\setfont\reducedsc\scshape{10}{900}{OT1}
2436\setfont\reducedttsl\ttslshape{10}{900}{OT1TT}
2437\font\reducedi=cmmi9
2438\font\reducedsy=cmsy9
2439\def\reducedecsize{0900}
2440
2441\divide\parskip by 2  % reduce space between paragraphs
2442\textleading = 12pt   % line spacing for 10pt CM
2443\textfonts            % reset the current fonts
2444\rm
2445} % end of 10pt text font size definitions, \definetextfontsizex
2446
2447% Fonts for short table of contents.
2448\setfont\shortcontrm\rmshape{12}{1000}{OT1}
2449\setfont\shortcontbf\bfshape{10}{\magstep1}{OT1}  % no cmb12
2450\setfont\shortcontsl\slshape{12}{1000}{OT1}
2451\setfont\shortconttt\ttshape{12}{1000}{OT1TT}
2452
2453
2454% We provide the user-level command
2455%   @fonttextsize 10
2456% (or 11) to redefine the text font size.  pt is assumed.
2457%
2458\def\xiword{11}
2459\def\xword{10}
2460\def\xwordpt{10pt}
2461%
2462\parseargdef\fonttextsize{%
2463  \def\textsizearg{#1}%
2464  %\wlog{doing @fonttextsize \textsizearg}%
2465  %
2466  % Set \globaldefs so that documents can use this inside @tex, since
2467  % makeinfo 4.8 does not support it, but we need it nonetheless.
2468  %
2469 \begingroup \globaldefs=1
2470  \ifx\textsizearg\xword \definetextfontsizex
2471  \else \ifx\textsizearg\xiword \definetextfontsizexi
2472  \else
2473    \errhelp=\EMsimple
2474    \errmessage{@fonttextsize only supports `10' or `11', not `\textsizearg'}
2475  \fi\fi
2476 \endgroup
2477}
2478
2479%
2480% Change the current font style to #1, remembering it in \curfontstyle.
2481% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
2482% italics, not bold italics.
2483%
2484\def\setfontstyle#1{%
2485  \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
2486  \csname #1font\endcsname  % change the current font
2487}
2488
2489\def\rm{\fam=0 \setfontstyle{rm}}
2490\def\it{\fam=\itfam \setfontstyle{it}}
2491\def\sl{\fam=\slfam \setfontstyle{sl}}
2492\def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf}
2493\def\tt{\fam=\ttfam \setfontstyle{tt}}
2494
2495% Texinfo sort of supports the sans serif font style, which plain TeX does not.
2496% So we set up a \sf.
2497\newfam\sffam
2498\def\sf{\fam=\sffam \setfontstyle{sf}}
2499
2500% We don't need math for this font style.
2501\def\ttsl{\setfontstyle{ttsl}}
2502
2503
2504% In order for the font changes to affect most math symbols and letters,
2505% we have to define the \textfont of the standard families.
2506% We don't bother to reset \scriptscriptfont; awaiting user need.
2507%
2508\def\resetmathfonts{%
2509  \textfont0=\rmfont \textfont1=\ifont \textfont2=\syfont
2510  \textfont\itfam=\itfont \textfont\slfam=\slfont \textfont\bffam=\bffont
2511  \textfont\ttfam=\ttfont \textfont\sffam=\sffont
2512  %
2513  % Fonts for superscript.  Note that the 7pt fonts are used regardless
2514  % of the current font size.
2515  \scriptfont0=\sevenrm \scriptfont1=\seveni \scriptfont2=\sevensy
2516  \scriptfont\itfam=\sevenit \scriptfont\slfam=\sevensl
2517  \scriptfont\bffam=\sevenbf \scriptfont\ttfam=\seventt
2518  \scriptfont\sffam=\sevensf
2519}
2520
2521%
2522
2523% The font-changing commands (all called \...fonts) redefine the meanings
2524% of \STYLEfont, instead of just \STYLE.  We do this because \STYLE needs
2525% to also set the current \fam for math mode.  Our \STYLE (e.g., \rm)
2526% commands hardwire \STYLEfont to set the current font.
2527%
2528% The fonts used for \ifont are for "math italics"  (\itfont is for italics
2529% in regular text).  \syfont is also used in math mode only.
2530%
2531% Each font-changing command also sets the names \lsize (one size lower)
2532% and \lllsize (three sizes lower).  These relative commands are used
2533% in, e.g., the LaTeX logo and acronyms.
2534%
2535% This all needs generalizing, badly.
2536%
2537
2538\def\assignfonts#1{%
2539  \expandafter\let\expandafter\rmfont\csname #1rm\endcsname
2540  \expandafter\let\expandafter\itfont\csname #1it\endcsname
2541  \expandafter\let\expandafter\slfont\csname #1sl\endcsname
2542  \expandafter\let\expandafter\bffont\csname #1bf\endcsname
2543  \expandafter\let\expandafter\ttfont\csname #1tt\endcsname
2544  \expandafter\let\expandafter\smallcaps\csname #1sc\endcsname
2545  \expandafter\let\expandafter\sffont  \csname #1sf\endcsname
2546  \expandafter\let\expandafter\ifont   \csname #1i\endcsname
2547  \expandafter\let\expandafter\syfont  \csname #1sy\endcsname
2548  \expandafter\let\expandafter\ttslfont\csname #1ttsl\endcsname
2549}
2550
2551\newif\ifrmisbold
2552
2553% Select smaller font size with the current style.  Used to change font size
2554% in, e.g., the LaTeX logo and acronyms.  If we are using bold fonts for
2555% normal roman text, also use bold fonts for roman text in the smaller size.
2556\def\switchtolllsize{%
2557   \expandafter\assignfonts\expandafter{\lllsize}%
2558   \ifrmisbold
2559     \let\rmfont\bffont
2560   \fi
2561   \csname\curfontstyle\endcsname
2562}%
2563
2564\def\switchtolsize{%
2565   \expandafter\assignfonts\expandafter{\lsize}%
2566   \ifrmisbold
2567     \let\rmfont\bffont
2568   \fi
2569   \csname\curfontstyle\endcsname
2570}%
2571
2572\def\definefontsetatsize#1#2#3#4#5{%
2573\expandafter\def\csname #1fonts\endcsname{%
2574  \def\curfontsize{#1}%
2575  \def\lsize{#2}\def\lllsize{#3}%
2576  \csname rmisbold#5\endcsname
2577  \assignfonts{#1}%
2578  \resetmathfonts
2579  \setleading{#4}%
2580}}
2581
2582\definefontsetatsize{text}   {reduced}{smaller}{\textleading}{false}
2583\definefontsetatsize{title}  {chap}   {subsec} {27pt}  {true}
2584\definefontsetatsize{chap}   {sec}    {text}   {19pt}  {true}
2585\definefontsetatsize{sec}    {subsec} {reduced}{17pt}  {true}
2586\definefontsetatsize{ssec}   {text}   {small}  {15pt}  {true}
2587\definefontsetatsize{reduced}{small}  {smaller}{10.5pt}{false}
2588\definefontsetatsize{small}  {smaller}{smaller}{10.5pt}{false}
2589\definefontsetatsize{smaller}{smaller}{smaller}{9.5pt} {false}
2590
2591\def\titlefont#1{{\titlefonts\rm #1}}
2592\let\subsecfonts = \ssecfonts
2593\let\subsubsecfonts = \ssecfonts
2594
2595% Define these just so they can be easily changed for other fonts.
2596\def\angleleft{$\langle$}
2597\def\angleright{$\rangle$}
2598
2599% Set the fonts to use with the @small... environments.
2600\let\smallexamplefonts = \smallfonts
2601
2602% About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
2603% can fit this many characters:
2604%   8.5x11=86   smallbook=72  a4=90  a5=69
2605% If we use \scriptfonts (8pt), then we can fit this many characters:
2606%   8.5x11=90+  smallbook=80  a4=90+  a5=77
2607% For me, subjectively, the few extra characters that fit aren't worth
2608% the additional smallness of 8pt.  So I'm making the default 9pt.
2609%
2610% By the way, for comparison, here's what fits with @example (10pt):
2611%   8.5x11=71  smallbook=60  a4=75  a5=58
2612% --karl, 24jan03.
2613
2614% Set up the default fonts, so we can use them for creating boxes.
2615%
2616\definetextfontsizexi
2617
2618
2619\message{markup,}
2620
2621% Check if we are currently using a typewriter font.  Since all the
2622% Computer Modern typewriter fonts have zero interword stretch (and
2623% shrink), and it is reasonable to expect all typewriter fonts to have
2624% this property, we can check that font parameter.
2625%
2626\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
2627
2628% Markup style infrastructure.  \defmarkupstylesetup\INITMACRO will
2629% define and register \INITMACRO to be called on markup style changes.
2630% \INITMACRO can check \currentmarkupstyle for the innermost
2631% style.
2632
2633\let\currentmarkupstyle\empty
2634
2635\def\setupmarkupstyle#1{%
2636  \def\currentmarkupstyle{#1}%
2637  \markupstylesetup
2638}
2639
2640\let\markupstylesetup\empty
2641
2642\def\defmarkupstylesetup#1{%
2643  \expandafter\def\expandafter\markupstylesetup
2644    \expandafter{\markupstylesetup #1}%
2645  \def#1%
2646}
2647
2648% Markup style setup for left and right quotes.
2649\defmarkupstylesetup\markupsetuplq{%
2650  \expandafter\let\expandafter \temp
2651    \csname markupsetuplq\currentmarkupstyle\endcsname
2652  \ifx\temp\relax \markupsetuplqdefault \else \temp \fi
2653}
2654
2655\defmarkupstylesetup\markupsetuprq{%
2656  \expandafter\let\expandafter \temp
2657    \csname markupsetuprq\currentmarkupstyle\endcsname
2658  \ifx\temp\relax \markupsetuprqdefault \else \temp \fi
2659}
2660
2661{
2662\catcode`\'=\active
2663\catcode`\`=\active
2664
2665\gdef\markupsetuplqdefault{\let`\lq}
2666\gdef\markupsetuprqdefault{\let'\rq}
2667
2668\gdef\markupsetcodequoteleft{\let`\codequoteleft}
2669\gdef\markupsetcodequoteright{\let'\codequoteright}
2670}
2671
2672\let\markupsetuplqcode \markupsetcodequoteleft
2673\let\markupsetuprqcode \markupsetcodequoteright
2674%
2675\let\markupsetuplqexample \markupsetcodequoteleft
2676\let\markupsetuprqexample \markupsetcodequoteright
2677%
2678\let\markupsetuplqkbd     \markupsetcodequoteleft
2679\let\markupsetuprqkbd     \markupsetcodequoteright
2680%
2681\let\markupsetuplqsamp \markupsetcodequoteleft
2682\let\markupsetuprqsamp \markupsetcodequoteright
2683%
2684\let\markupsetuplqverb \markupsetcodequoteleft
2685\let\markupsetuprqverb \markupsetcodequoteright
2686%
2687\let\markupsetuplqverbatim \markupsetcodequoteleft
2688\let\markupsetuprqverbatim \markupsetcodequoteright
2689
2690% Allow an option to not use regular directed right quote/apostrophe
2691% (char 0x27), but instead the undirected quote from cmtt (char 0x0d).
2692% The undirected quote is ugly, so don't make it the default, but it
2693% works for pasting with more pdf viewers (at least evince), the
2694% lilypond developers report.  xpdf does work with the regular 0x27.
2695%
2696\def\codequoteright{%
2697  \ifmonospace
2698    \expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax
2699      \expandafter\ifx\csname SETcodequoteundirected\endcsname\relax
2700        '%
2701      \else \char'15 \fi
2702    \else \char'15 \fi
2703   \else
2704     '%
2705   \fi
2706}
2707%
2708% and a similar option for the left quote char vs. a grave accent.
2709% Modern fonts display ASCII 0x60 as a grave accent, so some people like
2710% the code environments to do likewise.
2711%
2712\def\codequoteleft{%
2713  \ifmonospace
2714    \expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax
2715      \expandafter\ifx\csname SETcodequotebacktick\endcsname\relax
2716        % [Knuth] pp. 380,381,391
2717        % \relax disables Spanish ligatures ?` and !` of \tt font.
2718        \relax`%
2719      \else \char'22 \fi
2720    \else \char'22 \fi
2721   \else
2722     \relax`%
2723   \fi
2724}
2725
2726% Commands to set the quote options.
2727%
2728\parseargdef\codequoteundirected{%
2729  \def\temp{#1}%
2730  \ifx\temp\onword
2731    \expandafter\let\csname SETtxicodequoteundirected\endcsname
2732      = t%
2733  \else\ifx\temp\offword
2734    \expandafter\let\csname SETtxicodequoteundirected\endcsname
2735      = \relax
2736  \else
2737    \errhelp = \EMsimple
2738    \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}%
2739  \fi\fi
2740}
2741%
2742\parseargdef\codequotebacktick{%
2743  \def\temp{#1}%
2744  \ifx\temp\onword
2745    \expandafter\let\csname SETtxicodequotebacktick\endcsname
2746      = t%
2747  \else\ifx\temp\offword
2748    \expandafter\let\csname SETtxicodequotebacktick\endcsname
2749      = \relax
2750  \else
2751    \errhelp = \EMsimple
2752    \errmessage{Unknown @codequotebacktick value `\temp', must be on|off}%
2753  \fi\fi
2754}
2755
2756% [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font.
2757\def\noligaturesquoteleft{\relax\lq}
2758
2759% Count depth in font-changes, for error checks
2760\newcount\fontdepth \fontdepth=0
2761
2762% Font commands.
2763
2764% #1 is the font command (\sl or \it), #2 is the text to slant.
2765% If we are in a monospaced environment, however, 1) always use \ttsl,
2766% and 2) do not add an italic correction.
2767\def\dosmartslant#1#2{%
2768  \ifusingtt
2769    {{\ttsl #2}\let\next=\relax}%
2770    {\def\next{{#1#2}\futurelet\next\smartitaliccorrection}}%
2771  \next
2772}
2773\def\smartslanted{\dosmartslant\sl}
2774\def\smartitalic{\dosmartslant\it}
2775
2776% Output an italic correction unless \next (presumed to be the following
2777% character) is such as not to need one.
2778\def\smartitaliccorrection{%
2779  \ifx\next,%
2780  \else\ifx\next-%
2781  \else\ifx\next.%
2782  \else\ifx\next\.%
2783  \else\ifx\next\comma%
2784  \else\ptexslash
2785  \fi\fi\fi\fi\fi
2786  \aftersmartic
2787}
2788
2789% Unconditional use \ttsl, and no ic.  @var is set to this for defuns.
2790\def\ttslanted#1{{\ttsl #1}}
2791
2792% @cite is like \smartslanted except unconditionally use \sl.  We never want
2793% ttsl for book titles, do we?
2794\def\cite#1{{\sl #1}\futurelet\next\smartitaliccorrection}
2795
2796\def\aftersmartic{}
2797\def\var#1{%
2798  \let\saveaftersmartic = \aftersmartic
2799  \def\aftersmartic{\null\let\aftersmartic=\saveaftersmartic}%
2800  \smartslanted{#1}%
2801}
2802
2803\let\i=\smartitalic
2804\let\slanted=\smartslanted
2805\let\dfn=\smartslanted
2806\let\emph=\smartitalic
2807
2808% Explicit font changes: @r, @sc, undocumented @ii.
2809\def\r#1{{\rm #1}}              % roman font
2810\def\sc#1{{\smallcaps#1}}       % smallcaps font
2811\def\ii#1{{\it #1}}             % italic font
2812
2813% @b, explicit bold.  Also @strong.
2814\def\b#1{{\bf #1}}
2815\let\strong=\b
2816
2817% @sansserif, explicit sans.
2818\def\sansserif#1{{\sf #1}}
2819
2820% We can't just use \exhyphenpenalty, because that only has effect at
2821% the end of a paragraph.  Restore normal hyphenation at the end of the
2822% group within which \nohyphenation is presumably called.
2823%
2824\def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
2825\def\restorehyphenation{\hyphenchar\font = `- }
2826
2827% Set sfcode to normal for the chars that usually have another value.
2828% Can't use plain's \frenchspacing because it uses the `\x notation, and
2829% sometimes \x has an active definition that messes things up.
2830%
2831\catcode`@=11
2832  \def\plainfrenchspacing{%
2833    \sfcode`\.=\@m \sfcode`\?=\@m \sfcode`\!=\@m
2834    \sfcode`\:=\@m \sfcode`\;=\@m \sfcode`\,=\@m
2835    \def\endofsentencespacefactor{1000}% for @. and friends
2836  }
2837  \def\plainnonfrenchspacing{%
2838    \sfcode`\.3000\sfcode`\?3000\sfcode`\!3000
2839    \sfcode`\:2000\sfcode`\;1500\sfcode`\,1250
2840    \def\endofsentencespacefactor{3000}% for @. and friends
2841  }
2842\catcode`@=\other
2843\def\endofsentencespacefactor{3000}% default
2844
2845% @t, explicit typewriter.
2846\def\t#1{%
2847  {\tt \rawbackslash \plainfrenchspacing #1}%
2848  \null
2849}
2850
2851% @samp.
2852\def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}}
2853
2854% @indicateurl is \samp, that is, with quotes.
2855\let\indicateurl=\samp
2856
2857% @code (and similar) prints in typewriter, but with spaces the same
2858% size as normal in the surrounding text, without hyphenation, etc.
2859% This is a subroutine for that.
2860\def\tclose#1{%
2861  {%
2862    % Change normal interword space to be same as for the current font.
2863    \spaceskip = \fontdimen2\font
2864    %
2865    % Switch to typewriter.
2866    \tt
2867    %
2868    % But `\ ' produces the large typewriter interword space.
2869    \def\ {{\spaceskip = 0pt{} }}%
2870    %
2871    % Turn off hyphenation.
2872    \nohyphenation
2873    %
2874    \rawbackslash
2875    \plainfrenchspacing
2876    #1%
2877  }%
2878  \null % reset spacefactor to 1000
2879}
2880
2881% We *must* turn on hyphenation at `-' and `_' in @code.
2882% (But see \codedashfinish below.)
2883% Otherwise, it is too hard to avoid overfull hboxes
2884% in the Emacs manual, the Library manual, etc.
2885%
2886% Unfortunately, TeX uses one parameter (\hyphenchar) to control
2887% both hyphenation at - and hyphenation within words.
2888% We must therefore turn them both off (\tclose does that)
2889% and arrange explicitly to hyphenate at a dash. -- rms.
2890{
2891  \catcode`\-=\active \catcode`\_=\active
2892  \catcode`\'=\active \catcode`\`=\active
2893  \global\let'=\rq \global\let`=\lq  % default definitions
2894  %
2895  \global\def\code{\begingroup
2896    \setupmarkupstyle{code}%
2897    % The following should really be moved into \setupmarkupstyle handlers.
2898    \catcode\dashChar=\active  \catcode\underChar=\active
2899    \ifallowcodebreaks
2900     \let-\codedash
2901     \let_\codeunder
2902    \else
2903     \let-\normaldash
2904     \let_\realunder
2905    \fi
2906    % Given -foo (with a single dash), we do not want to allow a break
2907    % after the hyphen.
2908    \global\let\codedashprev=\codedash
2909    %
2910    \codex
2911  }
2912  %
2913  \gdef\codedash{\futurelet\next\codedashfinish}
2914  \gdef\codedashfinish{%
2915    \normaldash % always output the dash character itself.
2916    %
2917    % Now, output a discretionary to allow a line break, unless
2918    % (a) the next character is a -, or
2919    % (b) the preceding character is a -.
2920    % E.g., given --posix, we do not want to allow a break after either -.
2921    % Given --foo-bar, we do want to allow a break between the - and the b.
2922    \ifx\next\codedash \else
2923      \ifx\codedashprev\codedash
2924      \else \discretionary{}{}{}\fi
2925    \fi
2926    % we need the space after the = for the case when \next itself is a
2927    % space token; it would get swallowed otherwise.  As in @code{- a}.
2928    \global\let\codedashprev= \next
2929  }
2930}
2931\def\normaldash{-}
2932%
2933\def\codex #1{\tclose{#1}\endgroup}
2934
2935\def\codeunder{%
2936  % this is all so @math{@code{var_name}+1} can work.  In math mode, _
2937  % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
2938  % will therefore expand the active definition of _, which is us
2939  % (inside @code that is), therefore an endless loop.
2940  \ifusingtt{\ifmmode
2941               \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
2942             \else\normalunderscore \fi
2943             \discretionary{}{}{}}%
2944            {\_}%
2945}
2946
2947% An additional complication: the above will allow breaks after, e.g.,
2948% each of the four underscores in __typeof__.  This is bad.
2949% @allowcodebreaks provides a document-level way to turn breaking at -
2950% and _ on and off.
2951%
2952\newif\ifallowcodebreaks  \allowcodebreakstrue
2953
2954\def\keywordtrue{true}
2955\def\keywordfalse{false}
2956
2957\parseargdef\allowcodebreaks{%
2958  \def\txiarg{#1}%
2959  \ifx\txiarg\keywordtrue
2960    \allowcodebreakstrue
2961  \else\ifx\txiarg\keywordfalse
2962    \allowcodebreaksfalse
2963  \else
2964    \errhelp = \EMsimple
2965    \errmessage{Unknown @allowcodebreaks option `\txiarg', must be true|false}%
2966  \fi\fi
2967}
2968
2969% For @command, @env, @file, @option quotes seem unnecessary,
2970% so use \code rather than \samp.
2971\let\command=\code
2972\let\env=\code
2973\let\file=\code
2974\let\option=\code
2975
2976% @uref (abbreviation for `urlref') aka @url takes an optional
2977% (comma-separated) second argument specifying the text to display and
2978% an optional third arg as text to display instead of (rather than in
2979% addition to) the url itself.  First (mandatory) arg is the url.
2980
2981% TeX-only option to allow changing PDF output to show only the second
2982% arg (if given), and not the url (which is then just the link target).
2983\newif\ifurefurlonlylink
2984
2985% The main macro is \urefbreak, which allows breaking at expected
2986% places within the url.  (There used to be another version, which
2987% didn't support automatic breaking.)
2988\def\urefbreak{\begingroup \urefcatcodes \dourefbreak}
2989\let\uref=\urefbreak
2990%
2991\def\dourefbreak#1{\urefbreakfinish #1,,,\finish}
2992\def\urefbreakfinish#1,#2,#3,#4\finish{% doesn't work in @example
2993  \unsepspaces
2994  \pdfurl{#1}%
2995  \setbox0 = \hbox{\ignorespaces #3}%
2996  \ifdim\wd0 > 0pt
2997    \unhbox0 % third arg given, show only that
2998  \else
2999    \setbox0 = \hbox{\ignorespaces #2}% look for second arg
3000    \ifdim\wd0 > 0pt
3001      \ifpdf
3002        % For pdfTeX and LuaTeX
3003        \ifurefurlonlylink
3004          % PDF plus option to not display url, show just arg
3005          \unhbox0
3006        \else
3007          % PDF, normally display both arg and url for consistency,
3008          % visibility, if the pdf is eventually used to print, etc.
3009          \unhbox0\ (\urefcode{#1})%
3010        \fi
3011      \else
3012        \ifx\XeTeXrevision\thisisundefined
3013          \unhbox0\ (\urefcode{#1})% DVI, always show arg and url
3014        \else
3015          % For XeTeX
3016          \ifurefurlonlylink
3017            % PDF plus option to not display url, show just arg
3018            \unhbox0
3019          \else
3020            % PDF, normally display both arg and url for consistency,
3021            % visibility, if the pdf is eventually used to print, etc.
3022            \unhbox0\ (\urefcode{#1})%
3023          \fi
3024        \fi
3025      \fi
3026    \else
3027      \urefcode{#1}% only url given, so show it
3028    \fi
3029  \fi
3030  \endlink
3031\endgroup}
3032
3033% Allow line breaks around only a few characters (only).
3034\def\urefcatcodes{%
3035  \catcode`\&=\active \catcode`\.=\active
3036  \catcode`\#=\active \catcode`\?=\active
3037  \catcode`\/=\active
3038}
3039{
3040  \urefcatcodes
3041  %
3042  \global\def\urefcode{\begingroup
3043    \setupmarkupstyle{code}%
3044    \urefcatcodes
3045    \let&\urefcodeamp
3046    \let.\urefcodedot
3047    \let#\urefcodehash
3048    \let?\urefcodequest
3049    \let/\urefcodeslash
3050    \codex
3051  }
3052  %
3053  % By default, they are just regular characters.
3054  \global\def&{\normalamp}
3055  \global\def.{\normaldot}
3056  \global\def#{\normalhash}
3057  \global\def?{\normalquest}
3058  \global\def/{\normalslash}
3059}
3060
3061\def\urefcodeamp{\urefprebreak \&\urefpostbreak}
3062\def\urefcodedot{\urefprebreak .\urefpostbreak}
3063\def\urefcodehash{\urefprebreak \#\urefpostbreak}
3064\def\urefcodequest{\urefprebreak ?\urefpostbreak}
3065\def\urefcodeslash{\futurelet\next\urefcodeslashfinish}
3066{
3067  \catcode`\/=\active
3068  \global\def\urefcodeslashfinish{%
3069    \urefprebreak \slashChar
3070    % Allow line break only after the final / in a sequence of
3071    % slashes, to avoid line break between the slashes in http://.
3072    \ifx\next/\else \urefpostbreak \fi
3073  }
3074}
3075
3076% By default we'll break after the special characters, but some people like to
3077% break before the special chars, so allow that.  Also allow no breaking at
3078% all, for manual control.
3079%
3080\parseargdef\urefbreakstyle{%
3081  \def\txiarg{#1}%
3082  \ifx\txiarg\wordnone
3083    \def\urefprebreak{\nobreak}\def\urefpostbreak{\nobreak}
3084  \else\ifx\txiarg\wordbefore
3085    \def\urefprebreak{\urefallowbreak}\def\urefpostbreak{\nobreak}
3086  \else\ifx\txiarg\wordafter
3087    \def\urefprebreak{\nobreak}\def\urefpostbreak{\urefallowbreak}
3088  \else
3089    \errhelp = \EMsimple
3090    \errmessage{Unknown @urefbreakstyle setting `\txiarg'}%
3091  \fi\fi\fi
3092}
3093\def\wordafter{after}
3094\def\wordbefore{before}
3095\def\wordnone{none}
3096
3097% Allow a ragged right output to aid breaking long URL's.  Putting stretch in
3098% between characters of the URL doesn't look good.
3099\def\urefallowbreak{%
3100  \hskip 0pt plus 1fil\relax
3101  \allowbreak
3102  \hskip 0pt plus -1fil\relax
3103}
3104
3105\urefbreakstyle after
3106
3107% @url synonym for @uref, since that's how everyone uses it.
3108%
3109\let\url=\uref
3110
3111% rms does not like angle brackets --karl, 17may97.
3112% So now @email is just like @uref, unless we are pdf.
3113%
3114%\def\email#1{\angleleft{\tt #1}\angleright}
3115\ifpdf
3116  \def\email#1{\doemail#1,,\finish}
3117  \def\doemail#1,#2,#3\finish{\begingroup
3118    \unsepspaces
3119    \pdfurl{mailto:#1}%
3120    \setbox0 = \hbox{\ignorespaces #2}%
3121    \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3122    \endlink
3123  \endgroup}
3124\else
3125  \ifx\XeTeXrevision\thisisundefined
3126    \let\email=\uref
3127  \else
3128    \def\email#1{\doemail#1,,\finish}
3129    \def\doemail#1,#2,#3\finish{\begingroup
3130      \unsepspaces
3131      \pdfurl{mailto:#1}%
3132      \setbox0 = \hbox{\ignorespaces #2}%
3133      \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3134      \endlink
3135    \endgroup}
3136  \fi
3137\fi
3138
3139% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
3140%   `example' (@kbd uses ttsl only inside of @example and friends),
3141%   or `code' (@kbd uses normal tty font always).
3142\parseargdef\kbdinputstyle{%
3143  \def\txiarg{#1}%
3144  \ifx\txiarg\worddistinct
3145    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
3146  \else\ifx\txiarg\wordexample
3147    \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
3148  \else\ifx\txiarg\wordcode
3149    \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
3150  \else
3151    \errhelp = \EMsimple
3152    \errmessage{Unknown @kbdinputstyle setting `\txiarg'}%
3153  \fi\fi\fi
3154}
3155\def\worddistinct{distinct}
3156\def\wordexample{example}
3157\def\wordcode{code}
3158
3159% Default is `distinct'.
3160\kbdinputstyle distinct
3161
3162% @kbd is like @code, except that if the argument is just one @key command,
3163% then @kbd has no effect.
3164\def\kbd#1{{\def\look{#1}\expandafter\kbdsub\look??\par}}
3165
3166\def\xkey{\key}
3167\def\kbdsub#1#2#3\par{%
3168  \def\one{#1}\def\three{#3}\def\threex{??}%
3169  \ifx\one\xkey\ifx\threex\three \key{#2}%
3170  \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3171  \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3172}
3173
3174% definition of @key that produces a lozenge.  Doesn't adjust to text size.
3175%\setfont\keyrm\rmshape{8}{1000}{OT1}
3176%\font\keysy=cmsy9
3177%\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
3178%  \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
3179%    \vbox{\hrule\kern-0.4pt
3180%     \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
3181%    \kern-0.4pt\hrule}%
3182%  \kern-.06em\raise0.4pt\hbox{\angleright}}}}
3183
3184% definition of @key with no lozenge.  If the current font is already
3185% monospace, don't change it; that way, we respect @kbdinputstyle.  But
3186% if it isn't monospace, then use \tt.
3187%
3188\def\key#1{{\setupmarkupstyle{key}%
3189  \nohyphenation
3190  \ifmonospace\else\tt\fi
3191  #1}\null}
3192
3193% @clicksequence{File @click{} Open ...}
3194\def\clicksequence#1{\begingroup #1\endgroup}
3195
3196% @clickstyle @arrow   (by default)
3197\parseargdef\clickstyle{\def\click{#1}}
3198\def\click{\arrow}
3199
3200% Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
3201% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
3202%
3203\def\dmn#1{\thinspace #1}
3204
3205% @acronym for "FBI", "NATO", and the like.
3206% We print this one point size smaller, since it's intended for
3207% all-uppercase.
3208%
3209\def\acronym#1{\doacronym #1,,\finish}
3210\def\doacronym#1,#2,#3\finish{%
3211  {\switchtolsize #1}%
3212  \def\temp{#2}%
3213  \ifx\temp\empty \else
3214    \space ({\unsepspaces \ignorespaces \temp \unskip})%
3215  \fi
3216  \null % reset \spacefactor=1000
3217}
3218
3219% @abbr for "Comput. J." and the like.
3220% No font change, but don't do end-of-sentence spacing.
3221%
3222\def\abbr#1{\doabbr #1,,\finish}
3223\def\doabbr#1,#2,#3\finish{%
3224  {\plainfrenchspacing #1}%
3225  \def\temp{#2}%
3226  \ifx\temp\empty \else
3227    \space ({\unsepspaces \ignorespaces \temp \unskip})%
3228  \fi
3229  \null % reset \spacefactor=1000
3230}
3231
3232% @asis just yields its argument.  Used with @table, for example.
3233%
3234\def\asis#1{#1}
3235
3236% @math outputs its argument in math mode.
3237%
3238% One complication: _ usually means subscripts, but it could also mean
3239% an actual _ character, as in @math{@var{some_variable} + 1}.  So make
3240% _ active, and distinguish by seeing if the current family is \slfam,
3241% which is what @var uses.
3242{
3243  \catcode`\_ = \active
3244  \gdef\mathunderscore{%
3245    \catcode`\_=\active
3246    \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
3247  }
3248}
3249% Another complication: we want \\ (and @\) to output a math (or tt) \.
3250% FYI, plain.tex uses \\ as a temporary control sequence (for no
3251% particular reason), but this is not advertised and we don't care.
3252%
3253% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
3254\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
3255%
3256\def\math{%
3257  \ifmmode\else % only go into math if not in math mode already
3258    \tex
3259    \mathunderscore
3260    \let\\ = \mathbackslash
3261    \mathactive
3262    % make the texinfo accent commands work in math mode
3263    \let\"=\ddot
3264    \let\'=\acute
3265    \let\==\bar
3266    \let\^=\hat
3267    \let\`=\grave
3268    \let\u=\breve
3269    \let\v=\check
3270    \let\~=\tilde
3271    \let\dotaccent=\dot
3272    % have to provide another name for sup operator
3273    \let\mathopsup=\sup
3274  $\expandafter\finishmath\fi
3275}
3276\def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
3277
3278% Some active characters (such as <) are spaced differently in math.
3279% We have to reset their definitions in case the @math was an argument
3280% to a command which sets the catcodes (such as @item or @section).
3281%
3282{
3283  \catcode`^ = \active
3284  \catcode`< = \active
3285  \catcode`> = \active
3286  \catcode`+ = \active
3287  \catcode`' = \active
3288  \gdef\mathactive{%
3289    \let^ = \ptexhat
3290    \let< = \ptexless
3291    \let> = \ptexgtr
3292    \let+ = \ptexplus
3293    \let' = \ptexquoteright
3294  }
3295}
3296
3297% for @sub and @sup, if in math mode, just do a normal sub/superscript.
3298% If in text, use math to place as sub/superscript, but switch
3299% into text mode, with smaller fonts.  This is a different font than the
3300% one used for real math sub/superscripts (8pt vs. 7pt), but let's not
3301% fix it (significant additions to font machinery) until someone notices.
3302%
3303\def\sub{\ifmmode \expandafter\sb \else \expandafter\finishsub\fi}
3304\def\finishsub#1{$\sb{\hbox{\switchtolllsize #1}}$}%
3305%
3306\def\sup{\ifmmode \expandafter\ptexsp \else \expandafter\finishsup\fi}
3307\def\finishsup#1{$\ptexsp{\hbox{\switchtolllsize #1}}$}%
3308
3309% @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}.
3310% Ignore unless FMTNAME == tex; then it is like @iftex and @tex,
3311% except specified as a normal braced arg, so no newlines to worry about.
3312%
3313\def\outfmtnametex{tex}
3314%
3315\long\def\inlinefmt#1{\doinlinefmt #1,\finish}
3316\long\def\doinlinefmt#1,#2,\finish{%
3317  \def\inlinefmtname{#1}%
3318  \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\fi
3319}
3320%
3321% @inlinefmtifelse{FMTNAME,THEN-TEXT,ELSE-TEXT} expands THEN-TEXT if
3322% FMTNAME is tex, else ELSE-TEXT.
3323\long\def\inlinefmtifelse#1{\doinlinefmtifelse #1,,,\finish}
3324\long\def\doinlinefmtifelse#1,#2,#3,#4,\finish{%
3325  \def\inlinefmtname{#1}%
3326  \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\else \ignorespaces #3\fi
3327}
3328%
3329% For raw, must switch into @tex before parsing the argument, to avoid
3330% setting catcodes prematurely.  Doing it this way means that, for
3331% example, @inlineraw{html, foo{bar} gets a parse error instead of being
3332% ignored.  But this isn't important because if people want a literal
3333% *right* brace they would have to use a command anyway, so they may as
3334% well use a command to get a left brace too.  We could re-use the
3335% delimiter character idea from \verb, but it seems like overkill.
3336%
3337\long\def\inlineraw{\tex \doinlineraw}
3338\long\def\doinlineraw#1{\doinlinerawtwo #1,\finish}
3339\def\doinlinerawtwo#1,#2,\finish{%
3340  \def\inlinerawname{#1}%
3341  \ifx\inlinerawname\outfmtnametex \ignorespaces #2\fi
3342  \endgroup % close group opened by \tex.
3343}
3344
3345% @inlineifset{VAR, TEXT} expands TEXT if VAR is @set.
3346%
3347\long\def\inlineifset#1{\doinlineifset #1,\finish}
3348\long\def\doinlineifset#1,#2,\finish{%
3349  \def\inlinevarname{#1}%
3350  \expandafter\ifx\csname SET\inlinevarname\endcsname\relax
3351  \else\ignorespaces#2\fi
3352}
3353
3354% @inlineifclear{VAR, TEXT} expands TEXT if VAR is not @set.
3355%
3356\long\def\inlineifclear#1{\doinlineifclear #1,\finish}
3357\long\def\doinlineifclear#1,#2,\finish{%
3358  \def\inlinevarname{#1}%
3359  \expandafter\ifx\csname SET\inlinevarname\endcsname\relax \ignorespaces#2\fi
3360}
3361
3362
3363\message{glyphs,}
3364% and logos.
3365
3366% @@ prints an @, as does @atchar{}.
3367\def\@{\char64 }
3368\let\atchar=\@
3369
3370% @{ @} @lbracechar{} @rbracechar{} all generate brace characters.
3371\def\lbracechar{{\ifmonospace\char123\else\ensuremath\lbrace\fi}}
3372\def\rbracechar{{\ifmonospace\char125\else\ensuremath\rbrace\fi}}
3373\let\{=\lbracechar
3374\let\}=\rbracechar
3375
3376% @comma{} to avoid , parsing problems.
3377\let\comma = ,
3378
3379% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
3380% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
3381\let\, = \ptexc
3382\let\dotaccent = \ptexdot
3383\def\ringaccent#1{{\accent23 #1}}
3384\let\tieaccent = \ptext
3385\let\ubaraccent = \ptexb
3386\let\udotaccent = \d
3387
3388% Other special characters: @questiondown @exclamdown @ordf @ordm
3389% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
3390\def\questiondown{?`}
3391\def\exclamdown{!`}
3392\def\ordf{\leavevmode\raise1ex\hbox{\switchtolllsize \underbar{a}}}
3393\def\ordm{\leavevmode\raise1ex\hbox{\switchtolllsize \underbar{o}}}
3394
3395% Dotless i and dotless j, used for accents.
3396\def\imacro{i}
3397\def\jmacro{j}
3398\def\dotless#1{%
3399  \def\temp{#1}%
3400  \ifx\temp\imacro \ifmmode\imath \else\ptexi \fi
3401  \else\ifx\temp\jmacro \ifmmode\jmath \else\j \fi
3402  \else \errmessage{@dotless can be used only with i or j}%
3403  \fi\fi
3404}
3405
3406% The \TeX{} logo, as in plain, but resetting the spacing so that a
3407% period following counts as ending a sentence.  (Idea found in latex.)
3408%
3409\edef\TeX{\TeX \spacefactor=1000 }
3410
3411% @LaTeX{} logo.  Not quite the same results as the definition in
3412% latex.ltx, since we use a different font for the raised A; it's most
3413% convenient for us to use an explicitly smaller font, rather than using
3414% the \scriptstyle font (since we don't reset \scriptstyle and
3415% \scriptscriptstyle).
3416%
3417\def\LaTeX{%
3418  L\kern-.36em
3419  {\setbox0=\hbox{T}%
3420   \vbox to \ht0{\hbox{%
3421     \ifx\textnominalsize\xwordpt
3422       % for 10pt running text, lllsize (8pt) is too small for the A in LaTeX.
3423       % Revert to plain's \scriptsize, which is 7pt.
3424       \count255=\the\fam $\fam\count255 \scriptstyle A$%
3425     \else
3426       % For 11pt, we can use our lllsize.
3427       \switchtolllsize A%
3428     \fi
3429     }%
3430     \vss
3431  }}%
3432  \kern-.15em
3433  \TeX
3434}
3435
3436% Some math mode symbols.  Define \ensuremath to switch into math mode
3437% unless we are already there.  Expansion tricks may not be needed here,
3438% but safer, and can't hurt.
3439\def\ensuremath{\ifmmode \expandafter\asis \else\expandafter\ensuredmath \fi}
3440\def\ensuredmath#1{$\relax#1$}
3441%
3442\def\bullet{\ensuremath\ptexbullet}
3443\def\geq{\ensuremath\ge}
3444\def\leq{\ensuremath\le}
3445\def\minus{\ensuremath-}
3446
3447% @dots{} outputs an ellipsis using the current font.
3448% We do .5em per period so that it has the same spacing in the cm
3449% typewriter fonts as three actual period characters; on the other hand,
3450% in other typewriter fonts three periods are wider than 1.5em.  So do
3451% whichever is larger.
3452%
3453\def\dots{%
3454  \leavevmode
3455  \setbox0=\hbox{...}% get width of three periods
3456  \ifdim\wd0 > 1.5em
3457    \dimen0 = \wd0
3458  \else
3459    \dimen0 = 1.5em
3460  \fi
3461  \hbox to \dimen0{%
3462    \hskip 0pt plus.25fil
3463    .\hskip 0pt plus1fil
3464    .\hskip 0pt plus1fil
3465    .\hskip 0pt plus.5fil
3466  }%
3467}
3468
3469% @enddots{} is an end-of-sentence ellipsis.
3470%
3471\def\enddots{%
3472  \dots
3473  \spacefactor=\endofsentencespacefactor
3474}
3475
3476% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
3477%
3478% Since these characters are used in examples, they should be an even number of
3479% \tt widths. Each \tt character is 1en, so two makes it 1em.
3480%
3481\def\point{$\star$}
3482\def\arrow{\leavevmode\raise.05ex\hbox to 1em{\hfil$\rightarrow$\hfil}}
3483\def\result{\leavevmode\raise.05ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
3484\def\expansion{\leavevmode\hbox to 1em{\hfil$\mapsto$\hfil}}
3485\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
3486\def\equiv{\leavevmode\hbox to 1em{\hfil$\ptexequiv$\hfil}}
3487
3488% The @error{} command.
3489% Adapted from the TeXbook's \boxit.
3490%
3491\newbox\errorbox
3492%
3493{\ttfont \global\dimen0 = 3em}% Width of the box.
3494\dimen2 = .55pt % Thickness of rules
3495% The text. (`r' is open on the right, `e' somewhat less so on the left.)
3496\setbox0 = \hbox{\kern-.75pt \reducedsf \putworderror\kern-1.5pt}
3497%
3498\setbox\errorbox=\hbox to \dimen0{\hfil
3499   \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
3500   \advance\hsize by -2\dimen2 % Rules.
3501   \vbox{%
3502      \hrule height\dimen2
3503      \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
3504         \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
3505         \kern3pt\vrule width\dimen2}% Space to right.
3506      \hrule height\dimen2}
3507    \hfil}
3508%
3509\def\error{\leavevmode\lower.7ex\copy\errorbox}
3510
3511% @pounds{} is a sterling sign, which Knuth put in the CM italic font.
3512%
3513\def\pounds{{\it\$}}
3514
3515% @euro{} comes from a separate font, depending on the current style.
3516% We use the free feym* fonts from the eurosym package by Henrik
3517% Theiling, which support regular, slanted, bold and bold slanted (and
3518% "outlined" (blackboard board, sort of) versions, which we don't need).
3519% It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
3520%
3521% Although only regular is the truly official Euro symbol, we ignore
3522% that.  The Euro is designed to be slightly taller than the regular
3523% font height.
3524%
3525% feymr - regular
3526% feymo - slanted
3527% feybr - bold
3528% feybo - bold slanted
3529%
3530% There is no good (free) typewriter version, to my knowledge.
3531% A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
3532% Hmm.
3533%
3534% Also doesn't work in math.  Do we need to do math with euro symbols?
3535% Hope not.
3536%
3537%
3538\def\euro{{\eurofont e}}
3539\def\eurofont{%
3540  % We set the font at each command, rather than predefining it in
3541  % \textfonts and the other font-switching commands, so that
3542  % installations which never need the symbol don't have to have the
3543  % font installed.
3544  %
3545  % There is only one designed size (nominal 10pt), so we always scale
3546  % that to the current nominal size.
3547  %
3548  % By the way, simply using "at 1em" works for cmr10 and the like, but
3549  % does not work for cmbx10 and other extended/shrunken fonts.
3550  %
3551  \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
3552  %
3553  \ifx\curfontstyle\bfstylename
3554    % bold:
3555    \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
3556  \else
3557    % regular:
3558    \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
3559  \fi
3560  \thiseurofont
3561}
3562
3563% Glyphs from the EC fonts.  We don't use \let for the aliases, because
3564% sometimes we redefine the original macro, and the alias should reflect
3565% the redefinition.
3566%
3567% Use LaTeX names for the Icelandic letters.
3568\def\DH{{\ecfont \char"D0}} % Eth
3569\def\dh{{\ecfont \char"F0}} % eth
3570\def\TH{{\ecfont \char"DE}} % Thorn
3571\def\th{{\ecfont \char"FE}} % thorn
3572%
3573\def\guillemetleft{{\ecfont \char"13}}
3574\def\guillemotleft{\guillemetleft}
3575\def\guillemetright{{\ecfont \char"14}}
3576\def\guillemotright{\guillemetright}
3577\def\guilsinglleft{{\ecfont \char"0E}}
3578\def\guilsinglright{{\ecfont \char"0F}}
3579\def\quotedblbase{{\ecfont \char"12}}
3580\def\quotesinglbase{{\ecfont \char"0D}}
3581%
3582% This positioning is not perfect (see the ogonek LaTeX package), but
3583% we have the precomposed glyphs for the most common cases.  We put the
3584% tests to use those glyphs in the single \ogonek macro so we have fewer
3585% dummy definitions to worry about for index entries, etc.
3586%
3587% ogonek is also used with other letters in Lithuanian (IOU), but using
3588% the precomposed glyphs for those is not so easy since they aren't in
3589% the same EC font.
3590\def\ogonek#1{{%
3591  \def\temp{#1}%
3592  \ifx\temp\macrocharA\Aogonek
3593  \else\ifx\temp\macrochara\aogonek
3594  \else\ifx\temp\macrocharE\Eogonek
3595  \else\ifx\temp\macrochare\eogonek
3596  \else
3597    \ecfont \setbox0=\hbox{#1}%
3598    \ifdim\ht0=1ex\accent"0C #1%
3599    \else\ooalign{\unhbox0\crcr\hidewidth\char"0C \hidewidth}%
3600    \fi
3601  \fi\fi\fi\fi
3602  }%
3603}
3604\def\Aogonek{{\ecfont \char"81}}\def\macrocharA{A}
3605\def\aogonek{{\ecfont \char"A1}}\def\macrochara{a}
3606\def\Eogonek{{\ecfont \char"86}}\def\macrocharE{E}
3607\def\eogonek{{\ecfont \char"A6}}\def\macrochare{e}
3608%
3609% Use the European Computer Modern fonts (cm-super in outline format)
3610% for non-CM glyphs.  That is ec* for regular text and tc* for the text
3611% companion symbols (LaTeX TS1 encoding).  Both are part of the ec
3612% package and follow the same conventions.
3613%
3614\def\ecfont{\etcfont{e}}
3615\def\tcfont{\etcfont{t}}
3616%
3617\def\etcfont#1{%
3618  % We can't distinguish serif/sans and italic/slanted, but this
3619  % is used for crude hacks anyway (like adding French and German
3620  % quotes to documents typeset with CM, where we lose kerning), so
3621  % hopefully nobody will notice/care.
3622  \edef\ecsize{\csname\curfontsize ecsize\endcsname}%
3623  \edef\nominalsize{\csname\curfontsize nominalsize\endcsname}%
3624  \ifmonospace
3625    % typewriter:
3626    \font\thisecfont = #1ctt\ecsize \space at \nominalsize
3627  \else
3628    \ifx\curfontstyle\bfstylename
3629      % bold:
3630      \font\thisecfont = #1cb\ifusingit{i}{x}\ecsize \space at \nominalsize
3631    \else
3632      % regular:
3633      \font\thisecfont = #1c\ifusingit{ti}{rm}\ecsize \space at \nominalsize
3634    \fi
3635  \fi
3636  \thisecfont
3637}
3638
3639% @registeredsymbol - R in a circle.  The font for the R should really
3640% be smaller yet, but lllsize is the best we can do for now.
3641% Adapted from the plain.tex definition of \copyright.
3642%
3643\def\registeredsymbol{%
3644  $^{{\ooalign{\hfil\raise.07ex\hbox{\switchtolllsize R}%
3645               \hfil\crcr\Orb}}%
3646    }$%
3647}
3648
3649% @textdegree - the normal degrees sign.
3650%
3651\def\textdegree{$^\circ$}
3652
3653% Laurent Siebenmann reports \Orb undefined with:
3654%  Textures 1.7.7 (preloaded format=plain 93.10.14)  (68K)  16 APR 2004 02:38
3655% so we'll define it if necessary.
3656%
3657\ifx\Orb\thisisundefined
3658\def\Orb{\mathhexbox20D}
3659\fi
3660
3661% Quotes.
3662\chardef\quotedblleft="5C
3663\chardef\quotedblright=`\"
3664\chardef\quoteleft=`\`
3665\chardef\quoteright=`\'
3666
3667
3668\message{page headings,}
3669
3670\newskip\titlepagetopglue \titlepagetopglue = 1.5in
3671\newskip\titlepagebottomglue \titlepagebottomglue = 2pc
3672
3673% First the title page.  Must do @settitle before @titlepage.
3674\newif\ifseenauthor
3675\newif\iffinishedtitlepage
3676
3677% @setcontentsaftertitlepage used to do an implicit @contents or
3678% @shortcontents after @end titlepage, but it is now obsolete.
3679\def\setcontentsaftertitlepage{%
3680  \errmessage{@setcontentsaftertitlepage has been removed as a Texinfo
3681              command; move your @contents command if you want the contents
3682              after the title page.}}%
3683\def\setshortcontentsaftertitlepage{%
3684  \errmessage{@setshortcontentsaftertitlepage has been removed as a Texinfo
3685              command; move your @shortcontents and @contents commands if you
3686              want the contents after the title page.}}%
3687
3688\parseargdef\shorttitlepage{%
3689  \begingroup \hbox{}\vskip 1.5in \chaprm \centerline{#1}%
3690  \endgroup\page\hbox{}\page}
3691
3692\envdef\titlepage{%
3693  % Open one extra group, as we want to close it in the middle of \Etitlepage.
3694  \begingroup
3695    \parindent=0pt \textfonts
3696    % Leave some space at the very top of the page.
3697    \vglue\titlepagetopglue
3698    % No rule at page bottom unless we print one at the top with @title.
3699    \finishedtitlepagetrue
3700    %
3701    % Most title ``pages'' are actually two pages long, with space
3702    % at the top of the second.  We don't want the ragged left on the second.
3703    \let\oldpage = \page
3704    \def\page{%
3705      \iffinishedtitlepage\else
3706	 \finishtitlepage
3707      \fi
3708      \let\page = \oldpage
3709      \page
3710      \null
3711    }%
3712}
3713
3714\def\Etitlepage{%
3715    \iffinishedtitlepage\else
3716	\finishtitlepage
3717    \fi
3718    % It is important to do the page break before ending the group,
3719    % because the headline and footline are only empty inside the group.
3720    % If we use the new definition of \page, we always get a blank page
3721    % after the title page, which we certainly don't want.
3722    \oldpage
3723  \endgroup
3724  %
3725  % Need this before the \...aftertitlepage checks so that if they are
3726  % in effect the toc pages will come out with page numbers.
3727  \HEADINGSon
3728}
3729
3730\def\finishtitlepage{%
3731  \vskip4pt \hrule height 2pt width \hsize
3732  \vskip\titlepagebottomglue
3733  \finishedtitlepagetrue
3734}
3735
3736% Settings used for typesetting titles: no hyphenation, no indentation,
3737% don't worry much about spacing, ragged right.  This should be used
3738% inside a \vbox, and fonts need to be set appropriately first. \par should
3739% be specified before the end of the \vbox, since a vbox is a group.
3740%
3741\def\raggedtitlesettings{%
3742  \rm
3743  \hyphenpenalty=10000
3744  \parindent=0pt
3745  \tolerance=5000
3746  \ptexraggedright
3747}
3748
3749% Macros to be used within @titlepage:
3750
3751\let\subtitlerm=\rmfont
3752\def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
3753
3754\parseargdef\title{%
3755  \checkenv\titlepage
3756  \vbox{\titlefonts \raggedtitlesettings #1\par}%
3757  % print a rule at the page bottom also.
3758  \finishedtitlepagefalse
3759  \vskip4pt \hrule height 4pt width \hsize \vskip4pt
3760}
3761
3762\parseargdef\subtitle{%
3763  \checkenv\titlepage
3764  {\subtitlefont \rightline{#1}}%
3765}
3766
3767% @author should come last, but may come many times.
3768% It can also be used inside @quotation.
3769%
3770\parseargdef\author{%
3771  \def\temp{\quotation}%
3772  \ifx\thisenv\temp
3773    \def\quotationauthor{#1}% printed in \Equotation.
3774  \else
3775    \checkenv\titlepage
3776    \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
3777    {\secfonts\rm \leftline{#1}}%
3778  \fi
3779}
3780
3781
3782% Set up page headings and footings.
3783
3784\let\thispage=\folio
3785
3786\newtoks\evenheadline    % headline on even pages
3787\newtoks\oddheadline     % headline on odd pages
3788\newtoks\evenfootline    % footline on even pages
3789\newtoks\oddfootline     % footline on odd pages
3790
3791% Now make \makeheadline and \makefootline in Plain TeX use those variables
3792\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
3793                            \else \the\evenheadline \fi}}
3794\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
3795                            \else \the\evenfootline \fi}\HEADINGShook}
3796\let\HEADINGShook=\relax
3797
3798% Commands to set those variables.
3799% For example, this is what  @headings on  does
3800% @evenheading @thistitle|@thispage|@thischapter
3801% @oddheading @thischapter|@thispage|@thistitle
3802% @evenfooting @thisfile||
3803% @oddfooting ||@thisfile
3804
3805
3806\def\evenheading{\parsearg\evenheadingxxx}
3807\def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
3808\def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
3809\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3810
3811\def\oddheading{\parsearg\oddheadingxxx}
3812\def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
3813\def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
3814\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3815
3816\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
3817
3818\def\evenfooting{\parsearg\evenfootingxxx}
3819\def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
3820\def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
3821\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3822
3823\def\oddfooting{\parsearg\oddfootingxxx}
3824\def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
3825\def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
3826  \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
3827  %
3828  % Leave some space for the footline.  Hopefully ok to assume
3829  % @evenfooting will not be used by itself.
3830  \global\advance\txipageheight by -12pt
3831  \global\advance\vsize by -12pt
3832}
3833
3834\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
3835
3836% @evenheadingmarks top     \thischapter <- chapter at the top of a page
3837% @evenheadingmarks bottom  \thischapter <- chapter at the bottom of a page
3838%
3839% The same set of arguments for:
3840%
3841% @oddheadingmarks
3842% @evenfootingmarks
3843% @oddfootingmarks
3844% @everyheadingmarks
3845% @everyfootingmarks
3846
3847% These define \getoddheadingmarks, \getevenheadingmarks,
3848% \getoddfootingmarks, and \getevenfootingmarks, each to one of
3849% \gettopheadingmarks, \getbottomheadingmarks.
3850%
3851\def\evenheadingmarks{\headingmarks{even}{heading}}
3852\def\oddheadingmarks{\headingmarks{odd}{heading}}
3853\def\evenfootingmarks{\headingmarks{even}{footing}}
3854\def\oddfootingmarks{\headingmarks{odd}{footing}}
3855\parseargdef\everyheadingmarks{\headingmarks{even}{heading}{#1}
3856                          \headingmarks{odd}{heading}{#1} }
3857\parseargdef\everyfootingmarks{\headingmarks{even}{footing}{#1}
3858                          \headingmarks{odd}{footing}{#1} }
3859% #1 = even/odd, #2 = heading/footing, #3 = top/bottom.
3860\def\headingmarks#1#2#3 {%
3861  \expandafter\let\expandafter\temp \csname get#3headingmarks\endcsname
3862  \global\expandafter\let\csname get#1#2marks\endcsname \temp
3863}
3864
3865\everyheadingmarks bottom
3866\everyfootingmarks bottom
3867
3868% @headings double      turns headings on for double-sided printing.
3869% @headings single      turns headings on for single-sided printing.
3870% @headings off         turns them off.
3871% @headings on          same as @headings double, retained for compatibility.
3872% @headings after       turns on double-sided headings after this page.
3873% @headings doubleafter turns on double-sided headings after this page.
3874% @headings singleafter turns on single-sided headings after this page.
3875% By default, they are off at the start of a document,
3876% and turned `on' after @end titlepage.
3877
3878\parseargdef\headings{\csname HEADINGS#1\endcsname}
3879
3880\def\headingsoff{% non-global headings elimination
3881  \evenheadline={\hfil}\evenfootline={\hfil}%
3882   \oddheadline={\hfil}\oddfootline={\hfil}%
3883}
3884
3885\def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting
3886\HEADINGSoff  % it's the default
3887
3888% When we turn headings on, set the page number to 1.
3889% For double-sided printing, put current file name in lower left corner,
3890% chapter name on inside top of right hand pages, document
3891% title on inside top of left hand pages, and page numbers on outside top
3892% edge of all pages.
3893\def\HEADINGSdouble{%
3894\global\pageno=1
3895\global\evenfootline={\hfil}
3896\global\oddfootline={\hfil}
3897\global\evenheadline={\line{\folio\hfil\thistitle}}
3898\global\oddheadline={\line{\thischapterheading\hfil\folio}}
3899\global\let\contentsalignmacro = \chapoddpage
3900}
3901\let\contentsalignmacro = \chappager
3902
3903% For single-sided printing, chapter title goes across top left of page,
3904% page number on top right.
3905\def\HEADINGSsingle{%
3906\global\pageno=1
3907\global\evenfootline={\hfil}
3908\global\oddfootline={\hfil}
3909\global\evenheadline={\line{\thischapterheading\hfil\folio}}
3910\global\oddheadline={\line{\thischapterheading\hfil\folio}}
3911\global\let\contentsalignmacro = \chappager
3912}
3913\def\HEADINGSon{\HEADINGSdouble}
3914
3915\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
3916\let\HEADINGSdoubleafter=\HEADINGSafter
3917\def\HEADINGSdoublex{%
3918\global\evenfootline={\hfil}
3919\global\oddfootline={\hfil}
3920\global\evenheadline={\line{\folio\hfil\thistitle}}
3921\global\oddheadline={\line{\thischapterheading\hfil\folio}}
3922\global\let\contentsalignmacro = \chapoddpage
3923}
3924
3925\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
3926\def\HEADINGSsinglex{%
3927\global\evenfootline={\hfil}
3928\global\oddfootline={\hfil}
3929\global\evenheadline={\line{\thischapterheading\hfil\folio}}
3930\global\oddheadline={\line{\thischapterheading\hfil\folio}}
3931\global\let\contentsalignmacro = \chappager
3932}
3933
3934% Subroutines used in generating headings
3935% This produces Day Month Year style of output.
3936% Only define if not already defined, in case a txi-??.tex file has set
3937% up a different format (e.g., txi-cs.tex does this).
3938\ifx\today\thisisundefined
3939\def\today{%
3940  \number\day\space
3941  \ifcase\month
3942  \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
3943  \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
3944  \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
3945  \fi
3946  \space\number\year}
3947\fi
3948
3949% @settitle line...  specifies the title of the document, for headings.
3950% It generates no output of its own.
3951\def\thistitle{\putwordNoTitle}
3952\def\settitle{\parsearg{\gdef\thistitle}}
3953
3954
3955\message{tables,}
3956% Tables -- @table, @ftable, @vtable, @item(x).
3957
3958% default indentation of table text
3959\newdimen\tableindent \tableindent=.8in
3960% default indentation of @itemize and @enumerate text
3961\newdimen\itemindent  \itemindent=.3in
3962% margin between end of table item and start of table text.
3963\newdimen\itemmargin  \itemmargin=.1in
3964
3965% used internally for \itemindent minus \itemmargin
3966\newdimen\itemmax
3967
3968% Note @table, @ftable, and @vtable define @item, @itemx, etc., with
3969% these defs.
3970% They also define \itemindex
3971% to index the item name in whatever manner is desired (perhaps none).
3972
3973\newif\ifitemxneedsnegativevskip
3974
3975\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
3976
3977\def\internalBitem{\smallbreak \parsearg\itemzzz}
3978\def\internalBitemx{\itemxpar \parsearg\itemzzz}
3979
3980\def\itemzzz #1{\begingroup %
3981  \advance\hsize by -\rightskip
3982  \advance\hsize by -\tableindent
3983  \setbox0=\hbox{\itemindicate{#1}}%
3984  \itemindex{#1}%
3985  \nobreak % This prevents a break before @itemx.
3986  %
3987  % If the item text does not fit in the space we have, put it on a line
3988  % by itself, and do not allow a page break either before or after that
3989  % line.  We do not start a paragraph here because then if the next
3990  % command is, e.g., @kindex, the whatsit would get put into the
3991  % horizontal list on a line by itself, resulting in extra blank space.
3992  \ifdim \wd0>\itemmax
3993    %
3994    % Make this a paragraph so we get the \parskip glue and wrapping,
3995    % but leave it ragged-right.
3996    \begingroup
3997      \advance\leftskip by-\tableindent
3998      \advance\hsize by\tableindent
3999      \advance\rightskip by0pt plus1fil\relax
4000      \leavevmode\unhbox0\par
4001    \endgroup
4002    %
4003    % We're going to be starting a paragraph, but we don't want the
4004    % \parskip glue -- logically it's part of the @item we just started.
4005    \nobreak \vskip-\parskip
4006    %
4007    % Stop a page break at the \parskip glue coming up.  However, if
4008    % what follows is an environment such as @example, there will be no
4009    % \parskip glue; then the negative vskip we just inserted would
4010    % cause the example and the item to crash together.  So we use this
4011    % bizarre value of 10001 as a signal to \aboveenvbreak to insert
4012    % \parskip glue after all.  Section titles are handled this way also.
4013    %
4014    \penalty 10001
4015    \endgroup
4016    \itemxneedsnegativevskipfalse
4017  \else
4018    % The item text fits into the space.  Start a paragraph, so that the
4019    % following text (if any) will end up on the same line.
4020    \noindent
4021    % Do this with kerns and \unhbox so that if there is a footnote in
4022    % the item text, it can migrate to the main vertical list and
4023    % eventually be printed.
4024    \nobreak\kern-\tableindent
4025    \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
4026    \unhbox0
4027    \nobreak\kern\dimen0
4028    \endgroup
4029    \itemxneedsnegativevskiptrue
4030  \fi
4031}
4032
4033\def\item{\errmessage{@item while not in a list environment}}
4034\def\itemx{\errmessage{@itemx while not in a list environment}}
4035
4036% @table, @ftable, @vtable.
4037\envdef\table{%
4038  \let\itemindex\gobble
4039  \tablecheck{table}%
4040}
4041\envdef\ftable{%
4042  \def\itemindex ##1{\doind {fn}{\code{##1}}}%
4043  \tablecheck{ftable}%
4044}
4045\envdef\vtable{%
4046  \def\itemindex ##1{\doind {vr}{\code{##1}}}%
4047  \tablecheck{vtable}%
4048}
4049\def\tablecheck#1{%
4050  \ifnum \the\catcode`\^^M=\active
4051    \endgroup
4052    \errmessage{This command won't work in this context; perhaps the problem is
4053      that we are \inenvironment\thisenv}%
4054    \def\next{\doignore{#1}}%
4055  \else
4056    \let\next\tablex
4057  \fi
4058  \next
4059}
4060\def\tablex#1{%
4061  \def\itemindicate{#1}%
4062  \parsearg\tabley
4063}
4064\def\tabley#1{%
4065  {%
4066    \makevalueexpandable
4067    \edef\temp{\noexpand\tablez #1\space\space\space}%
4068    \expandafter
4069  }\temp \endtablez
4070}
4071\def\tablez #1 #2 #3 #4\endtablez{%
4072  \aboveenvbreak
4073  \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
4074  \ifnum 0#2>0 \tableindent=#2\mil \fi
4075  \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
4076  \itemmax=\tableindent
4077  \advance \itemmax by -\itemmargin
4078  \advance \leftskip by \tableindent
4079  \exdentamount=\tableindent
4080  \parindent = 0pt
4081  \parskip = \smallskipamount
4082  \ifdim \parskip=0pt \parskip=2pt \fi
4083  \let\item = \internalBitem
4084  \let\itemx = \internalBitemx
4085}
4086\def\Etable{\endgraf\afterenvbreak}
4087\let\Eftable\Etable
4088\let\Evtable\Etable
4089\let\Eitemize\Etable
4090\let\Eenumerate\Etable
4091
4092% This is the counter used by @enumerate, which is really @itemize
4093
4094\newcount \itemno
4095
4096\envdef\itemize{\parsearg\doitemize}
4097
4098\def\doitemize#1{%
4099  \aboveenvbreak
4100  \itemmax=\itemindent
4101  \advance\itemmax by -\itemmargin
4102  \advance\leftskip by \itemindent
4103  \exdentamount=\itemindent
4104  \parindent=0pt
4105  \parskip=\smallskipamount
4106  \ifdim\parskip=0pt \parskip=2pt \fi
4107  %
4108  % Try typesetting the item mark so that if the document erroneously says
4109  % something like @itemize @samp (intending @table), there's an error
4110  % right away at the @itemize.  It's not the best error message in the
4111  % world, but it's better than leaving it to the @item.  This means if
4112  % the user wants an empty mark, they have to say @w{} not just @w.
4113  \def\itemcontents{#1}%
4114  \setbox0 = \hbox{\itemcontents}%
4115  %
4116  % @itemize with no arg is equivalent to @itemize @bullet.
4117  \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
4118  %
4119  \let\item=\itemizeitem
4120}
4121
4122% Definition of @item while inside @itemize and @enumerate.
4123%
4124\def\itemizeitem{%
4125  \advance\itemno by 1  % for enumerations
4126  {\let\par=\endgraf \smallbreak}% reasonable place to break
4127  {%
4128   % If the document has an @itemize directly after a section title, a
4129   % \nobreak will be last on the list, and \sectionheading will have
4130   % done a \vskip-\parskip.  In that case, we don't want to zero
4131   % parskip, or the item text will crash with the heading.  On the
4132   % other hand, when there is normal text preceding the item (as there
4133   % usually is), we do want to zero parskip, or there would be too much
4134   % space.  In that case, we won't have a \nobreak before.  At least
4135   % that's the theory.
4136   \ifnum\lastpenalty<10000 \parskip=0in \fi
4137   \noindent
4138   \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
4139   %
4140   \ifinner\else
4141     \vadjust{\penalty 1200}% not good to break after first line of item.
4142   \fi
4143   % We can be in inner vertical mode in a footnote, although an
4144   % @itemize looks awful there.
4145  }%
4146  \flushcr
4147}
4148
4149% \splitoff TOKENS\endmark defines \first to be the first token in
4150% TOKENS, and \rest to be the remainder.
4151%
4152\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
4153
4154% Allow an optional argument of an uppercase letter, lowercase letter,
4155% or number, to specify the first label in the enumerated list.  No
4156% argument is the same as `1'.
4157%
4158\envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
4159\def\enumeratey #1 #2\endenumeratey{%
4160  % If we were given no argument, pretend we were given `1'.
4161  \def\thearg{#1}%
4162  \ifx\thearg\empty \def\thearg{1}\fi
4163  %
4164  % Detect if the argument is a single token.  If so, it might be a
4165  % letter.  Otherwise, the only valid thing it can be is a number.
4166  % (We will always have one token, because of the test we just made.
4167  % This is a good thing, since \splitoff doesn't work given nothing at
4168  % all -- the first parameter is undelimited.)
4169  \expandafter\splitoff\thearg\endmark
4170  \ifx\rest\empty
4171    % Only one token in the argument.  It could still be anything.
4172    % A ``lowercase letter'' is one whose \lccode is nonzero.
4173    % An ``uppercase letter'' is one whose \lccode is both nonzero, and
4174    %   not equal to itself.
4175    % Otherwise, we assume it's a number.
4176    %
4177    % We need the \relax at the end of the \ifnum lines to stop TeX from
4178    % continuing to look for a <number>.
4179    %
4180    \ifnum\lccode\expandafter`\thearg=0\relax
4181      \numericenumerate % a number (we hope)
4182    \else
4183      % It's a letter.
4184      \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
4185        \lowercaseenumerate % lowercase letter
4186      \else
4187        \uppercaseenumerate % uppercase letter
4188      \fi
4189    \fi
4190  \else
4191    % Multiple tokens in the argument.  We hope it's a number.
4192    \numericenumerate
4193  \fi
4194}
4195
4196% An @enumerate whose labels are integers.  The starting integer is
4197% given in \thearg.
4198%
4199\def\numericenumerate{%
4200  \itemno = \thearg
4201  \startenumeration{\the\itemno}%
4202}
4203
4204% The starting (lowercase) letter is in \thearg.
4205\def\lowercaseenumerate{%
4206  \itemno = \expandafter`\thearg
4207  \startenumeration{%
4208    % Be sure we're not beyond the end of the alphabet.
4209    \ifnum\itemno=0
4210      \errmessage{No more lowercase letters in @enumerate; get a bigger
4211                  alphabet}%
4212    \fi
4213    \char\lccode\itemno
4214  }%
4215}
4216
4217% The starting (uppercase) letter is in \thearg.
4218\def\uppercaseenumerate{%
4219  \itemno = \expandafter`\thearg
4220  \startenumeration{%
4221    % Be sure we're not beyond the end of the alphabet.
4222    \ifnum\itemno=0
4223      \errmessage{No more uppercase letters in @enumerate; get a bigger
4224                  alphabet}
4225    \fi
4226    \char\uccode\itemno
4227  }%
4228}
4229
4230% Call \doitemize, adding a period to the first argument and supplying the
4231% common last two arguments.  Also subtract one from the initial value in
4232% \itemno, since @item increments \itemno.
4233%
4234\def\startenumeration#1{%
4235  \advance\itemno by -1
4236  \doitemize{#1.}\flushcr
4237}
4238
4239% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
4240% to @enumerate.
4241%
4242\def\alphaenumerate{\enumerate{a}}
4243\def\capsenumerate{\enumerate{A}}
4244\def\Ealphaenumerate{\Eenumerate}
4245\def\Ecapsenumerate{\Eenumerate}
4246
4247
4248% @multitable macros
4249% Amy Hendrickson, 8/18/94, 3/6/96
4250%
4251% @multitable ... @end multitable will make as many columns as desired.
4252% Contents of each column will wrap at width given in preamble.  Width
4253% can be specified either with sample text given in a template line,
4254% or in percent of \hsize, the current width of text on page.
4255
4256% Table can continue over pages but will only break between lines.
4257
4258% To make preamble:
4259%
4260% Either define widths of columns in terms of percent of \hsize:
4261%   @multitable @columnfractions .25 .3 .45
4262%   @item ...
4263%
4264%   Numbers following @columnfractions are the percent of the total
4265%   current hsize to be used for each column. You may use as many
4266%   columns as desired.
4267
4268
4269% Or use a template:
4270%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4271%   @item ...
4272%   using the widest term desired in each column.
4273
4274% Each new table line starts with @item, each subsequent new column
4275% starts with @tab. Empty columns may be produced by supplying @tab's
4276% with nothing between them for as many times as empty columns are needed,
4277% ie, @tab@tab@tab will produce two empty columns.
4278
4279% @item, @tab do not need to be on their own lines, but it will not hurt
4280% if they are.
4281
4282% Sample multitable:
4283
4284%   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4285%   @item first col stuff @tab second col stuff @tab third col
4286%   @item
4287%   first col stuff
4288%   @tab
4289%   second col stuff
4290%   @tab
4291%   third col
4292%   @item first col stuff @tab second col stuff
4293%   @tab Many paragraphs of text may be used in any column.
4294%
4295%         They will wrap at the width determined by the template.
4296%   @item@tab@tab This will be in third column.
4297%   @end multitable
4298
4299% Default dimensions may be reset by user.
4300% @multitableparskip is vertical space between paragraphs in table.
4301% @multitableparindent is paragraph indent in table.
4302% @multitablecolmargin is horizontal space to be left between columns.
4303% @multitablelinespace is space to leave between table items, baseline
4304%                                                            to baseline.
4305%   0pt means it depends on current normal line spacing.
4306%
4307\newskip\multitableparskip
4308\newskip\multitableparindent
4309\newdimen\multitablecolspace
4310\newskip\multitablelinespace
4311\multitableparskip=0pt
4312\multitableparindent=6pt
4313\multitablecolspace=12pt
4314\multitablelinespace=0pt
4315
4316% Macros used to set up halign preamble:
4317%
4318\let\endsetuptable\relax
4319\def\xendsetuptable{\endsetuptable}
4320\let\columnfractions\relax
4321\def\xcolumnfractions{\columnfractions}
4322\newif\ifsetpercent
4323
4324% #1 is the @columnfraction, usually a decimal number like .5, but might
4325% be just 1.  We just use it, whatever it is.
4326%
4327\def\pickupwholefraction#1 {%
4328  \global\advance\colcount by 1
4329  \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
4330  \setuptable
4331}
4332
4333\newcount\colcount
4334\def\setuptable#1{%
4335  \def\firstarg{#1}%
4336  \ifx\firstarg\xendsetuptable
4337    \let\go = \relax
4338  \else
4339    \ifx\firstarg\xcolumnfractions
4340      \global\setpercenttrue
4341    \else
4342      \ifsetpercent
4343         \let\go\pickupwholefraction
4344      \else
4345         \global\advance\colcount by 1
4346         \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
4347                   % separator; typically that is always in the input, anyway.
4348         \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
4349      \fi
4350    \fi
4351    \ifx\go\pickupwholefraction
4352      % Put the argument back for the \pickupwholefraction call, so
4353      % we'll always have a period there to be parsed.
4354      \def\go{\pickupwholefraction#1}%
4355    \else
4356      \let\go = \setuptable
4357    \fi%
4358  \fi
4359  \go
4360}
4361
4362% multitable-only commands.
4363%
4364% @headitem starts a heading row, which we typeset in bold.  Assignments
4365% have to be global since we are inside the implicit group of an
4366% alignment entry.  \everycr below resets \everytab so we don't have to
4367% undo it ourselves.
4368\def\headitemfont{\b}% for people to use in the template row; not changeable
4369\def\headitem{%
4370  \checkenv\multitable
4371  \crcr
4372  \gdef\headitemcrhook{\nobreak}% attempt to avoid page break after headings
4373  \global\everytab={\bf}% can't use \headitemfont since the parsing differs
4374  \the\everytab % for the first item
4375}%
4376%
4377% default for tables with no headings.
4378\let\headitemcrhook=\relax
4379%
4380% A \tab used to include \hskip1sp.  But then the space in a template
4381% line is not enough.  That is bad.  So let's go back to just `&' until
4382% we again encounter the problem the 1sp was intended to solve.
4383%					--karl, nathan@acm.org, 20apr99.
4384\def\tab{\checkenv\multitable &\the\everytab}%
4385
4386% @multitable ... @end multitable definitions:
4387%
4388\newtoks\everytab  % insert after every tab.
4389%
4390\envdef\multitable{%
4391  \vskip\parskip
4392  \startsavinginserts
4393  %
4394  % @item within a multitable starts a normal row.
4395  % We use \def instead of \let so that if one of the multitable entries
4396  % contains an @itemize, we don't choke on the \item (seen as \crcr aka
4397  % \endtemplate) expanding \doitemize.
4398  \def\item{\crcr}%
4399  %
4400  \tolerance=9500
4401  \hbadness=9500
4402  \setmultitablespacing
4403  \parskip=\multitableparskip
4404  \parindent=\multitableparindent
4405  \overfullrule=0pt
4406  \global\colcount=0
4407  %
4408  \everycr = {%
4409    \noalign{%
4410      \global\everytab={}% Reset from possible headitem.
4411      \global\colcount=0 % Reset the column counter.
4412      %
4413      % Check for saved footnotes, etc.:
4414      \checkinserts
4415      %
4416      % Perhaps a \nobreak, then reset:
4417      \headitemcrhook
4418      \global\let\headitemcrhook=\relax
4419    }%
4420  }%
4421  %
4422  \parsearg\domultitable
4423}
4424\def\domultitable#1{%
4425  % To parse everything between @multitable and @item:
4426  \setuptable#1 \endsetuptable
4427  %
4428  % This preamble sets up a generic column definition, which will
4429  % be used as many times as user calls for columns.
4430  % \vtop will set a single line and will also let text wrap and
4431  % continue for many paragraphs if desired.
4432  \halign\bgroup &%
4433    \global\advance\colcount by 1
4434    \multistrut
4435    \vtop{%
4436      % Use the current \colcount to find the correct column width:
4437      \hsize=\expandafter\csname col\the\colcount\endcsname
4438      %
4439      % In order to keep entries from bumping into each other
4440      % we will add a \leftskip of \multitablecolspace to all columns after
4441      % the first one.
4442      %
4443      % If a template has been used, we will add \multitablecolspace
4444      % to the width of each template entry.
4445      %
4446      % If the user has set preamble in terms of percent of \hsize we will
4447      % use that dimension as the width of the column, and the \leftskip
4448      % will keep entries from bumping into each other.  Table will start at
4449      % left margin and final column will justify at right margin.
4450      %
4451      % Make sure we don't inherit \rightskip from the outer environment.
4452      \rightskip=0pt
4453      \ifnum\colcount=1
4454	% The first column will be indented with the surrounding text.
4455	\advance\hsize by\leftskip
4456      \else
4457	\ifsetpercent \else
4458	  % If user has not set preamble in terms of percent of \hsize
4459	  % we will advance \hsize by \multitablecolspace.
4460	  \advance\hsize by \multitablecolspace
4461	\fi
4462       % In either case we will make \leftskip=\multitablecolspace:
4463      \leftskip=\multitablecolspace
4464      \fi
4465      % Ignoring space at the beginning and end avoids an occasional spurious
4466      % blank line, when TeX decides to break the line at the space before the
4467      % box from the multistrut, so the strut ends up on a line by itself.
4468      % For example:
4469      % @multitable @columnfractions .11 .89
4470      % @item @code{#}
4471      % @tab Legal holiday which is valid in major parts of the whole country.
4472      % Is automatically provided with highlighting sequences respectively
4473      % marking characters.
4474      \noindent\ignorespaces##\unskip\multistrut
4475    }\cr
4476}
4477\def\Emultitable{%
4478  \crcr
4479  \egroup % end the \halign
4480  \global\setpercentfalse
4481}
4482
4483\def\setmultitablespacing{%
4484  \def\multistrut{\strut}% just use the standard line spacing
4485  %
4486  % Compute \multitablelinespace (if not defined by user) for use in
4487  % \multitableparskip calculation.  We used define \multistrut based on
4488  % this, but (ironically) that caused the spacing to be off.
4489  % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
4490\ifdim\multitablelinespace=0pt
4491\setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
4492\global\advance\multitablelinespace by-\ht0
4493\fi
4494% Test to see if parskip is larger than space between lines of
4495% table. If not, do nothing.
4496%        If so, set to same dimension as multitablelinespace.
4497\ifdim\multitableparskip>\multitablelinespace
4498\global\multitableparskip=\multitablelinespace
4499\global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4500                                      % than skip between lines in the table.
4501\fi%
4502\ifdim\multitableparskip=0pt
4503\global\multitableparskip=\multitablelinespace
4504\global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4505                                      % than skip between lines in the table.
4506\fi}
4507
4508
4509\message{conditionals,}
4510
4511% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
4512% @ifnotxml always succeed.  They currently do nothing; we don't
4513% attempt to check whether the conditionals are properly nested.  But we
4514% have to remember that they are conditionals, so that @end doesn't
4515% attempt to close an environment group.
4516%
4517\def\makecond#1{%
4518  \expandafter\let\csname #1\endcsname = \relax
4519  \expandafter\let\csname iscond.#1\endcsname = 1
4520}
4521\makecond{iftex}
4522\makecond{ifnotdocbook}
4523\makecond{ifnothtml}
4524\makecond{ifnotinfo}
4525\makecond{ifnotplaintext}
4526\makecond{ifnotxml}
4527
4528% Ignore @ignore, @ifhtml, @ifinfo, and the like.
4529%
4530\def\direntry{\doignore{direntry}}
4531\def\documentdescription{\doignore{documentdescription}}
4532\def\docbook{\doignore{docbook}}
4533\def\html{\doignore{html}}
4534\def\ifdocbook{\doignore{ifdocbook}}
4535\def\ifhtml{\doignore{ifhtml}}
4536\def\ifinfo{\doignore{ifinfo}}
4537\def\ifnottex{\doignore{ifnottex}}
4538\def\ifplaintext{\doignore{ifplaintext}}
4539\def\ifxml{\doignore{ifxml}}
4540\def\ignore{\doignore{ignore}}
4541\def\menu{\doignore{menu}}
4542\def\xml{\doignore{xml}}
4543
4544% Ignore text until a line `@end #1', keeping track of nested conditionals.
4545%
4546% A count to remember the depth of nesting.
4547\newcount\doignorecount
4548
4549\def\doignore#1{\begingroup
4550  % Scan in ``verbatim'' mode:
4551  \obeylines
4552  \catcode`\@ = \other
4553  \catcode`\{ = \other
4554  \catcode`\} = \other
4555  %
4556  % Make sure that spaces turn into tokens that match what \doignoretext wants.
4557  \spaceisspace
4558  %
4559  % Count number of #1's that we've seen.
4560  \doignorecount = 0
4561  %
4562  % Swallow text until we reach the matching `@end #1'.
4563  \dodoignore{#1}%
4564}
4565
4566{ \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
4567  \obeylines %
4568  %
4569  \gdef\dodoignore#1{%
4570    % #1 contains the command name as a string, e.g., `ifinfo'.
4571    %
4572    % Define a command to find the next `@end #1'.
4573    \long\def\doignoretext##1^^M@end #1{%
4574      \doignoretextyyy##1^^M@#1\_STOP_}%
4575    %
4576    % And this command to find another #1 command, at the beginning of a
4577    % line.  (Otherwise, we would consider a line `@c @ifset', for
4578    % example, to count as an @ifset for nesting.)
4579    \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
4580    %
4581    % And now expand that command.
4582    \doignoretext ^^M%
4583  }%
4584}
4585
4586\def\doignoreyyy#1{%
4587  \def\temp{#1}%
4588  \ifx\temp\empty			% Nothing found.
4589    \let\next\doignoretextzzz
4590  \else					% Found a nested condition, ...
4591    \advance\doignorecount by 1
4592    \let\next\doignoretextyyy		% ..., look for another.
4593    % If we're here, #1 ends with ^^M\ifinfo (for example).
4594  \fi
4595  \next #1% the token \_STOP_ is present just after this macro.
4596}
4597
4598% We have to swallow the remaining "\_STOP_".
4599%
4600\def\doignoretextzzz#1{%
4601  \ifnum\doignorecount = 0	% We have just found the outermost @end.
4602    \let\next\enddoignore
4603  \else				% Still inside a nested condition.
4604    \advance\doignorecount by -1
4605    \let\next\doignoretext      % Look for the next @end.
4606  \fi
4607  \next
4608}
4609
4610% Finish off ignored text.
4611{ \obeylines%
4612  % Ignore anything after the last `@end #1'; this matters in verbatim
4613  % environments, where otherwise the newline after an ignored conditional
4614  % would result in a blank line in the output.
4615  \gdef\enddoignore#1^^M{\endgroup\ignorespaces}%
4616}
4617
4618
4619% @set VAR sets the variable VAR to an empty value.
4620% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
4621%
4622% Since we want to separate VAR from REST-OF-LINE (which might be
4623% empty), we can't just use \parsearg; we have to insert a space of our
4624% own to delimit the rest of the line, and then take it out again if we
4625% didn't need it.
4626% We rely on the fact that \parsearg sets \catcode`\ =10.
4627%
4628\parseargdef\set{\setyyy#1 \endsetyyy}
4629\def\setyyy#1 #2\endsetyyy{%
4630  {%
4631    \makevalueexpandable
4632    \def\temp{#2}%
4633    \edef\next{\gdef\makecsname{SET#1}}%
4634    \ifx\temp\empty
4635      \next{}%
4636    \else
4637      \setzzz#2\endsetzzz
4638    \fi
4639  }%
4640}
4641% Remove the trailing space \setxxx inserted.
4642\def\setzzz#1 \endsetzzz{\next{#1}}
4643
4644% @clear VAR clears (i.e., unsets) the variable VAR.
4645%
4646\parseargdef\clear{%
4647  {%
4648    \makevalueexpandable
4649    \global\expandafter\let\csname SET#1\endcsname=\relax
4650  }%
4651}
4652
4653% @value{foo} gets the text saved in variable foo.
4654\def\value{\begingroup\makevalueexpandable\valuexxx}
4655\def\valuexxx#1{\expandablevalue{#1}\endgroup}
4656{
4657  \catcode`\-=\active \catcode`\_=\active
4658  %
4659  \gdef\makevalueexpandable{%
4660    \let\value = \expandablevalue
4661    % We don't want these characters active, ...
4662    \catcode`\-=\other \catcode`\_=\other
4663    % ..., but we might end up with active ones in the argument if
4664    % we're called from @code, as @code{@value{foo-bar_}}, though.
4665    % So \let them to their normal equivalents.
4666    \let-\normaldash \let_\normalunderscore
4667  }
4668}
4669
4670% We have this subroutine so that we can handle at least some @value's
4671% properly in indexes (we call \makevalueexpandable in \indexdummies).
4672% The command has to be fully expandable (if the variable is set), since
4673% the result winds up in the index file.  This means that if the
4674% variable's value contains other Texinfo commands, it's almost certain
4675% it will fail (although perhaps we could fix that with sufficient work
4676% to do a one-level expansion on the result, instead of complete).
4677%
4678% Unfortunately, this has the consequence that when _ is in the *value*
4679% of an @set, it does not print properly in the roman fonts (get the cmr
4680% dot accent at position 126 instead).  No fix comes to mind, and it's
4681% been this way since 2003 or earlier, so just ignore it.
4682%
4683\def\expandablevalue#1{%
4684  \expandafter\ifx\csname SET#1\endcsname\relax
4685    {[No value for ``#1'']}%
4686    \message{Variable `#1', used in @value, is not set.}%
4687  \else
4688    \csname SET#1\endcsname
4689  \fi
4690}
4691
4692% Like \expandablevalue, but completely expandable (the \message in the
4693% definition above operates at the execution level of TeX).  Used when
4694% writing to auxiliary files, due to the expansion that \write does.
4695% If flag is undefined, pass through an unexpanded @value command: maybe it
4696% will be set by the time it is read back in.
4697%
4698% NB flag names containing - or _ may not work here.
4699\def\dummyvalue#1{%
4700  \expandafter\ifx\csname SET#1\endcsname\relax
4701    \noexpand\value{#1}%
4702  \else
4703    \csname SET#1\endcsname
4704  \fi
4705}
4706
4707% Used for @value's in index entries to form the sort key: expand the @value
4708% if possible, otherwise sort late.
4709\def\indexnofontsvalue#1{%
4710  \expandafter\ifx\csname SET#1\endcsname\relax
4711    ZZZZZZZ
4712  \else
4713    \csname SET#1\endcsname
4714  \fi
4715}
4716
4717% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
4718% with @set.
4719%
4720% To get the special treatment we need for `@end ifset,' we call
4721% \makecond and then redefine.
4722%
4723\makecond{ifset}
4724\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
4725\def\doifset#1#2{%
4726  {%
4727    \makevalueexpandable
4728    \let\next=\empty
4729    \expandafter\ifx\csname SET#2\endcsname\relax
4730      #1% If not set, redefine \next.
4731    \fi
4732    \expandafter
4733  }\next
4734}
4735\def\ifsetfail{\doignore{ifset}}
4736
4737% @ifclear VAR ... @end executes the `...' iff VAR has never been
4738% defined with @set, or has been undefined with @clear.
4739%
4740% The `\else' inside the `\doifset' parameter is a trick to reuse the
4741% above code: if the variable is not set, do nothing, if it is set,
4742% then redefine \next to \ifclearfail.
4743%
4744\makecond{ifclear}
4745\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
4746\def\ifclearfail{\doignore{ifclear}}
4747
4748% @ifcommandisdefined CMD ... @end executes the `...' if CMD (written
4749% without the @) is in fact defined.  We can only feasibly check at the
4750% TeX level, so something like `mathcode' is going to considered
4751% defined even though it is not a Texinfo command.
4752%
4753\makecond{ifcommanddefined}
4754\def\ifcommanddefined{\parsearg{\doifcmddefined{\let\next=\ifcmddefinedfail}}}
4755%
4756\def\doifcmddefined#1#2{{%
4757    \makevalueexpandable
4758    \let\next=\empty
4759    \expandafter\ifx\csname #2\endcsname\relax
4760      #1% If not defined, \let\next as above.
4761    \fi
4762    \expandafter
4763  }\next
4764}
4765\def\ifcmddefinedfail{\doignore{ifcommanddefined}}
4766
4767% @ifcommandnotdefined CMD ... handled similar to @ifclear above.
4768\makecond{ifcommandnotdefined}
4769\def\ifcommandnotdefined{%
4770  \parsearg{\doifcmddefined{\else \let\next=\ifcmdnotdefinedfail}}}
4771\def\ifcmdnotdefinedfail{\doignore{ifcommandnotdefined}}
4772
4773% Set the `txicommandconditionals' variable, so documents have a way to
4774% test if the @ifcommand...defined conditionals are available.
4775\set txicommandconditionals
4776
4777% @dircategory CATEGORY  -- specify a category of the dir file
4778% which this file should belong to.  Ignore this in TeX.
4779\let\dircategory=\comment
4780
4781% @defininfoenclose.
4782\let\definfoenclose=\comment
4783
4784
4785\message{indexing,}
4786% Index generation facilities
4787
4788% Define \newwrite to be identical to plain tex's \newwrite
4789% except not \outer, so it can be used within macros and \if's.
4790\edef\newwrite{\makecsname{ptexnewwrite}}
4791
4792% \newindex {foo} defines an index named IX.
4793% It automatically defines \IXindex such that
4794% \IXindex ...rest of line... puts an entry in the index IX.
4795% It also defines \IXindfile to be the number of the output channel for
4796% the file that accumulates this index.  The file's extension is IX.
4797% The name of an index should be no more than 2 characters long
4798% for the sake of vms.
4799%
4800\def\newindex#1{%
4801  \expandafter\chardef\csname#1indfile\endcsname=0
4802  \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
4803    \noexpand\doindex{#1}}
4804}
4805
4806% @defindex foo  ==  \newindex{foo}
4807%
4808\def\defindex{\parsearg\newindex}
4809
4810% Define @defcodeindex, like @defindex except put all entries in @code.
4811%
4812\def\defcodeindex{\parsearg\newcodeindex}
4813%
4814\def\newcodeindex#1{%
4815  \expandafter\chardef\csname#1indfile\endcsname=0
4816  \expandafter\xdef\csname#1index\endcsname{%
4817    \noexpand\docodeindex{#1}}%
4818}
4819
4820% The default indices:
4821\newindex{cp}%      concepts,
4822\newcodeindex{fn}%  functions,
4823\newcodeindex{vr}%  variables,
4824\newcodeindex{tp}%  types,
4825\newcodeindex{ky}%  keys
4826\newcodeindex{pg}%  and programs.
4827
4828
4829% @synindex foo bar    makes index foo feed into index bar.
4830% Do this instead of @defindex foo if you don't want it as a separate index.
4831%
4832% @syncodeindex foo bar   similar, but put all entries made for index foo
4833% inside @code.
4834%
4835\def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
4836\def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
4837
4838% #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
4839% #3 the target index (bar).
4840\def\dosynindex#1#2#3{%
4841  \requireopenindexfile{#3}%
4842  % redefine \fooindfile:
4843  \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
4844  \expandafter\let\csname#2indfile\endcsname=\temp
4845  % redefine \fooindex:
4846  \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
4847}
4848
4849% Define \doindex, the driver for all index macros.
4850% Argument #1 is generated by the calling \fooindex macro,
4851% and it is the two-letter name of the index.
4852
4853\def\doindex#1{\edef\indexname{#1}\parsearg\doindexxxx}
4854\def\doindexxxx #1{\doind{\indexname}{#1}}
4855
4856% like the previous two, but they put @code around the argument.
4857\def\docodeindex#1{\edef\indexname{#1}\parsearg\docodeindexxxx}
4858\def\docodeindexxxx #1{\doind{\indexname}{\code{#1}}}
4859
4860
4861% Used when writing an index entry out to an index file to prevent
4862% expansion of Texinfo commands that can appear in an index entry.
4863%
4864\def\indexdummies{%
4865  \escapechar = `\\     % use backslash in output files.
4866  \definedummyletter\@%
4867  \definedummyletter\ %
4868  %
4869  % For texindex which always views { and } as separators.
4870  \def\{{\lbracechar{}}%
4871  \def\}{\rbracechar{}}%
4872  %
4873  % Do the redefinitions.
4874  \definedummies
4875}
4876
4877% Used for the aux and toc files, where @ is the escape character.
4878%
4879\def\atdummies{%
4880  \definedummyletter\@%
4881  \definedummyletter\ %
4882  \definedummyletter\{%
4883  \definedummyletter\}%
4884  %
4885  % Do the redefinitions.
4886  \definedummies
4887  \otherbackslash
4888}
4889
4890% \definedummyword defines \#1 as \string\#1\space, thus effectively
4891% preventing its expansion.  This is used only for control words,
4892% not control letters, because the \space would be incorrect for
4893% control characters, but is needed to separate the control word
4894% from whatever follows.
4895%
4896% These can be used both for control words that take an argument and
4897% those that do not.  If it is followed by {arg} in the input, then
4898% that will dutifully get written to the index (or wherever).
4899%
4900% For control letters, we have \definedummyletter, which omits the
4901% space.
4902%
4903\def\definedummyword  #1{\def#1{\string#1\space}}%
4904\def\definedummyletter#1{\def#1{\string#1}}%
4905\let\definedummyaccent\definedummyletter
4906
4907% Called from \indexdummies and \atdummies, to effectively prevent
4908% the expansion of commands.
4909%
4910\def\definedummies{%
4911  %
4912  \let\commondummyword\definedummyword
4913  \let\commondummyletter\definedummyletter
4914  \let\commondummyaccent\definedummyaccent
4915  \commondummiesnofonts
4916  %
4917  \definedummyletter\_%
4918  \definedummyletter\-%
4919  %
4920  % Non-English letters.
4921  \definedummyword\AA
4922  \definedummyword\AE
4923  \definedummyword\DH
4924  \definedummyword\L
4925  \definedummyword\O
4926  \definedummyword\OE
4927  \definedummyword\TH
4928  \definedummyword\aa
4929  \definedummyword\ae
4930  \definedummyword\dh
4931  \definedummyword\exclamdown
4932  \definedummyword\l
4933  \definedummyword\o
4934  \definedummyword\oe
4935  \definedummyword\ordf
4936  \definedummyword\ordm
4937  \definedummyword\questiondown
4938  \definedummyword\ss
4939  \definedummyword\th
4940  %
4941  % Although these internal commands shouldn't show up, sometimes they do.
4942  \definedummyword\bf
4943  \definedummyword\gtr
4944  \definedummyword\hat
4945  \definedummyword\less
4946  \definedummyword\sf
4947  \definedummyword\sl
4948  \definedummyword\tclose
4949  \definedummyword\tt
4950  %
4951  \definedummyword\LaTeX
4952  \definedummyword\TeX
4953  %
4954  % Assorted special characters.
4955  \definedummyword\atchar
4956  \definedummyword\arrow
4957  \definedummyword\bullet
4958  \definedummyword\comma
4959  \definedummyword\copyright
4960  \definedummyword\registeredsymbol
4961  \definedummyword\dots
4962  \definedummyword\enddots
4963  \definedummyword\entrybreak
4964  \definedummyword\equiv
4965  \definedummyword\error
4966  \definedummyword\euro
4967  \definedummyword\expansion
4968  \definedummyword\geq
4969  \definedummyword\guillemetleft
4970  \definedummyword\guillemetright
4971  \definedummyword\guilsinglleft
4972  \definedummyword\guilsinglright
4973  \definedummyword\lbracechar
4974  \definedummyword\leq
4975  \definedummyword\mathopsup
4976  \definedummyword\minus
4977  \definedummyword\ogonek
4978  \definedummyword\pounds
4979  \definedummyword\point
4980  \definedummyword\print
4981  \definedummyword\quotedblbase
4982  \definedummyword\quotedblleft
4983  \definedummyword\quotedblright
4984  \definedummyword\quoteleft
4985  \definedummyword\quoteright
4986  \definedummyword\quotesinglbase
4987  \definedummyword\rbracechar
4988  \definedummyword\result
4989  \definedummyword\sub
4990  \definedummyword\sup
4991  \definedummyword\textdegree
4992  %
4993  % We want to disable all macros so that they are not expanded by \write.
4994  \macrolist
4995  \let\value\dummyvalue
4996  %
4997  \normalturnoffactive
4998}
4999
5000% \commondummiesnofonts: common to \definedummies and \indexnofonts.
5001% Define \commondummyletter, \commondummyaccent and \commondummyword before
5002% using.  Used for accents, font commands, and various control letters.
5003%
5004\def\commondummiesnofonts{%
5005  % Control letters and accents.
5006  \commondummyletter\!%
5007  \commondummyaccent\"%
5008  \commondummyaccent\'%
5009  \commondummyletter\*%
5010  \commondummyaccent\,%
5011  \commondummyletter\.%
5012  \commondummyletter\/%
5013  \commondummyletter\:%
5014  \commondummyaccent\=%
5015  \commondummyletter\?%
5016  \commondummyaccent\^%
5017  \commondummyaccent\`%
5018  \commondummyaccent\~%
5019  \commondummyword\u
5020  \commondummyword\v
5021  \commondummyword\H
5022  \commondummyword\dotaccent
5023  \commondummyword\ogonek
5024  \commondummyword\ringaccent
5025  \commondummyword\tieaccent
5026  \commondummyword\ubaraccent
5027  \commondummyword\udotaccent
5028  \commondummyword\dotless
5029  %
5030  % Texinfo font commands.
5031  \commondummyword\b
5032  \commondummyword\i
5033  \commondummyword\r
5034  \commondummyword\sansserif
5035  \commondummyword\sc
5036  \commondummyword\slanted
5037  \commondummyword\t
5038  %
5039  % Commands that take arguments.
5040  \commondummyword\abbr
5041  \commondummyword\acronym
5042  \commondummyword\anchor
5043  \commondummyword\cite
5044  \commondummyword\code
5045  \commondummyword\command
5046  \commondummyword\dfn
5047  \commondummyword\dmn
5048  \commondummyword\email
5049  \commondummyword\emph
5050  \commondummyword\env
5051  \commondummyword\file
5052  \commondummyword\image
5053  \commondummyword\indicateurl
5054  \commondummyword\inforef
5055  \commondummyword\kbd
5056  \commondummyword\key
5057  \commondummyword\math
5058  \commondummyword\option
5059  \commondummyword\pxref
5060  \commondummyword\ref
5061  \commondummyword\samp
5062  \commondummyword\strong
5063  \commondummyword\tie
5064  \commondummyword\U
5065  \commondummyword\uref
5066  \commondummyword\url
5067  \commondummyword\var
5068  \commondummyword\verb
5069  \commondummyword\w
5070  \commondummyword\xref
5071}
5072
5073% This does nothing, but for a time it was recommended to use
5074% \usebracesinindexestrue to be able to use braces in index entries.
5075
5076\let\indexlbrace\relax
5077\let\indexrbrace\relax
5078
5079{\catcode`\@=0
5080\catcode`\\=13
5081  @gdef@backslashdisappear{@def\{}}
5082}
5083
5084{
5085\catcode`\<=13
5086\catcode`\-=13
5087\catcode`\`=13
5088  \gdef\indexnonalnumdisappear{%
5089    \expandafter\ifx\csname SETtxiindexlquoteignore\endcsname\relax\else
5090      % @set txiindexlquoteignore makes us ignore left quotes in the sort term.
5091      % (Introduced for FSFS 2nd ed.)
5092      \let`=\empty
5093    \fi
5094    %
5095    \expandafter\ifx\csname SETtxiindexbackslashignore\endcsname\relax\else
5096      \backslashdisappear
5097    \fi
5098    %
5099    \expandafter\ifx\csname SETtxiindexhyphenignore\endcsname\relax\else
5100      \def-{}%
5101    \fi
5102    \expandafter\ifx\csname SETtxiindexlessthanignore\endcsname\relax\else
5103      \def<{}%
5104    \fi
5105    \expandafter\ifx\csname SETtxiindexatsignignore\endcsname\relax\else
5106      \def\@{}%
5107    \fi
5108  }
5109
5110  \gdef\indexnonalnumreappear{%
5111    \useindexbackslash
5112    \let-\normaldash
5113    \let<\normalless
5114    \def\@{@}%
5115  }
5116}
5117
5118
5119% \indexnofonts is used when outputting the strings to sort the index
5120% by, and when constructing control sequence names.  It eliminates all
5121% control sequences and just writes whatever the best ASCII sort string
5122% would be for a given command (usually its argument).
5123%
5124\def\indexnofonts{%
5125  % Accent commands should become @asis.
5126  \def\commondummyaccent##1{\let##1\asis}%
5127  % We can just ignore other control letters.
5128  \def\commondummyletter##1{\let##1\empty}%
5129  % All control words become @asis by default; overrides below.
5130  \let\commondummyword\commondummyaccent
5131  \commondummiesnofonts
5132  %
5133  % Don't no-op \tt, since it isn't a user-level command
5134  % and is used in the definitions of the active chars like <, >, |, etc.
5135  % Likewise with the other plain tex font commands.
5136  %\let\tt=\asis
5137  %
5138  \def\ { }%
5139  \def\@{@}%
5140  \def\_{\normalunderscore}%
5141  \def\-{}% @- shouldn't affect sorting
5142  %
5143  \uccode`\1=`\{ \uppercase{\def\{{1}}%
5144  \uccode`\1=`\} \uppercase{\def\}{1}}%
5145  \let\lbracechar\{%
5146  \let\rbracechar\}%
5147  %
5148  % Non-English letters.
5149  \def\AA{AA}%
5150  \def\AE{AE}%
5151  \def\DH{DZZ}%
5152  \def\L{L}%
5153  \def\OE{OE}%
5154  \def\O{O}%
5155  \def\TH{TH}%
5156  \def\aa{aa}%
5157  \def\ae{ae}%
5158  \def\dh{dzz}%
5159  \def\exclamdown{!}%
5160  \def\l{l}%
5161  \def\oe{oe}%
5162  \def\ordf{a}%
5163  \def\ordm{o}%
5164  \def\o{o}%
5165  \def\questiondown{?}%
5166  \def\ss{ss}%
5167  \def\th{th}%
5168  %
5169  \def\LaTeX{LaTeX}%
5170  \def\TeX{TeX}%
5171  %
5172  % Assorted special characters.  \defglyph gives the control sequence a
5173  % definition that removes the {} that follows its use.
5174  \defglyph\atchar{@}%
5175  \defglyph\arrow{->}%
5176  \defglyph\bullet{bullet}%
5177  \defglyph\comma{,}%
5178  \defglyph\copyright{copyright}%
5179  \defglyph\dots{...}%
5180  \defglyph\enddots{...}%
5181  \defglyph\equiv{==}%
5182  \defglyph\error{error}%
5183  \defglyph\euro{euro}%
5184  \defglyph\expansion{==>}%
5185  \defglyph\geq{>=}%
5186  \defglyph\guillemetleft{<<}%
5187  \defglyph\guillemetright{>>}%
5188  \defglyph\guilsinglleft{<}%
5189  \defglyph\guilsinglright{>}%
5190  \defglyph\leq{<=}%
5191  \defglyph\lbracechar{\{}%
5192  \defglyph\minus{-}%
5193  \defglyph\point{.}%
5194  \defglyph\pounds{pounds}%
5195  \defglyph\print{-|}%
5196  \defglyph\quotedblbase{"}%
5197  \defglyph\quotedblleft{"}%
5198  \defglyph\quotedblright{"}%
5199  \defglyph\quoteleft{`}%
5200  \defglyph\quoteright{'}%
5201  \defglyph\quotesinglbase{,}%
5202  \defglyph\rbracechar{\}}%
5203  \defglyph\registeredsymbol{R}%
5204  \defglyph\result{=>}%
5205  \defglyph\textdegree{o}%
5206  %
5207  % We need to get rid of all macros, leaving only the arguments (if present).
5208  % Of course this is not nearly correct, but it is the best we can do for now.
5209  % makeinfo does not expand macros in the argument to @deffn, which ends up
5210  % writing an index entry, and texindex isn't prepared for an index sort entry
5211  % that starts with \.
5212  %
5213  % Since macro invocations are followed by braces, we can just redefine them
5214  % to take a single TeX argument.  The case of a macro invocation that
5215  % goes to end-of-line is not handled.
5216  %
5217  \macrolist
5218  \let\value\indexnofontsvalue
5219}
5220\def\defglyph#1#2{\def#1##1{#2}} % see above
5221
5222
5223
5224
5225\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
5226
5227% #1 is the index name, #2 is the entry text.
5228\def\doind#1#2{%
5229  \iflinks
5230  {%
5231    %
5232    \requireopenindexfile{#1}%
5233    \edef\writeto{\csname#1indfile\endcsname}%
5234    %
5235    \def\indextext{#2}%
5236    \safewhatsit\doindwrite
5237  }%
5238  \fi
5239}
5240
5241% Check if an index file has been opened, and if not, open it.
5242\def\requireopenindexfile#1{%
5243\ifnum\csname #1indfile\endcsname=0
5244  \expandafter\newwrite \csname#1indfile\endcsname
5245  \edef\suffix{#1}%
5246  % A .fls suffix would conflict with the file extension for the output
5247  % of -recorder, so use .f1s instead.
5248  \ifx\suffix\indexisfl\def\suffix{f1}\fi
5249  % Open the file
5250  \immediate\openout\csname#1indfile\endcsname \jobname.\suffix
5251  % Using \immediate above here prevents an object entering into the current
5252  % box, which could confound checks such as those in \safewhatsit for
5253  % preceding skips.
5254  \typeout{Writing index file \jobname.\suffix}%
5255\fi}
5256\def\indexisfl{fl}
5257
5258% Output \ as {\indexbackslash}, because \ is an escape character in
5259% the index files.
5260\let\indexbackslash=\relax
5261{\catcode`\@=0 \catcode`\\=\active
5262  @gdef@useindexbackslash{@def\{{@indexbackslash}}}
5263}
5264
5265% Definition for writing index entry sort key.
5266{
5267\catcode`\-=13
5268\gdef\indexwritesortas{%
5269  \begingroup
5270  \indexnonalnumreappear
5271  \indexwritesortasxxx}
5272\gdef\indexwritesortasxxx#1{%
5273  \xdef\indexsortkey{#1}\endgroup}
5274}
5275
5276% Given index entry text like "aaa @subentry bbb @sortas{ZZZ}":
5277%   * Set \bracedtext to "{aaa}{bbb}"
5278%   * Set \fullindexsortkey to "aaa @subentry ZZZ"
5279%
5280\def\splitindexentry#1{%
5281  \gdef\fullindexsortkey{}%
5282  \xdef\bracedtext{}%
5283  \def\sep{}%
5284  \expandafter\doindexsegment#1\subentry\finish\subentry
5285}
5286
5287% append the results from the next segment
5288\def\doindexsegment#1\subentry{%
5289  \def\segment{#1}%
5290  \ifx\segment\isfinish
5291  \else
5292    %
5293    % Fully expand the segment, throwing away any @sortas directives, and
5294    % trim spaces.
5295    \def\sortas##1{}%
5296    \edef\trimmed{\segment}%
5297    \edef\trimmed{\expandafter\eatspaces\expandafter{\trimmed}}%
5298    %
5299    \xdef\bracedtext{\bracedtext{\trimmed}}%
5300    %
5301    % Get the string to sort by.  Process the segment with all
5302    % font commands turned off.
5303    \bgroup
5304      \let\sortas\indexwritesortas
5305      \indexnofonts
5306      % The braces around the commands are recognized by texindex.
5307      \def\lbracechar{{\indexlbrace}}%
5308      \def\rbracechar{{\indexrbrace}}%
5309      \let\{=\lbracechar
5310      \let\}=\rbracechar
5311      %
5312      \let\indexsortkey\empty
5313      % Execute the segment and throw away the typeset output.  This executes
5314      % any @sortas commands in this segment.
5315      \setbox\dummybox = \hbox{\segment}%
5316      \ifx\indexsortkey\empty{%
5317        \indexnonalnumdisappear
5318        \xdef\trimmed{\segment}%
5319        \xdef\trimmed{\expandafter\eatspaces\expandafter{\trimmed}}%
5320        \xdef\indexsortkey{\trimmed}%
5321        \ifx\indexsortkey\empty\xdef\indexsortkey{ }\fi
5322      }\fi
5323      %
5324      % Append to \fullindexsortkey.
5325      \edef\tmp{\gdef\noexpand\fullindexsortkey{%
5326                  \fullindexsortkey\sep\indexsortkey}}%
5327      \tmp
5328    \egroup
5329    \def\sep{\subentry}%
5330    %
5331    \expandafter\doindexsegment
5332  \fi
5333}
5334\def\isfinish{\finish}%
5335
5336\let\subentry\relax
5337
5338% Write the entry in \toks0 to the index file.
5339%
5340\def\doindwrite{%
5341  % Put the index entry in the margin if desired.
5342  \ifx\SETmarginindex\relax\else
5343    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
5344  \fi
5345  %
5346  % Remember, we are within a group.
5347  \indexdummies % Must do this here, since \bf, etc expand at this stage
5348  \useindexbackslash % \indexbackslash isn't defined now so it will be output
5349                     % as is; and it will print as backslash.
5350  %
5351  % Split the entry into primary entry and any subentries, and get the index
5352  % sort key.
5353  \splitindexentry\indextext
5354  %
5355  % Set up the complete index entry, with both the sort key and
5356  % the original text, including any font commands.  We write
5357  % three arguments to \entry to the .?? file (four in the
5358  % subentry case), texindex reduces to two when writing the .??s
5359  % sorted result.
5360  %
5361  \edef\temp{%
5362    \write\writeto{%
5363      \string\entry{\fullindexsortkey}{\noexpand\folio}\bracedtext}%
5364  }%
5365  \temp
5366}
5367\newbox\dummybox % used above
5368
5369% Take care of unwanted page breaks/skips around a whatsit:
5370%
5371% If a skip is the last thing on the list now, preserve it
5372% by backing up by \lastskip, doing the \write, then inserting
5373% the skip again.  Otherwise, the whatsit generated by the
5374% \write or \pdfdest will make \lastskip zero.  The result is that
5375% sequences like this:
5376% @end defun
5377% @tindex whatever
5378% @defun ...
5379% will have extra space inserted, because the \medbreak in the
5380% start of the @defun won't see the skip inserted by the @end of
5381% the previous defun.
5382%
5383% But don't do any of this if we're not in vertical mode.  We
5384% don't want to do a \vskip and prematurely end a paragraph.
5385%
5386% Avoid page breaks due to these extra skips, too.
5387%
5388% But wait, there is a catch there:
5389% We'll have to check whether \lastskip is zero skip.  \ifdim is not
5390% sufficient for this purpose, as it ignores stretch and shrink parts
5391% of the skip.  The only way seems to be to check the textual
5392% representation of the skip.
5393%
5394% The following is almost like \def\zeroskipmacro{0.0pt} except that
5395% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
5396%
5397\edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
5398%
5399\newskip\whatsitskip
5400\newcount\whatsitpenalty
5401%
5402% ..., ready, GO:
5403%
5404\def\safewhatsit#1{\ifhmode
5405  #1%
5406 \else
5407  % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
5408  \whatsitskip = \lastskip
5409  \edef\lastskipmacro{\the\lastskip}%
5410  \whatsitpenalty = \lastpenalty
5411  %
5412  % If \lastskip is nonzero, that means the last item was a
5413  % skip.  And since a skip is discardable, that means this
5414  % -\whatsitskip glue we're inserting is preceded by a
5415  % non-discardable item, therefore it is not a potential
5416  % breakpoint, therefore no \nobreak needed.
5417  \ifx\lastskipmacro\zeroskipmacro
5418  \else
5419    \vskip-\whatsitskip
5420  \fi
5421  %
5422  #1%
5423  %
5424  \ifx\lastskipmacro\zeroskipmacro
5425    % If \lastskip was zero, perhaps the last item was a penalty, and
5426    % perhaps it was >=10000, e.g., a \nobreak.  In that case, we want
5427    % to re-insert the same penalty (values >10000 are used for various
5428    % signals); since we just inserted a non-discardable item, any
5429    % following glue (such as a \parskip) would be a breakpoint.  For example:
5430    %   @deffn deffn-whatever
5431    %   @vindex index-whatever
5432    %   Description.
5433    % would allow a break between the index-whatever whatsit
5434    % and the "Description." paragraph.
5435    \ifnum\whatsitpenalty>9999 \penalty\whatsitpenalty \fi
5436  \else
5437    % On the other hand, if we had a nonzero \lastskip,
5438    % this make-up glue would be preceded by a non-discardable item
5439    % (the whatsit from the \write), so we must insert a \nobreak.
5440    \nobreak\vskip\whatsitskip
5441  \fi
5442\fi}
5443
5444% The index entry written in the file actually looks like
5445%  \entry {sortstring}{page}{topic}
5446% or
5447%  \entry {sortstring}{page}{topic}{subtopic}
5448% The texindex program reads in these files and writes files
5449% containing these kinds of lines:
5450%  \initial {c}
5451%     before the first topic whose initial is c
5452%  \entry {topic}{pagelist}
5453%     for a topic that is used without subtopics
5454%  \primary {topic}
5455%     for the beginning of a topic that is used with subtopics
5456%  \secondary {subtopic}{pagelist}
5457%     for each subtopic.
5458
5459% Define the user-accessible indexing commands
5460% @findex, @vindex, @kindex, @cindex.
5461
5462\def\findex {\fnindex}
5463\def\kindex {\kyindex}
5464\def\cindex {\cpindex}
5465\def\vindex {\vrindex}
5466\def\tindex {\tpindex}
5467\def\pindex {\pgindex}
5468
5469% Define the macros used in formatting output of the sorted index material.
5470
5471% @printindex causes a particular index (the ??s file) to get printed.
5472% It does not print any chapter heading (usually an @unnumbered).
5473%
5474\parseargdef\printindex{\begingroup
5475  \dobreak \chapheadingskip{10000}%
5476  %
5477  \smallfonts \rm
5478  \tolerance = 9500
5479  \plainfrenchspacing
5480  \everypar = {}% don't want the \kern\-parindent from indentation suppression.
5481  %
5482  % See if the index file exists and is nonempty.
5483  % Change catcode of @ here so that if the index file contains
5484  % \initial {@}
5485  % as its first line, TeX doesn't complain about mismatched braces
5486  % (because it thinks @} is a control sequence).
5487  \catcode`\@ = 12
5488  % See comment in \requireopenindexfile.
5489  \def\indexname{#1}\ifx\indexname\indexisfl\def\indexname{f1}\fi
5490  \openin 1 \jobname.\indexname s
5491  \ifeof 1
5492    % \enddoublecolumns gets confused if there is no text in the index,
5493    % and it loses the chapter title and the aux file entries for the
5494    % index.  The easiest way to prevent this problem is to make sure
5495    % there is some text.
5496    \putwordIndexNonexistent
5497    \typeout{No file \jobname.\indexname s.}%
5498  \else
5499    \catcode`\\ = 0
5500    %
5501    % If the index file exists but is empty, then \openin leaves \ifeof
5502    % false.  We have to make TeX try to read something from the file, so
5503    % it can discover if there is anything in it.
5504    \read 1 to \thisline
5505    \ifeof 1
5506      \putwordIndexIsEmpty
5507    \else
5508      % Index files are almost Texinfo source, but we use \ as the escape
5509      % character.  It would be better to use @, but that's too big a change
5510      % to make right now.
5511      \def\indexbackslash{\ttbackslash}%
5512      \let\indexlbrace\{   % Likewise, set these sequences for braces
5513      \let\indexrbrace\}   % used in the sort key.
5514      \begindoublecolumns
5515      \let\dotheinsertentrybox\dotheinsertentryboxwithpenalty
5516      %
5517      % Read input from the index file line by line.
5518      \loopdo
5519        \ifeof1 \else
5520          \read 1 to \nextline
5521        \fi
5522        %
5523        \indexinputprocessing
5524        \thisline
5525        %
5526        \ifeof1\else
5527        \let\thisline\nextline
5528      \repeat
5529      %%
5530      \enddoublecolumns
5531    \fi
5532  \fi
5533  \closein 1
5534\endgroup}
5535\def\loopdo#1\repeat{\def\body{#1}\loopdoxxx}
5536\def\loopdoxxx{\let\next=\relax\body\let\next=\loopdoxxx\fi\next}
5537
5538\def\indexinputprocessing{%
5539  \ifeof1
5540    \let\firsttoken\relax
5541  \else
5542    \edef\act{\gdef\noexpand\firsttoken{\getfirsttoken\nextline}}%
5543    \act
5544  \fi
5545}
5546\def\getfirsttoken#1{\expandafter\getfirsttokenx#1\endfirsttoken}
5547\long\def\getfirsttokenx#1#2\endfirsttoken{\noexpand#1}
5548
5549
5550% These macros are used by the sorted index file itself.
5551% Change them to control the appearance of the index.
5552
5553{\catcode`\/=13 \catcode`\-=13 \catcode`\^=13 \catcode`\~=13 \catcode`\_=13
5554\catcode`\|=13 \catcode`\<=13 \catcode`\>=13 \catcode`\+=13 \catcode`\"=13
5555\catcode`\$=3
5556\gdef\initialglyphs{%
5557  % Some changes for non-alphabetic characters.  Using the glyphs from the
5558  % math fonts looks more consistent than the typewriter font used elsewhere
5559  % for these characters.
5560  \def\indexbackslash{\math{\backslash}}%
5561  \let\\=\indexbackslash
5562  %
5563  % Can't get bold backslash so don't use bold forward slash
5564  \catcode`\/=13
5565  \def/{{\secrmnotbold \normalslash}}%
5566  \def-{{\normaldash\normaldash}}% en dash `--'
5567  \def^{{\chapbf \normalcaret}}%
5568  \def~{{\chapbf \normaltilde}}%
5569  \def\_{%
5570     \leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }%
5571  \def|{$\vert$}%
5572  \def<{$\less$}%
5573  \def>{$\gtr$}%
5574  \def+{$\normalplus$}%
5575}}
5576
5577\def\initial{%
5578  \bgroup
5579  \initialglyphs
5580  \initialx
5581}
5582
5583\def\initialx#1{%
5584  % Remove any glue we may have, we'll be inserting our own.
5585  \removelastskip
5586  %
5587  % We like breaks before the index initials, so insert a bonus.
5588  % The glue before the bonus allows a little bit of space at the
5589  % bottom of a column to reduce an increase in inter-line spacing.
5590  \nobreak
5591  \vskip 0pt plus 5\baselineskip
5592  \penalty -300
5593  \vskip 0pt plus -5\baselineskip
5594  %
5595  % Typeset the initial.  Making this add up to a whole number of
5596  % baselineskips increases the chance of the dots lining up from column
5597  % to column.  It still won't often be perfect, because of the stretch
5598  % we need before each entry, but it's better.
5599  %
5600  % No shrink because it confuses \balancecolumns.
5601  \vskip 1.67\baselineskip plus 1\baselineskip
5602  \leftline{\secfonts \kern-0.05em \secbf #1}%
5603  % \secfonts is inside the argument of \leftline so that the change of
5604  % \baselineskip will not affect any glue inserted before the vbox that
5605  % \leftline creates.
5606  % Do our best not to break after the initial.
5607  \nobreak
5608  \vskip .33\baselineskip plus .1\baselineskip
5609  \egroup % \initialglyphs
5610}
5611
5612\newdimen\entryrightmargin
5613\entryrightmargin=0pt
5614
5615% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
5616% then page number (#2) flushed to the right margin.  It is used for index
5617% and table of contents entries.  The paragraph is indented by \leftskip.
5618%
5619\def\entry{%
5620  \begingroup
5621    %
5622    % For pdfTeX and XeTeX.
5623    % The redefinition of \domark stops marks being added in \pdflink to
5624    % preserve coloured links across page boundaries.  Otherwise the marks
5625    % would get in the way of \lastbox in \insertentrybox.
5626    \let\domark\relax
5627    %
5628    % Start a new paragraph if necessary, so our assignments below can't
5629    % affect previous text.
5630    \par
5631    %
5632    % No extra space above this paragraph.
5633    \parskip = 0in
5634    %
5635    % When reading the text of entry, convert explicit line breaks
5636    % from @* into spaces.  The user might give these in long section
5637    % titles, for instance.
5638    \def\*{\unskip\space\ignorespaces}%
5639    \def\entrybreak{\hfil\break}% An undocumented command
5640    %
5641    % Swallow the left brace of the text (first parameter):
5642    \afterassignment\doentry
5643    \let\temp =
5644}
5645\def\entrybreak{\unskip\space\ignorespaces}%
5646\def\doentry{%
5647    % Save the text of the entry
5648    \global\setbox\boxA=\hbox\bgroup
5649    \bgroup % Instead of the swallowed brace.
5650      \noindent
5651      \aftergroup\finishentry
5652      % And now comes the text of the entry.
5653      % Not absorbing as a macro argument reduces the chance of problems
5654      % with catcodes occurring.
5655}
5656{\catcode`\@=11
5657\gdef\finishentry#1{%
5658    \egroup % end box A
5659    \dimen@ = \wd\boxA % Length of text of entry
5660    \global\setbox\boxA=\hbox\bgroup\unhbox\boxA
5661    % #1 is the page number.
5662    %
5663    % Get the width of the page numbers, and only use
5664    % leaders if they are present.
5665    \global\setbox\boxB = \hbox{#1}%
5666    \ifdim\wd\boxB = 0pt
5667      \null\nobreak\hfill\ %
5668    \else
5669      %
5670      \null\nobreak\indexdotfill % Have leaders before the page number.
5671      %
5672      \ifpdf
5673        \pdfgettoks#1.%
5674        \hskip\skip\thinshrinkable\the\toksA
5675      \else
5676        \ifx\XeTeXrevision\thisisundefined
5677          \hskip\skip\thinshrinkable #1%
5678        \else
5679          \pdfgettoks#1.%
5680          \hskip\skip\thinshrinkable\the\toksA
5681        \fi
5682      \fi
5683    \fi
5684    \egroup % end \boxA
5685    \ifdim\wd\boxB = 0pt
5686      \global\setbox\entrybox=\vbox{\unhbox\boxA}%
5687    \else
5688    \global\setbox\entrybox=\vbox\bgroup
5689      % We want the text of the entries to be aligned to the left, and the
5690      % page numbers to be aligned to the right.
5691      %
5692      \parindent = 0pt
5693      \advance\leftskip by 0pt plus 1fil
5694      \advance\leftskip by 0pt plus -1fill
5695      \rightskip = 0pt plus -1fil
5696      \advance\rightskip by 0pt plus 1fill
5697      % Cause last line, which could consist of page numbers on their own
5698      % if the list of page numbers is long, to be aligned to the right.
5699      \parfillskip=0pt plus -1fill
5700      %
5701      \advance\rightskip by \entryrightmargin
5702      % Determine how far we can stretch into the margin.
5703      % This allows, e.g., "Appendix H  GNU Free Documentation License" to
5704      % fit on one line in @letterpaper format.
5705      \ifdim\entryrightmargin>2.1em
5706        \dimen@i=2.1em
5707      \else
5708        \dimen@i=0em
5709      \fi
5710      \advance \parfillskip by 0pt minus 1\dimen@i
5711      %
5712      \dimen@ii = \hsize
5713      \advance\dimen@ii by -1\leftskip
5714      \advance\dimen@ii by -1\entryrightmargin
5715      \advance\dimen@ii by 1\dimen@i
5716      \ifdim\wd\boxA > \dimen@ii % If the entry doesn't fit in one line
5717      \ifdim\dimen@ > 0.8\dimen@ii   % due to long index text
5718        % Try to split the text roughly evenly.  \dimen@ will be the length of
5719        % the first line.
5720        \dimen@ = 0.7\dimen@
5721        \dimen@ii = \hsize
5722        \ifnum\dimen@>\dimen@ii
5723          % If the entry is too long (for example, if it needs more than
5724          % two lines), use all the space in the first line.
5725          \dimen@ = \dimen@ii
5726        \fi
5727        \advance\leftskip by 0pt plus 1fill % ragged right
5728        \advance \dimen@ by 1\rightskip
5729        \parshape = 2 0pt \dimen@ 0em \dimen@ii
5730        % Ideally we'd add a finite glue at the end of the first line only,
5731        % instead of using \parshape with explicit line lengths, but TeX
5732        % doesn't seem to provide a way to do such a thing.
5733        %
5734        % Indent all lines but the first one.
5735        \advance\leftskip by 1em
5736        \advance\parindent by -1em
5737      \fi\fi
5738      \indent % start paragraph
5739      \unhbox\boxA
5740      %
5741      % Do not prefer a separate line ending with a hyphen to fewer lines.
5742      \finalhyphendemerits = 0
5743      %
5744      % Word spacing - no stretch
5745      \spaceskip=\fontdimen2\font minus \fontdimen4\font
5746      %
5747      \linepenalty=1000  % Discourage line breaks.
5748      \hyphenpenalty=5000  % Discourage hyphenation.
5749      %
5750      \par % format the paragraph
5751    \egroup % The \vbox
5752    \fi
5753  \endgroup
5754  \dotheinsertentrybox
5755}}
5756
5757\newskip\thinshrinkable
5758\skip\thinshrinkable=.15em minus .15em
5759
5760\newbox\entrybox
5761\def\insertentrybox{%
5762  \ourunvbox\entrybox
5763}
5764
5765% default definition
5766\let\dotheinsertentrybox\insertentrybox
5767
5768% Use \lastbox to take apart vbox box by box, and add each sub-box
5769% to the current vertical list.
5770\def\ourunvbox#1{%
5771\bgroup % for local binding of \delayedbox
5772  % Remove the last box from box #1
5773  \global\setbox#1=\vbox{%
5774    \unvbox#1%
5775    \unskip % remove any glue
5776    \unpenalty
5777    \global\setbox\interbox=\lastbox
5778  }%
5779  \setbox\delayedbox=\box\interbox
5780  \ifdim\ht#1=0pt\else
5781    \ourunvbox#1 % Repeat on what's left of the box
5782    \nobreak
5783  \fi
5784  \box\delayedbox
5785\egroup
5786}
5787\newbox\delayedbox
5788\newbox\interbox
5789
5790% Used from \printindex.  \firsttoken should be the first token
5791% after the \entry.  If it's not another \entry, we are at the last
5792% line of a group of index entries, so insert a penalty to discourage
5793% widowed index entries.
5794\def\dotheinsertentryboxwithpenalty{%
5795  \ifx\firsttoken\isentry
5796  \else
5797    \penalty 9000
5798  \fi
5799  \insertentrybox
5800}
5801\def\isentry{\entry}%
5802
5803% Like plain.tex's \dotfill, except uses up at least 1 em.
5804% The filll stretch here overpowers both the fil and fill stretch to push
5805% the page number to the right.
5806\def\indexdotfill{\cleaders
5807  \hbox{$\mathsurround=0pt \mkern1.5mu.\mkern1.5mu$}\hskip 1em plus 1filll}
5808
5809
5810\def\primary #1{\line{#1\hfil}}
5811
5812\newskip\secondaryindent \secondaryindent=0.5cm
5813\def\secondary#1#2{{%
5814  \parfillskip=0in
5815  \parskip=0in
5816  \hangindent=1in
5817  \hangafter=1
5818  \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
5819  \ifpdf
5820    \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5821  \else
5822    \ifx\XeTeXrevision\thisisundefined
5823      #2
5824    \else
5825      \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5826    \fi
5827  \fi
5828  \par
5829}}
5830
5831% Define two-column mode, which we use to typeset indexes.
5832% Adapted from the TeXbook, page 416, which is to say,
5833% the manmac.tex format used to print the TeXbook itself.
5834\catcode`\@=11  % private names
5835
5836\newbox\partialpage
5837\newdimen\doublecolumnhsize
5838
5839\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
5840  % If not much space left on page, start a new page.
5841  \ifdim\pagetotal>0.8\vsize\vfill\eject\fi
5842  %
5843  % Grab any single-column material above us.
5844  \output = {%
5845    \savetopmark
5846    %
5847    % Here is a possibility not foreseen in manmac: if we accumulate a
5848    % whole lot of material, we might end up calling this \output
5849    % routine twice in a row (see the doublecol-lose test, which is
5850    % essentially a couple of indexes with @setchapternewpage off).  In
5851    % that case we just ship out what is in \partialpage with the normal
5852    % output routine.  Generally, \partialpage will be empty when this
5853    % runs and this will be a no-op.  See the indexspread.tex test case.
5854    \ifvoid\partialpage \else
5855      \onepageout{\pagecontents\partialpage}%
5856    \fi
5857    %
5858    \global\setbox\partialpage = \vbox{%
5859      % Unvbox the main output page.
5860      \unvbox\PAGE
5861      \kern-\topskip \kern\baselineskip
5862    }%
5863  }%
5864  \eject % run that output routine to set \partialpage
5865  %
5866  % Use the double-column output routine for subsequent pages.
5867  \output = {\doublecolumnout}%
5868  %
5869  % Change the page size parameters.  We could do this once outside this
5870  % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
5871  % format, but then we repeat the same computation.  Repeating a couple
5872  % of assignments once per index is clearly meaningless for the
5873  % execution time, so we may as well do it in one place.
5874  %
5875  % First we halve the line length, less a little for the gutter between
5876  % the columns.  We compute the gutter based on the line length, so it
5877  % changes automatically with the paper format.  The magic constant
5878  % below is chosen so that the gutter has the same value (well, +-<1pt)
5879  % as it did when we hard-coded it.
5880  %
5881  % We put the result in a separate register, \doublecolumhsize, so we
5882  % can restore it in \pagesofar, after \hsize itself has (potentially)
5883  % been clobbered.
5884  %
5885  \doublecolumnhsize = \hsize
5886    \advance\doublecolumnhsize by -.04154\hsize
5887    \divide\doublecolumnhsize by 2
5888  \hsize = \doublecolumnhsize
5889  %
5890  % Get the available space for the double columns -- the normal
5891  % (undoubled) page height minus any material left over from the
5892  % previous page.
5893  \advance\vsize by -\ht\partialpage
5894  \vsize = 2\vsize
5895  %
5896  % For the benefit of balancing columns
5897  \advance\baselineskip by 0pt plus 0.5pt
5898}
5899
5900% The double-column output routine for all double-column pages except
5901% the last, which is done by \balancecolumns.
5902%
5903\def\doublecolumnout{%
5904  %
5905  \savetopmark
5906  \splittopskip=\topskip \splitmaxdepth=\maxdepth
5907  \dimen@ = \vsize
5908  \divide\dimen@ by 2
5909  %
5910  % box0 will be the left-hand column, box2 the right.
5911  \setbox0=\vsplit\PAGE to\dimen@ \setbox2=\vsplit\PAGE to\dimen@
5912  \global\advance\vsize by 2\ht\partialpage
5913  \onepageout\pagesofar % empty except for the first time we are called
5914  \unvbox\PAGE
5915  \penalty\outputpenalty
5916}
5917%
5918% Re-output the contents of the output page -- any previous material,
5919% followed by the two boxes we just split, in box0 and box2.
5920\def\pagesofar{%
5921  \unvbox\partialpage
5922  %
5923  \hsize = \doublecolumnhsize
5924  \wd0=\hsize \wd2=\hsize
5925  \hbox to\txipagewidth{\box0\hfil\box2}%
5926}
5927
5928
5929% Finished with with double columns.
5930\def\enddoublecolumns{%
5931  % The following penalty ensures that the page builder is exercised
5932  % _before_ we change the output routine.  This is necessary in the
5933  % following situation:
5934  %
5935  % The last section of the index consists only of a single entry.
5936  % Before this section, \pagetotal is less than \pagegoal, so no
5937  % break occurs before the last section starts.  However, the last
5938  % section, consisting of \initial and the single \entry, does not
5939  % fit on the page and has to be broken off.  Without the following
5940  % penalty the page builder will not be exercised until \eject
5941  % below, and by that time we'll already have changed the output
5942  % routine to the \balancecolumns version, so the next-to-last
5943  % double-column page will be processed with \balancecolumns, which
5944  % is wrong:  The two columns will go to the main vertical list, with
5945  % the broken-off section in the recent contributions.  As soon as
5946  % the output routine finishes, TeX starts reconsidering the page
5947  % break.  The two columns and the broken-off section both fit on the
5948  % page, because the two columns now take up only half of the page
5949  % goal.  When TeX sees \eject from below which follows the final
5950  % section, it invokes the new output routine that we've set after
5951  % \balancecolumns below; \onepageout will try to fit the two columns
5952  % and the final section into the vbox of \txipageheight (see
5953  % \pagebody), causing an overfull box.
5954  %
5955  % Note that glue won't work here, because glue does not exercise the
5956  % page builder, unlike penalties (see The TeXbook, pp. 280-281).
5957  \penalty0
5958  %
5959  \output = {%
5960    % Split the last of the double-column material.
5961    \savetopmark
5962    \balancecolumns
5963  }%
5964  \eject % call the \output just set
5965  \ifdim\pagetotal=0pt
5966    % Having called \balancecolumns once, we do not
5967    % want to call it again.  Therefore, reset \output to its normal
5968    % definition right away.
5969    \global\output=\expandafter{\the\defaultoutput}
5970    %
5971    \endgroup % started in \begindoublecolumns
5972    % Leave the double-column material on the current page, no automatic
5973    % page break.
5974    \box\balancedcolumns
5975    %
5976    % \pagegoal was set to the doubled \vsize above, since we restarted
5977    % the current page.  We're now back to normal single-column
5978    % typesetting, so reset \pagegoal to the normal \vsize.
5979    \global\vsize = \txipageheight %
5980    \pagegoal = \txipageheight %
5981  \else
5982    % We had some left-over material.  This might happen when \doublecolumnout
5983    % is called in \balancecolumns.  Try again.
5984    \expandafter\enddoublecolumns
5985  \fi
5986}
5987\newbox\balancedcolumns
5988\setbox\balancedcolumns=\vbox{shouldnt see this}%
5989%
5990% Only called for the last of the double column material.  \doublecolumnout
5991% does the others.
5992\def\balancecolumns{%
5993  \setbox0 = \vbox{\unvbox\PAGE}% like \box255 but more efficient, see p.120.
5994  \dimen@ = \ht0
5995  \ifdim\dimen@<7\baselineskip
5996    % Don't split a short final column in two.
5997    \setbox2=\vbox{}%
5998    \global\setbox\balancedcolumns=\vbox{\pagesofar}%
5999  \else
6000    % double the leading vertical space
6001    \advance\dimen@ by \topskip
6002    \advance\dimen@ by-\baselineskip
6003    \divide\dimen@ by 2 % target to split to
6004    \dimen@ii = \dimen@
6005    \splittopskip = \topskip
6006    % Loop until left column is at least as high as the right column.
6007    {%
6008      \vbadness = 10000
6009      \loop
6010        \global\setbox3 = \copy0
6011        \global\setbox1 = \vsplit3 to \dimen@
6012      \ifdim\ht1<\ht3
6013        \global\advance\dimen@ by 1pt
6014      \repeat
6015    }%
6016    % Now the left column is in box 1, and the right column in box 3.
6017    %
6018    % Check whether the left column has come out higher than the page itself.
6019    % (Note that we have doubled \vsize for the double columns, so
6020    % the actual height of the page is 0.5\vsize).
6021    \ifdim2\ht1>\vsize
6022      % It appears that we have been called upon to balance too much material.
6023      % Output some of it with \doublecolumnout, leaving the rest on the page.
6024      \setbox\PAGE=\box0
6025      \doublecolumnout
6026    \else
6027      % Compare the heights of the two columns.
6028      \ifdim4\ht1>5\ht3
6029        % Column heights are too different, so don't make their bottoms
6030        % flush with each other.
6031        \setbox2=\vbox to \ht1 {\unvbox3\vfill}%
6032        \setbox0=\vbox to \ht1 {\unvbox1\vfill}%
6033      \else
6034        % Make column bottoms flush with each other.
6035        \setbox2=\vbox to\ht1{\unvbox3\unskip}%
6036        \setbox0=\vbox to\ht1{\unvbox1\unskip}%
6037      \fi
6038      \global\setbox\balancedcolumns=\vbox{\pagesofar}%
6039    \fi
6040  \fi
6041  %
6042}
6043\catcode`\@ = \other
6044
6045
6046\message{sectioning,}
6047% Chapters, sections, etc.
6048
6049% Let's start with @part.
6050\outer\parseargdef\part{\partzzz{#1}}
6051\def\partzzz#1{%
6052  \chapoddpage
6053  \null
6054  \vskip.3\vsize  % move it down on the page a bit
6055  \begingroup
6056    \noindent \titlefonts\rm #1\par % the text
6057    \let\lastnode=\empty      % no node to associate with
6058    \writetocentry{part}{#1}{}% but put it in the toc
6059    \headingsoff              % no headline or footline on the part page
6060    % This outputs a mark at the end of the page that clears \thischapter
6061    % and \thissection, as is done in \startcontents.
6062    \let\pchapsepmacro\relax
6063    \chapmacro{}{Yomitfromtoc}{}%
6064    \chapoddpage
6065  \endgroup
6066}
6067
6068% \unnumberedno is an oxymoron.  But we count the unnumbered
6069% sections so that we can refer to them unambiguously in the pdf
6070% outlines by their "section number".  We avoid collisions with chapter
6071% numbers by starting them at 10000.  (If a document ever has 10000
6072% chapters, we're in trouble anyway, I'm sure.)
6073\newcount\unnumberedno \unnumberedno = 10000
6074\newcount\chapno
6075\newcount\secno        \secno=0
6076\newcount\subsecno     \subsecno=0
6077\newcount\subsubsecno  \subsubsecno=0
6078
6079% This counter is funny since it counts through charcodes of letters A, B, ...
6080\newcount\appendixno  \appendixno = `\@
6081%
6082% \def\appendixletter{\char\the\appendixno}
6083% We do the following ugly conditional instead of the above simple
6084% construct for the sake of pdftex, which needs the actual
6085% letter in the expansion, not just typeset.
6086%
6087\def\appendixletter{%
6088  \ifnum\appendixno=`A A%
6089  \else\ifnum\appendixno=`B B%
6090  \else\ifnum\appendixno=`C C%
6091  \else\ifnum\appendixno=`D D%
6092  \else\ifnum\appendixno=`E E%
6093  \else\ifnum\appendixno=`F F%
6094  \else\ifnum\appendixno=`G G%
6095  \else\ifnum\appendixno=`H H%
6096  \else\ifnum\appendixno=`I I%
6097  \else\ifnum\appendixno=`J J%
6098  \else\ifnum\appendixno=`K K%
6099  \else\ifnum\appendixno=`L L%
6100  \else\ifnum\appendixno=`M M%
6101  \else\ifnum\appendixno=`N N%
6102  \else\ifnum\appendixno=`O O%
6103  \else\ifnum\appendixno=`P P%
6104  \else\ifnum\appendixno=`Q Q%
6105  \else\ifnum\appendixno=`R R%
6106  \else\ifnum\appendixno=`S S%
6107  \else\ifnum\appendixno=`T T%
6108  \else\ifnum\appendixno=`U U%
6109  \else\ifnum\appendixno=`V V%
6110  \else\ifnum\appendixno=`W W%
6111  \else\ifnum\appendixno=`X X%
6112  \else\ifnum\appendixno=`Y Y%
6113  \else\ifnum\appendixno=`Z Z%
6114  % The \the is necessary, despite appearances, because \appendixletter is
6115  % expanded while writing the .toc file.  \char\appendixno is not
6116  % expandable, thus it is written literally, thus all appendixes come out
6117  % with the same letter (or @) in the toc without it.
6118  \else\char\the\appendixno
6119  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
6120  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
6121
6122% Each @chapter defines these (using marks) as the number+name, number
6123% and name of the chapter.  Page headings and footings can use
6124% these.  @section does likewise.
6125\def\thischapter{}
6126\def\thischapternum{}
6127\def\thischaptername{}
6128\def\thissection{}
6129\def\thissectionnum{}
6130\def\thissectionname{}
6131
6132\newcount\absseclevel % used to calculate proper heading level
6133\newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
6134
6135% @raisesections: treat @section as chapter, @subsection as section, etc.
6136\def\raisesections{\global\advance\secbase by -1}
6137\let\up=\raisesections % original BFox name
6138
6139% @lowersections: treat @chapter as section, @section as subsection, etc.
6140\def\lowersections{\global\advance\secbase by 1}
6141\let\down=\lowersections % original BFox name
6142
6143% we only have subsub.
6144\chardef\maxseclevel = 3
6145%
6146% A numbered section within an unnumbered changes to unnumbered too.
6147% To achieve this, remember the "biggest" unnum. sec. we are currently in:
6148\chardef\unnlevel = \maxseclevel
6149%
6150% Trace whether the current chapter is an appendix or not:
6151% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
6152\def\chapheadtype{N}
6153
6154% Choose a heading macro
6155% #1 is heading type
6156% #2 is heading level
6157% #3 is text for heading
6158\def\genhead#1#2#3{%
6159  % Compute the abs. sec. level:
6160  \absseclevel=#2
6161  \advance\absseclevel by \secbase
6162  % Make sure \absseclevel doesn't fall outside the range:
6163  \ifnum \absseclevel < 0
6164    \absseclevel = 0
6165  \else
6166    \ifnum \absseclevel > 3
6167      \absseclevel = 3
6168    \fi
6169  \fi
6170  % The heading type:
6171  \def\headtype{#1}%
6172  \if \headtype U%
6173    \ifnum \absseclevel < \unnlevel
6174      \chardef\unnlevel = \absseclevel
6175    \fi
6176  \else
6177    % Check for appendix sections:
6178    \ifnum \absseclevel = 0
6179      \edef\chapheadtype{\headtype}%
6180    \else
6181      \if \headtype A\if \chapheadtype N%
6182	\errmessage{@appendix... within a non-appendix chapter}%
6183      \fi\fi
6184    \fi
6185    % Check for numbered within unnumbered:
6186    \ifnum \absseclevel > \unnlevel
6187      \def\headtype{U}%
6188    \else
6189      \chardef\unnlevel = 3
6190    \fi
6191  \fi
6192  % Now print the heading:
6193  \if \headtype U%
6194    \ifcase\absseclevel
6195	\unnumberedzzz{#3}%
6196    \or \unnumberedseczzz{#3}%
6197    \or \unnumberedsubseczzz{#3}%
6198    \or \unnumberedsubsubseczzz{#3}%
6199    \fi
6200  \else
6201    \if \headtype A%
6202      \ifcase\absseclevel
6203	  \appendixzzz{#3}%
6204      \or \appendixsectionzzz{#3}%
6205      \or \appendixsubseczzz{#3}%
6206      \or \appendixsubsubseczzz{#3}%
6207      \fi
6208    \else
6209      \ifcase\absseclevel
6210	  \chapterzzz{#3}%
6211      \or \seczzz{#3}%
6212      \or \numberedsubseczzz{#3}%
6213      \or \numberedsubsubseczzz{#3}%
6214      \fi
6215    \fi
6216  \fi
6217  \suppressfirstparagraphindent
6218}
6219
6220% an interface:
6221\def\numhead{\genhead N}
6222\def\apphead{\genhead A}
6223\def\unnmhead{\genhead U}
6224
6225% @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
6226% all lower-level sectioning counters to zero.
6227%
6228% Also set \chaplevelprefix, which we prepend to @float sequence numbers
6229% (e.g., figures), q.v.  By default (before any chapter), that is empty.
6230\let\chaplevelprefix = \empty
6231%
6232\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
6233\def\chapterzzz#1{%
6234  % section resetting is \global in case the chapter is in a group, such
6235  % as an @include file.
6236  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6237    \global\advance\chapno by 1
6238  %
6239  % Used for \float.
6240  \gdef\chaplevelprefix{\the\chapno.}%
6241  \resetallfloatnos
6242  %
6243  % \putwordChapter can contain complex things in translations.
6244  \toks0=\expandafter{\putwordChapter}%
6245  \message{\the\toks0 \space \the\chapno}%
6246  %
6247  % Write the actual heading.
6248  \chapmacro{#1}{Ynumbered}{\the\chapno}%
6249  %
6250  % So @section and the like are numbered underneath this chapter.
6251  \global\let\section = \numberedsec
6252  \global\let\subsection = \numberedsubsec
6253  \global\let\subsubsection = \numberedsubsubsec
6254}
6255
6256\outer\parseargdef\appendix{\apphead0{#1}} % normally calls appendixzzz
6257%
6258\def\appendixzzz#1{%
6259  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6260    \global\advance\appendixno by 1
6261  \gdef\chaplevelprefix{\appendixletter.}%
6262  \resetallfloatnos
6263  %
6264  % \putwordAppendix can contain complex things in translations.
6265  \toks0=\expandafter{\putwordAppendix}%
6266  \message{\the\toks0 \space \appendixletter}%
6267  %
6268  \chapmacro{#1}{Yappendix}{\appendixletter}%
6269  %
6270  \global\let\section = \appendixsec
6271  \global\let\subsection = \appendixsubsec
6272  \global\let\subsubsection = \appendixsubsubsec
6273}
6274
6275% normally unnmhead0 calls unnumberedzzz:
6276\outer\parseargdef\unnumbered{\unnmhead0{#1}}
6277\def\unnumberedzzz#1{%
6278  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6279    \global\advance\unnumberedno by 1
6280  %
6281  % Since an unnumbered has no number, no prefix for figures.
6282  \global\let\chaplevelprefix = \empty
6283  \resetallfloatnos
6284  %
6285  % This used to be simply \message{#1}, but TeX fully expands the
6286  % argument to \message.  Therefore, if #1 contained @-commands, TeX
6287  % expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
6288  % expanded @cite (which turns out to cause errors because \cite is meant
6289  % to be executed, not expanded).
6290  %
6291  % Anyway, we don't want the fully-expanded definition of @cite to appear
6292  % as a result of the \message, we just want `@cite' itself.  We use
6293  % \the<toks register> to achieve this: TeX expands \the<toks> only once,
6294  % simply yielding the contents of <toks register>.  (We also do this for
6295  % the toc entries.)
6296  \toks0 = {#1}%
6297  \message{(\the\toks0)}%
6298  %
6299  \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
6300  %
6301  \global\let\section = \unnumberedsec
6302  \global\let\subsection = \unnumberedsubsec
6303  \global\let\subsubsection = \unnumberedsubsubsec
6304}
6305
6306% @centerchap is like @unnumbered, but the heading is centered.
6307\outer\parseargdef\centerchap{%
6308  \let\centerparametersmaybe = \centerparameters
6309  \unnmhead0{#1}%
6310  \let\centerparametersmaybe = \relax
6311}
6312
6313% @top is like @unnumbered.
6314\let\top\unnumbered
6315
6316% Sections.
6317%
6318\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
6319\def\seczzz#1{%
6320  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6321  \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
6322}
6323
6324% normally calls appendixsectionzzz:
6325\outer\parseargdef\appendixsection{\apphead1{#1}}
6326\def\appendixsectionzzz#1{%
6327  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6328  \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
6329}
6330\let\appendixsec\appendixsection
6331
6332% normally calls unnumberedseczzz:
6333\outer\parseargdef\unnumberedsec{\unnmhead1{#1}}
6334\def\unnumberedseczzz#1{%
6335  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6336  \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
6337}
6338
6339% Subsections.
6340%
6341% normally calls numberedsubseczzz:
6342\outer\parseargdef\numberedsubsec{\numhead2{#1}}
6343\def\numberedsubseczzz#1{%
6344  \global\subsubsecno=0  \global\advance\subsecno by 1
6345  \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
6346}
6347
6348% normally calls appendixsubseczzz:
6349\outer\parseargdef\appendixsubsec{\apphead2{#1}}
6350\def\appendixsubseczzz#1{%
6351  \global\subsubsecno=0  \global\advance\subsecno by 1
6352  \sectionheading{#1}{subsec}{Yappendix}%
6353                 {\appendixletter.\the\secno.\the\subsecno}%
6354}
6355
6356% normally calls unnumberedsubseczzz:
6357\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}}
6358\def\unnumberedsubseczzz#1{%
6359  \global\subsubsecno=0  \global\advance\subsecno by 1
6360  \sectionheading{#1}{subsec}{Ynothing}%
6361                 {\the\unnumberedno.\the\secno.\the\subsecno}%
6362}
6363
6364% Subsubsections.
6365%
6366% normally numberedsubsubseczzz:
6367\outer\parseargdef\numberedsubsubsec{\numhead3{#1}}
6368\def\numberedsubsubseczzz#1{%
6369  \global\advance\subsubsecno by 1
6370  \sectionheading{#1}{subsubsec}{Ynumbered}%
6371                 {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
6372}
6373
6374% normally appendixsubsubseczzz:
6375\outer\parseargdef\appendixsubsubsec{\apphead3{#1}}
6376\def\appendixsubsubseczzz#1{%
6377  \global\advance\subsubsecno by 1
6378  \sectionheading{#1}{subsubsec}{Yappendix}%
6379                 {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
6380}
6381
6382% normally unnumberedsubsubseczzz:
6383\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}}
6384\def\unnumberedsubsubseczzz#1{%
6385  \global\advance\subsubsecno by 1
6386  \sectionheading{#1}{subsubsec}{Ynothing}%
6387                 {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
6388}
6389
6390% These macros control what the section commands do, according
6391% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
6392% Define them by default for a numbered chapter.
6393\let\section = \numberedsec
6394\let\subsection = \numberedsubsec
6395\let\subsubsection = \numberedsubsubsec
6396
6397% Define @majorheading, @heading and @subheading
6398
6399\def\majorheading{%
6400  {\advance\chapheadingskip by 10pt \chapbreak }%
6401  \parsearg\chapheadingzzz
6402}
6403
6404\def\chapheading{\chapbreak \parsearg\chapheadingzzz}
6405\def\chapheadingzzz#1{%
6406  \vbox{\chapfonts \raggedtitlesettings #1\par}%
6407  \nobreak\bigskip \nobreak
6408  \suppressfirstparagraphindent
6409}
6410
6411% @heading, @subheading, @subsubheading.
6412\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
6413  \suppressfirstparagraphindent}
6414\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
6415  \suppressfirstparagraphindent}
6416\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
6417  \suppressfirstparagraphindent}
6418
6419% These macros generate a chapter, section, etc. heading only
6420% (including whitespace, linebreaking, etc. around it),
6421% given all the information in convenient, parsed form.
6422
6423% Args are the skip and penalty (usually negative)
6424\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
6425
6426% Parameter controlling skip before chapter headings (if needed)
6427\newskip\chapheadingskip
6428
6429% Define plain chapter starts, and page on/off switching for it.
6430\def\chapbreak{\dobreak \chapheadingskip {-4000}}
6431
6432% Start a new page
6433\def\chappager{\par\vfill\supereject}
6434
6435% \chapoddpage - start on an odd page for a new chapter
6436% Because \domark is called before \chapoddpage, the filler page will
6437% get the headings for the next chapter, which is wrong.  But we don't
6438% care -- we just disable all headings on the filler page.
6439\def\chapoddpage{%
6440  \chappager
6441  \ifodd\pageno \else
6442    \begingroup
6443      \headingsoff
6444      \null
6445      \chappager
6446    \endgroup
6447  \fi
6448}
6449
6450\parseargdef\setchapternewpage{\csname CHAPPAG#1\endcsname}
6451
6452\def\CHAPPAGoff{%
6453\global\let\contentsalignmacro = \chappager
6454\global\let\pchapsepmacro=\chapbreak
6455\global\let\pagealignmacro=\chappager}
6456
6457\def\CHAPPAGon{%
6458\global\let\contentsalignmacro = \chappager
6459\global\let\pchapsepmacro=\chappager
6460\global\let\pagealignmacro=\chappager
6461\global\def\HEADINGSon{\HEADINGSsingle}}
6462
6463\def\CHAPPAGodd{%
6464\global\let\contentsalignmacro = \chapoddpage
6465\global\let\pchapsepmacro=\chapoddpage
6466\global\let\pagealignmacro=\chapoddpage
6467\global\def\HEADINGSon{\HEADINGSdouble}}
6468
6469\CHAPPAGon
6470
6471% \chapmacro - Chapter opening.
6472%
6473% #1 is the text, #2 is the section type (Ynumbered, Ynothing,
6474% Yappendix, Yomitfromtoc), #3 the chapter number.
6475% Not used for @heading series.
6476%
6477% To test against our argument.
6478\def\Ynothingkeyword{Ynothing}
6479\def\Yappendixkeyword{Yappendix}
6480\def\Yomitfromtockeyword{Yomitfromtoc}
6481%
6482\def\chapmacro#1#2#3{%
6483  \expandafter\ifx\thisenv\titlepage\else
6484    \checkenv{}% chapters, etc., should not start inside an environment.
6485  \fi
6486  % Insert the first mark before the heading break (see notes for \domark).
6487  \let\prevchapterdefs=\currentchapterdefs
6488  \let\prevsectiondefs=\currentsectiondefs
6489  \gdef\currentsectiondefs{\gdef\thissectionname{}\gdef\thissectionnum{}%
6490                        \gdef\thissection{}}%
6491  %
6492  \def\temptype{#2}%
6493  \ifx\temptype\Ynothingkeyword
6494    \gdef\currentchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6495                          \gdef\thischapter{\thischaptername}}%
6496  \else\ifx\temptype\Yomitfromtockeyword
6497    \gdef\currentchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6498                          \gdef\thischapter{}}%
6499  \else\ifx\temptype\Yappendixkeyword
6500    \toks0={#1}%
6501    \xdef\currentchapterdefs{%
6502      \gdef\noexpand\thischaptername{\the\toks0}%
6503      \gdef\noexpand\thischapternum{\appendixletter}%
6504      % \noexpand\putwordAppendix avoids expanding indigestible
6505      % commands in some of the translations.
6506      \gdef\noexpand\thischapter{\noexpand\putwordAppendix{}
6507                                 \noexpand\thischapternum:
6508                                 \noexpand\thischaptername}%
6509    }%
6510  \else
6511    \toks0={#1}%
6512    \xdef\currentchapterdefs{%
6513      \gdef\noexpand\thischaptername{\the\toks0}%
6514      \gdef\noexpand\thischapternum{\the\chapno}%
6515      % \noexpand\putwordChapter avoids expanding indigestible
6516      % commands in some of the translations.
6517      \gdef\noexpand\thischapter{\noexpand\putwordChapter{}
6518                                 \noexpand\thischapternum:
6519                                 \noexpand\thischaptername}%
6520    }%
6521  \fi\fi\fi
6522  %
6523  % Output the mark.  Pass it through \safewhatsit, to take care of
6524  % the preceding space.
6525  \safewhatsit\domark
6526  %
6527  % Insert the chapter heading break.
6528  \pchapsepmacro
6529  %
6530  % Now the second mark, after the heading break.  No break points
6531  % between here and the heading.
6532  \let\prevchapterdefs=\currentchapterdefs
6533  \let\prevsectiondefs=\currentsectiondefs
6534  \domark
6535  %
6536  {%
6537    \chapfonts \rm
6538    \let\footnote=\errfootnoteheading % give better error message
6539    %
6540    % Have to define \currentsection before calling \donoderef, because the
6541    % xref code eventually uses it.  On the other hand, it has to be called
6542    % after \pchapsepmacro, or the headline will change too soon.
6543    \gdef\currentsection{#1}%
6544    %
6545    % Only insert the separating space if we have a chapter/appendix
6546    % number, and don't print the unnumbered ``number''.
6547    \ifx\temptype\Ynothingkeyword
6548      \setbox0 = \hbox{}%
6549      \def\toctype{unnchap}%
6550    \else\ifx\temptype\Yomitfromtockeyword
6551      \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
6552      \def\toctype{omit}%
6553    \else\ifx\temptype\Yappendixkeyword
6554      \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
6555      \def\toctype{app}%
6556    \else
6557      \setbox0 = \hbox{#3\enspace}%
6558      \def\toctype{numchap}%
6559    \fi\fi\fi
6560    %
6561    % Write the toc entry for this chapter.  Must come before the
6562    % \donoderef, because we include the current node name in the toc
6563    % entry, and \donoderef resets it to empty.
6564    \writetocentry{\toctype}{#1}{#3}%
6565    %
6566    % For pdftex, we have to write out the node definition (aka, make
6567    % the pdfdest) after any page break, but before the actual text has
6568    % been typeset.  If the destination for the pdf outline is after the
6569    % text, then jumping from the outline may wind up with the text not
6570    % being visible, for instance under high magnification.
6571    \donoderef{#2}%
6572    %
6573    % Typeset the actual heading.
6574    \nobreak % Avoid page breaks at the interline glue.
6575    \vbox{\raggedtitlesettings \hangindent=\wd0 \centerparametersmaybe
6576          \unhbox0 #1\par}%
6577  }%
6578  \nobreak\bigskip % no page break after a chapter title
6579  \nobreak
6580}
6581
6582% @centerchap -- centered and unnumbered.
6583\let\centerparametersmaybe = \relax
6584\def\centerparameters{%
6585  \advance\rightskip by 3\rightskip
6586  \leftskip = \rightskip
6587  \parfillskip = 0pt
6588}
6589
6590
6591% Section titles.  These macros combine the section number parts and
6592% call the generic \sectionheading to do the printing.
6593%
6594\newskip\secheadingskip
6595\def\secheadingbreak{\dobreak \secheadingskip{-1000}}
6596
6597% Subsection titles.
6598\newskip\subsecheadingskip
6599\def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
6600
6601% Subsubsection titles.
6602\def\subsubsecheadingskip{\subsecheadingskip}
6603\def\subsubsecheadingbreak{\subsecheadingbreak}
6604
6605
6606% Print any size, any type, section title.
6607%
6608% #1 is the text of the title,
6609% #2 is the section level (sec/subsec/subsubsec),
6610% #3 is the section type (Ynumbered, Ynothing, Yappendix, Yomitfromtoc),
6611% #4 is the section number.
6612%
6613\def\seckeyword{sec}
6614%
6615\def\sectionheading#1#2#3#4{%
6616  {%
6617    \def\sectionlevel{#2}%
6618    \def\temptype{#3}%
6619    %
6620    % It is ok for the @heading series commands to appear inside an
6621    % environment (it's been historically allowed, though the logic is
6622    % dubious), but not the others.
6623    \ifx\temptype\Yomitfromtockeyword\else
6624      \checkenv{}% non-@*heading should not be in an environment.
6625    \fi
6626    \let\footnote=\errfootnoteheading
6627    %
6628    % Switch to the right set of fonts.
6629    \csname #2fonts\endcsname \rm
6630    %
6631    % Insert first mark before the heading break (see notes for \domark).
6632    \let\prevsectiondefs=\currentsectiondefs
6633    \ifx\temptype\Ynothingkeyword
6634      \ifx\sectionlevel\seckeyword
6635        \gdef\currentsectiondefs{\gdef\thissectionname{#1}\gdef\thissectionnum{}%
6636                              \gdef\thissection{\thissectionname}}%
6637      \fi
6638    \else\ifx\temptype\Yomitfromtockeyword
6639      % Don't redefine \thissection.
6640    \else\ifx\temptype\Yappendixkeyword
6641      \ifx\sectionlevel\seckeyword
6642        \toks0={#1}%
6643        \xdef\currentsectiondefs{%
6644          \gdef\noexpand\thissectionname{\the\toks0}%
6645          \gdef\noexpand\thissectionnum{#4}%
6646          % \noexpand\putwordSection avoids expanding indigestible
6647          % commands in some of the translations.
6648          \gdef\noexpand\thissection{\noexpand\putwordSection{}
6649                                     \noexpand\thissectionnum:
6650                                     \noexpand\thissectionname}%
6651        }%
6652      \fi
6653    \else
6654      \ifx\sectionlevel\seckeyword
6655        \toks0={#1}%
6656        \xdef\currentsectiondefs{%
6657          \gdef\noexpand\thissectionname{\the\toks0}%
6658          \gdef\noexpand\thissectionnum{#4}%
6659          % \noexpand\putwordSection avoids expanding indigestible
6660          % commands in some of the translations.
6661          \gdef\noexpand\thissection{\noexpand\putwordSection{}
6662                                     \noexpand\thissectionnum:
6663                                     \noexpand\thissectionname}%
6664        }%
6665      \fi
6666    \fi\fi\fi
6667    %
6668    % Go into vertical mode.  Usually we'll already be there, but we
6669    % don't want the following whatsit to end up in a preceding paragraph
6670    % if the document didn't happen to have a blank line.
6671    \par
6672    %
6673    % Output the mark.  Pass it through \safewhatsit, to take care of
6674    % the preceding space.
6675    \safewhatsit\domark
6676    %
6677    % Insert space above the heading.
6678    \csname #2headingbreak\endcsname
6679    %
6680    % Now the second mark, after the heading break.  No break points
6681    % between here and the heading.
6682    \global\let\prevsectiondefs=\currentsectiondefs
6683    \domark
6684    %
6685    % Only insert the space after the number if we have a section number.
6686    \ifx\temptype\Ynothingkeyword
6687      \setbox0 = \hbox{}%
6688      \def\toctype{unn}%
6689      \gdef\currentsection{#1}%
6690    \else\ifx\temptype\Yomitfromtockeyword
6691      % for @headings -- no section number, don't include in toc,
6692      % and don't redefine \currentsection.
6693      \setbox0 = \hbox{}%
6694      \def\toctype{omit}%
6695      \let\sectionlevel=\empty
6696    \else\ifx\temptype\Yappendixkeyword
6697      \setbox0 = \hbox{#4\enspace}%
6698      \def\toctype{app}%
6699      \gdef\currentsection{#1}%
6700    \else
6701      \setbox0 = \hbox{#4\enspace}%
6702      \def\toctype{num}%
6703      \gdef\currentsection{#1}%
6704    \fi\fi\fi
6705    %
6706    % Write the toc entry (before \donoderef).  See comments in \chapmacro.
6707    \writetocentry{\toctype\sectionlevel}{#1}{#4}%
6708    %
6709    % Write the node reference (= pdf destination for pdftex).
6710    % Again, see comments in \chapmacro.
6711    \donoderef{#3}%
6712    %
6713    % Interline glue will be inserted when the vbox is completed.
6714    % That glue will be a valid breakpoint for the page, since it'll be
6715    % preceded by a whatsit (usually from the \donoderef, or from the
6716    % \writetocentry if there was no node).  We don't want to allow that
6717    % break, since then the whatsits could end up on page n while the
6718    % section is on page n+1, thus toc/etc. are wrong.  Debian bug 276000.
6719    \nobreak
6720    %
6721    % Output the actual section heading.
6722    \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \ptexraggedright
6723          \hangindent=\wd0  % zero if no section number
6724          \unhbox0 #1}%
6725  }%
6726  % Add extra space after the heading -- half of whatever came above it.
6727  % Don't allow stretch, though.
6728  \kern .5 \csname #2headingskip\endcsname
6729  %
6730  % Do not let the kern be a potential breakpoint, as it would be if it
6731  % was followed by glue.
6732  \nobreak
6733  %
6734  % We'll almost certainly start a paragraph next, so don't let that
6735  % glue accumulate.  (Not a breakpoint because it's preceded by a
6736  % discardable item.)  However, when a paragraph is not started next
6737  % (\startdefun, \cartouche, \center, etc.), this needs to be wiped out
6738  % or the negative glue will cause weirdly wrong output, typically
6739  % obscuring the section heading with something else.
6740  \vskip-\parskip
6741  %
6742  % This is so the last item on the main vertical list is a known
6743  % \penalty > 10000, so \startdefun, etc., can recognize the situation
6744  % and do the needful.
6745  \penalty 10001
6746}
6747
6748
6749\message{toc,}
6750% Table of contents.
6751\newwrite\tocfile
6752
6753% Write an entry to the toc file, opening it if necessary.
6754% Called from @chapter, etc.
6755%
6756% Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
6757% We append the current node name (if any) and page number as additional
6758% arguments for the \{chap,sec,...}entry macros which will eventually
6759% read this.  The node name is used in the pdf outlines as the
6760% destination to jump to.
6761%
6762% We open the .toc file for writing here instead of at @setfilename (or
6763% any other fixed time) so that @contents can be anywhere in the document.
6764% But if #1 is `omit', then we don't do anything.  This is used for the
6765% table of contents chapter openings themselves.
6766%
6767\newif\iftocfileopened
6768\def\omitkeyword{omit}%
6769%
6770\def\writetocentry#1#2#3{%
6771  \edef\writetoctype{#1}%
6772  \ifx\writetoctype\omitkeyword \else
6773    \iftocfileopened\else
6774      \immediate\openout\tocfile = \jobname.toc
6775      \global\tocfileopenedtrue
6776    \fi
6777    %
6778    \iflinks
6779      {\atdummies
6780       \edef\temp{%
6781         \write\tocfile{@#1entry{#2}{#3}{\lastnode}{\noexpand\folio}}}%
6782       \temp
6783      }%
6784    \fi
6785  \fi
6786  %
6787  % Tell \shipout to create a pdf destination on each page, if we're
6788  % writing pdf.  These are used in the table of contents.  We can't
6789  % just write one on every page because the title pages are numbered
6790  % 1 and 2 (the page numbers aren't printed), and so are the first
6791  % two pages of the document.  Thus, we'd have two destinations named
6792  % `1', and two named `2'.
6793  \ifpdf
6794    \global\pdfmakepagedesttrue
6795  \else
6796    \ifx\XeTeXrevision\thisisundefined
6797    \else
6798      \global\pdfmakepagedesttrue
6799    \fi
6800  \fi
6801}
6802
6803
6804% These characters do not print properly in the Computer Modern roman
6805% fonts, so we must take special care.  This is more or less redundant
6806% with the Texinfo input format setup at the end of this file.
6807%
6808\def\activecatcodes{%
6809  \catcode`\"=\active
6810  \catcode`\$=\active
6811  \catcode`\<=\active
6812  \catcode`\>=\active
6813  \catcode`\\=\active
6814  \catcode`\^=\active
6815  \catcode`\_=\active
6816  \catcode`\|=\active
6817  \catcode`\~=\active
6818}
6819
6820
6821% Read the toc file, which is essentially Texinfo input.
6822\def\readtocfile{%
6823  \setupdatafile
6824  \activecatcodes
6825  \input \tocreadfilename
6826}
6827
6828\newskip\contentsrightmargin \contentsrightmargin=1in
6829\newcount\savepageno
6830\newcount\lastnegativepageno \lastnegativepageno = -1
6831
6832% Prepare to read what we've written to \tocfile.
6833%
6834\def\startcontents#1{%
6835  % If @setchapternewpage on, and @headings double, the contents should
6836  % start on an odd page, unlike chapters.  Thus, we maintain
6837  % \contentsalignmacro in parallel with \pagealignmacro.
6838  % From: Torbjorn Granlund <tege@matematik.su.se>
6839  \contentsalignmacro
6840  \immediate\closeout\tocfile
6841  %
6842  % Don't need to put `Contents' or `Short Contents' in the headline.
6843  % It is abundantly clear what they are.
6844  \chapmacro{#1}{Yomitfromtoc}{}%
6845  %
6846  \savepageno = \pageno
6847  \begingroup                  % Set up to handle contents files properly.
6848    \raggedbottom              % Worry more about breakpoints than the bottom.
6849    \entryrightmargin=\contentsrightmargin % Don't use the full line length.
6850    %
6851    % Roman numerals for page numbers.
6852    \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
6853}
6854
6855% redefined for the two-volume lispref.  We always output on
6856% \jobname.toc even if this is redefined.
6857%
6858\def\tocreadfilename{\jobname.toc}
6859
6860% Normal (long) toc.
6861%
6862\def\contents{%
6863  \startcontents{\putwordTOC}%
6864    \openin 1 \tocreadfilename\space
6865    \ifeof 1 \else
6866      \readtocfile
6867    \fi
6868    \vfill \eject
6869    \contentsalignmacro % in case @setchapternewpage odd is in effect
6870    \ifeof 1 \else
6871      \pdfmakeoutlines
6872    \fi
6873    \closein 1
6874  \endgroup
6875  \lastnegativepageno = \pageno
6876  \global\pageno = \savepageno
6877}
6878
6879% And just the chapters.
6880\def\summarycontents{%
6881  \startcontents{\putwordShortTOC}%
6882    %
6883    \let\partentry = \shortpartentry
6884    \let\numchapentry = \shortchapentry
6885    \let\appentry = \shortchapentry
6886    \let\unnchapentry = \shortunnchapentry
6887    % We want a true roman here for the page numbers.
6888    \secfonts
6889    \let\rm=\shortcontrm \let\bf=\shortcontbf
6890    \let\sl=\shortcontsl \let\tt=\shortconttt
6891    \rm
6892    \hyphenpenalty = 10000
6893    \advance\baselineskip by 1pt % Open it up a little.
6894    \def\numsecentry##1##2##3##4{}
6895    \let\appsecentry = \numsecentry
6896    \let\unnsecentry = \numsecentry
6897    \let\numsubsecentry = \numsecentry
6898    \let\appsubsecentry = \numsecentry
6899    \let\unnsubsecentry = \numsecentry
6900    \let\numsubsubsecentry = \numsecentry
6901    \let\appsubsubsecentry = \numsecentry
6902    \let\unnsubsubsecentry = \numsecentry
6903    \openin 1 \tocreadfilename\space
6904    \ifeof 1 \else
6905      \readtocfile
6906    \fi
6907    \closein 1
6908    \vfill \eject
6909    \contentsalignmacro % in case @setchapternewpage odd is in effect
6910  \endgroup
6911  \lastnegativepageno = \pageno
6912  \global\pageno = \savepageno
6913}
6914\let\shortcontents = \summarycontents
6915
6916% Typeset the label for a chapter or appendix for the short contents.
6917% The arg is, e.g., `A' for an appendix, or `3' for a chapter.
6918%
6919\def\shortchaplabel#1{%
6920  % This space should be enough, since a single number is .5em, and the
6921  % widest letter (M) is 1em, at least in the Computer Modern fonts.
6922  % But use \hss just in case.
6923  % (This space doesn't include the extra space that gets added after
6924  % the label; that gets put in by \shortchapentry above.)
6925  %
6926  % We'd like to right-justify chapter numbers, but that looks strange
6927  % with appendix letters.  And right-justifying numbers and
6928  % left-justifying letters looks strange when there is less than 10
6929  % chapters.  Have to read the whole toc once to know how many chapters
6930  % there are before deciding ...
6931  \hbox to 1em{#1\hss}%
6932}
6933
6934% These macros generate individual entries in the table of contents.
6935% The first argument is the chapter or section name.
6936% The last argument is the page number.
6937% The arguments in between are the chapter number, section number, ...
6938
6939% Parts, in the main contents.  Replace the part number, which doesn't
6940% exist, with an empty box.  Let's hope all the numbers have the same width.
6941% Also ignore the page number, which is conventionally not printed.
6942\def\numeralbox{\setbox0=\hbox{8}\hbox to \wd0{\hfil}}
6943\def\partentry#1#2#3#4{%
6944  % Add stretch and a bonus for breaking the page before the part heading.
6945  % This reduces the chance of the page being broken immediately after the
6946  % part heading, before a following chapter heading.
6947  \vskip 0pt plus 5\baselineskip
6948  \penalty-300
6949  \vskip 0pt plus -5\baselineskip
6950  \dochapentry{\numeralbox\labelspace#1}{}%
6951}
6952%
6953% Parts, in the short toc.
6954\def\shortpartentry#1#2#3#4{%
6955  \penalty-300
6956  \vskip.5\baselineskip plus.15\baselineskip minus.1\baselineskip
6957  \shortchapentry{{\bf #1}}{\numeralbox}{}{}%
6958}
6959
6960% Chapters, in the main contents.
6961\def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
6962
6963% Chapters, in the short toc.
6964% See comments in \dochapentry re vbox and related settings.
6965\def\shortchapentry#1#2#3#4{%
6966  \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
6967}
6968
6969% Appendices, in the main contents.
6970% Need the word Appendix, and a fixed-size box.
6971%
6972\def\appendixbox#1{%
6973  % We use M since it's probably the widest letter.
6974  \setbox0 = \hbox{\putwordAppendix{} M}%
6975  \hbox to \wd0{\putwordAppendix{} #1\hss}}
6976%
6977\def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\hskip.7em#1}{#4}}
6978
6979% Unnumbered chapters.
6980\def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
6981\def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
6982
6983% Sections.
6984\def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
6985\let\appsecentry=\numsecentry
6986\def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
6987
6988% Subsections.
6989\def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
6990\let\appsubsecentry=\numsubsecentry
6991\def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
6992
6993% And subsubsections.
6994\def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
6995\let\appsubsubsecentry=\numsubsubsecentry
6996\def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
6997
6998% This parameter controls the indentation of the various levels.
6999% Same as \defaultparindent.
7000\newdimen\tocindent \tocindent = 15pt
7001
7002% Now for the actual typesetting. In all these, #1 is the text and #2 is the
7003% page number.
7004%
7005% If the toc has to be broken over pages, we want it to be at chapters
7006% if at all possible; hence the \penalty.
7007\def\dochapentry#1#2{%
7008   \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
7009   \begingroup
7010     % Move the page numbers slightly to the right
7011     \advance\entryrightmargin by -0.05em
7012     \chapentryfonts
7013     \tocentry{#1}{\dopageno\bgroup#2\egroup}%
7014   \endgroup
7015   \nobreak\vskip .25\baselineskip plus.1\baselineskip
7016}
7017
7018\def\dosecentry#1#2{\begingroup
7019  \secentryfonts \leftskip=\tocindent
7020  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
7021\endgroup}
7022
7023\def\dosubsecentry#1#2{\begingroup
7024  \subsecentryfonts \leftskip=2\tocindent
7025  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
7026\endgroup}
7027
7028\def\dosubsubsecentry#1#2{\begingroup
7029  \subsubsecentryfonts \leftskip=3\tocindent
7030  \tocentry{#1}{\dopageno\bgroup#2\egroup}%
7031\endgroup}
7032
7033% We use the same \entry macro as for the index entries.
7034\let\tocentry = \entry
7035
7036% Space between chapter (or whatever) number and the title.
7037\def\labelspace{\hskip1em \relax}
7038
7039\def\dopageno#1{{\rm #1}}
7040\def\doshortpageno#1{{\rm #1}}
7041
7042\def\chapentryfonts{\secfonts \rm}
7043\def\secentryfonts{\textfonts}
7044\def\subsecentryfonts{\textfonts}
7045\def\subsubsecentryfonts{\textfonts}
7046
7047
7048\message{environments,}
7049% @foo ... @end foo.
7050
7051% @tex ... @end tex    escapes into raw TeX temporarily.
7052% One exception: @ is still an escape character, so that @end tex works.
7053% But \@ or @@ will get a plain @ character.
7054
7055\envdef\tex{%
7056  \setupmarkupstyle{tex}%
7057  \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
7058  \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
7059  \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
7060  \catcode `\%=14
7061  \catcode `\+=\other
7062  \catcode `\"=\other
7063  \catcode `\|=\other
7064  \catcode `\<=\other
7065  \catcode `\>=\other
7066  \catcode `\`=\other
7067  \catcode `\'=\other
7068  %
7069  % ' is active in math mode (mathcode"8000).  So reset it, and all our
7070  % other math active characters (just in case), to plain's definitions.
7071  \mathactive
7072  %
7073  % Inverse of the list at the beginning of the file.
7074  \let\b=\ptexb
7075  \let\bullet=\ptexbullet
7076  \let\c=\ptexc
7077  \let\,=\ptexcomma
7078  \let\.=\ptexdot
7079  \let\dots=\ptexdots
7080  \let\equiv=\ptexequiv
7081  \let\!=\ptexexclam
7082  \let\i=\ptexi
7083  \let\indent=\ptexindent
7084  \let\noindent=\ptexnoindent
7085  \let\{=\ptexlbrace
7086  \let\+=\tabalign
7087  \let\}=\ptexrbrace
7088  \let\/=\ptexslash
7089  \let\sp=\ptexsp
7090  \let\*=\ptexstar
7091  %\let\sup=\ptexsup % do not redefine, we want @sup to work in math mode
7092  \let\t=\ptext
7093  \expandafter \let\csname top\endcsname=\ptextop  % we've made it outer
7094  \let\frenchspacing=\plainfrenchspacing
7095  %
7096  \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
7097  \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
7098  \def\@{@}%
7099}
7100% There is no need to define \Etex.
7101
7102% Define @lisp ... @end lisp.
7103% @lisp environment forms a group so it can rebind things,
7104% including the definition of @end lisp (which normally is erroneous).
7105
7106% Amount to narrow the margins by for @lisp.
7107\newskip\lispnarrowing \lispnarrowing=0.4in
7108
7109% This is the definition that ^^M gets inside @lisp, @example, and other
7110% such environments.  \null is better than a space, since it doesn't
7111% have any width.
7112\def\lisppar{\null\endgraf}
7113
7114% This space is always present above and below environments.
7115\newskip\envskipamount \envskipamount = 0pt
7116
7117% Make spacing and below environment symmetrical.  We use \parskip here
7118% to help in doing that, since in @example-like environments \parskip
7119% is reset to zero; thus the \afterenvbreak inserts no space -- but the
7120% start of the next paragraph will insert \parskip.
7121%
7122\def\aboveenvbreak{{%
7123  % =10000 instead of <10000 because of a special case in \itemzzz and
7124  % \sectionheading, q.v.
7125  \ifnum \lastpenalty=10000 \else
7126    \advance\envskipamount by \parskip
7127    \endgraf
7128    \ifdim\lastskip<\envskipamount
7129      \removelastskip
7130      \ifnum\lastpenalty<10000
7131        % Penalize breaking before the environment, because preceding text
7132        % often leads into it.
7133        \penalty100
7134      \fi
7135      \vskip\envskipamount
7136    \fi
7137  \fi
7138}}
7139
7140\def\afterenvbreak{{%
7141  % =10000 instead of <10000 because of a special case in \itemzzz and
7142  % \sectionheading, q.v.
7143  \ifnum \lastpenalty=10000 \else
7144    \advance\envskipamount by \parskip
7145    \endgraf
7146    \ifdim\lastskip<\envskipamount
7147      \removelastskip
7148      % it's not a good place to break if the last penalty was \nobreak
7149      % or better ...
7150      \ifnum\lastpenalty<10000 \penalty-50 \fi
7151      \vskip\envskipamount
7152    \fi
7153  \fi
7154}}
7155
7156% \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins; it will
7157% also clear it, so that its embedded environments do the narrowing again.
7158\let\nonarrowing=\relax
7159
7160% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
7161% environment contents.
7162\font\circle=lcircle10
7163\newdimen\circthick
7164\newdimen\cartouter\newdimen\cartinner
7165\newskip\normbskip\newskip\normpskip\newskip\normlskip
7166\circthick=\fontdimen8\circle
7167%
7168\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
7169\def\ctr{{\hskip 6pt\circle\char'010}}
7170\def\cbl{{\circle\char'012\hskip -6pt}}
7171\def\cbr{{\hskip 6pt\circle\char'011}}
7172\def\carttop{\hbox to \cartouter{\hskip\lskip
7173        \ctl\leaders\hrule height\circthick\hfil\ctr
7174        \hskip\rskip}}
7175\def\cartbot{\hbox to \cartouter{\hskip\lskip
7176        \cbl\leaders\hrule height\circthick\hfil\cbr
7177        \hskip\rskip}}
7178%
7179\newskip\lskip\newskip\rskip
7180
7181\envdef\cartouche{%
7182  \ifhmode\par\fi  % can't be in the midst of a paragraph.
7183  \startsavinginserts
7184  \lskip=\leftskip \rskip=\rightskip
7185  \leftskip=0pt\rightskip=0pt % we want these *outside*.
7186  \cartinner=\hsize \advance\cartinner by-\lskip
7187  \advance\cartinner by-\rskip
7188  \cartouter=\hsize
7189  \advance\cartouter by 18.4pt	% allow for 3pt kerns on either
7190				% side, and for 6pt waste from
7191				% each corner char, and rule thickness
7192  \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
7193  %
7194  % If this cartouche directly follows a sectioning command, we need the
7195  % \parskip glue (backspaced over by default) or the cartouche can
7196  % collide with the section heading.
7197  \ifnum\lastpenalty>10000 \vskip\parskip \penalty\lastpenalty \fi
7198  %
7199  \setbox\groupbox=\vbox\bgroup
7200      \baselineskip=0pt\parskip=0pt\lineskip=0pt
7201      \carttop
7202      \hbox\bgroup
7203	  \hskip\lskip
7204	  \vrule\kern3pt
7205	  \vbox\bgroup
7206	      \kern3pt
7207	      \hsize=\cartinner
7208	      \baselineskip=\normbskip
7209	      \lineskip=\normlskip
7210	      \parskip=\normpskip
7211	      \vskip -\parskip
7212	      \comment % For explanation, see the end of def\group.
7213}
7214\def\Ecartouche{%
7215              \ifhmode\par\fi
7216	      \kern3pt
7217	  \egroup
7218	  \kern3pt\vrule
7219	  \hskip\rskip
7220      \egroup
7221      \cartbot
7222  \egroup
7223  \addgroupbox
7224  \checkinserts
7225}
7226
7227
7228% This macro is called at the beginning of all the @example variants,
7229% inside a group.
7230\newdimen\nonfillparindent
7231\def\nonfillstart{%
7232  \aboveenvbreak
7233  \ifdim\hfuzz < 12pt \hfuzz = 12pt \fi % Don't be fussy
7234  \sepspaces % Make spaces be word-separators rather than space tokens.
7235  \let\par = \lisppar % don't ignore blank lines
7236  \obeylines % each line of input is a line of output
7237  \parskip = 0pt
7238  % Turn off paragraph indentation but redefine \indent to emulate
7239  % the normal \indent.
7240  \nonfillparindent=\parindent
7241  \parindent = 0pt
7242  \let\indent\nonfillindent
7243  %
7244  \emergencystretch = 0pt % don't try to avoid overfull boxes
7245  \ifx\nonarrowing\relax
7246    \advance \leftskip by \lispnarrowing
7247    \exdentamount=\lispnarrowing
7248  \else
7249    \let\nonarrowing = \relax
7250  \fi
7251  \let\exdent=\nofillexdent
7252}
7253
7254\begingroup
7255\obeyspaces
7256% We want to swallow spaces (but not other tokens) after the fake
7257% @indent in our nonfill-environments, where spaces are normally
7258% active and set to @tie, resulting in them not being ignored after
7259% @indent.
7260\gdef\nonfillindent{\futurelet\temp\nonfillindentcheck}%
7261\gdef\nonfillindentcheck{%
7262\ifx\temp %
7263\expandafter\nonfillindentgobble%
7264\else%
7265\leavevmode\nonfillindentbox%
7266\fi%
7267}%
7268\endgroup
7269\def\nonfillindentgobble#1{\nonfillindent}
7270\def\nonfillindentbox{\hbox to \nonfillparindent{\hss}}
7271
7272% If you want all examples etc. small: @set dispenvsize small.
7273% If you want even small examples the full size: @set dispenvsize nosmall.
7274% This affects the following displayed environments:
7275%    @example, @display, @format, @lisp
7276%
7277\def\smallword{small}
7278\def\nosmallword{nosmall}
7279\let\SETdispenvsize\relax
7280\def\setnormaldispenv{%
7281  \ifx\SETdispenvsize\smallword
7282    % end paragraph for sake of leading, in case document has no blank
7283    % line.  This is redundant with what happens in \aboveenvbreak, but
7284    % we need to do it before changing the fonts, and it's inconvenient
7285    % to change the fonts afterward.
7286    \ifnum \lastpenalty=10000 \else \endgraf \fi
7287    \smallexamplefonts \rm
7288  \fi
7289}
7290\def\setsmalldispenv{%
7291  \ifx\SETdispenvsize\nosmallword
7292  \else
7293    \ifnum \lastpenalty=10000 \else \endgraf \fi
7294    \smallexamplefonts \rm
7295  \fi
7296}
7297
7298% We often define two environments, @foo and @smallfoo.
7299% Let's do it in one command.  #1 is the env name, #2 the definition.
7300\def\makedispenvdef#1#2{%
7301  \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}%
7302  \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}%
7303  \expandafter\let\csname E#1\endcsname \afterenvbreak
7304  \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
7305}
7306
7307% Define two environment synonyms (#1 and #2) for an environment.
7308\def\maketwodispenvdef#1#2#3{%
7309  \makedispenvdef{#1}{#3}%
7310  \makedispenvdef{#2}{#3}%
7311}
7312%
7313% @lisp: indented, narrowed, typewriter font;
7314% @example: same as @lisp.
7315%
7316% @smallexample and @smalllisp: use smaller fonts.
7317% Originally contributed by Pavel@xerox.
7318%
7319\maketwodispenvdef{lisp}{example}{%
7320  \nonfillstart
7321  \tt\setupmarkupstyle{example}%
7322  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
7323  \gobble % eat return
7324}
7325% @display/@smalldisplay: same as @lisp except keep current font.
7326%
7327\makedispenvdef{display}{%
7328  \nonfillstart
7329  \gobble
7330}
7331
7332% @format/@smallformat: same as @display except don't narrow margins.
7333%
7334\makedispenvdef{format}{%
7335  \let\nonarrowing = t%
7336  \nonfillstart
7337  \gobble
7338}
7339
7340% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
7341\envdef\flushleft{%
7342  \let\nonarrowing = t%
7343  \nonfillstart
7344  \gobble
7345}
7346\let\Eflushleft = \afterenvbreak
7347
7348% @flushright.
7349%
7350\envdef\flushright{%
7351  \let\nonarrowing = t%
7352  \nonfillstart
7353  \advance\leftskip by 0pt plus 1fill\relax
7354  \gobble
7355}
7356\let\Eflushright = \afterenvbreak
7357
7358
7359% @raggedright does more-or-less normal line breaking but no right
7360% justification.  From plain.tex.
7361\envdef\raggedright{%
7362  \rightskip0pt plus2.4em \spaceskip.3333em \xspaceskip.5em\relax
7363}
7364\let\Eraggedright\par
7365
7366\envdef\raggedleft{%
7367  \parindent=0pt \leftskip0pt plus2em
7368  \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7369  \hbadness=10000 % Last line will usually be underfull, so turn off
7370                  % badness reporting.
7371}
7372\let\Eraggedleft\par
7373
7374\envdef\raggedcenter{%
7375  \parindent=0pt \rightskip0pt plus1em \leftskip0pt plus1em
7376  \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7377  \hbadness=10000 % Last line will usually be underfull, so turn off
7378                  % badness reporting.
7379}
7380\let\Eraggedcenter\par
7381
7382
7383% @quotation does normal linebreaking (hence we can't use \nonfillstart)
7384% and narrows the margins.  We keep \parskip nonzero in general, since
7385% we're doing normal filling.  So, when using \aboveenvbreak and
7386% \afterenvbreak, temporarily make \parskip 0.
7387%
7388\makedispenvdef{quotation}{\quotationstart}
7389%
7390\def\quotationstart{%
7391  \indentedblockstart % same as \indentedblock, but increase right margin too.
7392  \ifx\nonarrowing\relax
7393    \advance\rightskip by \lispnarrowing
7394  \fi
7395  \parsearg\quotationlabel
7396}
7397
7398% We have retained a nonzero parskip for the environment, since we're
7399% doing normal filling.
7400%
7401\def\Equotation{%
7402  \par
7403  \ifx\quotationauthor\thisisundefined\else
7404    % indent a bit.
7405    \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
7406  \fi
7407  {\parskip=0pt \afterenvbreak}%
7408}
7409\def\Esmallquotation{\Equotation}
7410
7411% If we're given an argument, typeset it in bold with a colon after.
7412\def\quotationlabel#1{%
7413  \def\temp{#1}%
7414  \ifx\temp\empty \else
7415    {\bf #1: }%
7416  \fi
7417}
7418
7419% @indentedblock is like @quotation, but indents only on the left and
7420% has no optional argument.
7421%
7422\makedispenvdef{indentedblock}{\indentedblockstart}
7423%
7424\def\indentedblockstart{%
7425  {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
7426  \parindent=0pt
7427  %
7428  % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
7429  \ifx\nonarrowing\relax
7430    \advance\leftskip by \lispnarrowing
7431    \exdentamount = \lispnarrowing
7432  \else
7433    \let\nonarrowing = \relax
7434  \fi
7435}
7436
7437% Keep a nonzero parskip for the environment, since we're doing normal filling.
7438%
7439\def\Eindentedblock{%
7440  \par
7441  {\parskip=0pt \afterenvbreak}%
7442}
7443\def\Esmallindentedblock{\Eindentedblock}
7444
7445
7446% LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
7447% If we want to allow any <char> as delimiter,
7448% we need the curly braces so that makeinfo sees the @verb command, eg:
7449% `@verbx...x' would look like the '@verbx' command.  --janneke@gnu.org
7450%
7451% [Knuth]: Donald Ervin Knuth, 1996.  The TeXbook.
7452%
7453% [Knuth] p.344; only we need to do the other characters Texinfo sets
7454% active too.  Otherwise, they get lost as the first character on a
7455% verbatim line.
7456\def\dospecials{%
7457  \do\ \do\\\do\{\do\}\do\$\do\&%
7458  \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
7459  \do\<\do\>\do\|\do\@\do+\do\"%
7460  % Don't do the quotes -- if we do, @set txicodequoteundirected and
7461  % @set txicodequotebacktick will not have effect on @verb and
7462  % @verbatim, and ?` and !` ligatures won't get disabled.
7463  %\do\`\do\'%
7464}
7465%
7466% [Knuth] p. 380
7467\def\uncatcodespecials{%
7468  \def\do##1{\catcode`##1=\other}\dospecials}
7469%
7470% Setup for the @verb command.
7471%
7472% Eight spaces for a tab
7473\begingroup
7474  \catcode`\^^I=\active
7475  \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
7476\endgroup
7477%
7478\def\setupverb{%
7479  \tt  % easiest (and conventionally used) font for verbatim
7480  \def\par{\leavevmode\endgraf}%
7481  \setupmarkupstyle{verb}%
7482  \tabeightspaces
7483  % Respect line breaks,
7484  % print special symbols as themselves, and
7485  % make each space count
7486  % must do in this order:
7487  \obeylines \uncatcodespecials \sepspaces
7488}
7489
7490% Setup for the @verbatim environment
7491%
7492% Real tab expansion.
7493\newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
7494%
7495% We typeset each line of the verbatim in an \hbox, so we can handle
7496% tabs.  The \global is in case the verbatim line starts with an accent,
7497% or some other command that starts with a begin-group.  Otherwise, the
7498% entire \verbbox would disappear at the corresponding end-group, before
7499% it is typeset.  Meanwhile, we can't have nested verbatim commands
7500% (can we?), so the \global won't be overwriting itself.
7501\newbox\verbbox
7502\def\starttabbox{\global\setbox\verbbox=\hbox\bgroup}
7503%
7504\begingroup
7505  \catcode`\^^I=\active
7506  \gdef\tabexpand{%
7507    \catcode`\^^I=\active
7508    \def^^I{\leavevmode\egroup
7509      \dimen\verbbox=\wd\verbbox % the width so far, or since the previous tab
7510      \divide\dimen\verbbox by\tabw
7511      \multiply\dimen\verbbox by\tabw % compute previous multiple of \tabw
7512      \advance\dimen\verbbox by\tabw  % advance to next multiple of \tabw
7513      \wd\verbbox=\dimen\verbbox \box\verbbox \starttabbox
7514    }%
7515  }
7516\endgroup
7517
7518% start the verbatim environment.
7519\def\setupverbatim{%
7520  \let\nonarrowing = t%
7521  \nonfillstart
7522  \tt % easiest (and conventionally used) font for verbatim
7523  % The \leavevmode here is for blank lines.  Otherwise, we would
7524  % never \starttabbox and the \egroup would end verbatim mode.
7525  \def\par{\leavevmode\egroup\box\verbbox\endgraf}%
7526  \tabexpand
7527  \setupmarkupstyle{verbatim}%
7528  % Respect line breaks,
7529  % print special symbols as themselves, and
7530  % make each space count.
7531  % Must do in this order:
7532  \obeylines \uncatcodespecials \sepspaces
7533  \everypar{\starttabbox}%
7534}
7535
7536% Do the @verb magic: verbatim text is quoted by unique
7537% delimiter characters.  Before first delimiter expect a
7538% right brace, after last delimiter expect closing brace:
7539%
7540%    \def\doverb'{'<char>#1<char>'}'{#1}
7541%
7542% [Knuth] p. 382; only eat outer {}
7543\begingroup
7544  \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
7545  \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
7546\endgroup
7547%
7548\def\verb{\begingroup\setupverb\doverb}
7549%
7550%
7551% Do the @verbatim magic: define the macro \doverbatim so that
7552% the (first) argument ends when '@end verbatim' is reached, ie:
7553%
7554%     \def\doverbatim#1@end verbatim{#1}
7555%
7556% For Texinfo it's a lot easier than for LaTeX,
7557% because texinfo's \verbatim doesn't stop at '\end{verbatim}':
7558% we need not redefine '\', '{' and '}'.
7559%
7560% Inspired by LaTeX's verbatim command set [latex.ltx]
7561%
7562\begingroup
7563  \catcode`\ =\active
7564  \obeylines %
7565  % ignore everything up to the first ^^M, that's the newline at the end
7566  % of the @verbatim input line itself.  Otherwise we get an extra blank
7567  % line in the output.
7568  \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
7569  % We really want {...\end verbatim} in the body of the macro, but
7570  % without the active space; thus we have to use \xdef and \gobble.
7571\endgroup
7572%
7573\envdef\verbatim{%
7574    \setupverbatim\doverbatim
7575}
7576\let\Everbatim = \afterenvbreak
7577
7578
7579% @verbatiminclude FILE - insert text of file in verbatim environment.
7580%
7581\def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
7582%
7583\def\doverbatiminclude#1{%
7584  {%
7585    \makevalueexpandable
7586    \setupverbatim
7587    {%
7588      \indexnofonts       % Allow `@@' and other weird things in file names.
7589      \wlog{texinfo.tex: doing @verbatiminclude of #1^^J}%
7590      \edef\tmp{\noexpand\input #1 }
7591      \expandafter
7592    }\tmp
7593    \afterenvbreak
7594  }%
7595}
7596
7597% @copying ... @end copying.
7598% Save the text away for @insertcopying later.
7599%
7600% We save the uninterpreted tokens, rather than creating a box.
7601% Saving the text in a box would be much easier, but then all the
7602% typesetting commands (@smallbook, font changes, etc.) have to be done
7603% beforehand -- and a) we want @copying to be done first in the source
7604% file; b) letting users define the frontmatter in as flexible order as
7605% possible is desirable.
7606%
7607\def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
7608\def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
7609%
7610\def\insertcopying{%
7611  \begingroup
7612    \parindent = 0pt  % paragraph indentation looks wrong on title page
7613    \scanexp\copyingtext
7614  \endgroup
7615}
7616
7617
7618\message{defuns,}
7619% @defun etc.
7620
7621\newskip\defbodyindent \defbodyindent=.4in
7622\newskip\defargsindent \defargsindent=50pt
7623\newskip\deflastargmargin \deflastargmargin=18pt
7624\newcount\defunpenalty
7625
7626% Start the processing of @deffn:
7627\def\startdefun{%
7628  \ifnum\lastpenalty<10000
7629    \medbreak
7630    \defunpenalty=10003 % Will keep this @deffn together with the
7631                        % following @def command, see below.
7632  \else
7633    % If there are two @def commands in a row, we'll have a \nobreak,
7634    % which is there to keep the function description together with its
7635    % header.  But if there's nothing but headers, we need to allow a
7636    % break somewhere.  Check specifically for penalty 10002, inserted
7637    % by \printdefunline, instead of 10000, since the sectioning
7638    % commands also insert a nobreak penalty, and we don't want to allow
7639    % a break between a section heading and a defun.
7640    %
7641    % As a further refinement, we avoid "club" headers by signalling
7642    % with penalty of 10003 after the very first @deffn in the
7643    % sequence (see above), and penalty of 10002 after any following
7644    % @def command.
7645    \ifnum\lastpenalty=10002 \penalty2000 \else \defunpenalty=10002 \fi
7646    %
7647    % Similarly, after a section heading, do not allow a break.
7648    % But do insert the glue.
7649    \medskip  % preceded by discardable penalty, so not a breakpoint
7650  \fi
7651  %
7652  \parindent=0in
7653  \advance\leftskip by \defbodyindent
7654  \exdentamount=\defbodyindent
7655}
7656
7657\def\dodefunx#1{%
7658  % First, check whether we are in the right environment:
7659  \checkenv#1%
7660  %
7661  % As above, allow line break if we have multiple x headers in a row.
7662  % It's not a great place, though.
7663  \ifnum\lastpenalty=10002 \penalty3000 \else \defunpenalty=10002 \fi
7664  %
7665  % And now, it's time to reuse the body of the original defun:
7666  \expandafter\gobbledefun#1%
7667}
7668\def\gobbledefun#1\startdefun{}
7669
7670% \printdefunline \deffnheader{text}
7671%
7672\def\printdefunline#1#2{%
7673  \begingroup
7674    % call \deffnheader:
7675    #1#2 \endheader
7676    % common ending:
7677    \interlinepenalty = 10000
7678    \advance\rightskip by 0pt plus 1fil\relax
7679    \endgraf
7680    \nobreak\vskip -\parskip
7681    \penalty\defunpenalty  % signal to \startdefun and \dodefunx
7682    % Some of the @defun-type tags do not enable magic parentheses,
7683    % rendering the following check redundant.  But we don't optimize.
7684    \checkparencounts
7685  \endgroup
7686}
7687
7688\def\Edefun{\endgraf\medbreak}
7689
7690% \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
7691% the only thing remaining is to define \deffnheader.
7692%
7693\def\makedefun#1{%
7694  \expandafter\let\csname E#1\endcsname = \Edefun
7695  \edef\temp{\noexpand\domakedefun
7696    \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
7697  \temp
7698}
7699
7700% \domakedefun \deffn \deffnx \deffnheader { (defn. of \deffnheader) }
7701%
7702% Define \deffn and \deffnx, without parameters.
7703% \deffnheader has to be defined explicitly.
7704%
7705\def\domakedefun#1#2#3{%
7706  \envdef#1{%
7707    \startdefun
7708    \doingtypefnfalse    % distinguish typed functions from all else
7709    \parseargusing\activeparens{\printdefunline#3}%
7710  }%
7711  \def#2{\dodefunx#1}%
7712  \def#3%
7713}
7714
7715\newif\ifdoingtypefn       % doing typed function?
7716\newif\ifrettypeownline    % typeset return type on its own line?
7717
7718% @deftypefnnewline on|off says whether the return type of typed functions
7719% are printed on their own line.  This affects @deftypefn, @deftypefun,
7720% @deftypeop, and @deftypemethod.
7721%
7722\parseargdef\deftypefnnewline{%
7723  \def\temp{#1}%
7724  \ifx\temp\onword
7725    \expandafter\let\csname SETtxideftypefnnl\endcsname
7726      = \empty
7727  \else\ifx\temp\offword
7728    \expandafter\let\csname SETtxideftypefnnl\endcsname
7729      = \relax
7730  \else
7731    \errhelp = \EMsimple
7732    \errmessage{Unknown @txideftypefnnl value `\temp',
7733                must be on|off}%
7734  \fi\fi
7735}
7736
7737% \dosubind {index}{topic}{subtopic}
7738%
7739% If SUBTOPIC is present, precede it with a space, and call \doind.
7740% (At some time during the 20th century, this made a two-level entry in an
7741% index such as the operation index.  Nobody seemed to notice the change in
7742% behaviour though.)
7743\def\dosubind#1#2#3{%
7744  \def\thirdarg{#3}%
7745  \ifx\thirdarg\empty
7746    \doind{#1}{#2}%
7747  \else
7748    \doind{#1}{#2\space#3}%
7749  \fi
7750}
7751
7752% Untyped functions:
7753
7754% @deffn category name args
7755\makedefun{deffn}{\deffngeneral{}}
7756
7757% @deffn category class name args
7758\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
7759
7760% \defopon {category on}class name args
7761\def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7762
7763% \deffngeneral {subind}category name args
7764%
7765\def\deffngeneral#1#2 #3 #4\endheader{%
7766  \dosubind{fn}{\code{#3}}{#1}%
7767  \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
7768}
7769
7770% Typed functions:
7771
7772% @deftypefn category type name args
7773\makedefun{deftypefn}{\deftypefngeneral{}}
7774
7775% @deftypeop category class type name args
7776\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
7777
7778% \deftypeopon {category on}class type name args
7779\def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7780
7781% \deftypefngeneral {subind}category type name args
7782%
7783\def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
7784  \dosubind{fn}{\code{#4}}{#1}%
7785  \doingtypefntrue
7786  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7787}
7788
7789% Typed variables:
7790
7791% @deftypevr category type var args
7792\makedefun{deftypevr}{\deftypecvgeneral{}}
7793
7794% @deftypecv category class type var args
7795\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
7796
7797% \deftypecvof {category of}class type var args
7798\def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
7799
7800% \deftypecvgeneral {subind}category type var args
7801%
7802\def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
7803  \dosubind{vr}{\code{#4}}{#1}%
7804  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7805}
7806
7807% Untyped variables:
7808
7809% @defvr category var args
7810\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
7811
7812% @defcv category class var args
7813\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
7814
7815% \defcvof {category of}class var args
7816\def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
7817
7818% Types:
7819
7820% @deftp category name args
7821\makedefun{deftp}#1 #2 #3\endheader{%
7822  \doind{tp}{\code{#2}}%
7823  \defname{#1}{}{#2}\defunargs{#3\unskip}%
7824}
7825
7826% Remaining @defun-like shortcuts:
7827\makedefun{defun}{\deffnheader{\putwordDeffunc} }
7828\makedefun{defmac}{\deffnheader{\putwordDefmac} }
7829\makedefun{defspec}{\deffnheader{\putwordDefspec} }
7830\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
7831\makedefun{defvar}{\defvrheader{\putwordDefvar} }
7832\makedefun{defopt}{\defvrheader{\putwordDefopt} }
7833\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
7834\makedefun{defmethod}{\defopon\putwordMethodon}
7835\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
7836\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
7837\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
7838
7839% \defname, which formats the name of the @def (not the args).
7840% #1 is the category, such as "Function".
7841% #2 is the return type, if any.
7842% #3 is the function name.
7843%
7844% We are followed by (but not passed) the arguments, if any.
7845%
7846\def\defname#1#2#3{%
7847  \par
7848  % Get the values of \leftskip and \rightskip as they were outside the @def...
7849  \advance\leftskip by -\defbodyindent
7850  %
7851  % Determine if we are typesetting the return type of a typed function
7852  % on a line by itself.
7853  \rettypeownlinefalse
7854  \ifdoingtypefn  % doing a typed function specifically?
7855    % then check user option for putting return type on its own line:
7856    \expandafter\ifx\csname SETtxideftypefnnl\endcsname\relax \else
7857      \rettypeownlinetrue
7858    \fi
7859  \fi
7860  %
7861  % How we'll format the category name.  Putting it in brackets helps
7862  % distinguish it from the body text that may end up on the next line
7863  % just below it.
7864  \def\temp{#1}%
7865  \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
7866  %
7867  % Figure out line sizes for the paragraph shape.  We'll always have at
7868  % least two.
7869  \tempnum = 2
7870  %
7871  % The first line needs space for \box0; but if \rightskip is nonzero,
7872  % we need only space for the part of \box0 which exceeds it:
7873  \dimen0=\hsize  \advance\dimen0 by -\wd0  \advance\dimen0 by \rightskip
7874  %
7875  % If doing a return type on its own line, we'll have another line.
7876  \ifrettypeownline
7877    \advance\tempnum by 1
7878    \def\maybeshapeline{0in \hsize}%
7879  \else
7880    \def\maybeshapeline{}%
7881  \fi
7882  %
7883  % The continuations:
7884  \dimen2=\hsize  \advance\dimen2 by -\defargsindent
7885  %
7886  % The final paragraph shape:
7887  \parshape \tempnum  0in \dimen0  \maybeshapeline  \defargsindent \dimen2
7888  %
7889  % Put the category name at the right margin.
7890  \noindent
7891  \hbox to 0pt{%
7892    \hfil\box0 \kern-\hsize
7893    % \hsize has to be shortened this way:
7894    \kern\leftskip
7895    % Intentionally do not respect \rightskip, since we need the space.
7896  }%
7897  %
7898  % Allow all lines to be underfull without complaint:
7899  \tolerance=10000 \hbadness=10000
7900  \exdentamount=\defbodyindent
7901  {%
7902    % defun fonts. We use typewriter by default (used to be bold) because:
7903    % . we're printing identifiers, they should be in tt in principle.
7904    % . in languages with many accents, such as Czech or French, it's
7905    %   common to leave accents off identifiers.  The result looks ok in
7906    %   tt, but exceedingly strange in rm.
7907    % . we don't want -- and --- to be treated as ligatures.
7908    % . this still does not fix the ?` and !` ligatures, but so far no
7909    %   one has made identifiers using them :).
7910    \df \tt
7911    \def\temp{#2}% text of the return type
7912    \ifx\temp\empty\else
7913      \tclose{\temp}% typeset the return type
7914      \ifrettypeownline
7915        % put return type on its own line; prohibit line break following:
7916        \hfil\vadjust{\nobreak}\break
7917      \else
7918        \space  % type on same line, so just followed by a space
7919      \fi
7920    \fi           % no return type
7921    #3% output function name
7922  }%
7923  {\rm\enskip}% hskip 0.5 em of \rmfont
7924  %
7925  \boldbrax
7926  % arguments will be output next, if any.
7927}
7928
7929% Print arguments in slanted roman (not ttsl), inconsistently with using
7930% tt for the name.  This is because literal text is sometimes needed in
7931% the argument list (groff manual), and ttsl and tt are not very
7932% distinguishable.  Prevent hyphenation at `-' chars.
7933%
7934\def\defunargs#1{%
7935  % use sl by default (not ttsl),
7936  % tt for the names.
7937  \df \sl \hyphenchar\font=0
7938  %
7939  % On the other hand, if an argument has two dashes (for instance), we
7940  % want a way to get ttsl.  We used to recommend @var for that, so
7941  % leave the code in, but it's strange for @var to lead to typewriter.
7942  % Nowadays we recommend @code, since the difference between a ttsl hyphen
7943  % and a tt hyphen is pretty tiny.  @code also disables ?` !`.
7944  \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}%
7945  #1%
7946  \sl\hyphenchar\font=45
7947}
7948
7949% We want ()&[] to print specially on the defun line.
7950%
7951\def\activeparens{%
7952  \catcode`\(=\active \catcode`\)=\active
7953  \catcode`\[=\active \catcode`\]=\active
7954  \catcode`\&=\active
7955}
7956
7957% Make control sequences which act like normal parenthesis chars.
7958\let\lparen = ( \let\rparen = )
7959
7960% Be sure that we always have a definition for `(', etc.  For example,
7961% if the fn name has parens in it, \boldbrax will not be in effect yet,
7962% so TeX would otherwise complain about undefined control sequence.
7963{
7964  \activeparens
7965  \global\let(=\lparen \global\let)=\rparen
7966  \global\let[=\lbrack \global\let]=\rbrack
7967  \global\let& = \&
7968
7969  \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
7970  \gdef\magicamp{\let&=\amprm}
7971}
7972\let\ampchar\&
7973
7974\newcount\parencount
7975
7976% If we encounter &foo, then turn on ()-hacking afterwards
7977\newif\ifampseen
7978\def\amprm#1 {\ampseentrue{\bf\&#1 }}
7979
7980\def\parenfont{%
7981  \ifampseen
7982    % At the first level, print parens in roman,
7983    % otherwise use the default font.
7984    \ifnum \parencount=1 \rm \fi
7985  \else
7986    % The \sf parens (in \boldbrax) actually are a little bolder than
7987    % the contained text.  This is especially needed for [ and ] .
7988    \sf
7989  \fi
7990}
7991\def\infirstlevel#1{%
7992  \ifampseen
7993    \ifnum\parencount=1
7994      #1%
7995    \fi
7996  \fi
7997}
7998\def\bfafterword#1 {#1 \bf}
7999
8000\def\opnr{%
8001  \global\advance\parencount by 1
8002  {\parenfont(}%
8003  \infirstlevel \bfafterword
8004}
8005\def\clnr{%
8006  {\parenfont)}%
8007  \infirstlevel \sl
8008  \global\advance\parencount by -1
8009}
8010
8011\newcount\brackcount
8012\def\lbrb{%
8013  \global\advance\brackcount by 1
8014  {\bf[}%
8015}
8016\def\rbrb{%
8017  {\bf]}%
8018  \global\advance\brackcount by -1
8019}
8020
8021\def\checkparencounts{%
8022  \ifnum\parencount=0 \else \badparencount \fi
8023  \ifnum\brackcount=0 \else \badbrackcount \fi
8024}
8025% these should not use \errmessage; the glibc manual, at least, actually
8026% has such constructs (when documenting function pointers).
8027\def\badparencount{%
8028  \message{Warning: unbalanced parentheses in @def...}%
8029  \global\parencount=0
8030}
8031\def\badbrackcount{%
8032  \message{Warning: unbalanced square brackets in @def...}%
8033  \global\brackcount=0
8034}
8035
8036
8037\message{macros,}
8038% @macro.
8039
8040% To do this right we need a feature of e-TeX, \scantokens,
8041% which we arrange to emulate with a temporary file in ordinary TeX.
8042\ifx\eTeXversion\thisisundefined
8043  \newwrite\macscribble
8044  \def\scantokens#1{%
8045    \toks0={#1}%
8046    \immediate\openout\macscribble=\jobname.tmp
8047    \immediate\write\macscribble{\the\toks0}%
8048    \immediate\closeout\macscribble
8049    \input \jobname.tmp
8050  }
8051\fi
8052
8053% alias because \c means cedilla in @tex or @math
8054\let\texinfoc=\c
8055
8056\newcount\savedcatcodeone
8057\newcount\savedcatcodetwo
8058
8059% Used at the time of macro expansion.
8060% Argument is macro body with arguments substituted
8061\def\scanmacro#1{%
8062  \newlinechar`\^^M
8063  \def\xeatspaces{\eatspaces}%
8064  %
8065  % Temporarily undo catcode changes of \printindex.  Set catcode of @ to
8066  % 0 so that @-commands in macro expansions aren't printed literally when
8067  % formatting an index file, where \ is used as the escape character.
8068  \savedcatcodeone=\catcode`\@
8069  \savedcatcodetwo=\catcode`\\
8070  \catcode`\@=0
8071  \catcode`\\=\active
8072  %
8073  % Process the macro body under the current catcode regime.
8074  \scantokens{#1@texinfoc}%
8075  %
8076  \catcode`\@=\savedcatcodeone
8077  \catcode`\\=\savedcatcodetwo
8078  %
8079  % The \texinfoc is to remove the \newlinechar added by \scantokens, and
8080  % can be noticed by \parsearg.
8081  %   We avoid surrounding the call to \scantokens with \bgroup and \egroup
8082  % to allow macros to open or close groups themselves.
8083}
8084
8085% Used for copying and captions
8086\def\scanexp#1{%
8087  \expandafter\scanmacro\expandafter{#1}%
8088}
8089
8090\newcount\paramno   % Count of parameters
8091\newtoks\macname    % Macro name
8092\newif\ifrecursive  % Is it recursive?
8093
8094% List of all defined macros in the form
8095%    \commondummyword\macro1\commondummyword\macro2...
8096% Currently is also contains all @aliases; the list can be split
8097% if there is a need.
8098\def\macrolist{}
8099
8100% Add the macro to \macrolist
8101\def\addtomacrolist#1{\expandafter \addtomacrolistxxx \csname#1\endcsname}
8102\def\addtomacrolistxxx#1{%
8103     \toks0 = \expandafter{\macrolist\commondummyword#1}%
8104     \xdef\macrolist{\the\toks0}%
8105}
8106
8107% Utility routines.
8108% This does \let #1 = #2, with \csnames; that is,
8109%   \let \csname#1\endcsname = \csname#2\endcsname
8110% (except of course we have to play expansion games).
8111%
8112\def\cslet#1#2{%
8113  \expandafter\let
8114  \csname#1\expandafter\endcsname
8115  \csname#2\endcsname
8116}
8117
8118% Trim leading and trailing spaces off a string.
8119% Concepts from aro-bend problem 15 (see CTAN).
8120{\catcode`\@=11
8121\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
8122\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
8123\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
8124\def\unbrace#1{#1}
8125\unbrace{\gdef\trim@@@ #1 } #2@{#1}
8126}
8127
8128% Trim a single trailing ^^M off a string.
8129{\catcode`\^^M=\other \catcode`\Q=3%
8130\gdef\eatcr #1{\eatcra #1Q^^MQ}%
8131\gdef\eatcra#1^^MQ{\eatcrb#1Q}%
8132\gdef\eatcrb#1Q#2Q{#1}%
8133}
8134
8135% Macro bodies are absorbed as an argument in a context where
8136% all characters are catcode 10, 11 or 12, except \ which is active
8137% (as in normal texinfo). It is necessary to change the definition of \
8138% to recognize macro arguments; this is the job of \mbodybackslash.
8139%
8140% Non-ASCII encodings make 8-bit characters active, so un-activate
8141% them to avoid their expansion.  Must do this non-globally, to
8142% confine the change to the current group.
8143%
8144% It's necessary to have hard CRs when the macro is executed. This is
8145% done by making ^^M (\endlinechar) catcode 12 when reading the macro
8146% body, and then making it the \newlinechar in \scanmacro.
8147%
8148\def\scanctxt{% used as subroutine
8149  \catcode`\"=\other
8150  \catcode`\+=\other
8151  \catcode`\<=\other
8152  \catcode`\>=\other
8153  \catcode`\^=\other
8154  \catcode`\_=\other
8155  \catcode`\|=\other
8156  \catcode`\~=\other
8157  \passthroughcharstrue
8158}
8159
8160\def\scanargctxt{% used for copying and captions, not macros.
8161  \scanctxt
8162  \catcode`\@=\other
8163  \catcode`\\=\other
8164  \catcode`\^^M=\other
8165}
8166
8167\def\macrobodyctxt{% used for @macro definitions
8168  \scanctxt
8169  \catcode`\ =\other
8170  \catcode`\@=\other
8171  \catcode`\{=\other
8172  \catcode`\}=\other
8173  \catcode`\^^M=\other
8174  \usembodybackslash
8175}
8176
8177% Used when scanning braced macro arguments.  Note, however, that catcode
8178% changes here are ineffectual if the macro invocation was nested inside
8179% an argument to another Texinfo command.
8180\def\macroargctxt{%
8181  \scanctxt
8182  \catcode`\ =\active
8183  \catcode`\^^M=\other
8184  \catcode`\\=\active
8185}
8186
8187\def\macrolineargctxt{% used for whole-line arguments without braces
8188  \scanctxt
8189  \catcode`\{=\other
8190  \catcode`\}=\other
8191}
8192
8193% \mbodybackslash is the definition of \ in @macro bodies.
8194% It maps \foo\ => \csname macarg.foo\endcsname => #N
8195% where N is the macro parameter number.
8196% We define \csname macarg.\endcsname to be \realbackslash, so
8197% \\ in macro replacement text gets you a backslash.
8198%
8199{\catcode`@=0 @catcode`@\=@active
8200 @gdef@usembodybackslash{@let\=@mbodybackslash}
8201 @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
8202}
8203\expandafter\def\csname macarg.\endcsname{\realbackslash}
8204
8205\def\margbackslash#1{\char`\#1 }
8206
8207\def\macro{\recursivefalse\parsearg\macroxxx}
8208\def\rmacro{\recursivetrue\parsearg\macroxxx}
8209
8210\def\macroxxx#1{%
8211  \getargs{#1}% now \macname is the macname and \argl the arglist
8212  \ifx\argl\empty       % no arguments
8213     \paramno=0\relax
8214  \else
8215     \expandafter\parsemargdef \argl;%
8216     \if\paramno>256\relax
8217       \ifx\eTeXversion\thisisundefined
8218         \errhelp = \EMsimple
8219         \errmessage{You need eTeX to compile a file with macros with more than 256 arguments}
8220       \fi
8221     \fi
8222  \fi
8223  \if1\csname ismacro.\the\macname\endcsname
8224     \message{Warning: redefining \the\macname}%
8225  \else
8226     \expandafter\ifx\csname \the\macname\endcsname \relax
8227     \else \errmessage{Macro name \the\macname\space already defined}\fi
8228     \global\cslet{macsave.\the\macname}{\the\macname}%
8229     \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
8230     \addtomacrolist{\the\macname}%
8231  \fi
8232  \begingroup \macrobodyctxt
8233  \ifrecursive \expandafter\parsermacbody
8234  \else \expandafter\parsemacbody
8235  \fi}
8236
8237\parseargdef\unmacro{%
8238  \if1\csname ismacro.#1\endcsname
8239    \global\cslet{#1}{macsave.#1}%
8240    \global\expandafter\let \csname ismacro.#1\endcsname=0%
8241    % Remove the macro name from \macrolist:
8242    \begingroup
8243      \expandafter\let\csname#1\endcsname \relax
8244      \let\commondummyword\unmacrodo
8245      \xdef\macrolist{\macrolist}%
8246    \endgroup
8247  \else
8248    \errmessage{Macro #1 not defined}%
8249  \fi
8250}
8251
8252% Called by \do from \dounmacro on each macro.  The idea is to omit any
8253% macro definitions that have been changed to \relax.
8254%
8255\def\unmacrodo#1{%
8256  \ifx #1\relax
8257    % remove this
8258  \else
8259    \noexpand\commondummyword \noexpand#1%
8260  \fi
8261}
8262
8263% \getargs -- Parse the arguments to a @macro line.  Set \macname to
8264% the name of the macro, and \argl to the braced argument list.
8265\def\getargs#1{\getargsxxx#1{}}
8266\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
8267\def\getmacname#1 #2\relax{\macname={#1}}
8268\def\getmacargs#1{\def\argl{#1}}
8269% This made use of the feature that if the last token of a
8270% <parameter list> is #, then the preceding argument is delimited by
8271% an opening brace, and that opening brace is not consumed.
8272
8273% Parse the optional {params} list to @macro or @rmacro.
8274% Set \paramno to the number of arguments,
8275% and \paramlist to a parameter text for the macro (e.g. #1,#2,#3 for a
8276% three-param macro.)  Define \macarg.BLAH for each BLAH in the params
8277% list to some hook where the argument is to be expanded.  If there are
8278% less than 10 arguments that hook is to be replaced by ##N where N
8279% is the position in that list, that is to say the macro arguments are to be
8280% defined `a la TeX in the macro body.
8281%
8282% That gets used by \mbodybackslash (above).
8283%
8284% If there are 10 or more arguments, a different technique is used: see
8285% \parsemmanyargdef.
8286%
8287\def\parsemargdef#1;{%
8288  \paramno=0\def\paramlist{}%
8289  \let\hash\relax
8290  % \hash is redefined to `#' later to get it into definitions
8291  \let\xeatspaces\relax
8292  \parsemargdefxxx#1,;,%
8293  \ifnum\paramno<10\relax\else
8294    \paramno0\relax
8295    \parsemmanyargdef@@#1,;,% 10 or more arguments
8296  \fi
8297}
8298\def\parsemargdefxxx#1,{%
8299  \if#1;\let\next=\relax
8300  \else \let\next=\parsemargdefxxx
8301    \advance\paramno by 1
8302    \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
8303        {\xeatspaces{\hash\the\paramno}}%
8304    \edef\paramlist{\paramlist\hash\the\paramno,}%
8305  \fi\next}
8306
8307% \parsemacbody, \parsermacbody
8308%
8309% Read recursive and nonrecursive macro bodies. (They're different since
8310% rec and nonrec macros end differently.)
8311%
8312% We are in \macrobodyctxt, and the \xdef causes backslashshes in the macro
8313% body to be transformed.
8314% Set \macrobody to the body of the macro, and call \defmacro.
8315%
8316{\catcode`\ =\other\long\gdef\parsemacbody#1@end macro{%
8317\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8318{\catcode`\ =\other\long\gdef\parsermacbody#1@end rmacro{%
8319\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8320
8321% Make @ a letter, so that we can make private-to-Texinfo macro names.
8322\edef\texiatcatcode{\the\catcode`\@}
8323\catcode `@=11\relax
8324
8325%%%%%%%%%%%%%% Code for > 10 arguments only   %%%%%%%%%%%%%%%%%%
8326
8327% If there are 10 or more arguments, a different technique is used, where the
8328% hook remains in the body, and when macro is to be expanded the body is
8329% processed again to replace the arguments.
8330%
8331% In that case, the hook is \the\toks N-1, and we simply set \toks N-1 to the
8332% argument N value and then \edef the body (nothing else will expand because of
8333% the catcode regime under which the body was input).
8334%
8335% If you compile with TeX (not eTeX), and you have macros with 10 or more
8336% arguments, no macro can have more than 256 arguments (else error).
8337%
8338% In case that there are 10 or more arguments we parse again the arguments
8339% list to set new definitions for the \macarg.BLAH macros corresponding to
8340% each BLAH argument. It was anyhow needed to parse already once this list
8341% in order to count the arguments, and as macros with at most 9 arguments
8342% are by far more frequent than macro with 10 or more arguments, defining
8343% twice the \macarg.BLAH macros does not cost too much processing power.
8344\def\parsemmanyargdef@@#1,{%
8345  \if#1;\let\next=\relax
8346  \else
8347    \let\next=\parsemmanyargdef@@
8348    \edef\tempb{\eatspaces{#1}}%
8349    \expandafter\def\expandafter\tempa
8350       \expandafter{\csname macarg.\tempb\endcsname}%
8351    % Note that we need some extra \noexpand\noexpand, this is because we
8352    % don't want \the  to be expanded in the \parsermacbody  as it uses an
8353    % \xdef .
8354    \expandafter\edef\tempa
8355      {\noexpand\noexpand\noexpand\the\toks\the\paramno}%
8356    \advance\paramno by 1\relax
8357  \fi\next}
8358
8359
8360\let\endargs@\relax
8361\let\nil@\relax
8362\def\nilm@{\nil@}%
8363\long\def\nillm@{\nil@}%
8364
8365% This macro is expanded during the Texinfo macro expansion, not during its
8366% definition.  It gets all the arguments' values and assigns them to macros
8367% macarg.ARGNAME
8368%
8369% #1 is the macro name
8370% #2 is the list of argument names
8371% #3 is the list of argument values
8372\def\getargvals@#1#2#3{%
8373  \def\macargdeflist@{}%
8374  \def\saveparamlist@{#2}% Need to keep a copy for parameter expansion.
8375  \def\paramlist{#2,\nil@}%
8376  \def\macroname{#1}%
8377  \begingroup
8378  \macroargctxt
8379  \def\argvaluelist{#3,\nil@}%
8380  \def\@tempa{#3}%
8381  \ifx\@tempa\empty
8382    \setemptyargvalues@
8383  \else
8384    \getargvals@@
8385  \fi
8386}
8387\def\getargvals@@{%
8388  \ifx\paramlist\nilm@
8389      % Some sanity check needed here that \argvaluelist is also empty.
8390      \ifx\argvaluelist\nillm@
8391      \else
8392        \errhelp = \EMsimple
8393        \errmessage{Too many arguments in macro `\macroname'!}%
8394      \fi
8395      \let\next\macargexpandinbody@
8396  \else
8397    \ifx\argvaluelist\nillm@
8398       % No more arguments values passed to macro.  Set remaining named-arg
8399       % macros to empty.
8400       \let\next\setemptyargvalues@
8401    \else
8402      % pop current arg name into \@tempb
8403      \def\@tempa##1{\pop@{\@tempb}{\paramlist}##1\endargs@}%
8404      \expandafter\@tempa\expandafter{\paramlist}%
8405       % pop current argument value into \@tempc
8406      \def\@tempa##1{\longpop@{\@tempc}{\argvaluelist}##1\endargs@}%
8407      \expandafter\@tempa\expandafter{\argvaluelist}%
8408       % Here \@tempb is the current arg name and \@tempc is the current arg value.
8409       % First place the new argument macro definition into \@tempd
8410       \expandafter\macname\expandafter{\@tempc}%
8411       \expandafter\let\csname macarg.\@tempb\endcsname\relax
8412       \expandafter\def\expandafter\@tempe\expandafter{%
8413         \csname macarg.\@tempb\endcsname}%
8414       \edef\@tempd{\long\def\@tempe{\the\macname}}%
8415       \push@\@tempd\macargdeflist@
8416       \let\next\getargvals@@
8417    \fi
8418  \fi
8419  \next
8420}
8421
8422\def\push@#1#2{%
8423  \expandafter\expandafter\expandafter\def
8424  \expandafter\expandafter\expandafter#2%
8425  \expandafter\expandafter\expandafter{%
8426  \expandafter#1#2}%
8427}
8428
8429% Replace arguments by their values in the macro body, and place the result
8430% in macro \@tempa.
8431%
8432\def\macvalstoargs@{%
8433  %  To do this we use the property that token registers that are \the'ed
8434  % within an \edef  expand only once. So we are going to place all argument
8435  % values into respective token registers.
8436  %
8437  % First we save the token context, and initialize argument numbering.
8438  \begingroup
8439    \paramno0\relax
8440    % Then, for each argument number #N, we place the corresponding argument
8441    % value into a new token list register \toks#N
8442    \expandafter\putargsintokens@\saveparamlist@,;,%
8443    % Then, we expand the body so that argument are replaced by their
8444    % values. The trick for values not to be expanded themselves is that they
8445    % are within tokens and that tokens expand only once in an \edef .
8446    \edef\@tempc{\csname mac.\macroname .body\endcsname}%
8447    % Now we restore the token stack pointer to free the token list registers
8448    % which we have used, but we make sure that expanded body is saved after
8449    % group.
8450    \expandafter
8451  \endgroup
8452  \expandafter\def\expandafter\@tempa\expandafter{\@tempc}%
8453  }
8454
8455% Define the named-macro outside of this group and then close this group.
8456%
8457\def\macargexpandinbody@{%
8458  \expandafter
8459  \endgroup
8460  \macargdeflist@
8461  % First the replace in body the macro arguments by their values, the result
8462  % is in \@tempa .
8463  \macvalstoargs@
8464  % Then we point at the \norecurse or \gobble (for recursive) macro value
8465  % with \@tempb .
8466  \expandafter\let\expandafter\@tempb\csname mac.\macroname .recurse\endcsname
8467  % Depending on whether it is recursive or not, we need some tailing
8468  % \egroup .
8469  \ifx\@tempb\gobble
8470     \let\@tempc\relax
8471  \else
8472     \let\@tempc\egroup
8473  \fi
8474  % And now we do the real job:
8475  \edef\@tempd{\noexpand\@tempb{\macroname}\noexpand\scanmacro{\@tempa}\@tempc}%
8476  \@tempd
8477}
8478
8479\def\putargsintokens@#1,{%
8480  \if#1;\let\next\relax
8481  \else
8482    \let\next\putargsintokens@
8483    % First we allocate the new token list register, and give it a temporary
8484    % alias \@tempb .
8485    \toksdef\@tempb\the\paramno
8486    % Then we place the argument value into that token list register.
8487    \expandafter\let\expandafter\@tempa\csname macarg.#1\endcsname
8488    \expandafter\@tempb\expandafter{\@tempa}%
8489    \advance\paramno by 1\relax
8490  \fi
8491  \next
8492}
8493
8494% Trailing missing arguments are set to empty.
8495%
8496\def\setemptyargvalues@{%
8497  \ifx\paramlist\nilm@
8498    \let\next\macargexpandinbody@
8499  \else
8500    \expandafter\setemptyargvaluesparser@\paramlist\endargs@
8501    \let\next\setemptyargvalues@
8502  \fi
8503  \next
8504}
8505
8506\def\setemptyargvaluesparser@#1,#2\endargs@{%
8507  \expandafter\def\expandafter\@tempa\expandafter{%
8508    \expandafter\def\csname macarg.#1\endcsname{}}%
8509  \push@\@tempa\macargdeflist@
8510  \def\paramlist{#2}%
8511}
8512
8513% #1 is the element target macro
8514% #2 is the list macro
8515% #3,#4\endargs@ is the list value
8516\def\pop@#1#2#3,#4\endargs@{%
8517   \def#1{#3}%
8518   \def#2{#4}%
8519}
8520\long\def\longpop@#1#2#3,#4\endargs@{%
8521   \long\def#1{#3}%
8522   \long\def#2{#4}%
8523}
8524
8525
8526%%%%%%%%%%%%%% End of code for > 10 arguments %%%%%%%%%%%%%%%%%%
8527
8528
8529% This defines a Texinfo @macro or @rmacro, called by \parsemacbody.
8530%    \macrobody has the body of the macro in it, with placeholders for
8531% its parameters, looking like "\xeatspaces{\hash 1}".
8532%    \paramno is the number of parameters
8533%    \paramlist is a TeX parameter text, e.g. "#1,#2,#3,"
8534% There are four cases: macros of zero, one, up to nine, and many arguments.
8535% \xdef is used so that macro definitions will survive the file
8536% they're defined in: @include reads the file inside a group.
8537%
8538\def\defmacro{%
8539  \let\hash=##% convert placeholders to macro parameter chars
8540  \ifnum\paramno=1
8541    \def\xeatspaces##1{##1}%
8542    % This removes the pair of braces around the argument.  We don't
8543    % use \eatspaces, because this can cause ends of lines to be lost
8544    % when the argument to \eatspaces is read, leading to line-based
8545    % commands like "@itemize" not being read correctly.
8546  \else
8547    \let\xeatspaces\relax % suppress expansion
8548  \fi
8549  \ifcase\paramno
8550  % 0
8551    \expandafter\xdef\csname\the\macname\endcsname{%
8552      \bgroup
8553        \noexpand\spaceisspace
8554        \noexpand\endlineisspace
8555        \noexpand\expandafter % skip any whitespace after the macro name.
8556        \expandafter\noexpand\csname\the\macname @@@\endcsname}%
8557    \expandafter\xdef\csname\the\macname @@@\endcsname{%
8558      \egroup
8559      \noexpand\scanmacro{\macrobody}}%
8560  \or % 1
8561    \expandafter\xdef\csname\the\macname\endcsname{%
8562       \bgroup
8563       \noexpand\braceorline
8564       \expandafter\noexpand\csname\the\macname @@@\endcsname}%
8565    \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8566      \egroup
8567      \noexpand\scanmacro{\macrobody}%
8568      }%
8569  \else % at most 9
8570    \ifnum\paramno<10\relax
8571      % @MACNAME sets the context for reading the macro argument
8572      % @MACNAME@@ gets the argument, processes backslashes and appends a
8573      % comma.
8574      % @MACNAME@@@ removes braces surrounding the argument list.
8575      % @MACNAME@@@@ scans the macro body with arguments substituted.
8576      \expandafter\xdef\csname\the\macname\endcsname{%
8577        \bgroup
8578        \noexpand\expandafter  % This \expandafter skip any spaces after the
8579        \noexpand\macroargctxt % macro before we change the catcode of space.
8580        \noexpand\expandafter
8581        \expandafter\noexpand\csname\the\macname @@\endcsname}%
8582      \expandafter\xdef\csname\the\macname @@\endcsname##1{%
8583          \noexpand\passargtomacro
8584          \expandafter\noexpand\csname\the\macname @@@\endcsname{##1,}}%
8585      \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8586          \expandafter\noexpand\csname\the\macname @@@@\endcsname ##1}%
8587      \expandafter\expandafter
8588      \expandafter\xdef
8589      \expandafter\expandafter
8590        \csname\the\macname @@@@\endcsname\paramlist{%
8591          \egroup\noexpand\scanmacro{\macrobody}}%
8592    \else % 10 or more:
8593      \expandafter\xdef\csname\the\macname\endcsname{%
8594        \noexpand\getargvals@{\the\macname}{\argl}%
8595      }%
8596      \global\expandafter\let\csname mac.\the\macname .body\endcsname\macrobody
8597      \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\gobble
8598    \fi
8599  \fi}
8600
8601\catcode `\@\texiatcatcode\relax % end private-to-Texinfo catcodes
8602
8603\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
8604
8605
8606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8607%
8608{\catcode`\@=0 \catcode`\\=13  % We need to manipulate \ so use @ as escape
8609@catcode`@_=11  % private names
8610@catcode`@!=11  % used as argument separator
8611
8612% \passargtomacro#1#2 -
8613% Call #1 with a list of tokens #2, with any doubled backslashes in #2
8614% compressed to one.
8615%
8616% This implementation works by expansion, and not execution (so we cannot use
8617% \def or similar).  This reduces the risk of this failing in contexts where
8618% complete expansion is done with no execution (for example, in writing out to
8619% an auxiliary file for an index entry).
8620%
8621% State is kept in the input stream: the argument passed to
8622% @look_ahead, @gobble_and_check_finish and @add_segment is
8623%
8624% THE_MACRO ARG_RESULT ! {PENDING_BS} NEXT_TOKEN  (... rest of input)
8625%
8626% where:
8627% THE_MACRO - name of the macro we want to call
8628% ARG_RESULT - argument list we build to pass to that macro
8629% PENDING_BS - either a backslash or nothing
8630% NEXT_TOKEN - used to look ahead in the input stream to see what's coming next
8631
8632@gdef@passargtomacro#1#2{%
8633  @add_segment #1!{}@relax#2\@_finish\%
8634}
8635@gdef@_finish{@_finishx} @global@let@_finishx@relax
8636
8637% #1 - THE_MACRO ARG_RESULT
8638% #2 - PENDING_BS
8639% #3 - NEXT_TOKEN
8640% #4 used to look ahead
8641%
8642% If the next token is not a backslash, process the rest of the argument;
8643% otherwise, remove the next token.
8644@gdef@look_ahead#1!#2#3#4{%
8645  @ifx#4\%
8646   @expandafter@gobble_and_check_finish
8647  @else
8648   @expandafter@add_segment
8649  @fi#1!{#2}#4#4%
8650}
8651
8652% #1 - THE_MACRO ARG_RESULT
8653% #2 - PENDING_BS
8654% #3 - NEXT_TOKEN
8655% #4 should be a backslash, which is gobbled.
8656% #5 looks ahead
8657%
8658% Double backslash found.  Add a single backslash, and look ahead.
8659@gdef@gobble_and_check_finish#1!#2#3#4#5{%
8660  @add_segment#1\!{}#5#5%
8661}
8662
8663@gdef@is_fi{@fi}
8664
8665% #1 - THE_MACRO ARG_RESULT
8666% #2 - PENDING_BS
8667% #3 - NEXT_TOKEN
8668% #4 is input stream until next backslash
8669%
8670% Input stream is either at the start of the argument, or just after a
8671% backslash sequence, either a lone backslash, or a doubled backslash.
8672% NEXT_TOKEN contains the first token in the input stream: if it is \finish,
8673% finish; otherwise, append to ARG_RESULT the segment of the argument up until
8674% the next backslash.  PENDING_BACKSLASH contains a backslash to represent
8675% a backslash just before the start of the input stream that has not been
8676% added to ARG_RESULT.
8677@gdef@add_segment#1!#2#3#4\{%
8678@ifx#3@_finish
8679  @call_the_macro#1!%
8680@else
8681  % append the pending backslash to the result, followed by the next segment
8682  @expandafter@is_fi@look_ahead#1#2#4!{\}@fi
8683  % this @fi is discarded by @look_ahead.
8684  % we can't get rid of it with \expandafter because we don't know how
8685  % long #4 is.
8686}
8687
8688% #1 - THE_MACRO
8689% #2 - ARG_RESULT
8690% #3 discards the res of the conditional in @add_segment, and @is_fi ends the
8691% conditional.
8692@gdef@call_the_macro#1#2!#3@fi{@is_fi #1{#2}}
8693
8694}
8695%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8696
8697% \braceorline MAC is used for a one-argument macro MAC.  It checks
8698% whether the next non-whitespace character is a {.  It sets the context
8699% for reading the argument (slightly different in the two cases).  Then,
8700% to read the argument, in the whole-line case, it then calls the regular
8701% \parsearg MAC; in the lbrace case, it calls \passargtomacro MAC.
8702%
8703\def\braceorline#1{\let\macnamexxx=#1\futurelet\nchar\braceorlinexxx}
8704\def\braceorlinexxx{%
8705  \ifx\nchar\bgroup
8706    \macroargctxt
8707    \expandafter\passargtomacro
8708  \else
8709    \macrolineargctxt\expandafter\parsearg
8710  \fi \macnamexxx}
8711
8712
8713% @alias.
8714% We need some trickery to remove the optional spaces around the equal
8715% sign.  Make them active and then expand them all to nothing.
8716%
8717\def\alias{\parseargusing\obeyspaces\aliasxxx}
8718\def\aliasxxx #1{\aliasyyy#1\relax}
8719\def\aliasyyy #1=#2\relax{%
8720  {%
8721    \expandafter\let\obeyedspace=\empty
8722    \addtomacrolist{#1}%
8723    \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
8724  }%
8725  \next
8726}
8727
8728
8729\message{cross references,}
8730
8731\newwrite\auxfile
8732\newif\ifhavexrefs    % True if xref values are known.
8733\newif\ifwarnedxrefs  % True if we warned once that they aren't known.
8734
8735% @inforef is relatively simple.
8736\def\inforef #1{\inforefzzz #1,,,,**}
8737\def\inforefzzz #1,#2,#3,#4**{%
8738  \putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
8739  node \samp{\ignorespaces#1{}}}
8740
8741% @node's only job in TeX is to define \lastnode, which is used in
8742% cross-references.  The @node line might or might not have commas, and
8743% might or might not have spaces before the first comma, like:
8744% @node foo , bar , ...
8745% We don't want such trailing spaces in the node name.
8746%
8747\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
8748%
8749% also remove a trailing comma, in case of something like this:
8750% @node Help-Cross,  ,  , Cross-refs
8751\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
8752\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
8753
8754\let\nwnode=\node
8755\let\lastnode=\empty
8756
8757% Write a cross-reference definition for the current node.  #1 is the
8758% type (Ynumbered, Yappendix, Ynothing).
8759%
8760\def\donoderef#1{%
8761  \ifx\lastnode\empty\else
8762    \setref{\lastnode}{#1}%
8763    \global\let\lastnode=\empty
8764  \fi
8765}
8766
8767% @anchor{NAME} -- define xref target at arbitrary point.
8768%
8769\newcount\savesfregister
8770%
8771\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
8772\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
8773\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
8774
8775% \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
8776% anchor), which consists of three parts:
8777% 1) NAME-title - the current sectioning name taken from \currentsection,
8778%                 or the anchor name.
8779% 2) NAME-snt   - section number and type, passed as the SNT arg, or
8780%                 empty for anchors.
8781% 3) NAME-pg    - the page number.
8782%
8783% This is called from \donoderef, \anchor, and \dofloat.  In the case of
8784% floats, there is an additional part, which is not written here:
8785% 4) NAME-lof   - the text as it should appear in a @listoffloats.
8786%
8787\def\setref#1#2{%
8788  \pdfmkdest{#1}%
8789  \iflinks
8790    {%
8791      \requireauxfile
8792      \atdummies  % preserve commands, but don't expand them
8793      % match definition in \xrdef, \refx, \xrefX.
8794      \def\value##1{##1}%
8795      \edef\writexrdef##1##2{%
8796	\write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
8797	  ##1}{##2}}% these are parameters of \writexrdef
8798      }%
8799      \toks0 = \expandafter{\currentsection}%
8800      \immediate \writexrdef{title}{\the\toks0 }%
8801      \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
8802      \safewhatsit{\writexrdef{pg}{\folio}}% will be written later, at \shipout
8803    }%
8804  \fi
8805}
8806
8807% @xrefautosectiontitle on|off says whether @section(ing) names are used
8808% automatically in xrefs, if the third arg is not explicitly specified.
8809% This was provided as a "secret" @set xref-automatic-section-title
8810% variable, now it's official.
8811%
8812\parseargdef\xrefautomaticsectiontitle{%
8813  \def\temp{#1}%
8814  \ifx\temp\onword
8815    \expandafter\let\csname SETxref-automatic-section-title\endcsname
8816      = \empty
8817  \else\ifx\temp\offword
8818    \expandafter\let\csname SETxref-automatic-section-title\endcsname
8819      = \relax
8820  \else
8821    \errhelp = \EMsimple
8822    \errmessage{Unknown @xrefautomaticsectiontitle value `\temp',
8823                must be on|off}%
8824  \fi\fi
8825}
8826
8827%
8828% @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
8829% the node name, #2 the name of the Info cross-reference, #3 the printed
8830% node name, #4 the name of the Info file, #5 the name of the printed
8831% manual.  All but the node name can be omitted.
8832%
8833\def\pxref{\putwordsee{} \xrefXX}
8834\def\xref{\putwordSee{} \xrefXX}
8835\def\ref{\xrefXX}
8836
8837\def\xrefXX#1{\def\xrefXXarg{#1}\futurelet\tokenafterxref\xrefXXX}
8838\def\xrefXXX{\expandafter\xrefX\expandafter[\xrefXXarg,,,,,,,]}
8839%
8840\newbox\toprefbox
8841\newbox\printedrefnamebox
8842\newbox\infofilenamebox
8843\newbox\printedmanualbox
8844%
8845\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
8846  \unsepspaces
8847  %
8848  % Get args without leading/trailing spaces.
8849  \def\printedrefname{\ignorespaces #3}%
8850  \setbox\printedrefnamebox = \hbox{\printedrefname\unskip}%
8851  %
8852  \def\infofilename{\ignorespaces #4}%
8853  \setbox\infofilenamebox = \hbox{\infofilename\unskip}%
8854  %
8855  \def\printedmanual{\ignorespaces #5}%
8856  \setbox\printedmanualbox  = \hbox{\printedmanual\unskip}%
8857  %
8858  % If the printed reference name (arg #3) was not explicitly given in
8859  % the @xref, figure out what we want to use.
8860  \ifdim \wd\printedrefnamebox = 0pt
8861    % No printed node name was explicitly given.
8862    \expandafter\ifx\csname SETxref-automatic-section-title\endcsname \relax
8863      % Not auto section-title: use node name inside the square brackets.
8864      \def\printedrefname{\ignorespaces #1}%
8865    \else
8866      % Auto section-title: use chapter/section title inside
8867      % the square brackets if we have it.
8868      \ifdim \wd\printedmanualbox > 0pt
8869        % It is in another manual, so we don't have it; use node name.
8870        \def\printedrefname{\ignorespaces #1}%
8871      \else
8872        \ifhavexrefs
8873          % We (should) know the real title if we have the xref values.
8874          \def\printedrefname{\refx{#1-title}{}}%
8875        \else
8876          % Otherwise just copy the Info node name.
8877          \def\printedrefname{\ignorespaces #1}%
8878        \fi%
8879      \fi
8880    \fi
8881  \fi
8882  %
8883  % Make link in pdf output.
8884  \ifpdf
8885    % For pdfTeX and LuaTeX
8886    {\indexnofonts
8887     \makevalueexpandable
8888     \turnoffactive
8889     % This expands tokens, so do it after making catcode changes, so _
8890     % etc. don't get their TeX definitions.  This ignores all spaces in
8891     % #4, including (wrongly) those in the middle of the filename.
8892     \getfilename{#4}%
8893     %
8894     % This (wrongly) does not take account of leading or trailing
8895     % spaces in #1, which should be ignored.
8896     \setpdfdestname{#1}%
8897     %
8898     \ifx\pdfdestname\empty
8899       \def\pdfdestname{Top}% no empty targets
8900     \fi
8901     %
8902     \leavevmode
8903     \startlink attr{/Border [0 0 0]}%
8904     \ifnum\filenamelength>0
8905       goto file{\the\filename.pdf} name{\pdfdestname}%
8906     \else
8907       goto name{\pdfmkpgn{\pdfdestname}}%
8908     \fi
8909    }%
8910    \setcolor{\linkcolor}%
8911  \else
8912    \ifx\XeTeXrevision\thisisundefined
8913    \else
8914      % For XeTeX
8915      {\indexnofonts
8916       \makevalueexpandable
8917       \turnoffactive
8918       % This expands tokens, so do it after making catcode changes, so _
8919       % etc. don't get their TeX definitions.  This ignores all spaces in
8920       % #4, including (wrongly) those in the middle of the filename.
8921       \getfilename{#4}%
8922       %
8923       % This (wrongly) does not take account of leading or trailing
8924       % spaces in #1, which should be ignored.
8925       \setpdfdestname{#1}%
8926       %
8927       \ifx\pdfdestname\empty
8928         \def\pdfdestname{Top}% no empty targets
8929       \fi
8930       %
8931       \leavevmode
8932       \ifnum\filenamelength>0
8933         % With default settings,
8934         % XeTeX (xdvipdfmx) replaces link destination names with integers.
8935         % In this case, the replaced destination names of
8936         % remote PDFs are no longer known.  In order to avoid a replacement,
8937         % you can use xdvipdfmx's command line option `-C 0x0010'.
8938         % If you use XeTeX 0.99996+ (TeX Live 2016+),
8939         % this command line option is no longer necessary
8940         % because we can use the `dvipdfmx:config' special.
8941         \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8942           << /S /GoToR /F (\the\filename.pdf) /D (\pdfdestname) >> >>}%
8943       \else
8944         \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8945           << /S /GoTo /D (\pdfdestname) >> >>}%
8946       \fi
8947      }%
8948      \setcolor{\linkcolor}%
8949    \fi
8950  \fi
8951  {%
8952    % Have to otherify everything special to allow the \csname to
8953    % include an _ in the xref name, etc.
8954    \indexnofonts
8955    \turnoffactive
8956    \def\value##1{##1}%
8957    \expandafter\global\expandafter\let\expandafter\Xthisreftitle
8958      \csname XR#1-title\endcsname
8959  }%
8960  %
8961  % Float references are printed completely differently: "Figure 1.2"
8962  % instead of "[somenode], p.3".  \iffloat distinguishes them by
8963  % \Xthisreftitle being set to a magic string.
8964  \iffloat\Xthisreftitle
8965    % If the user specified the print name (third arg) to the ref,
8966    % print it instead of our usual "Figure 1.2".
8967    \ifdim\wd\printedrefnamebox = 0pt
8968      \refx{#1-snt}{}%
8969    \else
8970      \printedrefname
8971    \fi
8972    %
8973    % If the user also gave the printed manual name (fifth arg), append
8974    % "in MANUALNAME".
8975    \ifdim \wd\printedmanualbox > 0pt
8976      \space \putwordin{} \cite{\printedmanual}%
8977    \fi
8978  \else
8979    % node/anchor (non-float) references.
8980    %
8981    % If we use \unhbox to print the node names, TeX does not insert
8982    % empty discretionaries after hyphens, which means that it will not
8983    % find a line break at a hyphen in a node names.  Since some manuals
8984    % are best written with fairly long node names, containing hyphens,
8985    % this is a loss.  Therefore, we give the text of the node name
8986    % again, so it is as if TeX is seeing it for the first time.
8987    %
8988    \ifdim \wd\printedmanualbox > 0pt
8989      % Cross-manual reference with a printed manual name.
8990      %
8991      \crossmanualxref{\cite{\printedmanual\unskip}}%
8992    %
8993    \else\ifdim \wd\infofilenamebox > 0pt
8994      % Cross-manual reference with only an info filename (arg 4), no
8995      % printed manual name (arg 5).  This is essentially the same as
8996      % the case above; we output the filename, since we have nothing else.
8997      %
8998      \crossmanualxref{\code{\infofilename\unskip}}%
8999    %
9000    \else
9001      % Reference within this manual.
9002      %
9003      % _ (for example) has to be the character _ for the purposes of the
9004      % control sequence corresponding to the node, but it has to expand
9005      % into the usual \leavevmode...\vrule stuff for purposes of
9006      % printing. So we \turnoffactive for the \refx-snt, back on for the
9007      % printing, back off for the \refx-pg.
9008      {\turnoffactive
9009       % Only output a following space if the -snt ref is nonempty; for
9010       % @unnumbered and @anchor, it won't be.
9011       \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
9012       \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
9013      }%
9014      % output the `[mynode]' via the macro below so it can be overridden.
9015      \xrefprintnodename\printedrefname
9016      %
9017      % But we always want a comma and a space:
9018      ,\space
9019      %
9020      % output the `page 3'.
9021      \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
9022      % Add a , if xref followed by a space
9023      \if\space\noexpand\tokenafterxref ,%
9024      \else\ifx\	\tokenafterxref ,% @TAB
9025      \else\ifx\*\tokenafterxref ,%   @*
9026      \else\ifx\ \tokenafterxref ,%   @SPACE
9027      \else\ifx\
9028                \tokenafterxref ,%    @NL
9029      \else\ifx\tie\tokenafterxref ,% @tie
9030      \fi\fi\fi\fi\fi\fi
9031    \fi\fi
9032  \fi
9033  \endlink
9034\endgroup}
9035
9036% Output a cross-manual xref to #1.  Used just above (twice).
9037%
9038% Only include the text "Section ``foo'' in" if the foo is neither
9039% missing or Top.  Thus, @xref{,,,foo,The Foo Manual} outputs simply
9040% "see The Foo Manual", the idea being to refer to the whole manual.
9041%
9042% But, this being TeX, we can't easily compare our node name against the
9043% string "Top" while ignoring the possible spaces before and after in
9044% the input.  By adding the arbitrary 7sp below, we make it much less
9045% likely that a real node name would have the same width as "Top" (e.g.,
9046% in a monospaced font).  Hopefully it will never happen in practice.
9047%
9048% For the same basic reason, we retypeset the "Top" at every
9049% reference, since the current font is indeterminate.
9050%
9051\def\crossmanualxref#1{%
9052  \setbox\toprefbox = \hbox{Top\kern7sp}%
9053  \setbox2 = \hbox{\ignorespaces \printedrefname \unskip \kern7sp}%
9054  \ifdim \wd2 > 7sp  % nonempty?
9055    \ifdim \wd2 = \wd\toprefbox \else  % same as Top?
9056      \putwordSection{} ``\printedrefname'' \putwordin{}\space
9057    \fi
9058  \fi
9059  #1%
9060}
9061
9062% This macro is called from \xrefX for the `[nodename]' part of xref
9063% output.  It's a separate macro only so it can be changed more easily,
9064% since square brackets don't work well in some documents.  Particularly
9065% one that Bob is working on :).
9066%
9067\def\xrefprintnodename#1{[#1]}
9068
9069% Things referred to by \setref.
9070%
9071\def\Ynothing{}
9072\def\Yomitfromtoc{}
9073\def\Ynumbered{%
9074  \ifnum\secno=0
9075    \putwordChapter@tie \the\chapno
9076  \else \ifnum\subsecno=0
9077    \putwordSection@tie \the\chapno.\the\secno
9078  \else \ifnum\subsubsecno=0
9079    \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
9080  \else
9081    \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
9082  \fi\fi\fi
9083}
9084\def\Yappendix{%
9085  \ifnum\secno=0
9086     \putwordAppendix@tie @char\the\appendixno{}%
9087  \else \ifnum\subsecno=0
9088     \putwordSection@tie @char\the\appendixno.\the\secno
9089  \else \ifnum\subsubsecno=0
9090    \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
9091  \else
9092    \putwordSection@tie
9093      @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
9094  \fi\fi\fi
9095}
9096
9097% \refx{NAME}{SUFFIX} - reference a cross-reference string named NAME.  SUFFIX
9098% is output afterwards if non-empty.
9099\def\refx#1#2{%
9100  \requireauxfile
9101  {%
9102    \indexnofonts
9103    \otherbackslash
9104    \def\value##1{##1}%
9105    \expandafter\global\expandafter\let\expandafter\thisrefX
9106      \csname XR#1\endcsname
9107  }%
9108  \ifx\thisrefX\relax
9109    % If not defined, say something at least.
9110    \angleleft un\-de\-fined\angleright
9111    \iflinks
9112      \ifhavexrefs
9113        {\toks0 = {#1}% avoid expansion of possibly-complex value
9114         \message{\linenumber Undefined cross reference `\the\toks0'.}}%
9115      \else
9116        \ifwarnedxrefs\else
9117          \global\warnedxrefstrue
9118          \message{Cross reference values unknown; you must run TeX again.}%
9119        \fi
9120      \fi
9121    \fi
9122  \else
9123    % It's defined, so just use it.
9124    \thisrefX
9125  \fi
9126  #2% Output the suffix in any case.
9127}
9128
9129% This is the macro invoked by entries in the aux file.  Define a control
9130% sequence for a cross-reference target (we prepend XR to the control sequence
9131% name to avoid collisions).  The value is the page number.  If this is a float
9132% type, we have more work to do.
9133%
9134\def\xrdef#1#2{%
9135  {% Expand the node or anchor name to remove control sequences.
9136   % \turnoffactive stops 8-bit characters being changed to commands
9137   % like @'e.  \refx does the same to retrieve the value in the definition.
9138    \indexnofonts
9139    \turnoffactive
9140    \def\value##1{##1}%
9141    \xdef\safexrefname{#1}%
9142  }%
9143  %
9144  \bgroup
9145    \expandafter\gdef\csname XR\safexrefname\endcsname{#2}%
9146  \egroup
9147  % We put the \gdef inside a group to avoid the definitions building up on
9148  % TeX's save stack, which can cause it to run out of space for aux files with
9149  % thousands of lines.  \gdef doesn't use the save stack, but \csname does
9150  % when it defines an unknown control sequence as \relax.
9151  %
9152  % Was that xref control sequence that we just defined for a float?
9153  \expandafter\iffloat\csname XR\safexrefname\endcsname
9154    % it was a float, and we have the (safe) float type in \iffloattype.
9155    \expandafter\let\expandafter\floatlist
9156      \csname floatlist\iffloattype\endcsname
9157    %
9158    % Is this the first time we've seen this float type?
9159    \expandafter\ifx\floatlist\relax
9160      \toks0 = {\do}% yes, so just \do
9161    \else
9162      % had it before, so preserve previous elements in list.
9163      \toks0 = \expandafter{\floatlist\do}%
9164    \fi
9165    %
9166    % Remember this xref in the control sequence \floatlistFLOATTYPE,
9167    % for later use in \listoffloats.
9168    \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0
9169      {\safexrefname}}%
9170  \fi
9171}
9172
9173% If working on a large document in chapters, it is convenient to
9174% be able to disable indexing, cross-referencing, and contents, for test runs.
9175% This is done with @novalidate at the beginning of the file.
9176%
9177\newif\iflinks \linkstrue % by default we want the aux files.
9178\let\novalidate = \linksfalse
9179
9180% Used when writing to the aux file, or when using data from it.
9181\def\requireauxfile{%
9182  \iflinks
9183    \tryauxfile
9184    % Open the new aux file.  TeX will close it automatically at exit.
9185    \immediate\openout\auxfile=\jobname.aux
9186  \fi
9187  \global\let\requireauxfile=\relax   % Only do this once.
9188}
9189
9190% Read the last existing aux file, if any.  No error if none exists.
9191%
9192\def\tryauxfile{%
9193  \openin 1 \jobname.aux
9194  \ifeof 1 \else
9195    \readdatafile{aux}%
9196    \global\havexrefstrue
9197  \fi
9198  \closein 1
9199}
9200
9201\def\setupdatafile{%
9202  \catcode`\^^@=\other
9203  \catcode`\^^A=\other
9204  \catcode`\^^B=\other
9205  \catcode`\^^C=\other
9206  \catcode`\^^D=\other
9207  \catcode`\^^E=\other
9208  \catcode`\^^F=\other
9209  \catcode`\^^G=\other
9210  \catcode`\^^H=\other
9211  \catcode`\^^K=\other
9212  \catcode`\^^L=\other
9213  \catcode`\^^N=\other
9214  \catcode`\^^P=\other
9215  \catcode`\^^Q=\other
9216  \catcode`\^^R=\other
9217  \catcode`\^^S=\other
9218  \catcode`\^^T=\other
9219  \catcode`\^^U=\other
9220  \catcode`\^^V=\other
9221  \catcode`\^^W=\other
9222  \catcode`\^^X=\other
9223  \catcode`\^^Z=\other
9224  \catcode`\^^[=\other
9225  \catcode`\^^\=\other
9226  \catcode`\^^]=\other
9227  \catcode`\^^^=\other
9228  \catcode`\^^_=\other
9229  % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
9230  % in xref tags, i.e., node names.  But since ^^e4 notation isn't
9231  % supported in the main text, it doesn't seem desirable.  Furthermore,
9232  % that is not enough: for node names that actually contain a ^
9233  % character, we would end up writing a line like this: 'xrdef {'hat
9234  % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
9235  % argument, and \hat is not an expandable control sequence.  It could
9236  % all be worked out, but why?  Either we support ^^ or we don't.
9237  %
9238  % The other change necessary for this was to define \auxhat:
9239  % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
9240  % and then to call \auxhat in \setq.
9241  %
9242  \catcode`\^=\other
9243  %
9244  % Special characters.  Should be turned off anyway, but...
9245  \catcode`\~=\other
9246  \catcode`\[=\other
9247  \catcode`\]=\other
9248  \catcode`\"=\other
9249  \catcode`\_=\other
9250  \catcode`\|=\other
9251  \catcode`\<=\other
9252  \catcode`\>=\other
9253  \catcode`\$=\other
9254  \catcode`\#=\other
9255  \catcode`\&=\other
9256  \catcode`\%=\other
9257  \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
9258  %
9259  % This is to support \ in node names and titles, since the \
9260  % characters end up in a \csname.  It's easier than
9261  % leaving it active and making its active definition an actual \
9262  % character.  What I don't understand is why it works in the *value*
9263  % of the xrdef.  Seems like it should be a catcode12 \, and that
9264  % should not typeset properly.  But it works, so I'm moving on for
9265  % now.  --karl, 15jan04.
9266  \catcode`\\=\other
9267  %
9268  % @ is our escape character in .aux files, and we need braces.
9269  \catcode`\{=1
9270  \catcode`\}=2
9271  \catcode`\@=0
9272}
9273
9274\def\readdatafile#1{%
9275\begingroup
9276  \setupdatafile
9277  \input\jobname.#1
9278\endgroup}
9279
9280
9281\message{insertions,}
9282% including footnotes.
9283
9284\newcount \footnoteno
9285
9286% The trailing space in the following definition for supereject is
9287% vital for proper filling; pages come out unaligned when you do a
9288% pagealignmacro call if that space before the closing brace is
9289% removed. (Generally, numeric constants should always be followed by a
9290% space to prevent strange expansion errors.)
9291\def\supereject{\par\penalty -20000\footnoteno =0 }
9292
9293% @footnotestyle is meaningful for Info output only.
9294\let\footnotestyle=\comment
9295
9296{\catcode `\@=11
9297%
9298% Auto-number footnotes.  Otherwise like plain.
9299\gdef\footnote{%
9300  \global\advance\footnoteno by \@ne
9301  \edef\thisfootno{$^{\the\footnoteno}$}%
9302  %
9303  % In case the footnote comes at the end of a sentence, preserve the
9304  % extra spacing after we do the footnote number.
9305  \let\@sf\empty
9306  \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
9307  %
9308  % Remove inadvertent blank space before typesetting the footnote number.
9309  \unskip
9310  \thisfootno\@sf
9311  \dofootnote
9312}%
9313
9314% Don't bother with the trickery in plain.tex to not require the
9315% footnote text as a parameter.  Our footnotes don't need to be so general.
9316%
9317% Oh yes, they do; otherwise, @ifset (and anything else that uses
9318% \parseargline) fails inside footnotes because the tokens are fixed when
9319% the footnote is read.  --karl, 16nov96.
9320%
9321\gdef\dofootnote{%
9322  \insert\footins\bgroup
9323  %
9324  % Nested footnotes are not supported in TeX, that would take a lot
9325  % more work.  (\startsavinginserts does not suffice.)
9326  \let\footnote=\errfootnotenest
9327  %
9328  % We want to typeset this text as a normal paragraph, even if the
9329  % footnote reference occurs in (for example) a display environment.
9330  % So reset some parameters.
9331  \hsize=\txipagewidth
9332  \interlinepenalty\interfootnotelinepenalty
9333  \splittopskip\ht\strutbox % top baseline for broken footnotes
9334  \splitmaxdepth\dp\strutbox
9335  \floatingpenalty\@MM
9336  \leftskip\z@skip
9337  \rightskip\z@skip
9338  \spaceskip\z@skip
9339  \xspaceskip\z@skip
9340  \parindent\defaultparindent
9341  %
9342  \smallfonts \rm
9343  %
9344  % Because we use hanging indentation in footnotes, a @noindent appears
9345  % to exdent this text, so make it be a no-op.  makeinfo does not use
9346  % hanging indentation so @noindent can still be needed within footnote
9347  % text after an @example or the like (not that this is good style).
9348  \let\noindent = \relax
9349  %
9350  % Hang the footnote text off the number.  Use \everypar in case the
9351  % footnote extends for more than one paragraph.
9352  \everypar = {\hang}%
9353  \textindent{\thisfootno}%
9354  %
9355  % Don't crash into the line above the footnote text.  Since this
9356  % expands into a box, it must come within the paragraph, lest it
9357  % provide a place where TeX can split the footnote.
9358  \footstrut
9359  %
9360  % Invoke rest of plain TeX footnote routine.
9361  \futurelet\next\fo@t
9362}
9363}%end \catcode `\@=11
9364
9365\def\errfootnotenest{%
9366  \errhelp=\EMsimple
9367  \errmessage{Nested footnotes not supported in texinfo.tex,
9368    even though they work in makeinfo; sorry}
9369}
9370
9371\def\errfootnoteheading{%
9372  \errhelp=\EMsimple
9373  \errmessage{Footnotes in chapters, sections, etc., are not supported}
9374}
9375
9376% In case a @footnote appears in a vbox, save the footnote text and create
9377% the real \insert just after the vbox finished.  Otherwise, the insertion
9378% would be lost.
9379% Similarly, if a @footnote appears inside an alignment, save the footnote
9380% text to a box and make the \insert when a row of the table is finished.
9381% And the same can be done for other insert classes.  --kasal, 16nov03.
9382%
9383% Replace the \insert primitive by a cheating macro.
9384% Deeper inside, just make sure that the saved insertions are not spilled
9385% out prematurely.
9386%
9387\def\startsavinginserts{%
9388  \ifx \insert\ptexinsert
9389    \let\insert\saveinsert
9390  \else
9391    \let\checkinserts\relax
9392  \fi
9393}
9394
9395% This \insert replacement works for both \insert\footins{foo} and
9396% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
9397%
9398\def\saveinsert#1{%
9399  \edef\next{\noexpand\savetobox \makeSAVEname#1}%
9400  \afterassignment\next
9401  % swallow the left brace
9402  \let\temp =
9403}
9404\def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
9405\def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
9406
9407\def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
9408
9409\def\placesaveins#1{%
9410  \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
9411    {\box#1}%
9412}
9413
9414% eat @SAVE -- beware, all of them have catcode \other:
9415{
9416  \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials  %  ;-)
9417  \gdef\gobblesave @SAVE{}
9418}
9419
9420% initialization:
9421\def\newsaveins #1{%
9422  \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
9423  \next
9424}
9425\def\newsaveinsX #1{%
9426  \csname newbox\endcsname #1%
9427  \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
9428    \checksaveins #1}%
9429}
9430
9431% initialize:
9432\let\checkinserts\empty
9433\newsaveins\footins
9434\newsaveins\margin
9435
9436
9437% @image.  We use the macros from epsf.tex to support this.
9438% If epsf.tex is not installed and @image is used, we complain.
9439%
9440% Check for and read epsf.tex up front.  If we read it only at @image
9441% time, we might be inside a group, and then its definitions would get
9442% undone and the next image would fail.
9443\openin 1 = epsf.tex
9444\ifeof 1 \else
9445  % Do not bother showing banner with epsf.tex v2.7k (available in
9446  % doc/epsf.tex and on ctan).
9447  \def\epsfannounce{\toks0 = }%
9448  \input epsf.tex
9449\fi
9450\closein 1
9451%
9452% We will only complain once about lack of epsf.tex.
9453\newif\ifwarnednoepsf
9454\newhelp\noepsfhelp{epsf.tex must be installed for images to
9455  work.  It is also included in the Texinfo distribution, or you can get
9456  it from https://ctan.org/texarchive/macros/texinfo/texinfo/doc/epsf.tex.}
9457%
9458\def\image#1{%
9459  \ifx\epsfbox\thisisundefined
9460    \ifwarnednoepsf \else
9461      \errhelp = \noepsfhelp
9462      \errmessage{epsf.tex not found, images will be ignored}%
9463      \global\warnednoepsftrue
9464    \fi
9465  \else
9466    \imagexxx #1,,,,,\finish
9467  \fi
9468}
9469%
9470% Arguments to @image:
9471% #1 is (mandatory) image filename; we tack on .eps extension.
9472% #2 is (optional) width, #3 is (optional) height.
9473% #4 is (ignored optional) html alt text.
9474% #5 is (ignored optional) extension.
9475% #6 is just the usual extra ignored arg for parsing stuff.
9476\newif\ifimagevmode
9477\def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
9478  \catcode`\^^M = 5     % in case we're inside an example
9479  \normalturnoffactive  % allow _ et al. in names
9480  \def\xprocessmacroarg{\eatspaces}% in case we are being used via a macro
9481  % If the image is by itself, center it.
9482  \ifvmode
9483    \imagevmodetrue
9484  \else \ifx\centersub\centerV
9485    % for @center @image, we need a vbox so we can have our vertical space
9486    \imagevmodetrue
9487    \vbox\bgroup % vbox has better behavior than vtop herev
9488  \fi\fi
9489  %
9490  \ifimagevmode
9491    \nobreak\medskip
9492    % Usually we'll have text after the image which will insert
9493    % \parskip glue, so insert it here too to equalize the space
9494    % above and below.
9495    \nobreak\vskip\parskip
9496    \nobreak
9497  \fi
9498  %
9499  % Leave vertical mode so that indentation from an enclosing
9500  %  environment such as @quotation is respected.
9501  % However, if we're at the top level, we don't want the
9502  %  normal paragraph indentation.
9503  % On the other hand, if we are in the case of @center @image, we don't
9504  %  want to start a paragraph, which will create a hsize-width box and
9505  %  eradicate the centering.
9506  \ifx\centersub\centerV\else \noindent \fi
9507  %
9508  % Output the image.
9509  \ifpdf
9510    % For pdfTeX and LuaTeX <= 0.80
9511    \dopdfimage{#1}{#2}{#3}%
9512  \else
9513    \ifx\XeTeXrevision\thisisundefined
9514      % For epsf.tex
9515      % \epsfbox itself resets \epsf?size at each figure.
9516      \setbox0 = \hbox{\ignorespaces #2}%
9517        \ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
9518      \setbox0 = \hbox{\ignorespaces #3}%
9519        \ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
9520      \epsfbox{#1.eps}%
9521    \else
9522      % For XeTeX
9523      \doxeteximage{#1}{#2}{#3}%
9524    \fi
9525  \fi
9526  %
9527  \ifimagevmode
9528    \medskip  % space after a standalone image
9529  \fi
9530  \ifx\centersub\centerV \egroup \fi
9531\endgroup}
9532
9533
9534% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
9535% etc.  We don't actually implement floating yet, we always include the
9536% float "here".  But it seemed the best name for the future.
9537%
9538\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
9539
9540% There may be a space before second and/or third parameter; delete it.
9541\def\eatcommaspace#1, {#1,}
9542
9543% #1 is the optional FLOATTYPE, the text label for this float, typically
9544% "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
9545% this float will not be numbered and cannot be referred to.
9546%
9547% #2 is the optional xref label.  Also must be present for the float to
9548% be referable.
9549%
9550% #3 is the optional positioning argument; for now, it is ignored.  It
9551% will somehow specify the positions allowed to float to (here, top, bottom).
9552%
9553% We keep a separate counter for each FLOATTYPE, which we reset at each
9554% chapter-level command.
9555\let\resetallfloatnos=\empty
9556%
9557\def\dofloat#1,#2,#3,#4\finish{%
9558  \let\thiscaption=\empty
9559  \let\thisshortcaption=\empty
9560  %
9561  % don't lose footnotes inside @float.
9562  %
9563  % BEWARE: when the floats start float, we have to issue warning whenever an
9564  % insert appears inside a float which could possibly float. --kasal, 26may04
9565  %
9566  \startsavinginserts
9567  %
9568  % We can't be used inside a paragraph.
9569  \par
9570  %
9571  \vtop\bgroup
9572    \def\floattype{#1}%
9573    \def\floatlabel{#2}%
9574    \def\floatloc{#3}% we do nothing with this yet.
9575    %
9576    \ifx\floattype\empty
9577      \let\safefloattype=\empty
9578    \else
9579      {%
9580        % the floattype might have accents or other special characters,
9581        % but we need to use it in a control sequence name.
9582        \indexnofonts
9583        \turnoffactive
9584        \xdef\safefloattype{\floattype}%
9585      }%
9586    \fi
9587    %
9588    % If label is given but no type, we handle that as the empty type.
9589    \ifx\floatlabel\empty \else
9590      % We want each FLOATTYPE to be numbered separately (Figure 1,
9591      % Table 1, Figure 2, ...).  (And if no label, no number.)
9592      %
9593      \expandafter\getfloatno\csname\safefloattype floatno\endcsname
9594      \global\advance\floatno by 1
9595      %
9596      {%
9597        % This magic value for \currentsection is output by \setref as the
9598        % XREFLABEL-title value.  \xrefX uses it to distinguish float
9599        % labels (which have a completely different output format) from
9600        % node and anchor labels.  And \xrdef uses it to construct the
9601        % lists of floats.
9602        %
9603        \edef\currentsection{\floatmagic=\safefloattype}%
9604        \setref{\floatlabel}{Yfloat}%
9605      }%
9606    \fi
9607    %
9608    % start with \parskip glue, I guess.
9609    \vskip\parskip
9610    %
9611    % Don't suppress indentation if a float happens to start a section.
9612    \restorefirstparagraphindent
9613}
9614
9615% we have these possibilities:
9616% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
9617% @float Foo,lbl & no caption:    Foo 1.1
9618% @float Foo & @caption{Cap}:     Foo: Cap
9619% @float Foo & no caption:        Foo
9620% @float ,lbl & Caption{Cap}:     1.1: Cap
9621% @float ,lbl & no caption:       1.1
9622% @float & @caption{Cap}:         Cap
9623% @float & no caption:
9624%
9625\def\Efloat{%
9626    \let\floatident = \empty
9627    %
9628    % In all cases, if we have a float type, it comes first.
9629    \ifx\floattype\empty \else \def\floatident{\floattype}\fi
9630    %
9631    % If we have an xref label, the number comes next.
9632    \ifx\floatlabel\empty \else
9633      \ifx\floattype\empty \else % if also had float type, need tie first.
9634        \appendtomacro\floatident{\tie}%
9635      \fi
9636      % the number.
9637      \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
9638    \fi
9639    %
9640    % Start the printed caption with what we've constructed in
9641    % \floatident, but keep it separate; we need \floatident again.
9642    \let\captionline = \floatident
9643    %
9644    \ifx\thiscaption\empty \else
9645      \ifx\floatident\empty \else
9646        \appendtomacro\captionline{: }% had ident, so need a colon between
9647      \fi
9648      %
9649      % caption text.
9650      \appendtomacro\captionline{\scanexp\thiscaption}%
9651    \fi
9652    %
9653    % If we have anything to print, print it, with space before.
9654    % Eventually this needs to become an \insert.
9655    \ifx\captionline\empty \else
9656      \vskip.5\parskip
9657      \captionline
9658      %
9659      % Space below caption.
9660      \vskip\parskip
9661    \fi
9662    %
9663    % If have an xref label, write the list of floats info.  Do this
9664    % after the caption, to avoid chance of it being a breakpoint.
9665    \ifx\floatlabel\empty \else
9666      % Write the text that goes in the lof to the aux file as
9667      % \floatlabel-lof.  Besides \floatident, we include the short
9668      % caption if specified, else the full caption if specified, else nothing.
9669      {%
9670        \requireauxfile
9671        \atdummies
9672        %
9673        \ifx\thisshortcaption\empty
9674          \def\gtemp{\thiscaption}%
9675        \else
9676          \def\gtemp{\thisshortcaption}%
9677        \fi
9678        \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
9679          \ifx\gtemp\empty \else : \gtemp \fi}}%
9680      }%
9681    \fi
9682  \egroup  % end of \vtop
9683  %
9684  \checkinserts
9685}
9686
9687% Append the tokens #2 to the definition of macro #1, not expanding either.
9688%
9689\def\appendtomacro#1#2{%
9690  \expandafter\def\expandafter#1\expandafter{#1#2}%
9691}
9692
9693% @caption, @shortcaption
9694%
9695\def\caption{\docaption\thiscaption}
9696\def\shortcaption{\docaption\thisshortcaption}
9697\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
9698\def\defcaption#1#2{\egroup \def#1{#2}}
9699
9700% The parameter is the control sequence identifying the counter we are
9701% going to use.  Create it if it doesn't exist and assign it to \floatno.
9702\def\getfloatno#1{%
9703  \ifx#1\relax
9704      % Haven't seen this figure type before.
9705      \csname newcount\endcsname #1%
9706      %
9707      % Remember to reset this floatno at the next chap.
9708      \expandafter\gdef\expandafter\resetallfloatnos
9709        \expandafter{\resetallfloatnos #1=0 }%
9710  \fi
9711  \let\floatno#1%
9712}
9713
9714% \setref calls this to get the XREFLABEL-snt value.  We want an @xref
9715% to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
9716% first read the @float command.
9717%
9718\def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
9719
9720% Magic string used for the XREFLABEL-title value, so \xrefX can
9721% distinguish floats from other xref types.
9722\def\floatmagic{!!float!!}
9723
9724% #1 is the control sequence we are passed; we expand into a conditional
9725% which is true if #1 represents a float ref.  That is, the magic
9726% \currentsection value which we \setref above.
9727%
9728\def\iffloat#1{\expandafter\doiffloat#1==\finish}
9729%
9730% #1 is (maybe) the \floatmagic string.  If so, #2 will be the
9731% (safe) float type for this float.  We set \iffloattype to #2.
9732%
9733\def\doiffloat#1=#2=#3\finish{%
9734  \def\temp{#1}%
9735  \def\iffloattype{#2}%
9736  \ifx\temp\floatmagic
9737}
9738
9739% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
9740%
9741\parseargdef\listoffloats{%
9742  \def\floattype{#1}% floattype
9743  {%
9744    % the floattype might have accents or other special characters,
9745    % but we need to use it in a control sequence name.
9746    \indexnofonts
9747    \turnoffactive
9748    \xdef\safefloattype{\floattype}%
9749  }%
9750  %
9751  % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
9752  \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
9753    \ifhavexrefs
9754      % if the user said @listoffloats foo but never @float foo.
9755      \message{\linenumber No `\safefloattype' floats to list.}%
9756    \fi
9757  \else
9758    \begingroup
9759      \leftskip=\tocindent  % indent these entries like a toc
9760      \let\do=\listoffloatsdo
9761      \csname floatlist\safefloattype\endcsname
9762    \endgroup
9763  \fi
9764}
9765
9766% This is called on each entry in a list of floats.  We're passed the
9767% xref label, in the form LABEL-title, which is how we save it in the
9768% aux file.  We strip off the -title and look up \XRLABEL-lof, which
9769% has the text we're supposed to typeset here.
9770%
9771% Figures without xref labels will not be included in the list (since
9772% they won't appear in the aux file).
9773%
9774\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
9775\def\listoffloatsdoentry#1-title\finish{{%
9776  % Can't fully expand XR#1-lof because it can contain anything.  Just
9777  % pass the control sequence.  On the other hand, XR#1-pg is just the
9778  % page number, and we want to fully expand that so we can get a link
9779  % in pdf output.
9780  \toksA = \expandafter{\csname XR#1-lof\endcsname}%
9781  %
9782  % use the same \entry macro we use to generate the TOC and index.
9783  \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
9784  \writeentry
9785}}
9786
9787
9788\message{localization,}
9789
9790% For single-language documents, @documentlanguage is usually given very
9791% early, just after @documentencoding.  Single argument is the language
9792% (de) or locale (de_DE) abbreviation.
9793%
9794{
9795  \catcode`\_ = \active
9796  \globaldefs=1
9797\parseargdef\documentlanguage{%
9798  \tex % read txi-??.tex file in plain TeX.
9799    % Read the file by the name they passed if it exists.
9800    \let_ = \normalunderscore  % normal _ character for filename test
9801    \openin 1 txi-#1.tex
9802    \ifeof 1
9803      \documentlanguagetrywithoutunderscore #1_\finish
9804    \else
9805      \globaldefs = 1  % everything in the txi-LL files needs to persist
9806      \input txi-#1.tex
9807    \fi
9808    \closein 1
9809  \endgroup % end raw TeX
9810}
9811%
9812% If they passed de_DE, and txi-de_DE.tex doesn't exist,
9813% try txi-de.tex.
9814%
9815\gdef\documentlanguagetrywithoutunderscore#1_#2\finish{%
9816  \openin 1 txi-#1.tex
9817  \ifeof 1
9818    \errhelp = \nolanghelp
9819    \errmessage{Cannot read language file txi-#1.tex}%
9820  \else
9821    \globaldefs = 1  % everything in the txi-LL files needs to persist
9822    \input txi-#1.tex
9823  \fi
9824  \closein 1
9825}
9826}% end of special _ catcode
9827%
9828\newhelp\nolanghelp{The given language definition file cannot be found or
9829is empty.  Maybe you need to install it?  Putting it in the current
9830directory should work if nowhere else does.}
9831
9832% This macro is called from txi-??.tex files; the first argument is the
9833% \language name to set (without the "\lang@" prefix), the second and
9834% third args are \{left,right}hyphenmin.
9835%
9836% The language names to pass are determined when the format is built.
9837% See the etex.log file created at that time, e.g.,
9838% /usr/local/texlive/2008/texmf-var/web2c/pdftex/etex.log.
9839%
9840% With TeX Live 2008, etex now includes hyphenation patterns for all
9841% available languages.  This means we can support hyphenation in
9842% Texinfo, at least to some extent.  (This still doesn't solve the
9843% accented characters problem.)
9844%
9845\catcode`@=11
9846\def\txisetlanguage#1#2#3{%
9847  % do not set the language if the name is undefined in the current TeX.
9848  \expandafter\ifx\csname lang@#1\endcsname \relax
9849    \message{no patterns for #1}%
9850  \else
9851    \global\language = \csname lang@#1\endcsname
9852  \fi
9853  % but there is no harm in adjusting the hyphenmin values regardless.
9854  \global\lefthyphenmin = #2\relax
9855  \global\righthyphenmin = #3\relax
9856}
9857
9858% XeTeX and LuaTeX can handle Unicode natively.
9859% Their default I/O uses UTF-8 sequences instead of a byte-wise operation.
9860% Other TeX engines' I/O (pdfTeX, etc.) is byte-wise.
9861%
9862\newif\iftxinativeunicodecapable
9863\newif\iftxiusebytewiseio
9864
9865\ifx\XeTeXrevision\thisisundefined
9866  \ifx\luatexversion\thisisundefined
9867    \txinativeunicodecapablefalse
9868    \txiusebytewiseiotrue
9869  \else
9870    \txinativeunicodecapabletrue
9871    \txiusebytewiseiofalse
9872  \fi
9873\else
9874  \txinativeunicodecapabletrue
9875  \txiusebytewiseiofalse
9876\fi
9877
9878% Set I/O by bytes instead of UTF-8 sequence for XeTeX and LuaTex
9879% for non-UTF-8 (byte-wise) encodings.
9880%
9881\def\setbytewiseio{%
9882  \ifx\XeTeXrevision\thisisundefined
9883  \else
9884    \XeTeXdefaultencoding "bytes"  % For subsequent files to be read
9885    \XeTeXinputencoding "bytes"  % For document root file
9886    % Unfortunately, there seems to be no corresponding XeTeX command for
9887    % output encoding.  This is a problem for auxiliary index and TOC files.
9888    % The only solution would be perhaps to write out @U{...} sequences in
9889    % place of non-ASCII characters.
9890  \fi
9891
9892  \ifx\luatexversion\thisisundefined
9893  \else
9894    \directlua{
9895    local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub
9896    local function convert_char (char)
9897      return utf8_char(byte(char))
9898    end
9899
9900    local function convert_line (line)
9901      return gsub(line, ".", convert_char)
9902    end
9903
9904    callback.register("process_input_buffer", convert_line)
9905
9906    local function convert_line_out (line)
9907      local line_out = ""
9908      for c in string.utfvalues(line) do
9909         line_out = line_out .. string.char(c)
9910      end
9911      return line_out
9912    end
9913
9914    callback.register("process_output_buffer", convert_line_out)
9915    }
9916  \fi
9917
9918  \txiusebytewiseiotrue
9919}
9920
9921
9922% Helpers for encodings.
9923% Set the catcode of characters 128 through 255 to the specified number.
9924%
9925\def\setnonasciicharscatcode#1{%
9926   \count255=128
9927   \loop\ifnum\count255<256
9928      \global\catcode\count255=#1\relax
9929      \advance\count255 by 1
9930   \repeat
9931}
9932
9933\def\setnonasciicharscatcodenonglobal#1{%
9934   \count255=128
9935   \loop\ifnum\count255<256
9936      \catcode\count255=#1\relax
9937      \advance\count255 by 1
9938   \repeat
9939}
9940
9941% @documentencoding sets the definition of non-ASCII characters
9942% according to the specified encoding.
9943%
9944\def\documentencoding{\parseargusing\filenamecatcodes\documentencodingzzz}
9945\def\documentencodingzzz#1{%
9946  %
9947  % Encoding being declared for the document.
9948  \def\declaredencoding{\csname #1.enc\endcsname}%
9949  %
9950  % Supported encodings: names converted to tokens in order to be able
9951  % to compare them with \ifx.
9952  \def\ascii{\csname US-ASCII.enc\endcsname}%
9953  \def\latnine{\csname ISO-8859-15.enc\endcsname}%
9954  \def\latone{\csname ISO-8859-1.enc\endcsname}%
9955  \def\lattwo{\csname ISO-8859-2.enc\endcsname}%
9956  \def\utfeight{\csname UTF-8.enc\endcsname}%
9957  %
9958  \ifx \declaredencoding \ascii
9959     \asciichardefs
9960  %
9961  \else \ifx \declaredencoding \lattwo
9962     \iftxinativeunicodecapable
9963       \setbytewiseio
9964     \fi
9965     \setnonasciicharscatcode\active
9966     \lattwochardefs
9967  %
9968  \else \ifx \declaredencoding \latone
9969     \iftxinativeunicodecapable
9970       \setbytewiseio
9971     \fi
9972     \setnonasciicharscatcode\active
9973     \latonechardefs
9974  %
9975  \else \ifx \declaredencoding \latnine
9976     \iftxinativeunicodecapable
9977       \setbytewiseio
9978     \fi
9979     \setnonasciicharscatcode\active
9980     \latninechardefs
9981  %
9982  \else \ifx \declaredencoding \utfeight
9983     \iftxinativeunicodecapable
9984       % For native Unicode handling (XeTeX and LuaTeX)
9985       \nativeunicodechardefs
9986     \else
9987       % For treating UTF-8 as byte sequences (TeX, eTeX and pdfTeX)
9988       \setnonasciicharscatcode\active
9989       % since we already invoked \utfeightchardefs at the top level
9990       % (below), do not re-invoke it, otherwise our check for duplicated
9991       % definitions gets triggered.  Making non-ascii chars active is
9992       % sufficient.
9993     \fi
9994  %
9995  \else
9996    \message{Ignoring unknown document encoding: #1.}%
9997  %
9998  \fi % utfeight
9999  \fi % latnine
10000  \fi % latone
10001  \fi % lattwo
10002  \fi % ascii
10003  %
10004  \ifx\XeTeXrevision\thisisundefined
10005  \else
10006    \ifx \declaredencoding \utfeight
10007    \else
10008      \ifx \declaredencoding \ascii
10009      \else
10010        \message{Warning: XeTeX with non-UTF-8 encodings cannot handle %
10011        non-ASCII characters in auxiliary files.}%
10012      \fi
10013    \fi
10014  \fi
10015}
10016
10017% emacs-page
10018% A message to be logged when using a character that isn't available
10019% the default font encoding (OT1).
10020%
10021\def\missingcharmsg#1{\message{Character missing, sorry: #1.}}
10022
10023% Take account of \c (plain) vs. \, (Texinfo) difference.
10024\def\cedilla#1{\ifx\c\ptexc\c{#1}\else\,{#1}\fi}
10025
10026% First, make active non-ASCII characters in order for them to be
10027% correctly categorized when TeX reads the replacement text of
10028% macros containing the character definitions.
10029\setnonasciicharscatcode\active
10030%
10031
10032\def\gdefchar#1#2{%
10033\gdef#1{%
10034   \ifpassthroughchars
10035     \string#1%
10036   \else
10037     #2%
10038   \fi
10039}}
10040
10041% Latin1 (ISO-8859-1) character definitions.
10042\def\latonechardefs{%
10043  \gdefchar^^a0{\tie}
10044  \gdefchar^^a1{\exclamdown}
10045  \gdefchar^^a2{{\tcfont \char162}} % cent
10046  \gdefchar^^a3{\pounds{}}
10047  \gdefchar^^a4{{\tcfont \char164}} % currency
10048  \gdefchar^^a5{{\tcfont \char165}} % yen
10049  \gdefchar^^a6{{\tcfont \char166}} % broken bar
10050  \gdefchar^^a7{\S}
10051  \gdefchar^^a8{\"{}}
10052  \gdefchar^^a9{\copyright{}}
10053  \gdefchar^^aa{\ordf}
10054  \gdefchar^^ab{\guillemetleft{}}
10055  \gdefchar^^ac{\ensuremath\lnot}
10056  \gdefchar^^ad{\-}
10057  \gdefchar^^ae{\registeredsymbol{}}
10058  \gdefchar^^af{\={}}
10059  %
10060  \gdefchar^^b0{\textdegree}
10061  \gdefchar^^b1{$\pm$}
10062  \gdefchar^^b2{$^2$}
10063  \gdefchar^^b3{$^3$}
10064  \gdefchar^^b4{\'{}}
10065  \gdefchar^^b5{$\mu$}
10066  \gdefchar^^b6{\P}
10067  \gdefchar^^b7{\ensuremath\cdot}
10068  \gdefchar^^b8{\cedilla\ }
10069  \gdefchar^^b9{$^1$}
10070  \gdefchar^^ba{\ordm}
10071  \gdefchar^^bb{\guillemetright{}}
10072  \gdefchar^^bc{$1\over4$}
10073  \gdefchar^^bd{$1\over2$}
10074  \gdefchar^^be{$3\over4$}
10075  \gdefchar^^bf{\questiondown}
10076  %
10077  \gdefchar^^c0{\`A}
10078  \gdefchar^^c1{\'A}
10079  \gdefchar^^c2{\^A}
10080  \gdefchar^^c3{\~A}
10081  \gdefchar^^c4{\"A}
10082  \gdefchar^^c5{\ringaccent A}
10083  \gdefchar^^c6{\AE}
10084  \gdefchar^^c7{\cedilla C}
10085  \gdefchar^^c8{\`E}
10086  \gdefchar^^c9{\'E}
10087  \gdefchar^^ca{\^E}
10088  \gdefchar^^cb{\"E}
10089  \gdefchar^^cc{\`I}
10090  \gdefchar^^cd{\'I}
10091  \gdefchar^^ce{\^I}
10092  \gdefchar^^cf{\"I}
10093  %
10094  \gdefchar^^d0{\DH}
10095  \gdefchar^^d1{\~N}
10096  \gdefchar^^d2{\`O}
10097  \gdefchar^^d3{\'O}
10098  \gdefchar^^d4{\^O}
10099  \gdefchar^^d5{\~O}
10100  \gdefchar^^d6{\"O}
10101  \gdefchar^^d7{$\times$}
10102  \gdefchar^^d8{\O}
10103  \gdefchar^^d9{\`U}
10104  \gdefchar^^da{\'U}
10105  \gdefchar^^db{\^U}
10106  \gdefchar^^dc{\"U}
10107  \gdefchar^^dd{\'Y}
10108  \gdefchar^^de{\TH}
10109  \gdefchar^^df{\ss}
10110  %
10111  \gdefchar^^e0{\`a}
10112  \gdefchar^^e1{\'a}
10113  \gdefchar^^e2{\^a}
10114  \gdefchar^^e3{\~a}
10115  \gdefchar^^e4{\"a}
10116  \gdefchar^^e5{\ringaccent a}
10117  \gdefchar^^e6{\ae}
10118  \gdefchar^^e7{\cedilla c}
10119  \gdefchar^^e8{\`e}
10120  \gdefchar^^e9{\'e}
10121  \gdefchar^^ea{\^e}
10122  \gdefchar^^eb{\"e}
10123  \gdefchar^^ec{\`{\dotless i}}
10124  \gdefchar^^ed{\'{\dotless i}}
10125  \gdefchar^^ee{\^{\dotless i}}
10126  \gdefchar^^ef{\"{\dotless i}}
10127  %
10128  \gdefchar^^f0{\dh}
10129  \gdefchar^^f1{\~n}
10130  \gdefchar^^f2{\`o}
10131  \gdefchar^^f3{\'o}
10132  \gdefchar^^f4{\^o}
10133  \gdefchar^^f5{\~o}
10134  \gdefchar^^f6{\"o}
10135  \gdefchar^^f7{$\div$}
10136  \gdefchar^^f8{\o}
10137  \gdefchar^^f9{\`u}
10138  \gdefchar^^fa{\'u}
10139  \gdefchar^^fb{\^u}
10140  \gdefchar^^fc{\"u}
10141  \gdefchar^^fd{\'y}
10142  \gdefchar^^fe{\th}
10143  \gdefchar^^ff{\"y}
10144}
10145
10146% Latin9 (ISO-8859-15) encoding character definitions.
10147\def\latninechardefs{%
10148  % Encoding is almost identical to Latin1.
10149  \latonechardefs
10150  %
10151  \gdefchar^^a4{\euro{}}
10152  \gdefchar^^a6{\v S}
10153  \gdefchar^^a8{\v s}
10154  \gdefchar^^b4{\v Z}
10155  \gdefchar^^b8{\v z}
10156  \gdefchar^^bc{\OE}
10157  \gdefchar^^bd{\oe}
10158  \gdefchar^^be{\"Y}
10159}
10160
10161% Latin2 (ISO-8859-2) character definitions.
10162\def\lattwochardefs{%
10163  \gdefchar^^a0{\tie}
10164  \gdefchar^^a1{\ogonek{A}}
10165  \gdefchar^^a2{\u{}}
10166  \gdefchar^^a3{\L}
10167  \gdefchar^^a4{\missingcharmsg{CURRENCY SIGN}}
10168  \gdefchar^^a5{\v L}
10169  \gdefchar^^a6{\'S}
10170  \gdefchar^^a7{\S}
10171  \gdefchar^^a8{\"{}}
10172  \gdefchar^^a9{\v S}
10173  \gdefchar^^aa{\cedilla S}
10174  \gdefchar^^ab{\v T}
10175  \gdefchar^^ac{\'Z}
10176  \gdefchar^^ad{\-}
10177  \gdefchar^^ae{\v Z}
10178  \gdefchar^^af{\dotaccent Z}
10179  %
10180  \gdefchar^^b0{\textdegree{}}
10181  \gdefchar^^b1{\ogonek{a}}
10182  \gdefchar^^b2{\ogonek{ }}
10183  \gdefchar^^b3{\l}
10184  \gdefchar^^b4{\'{}}
10185  \gdefchar^^b5{\v l}
10186  \gdefchar^^b6{\'s}
10187  \gdefchar^^b7{\v{}}
10188  \gdefchar^^b8{\cedilla\ }
10189  \gdefchar^^b9{\v s}
10190  \gdefchar^^ba{\cedilla s}
10191  \gdefchar^^bb{\v t}
10192  \gdefchar^^bc{\'z}
10193  \gdefchar^^bd{\H{}}
10194  \gdefchar^^be{\v z}
10195  \gdefchar^^bf{\dotaccent z}
10196  %
10197  \gdefchar^^c0{\'R}
10198  \gdefchar^^c1{\'A}
10199  \gdefchar^^c2{\^A}
10200  \gdefchar^^c3{\u A}
10201  \gdefchar^^c4{\"A}
10202  \gdefchar^^c5{\'L}
10203  \gdefchar^^c6{\'C}
10204  \gdefchar^^c7{\cedilla C}
10205  \gdefchar^^c8{\v C}
10206  \gdefchar^^c9{\'E}
10207  \gdefchar^^ca{\ogonek{E}}
10208  \gdefchar^^cb{\"E}
10209  \gdefchar^^cc{\v E}
10210  \gdefchar^^cd{\'I}
10211  \gdefchar^^ce{\^I}
10212  \gdefchar^^cf{\v D}
10213  %
10214  \gdefchar^^d0{\DH}
10215  \gdefchar^^d1{\'N}
10216  \gdefchar^^d2{\v N}
10217  \gdefchar^^d3{\'O}
10218  \gdefchar^^d4{\^O}
10219  \gdefchar^^d5{\H O}
10220  \gdefchar^^d6{\"O}
10221  \gdefchar^^d7{$\times$}
10222  \gdefchar^^d8{\v R}
10223  \gdefchar^^d9{\ringaccent U}
10224  \gdefchar^^da{\'U}
10225  \gdefchar^^db{\H U}
10226  \gdefchar^^dc{\"U}
10227  \gdefchar^^dd{\'Y}
10228  \gdefchar^^de{\cedilla T}
10229  \gdefchar^^df{\ss}
10230  %
10231  \gdefchar^^e0{\'r}
10232  \gdefchar^^e1{\'a}
10233  \gdefchar^^e2{\^a}
10234  \gdefchar^^e3{\u a}
10235  \gdefchar^^e4{\"a}
10236  \gdefchar^^e5{\'l}
10237  \gdefchar^^e6{\'c}
10238  \gdefchar^^e7{\cedilla c}
10239  \gdefchar^^e8{\v c}
10240  \gdefchar^^e9{\'e}
10241  \gdefchar^^ea{\ogonek{e}}
10242  \gdefchar^^eb{\"e}
10243  \gdefchar^^ec{\v e}
10244  \gdefchar^^ed{\'{\dotless{i}}}
10245  \gdefchar^^ee{\^{\dotless{i}}}
10246  \gdefchar^^ef{\v d}
10247  %
10248  \gdefchar^^f0{\dh}
10249  \gdefchar^^f1{\'n}
10250  \gdefchar^^f2{\v n}
10251  \gdefchar^^f3{\'o}
10252  \gdefchar^^f4{\^o}
10253  \gdefchar^^f5{\H o}
10254  \gdefchar^^f6{\"o}
10255  \gdefchar^^f7{$\div$}
10256  \gdefchar^^f8{\v r}
10257  \gdefchar^^f9{\ringaccent u}
10258  \gdefchar^^fa{\'u}
10259  \gdefchar^^fb{\H u}
10260  \gdefchar^^fc{\"u}
10261  \gdefchar^^fd{\'y}
10262  \gdefchar^^fe{\cedilla t}
10263  \gdefchar^^ff{\dotaccent{}}
10264}
10265
10266% UTF-8 character definitions.
10267%
10268% This code to support UTF-8 is based on LaTeX's utf8.def, with some
10269% changes for Texinfo conventions.  It is included here under the GPL by
10270% permission from Frank Mittelbach and the LaTeX team.
10271%
10272\newcount\countUTFx
10273\newcount\countUTFy
10274\newcount\countUTFz
10275
10276\gdef\UTFviiiTwoOctets#1#2{\expandafter
10277   \UTFviiiDefined\csname u8:#1\string #2\endcsname}
10278%
10279\gdef\UTFviiiThreeOctets#1#2#3{\expandafter
10280   \UTFviiiDefined\csname u8:#1\string #2\string #3\endcsname}
10281%
10282\gdef\UTFviiiFourOctets#1#2#3#4{\expandafter
10283   \UTFviiiDefined\csname u8:#1\string #2\string #3\string #4\endcsname}
10284
10285\gdef\UTFviiiDefined#1{%
10286  \ifx #1\relax
10287    \message{\linenumber Unicode char \string #1 not defined for Texinfo}%
10288  \else
10289    \expandafter #1%
10290  \fi
10291}
10292
10293% Give non-ASCII bytes the active definitions for processing UTF-8 sequences
10294\begingroup
10295  \catcode`\~13
10296  \catcode`\$12
10297  \catcode`\"12
10298
10299  % Loop from \countUTFx to \countUTFy, performing \UTFviiiTmp
10300  % substituting ~ and $ with a character token of that value.
10301  \def\UTFviiiLoop{%
10302    \global\catcode\countUTFx\active
10303    \uccode`\~\countUTFx
10304    \uccode`\$\countUTFx
10305    \uppercase\expandafter{\UTFviiiTmp}%
10306    \advance\countUTFx by 1
10307    \ifnum\countUTFx < \countUTFy
10308      \expandafter\UTFviiiLoop
10309    \fi}
10310
10311  % For bytes other than the first in a UTF-8 sequence.  Not expected to
10312  % be expanded except when writing to auxiliary files.
10313  \countUTFx = "80
10314  \countUTFy = "C2
10315  \def\UTFviiiTmp{%
10316    \gdef~{%
10317        \ifpassthroughchars $\fi}}%
10318  \UTFviiiLoop
10319
10320  \countUTFx = "C2
10321  \countUTFy = "E0
10322  \def\UTFviiiTmp{%
10323    \gdef~{%
10324        \ifpassthroughchars $%
10325        \else\expandafter\UTFviiiTwoOctets\expandafter$\fi}}%
10326  \UTFviiiLoop
10327
10328  \countUTFx = "E0
10329  \countUTFy = "F0
10330  \def\UTFviiiTmp{%
10331    \gdef~{%
10332        \ifpassthroughchars $%
10333        \else\expandafter\UTFviiiThreeOctets\expandafter$\fi}}%
10334  \UTFviiiLoop
10335
10336  \countUTFx = "F0
10337  \countUTFy = "F4
10338  \def\UTFviiiTmp{%
10339    \gdef~{%
10340        \ifpassthroughchars $%
10341        \else\expandafter\UTFviiiFourOctets\expandafter$\fi
10342        }}%
10343  \UTFviiiLoop
10344\endgroup
10345
10346\def\globallet{\global\let} % save some \expandafter's below
10347
10348% @U{xxxx} to produce U+xxxx, if we support it.
10349\def\U#1{%
10350  \expandafter\ifx\csname uni:#1\endcsname \relax
10351    \iftxinativeunicodecapable
10352      % All Unicode characters can be used if native Unicode handling is
10353      % active.  However, if the font does not have the glyph,
10354      % letters are missing.
10355      \begingroup
10356        \uccode`\.="#1\relax
10357        \uppercase{.}
10358      \endgroup
10359    \else
10360      \errhelp = \EMsimple
10361      \errmessage{Unicode character U+#1 not supported, sorry}%
10362    \fi
10363  \else
10364    \csname uni:#1\endcsname
10365  \fi
10366}
10367
10368% These macros are used here to construct the name of a control
10369% sequence to be defined.
10370\def\UTFviiiTwoOctetsName#1#2{%
10371  \csname u8:#1\string #2\endcsname}%
10372\def\UTFviiiThreeOctetsName#1#2#3{%
10373  \csname u8:#1\string #2\string #3\endcsname}%
10374\def\UTFviiiFourOctetsName#1#2#3#4{%
10375  \csname u8:#1\string #2\string #3\string #4\endcsname}%
10376
10377% For UTF-8 byte sequences (TeX, e-TeX and pdfTeX),
10378% provide a definition macro to replace a Unicode character;
10379% this gets used by the @U command
10380%
10381\begingroup
10382  \catcode`\"=12
10383  \catcode`\<=12
10384  \catcode`\.=12
10385  \catcode`\,=12
10386  \catcode`\;=12
10387  \catcode`\!=12
10388  \catcode`\~=13
10389  \gdef\DeclareUnicodeCharacterUTFviii#1#2{%
10390    \countUTFz = "#1\relax
10391    \begingroup
10392      \parseXMLCharref
10393
10394      % Give \u8:... its definition.  The sequence of seven \expandafter's
10395      % expands after the \gdef three times, e.g.
10396      %
10397      % 1.  \UTFviiTwoOctetsName B1 B2
10398      % 2.  \csname u8:B1 \string B2 \endcsname
10399      % 3.  \u8: B1 B2  (a single control sequence token)
10400      %
10401      \expandafter\expandafter
10402      \expandafter\expandafter
10403      \expandafter\expandafter
10404      \expandafter\gdef       \UTFviiiTmp{#2}%
10405      %
10406      \expandafter\ifx\csname uni:#1\endcsname \relax \else
10407       \message{Internal error, already defined: #1}%
10408      \fi
10409      %
10410      % define an additional control sequence for this code point.
10411      \expandafter\globallet\csname uni:#1\endcsname \UTFviiiTmp
10412    \endgroup}
10413  %
10414  % Given the value in \countUTFz as a Unicode code point, set \UTFviiiTmp
10415  % to the corresponding UTF-8 sequence.
10416  \gdef\parseXMLCharref{%
10417    \ifnum\countUTFz < "A0\relax
10418      \errhelp = \EMsimple
10419      \errmessage{Cannot define Unicode char value < 00A0}%
10420    \else\ifnum\countUTFz < "800\relax
10421      \parseUTFviiiA,%
10422      \parseUTFviiiB C\UTFviiiTwoOctetsName.,%
10423    \else\ifnum\countUTFz < "10000\relax
10424      \parseUTFviiiA;%
10425      \parseUTFviiiA,%
10426      \parseUTFviiiB E\UTFviiiThreeOctetsName.{,;}%
10427    \else
10428      \parseUTFviiiA;%
10429      \parseUTFviiiA,%
10430      \parseUTFviiiA!%
10431      \parseUTFviiiB F\UTFviiiFourOctetsName.{!,;}%
10432    \fi\fi\fi
10433  }
10434
10435  % Extract a byte from the end of the UTF-8 representation of \countUTFx.
10436  % It must be a non-initial byte in the sequence.
10437  % Change \uccode of #1 for it to be used in \parseUTFviiiB as one
10438  % of the bytes.
10439  \gdef\parseUTFviiiA#1{%
10440    \countUTFx = \countUTFz
10441    \divide\countUTFz by 64
10442    \countUTFy = \countUTFz  % Save to be the future value of \countUTFz.
10443    \multiply\countUTFz by 64
10444
10445    % \countUTFz is now \countUTFx with the last 5 bits cleared.  Subtract
10446    % in order to get the last five bits.
10447    \advance\countUTFx by -\countUTFz
10448
10449    % Convert this to the byte in the UTF-8 sequence.
10450    \advance\countUTFx by 128
10451    \uccode `#1\countUTFx
10452    \countUTFz = \countUTFy}
10453
10454  % Used to put a UTF-8 byte sequence into \UTFviiiTmp
10455  % #1 is the increment for \countUTFz to yield a the first byte of the UTF-8
10456  %    sequence.
10457  % #2 is one of the \UTFviii*OctetsName macros.
10458  % #3 is always a full stop (.)
10459  % #4 is a template for the other bytes in the sequence.  The values for these
10460  %    bytes is substituted in here with \uppercase using the \uccode's.
10461  \gdef\parseUTFviiiB#1#2#3#4{%
10462    \advance\countUTFz by "#10\relax
10463    \uccode `#3\countUTFz
10464    \uppercase{\gdef\UTFviiiTmp{#2#3#4}}}
10465\endgroup
10466
10467% For native Unicode handling (XeTeX and LuaTeX),
10468% provide a definition macro that sets a catcode to `other' non-globally
10469%
10470\def\DeclareUnicodeCharacterNativeOther#1#2{%
10471  \catcode"#1=\other
10472}
10473
10474% https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_M
10475% U+0000..U+007F = https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)
10476% U+0080..U+00FF = https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)
10477% U+0100..U+017F = https://en.wikipedia.org/wiki/Latin_Extended-A
10478% U+0180..U+024F = https://en.wikipedia.org/wiki/Latin_Extended-B
10479%
10480% Many of our renditions are less than wonderful, and all the missing
10481% characters are available somewhere.  Loading the necessary fonts
10482% awaits user request.  We can't truly support Unicode without
10483% reimplementing everything that's been done in LaTeX for many years,
10484% plus probably using luatex or xetex, and who knows what else.
10485% We won't be doing that here in this simple file.  But we can try to at
10486% least make most of the characters not bomb out.
10487%
10488\def\unicodechardefs{%
10489  \DeclareUnicodeCharacter{00A0}{\tie}%
10490  \DeclareUnicodeCharacter{00A1}{\exclamdown}%
10491  \DeclareUnicodeCharacter{00A2}{{\tcfont \char162}}% 0242=cent
10492  \DeclareUnicodeCharacter{00A3}{\pounds{}}%
10493  \DeclareUnicodeCharacter{00A4}{{\tcfont \char164}}% 0244=currency
10494  \DeclareUnicodeCharacter{00A5}{{\tcfont \char165}}% 0245=yen
10495  \DeclareUnicodeCharacter{00A6}{{\tcfont \char166}}% 0246=brokenbar
10496  \DeclareUnicodeCharacter{00A7}{\S}%
10497  \DeclareUnicodeCharacter{00A8}{\"{ }}%
10498  \DeclareUnicodeCharacter{00A9}{\copyright{}}%
10499  \DeclareUnicodeCharacter{00AA}{\ordf}%
10500  \DeclareUnicodeCharacter{00AB}{\guillemetleft{}}%
10501  \DeclareUnicodeCharacter{00AC}{\ensuremath\lnot}%
10502  \DeclareUnicodeCharacter{00AD}{\-}%
10503  \DeclareUnicodeCharacter{00AE}{\registeredsymbol{}}%
10504  \DeclareUnicodeCharacter{00AF}{\={ }}%
10505  %
10506  \DeclareUnicodeCharacter{00B0}{\ringaccent{ }}%
10507  \DeclareUnicodeCharacter{00B1}{\ensuremath\pm}%
10508  \DeclareUnicodeCharacter{00B2}{$^2$}%
10509  \DeclareUnicodeCharacter{00B3}{$^3$}%
10510  \DeclareUnicodeCharacter{00B4}{\'{ }}%
10511  \DeclareUnicodeCharacter{00B5}{$\mu$}%
10512  \DeclareUnicodeCharacter{00B6}{\P}%
10513  \DeclareUnicodeCharacter{00B7}{\ensuremath\cdot}%
10514  \DeclareUnicodeCharacter{00B8}{\cedilla{ }}%
10515  \DeclareUnicodeCharacter{00B9}{$^1$}%
10516  \DeclareUnicodeCharacter{00BA}{\ordm}%
10517  \DeclareUnicodeCharacter{00BB}{\guillemetright{}}%
10518  \DeclareUnicodeCharacter{00BC}{$1\over4$}%
10519  \DeclareUnicodeCharacter{00BD}{$1\over2$}%
10520  \DeclareUnicodeCharacter{00BE}{$3\over4$}%
10521  \DeclareUnicodeCharacter{00BF}{\questiondown}%
10522  %
10523  \DeclareUnicodeCharacter{00C0}{\`A}%
10524  \DeclareUnicodeCharacter{00C1}{\'A}%
10525  \DeclareUnicodeCharacter{00C2}{\^A}%
10526  \DeclareUnicodeCharacter{00C3}{\~A}%
10527  \DeclareUnicodeCharacter{00C4}{\"A}%
10528  \DeclareUnicodeCharacter{00C5}{\AA}%
10529  \DeclareUnicodeCharacter{00C6}{\AE}%
10530  \DeclareUnicodeCharacter{00C7}{\cedilla{C}}%
10531  \DeclareUnicodeCharacter{00C8}{\`E}%
10532  \DeclareUnicodeCharacter{00C9}{\'E}%
10533  \DeclareUnicodeCharacter{00CA}{\^E}%
10534  \DeclareUnicodeCharacter{00CB}{\"E}%
10535  \DeclareUnicodeCharacter{00CC}{\`I}%
10536  \DeclareUnicodeCharacter{00CD}{\'I}%
10537  \DeclareUnicodeCharacter{00CE}{\^I}%
10538  \DeclareUnicodeCharacter{00CF}{\"I}%
10539  %
10540  \DeclareUnicodeCharacter{00D0}{\DH}%
10541  \DeclareUnicodeCharacter{00D1}{\~N}%
10542  \DeclareUnicodeCharacter{00D2}{\`O}%
10543  \DeclareUnicodeCharacter{00D3}{\'O}%
10544  \DeclareUnicodeCharacter{00D4}{\^O}%
10545  \DeclareUnicodeCharacter{00D5}{\~O}%
10546  \DeclareUnicodeCharacter{00D6}{\"O}%
10547  \DeclareUnicodeCharacter{00D7}{\ensuremath\times}%
10548  \DeclareUnicodeCharacter{00D8}{\O}%
10549  \DeclareUnicodeCharacter{00D9}{\`U}%
10550  \DeclareUnicodeCharacter{00DA}{\'U}%
10551  \DeclareUnicodeCharacter{00DB}{\^U}%
10552  \DeclareUnicodeCharacter{00DC}{\"U}%
10553  \DeclareUnicodeCharacter{00DD}{\'Y}%
10554  \DeclareUnicodeCharacter{00DE}{\TH}%
10555  \DeclareUnicodeCharacter{00DF}{\ss}%
10556  %
10557  \DeclareUnicodeCharacter{00E0}{\`a}%
10558  \DeclareUnicodeCharacter{00E1}{\'a}%
10559  \DeclareUnicodeCharacter{00E2}{\^a}%
10560  \DeclareUnicodeCharacter{00E3}{\~a}%
10561  \DeclareUnicodeCharacter{00E4}{\"a}%
10562  \DeclareUnicodeCharacter{00E5}{\aa}%
10563  \DeclareUnicodeCharacter{00E6}{\ae}%
10564  \DeclareUnicodeCharacter{00E7}{\cedilla{c}}%
10565  \DeclareUnicodeCharacter{00E8}{\`e}%
10566  \DeclareUnicodeCharacter{00E9}{\'e}%
10567  \DeclareUnicodeCharacter{00EA}{\^e}%
10568  \DeclareUnicodeCharacter{00EB}{\"e}%
10569  \DeclareUnicodeCharacter{00EC}{\`{\dotless{i}}}%
10570  \DeclareUnicodeCharacter{00ED}{\'{\dotless{i}}}%
10571  \DeclareUnicodeCharacter{00EE}{\^{\dotless{i}}}%
10572  \DeclareUnicodeCharacter{00EF}{\"{\dotless{i}}}%
10573  %
10574  \DeclareUnicodeCharacter{00F0}{\dh}%
10575  \DeclareUnicodeCharacter{00F1}{\~n}%
10576  \DeclareUnicodeCharacter{00F2}{\`o}%
10577  \DeclareUnicodeCharacter{00F3}{\'o}%
10578  \DeclareUnicodeCharacter{00F4}{\^o}%
10579  \DeclareUnicodeCharacter{00F5}{\~o}%
10580  \DeclareUnicodeCharacter{00F6}{\"o}%
10581  \DeclareUnicodeCharacter{00F7}{\ensuremath\div}%
10582  \DeclareUnicodeCharacter{00F8}{\o}%
10583  \DeclareUnicodeCharacter{00F9}{\`u}%
10584  \DeclareUnicodeCharacter{00FA}{\'u}%
10585  \DeclareUnicodeCharacter{00FB}{\^u}%
10586  \DeclareUnicodeCharacter{00FC}{\"u}%
10587  \DeclareUnicodeCharacter{00FD}{\'y}%
10588  \DeclareUnicodeCharacter{00FE}{\th}%
10589  \DeclareUnicodeCharacter{00FF}{\"y}%
10590  %
10591  \DeclareUnicodeCharacter{0100}{\=A}%
10592  \DeclareUnicodeCharacter{0101}{\=a}%
10593  \DeclareUnicodeCharacter{0102}{\u{A}}%
10594  \DeclareUnicodeCharacter{0103}{\u{a}}%
10595  \DeclareUnicodeCharacter{0104}{\ogonek{A}}%
10596  \DeclareUnicodeCharacter{0105}{\ogonek{a}}%
10597  \DeclareUnicodeCharacter{0106}{\'C}%
10598  \DeclareUnicodeCharacter{0107}{\'c}%
10599  \DeclareUnicodeCharacter{0108}{\^C}%
10600  \DeclareUnicodeCharacter{0109}{\^c}%
10601  \DeclareUnicodeCharacter{010A}{\dotaccent{C}}%
10602  \DeclareUnicodeCharacter{010B}{\dotaccent{c}}%
10603  \DeclareUnicodeCharacter{010C}{\v{C}}%
10604  \DeclareUnicodeCharacter{010D}{\v{c}}%
10605  \DeclareUnicodeCharacter{010E}{\v{D}}%
10606  \DeclareUnicodeCharacter{010F}{d'}%
10607  %
10608  \DeclareUnicodeCharacter{0110}{\DH}%
10609  \DeclareUnicodeCharacter{0111}{\dh}%
10610  \DeclareUnicodeCharacter{0112}{\=E}%
10611  \DeclareUnicodeCharacter{0113}{\=e}%
10612  \DeclareUnicodeCharacter{0114}{\u{E}}%
10613  \DeclareUnicodeCharacter{0115}{\u{e}}%
10614  \DeclareUnicodeCharacter{0116}{\dotaccent{E}}%
10615  \DeclareUnicodeCharacter{0117}{\dotaccent{e}}%
10616  \DeclareUnicodeCharacter{0118}{\ogonek{E}}%
10617  \DeclareUnicodeCharacter{0119}{\ogonek{e}}%
10618  \DeclareUnicodeCharacter{011A}{\v{E}}%
10619  \DeclareUnicodeCharacter{011B}{\v{e}}%
10620  \DeclareUnicodeCharacter{011C}{\^G}%
10621  \DeclareUnicodeCharacter{011D}{\^g}%
10622  \DeclareUnicodeCharacter{011E}{\u{G}}%
10623  \DeclareUnicodeCharacter{011F}{\u{g}}%
10624  %
10625  \DeclareUnicodeCharacter{0120}{\dotaccent{G}}%
10626  \DeclareUnicodeCharacter{0121}{\dotaccent{g}}%
10627  \DeclareUnicodeCharacter{0122}{\cedilla{G}}%
10628  \DeclareUnicodeCharacter{0123}{\cedilla{g}}%
10629  \DeclareUnicodeCharacter{0124}{\^H}%
10630  \DeclareUnicodeCharacter{0125}{\^h}%
10631  \DeclareUnicodeCharacter{0126}{\missingcharmsg{H WITH STROKE}}%
10632  \DeclareUnicodeCharacter{0127}{\missingcharmsg{h WITH STROKE}}%
10633  \DeclareUnicodeCharacter{0128}{\~I}%
10634  \DeclareUnicodeCharacter{0129}{\~{\dotless{i}}}%
10635  \DeclareUnicodeCharacter{012A}{\=I}%
10636  \DeclareUnicodeCharacter{012B}{\={\dotless{i}}}%
10637  \DeclareUnicodeCharacter{012C}{\u{I}}%
10638  \DeclareUnicodeCharacter{012D}{\u{\dotless{i}}}%
10639  \DeclareUnicodeCharacter{012E}{\ogonek{I}}%
10640  \DeclareUnicodeCharacter{012F}{\ogonek{i}}%
10641  %
10642  \DeclareUnicodeCharacter{0130}{\dotaccent{I}}%
10643  \DeclareUnicodeCharacter{0131}{\dotless{i}}%
10644  \DeclareUnicodeCharacter{0132}{IJ}%
10645  \DeclareUnicodeCharacter{0133}{ij}%
10646  \DeclareUnicodeCharacter{0134}{\^J}%
10647  \DeclareUnicodeCharacter{0135}{\^{\dotless{j}}}%
10648  \DeclareUnicodeCharacter{0136}{\cedilla{K}}%
10649  \DeclareUnicodeCharacter{0137}{\cedilla{k}}%
10650  \DeclareUnicodeCharacter{0138}{\ensuremath\kappa}%
10651  \DeclareUnicodeCharacter{0139}{\'L}%
10652  \DeclareUnicodeCharacter{013A}{\'l}%
10653  \DeclareUnicodeCharacter{013B}{\cedilla{L}}%
10654  \DeclareUnicodeCharacter{013C}{\cedilla{l}}%
10655  \DeclareUnicodeCharacter{013D}{L'}% should kern
10656  \DeclareUnicodeCharacter{013E}{l'}% should kern
10657  \DeclareUnicodeCharacter{013F}{L\U{00B7}}%
10658  %
10659  \DeclareUnicodeCharacter{0140}{l\U{00B7}}%
10660  \DeclareUnicodeCharacter{0141}{\L}%
10661  \DeclareUnicodeCharacter{0142}{\l}%
10662  \DeclareUnicodeCharacter{0143}{\'N}%
10663  \DeclareUnicodeCharacter{0144}{\'n}%
10664  \DeclareUnicodeCharacter{0145}{\cedilla{N}}%
10665  \DeclareUnicodeCharacter{0146}{\cedilla{n}}%
10666  \DeclareUnicodeCharacter{0147}{\v{N}}%
10667  \DeclareUnicodeCharacter{0148}{\v{n}}%
10668  \DeclareUnicodeCharacter{0149}{'n}%
10669  \DeclareUnicodeCharacter{014A}{\missingcharmsg{ENG}}%
10670  \DeclareUnicodeCharacter{014B}{\missingcharmsg{eng}}%
10671  \DeclareUnicodeCharacter{014C}{\=O}%
10672  \DeclareUnicodeCharacter{014D}{\=o}%
10673  \DeclareUnicodeCharacter{014E}{\u{O}}%
10674  \DeclareUnicodeCharacter{014F}{\u{o}}%
10675  %
10676  \DeclareUnicodeCharacter{0150}{\H{O}}%
10677  \DeclareUnicodeCharacter{0151}{\H{o}}%
10678  \DeclareUnicodeCharacter{0152}{\OE}%
10679  \DeclareUnicodeCharacter{0153}{\oe}%
10680  \DeclareUnicodeCharacter{0154}{\'R}%
10681  \DeclareUnicodeCharacter{0155}{\'r}%
10682  \DeclareUnicodeCharacter{0156}{\cedilla{R}}%
10683  \DeclareUnicodeCharacter{0157}{\cedilla{r}}%
10684  \DeclareUnicodeCharacter{0158}{\v{R}}%
10685  \DeclareUnicodeCharacter{0159}{\v{r}}%
10686  \DeclareUnicodeCharacter{015A}{\'S}%
10687  \DeclareUnicodeCharacter{015B}{\'s}%
10688  \DeclareUnicodeCharacter{015C}{\^S}%
10689  \DeclareUnicodeCharacter{015D}{\^s}%
10690  \DeclareUnicodeCharacter{015E}{\cedilla{S}}%
10691  \DeclareUnicodeCharacter{015F}{\cedilla{s}}%
10692  %
10693  \DeclareUnicodeCharacter{0160}{\v{S}}%
10694  \DeclareUnicodeCharacter{0161}{\v{s}}%
10695  \DeclareUnicodeCharacter{0162}{\cedilla{T}}%
10696  \DeclareUnicodeCharacter{0163}{\cedilla{t}}%
10697  \DeclareUnicodeCharacter{0164}{\v{T}}%
10698  \DeclareUnicodeCharacter{0165}{\v{t}}%
10699  \DeclareUnicodeCharacter{0166}{\missingcharmsg{H WITH STROKE}}%
10700  \DeclareUnicodeCharacter{0167}{\missingcharmsg{h WITH STROKE}}%
10701  \DeclareUnicodeCharacter{0168}{\~U}%
10702  \DeclareUnicodeCharacter{0169}{\~u}%
10703  \DeclareUnicodeCharacter{016A}{\=U}%
10704  \DeclareUnicodeCharacter{016B}{\=u}%
10705  \DeclareUnicodeCharacter{016C}{\u{U}}%
10706  \DeclareUnicodeCharacter{016D}{\u{u}}%
10707  \DeclareUnicodeCharacter{016E}{\ringaccent{U}}%
10708  \DeclareUnicodeCharacter{016F}{\ringaccent{u}}%
10709  %
10710  \DeclareUnicodeCharacter{0170}{\H{U}}%
10711  \DeclareUnicodeCharacter{0171}{\H{u}}%
10712  \DeclareUnicodeCharacter{0172}{\ogonek{U}}%
10713  \DeclareUnicodeCharacter{0173}{\ogonek{u}}%
10714  \DeclareUnicodeCharacter{0174}{\^W}%
10715  \DeclareUnicodeCharacter{0175}{\^w}%
10716  \DeclareUnicodeCharacter{0176}{\^Y}%
10717  \DeclareUnicodeCharacter{0177}{\^y}%
10718  \DeclareUnicodeCharacter{0178}{\"Y}%
10719  \DeclareUnicodeCharacter{0179}{\'Z}%
10720  \DeclareUnicodeCharacter{017A}{\'z}%
10721  \DeclareUnicodeCharacter{017B}{\dotaccent{Z}}%
10722  \DeclareUnicodeCharacter{017C}{\dotaccent{z}}%
10723  \DeclareUnicodeCharacter{017D}{\v{Z}}%
10724  \DeclareUnicodeCharacter{017E}{\v{z}}%
10725  \DeclareUnicodeCharacter{017F}{\missingcharmsg{LONG S}}%
10726  %
10727  \DeclareUnicodeCharacter{01C4}{D\v{Z}}%
10728  \DeclareUnicodeCharacter{01C5}{D\v{z}}%
10729  \DeclareUnicodeCharacter{01C6}{d\v{z}}%
10730  \DeclareUnicodeCharacter{01C7}{LJ}%
10731  \DeclareUnicodeCharacter{01C8}{Lj}%
10732  \DeclareUnicodeCharacter{01C9}{lj}%
10733  \DeclareUnicodeCharacter{01CA}{NJ}%
10734  \DeclareUnicodeCharacter{01CB}{Nj}%
10735  \DeclareUnicodeCharacter{01CC}{nj}%
10736  \DeclareUnicodeCharacter{01CD}{\v{A}}%
10737  \DeclareUnicodeCharacter{01CE}{\v{a}}%
10738  \DeclareUnicodeCharacter{01CF}{\v{I}}%
10739  %
10740  \DeclareUnicodeCharacter{01D0}{\v{\dotless{i}}}%
10741  \DeclareUnicodeCharacter{01D1}{\v{O}}%
10742  \DeclareUnicodeCharacter{01D2}{\v{o}}%
10743  \DeclareUnicodeCharacter{01D3}{\v{U}}%
10744  \DeclareUnicodeCharacter{01D4}{\v{u}}%
10745  %
10746  \DeclareUnicodeCharacter{01E2}{\={\AE}}%
10747  \DeclareUnicodeCharacter{01E3}{\={\ae}}%
10748  \DeclareUnicodeCharacter{01E6}{\v{G}}%
10749  \DeclareUnicodeCharacter{01E7}{\v{g}}%
10750  \DeclareUnicodeCharacter{01E8}{\v{K}}%
10751  \DeclareUnicodeCharacter{01E9}{\v{k}}%
10752  %
10753  \DeclareUnicodeCharacter{01F0}{\v{\dotless{j}}}%
10754  \DeclareUnicodeCharacter{01F1}{DZ}%
10755  \DeclareUnicodeCharacter{01F2}{Dz}%
10756  \DeclareUnicodeCharacter{01F3}{dz}%
10757  \DeclareUnicodeCharacter{01F4}{\'G}%
10758  \DeclareUnicodeCharacter{01F5}{\'g}%
10759  \DeclareUnicodeCharacter{01F8}{\`N}%
10760  \DeclareUnicodeCharacter{01F9}{\`n}%
10761  \DeclareUnicodeCharacter{01FC}{\'{\AE}}%
10762  \DeclareUnicodeCharacter{01FD}{\'{\ae}}%
10763  \DeclareUnicodeCharacter{01FE}{\'{\O}}%
10764  \DeclareUnicodeCharacter{01FF}{\'{\o}}%
10765  %
10766  \DeclareUnicodeCharacter{021E}{\v{H}}%
10767  \DeclareUnicodeCharacter{021F}{\v{h}}%
10768  %
10769  \DeclareUnicodeCharacter{0226}{\dotaccent{A}}%
10770  \DeclareUnicodeCharacter{0227}{\dotaccent{a}}%
10771  \DeclareUnicodeCharacter{0228}{\cedilla{E}}%
10772  \DeclareUnicodeCharacter{0229}{\cedilla{e}}%
10773  \DeclareUnicodeCharacter{022E}{\dotaccent{O}}%
10774  \DeclareUnicodeCharacter{022F}{\dotaccent{o}}%
10775  %
10776  \DeclareUnicodeCharacter{0232}{\=Y}%
10777  \DeclareUnicodeCharacter{0233}{\=y}%
10778  \DeclareUnicodeCharacter{0237}{\dotless{j}}%
10779  %
10780  \DeclareUnicodeCharacter{02DB}{\ogonek{ }}%
10781  %
10782  % Greek letters upper case
10783  \DeclareUnicodeCharacter{0391}{{\it A}}%
10784  \DeclareUnicodeCharacter{0392}{{\it B}}%
10785  \DeclareUnicodeCharacter{0393}{\ensuremath{\mit\Gamma}}%
10786  \DeclareUnicodeCharacter{0394}{\ensuremath{\mit\Delta}}%
10787  \DeclareUnicodeCharacter{0395}{{\it E}}%
10788  \DeclareUnicodeCharacter{0396}{{\it Z}}%
10789  \DeclareUnicodeCharacter{0397}{{\it H}}%
10790  \DeclareUnicodeCharacter{0398}{\ensuremath{\mit\Theta}}%
10791  \DeclareUnicodeCharacter{0399}{{\it I}}%
10792  \DeclareUnicodeCharacter{039A}{{\it K}}%
10793  \DeclareUnicodeCharacter{039B}{\ensuremath{\mit\Lambda}}%
10794  \DeclareUnicodeCharacter{039C}{{\it M}}%
10795  \DeclareUnicodeCharacter{039D}{{\it N}}%
10796  \DeclareUnicodeCharacter{039E}{\ensuremath{\mit\Xi}}%
10797  \DeclareUnicodeCharacter{039F}{{\it O}}%
10798  \DeclareUnicodeCharacter{03A0}{\ensuremath{\mit\Pi}}%
10799  \DeclareUnicodeCharacter{03A1}{{\it P}}%
10800  %\DeclareUnicodeCharacter{03A2}{} % none - corresponds to final sigma
10801  \DeclareUnicodeCharacter{03A3}{\ensuremath{\mit\Sigma}}%
10802  \DeclareUnicodeCharacter{03A4}{{\it T}}%
10803  \DeclareUnicodeCharacter{03A5}{\ensuremath{\mit\Upsilon}}%
10804  \DeclareUnicodeCharacter{03A6}{\ensuremath{\mit\Phi}}%
10805  \DeclareUnicodeCharacter{03A7}{{\it X}}%
10806  \DeclareUnicodeCharacter{03A8}{\ensuremath{\mit\Psi}}%
10807  \DeclareUnicodeCharacter{03A9}{\ensuremath{\mit\Omega}}%
10808  %
10809  % Vowels with accents
10810  \DeclareUnicodeCharacter{0390}{\ensuremath{\ddot{\acute\iota}}}%
10811  \DeclareUnicodeCharacter{03AC}{\ensuremath{\acute\alpha}}%
10812  \DeclareUnicodeCharacter{03AD}{\ensuremath{\acute\epsilon}}%
10813  \DeclareUnicodeCharacter{03AE}{\ensuremath{\acute\eta}}%
10814  \DeclareUnicodeCharacter{03AF}{\ensuremath{\acute\iota}}%
10815  \DeclareUnicodeCharacter{03B0}{\ensuremath{\acute{\ddot\upsilon}}}%
10816  %
10817  % Standalone accent
10818  \DeclareUnicodeCharacter{0384}{\ensuremath{\acute{\ }}}%
10819  %
10820  % Greek letters lower case
10821  \DeclareUnicodeCharacter{03B1}{\ensuremath\alpha}%
10822  \DeclareUnicodeCharacter{03B2}{\ensuremath\beta}%
10823  \DeclareUnicodeCharacter{03B3}{\ensuremath\gamma}%
10824  \DeclareUnicodeCharacter{03B4}{\ensuremath\delta}%
10825  \DeclareUnicodeCharacter{03B5}{\ensuremath\epsilon}%
10826  \DeclareUnicodeCharacter{03B6}{\ensuremath\zeta}%
10827  \DeclareUnicodeCharacter{03B7}{\ensuremath\eta}%
10828  \DeclareUnicodeCharacter{03B8}{\ensuremath\theta}%
10829  \DeclareUnicodeCharacter{03B9}{\ensuremath\iota}%
10830  \DeclareUnicodeCharacter{03BA}{\ensuremath\kappa}%
10831  \DeclareUnicodeCharacter{03BB}{\ensuremath\lambda}%
10832  \DeclareUnicodeCharacter{03BC}{\ensuremath\mu}%
10833  \DeclareUnicodeCharacter{03BD}{\ensuremath\nu}%
10834  \DeclareUnicodeCharacter{03BE}{\ensuremath\xi}%
10835  \DeclareUnicodeCharacter{03BF}{{\it o}}% omicron
10836  \DeclareUnicodeCharacter{03C0}{\ensuremath\pi}%
10837  \DeclareUnicodeCharacter{03C1}{\ensuremath\rho}%
10838  \DeclareUnicodeCharacter{03C2}{\ensuremath\varsigma}%
10839  \DeclareUnicodeCharacter{03C3}{\ensuremath\sigma}%
10840  \DeclareUnicodeCharacter{03C4}{\ensuremath\tau}%
10841  \DeclareUnicodeCharacter{03C5}{\ensuremath\upsilon}%
10842  \DeclareUnicodeCharacter{03C6}{\ensuremath\phi}%
10843  \DeclareUnicodeCharacter{03C7}{\ensuremath\chi}%
10844  \DeclareUnicodeCharacter{03C8}{\ensuremath\psi}%
10845  \DeclareUnicodeCharacter{03C9}{\ensuremath\omega}%
10846  %
10847  % More Greek vowels with accents
10848  \DeclareUnicodeCharacter{03CA}{\ensuremath{\ddot\iota}}%
10849  \DeclareUnicodeCharacter{03CB}{\ensuremath{\ddot\upsilon}}%
10850  \DeclareUnicodeCharacter{03CC}{\ensuremath{\acute o}}%
10851  \DeclareUnicodeCharacter{03CD}{\ensuremath{\acute\upsilon}}%
10852  \DeclareUnicodeCharacter{03CE}{\ensuremath{\acute\omega}}%
10853  %
10854  % Variant Greek letters
10855  \DeclareUnicodeCharacter{03D1}{\ensuremath\vartheta}%
10856  \DeclareUnicodeCharacter{03D6}{\ensuremath\varpi}%
10857  \DeclareUnicodeCharacter{03F1}{\ensuremath\varrho}%
10858  %
10859  \DeclareUnicodeCharacter{1E02}{\dotaccent{B}}%
10860  \DeclareUnicodeCharacter{1E03}{\dotaccent{b}}%
10861  \DeclareUnicodeCharacter{1E04}{\udotaccent{B}}%
10862  \DeclareUnicodeCharacter{1E05}{\udotaccent{b}}%
10863  \DeclareUnicodeCharacter{1E06}{\ubaraccent{B}}%
10864  \DeclareUnicodeCharacter{1E07}{\ubaraccent{b}}%
10865  \DeclareUnicodeCharacter{1E0A}{\dotaccent{D}}%
10866  \DeclareUnicodeCharacter{1E0B}{\dotaccent{d}}%
10867  \DeclareUnicodeCharacter{1E0C}{\udotaccent{D}}%
10868  \DeclareUnicodeCharacter{1E0D}{\udotaccent{d}}%
10869  \DeclareUnicodeCharacter{1E0E}{\ubaraccent{D}}%
10870  \DeclareUnicodeCharacter{1E0F}{\ubaraccent{d}}%
10871  %
10872  \DeclareUnicodeCharacter{1E1E}{\dotaccent{F}}%
10873  \DeclareUnicodeCharacter{1E1F}{\dotaccent{f}}%
10874  %
10875  \DeclareUnicodeCharacter{1E20}{\=G}%
10876  \DeclareUnicodeCharacter{1E21}{\=g}%
10877  \DeclareUnicodeCharacter{1E22}{\dotaccent{H}}%
10878  \DeclareUnicodeCharacter{1E23}{\dotaccent{h}}%
10879  \DeclareUnicodeCharacter{1E24}{\udotaccent{H}}%
10880  \DeclareUnicodeCharacter{1E25}{\udotaccent{h}}%
10881  \DeclareUnicodeCharacter{1E26}{\"H}%
10882  \DeclareUnicodeCharacter{1E27}{\"h}%
10883  %
10884  \DeclareUnicodeCharacter{1E30}{\'K}%
10885  \DeclareUnicodeCharacter{1E31}{\'k}%
10886  \DeclareUnicodeCharacter{1E32}{\udotaccent{K}}%
10887  \DeclareUnicodeCharacter{1E33}{\udotaccent{k}}%
10888  \DeclareUnicodeCharacter{1E34}{\ubaraccent{K}}%
10889  \DeclareUnicodeCharacter{1E35}{\ubaraccent{k}}%
10890  \DeclareUnicodeCharacter{1E36}{\udotaccent{L}}%
10891  \DeclareUnicodeCharacter{1E37}{\udotaccent{l}}%
10892  \DeclareUnicodeCharacter{1E3A}{\ubaraccent{L}}%
10893  \DeclareUnicodeCharacter{1E3B}{\ubaraccent{l}}%
10894  \DeclareUnicodeCharacter{1E3E}{\'M}%
10895  \DeclareUnicodeCharacter{1E3F}{\'m}%
10896  %
10897  \DeclareUnicodeCharacter{1E40}{\dotaccent{M}}%
10898  \DeclareUnicodeCharacter{1E41}{\dotaccent{m}}%
10899  \DeclareUnicodeCharacter{1E42}{\udotaccent{M}}%
10900  \DeclareUnicodeCharacter{1E43}{\udotaccent{m}}%
10901  \DeclareUnicodeCharacter{1E44}{\dotaccent{N}}%
10902  \DeclareUnicodeCharacter{1E45}{\dotaccent{n}}%
10903  \DeclareUnicodeCharacter{1E46}{\udotaccent{N}}%
10904  \DeclareUnicodeCharacter{1E47}{\udotaccent{n}}%
10905  \DeclareUnicodeCharacter{1E48}{\ubaraccent{N}}%
10906  \DeclareUnicodeCharacter{1E49}{\ubaraccent{n}}%
10907  %
10908  \DeclareUnicodeCharacter{1E54}{\'P}%
10909  \DeclareUnicodeCharacter{1E55}{\'p}%
10910  \DeclareUnicodeCharacter{1E56}{\dotaccent{P}}%
10911  \DeclareUnicodeCharacter{1E57}{\dotaccent{p}}%
10912  \DeclareUnicodeCharacter{1E58}{\dotaccent{R}}%
10913  \DeclareUnicodeCharacter{1E59}{\dotaccent{r}}%
10914  \DeclareUnicodeCharacter{1E5A}{\udotaccent{R}}%
10915  \DeclareUnicodeCharacter{1E5B}{\udotaccent{r}}%
10916  \DeclareUnicodeCharacter{1E5E}{\ubaraccent{R}}%
10917  \DeclareUnicodeCharacter{1E5F}{\ubaraccent{r}}%
10918  %
10919  \DeclareUnicodeCharacter{1E60}{\dotaccent{S}}%
10920  \DeclareUnicodeCharacter{1E61}{\dotaccent{s}}%
10921  \DeclareUnicodeCharacter{1E62}{\udotaccent{S}}%
10922  \DeclareUnicodeCharacter{1E63}{\udotaccent{s}}%
10923  \DeclareUnicodeCharacter{1E6A}{\dotaccent{T}}%
10924  \DeclareUnicodeCharacter{1E6B}{\dotaccent{t}}%
10925  \DeclareUnicodeCharacter{1E6C}{\udotaccent{T}}%
10926  \DeclareUnicodeCharacter{1E6D}{\udotaccent{t}}%
10927  \DeclareUnicodeCharacter{1E6E}{\ubaraccent{T}}%
10928  \DeclareUnicodeCharacter{1E6F}{\ubaraccent{t}}%
10929  %
10930  \DeclareUnicodeCharacter{1E7C}{\~V}%
10931  \DeclareUnicodeCharacter{1E7D}{\~v}%
10932  \DeclareUnicodeCharacter{1E7E}{\udotaccent{V}}%
10933  \DeclareUnicodeCharacter{1E7F}{\udotaccent{v}}%
10934  %
10935  \DeclareUnicodeCharacter{1E80}{\`W}%
10936  \DeclareUnicodeCharacter{1E81}{\`w}%
10937  \DeclareUnicodeCharacter{1E82}{\'W}%
10938  \DeclareUnicodeCharacter{1E83}{\'w}%
10939  \DeclareUnicodeCharacter{1E84}{\"W}%
10940  \DeclareUnicodeCharacter{1E85}{\"w}%
10941  \DeclareUnicodeCharacter{1E86}{\dotaccent{W}}%
10942  \DeclareUnicodeCharacter{1E87}{\dotaccent{w}}%
10943  \DeclareUnicodeCharacter{1E88}{\udotaccent{W}}%
10944  \DeclareUnicodeCharacter{1E89}{\udotaccent{w}}%
10945  \DeclareUnicodeCharacter{1E8A}{\dotaccent{X}}%
10946  \DeclareUnicodeCharacter{1E8B}{\dotaccent{x}}%
10947  \DeclareUnicodeCharacter{1E8C}{\"X}%
10948  \DeclareUnicodeCharacter{1E8D}{\"x}%
10949  \DeclareUnicodeCharacter{1E8E}{\dotaccent{Y}}%
10950  \DeclareUnicodeCharacter{1E8F}{\dotaccent{y}}%
10951  %
10952  \DeclareUnicodeCharacter{1E90}{\^Z}%
10953  \DeclareUnicodeCharacter{1E91}{\^z}%
10954  \DeclareUnicodeCharacter{1E92}{\udotaccent{Z}}%
10955  \DeclareUnicodeCharacter{1E93}{\udotaccent{z}}%
10956  \DeclareUnicodeCharacter{1E94}{\ubaraccent{Z}}%
10957  \DeclareUnicodeCharacter{1E95}{\ubaraccent{z}}%
10958  \DeclareUnicodeCharacter{1E96}{\ubaraccent{h}}%
10959  \DeclareUnicodeCharacter{1E97}{\"t}%
10960  \DeclareUnicodeCharacter{1E98}{\ringaccent{w}}%
10961  \DeclareUnicodeCharacter{1E99}{\ringaccent{y}}%
10962  %
10963  \DeclareUnicodeCharacter{1EA0}{\udotaccent{A}}%
10964  \DeclareUnicodeCharacter{1EA1}{\udotaccent{a}}%
10965  %
10966  \DeclareUnicodeCharacter{1EB8}{\udotaccent{E}}%
10967  \DeclareUnicodeCharacter{1EB9}{\udotaccent{e}}%
10968  \DeclareUnicodeCharacter{1EBC}{\~E}%
10969  \DeclareUnicodeCharacter{1EBD}{\~e}%
10970  %
10971  \DeclareUnicodeCharacter{1ECA}{\udotaccent{I}}%
10972  \DeclareUnicodeCharacter{1ECB}{\udotaccent{i}}%
10973  \DeclareUnicodeCharacter{1ECC}{\udotaccent{O}}%
10974  \DeclareUnicodeCharacter{1ECD}{\udotaccent{o}}%
10975  %
10976  \DeclareUnicodeCharacter{1EE4}{\udotaccent{U}}%
10977  \DeclareUnicodeCharacter{1EE5}{\udotaccent{u}}%
10978  %
10979  \DeclareUnicodeCharacter{1EF2}{\`Y}%
10980  \DeclareUnicodeCharacter{1EF3}{\`y}%
10981  \DeclareUnicodeCharacter{1EF4}{\udotaccent{Y}}%
10982  %
10983  \DeclareUnicodeCharacter{1EF8}{\~Y}%
10984  \DeclareUnicodeCharacter{1EF9}{\~y}%
10985  %
10986  % Punctuation
10987  \DeclareUnicodeCharacter{2013}{--}%
10988  \DeclareUnicodeCharacter{2014}{---}%
10989  \DeclareUnicodeCharacter{2018}{\quoteleft{}}%
10990  \DeclareUnicodeCharacter{2019}{\quoteright{}}%
10991  \DeclareUnicodeCharacter{201A}{\quotesinglbase{}}%
10992  \DeclareUnicodeCharacter{201C}{\quotedblleft{}}%
10993  \DeclareUnicodeCharacter{201D}{\quotedblright{}}%
10994  \DeclareUnicodeCharacter{201E}{\quotedblbase{}}%
10995  \DeclareUnicodeCharacter{2020}{\ensuremath\dagger}%
10996  \DeclareUnicodeCharacter{2021}{\ensuremath\ddagger}%
10997  \DeclareUnicodeCharacter{2022}{\bullet{}}%
10998  \DeclareUnicodeCharacter{202F}{\thinspace}%
10999  \DeclareUnicodeCharacter{2026}{\dots{}}%
11000  \DeclareUnicodeCharacter{2039}{\guilsinglleft{}}%
11001  \DeclareUnicodeCharacter{203A}{\guilsinglright{}}%
11002  %
11003  \DeclareUnicodeCharacter{20AC}{\euro{}}%
11004  %
11005  \DeclareUnicodeCharacter{2192}{\expansion{}}%
11006  \DeclareUnicodeCharacter{21D2}{\result{}}%
11007  %
11008  % Mathematical symbols
11009  \DeclareUnicodeCharacter{2200}{\ensuremath\forall}%
11010  \DeclareUnicodeCharacter{2203}{\ensuremath\exists}%
11011  \DeclareUnicodeCharacter{2208}{\ensuremath\in}%
11012  \DeclareUnicodeCharacter{2212}{\minus{}}%
11013  \DeclareUnicodeCharacter{2217}{\ast}%
11014  \DeclareUnicodeCharacter{221E}{\ensuremath\infty}%
11015  \DeclareUnicodeCharacter{2225}{\ensuremath\parallel}%
11016  \DeclareUnicodeCharacter{2227}{\ensuremath\wedge}%
11017  \DeclareUnicodeCharacter{2229}{\ensuremath\cap}%
11018  \DeclareUnicodeCharacter{2261}{\equiv{}}%
11019  \DeclareUnicodeCharacter{2264}{\ensuremath\leq}%
11020  \DeclareUnicodeCharacter{2265}{\ensuremath\geq}%
11021  \DeclareUnicodeCharacter{2282}{\ensuremath\subset}%
11022  \DeclareUnicodeCharacter{2287}{\ensuremath\supseteq}%
11023  %
11024  \DeclareUnicodeCharacter{2016}{\ensuremath\Vert}%
11025  \DeclareUnicodeCharacter{2032}{\ensuremath\prime}%
11026  \DeclareUnicodeCharacter{210F}{\ensuremath\hbar}%
11027  \DeclareUnicodeCharacter{2111}{\ensuremath\Im}%
11028  \DeclareUnicodeCharacter{2113}{\ensuremath\ell}%
11029  \DeclareUnicodeCharacter{2118}{\ensuremath\wp}%
11030  \DeclareUnicodeCharacter{211C}{\ensuremath\Re}%
11031  \DeclareUnicodeCharacter{2135}{\ensuremath\aleph}%
11032  \DeclareUnicodeCharacter{2190}{\ensuremath\leftarrow}%
11033  \DeclareUnicodeCharacter{2191}{\ensuremath\uparrow}%
11034  \DeclareUnicodeCharacter{2193}{\ensuremath\downarrow}%
11035  \DeclareUnicodeCharacter{2194}{\ensuremath\leftrightarrow}%
11036  \DeclareUnicodeCharacter{2195}{\ensuremath\updownarrow}%
11037  \DeclareUnicodeCharacter{2196}{\ensuremath\nwarrow}%
11038  \DeclareUnicodeCharacter{2197}{\ensuremath\nearrow}%
11039  \DeclareUnicodeCharacter{2198}{\ensuremath\searrow}%
11040  \DeclareUnicodeCharacter{2199}{\ensuremath\swarrow}%
11041  \DeclareUnicodeCharacter{21A6}{\ensuremath\mapsto}%
11042  \DeclareUnicodeCharacter{21A9}{\ensuremath\hookleftarrow}%
11043  \DeclareUnicodeCharacter{21AA}{\ensuremath\hookrightarrow}%
11044  \DeclareUnicodeCharacter{21BC}{\ensuremath\leftharpoonup}%
11045  \DeclareUnicodeCharacter{21BD}{\ensuremath\leftharpoondown}%
11046  \DeclareUnicodeCharacter{21C0}{\ensuremath\rightharpoonup}%
11047  \DeclareUnicodeCharacter{21C1}{\ensuremath\rightharpoondown}%
11048  \DeclareUnicodeCharacter{21CC}{\ensuremath\rightleftharpoons}%
11049  \DeclareUnicodeCharacter{21D0}{\ensuremath\Leftarrow}%
11050  \DeclareUnicodeCharacter{21D1}{\ensuremath\Uparrow}%
11051  \DeclareUnicodeCharacter{21D3}{\ensuremath\Downarrow}%
11052  \DeclareUnicodeCharacter{21D4}{\ensuremath\Leftrightarrow}%
11053  \DeclareUnicodeCharacter{21D5}{\ensuremath\Updownarrow}%
11054  \DeclareUnicodeCharacter{2202}{\ensuremath\partial}%
11055  \DeclareUnicodeCharacter{2205}{\ensuremath\emptyset}%
11056  \DeclareUnicodeCharacter{2207}{\ensuremath\nabla}%
11057  \DeclareUnicodeCharacter{2209}{\ensuremath\notin}%
11058  \DeclareUnicodeCharacter{220B}{\ensuremath\owns}%
11059  \DeclareUnicodeCharacter{220F}{\ensuremath\prod}%
11060  \DeclareUnicodeCharacter{2210}{\ensuremath\coprod}%
11061  \DeclareUnicodeCharacter{2211}{\ensuremath\sum}%
11062  \DeclareUnicodeCharacter{2213}{\ensuremath\mp}%
11063  \DeclareUnicodeCharacter{2218}{\ensuremath\circ}%
11064  \DeclareUnicodeCharacter{221A}{\ensuremath\surd}%
11065  \DeclareUnicodeCharacter{221D}{\ensuremath\propto}%
11066  \DeclareUnicodeCharacter{2220}{\ensuremath\angle}%
11067  \DeclareUnicodeCharacter{2223}{\ensuremath\mid}%
11068  \DeclareUnicodeCharacter{2228}{\ensuremath\vee}%
11069  \DeclareUnicodeCharacter{222A}{\ensuremath\cup}%
11070  \DeclareUnicodeCharacter{222B}{\ensuremath\smallint}%
11071  \DeclareUnicodeCharacter{222E}{\ensuremath\oint}%
11072  \DeclareUnicodeCharacter{223C}{\ensuremath\sim}%
11073  \DeclareUnicodeCharacter{2240}{\ensuremath\wr}%
11074  \DeclareUnicodeCharacter{2243}{\ensuremath\simeq}%
11075  \DeclareUnicodeCharacter{2245}{\ensuremath\cong}%
11076  \DeclareUnicodeCharacter{2248}{\ensuremath\approx}%
11077  \DeclareUnicodeCharacter{224D}{\ensuremath\asymp}%
11078  \DeclareUnicodeCharacter{2250}{\ensuremath\doteq}%
11079  \DeclareUnicodeCharacter{2260}{\ensuremath\neq}%
11080  \DeclareUnicodeCharacter{226A}{\ensuremath\ll}%
11081  \DeclareUnicodeCharacter{226B}{\ensuremath\gg}%
11082  \DeclareUnicodeCharacter{227A}{\ensuremath\prec}%
11083  \DeclareUnicodeCharacter{227B}{\ensuremath\succ}%
11084  \DeclareUnicodeCharacter{2283}{\ensuremath\supset}%
11085  \DeclareUnicodeCharacter{2286}{\ensuremath\subseteq}%
11086  \DeclareUnicodeCharacter{228E}{\ensuremath\uplus}%
11087  \DeclareUnicodeCharacter{2291}{\ensuremath\sqsubseteq}%
11088  \DeclareUnicodeCharacter{2292}{\ensuremath\sqsupseteq}%
11089  \DeclareUnicodeCharacter{2293}{\ensuremath\sqcap}%
11090  \DeclareUnicodeCharacter{2294}{\ensuremath\sqcup}%
11091  \DeclareUnicodeCharacter{2295}{\ensuremath\oplus}%
11092  \DeclareUnicodeCharacter{2296}{\ensuremath\ominus}%
11093  \DeclareUnicodeCharacter{2297}{\ensuremath\otimes}%
11094  \DeclareUnicodeCharacter{2298}{\ensuremath\oslash}%
11095  \DeclareUnicodeCharacter{2299}{\ensuremath\odot}%
11096  \DeclareUnicodeCharacter{22A2}{\ensuremath\vdash}%
11097  \DeclareUnicodeCharacter{22A3}{\ensuremath\dashv}%
11098  \DeclareUnicodeCharacter{22A4}{\ensuremath\ptextop}%
11099  \DeclareUnicodeCharacter{22A5}{\ensuremath\bot}%
11100  \DeclareUnicodeCharacter{22A8}{\ensuremath\models}%
11101  \DeclareUnicodeCharacter{22C0}{\ensuremath\bigwedge}%
11102  \DeclareUnicodeCharacter{22C1}{\ensuremath\bigvee}%
11103  \DeclareUnicodeCharacter{22C2}{\ensuremath\bigcap}%
11104  \DeclareUnicodeCharacter{22C3}{\ensuremath\bigcup}%
11105  \DeclareUnicodeCharacter{22C4}{\ensuremath\diamond}%
11106  \DeclareUnicodeCharacter{22C5}{\ensuremath\cdot}%
11107  \DeclareUnicodeCharacter{22C6}{\ensuremath\star}%
11108  \DeclareUnicodeCharacter{22C8}{\ensuremath\bowtie}%
11109  \DeclareUnicodeCharacter{2308}{\ensuremath\lceil}%
11110  \DeclareUnicodeCharacter{2309}{\ensuremath\rceil}%
11111  \DeclareUnicodeCharacter{230A}{\ensuremath\lfloor}%
11112  \DeclareUnicodeCharacter{230B}{\ensuremath\rfloor}%
11113  \DeclareUnicodeCharacter{2322}{\ensuremath\frown}%
11114  \DeclareUnicodeCharacter{2323}{\ensuremath\smile}%
11115  %
11116  \DeclareUnicodeCharacter{25B3}{\ensuremath\triangle}%
11117  \DeclareUnicodeCharacter{25B7}{\ensuremath\triangleright}%
11118  \DeclareUnicodeCharacter{25BD}{\ensuremath\bigtriangledown}%
11119  \DeclareUnicodeCharacter{25C1}{\ensuremath\triangleleft}%
11120  \DeclareUnicodeCharacter{25C7}{\ensuremath\diamond}%
11121  \DeclareUnicodeCharacter{2660}{\ensuremath\spadesuit}%
11122  \DeclareUnicodeCharacter{2661}{\ensuremath\heartsuit}%
11123  \DeclareUnicodeCharacter{2662}{\ensuremath\diamondsuit}%
11124  \DeclareUnicodeCharacter{2663}{\ensuremath\clubsuit}%
11125  \DeclareUnicodeCharacter{266D}{\ensuremath\flat}%
11126  \DeclareUnicodeCharacter{266E}{\ensuremath\natural}%
11127  \DeclareUnicodeCharacter{266F}{\ensuremath\sharp}%
11128  \DeclareUnicodeCharacter{26AA}{\ensuremath\bigcirc}%
11129  \DeclareUnicodeCharacter{27B9}{\ensuremath\rangle}%
11130  \DeclareUnicodeCharacter{27C2}{\ensuremath\perp}%
11131  \DeclareUnicodeCharacter{27E8}{\ensuremath\langle}%
11132  \DeclareUnicodeCharacter{27F5}{\ensuremath\longleftarrow}%
11133  \DeclareUnicodeCharacter{27F6}{\ensuremath\longrightarrow}%
11134  \DeclareUnicodeCharacter{27F7}{\ensuremath\longleftrightarrow}%
11135  \DeclareUnicodeCharacter{27FC}{\ensuremath\longmapsto}%
11136  \DeclareUnicodeCharacter{29F5}{\ensuremath\setminus}%
11137  \DeclareUnicodeCharacter{2A00}{\ensuremath\bigodot}%
11138  \DeclareUnicodeCharacter{2A01}{\ensuremath\bigoplus}%
11139  \DeclareUnicodeCharacter{2A02}{\ensuremath\bigotimes}%
11140  \DeclareUnicodeCharacter{2A04}{\ensuremath\biguplus}%
11141  \DeclareUnicodeCharacter{2A06}{\ensuremath\bigsqcup}%
11142  \DeclareUnicodeCharacter{2A3F}{\ensuremath\amalg}%
11143  \DeclareUnicodeCharacter{2AAF}{\ensuremath\preceq}%
11144  \DeclareUnicodeCharacter{2AB0}{\ensuremath\succeq}%
11145  %
11146  \global\mathchardef\checkmark="1370% actually the square root sign
11147  \DeclareUnicodeCharacter{2713}{\ensuremath\checkmark}%
11148}% end of \unicodechardefs
11149
11150% UTF-8 byte sequence (pdfTeX) definitions (replacing and @U command)
11151% It makes the setting that replace UTF-8 byte sequence.
11152\def\utfeightchardefs{%
11153  \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterUTFviii
11154  \unicodechardefs
11155}
11156
11157% Whether the active definitions of non-ASCII characters expand to
11158% non-active tokens with the same character code.  This is used to
11159% write characters literally, instead of using active definitions for
11160% printing the correct glyphs.
11161\newif\ifpassthroughchars
11162\passthroughcharsfalse
11163
11164% For native Unicode handling (XeTeX and LuaTeX),
11165% provide a definition macro to replace/pass-through a Unicode character
11166%
11167\def\DeclareUnicodeCharacterNative#1#2{%
11168  \catcode"#1=\active
11169  \def\dodeclareunicodecharacternative##1##2##3{%
11170    \begingroup
11171      \uccode`\~="##2\relax
11172      \uppercase{\gdef~}{%
11173        \ifpassthroughchars
11174          ##1%
11175        \else
11176          ##3%
11177        \fi
11178      }
11179    \endgroup
11180  }
11181  \begingroup
11182    \uccode`\.="#1\relax
11183    \uppercase{\def\UTFNativeTmp{.}}%
11184    \expandafter\dodeclareunicodecharacternative\UTFNativeTmp{#1}{#2}%
11185  \endgroup
11186}
11187
11188% Native Unicode handling (XeTeX and LuaTeX) character replacing definition.
11189% It activates the setting that replaces Unicode characters.
11190\def\nativeunicodechardefs{%
11191  \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNative
11192  \unicodechardefs
11193}
11194
11195% For native Unicode handling (XeTeX and LuaTeX),
11196% make the character token expand
11197% to the sequences given in \unicodechardefs for printing.
11198\def\DeclareUnicodeCharacterNativeAtU#1#2{%
11199  \def\UTFAtUTmp{#2}
11200  \expandafter\globallet\csname uni:#1\endcsname \UTFAtUTmp
11201}
11202
11203% @U command definitions for native Unicode handling (XeTeX and LuaTeX).
11204\def\nativeunicodechardefsatu{%
11205  \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNativeAtU
11206  \unicodechardefs
11207}
11208
11209% US-ASCII character definitions.
11210\def\asciichardefs{% nothing need be done
11211   \relax
11212}
11213
11214% Define all Unicode characters we know about.  This makes UTF-8 the default
11215% input encoding and allows @U to work.
11216\iftxinativeunicodecapable
11217  \nativeunicodechardefsatu
11218\else
11219  \utfeightchardefs
11220\fi
11221
11222\message{formatting,}
11223
11224\newdimen\defaultparindent \defaultparindent = 15pt
11225
11226\chapheadingskip = 15pt plus 4pt minus 2pt
11227\secheadingskip = 12pt plus 3pt minus 2pt
11228\subsecheadingskip = 9pt plus 2pt minus 2pt
11229
11230% Prevent underfull vbox error messages.
11231\vbadness = 10000
11232
11233% Don't be very finicky about underfull hboxes, either.
11234\hbadness = 6666
11235
11236% Following George Bush, get rid of widows and orphans.
11237\widowpenalty=10000
11238\clubpenalty=10000
11239
11240% Use TeX 3.0's \emergencystretch to help line breaking, but if we're
11241% using an old version of TeX, don't do anything.  We want the amount of
11242% stretch added to depend on the line length, hence the dependence on
11243% \hsize.  We call this whenever the paper size is set.
11244%
11245\def\setemergencystretch{%
11246  \ifx\emergencystretch\thisisundefined
11247    % Allow us to assign to \emergencystretch anyway.
11248    \def\emergencystretch{\dimen0}%
11249  \else
11250    \emergencystretch = .15\hsize
11251  \fi
11252}
11253
11254% Parameters in order: 1) textheight; 2) textwidth;
11255% 3) voffset; 4) hoffset; 5) binding offset; 6) topskip;
11256% 7) physical page height; 8) physical page width.
11257%
11258% We also call \setleading{\textleading}, so the caller should define
11259% \textleading.  The caller should also set \parskip.
11260%
11261\def\internalpagesizes#1#2#3#4#5#6#7#8{%
11262  \voffset = #3\relax
11263  \topskip = #6\relax
11264  \splittopskip = \topskip
11265  %
11266  \vsize = #1\relax
11267  \advance\vsize by \topskip
11268  \outervsize = \vsize
11269  \advance\outervsize by 2\topandbottommargin
11270  \txipageheight = \vsize
11271  %
11272  \hsize = #2\relax
11273  \outerhsize = \hsize
11274  \advance\outerhsize by 0.5in
11275  \txipagewidth = \hsize
11276  %
11277  \normaloffset = #4\relax
11278  \bindingoffset = #5\relax
11279  %
11280  \ifpdf
11281    \pdfpageheight #7\relax
11282    \pdfpagewidth #8\relax
11283    % if we don't reset these, they will remain at "1 true in" of
11284    % whatever layout pdftex was dumped with.
11285    \pdfhorigin = 1 true in
11286    \pdfvorigin = 1 true in
11287  \else
11288    \ifx\XeTeXrevision\thisisundefined
11289      \special{papersize=#8,#7}%
11290    \else
11291      \pdfpageheight #7\relax
11292      \pdfpagewidth #8\relax
11293      % XeTeX does not have \pdfhorigin and \pdfvorigin.
11294    \fi
11295  \fi
11296  %
11297  \setleading{\textleading}
11298  %
11299  \parindent = \defaultparindent
11300  \setemergencystretch
11301}
11302
11303% @letterpaper (the default).
11304\def\letterpaper{{\globaldefs = 1
11305  \parskip = 3pt plus 2pt minus 1pt
11306  \textleading = 13.2pt
11307  %
11308  % If page is nothing but text, make it come out even.
11309  \internalpagesizes{607.2pt}{6in}% that's 46 lines
11310                    {\voffset}{.25in}%
11311                    {\bindingoffset}{36pt}%
11312                    {11in}{8.5in}%
11313}}
11314
11315% Use @smallbook to reset parameters for 7x9.25 trim size.
11316\def\smallbook{{\globaldefs = 1
11317  \parskip = 2pt plus 1pt
11318  \textleading = 12pt
11319  %
11320  \internalpagesizes{7.5in}{5in}%
11321                    {-.2in}{0in}%
11322                    {\bindingoffset}{16pt}%
11323                    {9.25in}{7in}%
11324  %
11325  \lispnarrowing = 0.3in
11326  \tolerance = 700
11327  \contentsrightmargin = 0pt
11328  \defbodyindent = .5cm
11329}}
11330
11331% Use @smallerbook to reset parameters for 6x9 trim size.
11332% (Just testing, parameters still in flux.)
11333\def\smallerbook{{\globaldefs = 1
11334  \parskip = 1.5pt plus 1pt
11335  \textleading = 12pt
11336  %
11337  \internalpagesizes{7.4in}{4.8in}%
11338                    {-.2in}{-.4in}%
11339                    {0pt}{14pt}%
11340                    {9in}{6in}%
11341  %
11342  \lispnarrowing = 0.25in
11343  \tolerance = 700
11344  \contentsrightmargin = 0pt
11345  \defbodyindent = .4cm
11346}}
11347
11348% Use @afourpaper to print on European A4 paper.
11349\def\afourpaper{{\globaldefs = 1
11350  \parskip = 3pt plus 2pt minus 1pt
11351  \textleading = 13.2pt
11352  %
11353  % Double-side printing via postscript on Laserjet 4050
11354  % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
11355  % To change the settings for a different printer or situation, adjust
11356  % \normaloffset until the front-side and back-side texts align.  Then
11357  % do the same for \bindingoffset.  You can set these for testing in
11358  % your texinfo source file like this:
11359  % @tex
11360  % \global\normaloffset = -6mm
11361  % \global\bindingoffset = 10mm
11362  % @end tex
11363  \internalpagesizes{673.2pt}{160mm}% that's 51 lines
11364                    {\voffset}{\hoffset}%
11365                    {\bindingoffset}{44pt}%
11366                    {297mm}{210mm}%
11367  %
11368  \tolerance = 700
11369  \contentsrightmargin = 0pt
11370  \defbodyindent = 5mm
11371}}
11372
11373% Use @afivepaper to print on European A5 paper.
11374% From romildo@urano.iceb.ufop.br, 2 July 2000.
11375% He also recommends making @example and @lisp be small.
11376\def\afivepaper{{\globaldefs = 1
11377  \parskip = 2pt plus 1pt minus 0.1pt
11378  \textleading = 12.5pt
11379  %
11380  \internalpagesizes{160mm}{120mm}%
11381                    {\voffset}{\hoffset}%
11382                    {\bindingoffset}{8pt}%
11383                    {210mm}{148mm}%
11384  %
11385  \lispnarrowing = 0.2in
11386  \tolerance = 800
11387  \contentsrightmargin = 0pt
11388  \defbodyindent = 2mm
11389  \tableindent = 12mm
11390}}
11391
11392% A specific text layout, 24x15cm overall, intended for A4 paper.
11393\def\afourlatex{{\globaldefs = 1
11394  \afourpaper
11395  \internalpagesizes{237mm}{150mm}%
11396                    {\voffset}{4.6mm}%
11397                    {\bindingoffset}{7mm}%
11398                    {297mm}{210mm}%
11399  %
11400  % Must explicitly reset to 0 because we call \afourpaper.
11401  \globaldefs = 0
11402}}
11403
11404% Use @afourwide to print on A4 paper in landscape format.
11405\def\afourwide{{\globaldefs = 1
11406  \afourpaper
11407  \internalpagesizes{241mm}{165mm}%
11408                    {\voffset}{-2.95mm}%
11409                    {\bindingoffset}{7mm}%
11410                    {297mm}{210mm}%
11411  \globaldefs = 0
11412}}
11413
11414% @pagesizes TEXTHEIGHT[,TEXTWIDTH]
11415% Perhaps we should allow setting the margins, \topskip, \parskip,
11416% and/or leading, also. Or perhaps we should compute them somehow.
11417%
11418\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
11419\def\pagesizesyyy#1,#2,#3\finish{{%
11420  \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
11421  \globaldefs = 1
11422  %
11423  \parskip = 3pt plus 2pt minus 1pt
11424  \setleading{\textleading}%
11425  %
11426  \dimen0 = #1\relax
11427  \advance\dimen0 by \voffset
11428  \advance\dimen0 by 1in % reference point for DVI is 1 inch from top of page
11429  %
11430  \dimen2 = \hsize
11431  \advance\dimen2 by \normaloffset
11432  \advance\dimen2 by 1in % reference point is 1 inch from left edge of page
11433  %
11434  \internalpagesizes{#1}{\hsize}%
11435                    {\voffset}{\normaloffset}%
11436                    {\bindingoffset}{44pt}%
11437                    {\dimen0}{\dimen2}%
11438}}
11439
11440% Set default to letter.
11441%
11442\letterpaper
11443
11444% Default value of \hfuzz, for suppressing warnings about overfull hboxes.
11445\hfuzz = 1pt
11446
11447
11448\message{and turning on texinfo input format.}
11449
11450\def^^L{\par} % remove \outer, so ^L can appear in an @comment
11451
11452% DEL is a comment character, in case @c does not suffice.
11453\catcode`\^^? = 14
11454
11455% Define macros to output various characters with catcode for normal text.
11456\catcode`\"=\other \def\normaldoublequote{"}
11457\catcode`\$=\other \def\normaldollar{$}%$ font-lock fix
11458\catcode`\+=\other \def\normalplus{+}
11459\catcode`\<=\other \def\normalless{<}
11460\catcode`\>=\other \def\normalgreater{>}
11461\catcode`\^=\other \def\normalcaret{^}
11462\catcode`\_=\other \def\normalunderscore{_}
11463\catcode`\|=\other \def\normalverticalbar{|}
11464\catcode`\~=\other \def\normaltilde{~}
11465
11466% This macro is used to make a character print one way in \tt
11467% (where it can probably be output as-is), and another way in other fonts,
11468% where something hairier probably needs to be done.
11469%
11470% #1 is what to print if we are indeed using \tt; #2 is what to print
11471% otherwise.  Since all the Computer Modern typewriter fonts have zero
11472% interword stretch (and shrink), and it is reasonable to expect all
11473% typewriter fonts to have this, we can check that font parameter.
11474%
11475\def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
11476
11477% Same as above, but check for italic font.  Actually this also catches
11478% non-italic slanted fonts since it is impossible to distinguish them from
11479% italic fonts.  But since this is only used by $ and it uses \sl anyway
11480% this is not a problem.
11481\def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
11482
11483% Set catcodes for Texinfo file
11484
11485% Active characters for printing the wanted glyph.
11486% Most of these we simply print from the \tt font, but for some, we can
11487% use math or other variants that look better in normal text.
11488%
11489\catcode`\"=\active
11490\def\activedoublequote{{\tt\char34}}
11491\let"=\activedoublequote
11492\catcode`\~=\active \def\activetilde{{\tt\char126}} \let~ = \activetilde
11493\chardef\hatchar=`\^
11494\catcode`\^=\active \def\activehat{{\tt \hatchar}} \let^ = \activehat
11495
11496\catcode`\_=\active
11497\def_{\ifusingtt\normalunderscore\_}
11498\def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
11499\let\realunder=_
11500
11501\catcode`\|=\active \def|{{\tt\char124}}
11502
11503\chardef \less=`\<
11504\catcode`\<=\active \def\activeless{{\tt \less}}\let< = \activeless
11505\chardef \gtr=`\>
11506\catcode`\>=\active \def\activegtr{{\tt \gtr}}\let> = \activegtr
11507\catcode`\+=\active \def+{{\tt \char 43}}
11508\catcode`\$=\active \def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
11509\catcode`\-=\active \let-=\normaldash
11510
11511
11512% used for headline/footline in the output routine, in case the page
11513% breaks in the middle of an @tex block.
11514\def\texinfochars{%
11515  \let< = \activeless
11516  \let> = \activegtr
11517  \let~ = \activetilde
11518  \let^ = \activehat
11519  \markupsetuplqdefault \markupsetuprqdefault
11520  \let\b = \strong
11521  \let\i = \smartitalic
11522  % in principle, all other definitions in \tex have to be undone too.
11523}
11524
11525% Used sometimes to turn off (effectively) the active characters even after
11526% parsing them.
11527\def\turnoffactive{%
11528  \normalturnoffactive
11529  \otherbackslash
11530}
11531
11532\catcode`\@=0
11533
11534% \backslashcurfont outputs one backslash character in current font,
11535% as in \char`\\.
11536\global\chardef\backslashcurfont=`\\
11537\global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
11538
11539% \realbackslash is an actual character `\' with catcode other, and
11540% \doublebackslash is two of them (for the pdf outlines).
11541{\catcode`\\=\other @gdef@realbackslash{\} @gdef@doublebackslash{\\}}
11542
11543% In Texinfo, backslash is an active character; it prints the backslash
11544% in fixed width font.
11545\catcode`\\=\active  % @ for escape char from now on.
11546
11547% Print a typewriter backslash.  For math mode, we can't simply use
11548% \backslashcurfont: the story here is that in math mode, the \char
11549% of \backslashcurfont ends up printing the roman \ from the math symbol
11550% font (because \char in math mode uses the \mathcode, and plain.tex
11551% sets \mathcode`\\="026E).  Hence we use an explicit \mathchar,
11552% which is the decimal equivalent of "715c (class 7, e.g., use \fam;
11553% ignored family value; char position "5C).  We can't use " for the
11554% usual hex value because it has already been made active.
11555
11556@def@ttbackslash{{@tt @ifmmode @mathchar29020 @else @backslashcurfont @fi}}
11557@let@backslashchar = @ttbackslash % @backslashchar{} is for user documents.
11558
11559% \rawbackslash defines an active \ to do \backslashcurfont.
11560% \otherbackslash defines an active \ to be a literal `\' character with
11561% catcode other.  We switch back and forth between these.
11562@gdef@rawbackslash{@let\=@backslashcurfont}
11563@gdef@otherbackslash{@let\=@realbackslash}
11564
11565% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
11566% the literal character `\'.
11567%
11568{@catcode`- = @active
11569 @gdef@normalturnoffactive{%
11570   @passthroughcharstrue
11571   @let-=@normaldash
11572   @let"=@normaldoublequote
11573   @let$=@normaldollar %$ font-lock fix
11574   @let+=@normalplus
11575   @let<=@normalless
11576   @let>=@normalgreater
11577   @let^=@normalcaret
11578   @let_=@normalunderscore
11579   @let|=@normalverticalbar
11580   @let~=@normaltilde
11581   @let\=@ttbackslash
11582   @markupsetuplqdefault
11583   @markupsetuprqdefault
11584   @unsepspaces
11585 }
11586}
11587
11588% If a .fmt file is being used, characters that might appear in a file
11589% name cannot be active until we have parsed the command line.
11590% So turn them off again, and have @fixbackslash turn them back on.
11591@catcode`+=@other @catcode`@_=@other
11592
11593% \enablebackslashhack - allow file to begin `\input texinfo'
11594%
11595% If a .fmt file is being used, we don't want the `\input texinfo' to show up.
11596% That is what \eatinput is for; after that, the `\' should revert to printing
11597% a backslash.
11598% If the file did not have a `\input texinfo', then it is turned off after
11599% the first line; otherwise the first `\' in the file would cause an error.
11600% This is used on the very last line of this file, texinfo.tex.
11601% We also use @c to call @fixbackslash, in case ends of lines are hidden.
11602{
11603@catcode`@^=7
11604@catcode`@^^M=13@gdef@enablebackslashhack{%
11605  @global@let\ = @eatinput%
11606  @catcode`@^^M=13%
11607  @def@c{@fixbackslash@c}%
11608  % Definition for the newline at the end of this file.
11609  @def ^^M{@let^^M@secondlinenl}%
11610  % Definition for a newline in the main Texinfo file.
11611  @gdef @secondlinenl{@fixbackslash}%
11612  % In case the first line has a whole-line command on it
11613  @let@originalparsearg@parsearg
11614  @def@parsearg{@fixbackslash@originalparsearg}
11615}}
11616
11617{@catcode`@^=7 @catcode`@^^M=13%
11618@gdef@eatinput input texinfo#1^^M{@fixbackslash}}
11619
11620% Emergency active definition of newline, in case an active newline token
11621% appears by mistake.
11622{@catcode`@^=7 @catcode13=13%
11623@gdef@enableemergencynewline{%
11624  @gdef^^M{%
11625    @par%
11626    %<warning: active newline>@par%
11627}}}
11628
11629
11630@gdef@fixbackslash{%
11631  @ifx\@eatinput @let\ = @ttbackslash @fi
11632  @catcode13=5 % regular end of line
11633  @enableemergencynewline
11634  @let@c=@texinfoc
11635  @let@parsearg@originalparsearg
11636  % Also turn back on active characters that might appear in the input
11637  % file name, in case not using a pre-dumped format.
11638  @catcode`+=@active
11639  @catcode`@_=@active
11640  %
11641  % If texinfo.cnf is present on the system, read it.
11642  % Useful for site-wide @afourpaper, etc.  This macro, @fixbackslash, gets
11643  % called at the beginning of every Texinfo file.  Not opening texinfo.cnf
11644  % directly in this file, texinfo.tex, makes it possible to make a format
11645  % file for Texinfo.
11646  %
11647  @openin 1 texinfo.cnf
11648  @ifeof 1 @else @input texinfo.cnf @fi
11649  @closein 1
11650}
11651
11652
11653% Say @foo, not \foo, in error messages.
11654@escapechar = `@@
11655
11656% These (along with & and #) are made active for url-breaking, so need
11657% active definitions as the normal characters.
11658@def@normaldot{.}
11659@def@normalquest{?}
11660@def@normalslash{/}
11661
11662% These look ok in all fonts, so just make them not special.
11663% @hashchar{} gets its own user-level command, because of #line.
11664@catcode`@& = @other @def@normalamp{&}
11665@catcode`@# = @other @def@normalhash{#}
11666@catcode`@% = @other @def@normalpercent{%}
11667
11668@let @hashchar = @normalhash
11669
11670@c Finally, make ` and ' active, so that txicodequoteundirected and
11671@c txicodequotebacktick work right in, e.g., @w{@code{`foo'}}.  If we
11672@c don't make ` and ' active, @code will not get them as active chars.
11673@c Do this last of all since we use ` in the previous @catcode assignments.
11674@catcode`@'=@active
11675@catcode`@`=@active
11676@markupsetuplqdefault
11677@markupsetuprqdefault
11678
11679@c Local variables:
11680@c eval: (add-hook 'before-save-hook 'time-stamp)
11681@c page-delimiter: "^\\\\message\\|emacs-page"
11682@c time-stamp-start: "def\\\\texinfoversion{"
11683@c time-stamp-format: "%:y-%02m-%02d.%02H"
11684@c time-stamp-end: "}"
11685@c End:
11686
11687@c vim:sw=2:
11688
11689@enablebackslashhack
11690