]> git.donarmstrong.com Git - lilypond.git/blob - tex/texinfo.tex
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / tex / texinfo.tex
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{2016-05-26.20}
7 %
8 % Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
9 % 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
10 % 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
11 % Free Software Foundation, Inc.
12 %
13 % This texinfo.tex file is free software: you can redistribute it and/or
14 % modify it under the terms of the GNU General Public License as
15 % published by the Free Software Foundation, either version 3 of the
16 % License, or (at your option) any later version.
17 %
18 % This texinfo.tex file is distributed in the hope that it will be
19 % useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 % of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 % General Public License for more details.
22 %
23 % You should have received a copy of the GNU General Public License
24 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
25 %
26 % As a special exception, when this file is read by TeX when processing
27 % a Texinfo source document, you may use the result without
28 % restriction. This Exception is an additional permission under section 7
29 % of the GNU General Public License, version 3 ("GPLv3").
30 %
31 % Please try the latest version of texinfo.tex before submitting bug
32 % reports; you can get the latest version from:
33 %   http://ftp.gnu.org/gnu/texinfo/ (the Texinfo release area), or
34 %   http://ftpmirror.gnu.org/texinfo/ (same, via a mirror), or
35 %   http://www.gnu.org/software/texinfo/ (the Texinfo home page)
36 % The texinfo.tex in any given distribution could well be out
37 % of date, so if that's what you're using, please check.
38 %
39 % Send bug reports to bug-texinfo@gnu.org.  Please include including a
40 % complete document in each bug report with which we can reproduce the
41 % problem.  Patches are, of course, greatly appreciated.
42 %
43 % To process a Texinfo manual with TeX, it's most reliable to use the
44 % texi2dvi shell script that comes with the distribution.  For a simple
45 % manual foo.texi, however, you can get away with this:
46 %   tex foo.texi
47 %   texindex foo.??
48 %   tex foo.texi
49 %   tex foo.texi
50 %   dvips foo.dvi -o  # or whatever; this makes foo.ps.
51 % The extra TeX runs get the cross-reference information correct.
52 % Sometimes one run after texindex suffices, and sometimes you need more
53 % than two; texi2dvi does it as many times as necessary.
54 %
55 % It is possible to adapt texinfo.tex for other languages, to some
56 % extent.  You can get the existing language-specific files from the
57 % full Texinfo distribution.
58 %
59 % The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
60
61
62 \message{Loading texinfo [version \texinfoversion]:}
63
64 % If in a .fmt file, print the version number
65 % and turn on active characters that we couldn't do earlier because
66 % they might have appeared in the input file name.
67 \everyjob{\message{[Texinfo version \texinfoversion]}%
68   \catcode`+=\active \catcode`\_=\active}
69
70 % LaTeX's \typeout.  This ensures that the messages it is used for
71 % are identical in format to the corresponding ones from latex/pdflatex.
72 \def\typeout{\immediate\write17}%
73
74 \chardef\other=12
75
76 % We never want plain's \outer definition of \+ in Texinfo.
77 % For @tex, we can use \tabalign.
78 \let\+ = \relax
79
80 % Save some plain tex macros whose names we will redefine.
81 \let\ptexb=\b
82 \let\ptexbullet=\bullet
83 \let\ptexc=\c
84 \let\ptexcomma=\,
85 \let\ptexdot=\.
86 \let\ptexdots=\dots
87 \let\ptexend=\end
88 \let\ptexequiv=\equiv
89 \let\ptexexclam=\!
90 \let\ptexfootnote=\footnote
91 \let\ptexgtr=>
92 \let\ptexhat=^
93 \let\ptexi=\i
94 \let\ptexindent=\indent
95 \let\ptexinsert=\insert
96 \let\ptexlbrace=\{
97 \let\ptexless=<
98 \let\ptexnewwrite\newwrite
99 \let\ptexnoindent=\noindent
100 \let\ptexplus=+
101 \let\ptexraggedright=\raggedright
102 \let\ptexrbrace=\}
103 \let\ptexslash=\/
104 \let\ptexsp=\sp
105 \let\ptexstar=\*
106 \let\ptexsup=\sup
107 \let\ptext=\t
108 \let\ptextop=\top
109 {\catcode`\'=\active \global\let\ptexquoteright'}% active in plain's math mode
110
111 % If this character appears in an error message or help string, it
112 % starts a new line in the output.
113 \newlinechar = `^^J
114
115 % Use TeX 3.0's \inputlineno to get the line number, for better error
116 % messages, but if we're using an old version of TeX, don't do anything.
117 %
118 \ifx\inputlineno\thisisundefined
119   \let\linenumber = \empty % Pre-3.0.
120 \else
121   \def\linenumber{l.\the\inputlineno:\space}
122 \fi
123
124 % Set up fixed words for English if not already set.
125 \ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
126 \ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
127 \ifx\putworderror\undefined     \gdef\putworderror{error}\fi
128 \ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
129 \ifx\putwordin\undefined        \gdef\putwordin{in}\fi
130 \ifx\putwordIndexIsEmpty\undefined       \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
131 \ifx\putwordIndexNonexistent\undefined   \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
132 \ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
133 \ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
134 \ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
135 \ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
136 \ifx\putwordof\undefined        \gdef\putwordof{of}\fi
137 \ifx\putwordon\undefined        \gdef\putwordon{on}\fi
138 \ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
139 \ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
140 \ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
141 \ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
142 \ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
143 \ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
144 \ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
145 %
146 \ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
147 \ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
148 \ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
149 \ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
150 \ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
151 \ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
152 \ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
153 \ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
154 \ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
155 \ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
156 \ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
157 \ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
158 %
159 \ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
160 \ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
161 \ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
162 \ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
163 \ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
164
165 % Give the space character the catcode for a space.
166 \def\spaceisspace{\catcode`\ =10\relax}
167
168 \chardef\dashChar  = `\-
169 \chardef\slashChar = `\/
170 \chardef\underChar = `\_
171
172 % Ignore a token.
173 %
174 \def\gobble#1{}
175
176 % The following is used inside several \edef's.
177 \def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
178
179 % Hyphenation fixes.
180 \hyphenation{
181   Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
182   ap-pen-dix bit-map bit-maps
183   data-base data-bases eshell fall-ing half-way long-est man-u-script
184   man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
185   par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
186   spell-ing spell-ings
187   stand-alone strong-est time-stamp time-stamps which-ever white-space
188   wide-spread wrap-around
189 }
190
191 % Sometimes it is convenient to have everything in the transcript file
192 % and nothing on the terminal.  We don't just call \tracingall here,
193 % since that produces some useless output on the terminal.  We also make
194 % some effort to order the tracing commands to reduce output in the log
195 % file; cf. trace.sty in LaTeX.
196 %
197 \def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
198 \def\loggingall{%
199   \tracingstats2
200   \tracingpages1
201   \tracinglostchars2  % 2 gives us more in etex
202   \tracingparagraphs1
203   \tracingoutput1
204   \tracingmacros2
205   \tracingrestores1
206   \showboxbreadth\maxdimen \showboxdepth\maxdimen
207   \ifx\eTeXversion\thisisundefined\else % etex gives us more logging
208     \tracingscantokens1
209     \tracingifs1
210     \tracinggroups1
211     \tracingnesting2
212     \tracingassigns1
213   \fi
214   \tracingcommands3  % 3 gives us more in etex
215   \errorcontextlines16
216 }%
217
218 % @errormsg{MSG}.  Do the index-like expansions on MSG, but if things
219 % aren't perfect, it's not the end of the world, being an error message,
220 % after all.
221
222 \def\errormsg{\begingroup \indexnofonts \doerrormsg}
223 \def\doerrormsg#1{\errmessage{#1}}
224
225 % add check for \lastpenalty to plain's definitions.  If the last thing
226 % we did was a \nobreak, we don't want to insert more space.
227 %
228 \def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
229   \removelastskip\penalty-50\smallskip\fi\fi}
230 \def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
231   \removelastskip\penalty-100\medskip\fi\fi}
232 \def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
233   \removelastskip\penalty-200\bigskip\fi\fi}
234
235 %\f Output routine
236 %
237
238 % For a final copy, take out the rectangles
239 % that mark overfull boxes (in case you have decided
240 % that the text looks ok even though it passes the margin).
241 %
242 \def\finalout{\overfullrule=0pt }
243
244 % Do @cropmarks to get crop marks.
245 %
246 \newif\ifcropmarks
247 \let\cropmarks = \cropmarkstrue
248 %
249 % Dimensions to add cropmarks at corners.
250 % Added by P. A. MacKay, 12 Nov. 1986
251 %
252 \newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
253 \newdimen\cornerlong  \cornerlong=1pc
254 \newdimen\cornerthick \cornerthick=.3pt
255 \newdimen\topandbottommargin \topandbottommargin=.75in
256
257 % Output a mark which sets \thischapter, \thissection and \thiscolor.
258 % We dump everything together because we only have one kind of mark.
259 % This works because we only use \botmark / \topmark, not \firstmark.
260 %
261 % A mark contains a subexpression of the \ifcase ... \fi construct.
262 % \get*marks macros below extract the needed part using \ifcase.
263 %
264 % Another complication is to let the user choose whether \thischapter
265 % (\thissection) refers to the chapter (section) in effect at the top
266 % of a page, or that at the bottom of a page.
267
268 % \domark is called twice inside \chapmacro, to add one
269 % mark before the section break, and one after.
270 %   In the second call \prevchapterdefs is the same as \lastchapterdefs,
271 % and \prevsectiondefs is the same as \lastsectiondefs.
272 %   Then if the page is not broken at the mark, some of the previous
273 % section appears on the page, and we can get the name of this section
274 % from \firstmark for @everyheadingmarks top.
275 %   @everyheadingmarks bottom uses \botmark.
276 %
277 % See page 260 of The TeXbook.
278 \def\domark{%
279   \toks0=\expandafter{\lastchapterdefs}%
280   \toks2=\expandafter{\lastsectiondefs}%
281   \toks4=\expandafter{\prevchapterdefs}%
282   \toks6=\expandafter{\prevsectiondefs}%
283   \toks8=\expandafter{\lastcolordefs}%
284   \mark{%
285                    \the\toks0 \the\toks2  % 0: marks for @everyheadingmarks top
286       \noexpand\or \the\toks4 \the\toks6  % 1: for @everyheadingmarks bottom
287     \noexpand\else \the\toks8             % 2: color marks
288   }%
289 }
290
291 % \gettopheadingmarks, \getbottomheadingmarks,
292 % \getcolormarks - extract needed part of mark.
293 %
294 % \topmark doesn't work for the very first chapter (after the title
295 % page or the contents), so we use \firstmark there -- this gets us
296 % the mark with the chapter defs, unless the user sneaks in, e.g.,
297 % @setcolor (or @url, or @link, etc.) between @contents and the very
298 % first @chapter.
299 \def\gettopheadingmarks{%
300   \ifcase0\topmark\fi
301   \ifx\thischapter\empty \ifcase0\firstmark\fi \fi
302 }
303 \def\getbottomheadingmarks{\ifcase1\botmark\fi}
304 \def\getcolormarks{\ifcase2\topmark\fi}
305
306 % Avoid "undefined control sequence" errors.
307 \def\lastchapterdefs{}
308 \def\lastsectiondefs{}
309 \def\lastsection{}
310 \def\prevchapterdefs{}
311 \def\prevsectiondefs{}
312 \def\lastcolordefs{}
313
314 % Margin to add to right of even pages, to left of odd pages.
315 \newdimen\bindingoffset
316 \newdimen\normaloffset
317 \newdimen\txipagewidth \newdimen\txipageheight
318
319 % Main output routine.
320 %
321 \chardef\PAGE = 255
322 \output = {\onepageout{\pagecontents\PAGE}}
323
324 \newbox\headlinebox
325 \newbox\footlinebox
326
327 % \onepageout takes a vbox as an argument.
328 % \shipout a vbox for a single page, adding an optional header, footer,
329 % cropmarks, and footnote.  This also causes index entries for this page
330 % to be written to the auxiliary files.
331 %
332 \def\onepageout#1{%
333   \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
334   %
335   \ifodd\pageno  \advance\hoffset by \bindingoffset
336   \else \advance\hoffset by -\bindingoffset\fi
337   %
338   % Common context changes for both heading and footing.
339   % Do this outside of the \shipout so @code etc. will be expanded in
340   % the headline as they should be, not taken literally (outputting ''code).
341   \def\commmonheadfootline{\let\hsize=\txipagewidth \texinfochars}
342   %
343   % Retrieve the information for the headings from the marks in the page,
344   % and call Plain TeX's \makeheadline and \makefootline, which use the
345   % values in \headline and \footline.
346   %
347   % This is used to check if we are on the first page of a chapter.
348   \ifcase1\topmark\fi
349   \let\prevchaptername\thischaptername
350   \ifcase0\firstmark\fi
351   \let\curchaptername\thischaptername
352   %
353   \ifodd\pageno \getoddheadingmarks \else \getevenheadingmarks \fi
354   \ifodd\pageno \getoddfootingmarks \else \getevenfootingmarks \fi
355   %
356   \ifx\curchaptername\prevchaptername
357     \let\thischapterheading\thischapter
358   \else
359     % \thischapterheading is the same as \thischapter except it is blank
360     % for the first page of a chapter.  This is to prevent the chapter name 
361     % being shown twice.
362     \def\thischapterheading{}%
363   \fi
364   %
365   \global\setbox\headlinebox = \vbox{\commmonheadfootline \makeheadline}%
366   \global\setbox\footlinebox = \vbox{\commmonheadfootline \makefootline}%
367   %
368   {%
369     % Set context for writing to auxiliary files like index files.
370     % Have to do this stuff outside the \shipout because we want it to
371     % take effect in \write's, yet the group defined by the \vbox ends
372     % before the \shipout runs.
373     %
374     \indexdummies         % don't expand commands in the output.
375     \normalturnoffactive  % \ in index entries must not stay \, e.g., if
376                % the page break happens to be in the middle of an example.
377                % We don't want .vr (or whatever) entries like this:
378                % \entry{{\indexbackslash }acronym}{32}{\code {\acronym}}
379                % "\acronym" won't work when it's read back in;
380                % it needs to be
381                % {\code {{\backslashcurfont }acronym}
382     \shipout\vbox{%
383       % Do this early so pdf references go to the beginning of the page.
384       \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
385       %
386       \ifcropmarks \vbox to \outervsize\bgroup
387         \hsize = \outerhsize
388         \vskip-\topandbottommargin
389         \vtop to0pt{%
390           \line{\ewtop\hfil\ewtop}%
391           \nointerlineskip
392           \line{%
393             \vbox{\moveleft\cornerthick\nstop}%
394             \hfill
395             \vbox{\moveright\cornerthick\nstop}%
396           }%
397           \vss}%
398         \vskip\topandbottommargin
399         \line\bgroup
400           \hfil % center the page within the outer (page) hsize.
401           \ifodd\pageno\hskip\bindingoffset\fi
402           \vbox\bgroup
403       \fi
404       %
405       \unvbox\headlinebox
406       \pagebody{#1}%
407       \ifdim\ht\footlinebox > 0pt
408         % Only leave this space if the footline is nonempty.
409         % (We lessened \vsize for it in \oddfootingyyy.)
410         % The \baselineskip=24pt in plain's \makefootline has no effect.
411         \vskip 24pt
412         \unvbox\footlinebox
413       \fi
414       %
415       \ifcropmarks
416           \egroup % end of \vbox\bgroup
417         \hfil\egroup % end of (centering) \line\bgroup
418         \vskip\topandbottommargin plus1fill minus1fill
419         \boxmaxdepth = \cornerthick
420         \vbox to0pt{\vss
421           \line{%
422             \vbox{\moveleft\cornerthick\nsbot}%
423             \hfill
424             \vbox{\moveright\cornerthick\nsbot}%
425           }%
426           \nointerlineskip
427           \line{\ewbot\hfil\ewbot}%
428         }%
429       \egroup % \vbox from first cropmarks clause
430       \fi
431     }% end of \shipout\vbox
432   }% end of group with \indexdummies
433   \advancepageno
434   \ifnum\outputpenalty>-20000 \else\dosupereject\fi
435 }
436
437 \newinsert\margin \dimen\margin=\maxdimen
438
439 % Main part of page, including any footnotes
440 \def\pagebody#1{\vbox to\txipageheight{\boxmaxdepth=\maxdepth #1}}
441 {\catcode`\@ =11
442 \gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
443 % marginal hacks, juha@viisa.uucp (Juha Takala)
444 \ifvoid\margin\else % marginal info is present
445   \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
446 \dimen@=\dp#1\relax \unvbox#1\relax
447 \ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
448 \ifr@ggedbottom \kern-\dimen@ \vfil \fi}
449 }
450
451 % Here are the rules for the cropmarks.  Note that they are
452 % offset so that the space between them is truly \outerhsize or \outervsize
453 % (P. A. MacKay, 12 November, 1986)
454 %
455 \def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
456 \def\nstop{\vbox
457   {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
458 \def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
459 \def\nsbot{\vbox
460   {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
461
462
463 % Argument parsing
464
465 % Parse an argument, then pass it to #1.  The argument is the rest of
466 % the input line (except we remove a trailing comment).  #1 should be a
467 % macro which expects an ordinary undelimited TeX argument.
468 % For example, \def\foo{\parsearg\fooxxx}.
469 %
470 \def\parsearg{\parseargusing{}}
471 \def\parseargusing#1#2{%
472   \def\argtorun{#2}%
473   \begingroup
474     \obeylines
475     \spaceisspace
476     #1%
477     \parseargline\empty% Insert the \empty token, see \finishparsearg below.
478 }
479
480 {\obeylines %
481   \gdef\parseargline#1^^M{%
482     \endgroup % End of the group started in \parsearg.
483     \argremovecomment #1\comment\ArgTerm%
484   }%
485 }
486
487 % First remove any @comment, then any @c comment.  Also remove a @texinfoc
488 % comment (see \scanmacro for details).  Pass the result on to \argcheckspaces.
489 \def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
490 \def\argremovec#1\c#2\ArgTerm{\argremovetexinfoc #1\texinfoc\ArgTerm}
491 \def\argremovetexinfoc#1\texinfoc#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
492
493 % Each occurrence of `\^^M' or `<space>\^^M' is replaced by a single space.
494 %
495 % \argremovec might leave us with trailing space, e.g.,
496 %    @end itemize  @c foo
497 % This space token undergoes the same procedure and is eventually removed
498 % by \finishparsearg.
499 %
500 \def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
501 \def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
502 \def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
503   \def\temp{#3}%
504   \ifx\temp\empty
505     % Do not use \next, perhaps the caller of \parsearg uses it; reuse \temp:
506     \let\temp\finishparsearg
507   \else
508     \let\temp\argcheckspaces
509   \fi
510   % Put the space token in:
511   \temp#1 #3\ArgTerm
512 }
513
514 % If a _delimited_ argument is enclosed in braces, they get stripped; so
515 % to get _exactly_ the rest of the line, we had to prevent such situation.
516 % We prepended an \empty token at the very beginning and we expand it now,
517 % just before passing the control to \argtorun.
518 % (Similarly, we have to think about #3 of \argcheckspacesY above: it is
519 % either the null string, or it ends with \^^M---thus there is no danger
520 % that a pair of braces would be stripped.
521 %
522 % But first, we have to remove the trailing space token.
523 %
524 \def\finishparsearg#1 \ArgTerm{\expandafter\argtorun\expandafter{#1}}
525
526
527 % \parseargdef - define a command taking an argument on the line
528 %
529 % \parseargdef\foo{...}
530 %       is roughly equivalent to
531 % \def\foo{\parsearg\Xfoo}
532 % \def\Xfoo#1{...}
533 \def\parseargdef#1{%
534   \expandafter \doparseargdef \csname\string#1\endcsname #1%
535 }
536 \def\doparseargdef#1#2{%
537   \def#2{\parsearg#1}%
538   \def#1##1%
539 }
540
541 % Several utility definitions with active space:
542 {
543   \obeyspaces
544   \gdef\obeyedspace{ }
545
546   % Make each space character in the input produce a normal interword
547   % space in the output.  Don't allow a line break at this space, as this
548   % is used only in environments like @example, where each line of input
549   % should produce a line of output anyway.
550   %
551   \gdef\sepspaces{\obeyspaces\let =\tie}
552
553   % If an index command is used in an @example environment, any spaces
554   % therein should become regular spaces in the raw index file, not the
555   % expansion of \tie (\leavevmode \penalty \@M \ ).
556   \gdef\unsepspaces{\let =\space}
557 }
558
559
560 \def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
561
562 % Define the framework for environments in texinfo.tex.  It's used like this:
563 %
564 %   \envdef\foo{...}
565 %   \def\Efoo{...}
566 %
567 % It's the responsibility of \envdef to insert \begingroup before the
568 % actual body; @end closes the group after calling \Efoo.  \envdef also
569 % defines \thisenv, so the current environment is known; @end checks
570 % whether the environment name matches.  The \checkenv macro can also be
571 % used to check whether the current environment is the one expected.
572 %
573 % Non-false conditionals (@iftex, @ifset) don't fit into this, so they
574 % are not treated as environments; they don't open a group.  (The
575 % implementation of @end takes care not to call \endgroup in this
576 % special case.)
577
578
579 % At run-time, environments start with this:
580 \def\startenvironment#1{\begingroup\def\thisenv{#1}}
581 % initialize
582 \let\thisenv\empty
583
584 % ... but they get defined via ``\envdef\foo{...}'':
585 \long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
586 \def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
587
588 % Check whether we're in the right environment:
589 \def\checkenv#1{%
590   \def\temp{#1}%
591   \ifx\thisenv\temp
592   \else
593     \badenverr
594   \fi
595 }
596
597 % Environment mismatch, #1 expected:
598 \def\badenverr{%
599   \errhelp = \EMsimple
600   \errmessage{This command can appear only \inenvironment\temp,
601     not \inenvironment\thisenv}%
602 }
603 \def\inenvironment#1{%
604   \ifx#1\empty
605     outside of any environment%
606   \else
607     in environment \expandafter\string#1%
608   \fi
609 }
610
611 % @end foo executes the definition of \Efoo.
612 % But first, it executes a specialized version of \checkenv
613 %
614 \parseargdef\end{%
615   \if 1\csname iscond.#1\endcsname
616   \else
617     % The general wording of \badenverr may not be ideal.
618     \expandafter\checkenv\csname#1\endcsname
619     \csname E#1\endcsname
620     \endgroup
621   \fi
622 }
623
624 \newhelp\EMsimple{Press RETURN to continue.}
625
626
627 % Be sure we're in horizontal mode when doing a tie, since we make space
628 % equivalent to this in @example-like environments. Otherwise, a space
629 % at the beginning of a line will start with \penalty -- and
630 % since \penalty is valid in vertical mode, we'd end up putting the
631 % penalty on the vertical list instead of in the new paragraph.
632 {\catcode`@ = 11
633  % Avoid using \@M directly, because that causes trouble
634  % if the definition is written into an index file.
635  \global\let\tiepenalty = \@M
636  \gdef\tie{\leavevmode\penalty\tiepenalty\ }
637 }
638
639 % @: forces normal size whitespace following.
640 \def\:{\spacefactor=1000 }
641
642 % @* forces a line break.
643 \def\*{\unskip\hfil\break\hbox{}\ignorespaces}
644
645 % @/ allows a line break.
646 \let\/=\allowbreak
647
648 % @. is an end-of-sentence period.
649 \def\.{.\spacefactor=\endofsentencespacefactor\space}
650
651 % @! is an end-of-sentence bang.
652 \def\!{!\spacefactor=\endofsentencespacefactor\space}
653
654 % @? is an end-of-sentence query.
655 \def\?{?\spacefactor=\endofsentencespacefactor\space}
656
657 % @frenchspacing on|off  says whether to put extra space after punctuation.
658 %
659 \def\onword{on}
660 \def\offword{off}
661 %
662 \parseargdef\frenchspacing{%
663   \def\temp{#1}%
664   \ifx\temp\onword \plainfrenchspacing
665   \else\ifx\temp\offword \plainnonfrenchspacing
666   \else
667     \errhelp = \EMsimple
668     \errmessage{Unknown @frenchspacing option `\temp', must be on|off}%
669   \fi\fi
670 }
671
672 % @w prevents a word break.  Without the \leavevmode, @w at the
673 % beginning of a paragraph, when TeX is still in vertical mode, would
674 % produce a whole line of output instead of starting the paragraph.
675 \def\w#1{\leavevmode\hbox{#1}}
676
677 % @group ... @end group forces ... to be all on one page, by enclosing
678 % it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
679 % to keep its height that of a normal line.  According to the rules for
680 % \topskip (p.114 of the TeXbook), the glue inserted is
681 % max (\topskip - \ht (first item), 0).  If that height is large,
682 % therefore, no glue is inserted, and the space between the headline and
683 % the text is small, which looks bad.
684 %
685 % Another complication is that the group might be very large.  This can
686 % cause the glue on the previous page to be unduly stretched, because it
687 % does not have much material.  In this case, it's better to add an
688 % explicit \vfill so that the extra space is at the bottom.  The
689 % threshold for doing this is if the group is more than \vfilllimit
690 % percent of a page (\vfilllimit can be changed inside of @tex).
691 %
692 \newbox\groupbox
693 \def\vfilllimit{0.7}
694 %
695 \envdef\group{%
696   \ifnum\catcode`\^^M=\active \else
697     \errhelp = \groupinvalidhelp
698     \errmessage{@group invalid in context where filling is enabled}%
699   \fi
700   \startsavinginserts
701   %
702   \setbox\groupbox = \vtop\bgroup
703     % Do @comment since we are called inside an environment such as
704     % @example, where each end-of-line in the input causes an
705     % end-of-line in the output.  We don't want the end-of-line after
706     % the `@group' to put extra space in the output.  Since @group
707     % should appear on a line by itself (according to the Texinfo
708     % manual), we don't worry about eating any user text.
709     \comment
710 }
711 %
712 % The \vtop produces a box with normal height and large depth; thus, TeX puts
713 % \baselineskip glue before it, and (when the next line of text is done)
714 % \lineskip glue after it.  Thus, space below is not quite equal to space
715 % above.  But it's pretty close.
716 \def\Egroup{%
717     % To get correct interline space between the last line of the group
718     % and the first line afterwards, we have to propagate \prevdepth.
719     \endgraf % Not \par, as it may have been set to \lisppar.
720     \global\dimen1 = \prevdepth
721   \egroup           % End the \vtop.
722   \addgroupbox
723   \prevdepth = \dimen1
724   \checkinserts
725 }
726
727 \def\addgroupbox{
728   % \dimen0 is the vertical size of the group's box.
729   \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
730   % \dimen2 is how much space is left on the page (more or less).
731   \dimen2 = \txipageheight   \advance\dimen2 by -\pagetotal
732   % if the group doesn't fit on the current page, and it's a big big
733   % group, force a page break.
734   \ifdim \dimen0 > \dimen2
735     \ifdim \pagetotal < \vfilllimit\txipageheight
736       \page
737     \fi
738   \fi
739   \box\groupbox
740 }
741
742 %
743 % TeX puts in an \escapechar (i.e., `@') at the beginning of the help
744 % message, so this ends up printing `@group can only ...'.
745 %
746 \newhelp\groupinvalidhelp{%
747 group can only be used in environments such as @example,^^J%
748 where each line of input produces a line of output.}
749
750 % @need space-in-mils
751 % forces a page break if there is not space-in-mils remaining.
752
753 \newdimen\mil  \mil=0.001in
754
755 \parseargdef\need{%
756   % Ensure vertical mode, so we don't make a big box in the middle of a
757   % paragraph.
758   \par
759   %
760   % If the @need value is less than one line space, it's useless.
761   \dimen0 = #1\mil
762   \dimen2 = \ht\strutbox
763   \advance\dimen2 by \dp\strutbox
764   \ifdim\dimen0 > \dimen2
765     %
766     % Do a \strut just to make the height of this box be normal, so the
767     % normal leading is inserted relative to the preceding line.
768     % And a page break here is fine.
769     \vtop to #1\mil{\strut\vfil}%
770     %
771     % TeX does not even consider page breaks if a penalty added to the
772     % main vertical list is 10000 or more.  But in order to see if the
773     % empty box we just added fits on the page, we must make it consider
774     % page breaks.  On the other hand, we don't want to actually break the
775     % page after the empty box.  So we use a penalty of 9999.
776     %
777     % There is an extremely small chance that TeX will actually break the
778     % page at this \penalty, if there are no other feasible breakpoints in
779     % sight.  (If the user is using lots of big @group commands, which
780     % almost-but-not-quite fill up a page, TeX will have a hard time doing
781     % good page breaking, for example.)  However, I could not construct an
782     % example where a page broke at this \penalty; if it happens in a real
783     % document, then we can reconsider our strategy.
784     \penalty9999
785     %
786     % Back up by the size of the box, whether we did a page break or not.
787     \kern -#1\mil
788     %
789     % Do not allow a page break right after this kern.
790     \nobreak
791   \fi
792 }
793
794 % @br   forces paragraph break (and is undocumented).
795
796 \let\br = \par
797
798 % @page forces the start of a new page.
799 %
800 \def\page{\par\vfill\supereject}
801
802 % @exdent text....
803 % outputs text on separate line in roman font, starting at standard page margin
804
805 % This records the amount of indent in the innermost environment.
806 % That's how much \exdent should take out.
807 \newskip\exdentamount
808
809 % This defn is used inside fill environments such as @defun.
810 \parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
811
812 % This defn is used inside nofill environments such as @example.
813 \parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
814   \leftline{\hskip\leftskip{\rm#1}}}}
815
816 % @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
817 % paragraph.  For more general purposes, use the \margin insertion
818 % class.  WHICH is `l' or `r'.  Not documented, written for gawk manual.
819 %
820 \newskip\inmarginspacing \inmarginspacing=1cm
821 \def\strutdepth{\dp\strutbox}
822 %
823 \def\doinmargin#1#2{\strut\vadjust{%
824   \nobreak
825   \kern-\strutdepth
826   \vtop to \strutdepth{%
827     \baselineskip=\strutdepth
828     \vss
829     % if you have multiple lines of stuff to put here, you'll need to
830     % make the vbox yourself of the appropriate size.
831     \ifx#1l%
832       \llap{\ignorespaces #2\hskip\inmarginspacing}%
833     \else
834       \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
835     \fi
836     \null
837   }%
838 }}
839 \def\inleftmargin{\doinmargin l}
840 \def\inrightmargin{\doinmargin r}
841 %
842 % @inmargin{TEXT [, RIGHT-TEXT]}
843 % (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
844 % else use TEXT for both).
845 %
846 \def\inmargin#1{\parseinmargin #1,,\finish}
847 \def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
848   \setbox0 = \hbox{\ignorespaces #2}%
849   \ifdim\wd0 > 0pt
850     \def\lefttext{#1}%  have both texts
851     \def\righttext{#2}%
852   \else
853     \def\lefttext{#1}%  have only one text
854     \def\righttext{#1}%
855   \fi
856   %
857   \ifodd\pageno
858     \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
859   \else
860     \def\temp{\inleftmargin\lefttext}%
861   \fi
862   \temp
863 }
864
865 % @| inserts a changebar to the left of the current line.  It should
866 % surround any changed text.  This approach does *not* work if the
867 % change spans more than two lines of output.  To handle that, we would
868 % have adopt a much more difficult approach (putting marks into the main
869 % vertical list for the beginning and end of each change).  This command
870 % is not documented, not supported, and doesn't work.
871 %
872 \def\|{%
873   % \vadjust can only be used in horizontal mode.
874   \leavevmode
875   %
876   % Append this vertical mode material after the current line in the output.
877   \vadjust{%
878     % We want to insert a rule with the height and depth of the current
879     % leading; that is exactly what \strutbox is supposed to record.
880     \vskip-\baselineskip
881     %
882     % \vadjust-items are inserted at the left edge of the type.  So
883     % the \llap here moves out into the left-hand margin.
884     \llap{%
885       %
886       % For a thicker or thinner bar, change the `1pt'.
887       \vrule height\baselineskip width1pt
888       %
889       % This is the space between the bar and the text.
890       \hskip 12pt
891     }%
892   }%
893 }
894
895 % @include FILE -- \input text of FILE.
896 %
897 \def\include{\parseargusing\filenamecatcodes\includezzz}
898 \def\includezzz#1{%
899   \pushthisfilestack
900   \def\thisfile{#1}%
901   {%
902     \makevalueexpandable  % we want to expand any @value in FILE.
903     \turnoffactive        % and allow special characters in the expansion
904     \indexnofonts         % Allow `@@' and other weird things in file names.
905     \wlog{texinfo.tex: doing @include of #1^^J}%
906     \edef\temp{\noexpand\input #1 }%
907     %
908     % This trickery is to read FILE outside of a group, in case it makes
909     % definitions, etc.
910     \expandafter
911   }\temp
912   \popthisfilestack
913 }
914 \def\filenamecatcodes{%
915   \catcode`\\=\other
916   \catcode`~=\other
917   \catcode`^=\other
918   \catcode`_=\other
919   \catcode`|=\other
920   \catcode`<=\other
921   \catcode`>=\other
922   \catcode`+=\other
923   \catcode`-=\other
924   \catcode`\`=\other
925   \catcode`\'=\other
926 }
927
928 \def\pushthisfilestack{%
929   \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
930 }
931 \def\pushthisfilestackX{%
932   \expandafter\pushthisfilestackY\thisfile\StackTerm
933 }
934 \def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
935   \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
936 }
937
938 \def\popthisfilestack{\errthisfilestackempty}
939 \def\errthisfilestackempty{\errmessage{Internal error:
940   the stack of filenames is empty.}}
941 %
942 \def\thisfile{}
943
944 % @center line
945 % outputs that line, centered.
946 %
947 \parseargdef\center{%
948   \ifhmode
949     \let\centersub\centerH
950   \else
951     \let\centersub\centerV
952   \fi
953   \centersub{\hfil \ignorespaces#1\unskip \hfil}%
954   \let\centersub\relax % don't let the definition persist, just in case
955 }
956 \def\centerH#1{{%
957   \hfil\break
958   \advance\hsize by -\leftskip
959   \advance\hsize by -\rightskip
960   \line{#1}%
961   \break
962 }}
963 %
964 \newcount\centerpenalty
965 \def\centerV#1{%
966   % The idea here is the same as in \startdefun, \cartouche, etc.: if
967   % @center is the first thing after a section heading, we need to wipe
968   % out the negative parskip inserted by \sectionheading, but still
969   % prevent a page break here.
970   \centerpenalty = \lastpenalty
971   \ifnum\centerpenalty>10000 \vskip\parskip \fi
972   \ifnum\centerpenalty>9999 \penalty\centerpenalty \fi
973   \line{\kern\leftskip #1\kern\rightskip}%
974 }
975
976 % @sp n   outputs n lines of vertical space
977 %
978 \parseargdef\sp{\vskip #1\baselineskip}
979
980 % @comment ...line which is ignored...
981 % @c is the same as @comment
982 % @ignore ... @end ignore  is another way to write a comment
983 %
984 \def\comment{\begingroup \catcode`\^^M=\active%
985 \catcode`\@=\other \catcode`\{=\other \catcode`\}=\other\commentxxx}%
986
987 {\catcode`\^^M=\active%
988 \gdef\commentxxx#1^^M{\endgroup%
989 \futurelet\nexttoken\commentxxxx}%
990 \gdef\commentxxxx{\ifx\nexttoken\aftermacro\expandafter\comment\fi}%
991 }
992
993 \def\c{\begingroup \catcode`\^^M=\active%
994 \catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
995 \cxxx}
996 {\catcode`\^^M=\active \gdef\cxxx#1^^M{\endgroup}}
997 % See comment in \scanmacro about why the definitions of @c and @comment differ
998
999 % @paragraphindent NCHARS
1000 % We'll use ems for NCHARS, close enough.
1001 % NCHARS can also be the word `asis' or `none'.
1002 % We cannot feasibly implement @paragraphindent asis, though.
1003 %
1004 \def\asisword{asis} % no translation, these are keywords
1005 \def\noneword{none}
1006 %
1007 \parseargdef\paragraphindent{%
1008   \def\temp{#1}%
1009   \ifx\temp\asisword
1010   \else
1011     \ifx\temp\noneword
1012       \defaultparindent = 0pt
1013     \else
1014       \defaultparindent = #1em
1015     \fi
1016   \fi
1017   \parindent = \defaultparindent
1018 }
1019
1020 % @exampleindent NCHARS
1021 % We'll use ems for NCHARS like @paragraphindent.
1022 % It seems @exampleindent asis isn't necessary, but
1023 % I preserve it to make it similar to @paragraphindent.
1024 \parseargdef\exampleindent{%
1025   \def\temp{#1}%
1026   \ifx\temp\asisword
1027   \else
1028     \ifx\temp\noneword
1029       \lispnarrowing = 0pt
1030     \else
1031       \lispnarrowing = #1em
1032     \fi
1033   \fi
1034 }
1035
1036 % @firstparagraphindent WORD
1037 % If WORD is `none', then suppress indentation of the first paragraph
1038 % after a section heading.  If WORD is `insert', then do indent at such
1039 % paragraphs.
1040 %
1041 % The paragraph indentation is suppressed or not by calling
1042 % \suppressfirstparagraphindent, which the sectioning commands do.
1043 % We switch the definition of this back and forth according to WORD.
1044 % By default, we suppress indentation.
1045 %
1046 \def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
1047 \def\insertword{insert}
1048 %
1049 \parseargdef\firstparagraphindent{%
1050   \def\temp{#1}%
1051   \ifx\temp\noneword
1052     \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
1053   \else\ifx\temp\insertword
1054     \let\suppressfirstparagraphindent = \relax
1055   \else
1056     \errhelp = \EMsimple
1057     \errmessage{Unknown @firstparagraphindent option `\temp'}%
1058   \fi\fi
1059 }
1060
1061 % Here is how we actually suppress indentation.  Redefine \everypar to
1062 % \kern backwards by \parindent, and then reset itself to empty.
1063 %
1064 % We also make \indent itself not actually do anything until the next
1065 % paragraph.
1066 %
1067 \gdef\dosuppressfirstparagraphindent{%
1068   \gdef\indent  {\restorefirstparagraphindent \indent}%
1069   \gdef\noindent{\restorefirstparagraphindent \noindent}%
1070   \global\everypar = {\kern -\parindent \restorefirstparagraphindent}%
1071 }
1072 %
1073 \gdef\restorefirstparagraphindent{%
1074   \global\let\indent = \ptexindent
1075   \global\let\noindent = \ptexnoindent
1076   \global\everypar = {}%
1077 }
1078
1079
1080 % @refill is a no-op.
1081 \let\refill=\relax
1082
1083 % @setfilename INFO-FILENAME - ignored
1084 \let\setfilename=\comment
1085
1086 % @bye.
1087 \outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
1088
1089
1090 \message{pdf,}
1091 % adobe `portable' document format
1092 \newcount\tempnum
1093 \newcount\lnkcount
1094 \newtoks\filename
1095 \newcount\filenamelength
1096 \newcount\pgn
1097 \newtoks\toksA
1098 \newtoks\toksB
1099 \newtoks\toksC
1100 \newtoks\toksD
1101 \newbox\boxA
1102 \newbox\boxB
1103 \newcount\countA
1104 \newif\ifpdf
1105 \newif\ifpdfmakepagedest
1106
1107 %
1108 % For LuaTeX
1109 %
1110
1111 \ifx\luatexversion\thisisundefined
1112 \else
1113   % Escape PDF strings UTF-8 to UTF-16
1114   \begingroup
1115     \catcode`\%=12
1116     \directlua{
1117       function UTF16oct(str)
1118         tex.sprint(string.char(0x5c) .. '376' .. string.char(0x5c) .. '377')
1119         for c in string.utfvalues(str) do
1120           if c < 0x10000 then
1121             tex.sprint(
1122               string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
1123                             string.char(0x5c) .. string.char(0x25) .. '03o',
1124                             (c / 256), (c % 256)))
1125           else
1126             c = c - 0x10000
1127             local c_hi = c / 1024 + 0xd800
1128             local c_lo = c % 1024 + 0xdc00
1129             tex.sprint(
1130               string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
1131                             string.char(0x5c) .. string.char(0x25) .. '03o' ..
1132                             string.char(0x5c) .. string.char(0x25) .. '03o' ..
1133                             string.char(0x5c) .. string.char(0x25) .. '03o',
1134                             (c_hi / 256), (c_hi % 256),
1135                             (c_lo / 256), (c_lo % 256)))
1136           end
1137         end
1138       end
1139     }
1140   \endgroup
1141   \def\pdfescapestring#1{\directlua{UTF16oct('\luaescapestring{#1}')}}
1142   \ifnum\luatexversion>84
1143     % For LuaTeX >= 0.85
1144     \def\pdfdest{\pdfextension dest}
1145     \let\pdfoutput\outputmode
1146     \def\pdfliteral{\pdfextension literal}
1147     \def\pdfcatalog{\pdfextension catalog}
1148     \def\pdftexversion{\numexpr\pdffeedback version\relax}
1149     \let\pdfximage\saveimageresource
1150     \let\pdfrefximage\useimageresource
1151     \let\pdflastximage\lastsavedimageresourceindex
1152     \def\pdfendlink{\pdfextension endlink\relax}
1153     \def\pdfoutline{\pdfextension outline}
1154     \def\pdfstartlink{\pdfextension startlink}
1155     \def\pdffontattr{\pdfextension fontattr}
1156     \def\pdfobj{\pdfextension obj}
1157     \def\pdflastobj{\numexpr\pdffeedback lastobj\relax}
1158     \let\pdfpagewidth\pagewidth
1159     \let\pdfpageheight\pageheight
1160     \edef\pdfhorigin{\pdfvariable horigin}
1161     \edef\pdfvorigin{\pdfvariable vorigin}
1162   \fi
1163 \fi
1164
1165 % when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
1166 % can be set).  So we test for \relax and 0 as well as being undefined.
1167 \ifx\pdfoutput\thisisundefined
1168 \else
1169   \ifx\pdfoutput\relax
1170   \else
1171     \ifcase\pdfoutput
1172     \else
1173       \pdftrue
1174     \fi
1175   \fi
1176 \fi
1177
1178 % PDF uses PostScript string constants for the names of xref targets,
1179 % for display in the outlines, and in other places.  Thus, we have to
1180 % double any backslashes.  Otherwise, a name like "\node" will be
1181 % interpreted as a newline (\n), followed by o, d, e.  Not good.
1182
1183 % See http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html and
1184 % related messages.  The final outcome is that it is up to the TeX user
1185 % to double the backslashes and otherwise make the string valid, so
1186 % that's what we do.  pdftex 1.30.0 (ca.2005) introduced a primitive to
1187 % do this reliably, so we use it.
1188
1189 % #1 is a control sequence in which to do the replacements,
1190 % which we \xdef.
1191 \def\txiescapepdf#1{%
1192   \ifx\pdfescapestring\thisisundefined
1193     % No primitive available; should we give a warning or log?
1194     % Many times it won't matter.
1195   \else
1196     % The expandable \pdfescapestring primitive escapes parentheses,
1197     % backslashes, and other special chars.
1198     \xdef#1{\pdfescapestring{#1}}%
1199   \fi
1200 }
1201
1202 \newhelp\nopdfimagehelp{Texinfo supports .png, .jpg, .jpeg, and .pdf images
1203 with PDF output, and none of those formats could be found.  (.eps cannot
1204 be supported due to the design of the PDF format; use regular TeX (DVI
1205 output) for that.)}
1206
1207 \ifpdf
1208   %
1209   % Color manipulation macros using ideas from pdfcolor.tex,
1210   % except using rgb instead of cmyk; the latter is said to render as a
1211   % very dark gray on-screen and a very dark halftone in print, instead
1212   % of actual black. The dark red here is dark enough to print on paper as
1213   % nearly black, but still distinguishable for online viewing.  We use
1214   % black by default, though.
1215   \def\rgbDarkRed{0.50 0.09 0.12}
1216   \def\rgbBlack{0 0 0}
1217   %
1218   % rg sets the color for filling (usual text, etc.);
1219   % RG sets the color for stroking (thin rules, e.g., normal _'s).
1220   \def\pdfsetcolor#1{\pdfliteral{#1 rg  #1 RG}}
1221   %
1222   % Set color, and create a mark which defines \thiscolor accordingly,
1223   % so that \makeheadline knows which color to restore.
1224   \def\setcolor#1{%
1225     \xdef\lastcolordefs{\gdef\noexpand\thiscolor{#1}}%
1226     \domark
1227     \pdfsetcolor{#1}%
1228   }
1229   %
1230   \def\maincolor{\rgbBlack}
1231   \pdfsetcolor{\maincolor}
1232   \edef\thiscolor{\maincolor}
1233   \def\lastcolordefs{}
1234   %
1235   \def\makefootline{%
1236     \baselineskip24pt
1237     \line{\pdfsetcolor{\maincolor}\the\footline}%
1238   }
1239   %
1240   \def\makeheadline{%
1241     \vbox to 0pt{%
1242       \vskip-22.5pt
1243       \line{%
1244         \vbox to8.5pt{}%
1245         % Extract \thiscolor definition from the marks.
1246         \getcolormarks
1247         % Typeset the headline with \maincolor, then restore the color.
1248         \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
1249       }%
1250       \vss
1251     }%
1252     \nointerlineskip
1253   }
1254   %
1255   %
1256   \pdfcatalog{/PageMode /UseOutlines}
1257   %
1258   % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1259   \def\dopdfimage#1#2#3{%
1260     \def\pdfimagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1261     \def\pdfimageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1262     %
1263     % pdftex (and the PDF format) support .pdf, .png, .jpg (among
1264     % others).  Let's try in that order, PDF first since if
1265     % someone has a scalable image, presumably better to use that than a
1266     % bitmap.
1267     \let\pdfimgext=\empty
1268     \begingroup
1269       \openin 1 #1.pdf \ifeof 1
1270         \openin 1 #1.PDF \ifeof 1
1271           \openin 1 #1.png \ifeof 1
1272             \openin 1 #1.jpg \ifeof 1
1273               \openin 1 #1.jpeg \ifeof 1
1274                 \openin 1 #1.JPG \ifeof 1
1275                   \errhelp = \nopdfimagehelp
1276                   \errmessage{Could not find image file #1 for pdf}%
1277                 \else \gdef\pdfimgext{JPG}%
1278                 \fi
1279               \else \gdef\pdfimgext{jpeg}%
1280               \fi
1281             \else \gdef\pdfimgext{jpg}%
1282             \fi
1283           \else \gdef\pdfimgext{png}%
1284           \fi
1285         \else \gdef\pdfimgext{PDF}%
1286         \fi
1287       \else \gdef\pdfimgext{pdf}%
1288       \fi
1289       \closein 1
1290     \endgroup
1291     %
1292     % without \immediate, ancient pdftex seg faults when the same image is
1293     % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
1294     \ifnum\pdftexversion < 14
1295       \immediate\pdfimage
1296     \else
1297       \immediate\pdfximage
1298     \fi
1299       \ifdim \wd0 >0pt width \pdfimagewidth \fi
1300       \ifdim \wd2 >0pt height \pdfimageheight \fi
1301       \ifnum\pdftexversion<13
1302          #1.\pdfimgext
1303        \else
1304          {#1.\pdfimgext}%
1305        \fi
1306     \ifnum\pdftexversion < 14 \else
1307       \pdfrefximage \pdflastximage
1308     \fi}
1309   %
1310   \def\pdfmkdest#1{{%
1311     % We have to set dummies so commands such as @code, and characters
1312     % such as \, aren't expanded when present in a section title.
1313     \indexnofonts
1314     \turnoffactive
1315     \makevalueexpandable
1316     \def\pdfdestname{#1}%
1317     \txiescapepdf\pdfdestname
1318     \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1319   }}
1320   %
1321   % used to mark target names; must be expandable.
1322   \def\pdfmkpgn#1{#1}
1323   %
1324   % by default, use black for everything.
1325   \def\urlcolor{\rgbBlack}
1326   \def\linkcolor{\rgbBlack}
1327   \def\endlink{\setcolor{\maincolor}\pdfendlink}
1328   %
1329   % Adding outlines to PDF; macros for calculating structure of outlines
1330   % come from Petr Olsak
1331   \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
1332     \else \csname#1\endcsname \fi}
1333   \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
1334     \advance\tempnum by 1
1335     \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
1336   %
1337   % #1 is the section text, which is what will be displayed in the
1338   % outline by the pdf viewer.  #2 is the pdf expression for the number
1339   % of subentries (or empty, for subsubsections).  #3 is the node text,
1340   % which might be empty if this toc entry had no corresponding node.
1341   % #4 is the page number
1342   %
1343   \def\dopdfoutline#1#2#3#4{%
1344     % Generate a link to the node text if that exists; else, use the
1345     % page number.  We could generate a destination for the section
1346     % text in the case where a section has no node, but it doesn't
1347     % seem worth the trouble, since most documents are normally structured.
1348     {
1349       \ifx\luatexversion\thisisundefined \else
1350         \turnoffactive % LuaTeX can use Unicode strings for PDF
1351       \fi
1352       \edef\pdfoutlinedest{#3}%
1353       \ifx\pdfoutlinedest\empty
1354         \def\pdfoutlinedest{#4}%
1355       \else
1356         \txiescapepdf\pdfoutlinedest
1357       \fi
1358       %
1359       % Also escape PDF chars in the display string.
1360       \edef\pdfoutlinetext{#1}%
1361       \txiescapepdf\pdfoutlinetext
1362       %
1363       \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
1364     }
1365   }
1366   %
1367   \def\pdfmakeoutlines{%
1368     \begingroup
1369       % Read toc silently, to get counts of subentries for \pdfoutline.
1370       \def\partentry##1##2##3##4{}% ignore parts in the outlines
1371       \def\numchapentry##1##2##3##4{%
1372         \def\thischapnum{##2}%
1373         \def\thissecnum{0}%
1374         \def\thissubsecnum{0}%
1375       }%
1376       \def\numsecentry##1##2##3##4{%
1377         \advancenumber{chap\thischapnum}%
1378         \def\thissecnum{##2}%
1379         \def\thissubsecnum{0}%
1380       }%
1381       \def\numsubsecentry##1##2##3##4{%
1382         \advancenumber{sec\thissecnum}%
1383         \def\thissubsecnum{##2}%
1384       }%
1385       \def\numsubsubsecentry##1##2##3##4{%
1386         \advancenumber{subsec\thissubsecnum}%
1387       }%
1388       \def\thischapnum{0}%
1389       \def\thissecnum{0}%
1390       \def\thissubsecnum{0}%
1391       %
1392       % use \def rather than \let here because we redefine \chapentry et
1393       % al. a second time, below.
1394       \def\appentry{\numchapentry}%
1395       \def\appsecentry{\numsecentry}%
1396       \def\appsubsecentry{\numsubsecentry}%
1397       \def\appsubsubsecentry{\numsubsubsecentry}%
1398       \def\unnchapentry{\numchapentry}%
1399       \def\unnsecentry{\numsecentry}%
1400       \def\unnsubsecentry{\numsubsecentry}%
1401       \def\unnsubsubsecentry{\numsubsubsecentry}%
1402       \readdatafile{toc}%
1403       %
1404       % Read toc second time, this time actually producing the outlines.
1405       % The `-' means take the \expnumber as the absolute number of
1406       % subentries, which we calculated on our first read of the .toc above.
1407       %
1408       % We use the node names as the destinations.
1409       \def\numchapentry##1##2##3##4{%
1410         \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
1411       \def\numsecentry##1##2##3##4{%
1412         \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
1413       \def\numsubsecentry##1##2##3##4{%
1414         \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
1415       \def\numsubsubsecentry##1##2##3##4{% count is always zero
1416         \dopdfoutline{##1}{}{##3}{##4}}%
1417       %
1418       % PDF outlines are displayed using system fonts, instead of
1419       % document fonts.  Therefore we cannot use special characters,
1420       % since the encoding is unknown.  For example, the eogonek from
1421       % Latin 2 (0xea) gets translated to a | character.  Info from
1422       % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
1423       %
1424       % TODO this right, we have to translate 8-bit characters to
1425       % their "best" equivalent, based on the @documentencoding.  Too
1426       % much work for too little return.  Just use the ASCII equivalents
1427       % we use for the index sort strings.
1428       % 
1429       \indexnofonts
1430       \setupdatafile
1431       % We can have normal brace characters in the PDF outlines, unlike
1432       % Texinfo index files.  So set that up.
1433       \def\{{\lbracecharliteral}%
1434       \def\}{\rbracecharliteral}%
1435       \catcode`\\=\active \otherbackslash
1436       \input \tocreadfilename
1437     \endgroup
1438   }
1439   {\catcode`[=1 \catcode`]=2
1440    \catcode`{=\other \catcode`}=\other
1441    \gdef\lbracecharliteral[{]%
1442    \gdef\rbracecharliteral[}]%
1443   ]
1444   %
1445   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1446     \ifx\PP\D\let\nextsp\relax
1447     \else\let\nextsp\skipspaces
1448       \addtokens{\filename}{\PP}%
1449       \advance\filenamelength by 1
1450     \fi
1451     \nextsp}
1452   \def\getfilename#1{%
1453     \filenamelength=0
1454     % If we don't expand the argument now, \skipspaces will get
1455     % snagged on things like "@value{foo}".
1456     \edef\temp{#1}%
1457     \expandafter\skipspaces\temp|\relax
1458   }
1459   \ifnum\pdftexversion < 14
1460     \let \startlink \pdfannotlink
1461   \else
1462     \let \startlink \pdfstartlink
1463   \fi
1464   % make a live url in pdf output.
1465   \def\pdfurl#1{%
1466     \begingroup
1467       % it seems we really need yet another set of dummies; have not
1468       % tried to figure out what each command should do in the context
1469       % of @url.  for now, just make @/ a no-op, that's the only one
1470       % people have actually reported a problem with.
1471       %
1472       \normalturnoffactive
1473       \def\@{@}%
1474       \let\/=\empty
1475       \makevalueexpandable
1476       % do we want to go so far as to use \indexnofonts instead of just
1477       % special-casing \var here?
1478       \def\var##1{##1}%
1479       %
1480       \leavevmode\setcolor{\urlcolor}%
1481       \startlink attr{/Border [0 0 0]}%
1482         user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
1483     \endgroup}
1484   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1485   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1486   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1487   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1488   \def\maketoks{%
1489     \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1490     \ifx\first0\adn0
1491     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1492     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1493     \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1494     \else
1495       \ifnum0=\countA\else\makelink\fi
1496       \ifx\first.\let\next=\done\else
1497         \let\next=\maketoks
1498         \addtokens{\toksB}{\the\toksD}
1499         \ifx\first,\addtokens{\toksB}{\space}\fi
1500       \fi
1501     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1502     \next}
1503   \def\makelink{\addtokens{\toksB}%
1504     {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1505   \def\pdflink#1{%
1506     \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
1507     \setcolor{\linkcolor}#1\endlink}
1508   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1509 \else
1510   % non-pdf mode
1511   \let\pdfmkdest = \gobble
1512   \let\pdfurl = \gobble
1513   \let\endlink = \relax
1514   \let\setcolor = \gobble
1515   \let\pdfsetcolor = \gobble
1516   \let\pdfmakeoutlines = \relax
1517 \fi  % \ifx\pdfoutput
1518
1519 %
1520 % For XeTeX
1521 %
1522 \newif\iftxiuseunicodedestname
1523 \ifx\XeTeXrevision\thisisundefined
1524 \else
1525   %
1526   % XeTeX version check
1527   %
1528   \ifnum\strcmp{\the\XeTeXversion\XeTeXrevision}{0.99995}>-1
1529     % XeTeX 0.99995+ contains xdvipdfmx 20160307+.
1530     % It can handle Unicode destination name for PDF.
1531     \txiuseunicodedestnametrue
1532   \else
1533     % XeTeX < 0.99995 can not handle Unicode destination name for PDF
1534     % because xdvipdfmx 20150315 has UTF-16 convert issue.
1535     % It fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1536     \txiuseunicodedestnamefalse
1537   \fi
1538   %
1539   % PDF outline support
1540   %
1541   % Emulate the primitive of pdfTeX
1542   \def\pdfdest name#1 xyz{%
1543     \special{pdf:dest (name#1) [@thispage /XYZ @xpos @ypos]}%
1544   }
1545   \def\pdfmkdest#1{{%
1546     % We have to set dummies so commands such as @code, and characters
1547     % such as \, aren't expanded when present in a section title.
1548     \indexnofonts
1549     \iftxiuseunicodedestname
1550       \def\pdfdestname{#1}% Pass through Unicode characters.
1551     \else
1552       \edef\pdfdestname{#1}% Replace Unicode characters to ASCII.
1553     \fi
1554     \turnoffactive
1555     \makevalueexpandable
1556     \txiescapepdf\pdfdestname
1557     \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1558   }}
1559   %
1560   \def\dopdfoutline#1#2#3#4{%
1561     \iftxiuseunicodedestname
1562       \def\pdfoutlinedest{#3}% Pass through Unicode characters.
1563     \else
1564       \edef\pdfoutlinedest{#3}% Replace Unicode characters to ASCII.
1565     \fi
1566     \ifx\pdfoutlinedest\empty
1567       \def\pdfoutlinedest{#4}%
1568     \fi
1569     {
1570       \turnoffactive
1571       \txiescapepdf\pdfoutlinedest
1572       \edef\pdfoutlinetext{#1}%
1573       \txiescapepdf\pdfoutlinetext
1574       %
1575       \special{pdf:out [-] #2 << /Title (\pdfoutlinetext) /A
1576         << /S /GoTo /D (name\pdfoutlinedest) >> >> }%
1577     }
1578   }
1579   %
1580   \def\pdfmakeoutlines{%
1581     \begingroup
1582       %
1583       % In the case of XeTeX, counts of subentries is not necesary.
1584       % Therefore, read toc only once.
1585       %
1586       % We use the node names as the destinations.
1587       \def\partentry##1##2##3##4{}% ignore parts in the outlines
1588       \def\numchapentry##1##2##3##4{%
1589         \dopdfoutline{##1}{1}{##3}{##4}}%
1590       \def\numsecentry##1##2##3##4{%
1591         \dopdfoutline{##1}{2}{##3}{##4}}%
1592       \def\numsubsecentry##1##2##3##4{%
1593         \dopdfoutline{##1}{3}{##3}{##4}}%
1594       \def\numsubsubsecentry##1##2##3##4{%
1595         \dopdfoutline{##1}{4}{##3}{##4}}%
1596       %
1597       \let\appentry\numchapentry%
1598       \let\appsecentry\numsecentry%
1599       \let\appsubsecentry\numsubsecentry%
1600       \let\appsubsubsecentry\numsubsubsecentry%
1601       \let\unnchapentry\numchapentry%
1602       \let\unnsecentry\numsecentry%
1603       \let\unnsubsecentry\numsubsecentry%
1604       \let\unnsubsubsecentry\numsubsubsecentry%
1605       %
1606       % In the case of XeTeX, xdvipdfmx converts strings to UTF-16.
1607       % Therefore, the encoding and the language may not be considered.
1608       %
1609       \indexnofonts
1610       \setupdatafile
1611       % We can have normal brace characters in the PDF outlines, unlike
1612       % Texinfo index files.  So set that up.
1613       \def\{{\lbracecharliteral}%
1614       \def\}{\rbracecharliteral}%
1615       \catcode`\\=\active \otherbackslash
1616       \input \tocreadfilename
1617     \endgroup
1618   }
1619   {\catcode`[=1 \catcode`]=2
1620    \catcode`{=\other \catcode`}=\other
1621    \gdef\lbracecharliteral[{]%
1622    \gdef\rbracecharliteral[}]%
1623   ]
1624
1625   \special{pdf:docview << /PageMode /UseOutlines >> }
1626   % ``\special{pdf:tounicode ...}'' is not necessary
1627   % because xdvipdfmx converts strings from UTF-8 to UTF-16 without it.
1628   % However, due to UTF-16 convert issue of xdvipdfmx 20150315,
1629   % ``\special{pdf:dest ...}'' can not handle non-ASCII strings.
1630   % It fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1631 %
1632   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1633     \ifx\PP\D\let\nextsp\relax
1634     \else\let\nextsp\skipspaces
1635       \addtokens{\filename}{\PP}%
1636       \advance\filenamelength by 1
1637     \fi
1638     \nextsp}
1639   \def\getfilename#1{%
1640     \filenamelength=0
1641     % If we don't expand the argument now, \skipspaces will get
1642     % snagged on things like "@value{foo}".
1643     \edef\temp{#1}%
1644     \expandafter\skipspaces\temp|\relax
1645   }
1646   % make a live url in pdf output.
1647   \def\pdfurl#1{%
1648     \begingroup
1649       % it seems we really need yet another set of dummies; have not
1650       % tried to figure out what each command should do in the context
1651       % of @url.  for now, just make @/ a no-op, that's the only one
1652       % people have actually reported a problem with.
1653       %
1654       \normalturnoffactive
1655       \def\@{@}%
1656       \let\/=\empty
1657       \makevalueexpandable
1658       % do we want to go so far as to use \indexnofonts instead of just
1659       % special-casing \var here?
1660       \def\var##1{##1}%
1661       %
1662       \leavevmode\setcolor{\urlcolor}%
1663       \special{pdf:bann << /Border [0 0 0]
1664         /Subtype /Link /A << /S /URI /URI (#1) >> >>}%
1665     \endgroup}
1666   \def\endlink{\setcolor{\maincolor}\special{pdf:eann}}
1667   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1668   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1669   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1670   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1671   \def\maketoks{%
1672     \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1673     \ifx\first0\adn0
1674     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1675     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1676     \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1677     \else
1678       \ifnum0=\countA\else\makelink\fi
1679       \ifx\first.\let\next=\done\else
1680         \let\next=\maketoks
1681         \addtokens{\toksB}{\the\toksD}
1682         \ifx\first,\addtokens{\toksB}{\space}\fi
1683       \fi
1684     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1685     \next}
1686   \def\makelink{\addtokens{\toksB}%
1687     {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1688   \def\pdflink#1{%
1689     \special{pdf:bann << /Border [0 0 0]
1690       /Type /Annot /Subtype /Link /A << /S /GoTo /D (name#1) >> >>}%
1691     \setcolor{\linkcolor}#1\endlink}
1692   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1693 %
1694   %
1695   % @image support
1696   %
1697   % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1698   \def\doxeteximage#1#2#3{%
1699     \def\xeteximagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1700     \def\xeteximageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1701     %
1702     % XeTeX (and the PDF format) support .pdf, .png, .jpg (among
1703     % others).  Let's try in that order, PDF first since if
1704     % someone has a scalable image, presumably better to use that than a
1705     % bitmap.
1706     \let\xeteximgext=\empty
1707     \begingroup
1708       \openin 1 #1.pdf \ifeof 1
1709         \openin 1 #1.PDF \ifeof 1
1710           \openin 1 #1.png \ifeof 1
1711             \openin 1 #1.jpg \ifeof 1
1712               \openin 1 #1.jpeg \ifeof 1
1713                 \openin 1 #1.JPG \ifeof 1
1714                   \errmessage{Could not find image file #1 for XeTeX}%
1715                 \else \gdef\xeteximgext{JPG}%
1716                 \fi
1717               \else \gdef\xeteximgext{jpeg}%
1718               \fi
1719             \else \gdef\xeteximgext{jpg}%
1720             \fi
1721           \else \gdef\xeteximgext{png}%
1722           \fi
1723         \else \gdef\xeteximgext{PDF}%
1724         \fi
1725       \else \gdef\xeteximgext{pdf}%
1726       \fi
1727       \closein 1
1728     \endgroup
1729     %
1730     \def\xetexpdfext{pdf}%
1731     \ifx\xeteximgext\xetexpdfext
1732       \XeTeXpdffile "#1".\xeteximgext ""
1733     \else
1734       \def\xetexpdfext{PDF}%
1735       \ifx\xeteximgext\xetexpdfext
1736         \XeTeXpdffile "#1".\xeteximgext ""
1737       \else
1738         \XeTeXpicfile "#1".\xeteximgext ""
1739       \fi
1740     \fi
1741     \ifdim \wd0 >0pt width \xeteximagewidth \fi
1742     \ifdim \wd2 >0pt height \xeteximageheight \fi \relax
1743   }
1744 \fi
1745
1746 \message{fonts,}
1747
1748 % Change the current font style to #1, remembering it in \curfontstyle.
1749 % For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
1750 % italics, not bold italics.
1751 %
1752 \def\setfontstyle#1{%
1753   \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
1754   \csname ten#1\endcsname  % change the current font
1755 }
1756
1757 % Select #1 fonts with the current style.
1758 %
1759 \def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
1760
1761 \def\rm{\fam=0 \setfontstyle{rm}}
1762 \def\it{\fam=\itfam \setfontstyle{it}}
1763 \def\sl{\fam=\slfam \setfontstyle{sl}}
1764 \def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf}
1765 \def\tt{\fam=\ttfam \setfontstyle{tt}}
1766
1767 % Unfortunately, we have to override this for titles and the like, since
1768 % in those cases "rm" is bold.  Sigh.
1769 \def\rmisbold{\rm\def\curfontstyle{bf}}
1770
1771 % Texinfo sort of supports the sans serif font style, which plain TeX does not.
1772 % So we set up a \sf.
1773 \newfam\sffam
1774 \def\sf{\fam=\sffam \setfontstyle{sf}}
1775 \let\li = \sf % Sometimes we call it \li, not \sf.
1776
1777 % We don't need math for this font style.
1778 \def\ttsl{\setfontstyle{ttsl}}
1779
1780
1781 % Set the baselineskip to #1, and the lineskip and strut size
1782 % correspondingly.  There is no deep meaning behind these magic numbers
1783 % used as factors; they just match (closely enough) what Knuth defined.
1784 %
1785 \def\lineskipfactor{.08333}
1786 \def\strutheightpercent{.70833}
1787 \def\strutdepthpercent {.29167}
1788 %
1789 % can get a sort of poor man's double spacing by redefining this.
1790 \def\baselinefactor{1}
1791 %
1792 \newdimen\textleading
1793 \def\setleading#1{%
1794   \dimen0 = #1\relax
1795   \normalbaselineskip = \baselinefactor\dimen0
1796   \normallineskip = \lineskipfactor\normalbaselineskip
1797   \normalbaselines
1798   \setbox\strutbox =\hbox{%
1799     \vrule width0pt height\strutheightpercent\baselineskip
1800                     depth \strutdepthpercent \baselineskip
1801   }%
1802 }
1803
1804 % PDF CMaps.  See also LaTeX's t1.cmap.
1805 %
1806 % do nothing with this by default.
1807 \expandafter\let\csname cmapOT1\endcsname\gobble
1808 \expandafter\let\csname cmapOT1IT\endcsname\gobble
1809 \expandafter\let\csname cmapOT1TT\endcsname\gobble
1810
1811 % if we are producing pdf, and we have \pdffontattr, then define cmaps.
1812 % (\pdffontattr was introduced many years ago, but people still run
1813 % older pdftex's; it's easy to conditionalize, so we do.)
1814 \ifpdf \ifx\pdffontattr\thisisundefined \else
1815   \begingroup
1816     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1817     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1818 %%DocumentNeededResources: ProcSet (CIDInit)
1819 %%IncludeResource: ProcSet (CIDInit)
1820 %%BeginResource: CMap (TeX-OT1-0)
1821 %%Title: (TeX-OT1-0 TeX OT1 0)
1822 %%Version: 1.000
1823 %%EndComments
1824 /CIDInit /ProcSet findresource begin
1825 12 dict begin
1826 begincmap
1827 /CIDSystemInfo
1828 << /Registry (TeX)
1829 /Ordering (OT1)
1830 /Supplement 0
1831 >> def
1832 /CMapName /TeX-OT1-0 def
1833 /CMapType 2 def
1834 1 begincodespacerange
1835 <00> <7F>
1836 endcodespacerange
1837 8 beginbfrange
1838 <00> <01> <0393>
1839 <09> <0A> <03A8>
1840 <23> <26> <0023>
1841 <28> <3B> <0028>
1842 <3F> <5B> <003F>
1843 <5D> <5E> <005D>
1844 <61> <7A> <0061>
1845 <7B> <7C> <2013>
1846 endbfrange
1847 40 beginbfchar
1848 <02> <0398>
1849 <03> <039B>
1850 <04> <039E>
1851 <05> <03A0>
1852 <06> <03A3>
1853 <07> <03D2>
1854 <08> <03A6>
1855 <0B> <00660066>
1856 <0C> <00660069>
1857 <0D> <0066006C>
1858 <0E> <006600660069>
1859 <0F> <00660066006C>
1860 <10> <0131>
1861 <11> <0237>
1862 <12> <0060>
1863 <13> <00B4>
1864 <14> <02C7>
1865 <15> <02D8>
1866 <16> <00AF>
1867 <17> <02DA>
1868 <18> <00B8>
1869 <19> <00DF>
1870 <1A> <00E6>
1871 <1B> <0153>
1872 <1C> <00F8>
1873 <1D> <00C6>
1874 <1E> <0152>
1875 <1F> <00D8>
1876 <21> <0021>
1877 <22> <201D>
1878 <27> <2019>
1879 <3C> <00A1>
1880 <3D> <003D>
1881 <3E> <00BF>
1882 <5C> <201C>
1883 <5F> <02D9>
1884 <60> <2018>
1885 <7D> <02DD>
1886 <7E> <007E>
1887 <7F> <00A8>
1888 endbfchar
1889 endcmap
1890 CMapName currentdict /CMap defineresource pop
1891 end
1892 end
1893 %%EndResource
1894 %%EOF
1895     }\endgroup
1896   \expandafter\edef\csname cmapOT1\endcsname#1{%
1897     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
1898   }%
1899 %
1900 % \cmapOT1IT
1901   \begingroup
1902     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1903     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1904 %%DocumentNeededResources: ProcSet (CIDInit)
1905 %%IncludeResource: ProcSet (CIDInit)
1906 %%BeginResource: CMap (TeX-OT1IT-0)
1907 %%Title: (TeX-OT1IT-0 TeX OT1IT 0)
1908 %%Version: 1.000
1909 %%EndComments
1910 /CIDInit /ProcSet findresource begin
1911 12 dict begin
1912 begincmap
1913 /CIDSystemInfo
1914 << /Registry (TeX)
1915 /Ordering (OT1IT)
1916 /Supplement 0
1917 >> def
1918 /CMapName /TeX-OT1IT-0 def
1919 /CMapType 2 def
1920 1 begincodespacerange
1921 <00> <7F>
1922 endcodespacerange
1923 8 beginbfrange
1924 <00> <01> <0393>
1925 <09> <0A> <03A8>
1926 <25> <26> <0025>
1927 <28> <3B> <0028>
1928 <3F> <5B> <003F>
1929 <5D> <5E> <005D>
1930 <61> <7A> <0061>
1931 <7B> <7C> <2013>
1932 endbfrange
1933 42 beginbfchar
1934 <02> <0398>
1935 <03> <039B>
1936 <04> <039E>
1937 <05> <03A0>
1938 <06> <03A3>
1939 <07> <03D2>
1940 <08> <03A6>
1941 <0B> <00660066>
1942 <0C> <00660069>
1943 <0D> <0066006C>
1944 <0E> <006600660069>
1945 <0F> <00660066006C>
1946 <10> <0131>
1947 <11> <0237>
1948 <12> <0060>
1949 <13> <00B4>
1950 <14> <02C7>
1951 <15> <02D8>
1952 <16> <00AF>
1953 <17> <02DA>
1954 <18> <00B8>
1955 <19> <00DF>
1956 <1A> <00E6>
1957 <1B> <0153>
1958 <1C> <00F8>
1959 <1D> <00C6>
1960 <1E> <0152>
1961 <1F> <00D8>
1962 <21> <0021>
1963 <22> <201D>
1964 <23> <0023>
1965 <24> <00A3>
1966 <27> <2019>
1967 <3C> <00A1>
1968 <3D> <003D>
1969 <3E> <00BF>
1970 <5C> <201C>
1971 <5F> <02D9>
1972 <60> <2018>
1973 <7D> <02DD>
1974 <7E> <007E>
1975 <7F> <00A8>
1976 endbfchar
1977 endcmap
1978 CMapName currentdict /CMap defineresource pop
1979 end
1980 end
1981 %%EndResource
1982 %%EOF
1983     }\endgroup
1984   \expandafter\edef\csname cmapOT1IT\endcsname#1{%
1985     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
1986   }%
1987 %
1988 % \cmapOT1TT
1989   \begingroup
1990     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1991     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1992 %%DocumentNeededResources: ProcSet (CIDInit)
1993 %%IncludeResource: ProcSet (CIDInit)
1994 %%BeginResource: CMap (TeX-OT1TT-0)
1995 %%Title: (TeX-OT1TT-0 TeX OT1TT 0)
1996 %%Version: 1.000
1997 %%EndComments
1998 /CIDInit /ProcSet findresource begin
1999 12 dict begin
2000 begincmap
2001 /CIDSystemInfo
2002 << /Registry (TeX)
2003 /Ordering (OT1TT)
2004 /Supplement 0
2005 >> def
2006 /CMapName /TeX-OT1TT-0 def
2007 /CMapType 2 def
2008 1 begincodespacerange
2009 <00> <7F>
2010 endcodespacerange
2011 5 beginbfrange
2012 <00> <01> <0393>
2013 <09> <0A> <03A8>
2014 <21> <26> <0021>
2015 <28> <5F> <0028>
2016 <61> <7E> <0061>
2017 endbfrange
2018 32 beginbfchar
2019 <02> <0398>
2020 <03> <039B>
2021 <04> <039E>
2022 <05> <03A0>
2023 <06> <03A3>
2024 <07> <03D2>
2025 <08> <03A6>
2026 <0B> <2191>
2027 <0C> <2193>
2028 <0D> <0027>
2029 <0E> <00A1>
2030 <0F> <00BF>
2031 <10> <0131>
2032 <11> <0237>
2033 <12> <0060>
2034 <13> <00B4>
2035 <14> <02C7>
2036 <15> <02D8>
2037 <16> <00AF>
2038 <17> <02DA>
2039 <18> <00B8>
2040 <19> <00DF>
2041 <1A> <00E6>
2042 <1B> <0153>
2043 <1C> <00F8>
2044 <1D> <00C6>
2045 <1E> <0152>
2046 <1F> <00D8>
2047 <20> <2423>
2048 <27> <2019>
2049 <60> <2018>
2050 <7F> <00A8>
2051 endbfchar
2052 endcmap
2053 CMapName currentdict /CMap defineresource pop
2054 end
2055 end
2056 %%EndResource
2057 %%EOF
2058     }\endgroup
2059   \expandafter\edef\csname cmapOT1TT\endcsname#1{%
2060     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
2061   }%
2062 \fi\fi
2063
2064
2065 % Set the font macro #1 to the font named \fontprefix#2.
2066 % #3 is the font's design size, #4 is a scale factor, #5 is the CMap
2067 % encoding (only OT1, OT1IT and OT1TT are allowed, or empty to omit).
2068 % Example:
2069 % #1 = \textrm
2070 % #2 = \rmshape
2071 % #3 = 10
2072 % #4 = \mainmagstep
2073 % #5 = OT1
2074 %
2075 \def\setfont#1#2#3#4#5{%
2076   \font#1=\fontprefix#2#3 scaled #4
2077   \csname cmap#5\endcsname#1%
2078 }
2079 % This is what gets called when #5 of \setfont is empty.
2080 \let\cmap\gobble
2081 %
2082 % (end of cmaps)
2083
2084 % Use cm as the default font prefix.
2085 % To specify the font prefix, you must define \fontprefix
2086 % before you read in texinfo.tex.
2087 \ifx\fontprefix\thisisundefined
2088 \def\fontprefix{cm}
2089 \fi
2090 % Support font families that don't use the same naming scheme as CM.
2091 \def\rmshape{r}
2092 \def\rmbshape{bx}               % where the normal face is bold
2093 \def\bfshape{b}
2094 \def\bxshape{bx}
2095 \def\ttshape{tt}
2096 \def\ttbshape{tt}
2097 \def\ttslshape{sltt}
2098 \def\itshape{ti}
2099 \def\itbshape{bxti}
2100 \def\slshape{sl}
2101 \def\slbshape{bxsl}
2102 \def\sfshape{ss}
2103 \def\sfbshape{ss}
2104 \def\scshape{csc}
2105 \def\scbshape{csc}
2106
2107 % Definitions for a main text size of 11pt.  (The default in Texinfo.)
2108 %
2109 \def\definetextfontsizexi{%
2110 % Text fonts (11.2pt, magstep1).
2111 \def\textnominalsize{11pt}
2112 \edef\mainmagstep{\magstephalf}
2113 \setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2114 \setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2115 \setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2116 \setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2117 \setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2118 \setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2119 \setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2120 \setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2121 \font\texti=cmmi10 scaled \mainmagstep
2122 \font\textsy=cmsy10 scaled \mainmagstep
2123 \def\textecsize{1095}
2124
2125 % A few fonts for @defun names and args.
2126 \setfont\defbf\bfshape{10}{\magstep1}{OT1}
2127 \setfont\deftt\ttshape{10}{\magstep1}{OT1TT}
2128 \setfont\defsl\slshape{10}{\magstep1}{OT1TT}
2129 \setfont\defttsl\ttslshape{10}{\magstep1}{OT1TT}
2130 \def\df{\let\tentt=\deftt \let\tenbf = \defbf
2131 \let\tenttsl=\defttsl \let\tensl=\defsl \bf}
2132
2133 % Fonts for indices, footnotes, small examples (9pt).
2134 \def\smallnominalsize{9pt}
2135 \setfont\smallrm\rmshape{9}{1000}{OT1}
2136 \setfont\smalltt\ttshape{9}{1000}{OT1TT}
2137 \setfont\smallbf\bfshape{10}{900}{OT1}
2138 \setfont\smallit\itshape{9}{1000}{OT1IT}
2139 \setfont\smallsl\slshape{9}{1000}{OT1}
2140 \setfont\smallsf\sfshape{9}{1000}{OT1}
2141 \setfont\smallsc\scshape{10}{900}{OT1}
2142 \setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2143 \font\smalli=cmmi9
2144 \font\smallsy=cmsy9
2145 \def\smallecsize{0900}
2146
2147 % Fonts for small examples (8pt).
2148 \def\smallernominalsize{8pt}
2149 \setfont\smallerrm\rmshape{8}{1000}{OT1}
2150 \setfont\smallertt\ttshape{8}{1000}{OT1TT}
2151 \setfont\smallerbf\bfshape{10}{800}{OT1}
2152 \setfont\smallerit\itshape{8}{1000}{OT1IT}
2153 \setfont\smallersl\slshape{8}{1000}{OT1}
2154 \setfont\smallersf\sfshape{8}{1000}{OT1}
2155 \setfont\smallersc\scshape{10}{800}{OT1}
2156 \setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2157 \font\smalleri=cmmi8
2158 \font\smallersy=cmsy8
2159 \def\smallerecsize{0800}
2160
2161 % Fonts for title page (20.4pt):
2162 \def\titlenominalsize{20pt}
2163 \setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2164 \setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2165 \setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2166 \setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2167 \setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2168 \setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2169 \let\titlebf=\titlerm
2170 \setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2171 \font\titlei=cmmi12 scaled \magstep3
2172 \font\titlesy=cmsy10 scaled \magstep4
2173 \def\titleecsize{2074}
2174
2175 % Chapter (and unnumbered) fonts (17.28pt).
2176 \def\chapnominalsize{17pt}
2177 \setfont\chaprm\rmbshape{12}{\magstep2}{OT1}
2178 \setfont\chapit\itbshape{10}{\magstep3}{OT1IT}
2179 \setfont\chapsl\slbshape{10}{\magstep3}{OT1}
2180 \setfont\chaptt\ttbshape{12}{\magstep2}{OT1TT}
2181 \setfont\chapttsl\ttslshape{10}{\magstep3}{OT1TT}
2182 \setfont\chapsf\sfbshape{17}{1000}{OT1}
2183 \let\chapbf=\chaprm
2184 \setfont\chapsc\scbshape{10}{\magstep3}{OT1}
2185 \font\chapi=cmmi12 scaled \magstep2
2186 \font\chapsy=cmsy10 scaled \magstep3
2187 \def\chapecsize{1728}
2188
2189 % Section fonts (14.4pt).
2190 \def\secnominalsize{14pt}
2191 \setfont\secrm\rmbshape{12}{\magstep1}{OT1}
2192 \setfont\secrmnotbold\rmshape{12}{\magstep1}{OT1}
2193 \setfont\secit\itbshape{10}{\magstep2}{OT1IT}
2194 \setfont\secsl\slbshape{10}{\magstep2}{OT1}
2195 \setfont\sectt\ttbshape{12}{\magstep1}{OT1TT}
2196 \setfont\secttsl\ttslshape{10}{\magstep2}{OT1TT}
2197 \setfont\secsf\sfbshape{12}{\magstep1}{OT1}
2198 \let\secbf\secrm
2199 \setfont\secsc\scbshape{10}{\magstep2}{OT1}
2200 \font\seci=cmmi12 scaled \magstep1
2201 \font\secsy=cmsy10 scaled \magstep2
2202 \def\sececsize{1440}
2203
2204 % Subsection fonts (13.15pt).
2205 \def\ssecnominalsize{13pt}
2206 \setfont\ssecrm\rmbshape{12}{\magstephalf}{OT1}
2207 \setfont\ssecit\itbshape{10}{1315}{OT1IT}
2208 \setfont\ssecsl\slbshape{10}{1315}{OT1}
2209 \setfont\ssectt\ttbshape{12}{\magstephalf}{OT1TT}
2210 \setfont\ssecttsl\ttslshape{10}{1315}{OT1TT}
2211 \setfont\ssecsf\sfbshape{12}{\magstephalf}{OT1}
2212 \let\ssecbf\ssecrm
2213 \setfont\ssecsc\scbshape{10}{1315}{OT1}
2214 \font\sseci=cmmi12 scaled \magstephalf
2215 \font\ssecsy=cmsy10 scaled 1315
2216 \def\ssececsize{1200}
2217
2218 % Reduced fonts for @acro in text (10pt).
2219 \def\reducednominalsize{10pt}
2220 \setfont\reducedrm\rmshape{10}{1000}{OT1}
2221 \setfont\reducedtt\ttshape{10}{1000}{OT1TT}
2222 \setfont\reducedbf\bfshape{10}{1000}{OT1}
2223 \setfont\reducedit\itshape{10}{1000}{OT1IT}
2224 \setfont\reducedsl\slshape{10}{1000}{OT1}
2225 \setfont\reducedsf\sfshape{10}{1000}{OT1}
2226 \setfont\reducedsc\scshape{10}{1000}{OT1}
2227 \setfont\reducedttsl\ttslshape{10}{1000}{OT1TT}
2228 \font\reducedi=cmmi10
2229 \font\reducedsy=cmsy10
2230 \def\reducedecsize{1000}
2231
2232 \textleading = 13.2pt % line spacing for 11pt CM
2233 \textfonts            % reset the current fonts
2234 \rm
2235 } % end of 11pt text font size definitions, \definetextfontsizexi
2236
2237
2238 % Definitions to make the main text be 10pt Computer Modern, with
2239 % section, chapter, etc., sizes following suit.  This is for the GNU
2240 % Press printing of the Emacs 22 manual.  Maybe other manuals in the
2241 % future.  Used with @smallbook, which sets the leading to 12pt.
2242 %
2243 \def\definetextfontsizex{%
2244 % Text fonts (10pt).
2245 \def\textnominalsize{10pt}
2246 \edef\mainmagstep{1000}
2247 \setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2248 \setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2249 \setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2250 \setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2251 \setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2252 \setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2253 \setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2254 \setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2255 \font\texti=cmmi10 scaled \mainmagstep
2256 \font\textsy=cmsy10 scaled \mainmagstep
2257 \def\textecsize{1000}
2258
2259 % A few fonts for @defun names and args.
2260 \setfont\defbf\bfshape{10}{\magstephalf}{OT1}
2261 \setfont\deftt\ttshape{10}{\magstephalf}{OT1TT}
2262 \setfont\defsl\slshape{10}{\magstephalf}{OT1TT}
2263 \setfont\defttsl\ttslshape{10}{\magstephalf}{OT1TT}
2264 \def\df{\let\tentt=\deftt \let\tenbf = \defbf
2265 \let\tensl=\defsl \let\tenttsl=\defttsl \bf}
2266
2267 % Fonts for indices, footnotes, small examples (9pt).
2268 \def\smallnominalsize{9pt}
2269 \setfont\smallrm\rmshape{9}{1000}{OT1}
2270 \setfont\smalltt\ttshape{9}{1000}{OT1TT}
2271 \setfont\smallbf\bfshape{10}{900}{OT1}
2272 \setfont\smallit\itshape{9}{1000}{OT1IT}
2273 \setfont\smallsl\slshape{9}{1000}{OT1}
2274 \setfont\smallsf\sfshape{9}{1000}{OT1}
2275 \setfont\smallsc\scshape{10}{900}{OT1}
2276 \setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2277 \font\smalli=cmmi9
2278 \font\smallsy=cmsy9
2279 \def\smallecsize{0900}
2280
2281 % Fonts for small examples (8pt).
2282 \def\smallernominalsize{8pt}
2283 \setfont\smallerrm\rmshape{8}{1000}{OT1}
2284 \setfont\smallertt\ttshape{8}{1000}{OT1TT}
2285 \setfont\smallerbf\bfshape{10}{800}{OT1}
2286 \setfont\smallerit\itshape{8}{1000}{OT1IT}
2287 \setfont\smallersl\slshape{8}{1000}{OT1}
2288 \setfont\smallersf\sfshape{8}{1000}{OT1}
2289 \setfont\smallersc\scshape{10}{800}{OT1}
2290 \setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2291 \font\smalleri=cmmi8
2292 \font\smallersy=cmsy8
2293 \def\smallerecsize{0800}
2294
2295 % Fonts for title page (20.4pt):
2296 \def\titlenominalsize{20pt}
2297 \setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2298 \setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2299 \setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2300 \setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2301 \setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2302 \setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2303 \let\titlebf=\titlerm
2304 \setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2305 \font\titlei=cmmi12 scaled \magstep3
2306 \font\titlesy=cmsy10 scaled \magstep4
2307 \def\titleecsize{2074}
2308
2309 % Chapter fonts (14.4pt).
2310 \def\chapnominalsize{14pt}
2311 \setfont\chaprm\rmbshape{12}{\magstep1}{OT1}
2312 \setfont\chapit\itbshape{10}{\magstep2}{OT1IT}
2313 \setfont\chapsl\slbshape{10}{\magstep2}{OT1}
2314 \setfont\chaptt\ttbshape{12}{\magstep1}{OT1TT}
2315 \setfont\chapttsl\ttslshape{10}{\magstep2}{OT1TT}
2316 \setfont\chapsf\sfbshape{12}{\magstep1}{OT1}
2317 \let\chapbf\chaprm
2318 \setfont\chapsc\scbshape{10}{\magstep2}{OT1}
2319 \font\chapi=cmmi12 scaled \magstep1
2320 \font\chapsy=cmsy10 scaled \magstep2
2321 \def\chapecsize{1440}
2322
2323 % Section fonts (12pt).
2324 \def\secnominalsize{12pt}
2325 \setfont\secrm\rmbshape{12}{1000}{OT1}
2326 \setfont\secit\itbshape{10}{\magstep1}{OT1IT}
2327 \setfont\secsl\slbshape{10}{\magstep1}{OT1}
2328 \setfont\sectt\ttbshape{12}{1000}{OT1TT}
2329 \setfont\secttsl\ttslshape{10}{\magstep1}{OT1TT}
2330 \setfont\secsf\sfbshape{12}{1000}{OT1}
2331 \let\secbf\secrm
2332 \setfont\secsc\scbshape{10}{\magstep1}{OT1}
2333 \font\seci=cmmi12
2334 \font\secsy=cmsy10 scaled \magstep1
2335 \def\sececsize{1200}
2336
2337 % Subsection fonts (10pt).
2338 \def\ssecnominalsize{10pt}
2339 \setfont\ssecrm\rmbshape{10}{1000}{OT1}
2340 \setfont\ssecit\itbshape{10}{1000}{OT1IT}
2341 \setfont\ssecsl\slbshape{10}{1000}{OT1}
2342 \setfont\ssectt\ttbshape{10}{1000}{OT1TT}
2343 \setfont\ssecttsl\ttslshape{10}{1000}{OT1TT}
2344 \setfont\ssecsf\sfbshape{10}{1000}{OT1}
2345 \let\ssecbf\ssecrm
2346 \setfont\ssecsc\scbshape{10}{1000}{OT1}
2347 \font\sseci=cmmi10
2348 \font\ssecsy=cmsy10
2349 \def\ssececsize{1000}
2350
2351 % Reduced fonts for @acro in text (9pt).
2352 \def\reducednominalsize{9pt}
2353 \setfont\reducedrm\rmshape{9}{1000}{OT1}
2354 \setfont\reducedtt\ttshape{9}{1000}{OT1TT}
2355 \setfont\reducedbf\bfshape{10}{900}{OT1}
2356 \setfont\reducedit\itshape{9}{1000}{OT1IT}
2357 \setfont\reducedsl\slshape{9}{1000}{OT1}
2358 \setfont\reducedsf\sfshape{9}{1000}{OT1}
2359 \setfont\reducedsc\scshape{10}{900}{OT1}
2360 \setfont\reducedttsl\ttslshape{10}{900}{OT1TT}
2361 \font\reducedi=cmmi9
2362 \font\reducedsy=cmsy9
2363 \def\reducedecsize{0900}
2364
2365 \divide\parskip by 2  % reduce space between paragraphs
2366 \textleading = 12pt   % line spacing for 10pt CM
2367 \textfonts            % reset the current fonts
2368 \rm
2369 } % end of 10pt text font size definitions, \definetextfontsizex
2370
2371
2372 % We provide the user-level command
2373 %   @fonttextsize 10
2374 % (or 11) to redefine the text font size.  pt is assumed.
2375 %
2376 \def\xiword{11}
2377 \def\xword{10}
2378 \def\xwordpt{10pt}
2379 %
2380 \parseargdef\fonttextsize{%
2381   \def\textsizearg{#1}%
2382   %\wlog{doing @fonttextsize \textsizearg}%
2383   %
2384   % Set \globaldefs so that documents can use this inside @tex, since
2385   % makeinfo 4.8 does not support it, but we need it nonetheless.
2386   %
2387  \begingroup \globaldefs=1
2388   \ifx\textsizearg\xword \definetextfontsizex
2389   \else \ifx\textsizearg\xiword \definetextfontsizexi
2390   \else
2391     \errhelp=\EMsimple
2392     \errmessage{@fonttextsize only supports `10' or `11', not `\textsizearg'}
2393   \fi\fi
2394  \endgroup
2395 }
2396
2397 % In order for the font changes to affect most math symbols and letters,
2398 % we have to define the \textfont of the standard families.  We don't
2399 % bother to reset \scriptfont and \scriptscriptfont; awaiting user need.
2400 %
2401 \def\resetmathfonts{%
2402   \textfont0=\tenrm \textfont1=\teni \textfont2=\tensy
2403   \textfont\itfam=\tenit \textfont\slfam=\tensl \textfont\bffam=\tenbf
2404   \textfont\ttfam=\tentt \textfont\sffam=\tensf
2405 }
2406
2407 % The font-changing commands redefine the meanings of \tenSTYLE, instead
2408 % of just \STYLE.  We do this because \STYLE needs to also set the
2409 % current \fam for math mode.  Our \STYLE (e.g., \rm) commands hardwire
2410 % \tenSTYLE to set the current font.
2411 %
2412 % Each font-changing command also sets the names \lsize (one size lower)
2413 % and \lllsize (three sizes lower).  These relative commands are used
2414 % in, e.g., the LaTeX logo and acronyms.
2415 %
2416 % This all needs generalizing, badly.
2417 %
2418 \def\textfonts{%
2419   \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
2420   \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
2421   \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
2422   \let\tenttsl=\textttsl
2423   \def\curfontsize{text}%
2424   \def\lsize{reduced}\def\lllsize{smaller}%
2425   \resetmathfonts \setleading{\textleading}}
2426 \def\titlefonts{%
2427   \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
2428   \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
2429   \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
2430   \let\tenttsl=\titlettsl
2431   \def\curfontsize{title}%
2432   \def\lsize{chap}\def\lllsize{subsec}%
2433   \resetmathfonts \setleading{27pt}}
2434 \def\titlefont#1{{\titlefonts\rmisbold #1}}
2435 \def\chapfonts{%
2436   \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
2437   \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
2438   \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy
2439   \let\tenttsl=\chapttsl
2440   \def\curfontsize{chap}%
2441   \def\lsize{sec}\def\lllsize{text}%
2442   \resetmathfonts \setleading{19pt}}
2443 \def\secfonts{%
2444   \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
2445   \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
2446   \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
2447   \let\tenttsl=\secttsl
2448   \def\curfontsize{sec}%
2449   \def\lsize{subsec}\def\lllsize{reduced}%
2450   \resetmathfonts \setleading{17pt}}
2451 \def\subsecfonts{%
2452   \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
2453   \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
2454   \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
2455   \let\tenttsl=\ssecttsl
2456   \def\curfontsize{ssec}%
2457   \def\lsize{text}\def\lllsize{small}%
2458   \resetmathfonts \setleading{15pt}}
2459 \let\subsubsecfonts = \subsecfonts
2460 \def\reducedfonts{%
2461   \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
2462   \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
2463   \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
2464   \let\tenttsl=\reducedttsl
2465   \def\curfontsize{reduced}%
2466   \def\lsize{small}\def\lllsize{smaller}%
2467   \resetmathfonts \setleading{10.5pt}}
2468 \def\smallfonts{%
2469   \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
2470   \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
2471   \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
2472   \let\tenttsl=\smallttsl
2473   \def\curfontsize{small}%
2474   \def\lsize{smaller}\def\lllsize{smaller}%
2475   \resetmathfonts \setleading{10.5pt}}
2476 \def\smallerfonts{%
2477   \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
2478   \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
2479   \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
2480   \let\tenttsl=\smallerttsl
2481   \def\curfontsize{smaller}%
2482   \def\lsize{smaller}\def\lllsize{smaller}%
2483   \resetmathfonts \setleading{9.5pt}}
2484
2485 % Fonts for short table of contents.
2486 \setfont\shortcontrm\rmshape{12}{1000}{OT1}
2487 \setfont\shortcontbf\bfshape{10}{\magstep1}{OT1}  % no cmb12
2488 \setfont\shortcontsl\slshape{12}{1000}{OT1}
2489 \setfont\shortconttt\ttshape{12}{1000}{OT1TT}
2490
2491 % Define these just so they can be easily changed for other fonts.
2492 \def\angleleft{$\langle$}
2493 \def\angleright{$\rangle$}
2494
2495 % Set the fonts to use with the @small... environments.
2496 \let\smallexamplefonts = \smallfonts
2497
2498 % About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
2499 % can fit this many characters:
2500 %   8.5x11=86   smallbook=72  a4=90  a5=69
2501 % If we use \scriptfonts (8pt), then we can fit this many characters:
2502 %   8.5x11=90+  smallbook=80  a4=90+  a5=77
2503 % For me, subjectively, the few extra characters that fit aren't worth
2504 % the additional smallness of 8pt.  So I'm making the default 9pt.
2505 %
2506 % By the way, for comparison, here's what fits with @example (10pt):
2507 %   8.5x11=71  smallbook=60  a4=75  a5=58
2508 % --karl, 24jan03.
2509
2510 % Set up the default fonts, so we can use them for creating boxes.
2511 %
2512 \definetextfontsizexi
2513
2514
2515 \message{markup,}
2516
2517 % Check if we are currently using a typewriter font.  Since all the
2518 % Computer Modern typewriter fonts have zero interword stretch (and
2519 % shrink), and it is reasonable to expect all typewriter fonts to have
2520 % this property, we can check that font parameter.
2521 %
2522 \def\ifmonospace{\ifdim\fontdimen3\font=0pt }
2523
2524 % Markup style infrastructure.  \defmarkupstylesetup\INITMACRO will
2525 % define and register \INITMACRO to be called on markup style changes.
2526 % \INITMACRO can check \currentmarkupstyle for the innermost
2527 % style and the set of \ifmarkupSTYLE switches for all styles
2528 % currently in effect.
2529 \newif\ifmarkupvar
2530 \newif\ifmarkupsamp
2531 \newif\ifmarkupkey
2532 %\newif\ifmarkupfile % @file == @samp.
2533 %\newif\ifmarkupoption % @option == @samp.
2534 \newif\ifmarkupcode
2535 \newif\ifmarkupkbd
2536 %\newif\ifmarkupenv % @env == @code.
2537 %\newif\ifmarkupcommand % @command == @code.
2538 \newif\ifmarkuptex % @tex (and part of @math, for now).
2539 \newif\ifmarkupexample
2540 \newif\ifmarkupverb
2541 \newif\ifmarkupverbatim
2542
2543 \let\currentmarkupstyle\empty
2544
2545 \def\setupmarkupstyle#1{%
2546   \csname markup#1true\endcsname
2547   \def\currentmarkupstyle{#1}%
2548   \markupstylesetup
2549 }
2550
2551 \let\markupstylesetup\empty
2552
2553 \def\defmarkupstylesetup#1{%
2554   \expandafter\def\expandafter\markupstylesetup
2555     \expandafter{\markupstylesetup #1}%
2556   \def#1%
2557 }
2558
2559 % Markup style setup for left and right quotes.
2560 \defmarkupstylesetup\markupsetuplq{%
2561   \expandafter\let\expandafter \temp
2562     \csname markupsetuplq\currentmarkupstyle\endcsname
2563   \ifx\temp\relax \markupsetuplqdefault \else \temp \fi
2564 }
2565
2566 \defmarkupstylesetup\markupsetuprq{%
2567   \expandafter\let\expandafter \temp
2568     \csname markupsetuprq\currentmarkupstyle\endcsname
2569   \ifx\temp\relax \markupsetuprqdefault \else \temp \fi
2570 }
2571
2572 {
2573 \catcode`\'=\active
2574 \catcode`\`=\active
2575
2576 \gdef\markupsetuplqdefault{\let`\lq}
2577 \gdef\markupsetuprqdefault{\let'\rq}
2578
2579 \gdef\markupsetcodequoteleft{\let`\codequoteleft}
2580 \gdef\markupsetcodequoteright{\let'\codequoteright}
2581 }
2582
2583 \let\markupsetuplqcode \markupsetcodequoteleft
2584 \let\markupsetuprqcode \markupsetcodequoteright
2585 %
2586 \let\markupsetuplqexample \markupsetcodequoteleft
2587 \let\markupsetuprqexample \markupsetcodequoteright
2588 %
2589 \let\markupsetuplqkbd     \markupsetcodequoteleft
2590 \let\markupsetuprqkbd     \markupsetcodequoteright
2591 %
2592 \let\markupsetuplqsamp \markupsetcodequoteleft
2593 \let\markupsetuprqsamp \markupsetcodequoteright
2594 %
2595 \let\markupsetuplqverb \markupsetcodequoteleft
2596 \let\markupsetuprqverb \markupsetcodequoteright
2597 %
2598 \let\markupsetuplqverbatim \markupsetcodequoteleft
2599 \let\markupsetuprqverbatim \markupsetcodequoteright
2600
2601 % Allow an option to not use regular directed right quote/apostrophe
2602 % (char 0x27), but instead the undirected quote from cmtt (char 0x0d).
2603 % The undirected quote is ugly, so don't make it the default, but it
2604 % works for pasting with more pdf viewers (at least evince), the
2605 % lilypond developers report.  xpdf does work with the regular 0x27.
2606 %
2607 \def\codequoteright{%
2608   \expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax
2609     \expandafter\ifx\csname SETcodequoteundirected\endcsname\relax
2610       '%
2611     \else \char'15 \fi
2612   \else \char'15 \fi
2613 }
2614 %
2615 % and a similar option for the left quote char vs. a grave accent.
2616 % Modern fonts display ASCII 0x60 as a grave accent, so some people like
2617 % the code environments to do likewise.
2618 %
2619 \def\codequoteleft{%
2620   \expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax
2621     \expandafter\ifx\csname SETcodequotebacktick\endcsname\relax
2622       % [Knuth] pp. 380,381,391
2623       % \relax disables Spanish ligatures ?` and !` of \tt font.
2624       \relax`%
2625     \else \char'22 \fi
2626   \else \char'22 \fi
2627 }
2628
2629 % Commands to set the quote options.
2630
2631 \parseargdef\codequoteundirected{%
2632   \def\temp{#1}%
2633   \ifx\temp\onword
2634     \expandafter\let\csname SETtxicodequoteundirected\endcsname
2635       = t%
2636   \else\ifx\temp\offword
2637     \expandafter\let\csname SETtxicodequoteundirected\endcsname
2638       = \relax
2639   \else
2640     \errhelp = \EMsimple
2641     \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}%
2642   \fi\fi
2643 }
2644 %
2645 \parseargdef\codequotebacktick{%
2646   \def\temp{#1}%
2647   \ifx\temp\onword
2648     \expandafter\let\csname SETtxicodequotebacktick\endcsname
2649       = t%
2650   \else\ifx\temp\offword
2651     \expandafter\let\csname SETtxicodequotebacktick\endcsname
2652       = \relax
2653   \else
2654     \errhelp = \EMsimple
2655     \errmessage{Unknown @codequotebacktick value `\temp', must be on|off}%
2656   \fi\fi
2657 }
2658
2659 % [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font.
2660 \def\noligaturesquoteleft{\relax\lq}
2661
2662 % Count depth in font-changes, for error checks
2663 \newcount\fontdepth \fontdepth=0
2664
2665 % Font commands.
2666
2667 % #1 is the font command (\sl or \it), #2 is the text to slant.
2668 % If we are in a monospaced environment, however, 1) always use \ttsl,
2669 % and 2) do not add an italic correction.
2670 \def\dosmartslant#1#2{%
2671   \ifusingtt 
2672     {{\ttsl #2}\let\next=\relax}%
2673     {\def\next{{#1#2}\futurelet\next\smartitaliccorrection}}%
2674   \next
2675 }
2676 \def\smartslanted{\dosmartslant\sl}
2677 \def\smartitalic{\dosmartslant\it}
2678
2679 % Output an italic correction unless \next (presumed to be the following
2680 % character) is such as not to need one.
2681 \def\smartitaliccorrection{%
2682   \ifx\next,%
2683   \else\ifx\next-%
2684   \else\ifx\next.%
2685   \else\ifx\next\.%
2686   \else\ifx\next\comma%
2687   \else\ptexslash
2688   \fi\fi\fi\fi\fi
2689   \aftersmartic
2690 }
2691
2692 % Unconditional use \ttsl, and no ic.  @var is set to this for defuns.
2693 \def\ttslanted#1{{\ttsl #1}}
2694
2695 % @cite is like \smartslanted except unconditionally use \sl.  We never want
2696 % ttsl for book titles, do we?
2697 \def\cite#1{{\sl #1}\futurelet\next\smartitaliccorrection}
2698
2699 \def\aftersmartic{}
2700 \def\var#1{%
2701   \let\saveaftersmartic = \aftersmartic
2702   \def\aftersmartic{\null\let\aftersmartic=\saveaftersmartic}%
2703   \smartslanted{#1}%
2704 }
2705
2706 \let\i=\smartitalic
2707 \let\slanted=\smartslanted
2708 \let\dfn=\smartslanted
2709 \let\emph=\smartitalic
2710
2711 % Explicit font changes: @r, @sc, undocumented @ii.
2712 \def\r#1{{\rm #1}}              % roman font
2713 \def\sc#1{{\smallcaps#1}}       % smallcaps font
2714 \def\ii#1{{\it #1}}             % italic font
2715
2716 % @b, explicit bold.  Also @strong.
2717 \def\b#1{{\bf #1}}
2718 \let\strong=\b
2719
2720 % @sansserif, explicit sans.
2721 \def\sansserif#1{{\sf #1}}
2722
2723 % We can't just use \exhyphenpenalty, because that only has effect at
2724 % the end of a paragraph.  Restore normal hyphenation at the end of the
2725 % group within which \nohyphenation is presumably called.
2726 %
2727 \def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
2728 \def\restorehyphenation{\hyphenchar\font = `- }
2729
2730 % Set sfcode to normal for the chars that usually have another value.
2731 % Can't use plain's \frenchspacing because it uses the `\x notation, and
2732 % sometimes \x has an active definition that messes things up.
2733 %
2734 \catcode`@=11
2735   \def\plainfrenchspacing{%
2736     \sfcode`\.=\@m \sfcode`\?=\@m \sfcode`\!=\@m
2737     \sfcode`\:=\@m \sfcode`\;=\@m \sfcode`\,=\@m
2738     \def\endofsentencespacefactor{1000}% for @. and friends
2739   }
2740   \def\plainnonfrenchspacing{%
2741     \sfcode`\.3000\sfcode`\?3000\sfcode`\!3000
2742     \sfcode`\:2000\sfcode`\;1500\sfcode`\,1250
2743     \def\endofsentencespacefactor{3000}% for @. and friends
2744   }
2745 \catcode`@=\other
2746 \def\endofsentencespacefactor{3000}% default
2747
2748 % @t, explicit typewriter.
2749 \def\t#1{%
2750   {\tt \rawbackslash \plainfrenchspacing #1}%
2751   \null
2752 }
2753
2754 % @samp.
2755 \def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}}
2756
2757 % @indicateurl is \samp, that is, with quotes.
2758 \let\indicateurl=\samp
2759
2760 % @code (and similar) prints in typewriter, but with spaces the same
2761 % size as normal in the surrounding text, without hyphenation, etc.
2762 % This is a subroutine for that.
2763 \def\tclose#1{%
2764   {%
2765     % Change normal interword space to be same as for the current font.
2766     \spaceskip = \fontdimen2\font
2767     %
2768     % Switch to typewriter.
2769     \tt
2770     %
2771     % But `\ ' produces the large typewriter interword space.
2772     \def\ {{\spaceskip = 0pt{} }}%
2773     %
2774     % Turn off hyphenation.
2775     \nohyphenation
2776     %
2777     \rawbackslash
2778     \plainfrenchspacing
2779     #1%
2780   }%
2781   \null % reset spacefactor to 1000
2782 }
2783
2784 % We *must* turn on hyphenation at `-' and `_' in @code.
2785 % (But see \codedashfinish below.)
2786 % Otherwise, it is too hard to avoid overfull hboxes
2787 % in the Emacs manual, the Library manual, etc.
2788 %
2789 % Unfortunately, TeX uses one parameter (\hyphenchar) to control
2790 % both hyphenation at - and hyphenation within words.
2791 % We must therefore turn them both off (\tclose does that)
2792 % and arrange explicitly to hyphenate at a dash. -- rms.
2793 {
2794   \catcode`\-=\active \catcode`\_=\active
2795   \catcode`\'=\active \catcode`\`=\active
2796   \global\let'=\rq \global\let`=\lq  % default definitions
2797   %
2798   \global\def\code{\begingroup
2799     \setupmarkupstyle{code}%
2800     % The following should really be moved into \setupmarkupstyle handlers.
2801     \catcode\dashChar=\active  \catcode\underChar=\active
2802     \ifallowcodebreaks
2803      \let-\codedash
2804      \let_\codeunder
2805     \else
2806      \let-\normaldash
2807      \let_\realunder
2808     \fi
2809     % Given -foo (with a single dash), we do not want to allow a break
2810     % after the hyphen.
2811     \global\let\codedashprev=\codedash
2812     %
2813     \codex
2814   }
2815   %
2816   \gdef\codedash{\futurelet\next\codedashfinish}
2817   \gdef\codedashfinish{%
2818     \normaldash % always output the dash character itself.
2819     % 
2820     % Now, output a discretionary to allow a line break, unless
2821     % (a) the next character is a -, or
2822     % (b) the preceding character is a -.
2823     % E.g., given --posix, we do not want to allow a break after either -.
2824     % Given --foo-bar, we do want to allow a break between the - and the b.
2825     \ifx\next\codedash \else
2826       \ifx\codedashprev\codedash 
2827       \else \discretionary{}{}{}\fi
2828     \fi
2829     % we need the space after the = for the case when \next itself is a
2830     % space token; it would get swallowed otherwise.  As in @code{- a}.
2831     \global\let\codedashprev= \next
2832   }
2833 }
2834 \def\normaldash{-}
2835 %
2836 \def\codex #1{\tclose{#1}\endgroup}
2837
2838 \def\codeunder{%
2839   % this is all so @math{@code{var_name}+1} can work.  In math mode, _
2840   % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
2841   % will therefore expand the active definition of _, which is us
2842   % (inside @code that is), therefore an endless loop.
2843   \ifusingtt{\ifmmode
2844                \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
2845              \else\normalunderscore \fi
2846              \discretionary{}{}{}}%
2847             {\_}%
2848 }
2849
2850 % An additional complication: the above will allow breaks after, e.g.,
2851 % each of the four underscores in __typeof__.  This is bad.
2852 % @allowcodebreaks provides a document-level way to turn breaking at -
2853 % and _ on and off.
2854 %
2855 \newif\ifallowcodebreaks  \allowcodebreakstrue
2856
2857 \def\keywordtrue{true}
2858 \def\keywordfalse{false}
2859
2860 \parseargdef\allowcodebreaks{%
2861   \def\txiarg{#1}%
2862   \ifx\txiarg\keywordtrue
2863     \allowcodebreakstrue
2864   \else\ifx\txiarg\keywordfalse
2865     \allowcodebreaksfalse
2866   \else
2867     \errhelp = \EMsimple
2868     \errmessage{Unknown @allowcodebreaks option `\txiarg', must be true|false}%
2869   \fi\fi
2870 }
2871
2872 % For @command, @env, @file, @option quotes seem unnecessary,
2873 % so use \code rather than \samp.
2874 \let\command=\code
2875 \let\env=\code
2876 \let\file=\code
2877 \let\option=\code
2878
2879 % @uref (abbreviation for `urlref') aka @url takes an optional
2880 % (comma-separated) second argument specifying the text to display and
2881 % an optional third arg as text to display instead of (rather than in
2882 % addition to) the url itself.  First (mandatory) arg is the url.
2883
2884 % TeX-only option to allow changing PDF output to show only the second
2885 % arg (if given), and not the url (which is then just the link target).
2886 \newif\ifurefurlonlylink
2887
2888 % The main macro is \urefbreak, which allows breaking at expected
2889 % places within the url.  (There used to be another version, which
2890 % didn't support automatic breaking.)
2891 \def\urefbreak{\begingroup \urefcatcodes \dourefbreak}
2892 \let\uref=\urefbreak
2893 %
2894 \def\dourefbreak#1{\urefbreakfinish #1,,,\finish}
2895 \def\urefbreakfinish#1,#2,#3,#4\finish{% doesn't work in @example
2896   \unsepspaces
2897   \pdfurl{#1}%
2898   \setbox0 = \hbox{\ignorespaces #3}%
2899   \ifdim\wd0 > 0pt
2900     \unhbox0 % third arg given, show only that
2901   \else
2902     \setbox0 = \hbox{\ignorespaces #2}% look for second arg
2903     \ifdim\wd0 > 0pt
2904       \ifpdf
2905         % For pdfTeX and LuaTeX
2906         \ifurefurlonlylink
2907           % PDF plus option to not display url, show just arg
2908           \unhbox0             
2909         \else
2910           % PDF, normally display both arg and url for consistency,
2911           % visibility, if the pdf is eventually used to print, etc.
2912           \unhbox0\ (\urefcode{#1})%
2913         \fi
2914       \else
2915         \ifx\XeTeXrevision\thisisundefined
2916           \unhbox0\ (\urefcode{#1})% DVI, always show arg and url
2917         \else
2918           % For XeTeX
2919           \ifurefurlonlylink
2920             % PDF plus option to not display url, show just arg
2921             \unhbox0             
2922           \else
2923             % PDF, normally display both arg and url for consistency,
2924             % visibility, if the pdf is eventually used to print, etc.
2925             \unhbox0\ (\urefcode{#1})%
2926           \fi
2927         \fi
2928       \fi
2929     \else
2930       \urefcode{#1}% only url given, so show it
2931     \fi
2932   \fi
2933   \endlink
2934 \endgroup}
2935
2936 % Allow line breaks around only a few characters (only).
2937 \def\urefcatcodes{%
2938   \catcode`\&=\active \catcode`\.=\active
2939   \catcode`\#=\active \catcode`\?=\active
2940   \catcode`\/=\active
2941 }
2942 {
2943   \urefcatcodes
2944   %
2945   \global\def\urefcode{\begingroup
2946     \setupmarkupstyle{code}%
2947     \urefcatcodes
2948     \let&\urefcodeamp
2949     \let.\urefcodedot
2950     \let#\urefcodehash
2951     \let?\urefcodequest
2952     \let/\urefcodeslash
2953     \codex
2954   }
2955   %
2956   % By default, they are just regular characters.
2957   \global\def&{\normalamp}
2958   \global\def.{\normaldot}
2959   \global\def#{\normalhash}
2960   \global\def?{\normalquest}
2961   \global\def/{\normalslash}
2962 }
2963
2964 % we put a little stretch before and after the breakable chars, to help
2965 % line breaking of long url's.  The unequal skips make look better in
2966 % cmtt at least, especially for dots.
2967 \def\urefprestretchamount{.13em}
2968 \def\urefpoststretchamount{.1em}
2969 \def\urefprestretch{\urefprebreak \hskip0pt plus\urefprestretchamount\relax}
2970 \def\urefpoststretch{\urefpostbreak \hskip0pt plus\urefprestretchamount\relax}
2971 %
2972 \def\urefcodeamp{\urefprestretch \&\urefpoststretch}
2973 \def\urefcodedot{\urefprestretch .\urefpoststretch}
2974 \def\urefcodehash{\urefprestretch \#\urefpoststretch}
2975 \def\urefcodequest{\urefprestretch ?\urefpoststretch}
2976 \def\urefcodeslash{\futurelet\next\urefcodeslashfinish}
2977 {
2978   \catcode`\/=\active
2979   \global\def\urefcodeslashfinish{%
2980     \urefprestretch \slashChar
2981     % Allow line break only after the final / in a sequence of
2982     % slashes, to avoid line break between the slashes in http://.
2983     \ifx\next/\else \urefpoststretch \fi
2984   }
2985 }
2986
2987 % One more complication: by default we'll break after the special
2988 % characters, but some people like to break before the special chars, so
2989 % allow that.  Also allow no breaking at all, for manual control.
2990
2991 \parseargdef\urefbreakstyle{%
2992   \def\txiarg{#1}%
2993   \ifx\txiarg\wordnone
2994     \def\urefprebreak{\nobreak}\def\urefpostbreak{\nobreak}
2995   \else\ifx\txiarg\wordbefore
2996     \def\urefprebreak{\allowbreak}\def\urefpostbreak{\nobreak}
2997   \else\ifx\txiarg\wordafter
2998     \def\urefprebreak{\nobreak}\def\urefpostbreak{\allowbreak}
2999   \else
3000     \errhelp = \EMsimple
3001     \errmessage{Unknown @urefbreakstyle setting `\txiarg'}%
3002   \fi\fi\fi
3003 }
3004 \def\wordafter{after}
3005 \def\wordbefore{before}
3006 \def\wordnone{none}
3007
3008 \urefbreakstyle after
3009
3010 % @url synonym for @uref, since that's how everyone uses it.
3011 %
3012 \let\url=\uref
3013
3014 % rms does not like angle brackets --karl, 17may97.
3015 % So now @email is just like @uref, unless we are pdf.
3016 %
3017 %\def\email#1{\angleleft{\tt #1}\angleright}
3018 \ifpdf
3019   \def\email#1{\doemail#1,,\finish}
3020   \def\doemail#1,#2,#3\finish{\begingroup
3021     \unsepspaces
3022     \pdfurl{mailto:#1}%
3023     \setbox0 = \hbox{\ignorespaces #2}%
3024     \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3025     \endlink
3026   \endgroup}
3027 \else
3028   \ifx\XeTeXrevision\thisisundefined
3029     \let\email=\uref
3030   \else
3031     \def\email#1{\doemail#1,,\finish}
3032     \def\doemail#1,#2,#3\finish{\begingroup
3033       \unsepspaces
3034       \pdfurl{mailto:#1}%
3035       \setbox0 = \hbox{\ignorespaces #2}%
3036       \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3037       \endlink
3038     \endgroup}
3039   \fi
3040 \fi
3041
3042 % @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
3043 %   `example' (@kbd uses ttsl only inside of @example and friends),
3044 %   or `code' (@kbd uses normal tty font always).
3045 \parseargdef\kbdinputstyle{%
3046   \def\txiarg{#1}%
3047   \ifx\txiarg\worddistinct
3048     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
3049   \else\ifx\txiarg\wordexample
3050     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
3051   \else\ifx\txiarg\wordcode
3052     \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
3053   \else
3054     \errhelp = \EMsimple
3055     \errmessage{Unknown @kbdinputstyle setting `\txiarg'}%
3056   \fi\fi\fi
3057 }
3058 \def\worddistinct{distinct}
3059 \def\wordexample{example}
3060 \def\wordcode{code}
3061
3062 % Default is `distinct'.
3063 \kbdinputstyle distinct
3064
3065 % @kbd is like @code, except that if the argument is just one @key command,
3066 % then @kbd has no effect.
3067 \def\kbd#1{{\def\look{#1}\expandafter\kbdsub\look??\par}}
3068
3069 \def\xkey{\key}
3070 \def\kbdsub#1#2#3\par{%
3071   \def\one{#1}\def\three{#3}\def\threex{??}%
3072   \ifx\one\xkey\ifx\threex\three \key{#2}%
3073   \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3074   \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3075 }
3076
3077 % definition of @key that produces a lozenge.  Doesn't adjust to text size.
3078 %\setfont\keyrm\rmshape{8}{1000}{OT1}
3079 %\font\keysy=cmsy9
3080 %\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
3081 %  \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
3082 %    \vbox{\hrule\kern-0.4pt
3083 %     \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
3084 %    \kern-0.4pt\hrule}%
3085 %  \kern-.06em\raise0.4pt\hbox{\angleright}}}}
3086
3087 % definition of @key with no lozenge.  If the current font is already
3088 % monospace, don't change it; that way, we respect @kbdinputstyle.  But
3089 % if it isn't monospace, then use \tt.
3090 %
3091 \def\key#1{{\setupmarkupstyle{key}%
3092   \nohyphenation
3093   \ifmonospace\else\tt\fi
3094   #1}\null}
3095
3096 % @clicksequence{File @click{} Open ...}
3097 \def\clicksequence#1{\begingroup #1\endgroup}
3098
3099 % @clickstyle @arrow   (by default)
3100 \parseargdef\clickstyle{\def\click{#1}}
3101 \def\click{\arrow}
3102
3103 % Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
3104 % argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
3105 %
3106 \def\dmn#1{\thinspace #1}
3107
3108 % @acronym for "FBI", "NATO", and the like.
3109 % We print this one point size smaller, since it's intended for
3110 % all-uppercase.
3111 %
3112 \def\acronym#1{\doacronym #1,,\finish}
3113 \def\doacronym#1,#2,#3\finish{%
3114   {\selectfonts\lsize #1}%
3115   \def\temp{#2}%
3116   \ifx\temp\empty \else
3117     \space ({\unsepspaces \ignorespaces \temp \unskip})%
3118   \fi
3119   \null % reset \spacefactor=1000
3120 }
3121
3122 % @abbr for "Comput. J." and the like.
3123 % No font change, but don't do end-of-sentence spacing.
3124 %
3125 \def\abbr#1{\doabbr #1,,\finish}
3126 \def\doabbr#1,#2,#3\finish{%
3127   {\plainfrenchspacing #1}%
3128   \def\temp{#2}%
3129   \ifx\temp\empty \else
3130     \space ({\unsepspaces \ignorespaces \temp \unskip})%
3131   \fi
3132   \null % reset \spacefactor=1000
3133 }
3134
3135 % @asis just yields its argument.  Used with @table, for example.
3136 %
3137 \def\asis#1{#1}
3138
3139 % @math outputs its argument in math mode.
3140 %
3141 % One complication: _ usually means subscripts, but it could also mean
3142 % an actual _ character, as in @math{@var{some_variable} + 1}.  So make
3143 % _ active, and distinguish by seeing if the current family is \slfam,
3144 % which is what @var uses.
3145 {
3146   \catcode`\_ = \active
3147   \gdef\mathunderscore{%
3148     \catcode`\_=\active
3149     \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
3150   }
3151 }
3152 % Another complication: we want \\ (and @\) to output a math (or tt) \.
3153 % FYI, plain.tex uses \\ as a temporary control sequence (for no
3154 % particular reason), but this is not advertised and we don't care.
3155 %
3156 % The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
3157 \def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
3158 %
3159 \def\math{%
3160   \ifmmode\else % only go into math if not in math mode already
3161     \tex
3162     \mathunderscore
3163     \let\\ = \mathbackslash
3164     \mathactive
3165     % make the texinfo accent commands work in math mode
3166     \let\"=\ddot
3167     \let\'=\acute
3168     \let\==\bar
3169     \let\^=\hat
3170     \let\`=\grave
3171     \let\u=\breve
3172     \let\v=\check
3173     \let\~=\tilde
3174     \let\dotaccent=\dot
3175     % have to provide another name for sup operator
3176     \let\mathopsup=\sup
3177   $\expandafter\finishmath\fi
3178 }
3179 \def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
3180
3181 % Some active characters (such as <) are spaced differently in math.
3182 % We have to reset their definitions in case the @math was an argument
3183 % to a command which sets the catcodes (such as @item or @section).
3184 %
3185 {
3186   \catcode`^ = \active
3187   \catcode`< = \active
3188   \catcode`> = \active
3189   \catcode`+ = \active
3190   \catcode`' = \active
3191   \gdef\mathactive{%
3192     \let^ = \ptexhat
3193     \let< = \ptexless
3194     \let> = \ptexgtr
3195     \let+ = \ptexplus
3196     \let' = \ptexquoteright
3197   }
3198 }
3199
3200 % for @sub and @sup, if in math mode, just do a normal sub/superscript.
3201 % If in text, use math to place as sub/superscript, but switch
3202 % into text mode, with smaller fonts.  This is a different font than the
3203 % one used for real math sub/superscripts (8pt vs. 7pt), but let's not
3204 % fix it (significant additions to font machinery) until someone notices.
3205 %
3206 \def\sub{\ifmmode \expandafter\sb \else \expandafter\finishsub\fi}
3207 \def\finishsub#1{$\sb{\hbox{\selectfonts\lllsize #1}}$}%
3208 %
3209 \def\sup{\ifmmode \expandafter\ptexsp \else \expandafter\finishsup\fi}
3210 \def\finishsup#1{$\ptexsp{\hbox{\selectfonts\lllsize #1}}$}%
3211
3212 % @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}.
3213 % Ignore unless FMTNAME == tex; then it is like @iftex and @tex,
3214 % except specified as a normal braced arg, so no newlines to worry about.
3215
3216 \def\outfmtnametex{tex}
3217 %
3218 \long\def\inlinefmt#1{\doinlinefmt #1,\finish}
3219 \long\def\doinlinefmt#1,#2,\finish{%
3220   \def\inlinefmtname{#1}%
3221   \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\fi
3222 }
3223
3224 % @inlinefmtifelse{FMTNAME,THEN-TEXT,ELSE-TEXT} expands THEN-TEXT if
3225 % FMTNAME is tex, else ELSE-TEXT.
3226 \long\def\inlinefmtifelse#1{\doinlinefmtifelse #1,,,\finish}
3227 \long\def\doinlinefmtifelse#1,#2,#3,#4,\finish{%
3228   \def\inlinefmtname{#1}%
3229   \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\else \ignorespaces #3\fi
3230 }
3231 %
3232 % For raw, must switch into @tex before parsing the argument, to avoid
3233 % setting catcodes prematurely.  Doing it this way means that, for
3234 % example, @inlineraw{html, foo{bar} gets a parse error instead of being
3235 % ignored.  But this isn't important because if people want a literal
3236 % *right* brace they would have to use a command anyway, so they may as
3237 % well use a command to get a left brace too.  We could re-use the
3238 % delimiter character idea from \verb, but it seems like overkill.
3239
3240 \long\def\inlineraw{\tex \doinlineraw}
3241 \long\def\doinlineraw#1{\doinlinerawtwo #1,\finish}
3242 \def\doinlinerawtwo#1,#2,\finish{%
3243   \def\inlinerawname{#1}%
3244   \ifx\inlinerawname\outfmtnametex \ignorespaces #2\fi
3245   \endgroup % close group opened by \tex.
3246 }
3247
3248 % @inlineifset{VAR, TEXT} expands TEXT if VAR is @set.
3249 %
3250 \long\def\inlineifset#1{\doinlineifset #1,\finish}
3251 \long\def\doinlineifset#1,#2,\finish{%
3252   \def\inlinevarname{#1}%
3253   \expandafter\ifx\csname SET\inlinevarname\endcsname\relax
3254   \else\ignorespaces#2\fi
3255 }
3256
3257 % @inlineifclear{VAR, TEXT} expands TEXT if VAR is not @set.
3258 %
3259 \long\def\inlineifclear#1{\doinlineifclear #1,\finish}
3260 \long\def\doinlineifclear#1,#2,\finish{%
3261   \def\inlinevarname{#1}%
3262   \expandafter\ifx\csname SET\inlinevarname\endcsname\relax \ignorespaces#2\fi
3263 }
3264
3265
3266 \message{glyphs,}
3267 % and logos.
3268
3269 % @@ prints an @, as does @atchar{}.
3270 \def\@{\char64 }
3271 \let\atchar=\@
3272
3273 % @{ @} @lbracechar{} @rbracechar{} all generate brace characters.
3274 % Unless we're in typewriter, use \ecfont because the CM text fonts do
3275 % not have braces, and we don't want to switch into math.
3276 \def\mylbrace{{\ifmonospace\char123\else\ensuremath\lbrace\fi}}
3277 \def\myrbrace{{\ifmonospace\char125\else\ensuremath\rbrace\fi}}
3278 \let\{=\mylbrace \let\lbracechar=\{
3279 \let\}=\myrbrace \let\rbracechar=\}
3280 \begingroup
3281   % Definitions to produce \{ and \} commands for indices,
3282   % and @{ and @} for the aux/toc files.
3283   \catcode`\{ = \other \catcode`\} = \other
3284   \catcode`\[ = 1 \catcode`\] = 2
3285   \catcode`\! = 0 \catcode`\\ = \other
3286   !gdef!lbracecmd[\{]%
3287   !gdef!rbracecmd[\}]%
3288   !gdef!lbraceatcmd[@{]%
3289   !gdef!rbraceatcmd[@}]%
3290 !endgroup
3291
3292 % @comma{} to avoid , parsing problems.
3293 \let\comma = ,
3294
3295 % Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
3296 % Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
3297 \let\, = \ptexc
3298 \let\dotaccent = \ptexdot
3299 \def\ringaccent#1{{\accent23 #1}}
3300 \let\tieaccent = \ptext
3301 \let\ubaraccent = \ptexb
3302 \let\udotaccent = \d
3303
3304 % Other special characters: @questiondown @exclamdown @ordf @ordm
3305 % Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
3306 \def\questiondown{?`}
3307 \def\exclamdown{!`}
3308 \def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
3309 \def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
3310
3311 % Dotless i and dotless j, used for accents.
3312 \def\imacro{i}
3313 \def\jmacro{j}
3314 \def\dotless#1{%
3315   \def\temp{#1}%
3316   \ifx\temp\imacro \ifmmode\imath \else\ptexi \fi
3317   \else\ifx\temp\jmacro \ifmmode\jmath \else\j \fi
3318   \else \errmessage{@dotless can be used only with i or j}%
3319   \fi\fi
3320 }
3321
3322 % The \TeX{} logo, as in plain, but resetting the spacing so that a
3323 % period following counts as ending a sentence.  (Idea found in latex.)
3324 %
3325 \edef\TeX{\TeX \spacefactor=1000 }
3326
3327 % @LaTeX{} logo.  Not quite the same results as the definition in
3328 % latex.ltx, since we use a different font for the raised A; it's most
3329 % convenient for us to use an explicitly smaller font, rather than using
3330 % the \scriptstyle font (since we don't reset \scriptstyle and
3331 % \scriptscriptstyle).
3332 %
3333 \def\LaTeX{%
3334   L\kern-.36em
3335   {\setbox0=\hbox{T}%
3336    \vbox to \ht0{\hbox{%
3337      \ifx\textnominalsize\xwordpt
3338        % for 10pt running text, \lllsize (8pt) is too small for the A in LaTeX.
3339        % Revert to plain's \scriptsize, which is 7pt.
3340        \count255=\the\fam $\fam\count255 \scriptstyle A$%
3341      \else
3342        % For 11pt, we can use our lllsize.
3343        \selectfonts\lllsize A%
3344      \fi
3345      }%
3346      \vss
3347   }}%
3348   \kern-.15em
3349   \TeX
3350 }
3351
3352 % Some math mode symbols.  Define \ensuremath to switch into math mode
3353 % unless we are already there.  Expansion tricks may not be needed here,
3354 % but safer, and can't hurt.
3355 \def\ensuremath{\ifmmode \expandafter\asis \else\expandafter\ensuredmath \fi}
3356 \def\ensuredmath#1{$\relax#1$}
3357 %
3358 \def\bullet{\ensuremath\ptexbullet}
3359 \def\geq{\ensuremath\ge}
3360 \def\leq{\ensuremath\le}
3361 \def\minus{\ensuremath-}
3362
3363 % @dots{} outputs an ellipsis using the current font.
3364 % We do .5em per period so that it has the same spacing in the cm
3365 % typewriter fonts as three actual period characters; on the other hand,
3366 % in other typewriter fonts three periods are wider than 1.5em.  So do
3367 % whichever is larger.
3368 %
3369 \def\dots{%
3370   \leavevmode
3371   \setbox0=\hbox{...}% get width of three periods
3372   \ifdim\wd0 > 1.5em
3373     \dimen0 = \wd0
3374   \else
3375     \dimen0 = 1.5em
3376   \fi
3377   \hbox to \dimen0{%
3378     \hskip 0pt plus.25fil
3379     .\hskip 0pt plus1fil
3380     .\hskip 0pt plus1fil
3381     .\hskip 0pt plus.5fil
3382   }%
3383 }
3384
3385 % @enddots{} is an end-of-sentence ellipsis.
3386 %
3387 \def\enddots{%
3388   \dots
3389   \spacefactor=\endofsentencespacefactor
3390 }
3391
3392 % @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
3393 %
3394 % Since these characters are used in examples, they should be an even number of
3395 % \tt widths. Each \tt character is 1en, so two makes it 1em.
3396 %
3397 \def\point{$\star$}
3398 \def\arrow{\leavevmode\raise.05ex\hbox to 1em{\hfil$\rightarrow$\hfil}}
3399 \def\result{\leavevmode\raise.05ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
3400 \def\expansion{\leavevmode\hbox to 1em{\hfil$\mapsto$\hfil}}
3401 \def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
3402 \def\equiv{\leavevmode\hbox to 1em{\hfil$\ptexequiv$\hfil}}
3403
3404 % The @error{} command.
3405 % Adapted from the TeXbook's \boxit.
3406 %
3407 \newbox\errorbox
3408 %
3409 {\tentt \global\dimen0 = 3em}% Width of the box.
3410 \dimen2 = .55pt % Thickness of rules
3411 % The text. (`r' is open on the right, `e' somewhat less so on the left.)
3412 \setbox0 = \hbox{\kern-.75pt \reducedsf \putworderror\kern-1.5pt}
3413 %
3414 \setbox\errorbox=\hbox to \dimen0{\hfil
3415    \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
3416    \advance\hsize by -2\dimen2 % Rules.
3417    \vbox{%
3418       \hrule height\dimen2
3419       \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
3420          \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
3421          \kern3pt\vrule width\dimen2}% Space to right.
3422       \hrule height\dimen2}
3423     \hfil}
3424 %
3425 \def\error{\leavevmode\lower.7ex\copy\errorbox}
3426
3427 % @pounds{} is a sterling sign, which Knuth put in the CM italic font.
3428 %
3429 \def\pounds{{\it\$}}
3430
3431 % @euro{} comes from a separate font, depending on the current style.
3432 % We use the free feym* fonts from the eurosym package by Henrik
3433 % Theiling, which support regular, slanted, bold and bold slanted (and
3434 % "outlined" (blackboard board, sort of) versions, which we don't need).
3435 % It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
3436 %
3437 % Although only regular is the truly official Euro symbol, we ignore
3438 % that.  The Euro is designed to be slightly taller than the regular
3439 % font height.
3440 %
3441 % feymr - regular
3442 % feymo - slanted
3443 % feybr - bold
3444 % feybo - bold slanted
3445 %
3446 % There is no good (free) typewriter version, to my knowledge.
3447 % A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
3448 % Hmm.
3449 %
3450 % Also doesn't work in math.  Do we need to do math with euro symbols?
3451 % Hope not.
3452 %
3453 %
3454 \def\euro{{\eurofont e}}
3455 \def\eurofont{%
3456   % We set the font at each command, rather than predefining it in
3457   % \textfonts and the other font-switching commands, so that
3458   % installations which never need the symbol don't have to have the
3459   % font installed.
3460   %
3461   % There is only one designed size (nominal 10pt), so we always scale
3462   % that to the current nominal size.
3463   %
3464   % By the way, simply using "at 1em" works for cmr10 and the like, but
3465   % does not work for cmbx10 and other extended/shrunken fonts.
3466   %
3467   \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
3468   %
3469   \ifx\curfontstyle\bfstylename
3470     % bold:
3471     \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
3472   \else
3473     % regular:
3474     \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
3475   \fi
3476   \thiseurofont
3477 }
3478
3479 % Glyphs from the EC fonts.  We don't use \let for the aliases, because
3480 % sometimes we redefine the original macro, and the alias should reflect
3481 % the redefinition.
3482 %
3483 % Use LaTeX names for the Icelandic letters.
3484 \def\DH{{\ecfont \char"D0}} % Eth
3485 \def\dh{{\ecfont \char"F0}} % eth
3486 \def\TH{{\ecfont \char"DE}} % Thorn
3487 \def\th{{\ecfont \char"FE}} % thorn
3488 %
3489 \def\guillemetleft{{\ecfont \char"13}}
3490 \def\guillemotleft{\guillemetleft}
3491 \def\guillemetright{{\ecfont \char"14}}
3492 \def\guillemotright{\guillemetright}
3493 \def\guilsinglleft{{\ecfont \char"0E}}
3494 \def\guilsinglright{{\ecfont \char"0F}}
3495 \def\quotedblbase{{\ecfont \char"12}}
3496 \def\quotesinglbase{{\ecfont \char"0D}}
3497 %
3498 % This positioning is not perfect (see the ogonek LaTeX package), but
3499 % we have the precomposed glyphs for the most common cases.  We put the
3500 % tests to use those glyphs in the single \ogonek macro so we have fewer
3501 % dummy definitions to worry about for index entries, etc.
3502 %
3503 % ogonek is also used with other letters in Lithuanian (IOU), but using
3504 % the precomposed glyphs for those is not so easy since they aren't in
3505 % the same EC font.
3506 \def\ogonek#1{{%
3507   \def\temp{#1}%
3508   \ifx\temp\macrocharA\Aogonek
3509   \else\ifx\temp\macrochara\aogonek
3510   \else\ifx\temp\macrocharE\Eogonek
3511   \else\ifx\temp\macrochare\eogonek
3512   \else
3513     \ecfont \setbox0=\hbox{#1}%
3514     \ifdim\ht0=1ex\accent"0C #1%
3515     \else\ooalign{\unhbox0\crcr\hidewidth\char"0C \hidewidth}%
3516     \fi
3517   \fi\fi\fi\fi
3518   }%
3519 }
3520 \def\Aogonek{{\ecfont \char"81}}\def\macrocharA{A}
3521 \def\aogonek{{\ecfont \char"A1}}\def\macrochara{a}
3522 \def\Eogonek{{\ecfont \char"86}}\def\macrocharE{E}
3523 \def\eogonek{{\ecfont \char"A6}}\def\macrochare{e}
3524 %
3525 % Use the European Computer Modern fonts (cm-super in outline format)
3526 % for non-CM glyphs.  That is ec* for regular text and tc* for the text
3527 % companion symbols (LaTeX TS1 encoding).  Both are part of the ec
3528 % package and follow the same conventions.
3529
3530 \def\ecfont{\etcfont{e}}
3531 \def\tcfont{\etcfont{t}}
3532 %
3533 \def\etcfont#1{%
3534   % We can't distinguish serif/sans and italic/slanted, but this
3535   % is used for crude hacks anyway (like adding French and German
3536   % quotes to documents typeset with CM, where we lose kerning), so
3537   % hopefully nobody will notice/care.
3538   \edef\ecsize{\csname\curfontsize ecsize\endcsname}%
3539   \edef\nominalsize{\csname\curfontsize nominalsize\endcsname}%
3540   \ifmonospace
3541     % typewriter:
3542     \font\thisecfont = #1ctt\ecsize \space at \nominalsize
3543   \else
3544     \ifx\curfontstyle\bfstylename
3545       % bold:
3546       \font\thisecfont = #1cb\ifusingit{i}{x}\ecsize \space at \nominalsize
3547     \else
3548       % regular:
3549       \font\thisecfont = #1c\ifusingit{ti}{rm}\ecsize \space at \nominalsize
3550     \fi
3551   \fi
3552   \thisecfont
3553 }
3554
3555 % @registeredsymbol - R in a circle.  The font for the R should really
3556 % be smaller yet, but lllsize is the best we can do for now.
3557 % Adapted from the plain.tex definition of \copyright.
3558 %
3559 \def\registeredsymbol{%
3560   $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
3561                \hfil\crcr\Orb}}%
3562     }$%
3563 }
3564
3565 % @textdegree - the normal degrees sign.
3566 %
3567 \def\textdegree{$^\circ$}
3568
3569 % Laurent Siebenmann reports \Orb undefined with:
3570 %  Textures 1.7.7 (preloaded format=plain 93.10.14)  (68K)  16 APR 2004 02:38
3571 % so we'll define it if necessary.
3572 %
3573 \ifx\Orb\thisisundefined
3574 \def\Orb{\mathhexbox20D}
3575 \fi
3576
3577 % Quotes.
3578 \chardef\quotedblleft="5C
3579 \chardef\quotedblright=`\"
3580 \chardef\quoteleft=`\`
3581 \chardef\quoteright=`\'
3582
3583
3584 \message{page headings,}
3585
3586 \newskip\titlepagetopglue \titlepagetopglue = 1.5in
3587 \newskip\titlepagebottomglue \titlepagebottomglue = 2pc
3588
3589 % First the title page.  Must do @settitle before @titlepage.
3590 \newif\ifseenauthor
3591 \newif\iffinishedtitlepage
3592
3593 % @setcontentsaftertitlepage used to do an implicit @contents or
3594 % @shortcontents after @end titlepage, but it is now obsolete.
3595 \def\setcontentsaftertitlepage{%
3596   \errmessage{@setcontentsaftertitlepage has been removed as a Texinfo
3597               command; move your @contents command if you want the contents
3598               after the title page.}}%
3599 \def\setshortcontentsaftertitlepage{%
3600   \errmessage{@setshortcontentsaftertitlepage has been removed as a Texinfo
3601               command; move your @shortcontents and @contents commands if you 
3602               want the contents after the title page.}}%
3603
3604 \parseargdef\shorttitlepage{%
3605   \begingroup \hbox{}\vskip 1.5in \chaprm \centerline{#1}%
3606   \endgroup\page\hbox{}\page}
3607
3608 \envdef\titlepage{%
3609   % Open one extra group, as we want to close it in the middle of \Etitlepage.
3610   \begingroup
3611     \parindent=0pt \textfonts
3612     % Leave some space at the very top of the page.
3613     \vglue\titlepagetopglue
3614     % No rule at page bottom unless we print one at the top with @title.
3615     \finishedtitlepagetrue
3616     %
3617     % Most title ``pages'' are actually two pages long, with space
3618     % at the top of the second.  We don't want the ragged left on the second.
3619     \let\oldpage = \page
3620     \def\page{%
3621       \iffinishedtitlepage\else
3622          \finishtitlepage
3623       \fi
3624       \let\page = \oldpage
3625       \page
3626       \null
3627     }%
3628 }
3629
3630 \def\Etitlepage{%
3631     \iffinishedtitlepage\else
3632         \finishtitlepage
3633     \fi
3634     % It is important to do the page break before ending the group,
3635     % because the headline and footline are only empty inside the group.
3636     % If we use the new definition of \page, we always get a blank page
3637     % after the title page, which we certainly don't want.
3638     \oldpage
3639   \endgroup
3640   %
3641   % Need this before the \...aftertitlepage checks so that if they are
3642   % in effect the toc pages will come out with page numbers.
3643   \HEADINGSon
3644 }
3645
3646 \def\finishtitlepage{%
3647   \vskip4pt \hrule height 2pt width \hsize
3648   \vskip\titlepagebottomglue
3649   \finishedtitlepagetrue
3650 }
3651
3652 % Settings used for typesetting titles: no hyphenation, no indentation,
3653 % don't worry much about spacing, ragged right.  This should be used
3654 % inside a \vbox, and fonts need to be set appropriately first.  Because
3655 % it is always used for titles, nothing else, we call \rmisbold.  \par
3656 % should be specified before the end of the \vbox, since a vbox is a group.
3657
3658 \def\raggedtitlesettings{%
3659   \rmisbold
3660   \hyphenpenalty=10000
3661   \parindent=0pt
3662   \tolerance=5000
3663   \ptexraggedright
3664 }
3665
3666 % Macros to be used within @titlepage:
3667
3668 \let\subtitlerm=\tenrm
3669 \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
3670
3671 \parseargdef\title{%
3672   \checkenv\titlepage
3673   \vbox{\titlefonts \raggedtitlesettings #1\par}%
3674   % print a rule at the page bottom also.
3675   \finishedtitlepagefalse
3676   \vskip4pt \hrule height 4pt width \hsize \vskip4pt
3677 }
3678
3679 \parseargdef\subtitle{%
3680   \checkenv\titlepage
3681   {\subtitlefont \rightline{#1}}%
3682 }
3683
3684 % @author should come last, but may come many times.
3685 % It can also be used inside @quotation.
3686 %
3687 \parseargdef\author{%
3688   \def\temp{\quotation}%
3689   \ifx\thisenv\temp
3690     \def\quotationauthor{#1}% printed in \Equotation.
3691   \else
3692     \checkenv\titlepage
3693     \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
3694     {\secfonts\rmisbold \leftline{#1}}%
3695   \fi
3696 }
3697
3698
3699 % Set up page headings and footings.
3700
3701 \let\thispage=\folio
3702
3703 \newtoks\evenheadline    % headline on even pages
3704 \newtoks\oddheadline     % headline on odd pages
3705 \newtoks\evenfootline    % footline on even pages
3706 \newtoks\oddfootline     % footline on odd pages
3707
3708 % Now make \makeheadline and \makefootline in Plain TeX use those variables
3709 \headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
3710                             \else \the\evenheadline \fi}}
3711 \footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
3712                             \else \the\evenfootline \fi}\HEADINGShook}
3713 \let\HEADINGShook=\relax
3714
3715 % Commands to set those variables.
3716 % For example, this is what  @headings on  does
3717 % @evenheading @thistitle|@thispage|@thischapter
3718 % @oddheading @thischapter|@thispage|@thistitle
3719 % @evenfooting @thisfile||
3720 % @oddfooting ||@thisfile
3721
3722
3723 \def\evenheading{\parsearg\evenheadingxxx}
3724 \def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
3725 \def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
3726 \global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3727
3728 \def\oddheading{\parsearg\oddheadingxxx}
3729 \def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
3730 \def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
3731 \global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3732
3733 \parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
3734
3735 \def\evenfooting{\parsearg\evenfootingxxx}
3736 \def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
3737 \def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
3738 \global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3739
3740 \def\oddfooting{\parsearg\oddfootingxxx}
3741 \def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
3742 \def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
3743   \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
3744   %
3745   % Leave some space for the footline.  Hopefully ok to assume
3746   % @evenfooting will not be used by itself.
3747   \global\advance\txipageheight by -12pt
3748   \global\advance\vsize by -12pt
3749 }
3750
3751 \parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
3752
3753 % @evenheadingmarks top     \thischapter <- chapter at the top of a page
3754 % @evenheadingmarks bottom  \thischapter <- chapter at the bottom of a page
3755 %
3756 % The same set of arguments for:
3757 %
3758 % @oddheadingmarks
3759 % @evenfootingmarks
3760 % @oddfootingmarks
3761 % @everyheadingmarks
3762 % @everyfootingmarks
3763
3764 % These define \getoddheadingmarks, \getevenheadingmarks,
3765 % \getoddfootingmarks, and \getevenfootingmarks, each to one of
3766 % \gettopheadingmarks, \getbottomheadingmarks.
3767 %
3768 \def\evenheadingmarks{\headingmarks{even}{heading}}
3769 \def\oddheadingmarks{\headingmarks{odd}{heading}}
3770 \def\evenfootingmarks{\headingmarks{even}{footing}}
3771 \def\oddfootingmarks{\headingmarks{odd}{footing}}
3772 \parseargdef\everyheadingmarks{\headingmarks{even}{heading}{#1}
3773                           \headingmarks{odd}{heading}{#1} }
3774 \parseargdef\everyfootingmarks{\headingmarks{even}{footing}{#1}
3775                           \headingmarks{odd}{footing}{#1} }
3776 % #1 = even/odd, #2 = heading/footing, #3 = top/bottom.
3777 \def\headingmarks#1#2#3 {%
3778   \expandafter\let\expandafter\temp \csname get#3headingmarks\endcsname
3779   \global\expandafter\let\csname get#1#2marks\endcsname \temp
3780 }
3781
3782 \everyheadingmarks bottom
3783 \everyfootingmarks bottom
3784
3785 % @headings double      turns headings on for double-sided printing.
3786 % @headings single      turns headings on for single-sided printing.
3787 % @headings off         turns them off.
3788 % @headings on          same as @headings double, retained for compatibility.
3789 % @headings after       turns on double-sided headings after this page.
3790 % @headings doubleafter turns on double-sided headings after this page.
3791 % @headings singleafter turns on single-sided headings after this page.
3792 % By default, they are off at the start of a document,
3793 % and turned `on' after @end titlepage.
3794
3795 \parseargdef\headings{\csname HEADINGS#1\endcsname}
3796
3797 \def\headingsoff{% non-global headings elimination
3798   \evenheadline={\hfil}\evenfootline={\hfil}%
3799    \oddheadline={\hfil}\oddfootline={\hfil}%
3800 }
3801
3802 \def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting
3803 \HEADINGSoff  % it's the default
3804
3805 % When we turn headings on, set the page number to 1.
3806 % For double-sided printing, put current file name in lower left corner,
3807 % chapter name on inside top of right hand pages, document
3808 % title on inside top of left hand pages, and page numbers on outside top
3809 % edge of all pages.
3810 \def\HEADINGSdouble{%
3811 \global\pageno=1
3812 \global\evenfootline={\hfil}
3813 \global\oddfootline={\hfil}
3814 \global\evenheadline={\line{\folio\hfil\thistitle}}
3815 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3816 \global\let\contentsalignmacro = \chapoddpage
3817 }
3818 \let\contentsalignmacro = \chappager
3819
3820 % For single-sided printing, chapter title goes across top left of page,
3821 % page number on top right.
3822 \def\HEADINGSsingle{%
3823 \global\pageno=1
3824 \global\evenfootline={\hfil}
3825 \global\oddfootline={\hfil}
3826 \global\evenheadline={\line{\thischapterheading\hfil\folio}}
3827 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3828 \global\let\contentsalignmacro = \chappager
3829 }
3830 \def\HEADINGSon{\HEADINGSdouble}
3831
3832 \def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
3833 \let\HEADINGSdoubleafter=\HEADINGSafter
3834 \def\HEADINGSdoublex{%
3835 \global\evenfootline={\hfil}
3836 \global\oddfootline={\hfil}
3837 \global\evenheadline={\line{\folio\hfil\thistitle}}
3838 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3839 \global\let\contentsalignmacro = \chapoddpage
3840 }
3841
3842 \def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
3843 \def\HEADINGSsinglex{%
3844 \global\evenfootline={\hfil}
3845 \global\oddfootline={\hfil}
3846 \global\evenheadline={\line{\thischapterheading\hfil\folio}}
3847 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3848 \global\let\contentsalignmacro = \chappager
3849 }
3850
3851 % Subroutines used in generating headings
3852 % This produces Day Month Year style of output.
3853 % Only define if not already defined, in case a txi-??.tex file has set
3854 % up a different format (e.g., txi-cs.tex does this).
3855 \ifx\today\thisisundefined
3856 \def\today{%
3857   \number\day\space
3858   \ifcase\month
3859   \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
3860   \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
3861   \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
3862   \fi
3863   \space\number\year}
3864 \fi
3865
3866 % @settitle line...  specifies the title of the document, for headings.
3867 % It generates no output of its own.
3868 \def\thistitle{\putwordNoTitle}
3869 \def\settitle{\parsearg{\gdef\thistitle}}
3870
3871
3872 \message{tables,}
3873 % Tables -- @table, @ftable, @vtable, @item(x).
3874
3875 % default indentation of table text
3876 \newdimen\tableindent \tableindent=.8in
3877 % default indentation of @itemize and @enumerate text
3878 \newdimen\itemindent  \itemindent=.3in
3879 % margin between end of table item and start of table text.
3880 \newdimen\itemmargin  \itemmargin=.1in
3881
3882 % used internally for \itemindent minus \itemmargin
3883 \newdimen\itemmax
3884
3885 % Note @table, @ftable, and @vtable define @item, @itemx, etc., with
3886 % these defs.
3887 % They also define \itemindex
3888 % to index the item name in whatever manner is desired (perhaps none).
3889
3890 \newif\ifitemxneedsnegativevskip
3891
3892 \def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
3893
3894 \def\internalBitem{\smallbreak \parsearg\itemzzz}
3895 \def\internalBitemx{\itemxpar \parsearg\itemzzz}
3896
3897 \def\itemzzz #1{\begingroup %
3898   \advance\hsize by -\rightskip
3899   \advance\hsize by -\tableindent
3900   \setbox0=\hbox{\itemindicate{#1}}%
3901   \itemindex{#1}%
3902   \nobreak % This prevents a break before @itemx.
3903   %
3904   % If the item text does not fit in the space we have, put it on a line
3905   % by itself, and do not allow a page break either before or after that
3906   % line.  We do not start a paragraph here because then if the next
3907   % command is, e.g., @kindex, the whatsit would get put into the
3908   % horizontal list on a line by itself, resulting in extra blank space.
3909   \ifdim \wd0>\itemmax
3910     %
3911     % Make this a paragraph so we get the \parskip glue and wrapping,
3912     % but leave it ragged-right.
3913     \begingroup
3914       \advance\leftskip by-\tableindent
3915       \advance\hsize by\tableindent
3916       \advance\rightskip by0pt plus1fil\relax
3917       \leavevmode\unhbox0\par
3918     \endgroup
3919     %
3920     % We're going to be starting a paragraph, but we don't want the
3921     % \parskip glue -- logically it's part of the @item we just started.
3922     \nobreak \vskip-\parskip
3923     %
3924     % Stop a page break at the \parskip glue coming up.  However, if
3925     % what follows is an environment such as @example, there will be no
3926     % \parskip glue; then the negative vskip we just inserted would
3927     % cause the example and the item to crash together.  So we use this
3928     % bizarre value of 10001 as a signal to \aboveenvbreak to insert
3929     % \parskip glue after all.  Section titles are handled this way also.
3930     %
3931     \penalty 10001
3932     \endgroup
3933     \itemxneedsnegativevskipfalse
3934   \else
3935     % The item text fits into the space.  Start a paragraph, so that the
3936     % following text (if any) will end up on the same line.
3937     \noindent
3938     % Do this with kerns and \unhbox so that if there is a footnote in
3939     % the item text, it can migrate to the main vertical list and
3940     % eventually be printed.
3941     \nobreak\kern-\tableindent
3942     \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
3943     \unhbox0
3944     \nobreak\kern\dimen0
3945     \endgroup
3946     \itemxneedsnegativevskiptrue
3947   \fi
3948 }
3949
3950 \def\item{\errmessage{@item while not in a list environment}}
3951 \def\itemx{\errmessage{@itemx while not in a list environment}}
3952
3953 % @table, @ftable, @vtable.
3954 \envdef\table{%
3955   \let\itemindex\gobble
3956   \tablecheck{table}%
3957 }
3958 \envdef\ftable{%
3959   \def\itemindex ##1{\doind {fn}{\code{##1}}}%
3960   \tablecheck{ftable}%
3961 }
3962 \envdef\vtable{%
3963   \def\itemindex ##1{\doind {vr}{\code{##1}}}%
3964   \tablecheck{vtable}%
3965 }
3966 \def\tablecheck#1{%
3967   \ifnum \the\catcode`\^^M=\active
3968     \endgroup
3969     \errmessage{This command won't work in this context; perhaps the problem is
3970       that we are \inenvironment\thisenv}%
3971     \def\next{\doignore{#1}}%
3972   \else
3973     \let\next\tablex
3974   \fi
3975   \next
3976 }
3977 \def\tablex#1{%
3978   \def\itemindicate{#1}%
3979   \parsearg\tabley
3980 }
3981 \def\tabley#1{%
3982   {%
3983     \makevalueexpandable
3984     \edef\temp{\noexpand\tablez #1\space\space\space}%
3985     \expandafter
3986   }\temp \endtablez
3987 }
3988 \def\tablez #1 #2 #3 #4\endtablez{%
3989   \aboveenvbreak
3990   \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
3991   \ifnum 0#2>0 \tableindent=#2\mil \fi
3992   \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
3993   \itemmax=\tableindent
3994   \advance \itemmax by -\itemmargin
3995   \advance \leftskip by \tableindent
3996   \exdentamount=\tableindent
3997   \parindent = 0pt
3998   \parskip = \smallskipamount
3999   \ifdim \parskip=0pt \parskip=2pt \fi
4000   \let\item = \internalBitem
4001   \let\itemx = \internalBitemx
4002 }
4003 \def\Etable{\endgraf\afterenvbreak}
4004 \let\Eftable\Etable
4005 \let\Evtable\Etable
4006 \let\Eitemize\Etable
4007 \let\Eenumerate\Etable
4008
4009 % This is the counter used by @enumerate, which is really @itemize
4010
4011 \newcount \itemno
4012
4013 \envdef\itemize{\parsearg\doitemize}
4014
4015 \def\doitemize#1{%
4016   \aboveenvbreak
4017   \itemmax=\itemindent
4018   \advance\itemmax by -\itemmargin
4019   \advance\leftskip by \itemindent
4020   \exdentamount=\itemindent
4021   \parindent=0pt
4022   \parskip=\smallskipamount
4023   \ifdim\parskip=0pt \parskip=2pt \fi
4024   %
4025   % Try typesetting the item mark so that if the document erroneously says
4026   % something like @itemize @samp (intending @table), there's an error
4027   % right away at the @itemize.  It's not the best error message in the
4028   % world, but it's better than leaving it to the @item.  This means if
4029   % the user wants an empty mark, they have to say @w{} not just @w.
4030   \def\itemcontents{#1}%
4031   \setbox0 = \hbox{\itemcontents}%
4032   %
4033   % @itemize with no arg is equivalent to @itemize @bullet.
4034   \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
4035   %
4036   \let\item=\itemizeitem
4037 }
4038
4039 % Definition of @item while inside @itemize and @enumerate.
4040 %
4041 \def\itemizeitem{%
4042   \advance\itemno by 1  % for enumerations
4043   {\let\par=\endgraf \smallbreak}% reasonable place to break
4044   {%
4045    % If the document has an @itemize directly after a section title, a
4046    % \nobreak will be last on the list, and \sectionheading will have
4047    % done a \vskip-\parskip.  In that case, we don't want to zero
4048    % parskip, or the item text will crash with the heading.  On the
4049    % other hand, when there is normal text preceding the item (as there
4050    % usually is), we do want to zero parskip, or there would be too much
4051    % space.  In that case, we won't have a \nobreak before.  At least
4052    % that's the theory.
4053    \ifnum\lastpenalty<10000 \parskip=0in \fi
4054    \noindent
4055    \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
4056    %
4057    \ifinner\else
4058      \vadjust{\penalty 1200}% not good to break after first line of item.
4059    \fi
4060    % We can be in inner vertical mode in a footnote, although an
4061    % @itemize looks awful there.
4062   }%
4063   \flushcr
4064 }
4065
4066 % \splitoff TOKENS\endmark defines \first to be the first token in
4067 % TOKENS, and \rest to be the remainder.
4068 %
4069 \def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
4070
4071 % Allow an optional argument of an uppercase letter, lowercase letter,
4072 % or number, to specify the first label in the enumerated list.  No
4073 % argument is the same as `1'.
4074 %
4075 \envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
4076 \def\enumeratey #1 #2\endenumeratey{%
4077   % If we were given no argument, pretend we were given `1'.
4078   \def\thearg{#1}%
4079   \ifx\thearg\empty \def\thearg{1}\fi
4080   %
4081   % Detect if the argument is a single token.  If so, it might be a
4082   % letter.  Otherwise, the only valid thing it can be is a number.
4083   % (We will always have one token, because of the test we just made.
4084   % This is a good thing, since \splitoff doesn't work given nothing at
4085   % all -- the first parameter is undelimited.)
4086   \expandafter\splitoff\thearg\endmark
4087   \ifx\rest\empty
4088     % Only one token in the argument.  It could still be anything.
4089     % A ``lowercase letter'' is one whose \lccode is nonzero.
4090     % An ``uppercase letter'' is one whose \lccode is both nonzero, and
4091     %   not equal to itself.
4092     % Otherwise, we assume it's a number.
4093     %
4094     % We need the \relax at the end of the \ifnum lines to stop TeX from
4095     % continuing to look for a <number>.
4096     %
4097     \ifnum\lccode\expandafter`\thearg=0\relax
4098       \numericenumerate % a number (we hope)
4099     \else
4100       % It's a letter.
4101       \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
4102         \lowercaseenumerate % lowercase letter
4103       \else
4104         \uppercaseenumerate % uppercase letter
4105       \fi
4106     \fi
4107   \else
4108     % Multiple tokens in the argument.  We hope it's a number.
4109     \numericenumerate
4110   \fi
4111 }
4112
4113 % An @enumerate whose labels are integers.  The starting integer is
4114 % given in \thearg.
4115 %
4116 \def\numericenumerate{%
4117   \itemno = \thearg
4118   \startenumeration{\the\itemno}%
4119 }
4120
4121 % The starting (lowercase) letter is in \thearg.
4122 \def\lowercaseenumerate{%
4123   \itemno = \expandafter`\thearg
4124   \startenumeration{%
4125     % Be sure we're not beyond the end of the alphabet.
4126     \ifnum\itemno=0
4127       \errmessage{No more lowercase letters in @enumerate; get a bigger
4128                   alphabet}%
4129     \fi
4130     \char\lccode\itemno
4131   }%
4132 }
4133
4134 % The starting (uppercase) letter is in \thearg.
4135 \def\uppercaseenumerate{%
4136   \itemno = \expandafter`\thearg
4137   \startenumeration{%
4138     % Be sure we're not beyond the end of the alphabet.
4139     \ifnum\itemno=0
4140       \errmessage{No more uppercase letters in @enumerate; get a bigger
4141                   alphabet}
4142     \fi
4143     \char\uccode\itemno
4144   }%
4145 }
4146
4147 % Call \doitemize, adding a period to the first argument and supplying the
4148 % common last two arguments.  Also subtract one from the initial value in
4149 % \itemno, since @item increments \itemno.
4150 %
4151 \def\startenumeration#1{%
4152   \advance\itemno by -1
4153   \doitemize{#1.}\flushcr
4154 }
4155
4156 % @alphaenumerate and @capsenumerate are abbreviations for giving an arg
4157 % to @enumerate.
4158 %
4159 \def\alphaenumerate{\enumerate{a}}
4160 \def\capsenumerate{\enumerate{A}}
4161 \def\Ealphaenumerate{\Eenumerate}
4162 \def\Ecapsenumerate{\Eenumerate}
4163
4164
4165 % @multitable macros
4166 % Amy Hendrickson, 8/18/94, 3/6/96
4167 %
4168 % @multitable ... @end multitable will make as many columns as desired.
4169 % Contents of each column will wrap at width given in preamble.  Width
4170 % can be specified either with sample text given in a template line,
4171 % or in percent of \hsize, the current width of text on page.
4172
4173 % Table can continue over pages but will only break between lines.
4174
4175 % To make preamble:
4176 %
4177 % Either define widths of columns in terms of percent of \hsize:
4178 %   @multitable @columnfractions .25 .3 .45
4179 %   @item ...
4180 %
4181 %   Numbers following @columnfractions are the percent of the total
4182 %   current hsize to be used for each column. You may use as many
4183 %   columns as desired.
4184
4185
4186 % Or use a template:
4187 %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4188 %   @item ...
4189 %   using the widest term desired in each column.
4190
4191 % Each new table line starts with @item, each subsequent new column
4192 % starts with @tab. Empty columns may be produced by supplying @tab's
4193 % with nothing between them for as many times as empty columns are needed,
4194 % ie, @tab@tab@tab will produce two empty columns.
4195
4196 % @item, @tab do not need to be on their own lines, but it will not hurt
4197 % if they are.
4198
4199 % Sample multitable:
4200
4201 %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4202 %   @item first col stuff @tab second col stuff @tab third col
4203 %   @item
4204 %   first col stuff
4205 %   @tab
4206 %   second col stuff
4207 %   @tab
4208 %   third col
4209 %   @item first col stuff @tab second col stuff
4210 %   @tab Many paragraphs of text may be used in any column.
4211 %
4212 %         They will wrap at the width determined by the template.
4213 %   @item@tab@tab This will be in third column.
4214 %   @end multitable
4215
4216 % Default dimensions may be reset by user.
4217 % @multitableparskip is vertical space between paragraphs in table.
4218 % @multitableparindent is paragraph indent in table.
4219 % @multitablecolmargin is horizontal space to be left between columns.
4220 % @multitablelinespace is space to leave between table items, baseline
4221 %                                                            to baseline.
4222 %   0pt means it depends on current normal line spacing.
4223 %
4224 \newskip\multitableparskip
4225 \newskip\multitableparindent
4226 \newdimen\multitablecolspace
4227 \newskip\multitablelinespace
4228 \multitableparskip=0pt
4229 \multitableparindent=6pt
4230 \multitablecolspace=12pt
4231 \multitablelinespace=0pt
4232
4233 % Macros used to set up halign preamble:
4234 %
4235 \let\endsetuptable\relax
4236 \def\xendsetuptable{\endsetuptable}
4237 \let\columnfractions\relax
4238 \def\xcolumnfractions{\columnfractions}
4239 \newif\ifsetpercent
4240
4241 % #1 is the @columnfraction, usually a decimal number like .5, but might
4242 % be just 1.  We just use it, whatever it is.
4243 %
4244 \def\pickupwholefraction#1 {%
4245   \global\advance\colcount by 1
4246   \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
4247   \setuptable
4248 }
4249
4250 \newcount\colcount
4251 \def\setuptable#1{%
4252   \def\firstarg{#1}%
4253   \ifx\firstarg\xendsetuptable
4254     \let\go = \relax
4255   \else
4256     \ifx\firstarg\xcolumnfractions
4257       \global\setpercenttrue
4258     \else
4259       \ifsetpercent
4260          \let\go\pickupwholefraction
4261       \else
4262          \global\advance\colcount by 1
4263          \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
4264                    % separator; typically that is always in the input, anyway.
4265          \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
4266       \fi
4267     \fi
4268     \ifx\go\pickupwholefraction
4269       % Put the argument back for the \pickupwholefraction call, so
4270       % we'll always have a period there to be parsed.
4271       \def\go{\pickupwholefraction#1}%
4272     \else
4273       \let\go = \setuptable
4274     \fi%
4275   \fi
4276   \go
4277 }
4278
4279 % multitable-only commands.
4280
4281 % @headitem starts a heading row, which we typeset in bold.  Assignments
4282 % have to be global since we are inside the implicit group of an
4283 % alignment entry.  \everycr below resets \everytab so we don't have to
4284 % undo it ourselves.
4285 \def\headitemfont{\b}% for people to use in the template row; not changeable
4286 \def\headitem{%
4287   \checkenv\multitable
4288   \crcr
4289   \gdef\headitemcrhook{\nobreak}% attempt to avoid page break after headings
4290   \global\everytab={\bf}% can't use \headitemfont since the parsing differs
4291   \the\everytab % for the first item
4292 }%
4293 %
4294 % default for tables with no headings.
4295 \let\headitemcrhook=\relax
4296 %
4297 % A \tab used to include \hskip1sp.  But then the space in a template
4298 % line is not enough.  That is bad.  So let's go back to just `&' until
4299 % we again encounter the problem the 1sp was intended to solve.
4300 %                                       --karl, nathan@acm.org, 20apr99.
4301 \def\tab{\checkenv\multitable &\the\everytab}%
4302
4303 % @multitable ... @end multitable definitions:
4304 %
4305 \newtoks\everytab  % insert after every tab.
4306 %
4307 \envdef\multitable{%
4308   \vskip\parskip
4309   \startsavinginserts
4310   %
4311   % @item within a multitable starts a normal row.
4312   % We use \def instead of \let so that if one of the multitable entries
4313   % contains an @itemize, we don't choke on the \item (seen as \crcr aka
4314   % \endtemplate) expanding \doitemize.
4315   \def\item{\crcr}%
4316   %
4317   \tolerance=9500
4318   \hbadness=9500
4319   \setmultitablespacing
4320   \parskip=\multitableparskip
4321   \parindent=\multitableparindent
4322   \overfullrule=0pt
4323   \global\colcount=0
4324   %
4325   \everycr = {%
4326     \noalign{%
4327       \global\everytab={}% Reset from possible headitem.
4328       \global\colcount=0 % Reset the column counter.
4329       %
4330       % Check for saved footnotes, etc.:
4331       \checkinserts
4332       %
4333       % Perhaps a \nobreak, then reset:
4334       \headitemcrhook
4335       \global\let\headitemcrhook=\relax
4336     }%
4337   }%
4338   %
4339   \parsearg\domultitable
4340 }
4341 \def\domultitable#1{%
4342   % To parse everything between @multitable and @item:
4343   \setuptable#1 \endsetuptable
4344   %
4345   % This preamble sets up a generic column definition, which will
4346   % be used as many times as user calls for columns.
4347   % \vtop will set a single line and will also let text wrap and
4348   % continue for many paragraphs if desired.
4349   \halign\bgroup &%
4350     \global\advance\colcount by 1
4351     \multistrut
4352     \vtop{%
4353       % Use the current \colcount to find the correct column width:
4354       \hsize=\expandafter\csname col\the\colcount\endcsname
4355       %
4356       % In order to keep entries from bumping into each other
4357       % we will add a \leftskip of \multitablecolspace to all columns after
4358       % the first one.
4359       %
4360       % If a template has been used, we will add \multitablecolspace
4361       % to the width of each template entry.
4362       %
4363       % If the user has set preamble in terms of percent of \hsize we will
4364       % use that dimension as the width of the column, and the \leftskip
4365       % will keep entries from bumping into each other.  Table will start at
4366       % left margin and final column will justify at right margin.
4367       %
4368       % Make sure we don't inherit \rightskip from the outer environment.
4369       \rightskip=0pt
4370       \ifnum\colcount=1
4371         % The first column will be indented with the surrounding text.
4372         \advance\hsize by\leftskip
4373       \else
4374         \ifsetpercent \else
4375           % If user has not set preamble in terms of percent of \hsize
4376           % we will advance \hsize by \multitablecolspace.
4377           \advance\hsize by \multitablecolspace
4378         \fi
4379        % In either case we will make \leftskip=\multitablecolspace:
4380       \leftskip=\multitablecolspace
4381       \fi
4382       % Ignoring space at the beginning and end avoids an occasional spurious
4383       % blank line, when TeX decides to break the line at the space before the
4384       % box from the multistrut, so the strut ends up on a line by itself.
4385       % For example:
4386       % @multitable @columnfractions .11 .89
4387       % @item @code{#}
4388       % @tab Legal holiday which is valid in major parts of the whole country.
4389       % Is automatically provided with highlighting sequences respectively
4390       % marking characters.
4391       \noindent\ignorespaces##\unskip\multistrut
4392     }\cr
4393 }
4394 \def\Emultitable{%
4395   \crcr
4396   \egroup % end the \halign
4397   \global\setpercentfalse
4398 }
4399
4400 \def\setmultitablespacing{%
4401   \def\multistrut{\strut}% just use the standard line spacing
4402   %
4403   % Compute \multitablelinespace (if not defined by user) for use in
4404   % \multitableparskip calculation.  We used define \multistrut based on
4405   % this, but (ironically) that caused the spacing to be off.
4406   % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
4407 \ifdim\multitablelinespace=0pt
4408 \setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
4409 \global\advance\multitablelinespace by-\ht0
4410 \fi
4411 % Test to see if parskip is larger than space between lines of
4412 % table. If not, do nothing.
4413 %        If so, set to same dimension as multitablelinespace.
4414 \ifdim\multitableparskip>\multitablelinespace
4415 \global\multitableparskip=\multitablelinespace
4416 \global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4417                                       % than skip between lines in the table.
4418 \fi%
4419 \ifdim\multitableparskip=0pt
4420 \global\multitableparskip=\multitablelinespace
4421 \global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4422                                       % than skip between lines in the table.
4423 \fi}
4424
4425
4426 \message{conditionals,}
4427
4428 % @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
4429 % @ifnotxml always succeed.  They currently do nothing; we don't
4430 % attempt to check whether the conditionals are properly nested.  But we
4431 % have to remember that they are conditionals, so that @end doesn't
4432 % attempt to close an environment group.
4433 %
4434 \def\makecond#1{%
4435   \expandafter\let\csname #1\endcsname = \relax
4436   \expandafter\let\csname iscond.#1\endcsname = 1
4437 }
4438 \makecond{iftex}
4439 \makecond{ifnotdocbook}
4440 \makecond{ifnothtml}
4441 \makecond{ifnotinfo}
4442 \makecond{ifnotplaintext}
4443 \makecond{ifnotxml}
4444
4445 % Ignore @ignore, @ifhtml, @ifinfo, and the like.
4446 %
4447 \def\direntry{\doignore{direntry}}
4448 \def\documentdescription{\doignore{documentdescription}}
4449 \def\docbook{\doignore{docbook}}
4450 \def\html{\doignore{html}}
4451 \def\ifdocbook{\doignore{ifdocbook}}
4452 \def\ifhtml{\doignore{ifhtml}}
4453 \def\ifinfo{\doignore{ifinfo}}
4454 \def\ifnottex{\doignore{ifnottex}}
4455 \def\ifplaintext{\doignore{ifplaintext}}
4456 \def\ifxml{\doignore{ifxml}}
4457 \def\ignore{\doignore{ignore}}
4458 \def\menu{\doignore{menu}}
4459 \def\xml{\doignore{xml}}
4460
4461 % Ignore text until a line `@end #1', keeping track of nested conditionals.
4462 %
4463 % A count to remember the depth of nesting.
4464 \newcount\doignorecount
4465
4466 \def\doignore#1{\begingroup
4467   % Scan in ``verbatim'' mode:
4468   \obeylines
4469   \catcode`\@ = \other
4470   \catcode`\{ = \other
4471   \catcode`\} = \other
4472   %
4473   % Make sure that spaces turn into tokens that match what \doignoretext wants.
4474   \spaceisspace
4475   %
4476   % Count number of #1's that we've seen.
4477   \doignorecount = 0
4478   %
4479   % Swallow text until we reach the matching `@end #1'.
4480   \dodoignore{#1}%
4481 }
4482
4483 { \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
4484   \obeylines %
4485   %
4486   \gdef\dodoignore#1{%
4487     % #1 contains the command name as a string, e.g., `ifinfo'.
4488     %
4489     % Define a command to find the next `@end #1'.
4490     \long\def\doignoretext##1^^M@end #1{%
4491       \doignoretextyyy##1^^M@#1\_STOP_}%
4492     %
4493     % And this command to find another #1 command, at the beginning of a
4494     % line.  (Otherwise, we would consider a line `@c @ifset', for
4495     % example, to count as an @ifset for nesting.)
4496     \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
4497     %
4498     % And now expand that command.
4499     \doignoretext ^^M%
4500   }%
4501 }
4502
4503 \def\doignoreyyy#1{%
4504   \def\temp{#1}%
4505   \ifx\temp\empty                       % Nothing found.
4506     \let\next\doignoretextzzz
4507   \else                                 % Found a nested condition, ...
4508     \advance\doignorecount by 1
4509     \let\next\doignoretextyyy           % ..., look for another.
4510     % If we're here, #1 ends with ^^M\ifinfo (for example).
4511   \fi
4512   \next #1% the token \_STOP_ is present just after this macro.
4513 }
4514
4515 % We have to swallow the remaining "\_STOP_".
4516 %
4517 \def\doignoretextzzz#1{%
4518   \ifnum\doignorecount = 0      % We have just found the outermost @end.
4519     \let\next\enddoignore
4520   \else                         % Still inside a nested condition.
4521     \advance\doignorecount by -1
4522     \let\next\doignoretext      % Look for the next @end.
4523   \fi
4524   \next
4525 }
4526
4527 % Finish off ignored text.
4528 { \obeylines%
4529   % Ignore anything after the last `@end #1'; this matters in verbatim
4530   % environments, where otherwise the newline after an ignored conditional
4531   % would result in a blank line in the output.
4532   \gdef\enddoignore#1^^M{\endgroup\ignorespaces}%
4533 }
4534
4535
4536 % @set VAR sets the variable VAR to an empty value.
4537 % @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
4538 %
4539 % Since we want to separate VAR from REST-OF-LINE (which might be
4540 % empty), we can't just use \parsearg; we have to insert a space of our
4541 % own to delimit the rest of the line, and then take it out again if we
4542 % didn't need it.
4543 % We rely on the fact that \parsearg sets \catcode`\ =10.
4544 %
4545 \parseargdef\set{\setyyy#1 \endsetyyy}
4546 \def\setyyy#1 #2\endsetyyy{%
4547   {%
4548     \makevalueexpandable
4549     \def\temp{#2}%
4550     \edef\next{\gdef\makecsname{SET#1}}%
4551     \ifx\temp\empty
4552       \next{}%
4553     \else
4554       \setzzz#2\endsetzzz
4555     \fi
4556   }%
4557 }
4558 % Remove the trailing space \setxxx inserted.
4559 \def\setzzz#1 \endsetzzz{\next{#1}}
4560
4561 % @clear VAR clears (i.e., unsets) the variable VAR.
4562 %
4563 \parseargdef\clear{%
4564   {%
4565     \makevalueexpandable
4566     \global\expandafter\let\csname SET#1\endcsname=\relax
4567   }%
4568 }
4569
4570 % @value{foo} gets the text saved in variable foo.
4571 \def\value{\begingroup\makevalueexpandable\valuexxx}
4572 \def\valuexxx#1{\expandablevalue{#1}\endgroup}
4573 {
4574   \catcode`\-=\active \catcode`\_=\active
4575   %
4576   \gdef\makevalueexpandable{%
4577     \let\value = \expandablevalue
4578     % We don't want these characters active, ...
4579     \catcode`\-=\other \catcode`\_=\other
4580     % ..., but we might end up with active ones in the argument if
4581     % we're called from @code, as @code{@value{foo-bar_}}, though.
4582     % So \let them to their normal equivalents.
4583     \let-\normaldash \let_\normalunderscore
4584   }
4585 }
4586
4587 % We have this subroutine so that we can handle at least some @value's
4588 % properly in indexes (we call \makevalueexpandable in \indexdummies).
4589 % The command has to be fully expandable (if the variable is set), since
4590 % the result winds up in the index file.  This means that if the
4591 % variable's value contains other Texinfo commands, it's almost certain
4592 % it will fail (although perhaps we could fix that with sufficient work
4593 % to do a one-level expansion on the result, instead of complete).
4594
4595 % Unfortunately, this has the consequence that when _ is in the *value*
4596 % of an @set, it does not print properly in the roman fonts (get the cmr
4597 % dot accent at position 126 instead).  No fix comes to mind, and it's
4598 % been this way since 2003 or earlier, so just ignore it.
4599
4600 \def\expandablevalue#1{%
4601   \expandafter\ifx\csname SET#1\endcsname\relax
4602     {[No value for ``#1'']}%
4603     \message{Variable `#1', used in @value, is not set.}%
4604   \else
4605     \csname SET#1\endcsname
4606   \fi
4607 }
4608
4609 % Like \expandablevalue, but completely expandable (the \message in the
4610 % definition above operates at the execution level of TeX).  Used when
4611 % writing to auxiliary files, due to the expansion that \write does.
4612 %
4613 % NB flag names containing - or _ may not work here.
4614 \def\dummyvalue#1{%
4615   \expandafter\ifx\csname SET#1\endcsname\relax
4616     [No value for ``#1'']%
4617   \else
4618     \csname SET#1\endcsname
4619   \fi
4620 }
4621
4622 % @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
4623 % with @set.
4624
4625 % To get the special treatment we need for `@end ifset,' we call
4626 % \makecond and then redefine.
4627 %
4628 \makecond{ifset}
4629 \def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
4630 \def\doifset#1#2{%
4631   {%
4632     \makevalueexpandable
4633     \let\next=\empty
4634     \expandafter\ifx\csname SET#2\endcsname\relax
4635       #1% If not set, redefine \next.
4636     \fi
4637     \expandafter
4638   }\next
4639 }
4640 \def\ifsetfail{\doignore{ifset}}
4641
4642 % @ifclear VAR ... @end executes the `...' iff VAR has never been
4643 % defined with @set, or has been undefined with @clear.
4644 %
4645 % The `\else' inside the `\doifset' parameter is a trick to reuse the
4646 % above code: if the variable is not set, do nothing, if it is set,
4647 % then redefine \next to \ifclearfail.
4648 %
4649 \makecond{ifclear}
4650 \def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
4651 \def\ifclearfail{\doignore{ifclear}}
4652
4653 % @ifcommandisdefined CMD ... @end executes the `...' if CMD (written
4654 % without the @) is in fact defined.  We can only feasibly check at the
4655 % TeX level, so something like `mathcode' is going to considered
4656 % defined even though it is not a Texinfo command.
4657
4658 \makecond{ifcommanddefined}
4659 \def\ifcommanddefined{\parsearg{\doifcmddefined{\let\next=\ifcmddefinedfail}}}
4660 %
4661 \def\doifcmddefined#1#2{{%
4662     \makevalueexpandable
4663     \let\next=\empty
4664     \expandafter\ifx\csname #2\endcsname\relax
4665       #1% If not defined, \let\next as above.
4666     \fi
4667     \expandafter
4668   }\next
4669 }
4670 \def\ifcmddefinedfail{\doignore{ifcommanddefined}}
4671
4672 % @ifcommandnotdefined CMD ... handled similar to @ifclear above.
4673 \makecond{ifcommandnotdefined}
4674 \def\ifcommandnotdefined{%
4675   \parsearg{\doifcmddefined{\else \let\next=\ifcmdnotdefinedfail}}}
4676 \def\ifcmdnotdefinedfail{\doignore{ifcommandnotdefined}}
4677
4678 % Set the `txicommandconditionals' variable, so documents have a way to
4679 % test if the @ifcommand...defined conditionals are available.
4680 \set txicommandconditionals
4681
4682 % @dircategory CATEGORY  -- specify a category of the dir file
4683 % which this file should belong to.  Ignore this in TeX.
4684 \let\dircategory=\comment
4685
4686 % @defininfoenclose.
4687 \let\definfoenclose=\comment
4688
4689
4690 \message{indexing,}
4691 % Index generation facilities
4692
4693 % Define \newwrite to be identical to plain tex's \newwrite
4694 % except not \outer, so it can be used within macros and \if's.
4695 \edef\newwrite{\makecsname{ptexnewwrite}}
4696
4697 % \newindex {foo} defines an index named IX.
4698 % It automatically defines \IXindex such that
4699 % \IXindex ...rest of line... puts an entry in the index IX.
4700 % It also defines \IXindfile to be the number of the output channel for
4701 % the file that accumulates this index.  The file's extension is IX.
4702 % The name of an index should be no more than 2 characters long
4703 % for the sake of vms.
4704 %
4705 \def\newindex#1{%
4706   \expandafter\chardef\csname#1indfile\endcsname=0
4707   \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
4708     \noexpand\doindex{#1}}
4709 }
4710
4711 % @defindex foo  ==  \newindex{foo}
4712 %
4713 \def\defindex{\parsearg\newindex}
4714
4715 % Define @defcodeindex, like @defindex except put all entries in @code.
4716 %
4717 \def\defcodeindex{\parsearg\newcodeindex}
4718 %
4719 \def\newcodeindex#1{%
4720   \expandafter\chardef\csname#1indfile\endcsname=0
4721   \expandafter\xdef\csname#1index\endcsname{%
4722     \noexpand\docodeindex{#1}}%
4723 }
4724
4725 % The default indices:
4726 \newindex{cp}%      concepts,
4727 \newcodeindex{fn}%  functions,
4728 \newcodeindex{vr}%  variables,
4729 \newcodeindex{tp}%  types,
4730 \newcodeindex{ky}%  keys
4731 \newcodeindex{pg}%  and programs.
4732
4733
4734 % @synindex foo bar    makes index foo feed into index bar.
4735 % Do this instead of @defindex foo if you don't want it as a separate index.
4736 %
4737 % @syncodeindex foo bar   similar, but put all entries made for index foo
4738 % inside @code.
4739 %
4740 \def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
4741 \def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
4742
4743 % #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
4744 % #3 the target index (bar).
4745 \def\dosynindex#1#2#3{%
4746   % Only do \closeout if we haven't already done it, else we'll end up
4747   % closing the target index.
4748   \expandafter \ifx\csname donesynindex#2\endcsname \relax
4749     % The \closeout helps reduce unnecessary open files; the limit on the
4750     % Acorn RISC OS is a mere 16 files.
4751     \expandafter\closeout\csname#2indfile\endcsname
4752     \expandafter\let\csname donesynindex#2\endcsname = 1
4753   \fi
4754   % redefine \fooindfile:
4755   \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
4756   \expandafter\let\csname#2indfile\endcsname=\temp
4757   % redefine \fooindex:
4758   \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
4759 }
4760
4761 % Define \doindex, the driver for all index macros.
4762 % Argument #1 is generated by the calling \fooindex macro,
4763 % and it the two-letter name of the index.
4764
4765 \def\doindex#1{\edef\indexname{#1}\parsearg\doindexxxx}
4766 \def\doindexxxx #1{\doind{\indexname}{#1}}
4767
4768 % like the previous two, but they put @code around the argument.
4769 \def\docodeindex#1{\edef\indexname{#1}\parsearg\docodeindexxxx}
4770 \def\docodeindexxxx #1{\doind{\indexname}{\code{#1}}}
4771
4772 % Used when writing an index entry out to an index file to prevent
4773 % expansion of Texinfo commands that can appear in an index entry.
4774 %
4775 \def\indexdummies{%
4776   \escapechar = `\\     % use backslash in output files.
4777   \def\@{@}% change to @@ when we switch to @ as escape char in index files.
4778   \def\ {\realbackslash\space }%
4779   %
4780   % Need these unexpandable (because we define \tt as a dummy)
4781   % definitions when @{ or @} appear in index entry text.  Also, more
4782   % complicated, when \tex is in effect and \{ is a \delimiter again.
4783   % We can't use \lbracecmd and \rbracecmd because texindex assumes
4784   % braces and backslashes are used only as delimiters.  Perhaps we
4785   % should use @lbracechar and @rbracechar?
4786   \def\{{{\tt\char123}}%
4787   \def\}{{\tt\char125}}%
4788   %
4789   % Do the redefinitions.
4790   \commondummies
4791 }
4792
4793 % For the aux and toc files, @ is the escape character.  So we want to
4794 % redefine everything using @ as the escape character (instead of
4795 % \realbackslash, still used for index files).  When everything uses @,
4796 % this will be simpler.
4797 %
4798 \def\atdummies{%
4799   \def\@{@@}%
4800   \def\ {@ }%
4801   \let\{ = \lbraceatcmd
4802   \let\} = \rbraceatcmd
4803   %
4804   % Do the redefinitions.
4805   \commondummies
4806   \otherbackslash
4807 }
4808
4809 % Called from \indexdummies and \atdummies.
4810 %
4811 \def\commondummies{%
4812   % \definedummyword defines \#1 as \string\#1\space, thus effectively
4813   % preventing its expansion.  This is used only for control words,
4814   % not control letters, because the \space would be incorrect for
4815   % control characters, but is needed to separate the control word
4816   % from whatever follows.
4817   %
4818   % For control letters, we have \definedummyletter, which omits the
4819   % space.
4820   %
4821   % These can be used both for control words that take an argument and
4822   % those that do not.  If it is followed by {arg} in the input, then
4823   % that will dutifully get written to the index (or wherever).
4824   %
4825   \def\definedummyword  ##1{\def##1{\string##1\space}}%
4826   \def\definedummyletter##1{\def##1{\string##1}}%
4827   \let\definedummyaccent\definedummyletter
4828   %
4829   \commondummiesnofonts
4830   %
4831   \definedummyletter\_%
4832   \definedummyletter\-%
4833   %
4834   % Non-English letters.
4835   \definedummyword\AA
4836   \definedummyword\AE
4837   \definedummyword\DH
4838   \definedummyword\L
4839   \definedummyword\O
4840   \definedummyword\OE
4841   \definedummyword\TH
4842   \definedummyword\aa
4843   \definedummyword\ae
4844   \definedummyword\dh
4845   \definedummyword\exclamdown
4846   \definedummyword\l
4847   \definedummyword\o
4848   \definedummyword\oe
4849   \definedummyword\ordf
4850   \definedummyword\ordm
4851   \definedummyword\questiondown
4852   \definedummyword\ss
4853   \definedummyword\th
4854   %
4855   % Although these internal commands shouldn't show up, sometimes they do.
4856   \definedummyword\bf
4857   \definedummyword\gtr
4858   \definedummyword\hat
4859   \definedummyword\less
4860   \definedummyword\sf
4861   \definedummyword\sl
4862   \definedummyword\tclose
4863   \definedummyword\tt
4864   %
4865   \definedummyword\LaTeX
4866   \definedummyword\TeX
4867   %
4868   % Assorted special characters.
4869   \definedummyword\arrow
4870   \definedummyword\bullet
4871   \definedummyword\comma
4872   \definedummyword\copyright
4873   \definedummyword\registeredsymbol
4874   \definedummyword\dots
4875   \definedummyword\enddots
4876   \definedummyword\entrybreak
4877   \definedummyword\equiv
4878   \definedummyword\error
4879   \definedummyword\euro
4880   \definedummyword\expansion
4881   \definedummyword\geq
4882   \definedummyword\guillemetleft
4883   \definedummyword\guillemetright
4884   \definedummyword\guilsinglleft
4885   \definedummyword\guilsinglright
4886   \definedummyword\lbracechar
4887   \definedummyword\leq
4888   \definedummyword\mathopsup
4889   \definedummyword\minus
4890   \definedummyword\ogonek
4891   \definedummyword\pounds
4892   \definedummyword\point
4893   \definedummyword\print
4894   \definedummyword\quotedblbase
4895   \definedummyword\quotedblleft
4896   \definedummyword\quotedblright
4897   \definedummyword\quoteleft
4898   \definedummyword\quoteright
4899   \definedummyword\quotesinglbase
4900   \definedummyword\rbracechar
4901   \definedummyword\result
4902   \definedummyword\sub
4903   \definedummyword\sup
4904   \definedummyword\textdegree
4905   %
4906   % We want to disable all macros so that they are not expanded by \write.
4907   \macrolist
4908   \let\value\dummyvalue
4909   %
4910   \normalturnoffactive
4911 }
4912
4913 % \commondummiesnofonts: common to \commondummies and \indexnofonts.
4914 % Define \definedumyletter, \definedummyaccent and \definedummyword before
4915 % using.
4916 %
4917 \def\commondummiesnofonts{%
4918   % Control letters and accents.
4919   \definedummyletter\!%
4920   \definedummyaccent\"%
4921   \definedummyaccent\'%
4922   \definedummyletter\*%
4923   \definedummyaccent\,%
4924   \definedummyletter\.%
4925   \definedummyletter\/%
4926   \definedummyletter\:%
4927   \definedummyaccent\=%
4928   \definedummyletter\?%
4929   \definedummyaccent\^%
4930   \definedummyaccent\`%
4931   \definedummyaccent\~%
4932   \definedummyword\u
4933   \definedummyword\v
4934   \definedummyword\H
4935   \definedummyword\dotaccent
4936   \definedummyword\ogonek
4937   \definedummyword\ringaccent
4938   \definedummyword\tieaccent
4939   \definedummyword\ubaraccent
4940   \definedummyword\udotaccent
4941   \definedummyword\dotless
4942   %
4943   % Texinfo font commands.
4944   \definedummyword\b
4945   \definedummyword\i
4946   \definedummyword\r
4947   \definedummyword\sansserif
4948   \definedummyword\sc
4949   \definedummyword\slanted
4950   \definedummyword\t
4951   %
4952   % Commands that take arguments.
4953   \definedummyword\abbr
4954   \definedummyword\acronym
4955   \definedummyword\anchor
4956   \definedummyword\cite
4957   \definedummyword\code
4958   \definedummyword\command
4959   \definedummyword\dfn
4960   \definedummyword\dmn
4961   \definedummyword\email
4962   \definedummyword\emph
4963   \definedummyword\env
4964   \definedummyword\file
4965   \definedummyword\image
4966   \definedummyword\indicateurl
4967   \definedummyword\inforef
4968   \definedummyword\kbd
4969   \definedummyword\key
4970   \definedummyword\math
4971   \definedummyword\option
4972   \definedummyword\pxref
4973   \definedummyword\ref
4974   \definedummyword\samp
4975   \definedummyword\strong
4976   \definedummyword\tie
4977   \definedummyword\U
4978   \definedummyword\uref
4979   \definedummyword\url
4980   \definedummyword\var
4981   \definedummyword\verb
4982   \definedummyword\w
4983   \definedummyword\xref
4984 }
4985
4986 % For testing: output @{ and @} in index sort strings as \{ and \}.
4987 \newif\ifusebracesinindexes
4988
4989 \let\indexlbrace\relax
4990 \let\indexrbrace\relax
4991
4992 {\catcode`\@=0
4993 \catcode`\\=13
4994   @gdef@backslashdisappear{@def\{}}
4995 }
4996
4997 {
4998 \catcode`\<=13
4999 \catcode`\-=13
5000 \catcode`\`=13
5001   \gdef\indexnonalnumdisappear{%
5002     \expandafter\ifx\csname SETtxiindexlquoteignore\endcsname\relax\else
5003       % @set txiindexlquoteignore makes us ignore left quotes in the sort term.
5004       % (Introduced for FSFS 2nd ed.)
5005       \let`=\empty
5006     \fi
5007     %
5008     \expandafter\ifx\csname SETtxiindexbackslashignore\endcsname\relax\else
5009       \backslashdisappear
5010     \fi
5011     %
5012     \expandafter\ifx\csname SETtxiindexhyphenignore\endcsname\relax\else
5013       \def-{}%
5014     \fi
5015     \expandafter\ifx\csname SETtxiindexlessthanignore\endcsname\relax\else
5016       \def<{}%
5017     \fi
5018     \expandafter\ifx\csname SETtxiindexatsignignore\endcsname\relax\else
5019       \def\@{}%
5020     \fi
5021   }
5022
5023   \gdef\indexnonalnumreappear{%
5024     \useindexbackslash
5025     \let-\normaldash
5026     \let<\normalless
5027     \def\@{@}%
5028   }
5029 }
5030
5031
5032 % \indexnofonts is used when outputting the strings to sort the index
5033 % by, and when constructing control sequence names.  It eliminates all
5034 % control sequences and just writes whatever the best ASCII sort string
5035 % would be for a given command (usually its argument).
5036 %
5037 \def\indexnofonts{%
5038   % Accent commands should become @asis.
5039   \def\definedummyaccent##1{\let##1\asis}%
5040   % We can just ignore other control letters.
5041   \def\definedummyletter##1{\let##1\empty}%
5042   % All control words become @asis by default; overrides below.
5043   \let\definedummyword\definedummyaccent
5044   \commondummiesnofonts
5045   %
5046   % Don't no-op \tt, since it isn't a user-level command
5047   % and is used in the definitions of the active chars like <, >, |, etc.
5048   % Likewise with the other plain tex font commands.
5049   %\let\tt=\asis
5050   %
5051   \def\ { }%
5052   \def\@{@}%
5053   \def\_{\normalunderscore}%
5054   \def\-{}% @- shouldn't affect sorting
5055   %
5056   \uccode`\1=`\{ \uppercase{\def\{{1}}%
5057   \uccode`\1=`\} \uppercase{\def\}{1}}%
5058   \let\lbracechar\{%
5059   \let\rbracechar\}%
5060   %
5061   % Non-English letters.
5062   \def\AA{AA}%
5063   \def\AE{AE}%
5064   \def\DH{DZZ}%
5065   \def\L{L}%
5066   \def\OE{OE}%
5067   \def\O{O}%
5068   \def\TH{TH}%
5069   \def\aa{aa}%
5070   \def\ae{ae}%
5071   \def\dh{dzz}%
5072   \def\exclamdown{!}%
5073   \def\l{l}%
5074   \def\oe{oe}%
5075   \def\ordf{a}%
5076   \def\ordm{o}%
5077   \def\o{o}%
5078   \def\questiondown{?}%
5079   \def\ss{ss}%
5080   \def\th{th}%
5081   %
5082   \def\LaTeX{LaTeX}%
5083   \def\TeX{TeX}%
5084   %
5085   % Assorted special characters.
5086   % (The following {} will end up in the sort string, but that's ok.)
5087   \def\arrow{->}%
5088   \def\bullet{bullet}%
5089   \def\comma{,}%
5090   \def\copyright{copyright}%
5091   \def\dots{...}%
5092   \def\enddots{...}%
5093   \def\equiv{==}%
5094   \def\error{error}%
5095   \def\euro{euro}%
5096   \def\expansion{==>}%
5097   \def\geq{>=}%
5098   \def\guillemetleft{<<}%
5099   \def\guillemetright{>>}%
5100   \def\guilsinglleft{<}%
5101   \def\guilsinglright{>}%
5102   \def\leq{<=}%
5103   \def\minus{-}%
5104   \def\point{.}%
5105   \def\pounds{pounds}%
5106   \def\print{-|}%
5107   \def\quotedblbase{"}%
5108   \def\quotedblleft{"}%
5109   \def\quotedblright{"}%
5110   \def\quoteleft{`}%
5111   \def\quoteright{'}%
5112   \def\quotesinglbase{,}%
5113   \def\registeredsymbol{R}%
5114   \def\result{=>}%
5115   \def\textdegree{o}%
5116   %
5117   % We need to get rid of all macros, leaving only the arguments (if present).
5118   % Of course this is not nearly correct, but it is the best we can do for now.
5119   % makeinfo does not expand macros in the argument to @deffn, which ends up
5120   % writing an index entry, and texindex isn't prepared for an index sort entry
5121   % that starts with \.
5122   %
5123   % Since macro invocations are followed by braces, we can just redefine them
5124   % to take a single TeX argument.  The case of a macro invocation that
5125   % goes to end-of-line is not handled.
5126   %
5127   \macrolist
5128 }
5129
5130
5131 \let\SETmarginindex=\relax % put index entries in margin (undocumented)?
5132
5133 % Most index entries go through here, but \dosubind is the general case.
5134 % #1 is the index name, #2 is the entry text.
5135 \def\doind#1#2{\dosubind{#1}{#2}{}}
5136
5137 % There is also \dosubind {index}{topic}{subtopic}
5138 % which makes an entry in a two-level index such as the operation index.
5139 % TODO: Two-level index?  Operation index?
5140
5141 % Workhorse for all indexes.
5142 % #1 is name of index, #2 is stuff to put there, #3 is subentry --
5143 % empty if called from \doind, as we usually are (the main exception
5144 % is with most defuns, which call us directly).
5145 %
5146 \def\dosubind#1#2#3{%
5147   \iflinks
5148   {%
5149     \requireopenindexfile{#1}%
5150     % Store the main index entry text (including the third arg).
5151     \toks0 = {#2}%
5152     % If third arg is present, precede it with a space.
5153     \def\thirdarg{#3}%
5154     \ifx\thirdarg\empty \else
5155       \toks0 = \expandafter{\the\toks0 \space #3}%
5156     \fi
5157     %
5158     \edef\writeto{\csname#1indfile\endcsname}%
5159     %
5160     \safewhatsit\dosubindwrite
5161   }%
5162   \fi
5163 }
5164
5165 % Check if an index file has been opened, and if not, open it.
5166 \def\requireopenindexfile#1{%
5167 \ifnum\csname #1indfile\endcsname=0
5168   \expandafter\newwrite \csname#1indfile\endcsname
5169   \edef\suffix{#1}%
5170   % A .fls suffix would conflict with the file extension for the output
5171   % of -recorder, so use .f1s instead.
5172   \ifx\suffix\indexisfl\def\suffix{f1}\fi
5173   % Open the file
5174   \immediate\openout\csname#1indfile\endcsname \jobname.\suffix
5175   % Using \immediate above here prevents an object entering into the current 
5176   % box, which could confound checks such as those in \safewhatsit for
5177   % preceding skips.
5178   \typeout{Writing index file \jobname.\suffix}%
5179 \fi}
5180 \def\indexisfl{fl}
5181
5182 % Output \ as {\indexbackslash}, because \ is an escape character in
5183 % the index files.
5184 \let\indexbackslash=\relax
5185 {\catcode`\@=0 \catcode`\\=\active
5186   @gdef@useindexbackslash{@def\{{@indexbackslash}}}
5187 }
5188
5189 % Definition for writing index entry text.
5190 \def\sortas#1{\ignorespaces}%
5191
5192 % Definition for writing index entry sort key.  Should occur at the at
5193 % the beginning of the index entry, like
5194 %     @cindex @sortas{september} \september
5195 % The \ignorespaces takes care of following space, but there's no way
5196 % to remove space before it.
5197 {
5198 \catcode`\-=13
5199 \gdef\indexwritesortas{%
5200   \begingroup
5201   \indexnonalnumreappear
5202   \indexwritesortasxxx}
5203 \gdef\indexwritesortasxxx#1{%
5204   \xdef\indexsortkey{#1}\endgroup}
5205 }
5206
5207
5208 % Write the entry in \toks0 to the index file.
5209 %
5210 \def\dosubindwrite{%
5211   % Put the index entry in the margin if desired.
5212   \ifx\SETmarginindex\relax\else
5213     \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
5214   \fi
5215   %
5216   % Remember, we are within a group.
5217   \indexdummies % Must do this here, since \bf, etc expand at this stage
5218   \useindexbackslash % \indexbackslash isn't defined now so it will be output 
5219                      % as is; and it will print as backslash.
5220   % The braces around \indexbrace are recognized by texindex.
5221   %
5222   % Get the string to sort by, by processing the index entry with all
5223   % font commands turned off.
5224   {\indexnofonts
5225    \def\lbracechar{{\indexlbrace}}%
5226    \def\rbracechar{{\indexrbrace}}%
5227    \let\{=\lbracechar
5228    \let\}=\rbracechar
5229    \indexnonalnumdisappear
5230    \xdef\indexsortkey{}%
5231    \let\sortas=\indexwritesortas
5232    \edef\temp{\the\toks0}%
5233    \setbox\dummybox = \hbox{\temp}% Make sure to execute any \sortas
5234    \ifx\indexsortkey\empty
5235      \xdef\indexsortkey{\temp}%
5236      \ifx\indexsortkey\empty\xdef\indexsortkey{ }\fi
5237    \fi
5238   }%
5239   %
5240   % Set up the complete index entry, with both the sort key and
5241   % the original text, including any font commands.  We write
5242   % three arguments to \entry to the .?? file (four in the
5243   % subentry case), texindex reduces to two when writing the .??s
5244   % sorted result.
5245   \edef\temp{%
5246     \write\writeto{%
5247       \string\entry{\indexsortkey}{\noexpand\folio}{\the\toks0}}%
5248   }%
5249   \temp
5250 }
5251 \newbox\dummybox % used above
5252
5253 % Take care of unwanted page breaks/skips around a whatsit:
5254 %
5255 % If a skip is the last thing on the list now, preserve it
5256 % by backing up by \lastskip, doing the \write, then inserting
5257 % the skip again.  Otherwise, the whatsit generated by the
5258 % \write or \pdfdest will make \lastskip zero.  The result is that
5259 % sequences like this:
5260 % @end defun
5261 % @tindex whatever
5262 % @defun ...
5263 % will have extra space inserted, because the \medbreak in the
5264 % start of the @defun won't see the skip inserted by the @end of
5265 % the previous defun.
5266 %
5267 % But don't do any of this if we're not in vertical mode.  We
5268 % don't want to do a \vskip and prematurely end a paragraph.
5269 %
5270 % Avoid page breaks due to these extra skips, too.
5271 %
5272 % But wait, there is a catch there:
5273 % We'll have to check whether \lastskip is zero skip.  \ifdim is not
5274 % sufficient for this purpose, as it ignores stretch and shrink parts
5275 % of the skip.  The only way seems to be to check the textual
5276 % representation of the skip.
5277 %
5278 % The following is almost like \def\zeroskipmacro{0.0pt} except that
5279 % the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
5280 %
5281 \edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
5282 %
5283 \newskip\whatsitskip
5284 \newcount\whatsitpenalty
5285 %
5286 % ..., ready, GO:
5287 %
5288 \def\safewhatsit#1{\ifhmode
5289   #1%
5290  \else
5291   % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
5292   \whatsitskip = \lastskip
5293   \edef\lastskipmacro{\the\lastskip}%
5294   \whatsitpenalty = \lastpenalty
5295   %
5296   % If \lastskip is nonzero, that means the last item was a
5297   % skip.  And since a skip is discardable, that means this
5298   % -\whatsitskip glue we're inserting is preceded by a
5299   % non-discardable item, therefore it is not a potential
5300   % breakpoint, therefore no \nobreak needed.
5301   \ifx\lastskipmacro\zeroskipmacro
5302   \else
5303     \vskip-\whatsitskip
5304   \fi
5305   %
5306   #1%
5307   %
5308   \ifx\lastskipmacro\zeroskipmacro
5309     % If \lastskip was zero, perhaps the last item was a penalty, and
5310     % perhaps it was >=10000, e.g., a \nobreak.  In that case, we want
5311     % to re-insert the same penalty (values >10000 are used for various
5312     % signals); since we just inserted a non-discardable item, any
5313     % following glue (such as a \parskip) would be a breakpoint.  For example:
5314     %   @deffn deffn-whatever
5315     %   @vindex index-whatever
5316     %   Description.
5317     % would allow a break between the index-whatever whatsit
5318     % and the "Description." paragraph.
5319     \ifnum\whatsitpenalty>9999 \penalty\whatsitpenalty \fi
5320   \else
5321     % On the other hand, if we had a nonzero \lastskip,
5322     % this make-up glue would be preceded by a non-discardable item
5323     % (the whatsit from the \write), so we must insert a \nobreak.
5324     \nobreak\vskip\whatsitskip
5325   \fi
5326 \fi}
5327
5328 % The index entry written in the file actually looks like
5329 %  \entry {sortstring}{page}{topic}
5330 % or
5331 %  \entry {sortstring}{page}{topic}{subtopic}
5332 % The texindex program reads in these files and writes files
5333 % containing these kinds of lines:
5334 %  \initial {c}
5335 %     before the first topic whose initial is c
5336 %  \entry {topic}{pagelist}
5337 %     for a topic that is used without subtopics
5338 %  \primary {topic}
5339 %     for the beginning of a topic that is used with subtopics
5340 %  \secondary {subtopic}{pagelist}
5341 %     for each subtopic.
5342
5343 % Define the user-accessible indexing commands
5344 % @findex, @vindex, @kindex, @cindex.
5345
5346 \def\findex {\fnindex}
5347 \def\kindex {\kyindex}
5348 \def\cindex {\cpindex}
5349 \def\vindex {\vrindex}
5350 \def\tindex {\tpindex}
5351 \def\pindex {\pgindex}
5352
5353 \def\cindexsub {\begingroup\obeylines\cindexsub}
5354 {\obeylines %
5355 \gdef\cindexsub "#1" #2^^M{\endgroup %
5356 \dosubind{cp}{#2}{#1}}}
5357
5358 % Define the macros used in formatting output of the sorted index material.
5359
5360 % @printindex causes a particular index (the ??s file) to get printed.
5361 % It does not print any chapter heading (usually an @unnumbered).
5362 %
5363 \parseargdef\printindex{\begingroup
5364   \dobreak \chapheadingskip{10000}%
5365   %
5366   \smallfonts \rm
5367   \tolerance = 9500
5368   \plainfrenchspacing
5369   \everypar = {}% don't want the \kern\-parindent from indentation suppression.
5370   %
5371   % See if the index file exists and is nonempty.
5372   % Change catcode of @ here so that if the index file contains
5373   % \initial {@}
5374   % as its first line, TeX doesn't complain about mismatched braces
5375   % (because it thinks @} is a control sequence).
5376   \catcode`\@ = 11
5377   % See comment in \requireopenindexfile.
5378   \def\indexname{#1}\ifx\indexname\indexisfl\def\indexname{f1}\fi
5379   \openin 1 \jobname.\indexname s
5380   \ifeof 1
5381     % \enddoublecolumns gets confused if there is no text in the index,
5382     % and it loses the chapter title and the aux file entries for the
5383     % index.  The easiest way to prevent this problem is to make sure
5384     % there is some text.
5385     \putwordIndexNonexistent
5386     \typeout{No file \jobname.\indexname s.}%
5387   \else
5388     \catcode`\\ = 0
5389     %
5390     % If the index file exists but is empty, then \openin leaves \ifeof
5391     % false.  We have to make TeX try to read something from the file, so
5392     % it can discover if there is anything in it.
5393     \read 1 to \thisline
5394     \ifeof 1
5395       \putwordIndexIsEmpty
5396     \else
5397       % Index files are almost Texinfo source, but we use \ as the escape
5398       % character.  It would be better to use @, but that's too big a change
5399       % to make right now.
5400       \def\indexbackslash{\ttbackslash}%
5401       \let\indexlbrace\{   % Likewise, set these sequences for braces
5402       \let\indexrbrace\}   % used in the sort key.
5403       \begindoublecolumns
5404       \let\entryorphanpenalty=\indexorphanpenalty
5405       %
5406       % Read input from the index file line by line.
5407       \loopdo
5408         \ifeof1
5409           \let\firsttoken\relax
5410         \else
5411           \read 1 to \nextline
5412           \edef\act{\gdef\noexpand\firsttoken{\getfirsttoken\nextline}}%
5413           \act
5414         \fi
5415         \thisline
5416         %
5417         \ifeof1\else
5418         \let\thisline\nextline
5419       \repeat
5420       %%
5421       \enddoublecolumns
5422     \fi
5423   \fi
5424   \closein 1
5425 \endgroup}
5426
5427 \def\getfirsttoken#1{\expandafter\getfirsttokenx#1\endfirsttoken}
5428 \long\def\getfirsttokenx#1#2\endfirsttoken{\noexpand#1}
5429
5430 \def\loopdo#1\repeat{\def\body{#1}\loopdoxxx}
5431 \def\loopdoxxx{\let\next=\relax\body\let\next=\loopdoxxx\fi\next}
5432
5433 % These macros are used by the sorted index file itself.
5434 % Change them to control the appearance of the index.
5435
5436 {\catcode`\/=13 \catcode`\-=13 \catcode`\^=13 \catcode`\~=13 \catcode`\_=13
5437 \catcode`\|=13 \catcode`\<=13 \catcode`\>=13 \catcode`\+=13 \catcode`\"=13
5438 \catcode`\$=3
5439 \gdef\initialglyphs{%
5440   % Some changes for non-alphabetic characters.  Using the glyphs from the
5441   % math fonts looks more consistent than the typewriter font used elsewhere
5442   % for these characters.
5443   \def\indexbackslash{\math{\backslash}}%
5444   \let\\=\indexbackslash
5445   %
5446   % Can't get bold backslash so don't use bold forward slash
5447   \catcode`\/=13
5448   \def/{{\secrmnotbold \normalslash}}%
5449   \def-{{\normaldash\normaldash}}% en dash `--'
5450   \def^{{\chapbf \normalcaret}}%
5451   \def~{{\chapbf \normaltilde}}%
5452   \def\_{%
5453      \leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }%
5454   \def|{$\vert$}%
5455   \def<{$\less$}%
5456   \def>{$\gtr$}%
5457   \def+{$\normalplus$}%
5458 }}
5459
5460 \def\initial{%
5461   \bgroup
5462   \initialglyphs
5463   \initialx
5464 }
5465
5466 \def\initialx#1{%
5467   % Remove any glue we may have, we'll be inserting our own.
5468   \removelastskip
5469   %
5470   % We like breaks before the index initials, so insert a bonus.
5471   % The glue before the bonus allows a little bit of space at the
5472   % bottom of a column to reduce an increase in inter-line spacing.
5473   \nobreak
5474   \vskip 0pt plus 5\baselineskip
5475   \penalty -300 
5476   \vskip 0pt plus -5\baselineskip
5477   %
5478   % Typeset the initial.  Making this add up to a whole number of
5479   % baselineskips increases the chance of the dots lining up from column
5480   % to column.  It still won't often be perfect, because of the stretch
5481   % we need before each entry, but it's better.
5482   %
5483   % No shrink because it confuses \balancecolumns.
5484   \vskip 1.67\baselineskip plus 1\baselineskip
5485   \leftline{\secfonts \kern-0.05em \secbf #1}%
5486   % \secfonts is inside the argument of \leftline so that the change of
5487   % \baselineskip will not affect any glue inserted before the vbox that
5488   % \leftline creates.
5489   % Do our best not to break after the initial.
5490   \nobreak
5491   \vskip .33\baselineskip plus .1\baselineskip
5492   \egroup % \initialglyphs
5493 }
5494
5495 \newdimen\entryrightmargin
5496 \entryrightmargin=0pt
5497
5498 % \entry typesets a paragraph consisting of the text (#1), dot leaders, and
5499 % then page number (#2) flushed to the right margin.  It is used for index
5500 % and table of contents entries.  The paragraph is indented by \leftskip.
5501 %
5502 \def\entry{%
5503   \begingroup
5504     %
5505     % Start a new paragraph if necessary, so our assignments below can't
5506     % affect previous text.
5507     \par
5508     %
5509     % No extra space above this paragraph.
5510     \parskip = 0in
5511     %
5512     % When reading the text of entry, convert explicit line breaks
5513     % from @* into spaces.  The user might give these in long section
5514     % titles, for instance.
5515     \def\*{\unskip\space\ignorespaces}%
5516     \def\entrybreak{\hfil\break}% An undocumented command
5517     %
5518     % A bit of stretch before each entry for the benefit of balancing
5519     % columns.
5520     \vskip 0pt plus0.5pt
5521     %
5522     % Swallow the left brace of the text (first parameter):
5523     \afterassignment\doentry
5524     \let\temp =
5525 }
5526 \def\entrybreak{\unskip\space\ignorespaces}%
5527 \def\doentry{%
5528     % Save the text of the entry
5529     \global\setbox\boxA=\hbox\bgroup
5530     \bgroup % Instead of the swallowed brace.
5531       \noindent
5532       \aftergroup\finishentry
5533       % And now comes the text of the entry.
5534       % Not absorbing as a macro argument reduces the chance of problems
5535       % with catcodes occurring.
5536 }
5537 {\catcode`\@=11
5538 \gdef\finishentry#1{%
5539     \egroup % end box A
5540     \dimen@ = \wd\boxA % Length of text of entry
5541     \global\setbox\boxA=\hbox\bgroup\unhbox\boxA
5542     % #1 is the page number.
5543     %
5544     % Get the width of the page numbers, and only use
5545     % leaders if they are present.
5546     \global\setbox\boxB = \hbox{#1}%
5547     \ifdim\wd\boxB = 0pt
5548       \null\nobreak\hfill\ %
5549     \else
5550       %
5551       \null\nobreak\indexdotfill % Have leaders before the page number.
5552       %
5553       \ifpdf
5554         \pdfgettoks#1.%
5555         \bgroup\let\domark\relax
5556           \hskip\skip\thinshrinkable\the\toksA
5557         \egroup
5558         % The redefinion of \domark stops marks being added in \pdflink to 
5559         % preserve coloured links across page boundaries.  Otherwise the marks
5560         % would get in the way of \lastbox in \insertindexentrybox.
5561       \else
5562         \ifx\XeTeXrevision\thisisundefined
5563           \hskip\skip\thinshrinkable #1%
5564         \else
5565           \pdfgettoks#1.%
5566           \bgroup\let\domark\relax
5567             \hskip\skip\thinshrinkable\the\toksA
5568           \egroup
5569         \fi
5570       \fi
5571     \fi
5572     \egroup % end \boxA
5573     \ifdim\wd\boxB = 0pt
5574       \global\setbox\entryindexbox=\vbox{\unhbox\boxA}%
5575     \else
5576     \global\setbox\entryindexbox=\vbox\bgroup
5577       \prevdepth=\entrylinedepth
5578       \noindent
5579       % We want the text of the entries to be aligned to the left, and the
5580       % page numbers to be aligned to the right.
5581       %
5582       \advance\leftskip by 0pt plus 1fil
5583       \advance\leftskip by 0pt plus -1fill
5584       \rightskip = 0pt plus -1fil
5585       \advance\rightskip by 0pt plus 1fill
5586       % Cause last line, which could consist of page numbers on their own
5587       % if the list of page numbers is long, to be aligned to the right.
5588       \parfillskip=0pt plus -1fill
5589       %
5590       \hangindent=1em
5591       %
5592       \advance\rightskip by \entryrightmargin
5593       % Determine how far we can stretch into the margin.
5594       % This allows, e.g., "Appendix H  GNU Free Documentation License" to
5595       % fit on one line in @letterpaper format.
5596       \ifdim\entryrightmargin>2.1em
5597         \dimen@i=2.1em
5598       \else
5599         \dimen@i=0em
5600       \fi
5601       \advance \parfillskip by 0pt minus 1\dimen@i
5602       %
5603       \dimen@ii = \hsize
5604       \advance\dimen@ii by -1\leftskip
5605       \advance\dimen@ii by -1\entryrightmargin
5606       \advance\dimen@ii by 1\dimen@i
5607       \ifdim\wd\boxA > \dimen@ii % If the entry doesn't fit in one line
5608       \ifdim\dimen@ > 0.8\dimen@ii   % due to long index text
5609         \dimen@ = 0.7\dimen@ % Try to split the text roughly evenly
5610         \dimen@ii = \hsize
5611         \advance \dimen@ii by -1em
5612         \ifnum\dimen@>\dimen@ii
5613           % If the entry is too long, use the whole line
5614           \dimen@ = \dimen@ii
5615         \fi
5616         \advance\leftskip by 0pt plus 1fill % ragged right
5617         \advance \dimen@ by 1\rightskip
5618         \parshape = 2 0pt \dimen@ 1em \dimen@ii
5619         % Ideally we'd add a finite glue at the end of the first line only, but
5620         % TeX doesn't seem to provide a way to do such a thing.
5621       \fi\fi
5622       \unhbox\boxA
5623       %
5624       % Do not prefer a separate line ending with a hyphen to fewer lines.
5625       \finalhyphendemerits = 0
5626       %
5627       % Word spacing - no stretch
5628       \spaceskip=\fontdimen2\font minus \fontdimen4\font
5629       %
5630       \linepenalty=1000  % Discourage line breaks.
5631       \hyphenpenalty=5000  % Discourage hyphenation.
5632       %
5633       \par % format the paragraph
5634     \egroup % The \vbox
5635     \fi
5636   \endgroup
5637   % delay text of entry until after penalty
5638   \bgroup\aftergroup\insertindexentrybox
5639   \entryorphanpenalty
5640 }}
5641
5642 \newskip\thinshrinkable
5643 \skip\thinshrinkable=.15em minus .15em
5644
5645 \newbox\entryindexbox
5646 \def\insertindexentrybox{%
5647   \copy\entryindexbox
5648   % The following gets the depth of the last box.  This is for even
5649   % line spacing when entries span several lines.
5650   \setbox\dummybox\vbox{%
5651     \unvbox\entryindexbox
5652     \nointerlineskip
5653     \lastbox
5654     \global\entrylinedepth=\prevdepth
5655   }%
5656   % Note that we couldn't simply \unvbox\entryindexbox followed by 
5657   % \nointerlineskip\lastbox to remove the last box and then reinstate it, 
5658   % because this resets how far the box has been \moveleft'ed to 0.  \unvbox
5659   % doesn't affect \prevdepth either.
5660 }
5661 \newdimen\entrylinedepth
5662
5663 % Default is no penalty
5664 \let\entryorphanpenalty\egroup
5665
5666 % Used from \printindex.  \firsttoken should be the first token
5667 % after the \entry.  If it's not another \entry, we are at the last
5668 % line of a group of index entries, so insert a penalty to discourage
5669 % orphaned index entries.
5670 \long\def\indexorphanpenalty{%
5671   \def\isentry{\entry}%
5672   \ifx\firsttoken\isentry
5673   \else
5674     \unskip\penalty 9000
5675     % The \unskip here stops breaking before the glue.  It relies on the
5676     % \vskip above being there, otherwise there is an error
5677     % "You can't use `\unskip' in vertical mode".  There has to be glue
5678     % in the current vertical list that hasn't been added to the
5679     % "current page".  See Chapter 24 of the TeXbook.  This contradicts
5680     % Section 8.3.7 in "TeX by Topic," though.
5681   \fi
5682   \egroup % now comes the box added with \aftergroup
5683 }
5684
5685 % Like plain.tex's \dotfill, except uses up at least 1 em.
5686 % The filll stretch here overpowers both the fil and fill stretch to push
5687 % the page number to the right.
5688 \def\indexdotfill{\cleaders
5689   \hbox{$\mathsurround=0pt \mkern1.5mu.\mkern1.5mu$}\hskip 1em plus 1filll}
5690
5691
5692 \def\primary #1{\line{#1\hfil}}
5693
5694 \newskip\secondaryindent \secondaryindent=0.5cm
5695 \def\secondary#1#2{{%
5696   \parfillskip=0in
5697   \parskip=0in
5698   \hangindent=1in
5699   \hangafter=1
5700   \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
5701   \ifpdf
5702     \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5703   \else
5704     \ifx\XeTeXrevision\thisisundefined
5705       #2
5706     \else
5707       \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5708     \fi
5709   \fi
5710   \par
5711 }}
5712
5713 % Define two-column mode, which we use to typeset indexes.
5714 % Adapted from the TeXbook, page 416, which is to say,
5715 % the manmac.tex format used to print the TeXbook itself.
5716 \catcode`\@=11  % private names
5717
5718 \newbox\partialpage
5719 \newdimen\doublecolumnhsize
5720 \newdimen\doublecolumntopgap
5721 \doublecolumntopgap = 0pt
5722
5723 % Use inside an output routine to save \topmark and \firstmark
5724 \def\savemarks{%
5725   \global\savedtopmark=\expandafter{\topmark }%
5726   \global\savedfirstmark=\expandafter{\firstmark }%
5727 }
5728 \newtoks\savedtopmark
5729 \newtoks\savedfirstmark
5730
5731 % Set \topmark and \firstmark for next time \output runs.
5732 % Can't be run from withinside \output (because any material
5733 % added while an output routine is active, including 
5734 % penalties, is saved for after it finishes).  The page so far
5735 % should be empty, otherwise what's on it will be thrown away.
5736 \def\restoremarks{%
5737   \mark{\the\savedtopmark}%
5738   \bgroup\output = {%
5739     \setbox\dummybox=\box\PAGE
5740   }abc\eject\egroup
5741   % "abc" because output routine doesn't fire for a completely empty page.
5742   \mark{\the\savedfirstmark}%
5743 }
5744
5745 \def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
5746   % If not much space left on page, start a new page.
5747   \ifdim\pagetotal>0.8\vsize\vfill\eject\fi
5748   %
5749   % Grab any single-column material above us.
5750   \output = {%
5751     %
5752     % Here is a possibility not foreseen in manmac: if we accumulate a
5753     % whole lot of material, we might end up calling this \output
5754     % routine twice in a row (see the doublecol-lose test, which is
5755     % essentially a couple of indexes with @setchapternewpage off).  In
5756     % that case we just ship out what is in \partialpage with the normal
5757     % output routine.  Generally, \partialpage will be empty when this
5758     % runs and this will be a no-op.  See the indexspread.tex test case.
5759     \ifvoid\partialpage \else
5760       \onepageout{\pagecontents\partialpage}%
5761     \fi
5762     %
5763     \global\setbox\partialpage = \vbox{%
5764       % Unvbox the main output page.
5765       \unvbox\PAGE
5766       \kern-\topskip \kern\baselineskip
5767     }%
5768     \savemarks
5769   }%
5770   \eject % run that output routine to set \partialpage
5771   \restoremarks
5772   %
5773   % We recover the two marks that the last output routine saved in order
5774   % to propagate the information in marks added around a chapter heading,
5775   % which could be otherwise be lost by the time the final page is output.
5776   %
5777   %
5778   % Use the double-column output routine for subsequent pages.
5779   \output = {\doublecolumnout}%
5780   %
5781   % Change the page size parameters.  We could do this once outside this
5782   % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
5783   % format, but then we repeat the same computation.  Repeating a couple
5784   % of assignments once per index is clearly meaningless for the
5785   % execution time, so we may as well do it in one place.
5786   %
5787   % First we halve the line length, less a little for the gutter between
5788   % the columns.  We compute the gutter based on the line length, so it
5789   % changes automatically with the paper format.  The magic constant
5790   % below is chosen so that the gutter has the same value (well, +-<1pt)
5791   % as it did when we hard-coded it.
5792   %
5793   % We put the result in a separate register, \doublecolumhsize, so we
5794   % can restore it in \pagesofar, after \hsize itself has (potentially)
5795   % been clobbered.
5796   %
5797   \doublecolumnhsize = \hsize
5798     \advance\doublecolumnhsize by -.04154\hsize
5799     \divide\doublecolumnhsize by 2
5800   \hsize = \doublecolumnhsize
5801   %
5802   % Double the \vsize as well.  (We don't need a separate register here,
5803   % since nobody clobbers \vsize.)
5804   \global\doublecolumntopgap = \topskip
5805   \global\advance\doublecolumntopgap by -1\baselineskip
5806   \advance\vsize by -1\doublecolumntopgap
5807   \vsize = 2\vsize
5808   \topskip=0pt
5809   \global\entrylinedepth=0pt\relax
5810 }
5811
5812 % The double-column output routine for all double-column pages except
5813 % the last, which is done by \balancecolumns.
5814 %
5815 \def\doublecolumnout{%
5816   %
5817   \splittopskip=\topskip \splitmaxdepth=\maxdepth
5818   % Get the available space for the double columns -- the normal
5819   % (undoubled) page height minus any material left over from the
5820   % previous page.
5821   \dimen@ = \vsize
5822   \divide\dimen@ by 2
5823   \advance\dimen@ by -\ht\partialpage
5824   %
5825   % box0 will be the left-hand column, box2 the right.
5826   \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
5827   \onepageout\pagesofar
5828   \unvbox255
5829   \penalty\outputpenalty
5830 }
5831 %
5832 % Re-output the contents of the output page -- any previous material,
5833 % followed by the two boxes we just split, in box0 and box2.
5834 \def\pagesofar{%
5835   \unvbox\partialpage
5836   %
5837   \hsize = \doublecolumnhsize
5838   \wd0=\hsize \wd2=\hsize
5839   \vbox{%
5840     \vskip\doublecolumntopgap
5841     \hbox to\txipagewidth{\box0\hfil\box2}}%
5842 }
5843
5844
5845 % Finished with with double columns.
5846 \def\enddoublecolumns{%
5847   % The following penalty ensures that the page builder is exercised
5848   % _before_ we change the output routine.  This is necessary in the
5849   % following situation:
5850   %
5851   % The last section of the index consists only of a single entry.
5852   % Before this section, \pagetotal is less than \pagegoal, so no
5853   % break occurs before the last section starts.  However, the last
5854   % section, consisting of \initial and the single \entry, does not
5855   % fit on the page and has to be broken off.  Without the following
5856   % penalty the page builder will not be exercised until \eject
5857   % below, and by that time we'll already have changed the output
5858   % routine to the \balancecolumns version, so the next-to-last
5859   % double-column page will be processed with \balancecolumns, which
5860   % is wrong:  The two columns will go to the main vertical list, with
5861   % the broken-off section in the recent contributions.  As soon as
5862   % the output routine finishes, TeX starts reconsidering the page
5863   % break.  The two columns and the broken-off section both fit on the
5864   % page, because the two columns now take up only half of the page
5865   % goal.  When TeX sees \eject from below which follows the final
5866   % section, it invokes the new output routine that we've set after
5867   % \balancecolumns below; \onepageout will try to fit the two columns
5868   % and the final section into the vbox of \txipageheight (see
5869   % \pagebody), causing an overfull box.
5870   %
5871   % Note that glue won't work here, because glue does not exercise the
5872   % page builder, unlike penalties (see The TeXbook, pp. 280-281).
5873   \penalty0
5874   %
5875   \output = {%
5876     % Split the last of the double-column material.
5877     \savemarks
5878     \balancecolumns
5879     %
5880     % Having called \balancecolumns once, we do not
5881     % want to call it again.  Therefore, reset \output to its normal
5882     % definition right away.
5883     \global\output = {\onepageout{\pagecontents\PAGE}}%
5884   }%
5885   \eject
5886   \endgroup % started in \begindoublecolumns
5887   \restoremarks
5888   % Leave the double-column material on the current page, no automatic
5889   % page break.
5890   \box\balancedcolumns
5891   %
5892   % \pagegoal was set to the doubled \vsize above, since we restarted
5893   % the current page.  We're now back to normal single-column
5894   % typesetting, so reset \pagegoal to the normal \vsize (after the
5895   % \endgroup where \vsize got restored).
5896   \pagegoal = \vsize
5897 }
5898 \newbox\balancedcolumns
5899 \setbox\balancedcolumns=\vbox{shouldnt see this}%
5900 %
5901 % Only called for the last of the double column material.  \doublecolumnout 
5902 % does the others.
5903 \def\balancecolumns{%
5904   \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
5905   \dimen@ = \ht0
5906   \advance\dimen@ by \topskip
5907   \advance\dimen@ by-\baselineskip
5908   \ifdim\dimen@<14\baselineskip
5909     % Don't split a short final column in two.
5910     \setbox2=\vbox{}%
5911   \else
5912     \divide\dimen@ by 2 % target to split to
5913     \dimen@ii = \dimen@
5914     \splittopskip = \topskip
5915     % Loop until the second column is no higher than the first
5916     {%
5917       \vbadness = 10000
5918       \loop
5919         \global\setbox3 = \copy0
5920         \global\setbox1 = \vsplit3 to \dimen@
5921         % Remove glue from bottom of first column to
5922         % make sure it is higher than the second.
5923         \global\setbox1 = \vbox{\unvbox1\unpenalty\unskip}%
5924       \ifdim\ht3>\ht1
5925         \global\advance\dimen@ by 1pt
5926       \repeat
5927     }%
5928     \multiply\dimen@ii by 4
5929     \divide\dimen@ii by 5
5930     \ifdim\ht3<\dimen@ii
5931       % Column heights are too different, so don't make their bottoms
5932       % flush with each other.  The glue at the end of the second column
5933       % allows a second column to stretch, reducing the difference in
5934       % height between the two.
5935       \setbox0=\vbox to\dimen@{\unvbox1\vfill}%
5936       \setbox2=\vbox to\dimen@{\unvbox3\vskip 0pt plus 0.3\ht0}%
5937     \else
5938       \setbox0=\vbox to\dimen@{\unvbox1}%
5939       \setbox2=\vbox to\dimen@{\unvbox3}%
5940     \fi
5941   \fi
5942   %
5943   \global\setbox\balancedcolumns=\vbox{\pagesofar}%
5944 }
5945 \catcode`\@ = \other
5946
5947
5948 \message{sectioning,}
5949 % Chapters, sections, etc.
5950
5951 % Let's start with @part.
5952 \outer\parseargdef\part{\partzzz{#1}}
5953 \def\partzzz#1{%
5954   \chapoddpage
5955   \null
5956   \vskip.3\vsize  % move it down on the page a bit
5957   \begingroup
5958     \noindent \titlefonts\rmisbold #1\par % the text
5959     \let\lastnode=\empty      % no node to associate with
5960     \writetocentry{part}{#1}{}% but put it in the toc
5961     \headingsoff              % no headline or footline on the part page
5962     % This outputs a mark at the end of the page that clears \thischapter
5963     % and \thissection, as is done in \startcontents.
5964     \let\pchapsepmacro\relax
5965     \chapmacro{}{Yomitfromtoc}{}%
5966     \chapoddpage
5967   \endgroup
5968 }
5969
5970 % \unnumberedno is an oxymoron.  But we count the unnumbered
5971 % sections so that we can refer to them unambiguously in the pdf
5972 % outlines by their "section number".  We avoid collisions with chapter
5973 % numbers by starting them at 10000.  (If a document ever has 10000
5974 % chapters, we're in trouble anyway, I'm sure.)
5975 \newcount\unnumberedno \unnumberedno = 10000
5976 \newcount\chapno
5977 \newcount\secno        \secno=0
5978 \newcount\subsecno     \subsecno=0
5979 \newcount\subsubsecno  \subsubsecno=0
5980
5981 % This counter is funny since it counts through charcodes of letters A, B, ...
5982 \newcount\appendixno  \appendixno = `\@
5983 %
5984 % \def\appendixletter{\char\the\appendixno}
5985 % We do the following ugly conditional instead of the above simple
5986 % construct for the sake of pdftex, which needs the actual
5987 % letter in the expansion, not just typeset.
5988 %
5989 \def\appendixletter{%
5990   \ifnum\appendixno=`A A%
5991   \else\ifnum\appendixno=`B B%
5992   \else\ifnum\appendixno=`C C%
5993   \else\ifnum\appendixno=`D D%
5994   \else\ifnum\appendixno=`E E%
5995   \else\ifnum\appendixno=`F F%
5996   \else\ifnum\appendixno=`G G%
5997   \else\ifnum\appendixno=`H H%
5998   \else\ifnum\appendixno=`I I%
5999   \else\ifnum\appendixno=`J J%
6000   \else\ifnum\appendixno=`K K%
6001   \else\ifnum\appendixno=`L L%
6002   \else\ifnum\appendixno=`M M%
6003   \else\ifnum\appendixno=`N N%
6004   \else\ifnum\appendixno=`O O%
6005   \else\ifnum\appendixno=`P P%
6006   \else\ifnum\appendixno=`Q Q%
6007   \else\ifnum\appendixno=`R R%
6008   \else\ifnum\appendixno=`S S%
6009   \else\ifnum\appendixno=`T T%
6010   \else\ifnum\appendixno=`U U%
6011   \else\ifnum\appendixno=`V V%
6012   \else\ifnum\appendixno=`W W%
6013   \else\ifnum\appendixno=`X X%
6014   \else\ifnum\appendixno=`Y Y%
6015   \else\ifnum\appendixno=`Z Z%
6016   % The \the is necessary, despite appearances, because \appendixletter is
6017   % expanded while writing the .toc file.  \char\appendixno is not
6018   % expandable, thus it is written literally, thus all appendixes come out
6019   % with the same letter (or @) in the toc without it.
6020   \else\char\the\appendixno
6021   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
6022   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
6023
6024 % Each @chapter defines these (using marks) as the number+name, number
6025 % and name of the chapter.  Page headings and footings can use
6026 % these.  @section does likewise.
6027 \def\thischapter{}
6028 \def\thischapternum{}
6029 \def\thischaptername{}
6030 \def\thissection{}
6031 \def\thissectionnum{}
6032 \def\thissectionname{}
6033
6034 \newcount\absseclevel % used to calculate proper heading level
6035 \newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
6036
6037 % @raisesections: treat @section as chapter, @subsection as section, etc.
6038 \def\raisesections{\global\advance\secbase by -1}
6039 \let\up=\raisesections % original BFox name
6040
6041 % @lowersections: treat @chapter as section, @section as subsection, etc.
6042 \def\lowersections{\global\advance\secbase by 1}
6043 \let\down=\lowersections % original BFox name
6044
6045 % we only have subsub.
6046 \chardef\maxseclevel = 3
6047 %
6048 % A numbered section within an unnumbered changes to unnumbered too.
6049 % To achieve this, remember the "biggest" unnum. sec. we are currently in:
6050 \chardef\unnlevel = \maxseclevel
6051 %
6052 % Trace whether the current chapter is an appendix or not:
6053 % \chapheadtype is "N" or "A", unnumbered chapters are ignored.
6054 \def\chapheadtype{N}
6055
6056 % Choose a heading macro
6057 % #1 is heading type
6058 % #2 is heading level
6059 % #3 is text for heading
6060 \def\genhead#1#2#3{%
6061   % Compute the abs. sec. level:
6062   \absseclevel=#2
6063   \advance\absseclevel by \secbase
6064   % Make sure \absseclevel doesn't fall outside the range:
6065   \ifnum \absseclevel < 0
6066     \absseclevel = 0
6067   \else
6068     \ifnum \absseclevel > 3
6069       \absseclevel = 3
6070     \fi
6071   \fi
6072   % The heading type:
6073   \def\headtype{#1}%
6074   \if \headtype U%
6075     \ifnum \absseclevel < \unnlevel
6076       \chardef\unnlevel = \absseclevel
6077     \fi
6078   \else
6079     % Check for appendix sections:
6080     \ifnum \absseclevel = 0
6081       \edef\chapheadtype{\headtype}%
6082     \else
6083       \if \headtype A\if \chapheadtype N%
6084         \errmessage{@appendix... within a non-appendix chapter}%
6085       \fi\fi
6086     \fi
6087     % Check for numbered within unnumbered:
6088     \ifnum \absseclevel > \unnlevel
6089       \def\headtype{U}%
6090     \else
6091       \chardef\unnlevel = 3
6092     \fi
6093   \fi
6094   % Now print the heading:
6095   \if \headtype U%
6096     \ifcase\absseclevel
6097         \unnumberedzzz{#3}%
6098     \or \unnumberedseczzz{#3}%
6099     \or \unnumberedsubseczzz{#3}%
6100     \or \unnumberedsubsubseczzz{#3}%
6101     \fi
6102   \else
6103     \if \headtype A%
6104       \ifcase\absseclevel
6105           \appendixzzz{#3}%
6106       \or \appendixsectionzzz{#3}%
6107       \or \appendixsubseczzz{#3}%
6108       \or \appendixsubsubseczzz{#3}%
6109       \fi
6110     \else
6111       \ifcase\absseclevel
6112           \chapterzzz{#3}%
6113       \or \seczzz{#3}%
6114       \or \numberedsubseczzz{#3}%
6115       \or \numberedsubsubseczzz{#3}%
6116       \fi
6117     \fi
6118   \fi
6119   \suppressfirstparagraphindent
6120 }
6121
6122 % an interface:
6123 \def\numhead{\genhead N}
6124 \def\apphead{\genhead A}
6125 \def\unnmhead{\genhead U}
6126
6127 % @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
6128 % all lower-level sectioning counters to zero.
6129 %
6130 % Also set \chaplevelprefix, which we prepend to @float sequence numbers
6131 % (e.g., figures), q.v.  By default (before any chapter), that is empty.
6132 \let\chaplevelprefix = \empty
6133 %
6134 \outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
6135 \def\chapterzzz#1{%
6136   % section resetting is \global in case the chapter is in a group, such
6137   % as an @include file.
6138   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6139     \global\advance\chapno by 1
6140   %
6141   % Used for \float.
6142   \gdef\chaplevelprefix{\the\chapno.}%
6143   \resetallfloatnos
6144   %
6145   % \putwordChapter can contain complex things in translations.
6146   \toks0=\expandafter{\putwordChapter}%
6147   \message{\the\toks0 \space \the\chapno}%
6148   %
6149   % Write the actual heading.
6150   \chapmacro{#1}{Ynumbered}{\the\chapno}%
6151   %
6152   % So @section and the like are numbered underneath this chapter.
6153   \global\let\section = \numberedsec
6154   \global\let\subsection = \numberedsubsec
6155   \global\let\subsubsection = \numberedsubsubsec
6156 }
6157
6158 \outer\parseargdef\appendix{\apphead0{#1}} % normally calls appendixzzz
6159 %
6160 \def\appendixzzz#1{%
6161   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6162     \global\advance\appendixno by 1
6163   \gdef\chaplevelprefix{\appendixletter.}%
6164   \resetallfloatnos
6165   %
6166   % \putwordAppendix can contain complex things in translations.
6167   \toks0=\expandafter{\putwordAppendix}%
6168   \message{\the\toks0 \space \appendixletter}%
6169   %
6170   \chapmacro{#1}{Yappendix}{\appendixletter}%
6171   %
6172   \global\let\section = \appendixsec
6173   \global\let\subsection = \appendixsubsec
6174   \global\let\subsubsection = \appendixsubsubsec
6175 }
6176
6177 % normally unnmhead0 calls unnumberedzzz:
6178 \outer\parseargdef\unnumbered{\unnmhead0{#1}}
6179 \def\unnumberedzzz#1{%
6180   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6181     \global\advance\unnumberedno by 1
6182   %
6183   % Since an unnumbered has no number, no prefix for figures.
6184   \global\let\chaplevelprefix = \empty
6185   \resetallfloatnos
6186   %
6187   % This used to be simply \message{#1}, but TeX fully expands the
6188   % argument to \message.  Therefore, if #1 contained @-commands, TeX
6189   % expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
6190   % expanded @cite (which turns out to cause errors because \cite is meant
6191   % to be executed, not expanded).
6192   %
6193   % Anyway, we don't want the fully-expanded definition of @cite to appear
6194   % as a result of the \message, we just want `@cite' itself.  We use
6195   % \the<toks register> to achieve this: TeX expands \the<toks> only once,
6196   % simply yielding the contents of <toks register>.  (We also do this for
6197   % the toc entries.)
6198   \toks0 = {#1}%
6199   \message{(\the\toks0)}%
6200   %
6201   \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
6202   %
6203   \global\let\section = \unnumberedsec
6204   \global\let\subsection = \unnumberedsubsec
6205   \global\let\subsubsection = \unnumberedsubsubsec
6206 }
6207
6208 % @centerchap is like @unnumbered, but the heading is centered.
6209 \outer\parseargdef\centerchap{%
6210   \let\centerparametersmaybe = \centerparameters
6211   \unnmhead0{#1}%
6212   \let\centerparametersmaybe = \relax
6213 }
6214
6215 % @top is like @unnumbered.
6216 \let\top\unnumbered
6217
6218 % Sections.
6219
6220 \outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
6221 \def\seczzz#1{%
6222   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6223   \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
6224 }
6225
6226 % normally calls appendixsectionzzz:
6227 \outer\parseargdef\appendixsection{\apphead1{#1}}
6228 \def\appendixsectionzzz#1{%
6229   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6230   \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
6231 }
6232 \let\appendixsec\appendixsection
6233
6234 % normally calls unnumberedseczzz:
6235 \outer\parseargdef\unnumberedsec{\unnmhead1{#1}}
6236 \def\unnumberedseczzz#1{%
6237   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6238   \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
6239 }
6240
6241 % Subsections.
6242
6243 % normally calls numberedsubseczzz:
6244 \outer\parseargdef\numberedsubsec{\numhead2{#1}}
6245 \def\numberedsubseczzz#1{%
6246   \global\subsubsecno=0  \global\advance\subsecno by 1
6247   \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
6248 }
6249
6250 % normally calls appendixsubseczzz:
6251 \outer\parseargdef\appendixsubsec{\apphead2{#1}}
6252 \def\appendixsubseczzz#1{%
6253   \global\subsubsecno=0  \global\advance\subsecno by 1
6254   \sectionheading{#1}{subsec}{Yappendix}%
6255                  {\appendixletter.\the\secno.\the\subsecno}%
6256 }
6257
6258 % normally calls unnumberedsubseczzz:
6259 \outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}}
6260 \def\unnumberedsubseczzz#1{%
6261   \global\subsubsecno=0  \global\advance\subsecno by 1
6262   \sectionheading{#1}{subsec}{Ynothing}%
6263                  {\the\unnumberedno.\the\secno.\the\subsecno}%
6264 }
6265
6266 % Subsubsections.
6267
6268 % normally numberedsubsubseczzz:
6269 \outer\parseargdef\numberedsubsubsec{\numhead3{#1}}
6270 \def\numberedsubsubseczzz#1{%
6271   \global\advance\subsubsecno by 1
6272   \sectionheading{#1}{subsubsec}{Ynumbered}%
6273                  {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
6274 }
6275
6276 % normally appendixsubsubseczzz:
6277 \outer\parseargdef\appendixsubsubsec{\apphead3{#1}}
6278 \def\appendixsubsubseczzz#1{%
6279   \global\advance\subsubsecno by 1
6280   \sectionheading{#1}{subsubsec}{Yappendix}%
6281                  {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
6282 }
6283
6284 % normally unnumberedsubsubseczzz:
6285 \outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}}
6286 \def\unnumberedsubsubseczzz#1{%
6287   \global\advance\subsubsecno by 1
6288   \sectionheading{#1}{subsubsec}{Ynothing}%
6289                  {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
6290 }
6291
6292 % These macros control what the section commands do, according
6293 % to what kind of chapter we are in (ordinary, appendix, or unnumbered).
6294 % Define them by default for a numbered chapter.
6295 \let\section = \numberedsec
6296 \let\subsection = \numberedsubsec
6297 \let\subsubsection = \numberedsubsubsec
6298
6299 % Define @majorheading, @heading and @subheading
6300
6301 \def\majorheading{%
6302   {\advance\chapheadingskip by 10pt \chapbreak }%
6303   \parsearg\chapheadingzzz
6304 }
6305
6306 \def\chapheading{\chapbreak \parsearg\chapheadingzzz}
6307 \def\chapheadingzzz#1{%
6308   \vbox{\chapfonts \raggedtitlesettings #1\par}%
6309   \nobreak\bigskip \nobreak
6310   \suppressfirstparagraphindent
6311 }
6312
6313 % @heading, @subheading, @subsubheading.
6314 \parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
6315   \suppressfirstparagraphindent}
6316 \parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
6317   \suppressfirstparagraphindent}
6318 \parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
6319   \suppressfirstparagraphindent}
6320
6321 % These macros generate a chapter, section, etc. heading only
6322 % (including whitespace, linebreaking, etc. around it),
6323 % given all the information in convenient, parsed form.
6324
6325 % Args are the skip and penalty (usually negative)
6326 \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
6327
6328 % Parameter controlling skip before chapter headings (if needed)
6329 \newskip\chapheadingskip
6330
6331 % Define plain chapter starts, and page on/off switching for it.
6332 \def\chapbreak{\dobreak \chapheadingskip {-4000}}
6333
6334 % Start a new page
6335 \def\chappager{\par\vfill\supereject}
6336
6337 % \chapoddpage - start on an odd page for a new chapter
6338 % Because \domark is called before \chapoddpage, the filler page will
6339 % get the headings for the next chapter, which is wrong.  But we don't
6340 % care -- we just disable all headings on the filler page.
6341 \def\chapoddpage{%
6342   \chappager
6343   \ifodd\pageno \else
6344     \begingroup
6345       \headingsoff
6346       \null
6347       \chappager
6348     \endgroup
6349   \fi
6350 }
6351
6352 \parseargdef\setchapternewpage{\csname CHAPPAG#1\endcsname}
6353
6354 \def\CHAPPAGoff{%
6355 \global\let\contentsalignmacro = \chappager
6356 \global\let\pchapsepmacro=\chapbreak
6357 \global\let\pagealignmacro=\chappager}
6358
6359 \def\CHAPPAGon{%
6360 \global\let\contentsalignmacro = \chappager
6361 \global\let\pchapsepmacro=\chappager
6362 \global\let\pagealignmacro=\chappager
6363 \global\def\HEADINGSon{\HEADINGSsingle}}
6364
6365 \def\CHAPPAGodd{%
6366 \global\let\contentsalignmacro = \chapoddpage
6367 \global\let\pchapsepmacro=\chapoddpage
6368 \global\let\pagealignmacro=\chapoddpage
6369 \global\def\HEADINGSon{\HEADINGSdouble}}
6370
6371 \CHAPPAGon
6372
6373 % \chapmacro - Chapter opening.
6374 %
6375 % #1 is the text, #2 is the section type (Ynumbered, Ynothing,
6376 % Yappendix, Yomitfromtoc), #3 the chapter number.
6377 % Not used for @heading series.
6378 %
6379 % To test against our argument.
6380 \def\Ynothingkeyword{Ynothing}
6381 \def\Yappendixkeyword{Yappendix}
6382 \def\Yomitfromtockeyword{Yomitfromtoc}
6383 %
6384 \def\chapmacro#1#2#3{%
6385   \expandafter\ifx\thisenv\titlepage\else
6386     \checkenv{}% chapters, etc., should not start inside an environment.
6387   \fi
6388   % FIXME: \chapmacro is currently called from inside \titlepage when
6389   % \setcontentsaftertitlepage to print the "Table of Contents" heading, but
6390   % this should probably be done by \sectionheading with an option to print
6391   % in chapter size.
6392   %
6393   % Insert the first mark before the heading break (see notes for \domark).
6394   \let\prevchapterdefs=\lastchapterdefs
6395   \let\prevsectiondefs=\lastsectiondefs
6396   \gdef\lastsectiondefs{\gdef\thissectionname{}\gdef\thissectionnum{}%
6397                         \gdef\thissection{}}%
6398   %
6399   \def\temptype{#2}%
6400   \ifx\temptype\Ynothingkeyword
6401     \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6402                           \gdef\thischapter{\thischaptername}}%
6403   \else\ifx\temptype\Yomitfromtockeyword
6404     \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6405                           \gdef\thischapter{}}%
6406   \else\ifx\temptype\Yappendixkeyword
6407     \toks0={#1}%
6408     \xdef\lastchapterdefs{%
6409       \gdef\noexpand\thischaptername{\the\toks0}%
6410       \gdef\noexpand\thischapternum{\appendixletter}%
6411       % \noexpand\putwordAppendix avoids expanding indigestible
6412       % commands in some of the translations.
6413       \gdef\noexpand\thischapter{\noexpand\putwordAppendix{}
6414                                  \noexpand\thischapternum:
6415                                  \noexpand\thischaptername}%
6416     }%
6417   \else
6418     \toks0={#1}%
6419     \xdef\lastchapterdefs{%
6420       \gdef\noexpand\thischaptername{\the\toks0}%
6421       \gdef\noexpand\thischapternum{\the\chapno}%
6422       % \noexpand\putwordChapter avoids expanding indigestible
6423       % commands in some of the translations.
6424       \gdef\noexpand\thischapter{\noexpand\putwordChapter{}
6425                                  \noexpand\thischapternum:
6426                                  \noexpand\thischaptername}%
6427     }%
6428   \fi\fi\fi
6429   %
6430   % Output the mark.  Pass it through \safewhatsit, to take care of
6431   % the preceding space.
6432   \safewhatsit\domark
6433   %
6434   % Insert the chapter heading break.
6435   \pchapsepmacro
6436   %
6437   % Now the second mark, after the heading break.  No break points
6438   % between here and the heading.
6439   \let\prevchapterdefs=\lastchapterdefs
6440   \let\prevsectiondefs=\lastsectiondefs
6441   \domark
6442   %
6443   {%
6444     \chapfonts \rmisbold
6445     \let\footnote=\errfootnoteheading % give better error message
6446     %
6447     % Have to define \lastsection before calling \donoderef, because the
6448     % xref code eventually uses it.  On the other hand, it has to be called
6449     % after \pchapsepmacro, or the headline will change too soon.
6450     \gdef\lastsection{#1}%
6451     %
6452     % Only insert the separating space if we have a chapter/appendix
6453     % number, and don't print the unnumbered ``number''.
6454     \ifx\temptype\Ynothingkeyword
6455       \setbox0 = \hbox{}%
6456       \def\toctype{unnchap}%
6457     \else\ifx\temptype\Yomitfromtockeyword
6458       \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
6459       \def\toctype{omit}%
6460     \else\ifx\temptype\Yappendixkeyword
6461       \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
6462       \def\toctype{app}%
6463     \else
6464       \setbox0 = \hbox{#3\enspace}%
6465       \def\toctype{numchap}%
6466     \fi\fi\fi
6467     %
6468     % Write the toc entry for this chapter.  Must come before the
6469     % \donoderef, because we include the current node name in the toc
6470     % entry, and \donoderef resets it to empty.
6471     \writetocentry{\toctype}{#1}{#3}%
6472     %
6473     % For pdftex, we have to write out the node definition (aka, make
6474     % the pdfdest) after any page break, but before the actual text has
6475     % been typeset.  If the destination for the pdf outline is after the
6476     % text, then jumping from the outline may wind up with the text not
6477     % being visible, for instance under high magnification.
6478     \donoderef{#2}%
6479     %
6480     % Typeset the actual heading.
6481     \nobreak % Avoid page breaks at the interline glue.
6482     \vbox{\raggedtitlesettings \hangindent=\wd0 \centerparametersmaybe
6483           \unhbox0 #1\par}%
6484   }%
6485   \nobreak\bigskip % no page break after a chapter title
6486   \nobreak
6487 }
6488
6489 % @centerchap -- centered and unnumbered.
6490 \let\centerparametersmaybe = \relax
6491 \def\centerparameters{%
6492   \advance\rightskip by 3\rightskip
6493   \leftskip = \rightskip
6494   \parfillskip = 0pt
6495 }
6496
6497
6498 % Section titles.  These macros combine the section number parts and
6499 % call the generic \sectionheading to do the printing.
6500 %
6501 \newskip\secheadingskip
6502 \def\secheadingbreak{\dobreak \secheadingskip{-1000}}
6503
6504 % Subsection titles.
6505 \newskip\subsecheadingskip
6506 \def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
6507
6508 % Subsubsection titles.
6509 \def\subsubsecheadingskip{\subsecheadingskip}
6510 \def\subsubsecheadingbreak{\subsecheadingbreak}
6511
6512
6513 % Print any size, any type, section title.
6514 %
6515 % #1 is the text of the title,
6516 % #2 is the section level (sec/subsec/subsubsec),
6517 % #3 is the section type (Ynumbered, Ynothing, Yappendix, Yomitfromtoc),
6518 % #4 is the section number.
6519 %
6520 \def\seckeyword{sec}
6521 %
6522 \def\sectionheading#1#2#3#4{%
6523   {%
6524     \def\sectionlevel{#2}%
6525     \def\temptype{#3}%
6526     %
6527     % It is ok for the @heading series commands to appear inside an
6528     % environment (it's been historically allowed, though the logic is
6529     % dubious), but not the others.
6530     \ifx\temptype\Yomitfromtockeyword\else
6531       \checkenv{}% non-@*heading should not be in an environment.
6532     \fi
6533     \let\footnote=\errfootnoteheading
6534     %
6535     % Switch to the right set of fonts.
6536     \csname #2fonts\endcsname \rmisbold
6537     %
6538     % Insert first mark before the heading break (see notes for \domark).
6539     \let\prevsectiondefs=\lastsectiondefs
6540     \ifx\temptype\Ynothingkeyword
6541       \ifx\sectionlevel\seckeyword
6542         \gdef\lastsectiondefs{\gdef\thissectionname{#1}\gdef\thissectionnum{}%
6543                               \gdef\thissection{\thissectionname}}%
6544       \fi
6545     \else\ifx\temptype\Yomitfromtockeyword
6546       % Don't redefine \thissection.
6547     \else\ifx\temptype\Yappendixkeyword
6548       \ifx\sectionlevel\seckeyword
6549         \toks0={#1}%
6550         \xdef\lastsectiondefs{%
6551           \gdef\noexpand\thissectionname{\the\toks0}%
6552           \gdef\noexpand\thissectionnum{#4}%
6553           % \noexpand\putwordSection avoids expanding indigestible
6554           % commands in some of the translations.
6555           \gdef\noexpand\thissection{\noexpand\putwordSection{}
6556                                      \noexpand\thissectionnum:
6557                                      \noexpand\thissectionname}%
6558         }%
6559       \fi
6560     \else
6561       \ifx\sectionlevel\seckeyword
6562         \toks0={#1}%
6563         \xdef\lastsectiondefs{%
6564           \gdef\noexpand\thissectionname{\the\toks0}%
6565           \gdef\noexpand\thissectionnum{#4}%
6566           % \noexpand\putwordSection avoids expanding indigestible
6567           % commands in some of the translations.
6568           \gdef\noexpand\thissection{\noexpand\putwordSection{}
6569                                      \noexpand\thissectionnum:
6570                                      \noexpand\thissectionname}%
6571         }%
6572       \fi
6573     \fi\fi\fi
6574     %
6575     % Go into vertical mode.  Usually we'll already be there, but we
6576     % don't want the following whatsit to end up in a preceding paragraph
6577     % if the document didn't happen to have a blank line.
6578     \par
6579     %
6580     % Output the mark.  Pass it through \safewhatsit, to take care of
6581     % the preceding space.
6582     \safewhatsit\domark
6583     %
6584     % Insert space above the heading.
6585     \csname #2headingbreak\endcsname
6586     %
6587     % Now the second mark, after the heading break.  No break points
6588     % between here and the heading.
6589     \global\let\prevsectiondefs=\lastsectiondefs
6590     \domark
6591     %
6592     % Only insert the space after the number if we have a section number.
6593     \ifx\temptype\Ynothingkeyword
6594       \setbox0 = \hbox{}%
6595       \def\toctype{unn}%
6596       \gdef\lastsection{#1}%
6597     \else\ifx\temptype\Yomitfromtockeyword
6598       % for @headings -- no section number, don't include in toc,
6599       % and don't redefine \lastsection.
6600       \setbox0 = \hbox{}%
6601       \def\toctype{omit}%
6602       \let\sectionlevel=\empty
6603     \else\ifx\temptype\Yappendixkeyword
6604       \setbox0 = \hbox{#4\enspace}%
6605       \def\toctype{app}%
6606       \gdef\lastsection{#1}%
6607     \else
6608       \setbox0 = \hbox{#4\enspace}%
6609       \def\toctype{num}%
6610       \gdef\lastsection{#1}%
6611     \fi\fi\fi
6612     %
6613     % Write the toc entry (before \donoderef).  See comments in \chapmacro.
6614     \writetocentry{\toctype\sectionlevel}{#1}{#4}%
6615     %
6616     % Write the node reference (= pdf destination for pdftex).
6617     % Again, see comments in \chapmacro.
6618     \donoderef{#3}%
6619     %
6620     % Interline glue will be inserted when the vbox is completed.
6621     % That glue will be a valid breakpoint for the page, since it'll be
6622     % preceded by a whatsit (usually from the \donoderef, or from the
6623     % \writetocentry if there was no node).  We don't want to allow that
6624     % break, since then the whatsits could end up on page n while the
6625     % section is on page n+1, thus toc/etc. are wrong.  Debian bug 276000.
6626     \nobreak
6627     %
6628     % Output the actual section heading.
6629     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \ptexraggedright
6630           \hangindent=\wd0  % zero if no section number
6631           \unhbox0 #1}%
6632   }%
6633   % Add extra space after the heading -- half of whatever came above it.
6634   % Don't allow stretch, though.
6635   \kern .5 \csname #2headingskip\endcsname
6636   %
6637   % Do not let the kern be a potential breakpoint, as it would be if it
6638   % was followed by glue.
6639   \nobreak
6640   %
6641   % We'll almost certainly start a paragraph next, so don't let that
6642   % glue accumulate.  (Not a breakpoint because it's preceded by a
6643   % discardable item.)  However, when a paragraph is not started next
6644   % (\startdefun, \cartouche, \center, etc.), this needs to be wiped out
6645   % or the negative glue will cause weirdly wrong output, typically
6646   % obscuring the section heading with something else.
6647   \vskip-\parskip
6648   %
6649   % This is so the last item on the main vertical list is a known
6650   % \penalty > 10000, so \startdefun, etc., can recognize the situation
6651   % and do the needful.
6652   \penalty 10001
6653 }
6654
6655
6656 \message{toc,}
6657 % Table of contents.
6658 \newwrite\tocfile
6659
6660 % Write an entry to the toc file, opening it if necessary.
6661 % Called from @chapter, etc.
6662 %
6663 % Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
6664 % We append the current node name (if any) and page number as additional
6665 % arguments for the \{chap,sec,...}entry macros which will eventually
6666 % read this.  The node name is used in the pdf outlines as the
6667 % destination to jump to.
6668 %
6669 % We open the .toc file for writing here instead of at @setfilename (or
6670 % any other fixed time) so that @contents can be anywhere in the document.
6671 % But if #1 is `omit', then we don't do anything.  This is used for the
6672 % table of contents chapter openings themselves.
6673 %
6674 \newif\iftocfileopened
6675 \def\omitkeyword{omit}%
6676 %
6677 \def\writetocentry#1#2#3{%
6678   \edef\writetoctype{#1}%
6679   \ifx\writetoctype\omitkeyword \else
6680     \iftocfileopened\else
6681       \immediate\openout\tocfile = \jobname.toc
6682       \global\tocfileopenedtrue
6683     \fi
6684     %
6685     \iflinks
6686       {\atdummies
6687        \edef\temp{%
6688          \write\tocfile{@#1entry{#2}{#3}{\lastnode}{\noexpand\folio}}}%
6689        \temp
6690       }%
6691     \fi
6692   \fi
6693   %
6694   % Tell \shipout to create a pdf destination on each page, if we're
6695   % writing pdf.  These are used in the table of contents.  We can't
6696   % just write one on every page because the title pages are numbered
6697   % 1 and 2 (the page numbers aren't printed), and so are the first
6698   % two pages of the document.  Thus, we'd have two destinations named
6699   % `1', and two named `2'.
6700   \ifpdf
6701     \global\pdfmakepagedesttrue
6702   \else
6703     \ifx\XeTeXrevision\thisisundefined
6704     \else
6705       \global\pdfmakepagedesttrue
6706     \fi
6707   \fi
6708 }
6709
6710
6711 % These characters do not print properly in the Computer Modern roman
6712 % fonts, so we must take special care.  This is more or less redundant
6713 % with the Texinfo input format setup at the end of this file.
6714 %
6715 \def\activecatcodes{%
6716   \catcode`\"=\active
6717   \catcode`\$=\active
6718   \catcode`\<=\active
6719   \catcode`\>=\active
6720   \catcode`\\=\active
6721   \catcode`\^=\active
6722   \catcode`\_=\active
6723   \catcode`\|=\active
6724   \catcode`\~=\active
6725 }
6726
6727
6728 % Read the toc file, which is essentially Texinfo input.
6729 \def\readtocfile{%
6730   \setupdatafile
6731   \activecatcodes
6732   \input \tocreadfilename
6733 }
6734
6735 \newskip\contentsrightmargin \contentsrightmargin=1in
6736 \newcount\savepageno
6737 \newcount\lastnegativepageno \lastnegativepageno = -1
6738
6739 % Prepare to read what we've written to \tocfile.
6740 %
6741 \def\startcontents#1{%
6742   % If @setchapternewpage on, and @headings double, the contents should
6743   % start on an odd page, unlike chapters.  Thus, we maintain
6744   % \contentsalignmacro in parallel with \pagealignmacro.
6745   % From: Torbjorn Granlund <tege@matematik.su.se>
6746   \contentsalignmacro
6747   \immediate\closeout\tocfile
6748   %
6749   % Don't need to put `Contents' or `Short Contents' in the headline.
6750   % It is abundantly clear what they are.
6751   \chapmacro{#1}{Yomitfromtoc}{}%
6752   %
6753   \savepageno = \pageno
6754   \begingroup                  % Set up to handle contents files properly.
6755     \raggedbottom              % Worry more about breakpoints than the bottom.
6756     \entryrightmargin=\contentsrightmargin % Don't use the full line length.
6757     %
6758     % Roman numerals for page numbers.
6759     \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
6760 }
6761
6762 % redefined for the two-volume lispref.  We always output on
6763 % \jobname.toc even if this is redefined.
6764 %
6765 \def\tocreadfilename{\jobname.toc}
6766
6767 % Normal (long) toc.
6768 %
6769 \def\contents{%
6770   \startcontents{\putwordTOC}%
6771     \openin 1 \tocreadfilename\space
6772     \ifeof 1 \else
6773       \readtocfile
6774     \fi
6775     \vfill \eject
6776     \contentsalignmacro % in case @setchapternewpage odd is in effect
6777     \ifeof 1 \else
6778       \pdfmakeoutlines
6779     \fi
6780     \closein 1
6781   \endgroup
6782   \lastnegativepageno = \pageno
6783   \global\pageno = \savepageno
6784 }
6785
6786 % And just the chapters.
6787 \def\summarycontents{%
6788   \startcontents{\putwordShortTOC}%
6789     %
6790     \let\partentry = \shortpartentry
6791     \let\numchapentry = \shortchapentry
6792     \let\appentry = \shortchapentry
6793     \let\unnchapentry = \shortunnchapentry
6794     % We want a true roman here for the page numbers.
6795     \secfonts
6796     \let\rm=\shortcontrm \let\bf=\shortcontbf
6797     \let\sl=\shortcontsl \let\tt=\shortconttt
6798     \rm
6799     \hyphenpenalty = 10000
6800     \advance\baselineskip by 1pt % Open it up a little.
6801     \def\numsecentry##1##2##3##4{}
6802     \let\appsecentry = \numsecentry
6803     \let\unnsecentry = \numsecentry
6804     \let\numsubsecentry = \numsecentry
6805     \let\appsubsecentry = \numsecentry
6806     \let\unnsubsecentry = \numsecentry
6807     \let\numsubsubsecentry = \numsecentry
6808     \let\appsubsubsecentry = \numsecentry
6809     \let\unnsubsubsecentry = \numsecentry
6810     \openin 1 \tocreadfilename\space
6811     \ifeof 1 \else
6812       \readtocfile
6813     \fi
6814     \closein 1
6815     \vfill \eject
6816     \contentsalignmacro % in case @setchapternewpage odd is in effect
6817   \endgroup
6818   \lastnegativepageno = \pageno
6819   \global\pageno = \savepageno
6820 }
6821 \let\shortcontents = \summarycontents
6822
6823 % Typeset the label for a chapter or appendix for the short contents.
6824 % The arg is, e.g., `A' for an appendix, or `3' for a chapter.
6825 %
6826 \def\shortchaplabel#1{%
6827   % This space should be enough, since a single number is .5em, and the
6828   % widest letter (M) is 1em, at least in the Computer Modern fonts.
6829   % But use \hss just in case.
6830   % (This space doesn't include the extra space that gets added after
6831   % the label; that gets put in by \shortchapentry above.)
6832   %
6833   % We'd like to right-justify chapter numbers, but that looks strange
6834   % with appendix letters.  And right-justifying numbers and
6835   % left-justifying letters looks strange when there is less than 10
6836   % chapters.  Have to read the whole toc once to know how many chapters
6837   % there are before deciding ...
6838   \hbox to 1em{#1\hss}%
6839 }
6840
6841 % These macros generate individual entries in the table of contents.
6842 % The first argument is the chapter or section name.
6843 % The last argument is the page number.
6844 % The arguments in between are the chapter number, section number, ...
6845
6846 % Parts, in the main contents.  Replace the part number, which doesn't
6847 % exist, with an empty box.  Let's hope all the numbers have the same width.
6848 % Also ignore the page number, which is conventionally not printed.
6849 \def\numeralbox{\setbox0=\hbox{8}\hbox to \wd0{\hfil}}
6850 \def\partentry#1#2#3#4{\dochapentry{\numeralbox\labelspace#1}{}}
6851 %
6852 % Parts, in the short toc.
6853 \def\shortpartentry#1#2#3#4{%
6854   \penalty-300
6855   \vskip.5\baselineskip plus.15\baselineskip minus.1\baselineskip
6856   \shortchapentry{{\bf #1}}{\numeralbox}{}{}%
6857 }
6858
6859 % Chapters, in the main contents.
6860 \def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
6861
6862 % Chapters, in the short toc.
6863 % See comments in \dochapentry re vbox and related settings.
6864 \def\shortchapentry#1#2#3#4{%
6865   \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
6866 }
6867
6868 % Appendices, in the main contents.
6869 % Need the word Appendix, and a fixed-size box.
6870 %
6871 \def\appendixbox#1{%
6872   % We use M since it's probably the widest letter.
6873   \setbox0 = \hbox{\putwordAppendix{} M}%
6874   \hbox to \wd0{\putwordAppendix{} #1\hss}}
6875 %
6876 \def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\hskip.7em#1}{#4}}
6877
6878 % Unnumbered chapters.
6879 \def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
6880 \def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
6881
6882 % Sections.
6883 \def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
6884 \let\appsecentry=\numsecentry
6885 \def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
6886
6887 % Subsections.
6888 \def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
6889 \let\appsubsecentry=\numsubsecentry
6890 \def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
6891
6892 % And subsubsections.
6893 \def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
6894 \let\appsubsubsecentry=\numsubsubsecentry
6895 \def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
6896
6897 % This parameter controls the indentation of the various levels.
6898 % Same as \defaultparindent.
6899 \newdimen\tocindent \tocindent = 15pt
6900
6901 % Now for the actual typesetting. In all these, #1 is the text and #2 is the
6902 % page number.
6903 %
6904 % If the toc has to be broken over pages, we want it to be at chapters
6905 % if at all possible; hence the \penalty.
6906 \def\dochapentry#1#2{%
6907    \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
6908    \begingroup
6909      % Move the page numbers slightly to the right
6910      \advance\entryrightmargin by -0.05em
6911      \chapentryfonts
6912      \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6913    \endgroup
6914    \nobreak\vskip .25\baselineskip plus.1\baselineskip
6915 }
6916
6917 \def\dosecentry#1#2{\begingroup
6918   \secentryfonts \leftskip=\tocindent
6919   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6920 \endgroup}
6921
6922 \def\dosubsecentry#1#2{\begingroup
6923   \subsecentryfonts \leftskip=2\tocindent
6924   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6925 \endgroup}
6926
6927 \def\dosubsubsecentry#1#2{\begingroup
6928   \subsubsecentryfonts \leftskip=3\tocindent
6929   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6930 \endgroup}
6931
6932 % We use the same \entry macro as for the index entries.
6933 \let\tocentry = \entry
6934
6935 % Space between chapter (or whatever) number and the title.
6936 \def\labelspace{\hskip1em \relax}
6937
6938 \def\dopageno#1{{\rm #1}}
6939 \def\doshortpageno#1{{\rm #1}}
6940
6941 \def\chapentryfonts{\secfonts \rm}
6942 \def\secentryfonts{\textfonts}
6943 \def\subsecentryfonts{\textfonts}
6944 \def\subsubsecentryfonts{\textfonts}
6945
6946
6947 \message{environments,}
6948 % @foo ... @end foo.
6949
6950 % @tex ... @end tex    escapes into raw TeX temporarily.
6951 % One exception: @ is still an escape character, so that @end tex works.
6952 % But \@ or @@ will get a plain @ character.
6953
6954 \envdef\tex{%
6955   \setupmarkupstyle{tex}%
6956   \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
6957   \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
6958   \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
6959   \catcode `\%=14
6960   \catcode `\+=\other
6961   \catcode `\"=\other
6962   \catcode `\|=\other
6963   \catcode `\<=\other
6964   \catcode `\>=\other
6965   \catcode `\`=\other
6966   \catcode `\'=\other
6967   %
6968   % ' is active in math mode (mathcode"8000).  So reset it, and all our
6969   % other math active characters (just in case), to plain's definitions.
6970   \mathactive
6971   %
6972   % Inverse of the list at the beginning of the file.
6973   \let\b=\ptexb
6974   \let\bullet=\ptexbullet
6975   \let\c=\ptexc
6976   \let\,=\ptexcomma
6977   \let\.=\ptexdot
6978   \let\dots=\ptexdots
6979   \let\equiv=\ptexequiv
6980   \let\!=\ptexexclam
6981   \let\i=\ptexi
6982   \let\indent=\ptexindent
6983   \let\noindent=\ptexnoindent
6984   \let\{=\ptexlbrace
6985   \let\+=\tabalign
6986   \let\}=\ptexrbrace
6987   \let\/=\ptexslash
6988   \let\sp=\ptexsp
6989   \let\*=\ptexstar
6990   %\let\sup=\ptexsup % do not redefine, we want @sup to work in math mode
6991   \let\t=\ptext
6992   \expandafter \let\csname top\endcsname=\ptextop  % we've made it outer
6993   \let\frenchspacing=\plainfrenchspacing
6994   %
6995   \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
6996   \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
6997   \def\@{@}%
6998 }
6999 % There is no need to define \Etex.
7000
7001 % Define @lisp ... @end lisp.
7002 % @lisp environment forms a group so it can rebind things,
7003 % including the definition of @end lisp (which normally is erroneous).
7004
7005 % Amount to narrow the margins by for @lisp.
7006 \newskip\lispnarrowing \lispnarrowing=0.4in
7007
7008 % This is the definition that ^^M gets inside @lisp, @example, and other
7009 % such environments.  \null is better than a space, since it doesn't
7010 % have any width.
7011 \def\lisppar{\null\endgraf}
7012
7013 % This space is always present above and below environments.
7014 \newskip\envskipamount \envskipamount = 0pt
7015
7016 % Make spacing and below environment symmetrical.  We use \parskip here
7017 % to help in doing that, since in @example-like environments \parskip
7018 % is reset to zero; thus the \afterenvbreak inserts no space -- but the
7019 % start of the next paragraph will insert \parskip.
7020 %
7021 \def\aboveenvbreak{{%
7022   % =10000 instead of <10000 because of a special case in \itemzzz and
7023   % \sectionheading, q.v.
7024   \ifnum \lastpenalty=10000 \else
7025     \advance\envskipamount by \parskip
7026     \endgraf
7027     \ifdim\lastskip<\envskipamount
7028       \removelastskip
7029       \ifnum\lastpenalty<10000
7030         % Penalize breaking before the environment, because preceding text
7031         % often leads into it.
7032         \penalty100
7033       \fi
7034       \vskip\envskipamount
7035     \fi
7036   \fi
7037 }}
7038
7039 \def\afterenvbreak{{%
7040   % =10000 instead of <10000 because of a special case in \itemzzz and
7041   % \sectionheading, q.v.
7042   \ifnum \lastpenalty=10000 \else
7043     \advance\envskipamount by \parskip
7044     \endgraf
7045     \ifdim\lastskip<\envskipamount
7046       \removelastskip
7047       % it's not a good place to break if the last penalty was \nobreak
7048       % or better ...
7049       \ifnum\lastpenalty<10000 \penalty-50 \fi
7050       \vskip\envskipamount
7051     \fi
7052   \fi
7053 }}
7054
7055 % \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins; it will
7056 % also clear it, so that its embedded environments do the narrowing again.
7057 \let\nonarrowing=\relax
7058
7059 % @cartouche ... @end cartouche: draw rectangle w/rounded corners around
7060 % environment contents.
7061 \font\circle=lcircle10
7062 \newdimen\circthick
7063 \newdimen\cartouter\newdimen\cartinner
7064 \newskip\normbskip\newskip\normpskip\newskip\normlskip
7065 \circthick=\fontdimen8\circle
7066 %
7067 \def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
7068 \def\ctr{{\hskip 6pt\circle\char'010}}
7069 \def\cbl{{\circle\char'012\hskip -6pt}}
7070 \def\cbr{{\hskip 6pt\circle\char'011}}
7071 \def\carttop{\hbox to \cartouter{\hskip\lskip
7072         \ctl\leaders\hrule height\circthick\hfil\ctr
7073         \hskip\rskip}}
7074 \def\cartbot{\hbox to \cartouter{\hskip\lskip
7075         \cbl\leaders\hrule height\circthick\hfil\cbr
7076         \hskip\rskip}}
7077 %
7078 \newskip\lskip\newskip\rskip
7079
7080 \envdef\cartouche{%
7081   \ifhmode\par\fi  % can't be in the midst of a paragraph.
7082   \startsavinginserts
7083   \lskip=\leftskip \rskip=\rightskip
7084   \leftskip=0pt\rightskip=0pt % we want these *outside*.
7085   \cartinner=\hsize \advance\cartinner by-\lskip
7086   \advance\cartinner by-\rskip
7087   \cartouter=\hsize
7088   \advance\cartouter by 18.4pt  % allow for 3pt kerns on either
7089                                 % side, and for 6pt waste from
7090                                 % each corner char, and rule thickness
7091   \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
7092   %
7093   % If this cartouche directly follows a sectioning command, we need the
7094   % \parskip glue (backspaced over by default) or the cartouche can
7095   % collide with the section heading.
7096   \ifnum\lastpenalty>10000 \vskip\parskip \penalty\lastpenalty \fi
7097   %
7098   \setbox\groupbox=\vbox\bgroup
7099       \baselineskip=0pt\parskip=0pt\lineskip=0pt
7100       \carttop
7101       \hbox\bgroup
7102           \hskip\lskip
7103           \vrule\kern3pt
7104           \vbox\bgroup
7105               \kern3pt
7106               \hsize=\cartinner
7107               \baselineskip=\normbskip
7108               \lineskip=\normlskip
7109               \parskip=\normpskip
7110               \vskip -\parskip
7111               \comment % For explanation, see the end of def\group.
7112 }
7113 \def\Ecartouche{%
7114               \ifhmode\par\fi
7115               \kern3pt
7116           \egroup
7117           \kern3pt\vrule
7118           \hskip\rskip
7119       \egroup
7120       \cartbot
7121   \egroup
7122   \addgroupbox
7123   \checkinserts
7124 }
7125
7126
7127 % This macro is called at the beginning of all the @example variants,
7128 % inside a group.
7129 \newdimen\nonfillparindent
7130 \def\nonfillstart{%
7131   \aboveenvbreak
7132   \ifdim\hfuzz < 12pt \hfuzz = 12pt \fi % Don't be fussy
7133   \sepspaces % Make spaces be word-separators rather than space tokens.
7134   \let\par = \lisppar % don't ignore blank lines
7135   \obeylines % each line of input is a line of output
7136   \parskip = 0pt
7137   % Turn off paragraph indentation but redefine \indent to emulate
7138   % the normal \indent.
7139   \nonfillparindent=\parindent
7140   \parindent = 0pt
7141   \let\indent\nonfillindent
7142   %
7143   \emergencystretch = 0pt % don't try to avoid overfull boxes
7144   \ifx\nonarrowing\relax
7145     \advance \leftskip by \lispnarrowing
7146     \exdentamount=\lispnarrowing
7147   \else
7148     \let\nonarrowing = \relax
7149   \fi
7150   \let\exdent=\nofillexdent
7151 }
7152
7153 \begingroup
7154 \obeyspaces
7155 % We want to swallow spaces (but not other tokens) after the fake
7156 % @indent in our nonfill-environments, where spaces are normally
7157 % active and set to @tie, resulting in them not being ignored after
7158 % @indent.
7159 \gdef\nonfillindent{\futurelet\temp\nonfillindentcheck}%
7160 \gdef\nonfillindentcheck{%
7161 \ifx\temp %
7162 \expandafter\nonfillindentgobble%
7163 \else%
7164 \leavevmode\nonfillindentbox%
7165 \fi%
7166 }%
7167 \endgroup
7168 \def\nonfillindentgobble#1{\nonfillindent}
7169 \def\nonfillindentbox{\hbox to \nonfillparindent{\hss}}
7170
7171 % If you want all examples etc. small: @set dispenvsize small.
7172 % If you want even small examples the full size: @set dispenvsize nosmall.
7173 % This affects the following displayed environments:
7174 %    @example, @display, @format, @lisp
7175 %
7176 \def\smallword{small}
7177 \def\nosmallword{nosmall}
7178 \let\SETdispenvsize\relax
7179 \def\setnormaldispenv{%
7180   \ifx\SETdispenvsize\smallword
7181     % end paragraph for sake of leading, in case document has no blank
7182     % line.  This is redundant with what happens in \aboveenvbreak, but
7183     % we need to do it before changing the fonts, and it's inconvenient
7184     % to change the fonts afterward.
7185     \ifnum \lastpenalty=10000 \else \endgraf \fi
7186     \smallexamplefonts \rm
7187   \fi
7188 }
7189 \def\setsmalldispenv{%
7190   \ifx\SETdispenvsize\nosmallword
7191   \else
7192     \ifnum \lastpenalty=10000 \else \endgraf \fi
7193     \smallexamplefonts \rm
7194   \fi
7195 }
7196
7197 % We often define two environments, @foo and @smallfoo.
7198 % Let's do it in one command.  #1 is the env name, #2 the definition.
7199 \def\makedispenvdef#1#2{%
7200   \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}%
7201   \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}%
7202   \expandafter\let\csname E#1\endcsname \afterenvbreak
7203   \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
7204 }
7205
7206 % Define two environment synonyms (#1 and #2) for an environment.
7207 \def\maketwodispenvdef#1#2#3{%
7208   \makedispenvdef{#1}{#3}%
7209   \makedispenvdef{#2}{#3}%
7210 }
7211 %
7212 % @lisp: indented, narrowed, typewriter font;
7213 % @example: same as @lisp.
7214 %
7215 % @smallexample and @smalllisp: use smaller fonts.
7216 % Originally contributed by Pavel@xerox.
7217 %
7218 \maketwodispenvdef{lisp}{example}{%
7219   \nonfillstart
7220   \tt\setupmarkupstyle{example}%
7221   \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
7222   \gobble % eat return
7223 }
7224 % @display/@smalldisplay: same as @lisp except keep current font.
7225 %
7226 \makedispenvdef{display}{%
7227   \nonfillstart
7228   \gobble
7229 }
7230
7231 % @format/@smallformat: same as @display except don't narrow margins.
7232 %
7233 \makedispenvdef{format}{%
7234   \let\nonarrowing = t%
7235   \nonfillstart
7236   \gobble
7237 }
7238
7239 % @flushleft: same as @format, but doesn't obey \SETdispenvsize.
7240 \envdef\flushleft{%
7241   \let\nonarrowing = t%
7242   \nonfillstart
7243   \gobble
7244 }
7245 \let\Eflushleft = \afterenvbreak
7246
7247 % @flushright.
7248 %
7249 \envdef\flushright{%
7250   \let\nonarrowing = t%
7251   \nonfillstart
7252   \advance\leftskip by 0pt plus 1fill\relax
7253   \gobble
7254 }
7255 \let\Eflushright = \afterenvbreak
7256
7257
7258 % @raggedright does more-or-less normal line breaking but no right
7259 % justification.  From plain.tex.  Don't stretch around special
7260 % characters in urls in this environment, since the stretch at the right
7261 % should be enough.
7262 \envdef\raggedright{%
7263   \rightskip0pt plus2.4em \spaceskip.3333em \xspaceskip.5em\relax
7264   \def\urefprestretchamount{0pt}%
7265   \def\urefpoststretchamount{0pt}%
7266 }
7267 \let\Eraggedright\par
7268
7269 \envdef\raggedleft{%
7270   \parindent=0pt \leftskip0pt plus2em
7271   \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7272   \hbadness=10000 % Last line will usually be underfull, so turn off
7273                   % badness reporting.
7274 }
7275 \let\Eraggedleft\par
7276
7277 \envdef\raggedcenter{%
7278   \parindent=0pt \rightskip0pt plus1em \leftskip0pt plus1em
7279   \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7280   \hbadness=10000 % Last line will usually be underfull, so turn off
7281                   % badness reporting.
7282 }
7283 \let\Eraggedcenter\par
7284
7285
7286 % @quotation does normal linebreaking (hence we can't use \nonfillstart)
7287 % and narrows the margins.  We keep \parskip nonzero in general, since
7288 % we're doing normal filling.  So, when using \aboveenvbreak and
7289 % \afterenvbreak, temporarily make \parskip 0.
7290 %
7291 \makedispenvdef{quotation}{\quotationstart}
7292 %
7293 \def\quotationstart{%
7294   \indentedblockstart % same as \indentedblock, but increase right margin too.
7295   \ifx\nonarrowing\relax
7296     \advance\rightskip by \lispnarrowing
7297   \fi
7298   \parsearg\quotationlabel
7299 }
7300
7301 % We have retained a nonzero parskip for the environment, since we're
7302 % doing normal filling.
7303 %
7304 \def\Equotation{%
7305   \par
7306   \ifx\quotationauthor\thisisundefined\else
7307     % indent a bit.
7308     \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
7309   \fi
7310   {\parskip=0pt \afterenvbreak}%
7311 }
7312 \def\Esmallquotation{\Equotation}
7313
7314 % If we're given an argument, typeset it in bold with a colon after.
7315 \def\quotationlabel#1{%
7316   \def\temp{#1}%
7317   \ifx\temp\empty \else
7318     {\bf #1: }%
7319   \fi
7320 }
7321
7322 % @indentedblock is like @quotation, but indents only on the left and
7323 % has no optional argument.
7324
7325 \makedispenvdef{indentedblock}{\indentedblockstart}
7326 %
7327 \def\indentedblockstart{%
7328   {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
7329   \parindent=0pt
7330   %
7331   % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
7332   \ifx\nonarrowing\relax
7333     \advance\leftskip by \lispnarrowing
7334     \exdentamount = \lispnarrowing
7335   \else
7336     \let\nonarrowing = \relax
7337   \fi
7338 }
7339
7340 % Keep a nonzero parskip for the environment, since we're doing normal filling.
7341 %
7342 \def\Eindentedblock{%
7343   \par
7344   {\parskip=0pt \afterenvbreak}%
7345 }
7346 \def\Esmallindentedblock{\Eindentedblock}
7347
7348
7349 % LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
7350 % If we want to allow any <char> as delimiter,
7351 % we need the curly braces so that makeinfo sees the @verb command, eg:
7352 % `@verbx...x' would look like the '@verbx' command.  --janneke@gnu.org
7353 %
7354 % [Knuth]: Donald Ervin Knuth, 1996.  The TeXbook.
7355 %
7356 % [Knuth] p.344; only we need to do the other characters Texinfo sets
7357 % active too.  Otherwise, they get lost as the first character on a
7358 % verbatim line.
7359 \def\dospecials{%
7360   \do\ \do\\\do\{\do\}\do\$\do\&%
7361   \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
7362   \do\<\do\>\do\|\do\@\do+\do\"%
7363   % Don't do the quotes -- if we do, @set txicodequoteundirected and
7364   % @set txicodequotebacktick will not have effect on @verb and
7365   % @verbatim, and ?` and !` ligatures won't get disabled.
7366   %\do\`\do\'%
7367 }
7368 %
7369 % [Knuth] p. 380
7370 \def\uncatcodespecials{%
7371   \def\do##1{\catcode`##1=\other}\dospecials}
7372 %
7373 % Setup for the @verb command.
7374 %
7375 % Eight spaces for a tab
7376 \begingroup
7377   \catcode`\^^I=\active
7378   \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
7379 \endgroup
7380 %
7381 \def\setupverb{%
7382   \tt  % easiest (and conventionally used) font for verbatim
7383   \def\par{\leavevmode\endgraf}%
7384   \setupmarkupstyle{verb}%
7385   \tabeightspaces
7386   % Respect line breaks,
7387   % print special symbols as themselves, and
7388   % make each space count
7389   % must do in this order:
7390   \obeylines \uncatcodespecials \sepspaces
7391 }
7392
7393 % Setup for the @verbatim environment
7394 %
7395 % Real tab expansion.
7396 \newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
7397 %
7398 % We typeset each line of the verbatim in an \hbox, so we can handle
7399 % tabs.  The \global is in case the verbatim line starts with an accent,
7400 % or some other command that starts with a begin-group.  Otherwise, the
7401 % entire \verbbox would disappear at the corresponding end-group, before
7402 % it is typeset.  Meanwhile, we can't have nested verbatim commands
7403 % (can we?), so the \global won't be overwriting itself.
7404 \newbox\verbbox
7405 \def\starttabbox{\global\setbox\verbbox=\hbox\bgroup}
7406 %
7407 \begingroup
7408   \catcode`\^^I=\active
7409   \gdef\tabexpand{%
7410     \catcode`\^^I=\active
7411     \def^^I{\leavevmode\egroup
7412       \dimen\verbbox=\wd\verbbox % the width so far, or since the previous tab
7413       \divide\dimen\verbbox by\tabw
7414       \multiply\dimen\verbbox by\tabw % compute previous multiple of \tabw
7415       \advance\dimen\verbbox by\tabw  % advance to next multiple of \tabw
7416       \wd\verbbox=\dimen\verbbox \box\verbbox \starttabbox
7417     }%
7418   }
7419 \endgroup
7420
7421 % start the verbatim environment.
7422 \def\setupverbatim{%
7423   \let\nonarrowing = t%
7424   \nonfillstart
7425   \tt % easiest (and conventionally used) font for verbatim
7426   % The \leavevmode here is for blank lines.  Otherwise, we would
7427   % never \starttabox and the \egroup would end verbatim mode.
7428   \def\par{\leavevmode\egroup\box\verbbox\endgraf}%
7429   \tabexpand
7430   \setupmarkupstyle{verbatim}%
7431   % Respect line breaks,
7432   % print special symbols as themselves, and
7433   % make each space count.
7434   % Must do in this order:
7435   \obeylines \uncatcodespecials \sepspaces
7436   \everypar{\starttabbox}%
7437 }
7438
7439 % Do the @verb magic: verbatim text is quoted by unique
7440 % delimiter characters.  Before first delimiter expect a
7441 % right brace, after last delimiter expect closing brace:
7442 %
7443 %    \def\doverb'{'<char>#1<char>'}'{#1}
7444 %
7445 % [Knuth] p. 382; only eat outer {}
7446 \begingroup
7447   \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
7448   \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
7449 \endgroup
7450 %
7451 \def\verb{\begingroup\setupverb\doverb}
7452 %
7453 %
7454 % Do the @verbatim magic: define the macro \doverbatim so that
7455 % the (first) argument ends when '@end verbatim' is reached, ie:
7456 %
7457 %     \def\doverbatim#1@end verbatim{#1}
7458 %
7459 % For Texinfo it's a lot easier than for LaTeX,
7460 % because texinfo's \verbatim doesn't stop at '\end{verbatim}':
7461 % we need not redefine '\', '{' and '}'.
7462 %
7463 % Inspired by LaTeX's verbatim command set [latex.ltx]
7464 %
7465 \begingroup
7466   \catcode`\ =\active
7467   \obeylines %
7468   % ignore everything up to the first ^^M, that's the newline at the end
7469   % of the @verbatim input line itself.  Otherwise we get an extra blank
7470   % line in the output.
7471   \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
7472   % We really want {...\end verbatim} in the body of the macro, but
7473   % without the active space; thus we have to use \xdef and \gobble.
7474 \endgroup
7475 %
7476 \envdef\verbatim{%
7477     \setupverbatim\doverbatim
7478 }
7479 \let\Everbatim = \afterenvbreak
7480
7481
7482 % @verbatiminclude FILE - insert text of file in verbatim environment.
7483 %
7484 \def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
7485 %
7486 \def\doverbatiminclude#1{%
7487   {%
7488     \makevalueexpandable
7489     \setupverbatim
7490     \indexnofonts       % Allow `@@' and other weird things in file names.
7491     \wlog{texinfo.tex: doing @verbatiminclude of #1^^J}%
7492     \input #1
7493     \afterenvbreak
7494   }%
7495 }
7496
7497 % @copying ... @end copying.
7498 % Save the text away for @insertcopying later.
7499 %
7500 % We save the uninterpreted tokens, rather than creating a box.
7501 % Saving the text in a box would be much easier, but then all the
7502 % typesetting commands (@smallbook, font changes, etc.) have to be done
7503 % beforehand -- and a) we want @copying to be done first in the source
7504 % file; b) letting users define the frontmatter in as flexible order as
7505 % possible is desirable.
7506 %
7507 \def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
7508 \def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
7509 %
7510 \def\insertcopying{%
7511   \begingroup
7512     \parindent = 0pt  % paragraph indentation looks wrong on title page
7513     \scanexp\copyingtext
7514   \endgroup
7515 }
7516
7517
7518 \message{defuns,}
7519 % @defun etc.
7520
7521 \newskip\defbodyindent \defbodyindent=.4in
7522 \newskip\defargsindent \defargsindent=50pt
7523 \newskip\deflastargmargin \deflastargmargin=18pt
7524 \newcount\defunpenalty
7525
7526 % Start the processing of @deffn:
7527 \def\startdefun{%
7528   \ifnum\lastpenalty<10000
7529     \medbreak
7530     \defunpenalty=10003 % Will keep this @deffn together with the
7531                         % following @def command, see below.
7532   \else
7533     % If there are two @def commands in a row, we'll have a \nobreak,
7534     % which is there to keep the function description together with its
7535     % header.  But if there's nothing but headers, we need to allow a
7536     % break somewhere.  Check specifically for penalty 10002, inserted
7537     % by \printdefunline, instead of 10000, since the sectioning
7538     % commands also insert a nobreak penalty, and we don't want to allow
7539     % a break between a section heading and a defun.
7540     %
7541     % As a further refinement, we avoid "club" headers by signalling
7542     % with penalty of 10003 after the very first @deffn in the
7543     % sequence (see above), and penalty of 10002 after any following
7544     % @def command.
7545     \ifnum\lastpenalty=10002 \penalty2000 \else \defunpenalty=10002 \fi
7546     %
7547     % Similarly, after a section heading, do not allow a break.
7548     % But do insert the glue.
7549     \medskip  % preceded by discardable penalty, so not a breakpoint
7550   \fi
7551   %
7552   \parindent=0in
7553   \advance\leftskip by \defbodyindent
7554   \exdentamount=\defbodyindent
7555 }
7556
7557 \def\dodefunx#1{%
7558   % First, check whether we are in the right environment:
7559   \checkenv#1%
7560   %
7561   % As above, allow line break if we have multiple x headers in a row.
7562   % It's not a great place, though.
7563   \ifnum\lastpenalty=10002 \penalty3000 \else \defunpenalty=10002 \fi
7564   %
7565   % And now, it's time to reuse the body of the original defun:
7566   \expandafter\gobbledefun#1%
7567 }
7568 \def\gobbledefun#1\startdefun{}
7569
7570 % \printdefunline \deffnheader{text}
7571 %
7572 \def\printdefunline#1#2{%
7573   \begingroup
7574     % call \deffnheader:
7575     #1#2 \endheader
7576     % common ending:
7577     \interlinepenalty = 10000
7578     \advance\rightskip by 0pt plus 1fil\relax
7579     \endgraf
7580     \nobreak\vskip -\parskip
7581     \penalty\defunpenalty  % signal to \startdefun and \dodefunx
7582     % Some of the @defun-type tags do not enable magic parentheses,
7583     % rendering the following check redundant.  But we don't optimize.
7584     \checkparencounts
7585   \endgroup
7586 }
7587
7588 \def\Edefun{\endgraf\medbreak}
7589
7590 % \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
7591 % the only thing remaining is to define \deffnheader.
7592 %
7593 \def\makedefun#1{%
7594   \expandafter\let\csname E#1\endcsname = \Edefun
7595   \edef\temp{\noexpand\domakedefun
7596     \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
7597   \temp
7598 }
7599
7600 % \domakedefun \deffn \deffnx \deffnheader { (defn. of \deffnheader) }
7601 %
7602 % Define \deffn and \deffnx, without parameters.
7603 % \deffnheader has to be defined explicitly.
7604 %
7605 \def\domakedefun#1#2#3{%
7606   \envdef#1{%
7607     \startdefun
7608     \doingtypefnfalse    % distinguish typed functions from all else
7609     \parseargusing\activeparens{\printdefunline#3}%
7610   }%
7611   \def#2{\dodefunx#1}%
7612   \def#3%
7613 }
7614
7615 \newif\ifdoingtypefn       % doing typed function?
7616 \newif\ifrettypeownline    % typeset return type on its own line?
7617
7618 % @deftypefnnewline on|off says whether the return type of typed functions
7619 % are printed on their own line.  This affects @deftypefn, @deftypefun,
7620 % @deftypeop, and @deftypemethod.
7621
7622 \parseargdef\deftypefnnewline{%
7623   \def\temp{#1}%
7624   \ifx\temp\onword
7625     \expandafter\let\csname SETtxideftypefnnl\endcsname
7626       = \empty
7627   \else\ifx\temp\offword
7628     \expandafter\let\csname SETtxideftypefnnl\endcsname
7629       = \relax
7630   \else
7631     \errhelp = \EMsimple
7632     \errmessage{Unknown @txideftypefnnl value `\temp',
7633                 must be on|off}%
7634   \fi\fi
7635 }
7636
7637 % Untyped functions:
7638
7639 % @deffn category name args
7640 \makedefun{deffn}{\deffngeneral{}}
7641
7642 % @deffn category class name args
7643 \makedefun{defop}#1 {\defopon{#1\ \putwordon}}
7644
7645 % \defopon {category on}class name args
7646 \def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7647
7648 % \deffngeneral {subind}category name args
7649 %
7650 \def\deffngeneral#1#2 #3 #4\endheader{%
7651   % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
7652   \dosubind{fn}{\code{#3}}{#1}%
7653   \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
7654 }
7655
7656 % Typed functions:
7657
7658 % @deftypefn category type name args
7659 \makedefun{deftypefn}{\deftypefngeneral{}}
7660
7661 % @deftypeop category class type name args
7662 \makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
7663
7664 % \deftypeopon {category on}class type name args
7665 \def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7666
7667 % \deftypefngeneral {subind}category type name args
7668 %
7669 \def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
7670   \dosubind{fn}{\code{#4}}{#1}%
7671   \doingtypefntrue
7672   \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7673 }
7674
7675 % Typed variables:
7676
7677 % @deftypevr category type var args
7678 \makedefun{deftypevr}{\deftypecvgeneral{}}
7679
7680 % @deftypecv category class type var args
7681 \makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
7682
7683 % \deftypecvof {category of}class type var args
7684 \def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
7685
7686 % \deftypecvgeneral {subind}category type var args
7687 %
7688 \def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
7689   \dosubind{vr}{\code{#4}}{#1}%
7690   \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7691 }
7692
7693 % Untyped variables:
7694
7695 % @defvr category var args
7696 \makedefun{defvr}#1 {\deftypevrheader{#1} {} }
7697
7698 % @defcv category class var args
7699 \makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
7700
7701 % \defcvof {category of}class var args
7702 \def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
7703
7704 % Types:
7705
7706 % @deftp category name args
7707 \makedefun{deftp}#1 #2 #3\endheader{%
7708   \doind{tp}{\code{#2}}%
7709   \defname{#1}{}{#2}\defunargs{#3\unskip}%
7710 }
7711
7712 % Remaining @defun-like shortcuts:
7713 \makedefun{defun}{\deffnheader{\putwordDeffunc} }
7714 \makedefun{defmac}{\deffnheader{\putwordDefmac} }
7715 \makedefun{defspec}{\deffnheader{\putwordDefspec} }
7716 \makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
7717 \makedefun{defvar}{\defvrheader{\putwordDefvar} }
7718 \makedefun{defopt}{\defvrheader{\putwordDefopt} }
7719 \makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
7720 \makedefun{defmethod}{\defopon\putwordMethodon}
7721 \makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
7722 \makedefun{defivar}{\defcvof\putwordInstanceVariableof}
7723 \makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
7724
7725 % \defname, which formats the name of the @def (not the args).
7726 % #1 is the category, such as "Function".
7727 % #2 is the return type, if any.
7728 % #3 is the function name.
7729 %
7730 % We are followed by (but not passed) the arguments, if any.
7731 %
7732 \def\defname#1#2#3{%
7733   \par
7734   % Get the values of \leftskip and \rightskip as they were outside the @def...
7735   \advance\leftskip by -\defbodyindent
7736   %
7737   % Determine if we are typesetting the return type of a typed function
7738   % on a line by itself.
7739   \rettypeownlinefalse
7740   \ifdoingtypefn  % doing a typed function specifically?
7741     % then check user option for putting return type on its own line:
7742     \expandafter\ifx\csname SETtxideftypefnnl\endcsname\relax \else
7743       \rettypeownlinetrue
7744     \fi
7745   \fi
7746   %
7747   % How we'll format the category name.  Putting it in brackets helps
7748   % distinguish it from the body text that may end up on the next line
7749   % just below it.
7750   \def\temp{#1}%
7751   \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
7752   %
7753   % Figure out line sizes for the paragraph shape.  We'll always have at
7754   % least two.
7755   \tempnum = 2
7756   %
7757   % The first line needs space for \box0; but if \rightskip is nonzero,
7758   % we need only space for the part of \box0 which exceeds it:
7759   \dimen0=\hsize  \advance\dimen0 by -\wd0  \advance\dimen0 by \rightskip
7760   %
7761   % If doing a return type on its own line, we'll have another line.
7762   \ifrettypeownline
7763     \advance\tempnum by 1
7764     \def\maybeshapeline{0in \hsize}%
7765   \else
7766     \def\maybeshapeline{}%
7767   \fi
7768   %
7769   % The continuations:
7770   \dimen2=\hsize  \advance\dimen2 by -\defargsindent
7771   %
7772   % The final paragraph shape:
7773   \parshape \tempnum  0in \dimen0  \maybeshapeline  \defargsindent \dimen2
7774   %
7775   % Put the category name at the right margin.
7776   \noindent
7777   \hbox to 0pt{%
7778     \hfil\box0 \kern-\hsize
7779     % \hsize has to be shortened this way:
7780     \kern\leftskip
7781     % Intentionally do not respect \rightskip, since we need the space.
7782   }%
7783   %
7784   % Allow all lines to be underfull without complaint:
7785   \tolerance=10000 \hbadness=10000
7786   \exdentamount=\defbodyindent
7787   {%
7788     % defun fonts. We use typewriter by default (used to be bold) because:
7789     % . we're printing identifiers, they should be in tt in principle.
7790     % . in languages with many accents, such as Czech or French, it's
7791     %   common to leave accents off identifiers.  The result looks ok in
7792     %   tt, but exceedingly strange in rm.
7793     % . we don't want -- and --- to be treated as ligatures.
7794     % . this still does not fix the ?` and !` ligatures, but so far no
7795     %   one has made identifiers using them :).
7796     \df \tt
7797     \def\temp{#2}% text of the return type
7798     \ifx\temp\empty\else
7799       \tclose{\temp}% typeset the return type
7800       \ifrettypeownline
7801         % put return type on its own line; prohibit line break following:
7802         \hfil\vadjust{\nobreak}\break  
7803       \else
7804         \space  % type on same line, so just followed by a space
7805       \fi
7806     \fi           % no return type
7807     #3% output function name
7808   }%
7809   {\rm\enskip}% hskip 0.5 em of \tenrm
7810   %
7811   \boldbrax
7812   % arguments will be output next, if any.
7813 }
7814
7815 % Print arguments in slanted roman (not ttsl), inconsistently with using
7816 % tt for the name.  This is because literal text is sometimes needed in
7817 % the argument list (groff manual), and ttsl and tt are not very
7818 % distinguishable.  Prevent hyphenation at `-' chars.
7819 %
7820 \def\defunargs#1{%
7821   % use sl by default (not ttsl),
7822   % tt for the names.
7823   \df \sl \hyphenchar\font=0
7824   %
7825   % On the other hand, if an argument has two dashes (for instance), we
7826   % want a way to get ttsl.  We used to recommend @var for that, so
7827   % leave the code in, but it's strange for @var to lead to typewriter.
7828   % Nowadays we recommend @code, since the difference between a ttsl hyphen
7829   % and a tt hyphen is pretty tiny.  @code also disables ?` !`.
7830   \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}%
7831   #1%
7832   \sl\hyphenchar\font=45
7833 }
7834
7835 % We want ()&[] to print specially on the defun line.
7836 %
7837 \def\activeparens{%
7838   \catcode`\(=\active \catcode`\)=\active
7839   \catcode`\[=\active \catcode`\]=\active
7840   \catcode`\&=\active
7841 }
7842
7843 % Make control sequences which act like normal parenthesis chars.
7844 \let\lparen = ( \let\rparen = )
7845
7846 % Be sure that we always have a definition for `(', etc.  For example,
7847 % if the fn name has parens in it, \boldbrax will not be in effect yet,
7848 % so TeX would otherwise complain about undefined control sequence.
7849 {
7850   \activeparens
7851   \global\let(=\lparen \global\let)=\rparen
7852   \global\let[=\lbrack \global\let]=\rbrack
7853   \global\let& = \&
7854
7855   \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
7856   \gdef\magicamp{\let&=\amprm}
7857 }
7858
7859 \newcount\parencount
7860
7861 % If we encounter &foo, then turn on ()-hacking afterwards
7862 \newif\ifampseen
7863 \def\amprm#1 {\ampseentrue{\bf\&#1 }}
7864
7865 \def\parenfont{%
7866   \ifampseen
7867     % At the first level, print parens in roman,
7868     % otherwise use the default font.
7869     \ifnum \parencount=1 \rm \fi
7870   \else
7871     % The \sf parens (in \boldbrax) actually are a little bolder than
7872     % the contained text.  This is especially needed for [ and ] .
7873     \sf
7874   \fi
7875 }
7876 \def\infirstlevel#1{%
7877   \ifampseen
7878     \ifnum\parencount=1
7879       #1%
7880     \fi
7881   \fi
7882 }
7883 \def\bfafterword#1 {#1 \bf}
7884
7885 \def\opnr{%
7886   \global\advance\parencount by 1
7887   {\parenfont(}%
7888   \infirstlevel \bfafterword
7889 }
7890 \def\clnr{%
7891   {\parenfont)}%
7892   \infirstlevel \sl
7893   \global\advance\parencount by -1
7894 }
7895
7896 \newcount\brackcount
7897 \def\lbrb{%
7898   \global\advance\brackcount by 1
7899   {\bf[}%
7900 }
7901 \def\rbrb{%
7902   {\bf]}%
7903   \global\advance\brackcount by -1
7904 }
7905
7906 \def\checkparencounts{%
7907   \ifnum\parencount=0 \else \badparencount \fi
7908   \ifnum\brackcount=0 \else \badbrackcount \fi
7909 }
7910 % these should not use \errmessage; the glibc manual, at least, actually
7911 % has such constructs (when documenting function pointers).
7912 \def\badparencount{%
7913   \message{Warning: unbalanced parentheses in @def...}%
7914   \global\parencount=0
7915 }
7916 \def\badbrackcount{%
7917   \message{Warning: unbalanced square brackets in @def...}%
7918   \global\brackcount=0
7919 }
7920
7921
7922 \message{macros,}
7923 % @macro.
7924
7925 % To do this right we need a feature of e-TeX, \scantokens,
7926 % which we arrange to emulate with a temporary file in ordinary TeX.
7927 \ifx\eTeXversion\thisisundefined
7928   \newwrite\macscribble
7929   \def\scantokens#1{%
7930     \toks0={#1}%
7931     \immediate\openout\macscribble=\jobname.tmp
7932     \immediate\write\macscribble{\the\toks0}%
7933     \immediate\closeout\macscribble
7934     \input \jobname.tmp
7935   }
7936 \fi
7937
7938 \let\aftermacroxxx\relax
7939 \def\aftermacro{\aftermacroxxx}
7940
7941 % alias because \c means cedilla in @tex or @math
7942 \let\texinfoc=\c
7943
7944 \newcount\savedcatcodeone
7945 \newcount\savedcatcodetwo
7946
7947 % Used at the time of macro expansion.
7948 % Argument is macro body with arguments substituted
7949 \def\scanmacro#1{%
7950   \newlinechar`\^^M
7951   \def\xeatspaces{\eatspaces}%
7952   %
7953   % Temporarily undo catcode changes of \printindex.  Set catcode of @ to
7954   % 0 so that @-commands in macro expansions aren't printed literally when 
7955   % formatting an index file, where \ is used as the escape character.
7956   \savedcatcodeone=\catcode`\@
7957   \savedcatcodetwo=\catcode`\\
7958   \catcode`\@=0
7959   \catcode`\\=\active
7960   %
7961   % Process the macro body under the current catcode regime.
7962   \scantokens{#1@texinfoc}\aftermacro%
7963   %
7964   \catcode`\@=\savedcatcodeone
7965   \catcode`\\=\savedcatcodetwo
7966   %
7967   % The \texinfoc is to remove the \newlinechar added by \scantokens, and
7968   % can be noticed by \parsearg.
7969   %   The \aftermacro allows a \comment at the end of the macro definition
7970   % to duplicate itself past the final \newlinechar added by \scantokens:
7971   % this is used in the definition of \group to comment out a newline.  We
7972   % don't do the same for \c to support Texinfo files with macros that ended
7973   % with a @c, which should no longer be necessary.
7974   %   We avoid surrounding the call to \scantokens with \bgroup and \egroup
7975   % to allow macros to open or close groups themselves.
7976 }
7977
7978 % Used for copying and captions
7979 \def\scanexp#1{%
7980   \expandafter\scanmacro\expandafter{#1}%
7981 }
7982
7983 \newcount\paramno   % Count of parameters
7984 \newtoks\macname    % Macro name
7985 \newif\ifrecursive  % Is it recursive?
7986
7987 % List of all defined macros in the form
7988 %    \definedummyword\macro1\definedummyword\macro2...
7989 % Currently is also contains all @aliases; the list can be split
7990 % if there is a need.
7991 \def\macrolist{}
7992
7993 % Add the macro to \macrolist
7994 \def\addtomacrolist#1{\expandafter \addtomacrolistxxx \csname#1\endcsname}
7995 \def\addtomacrolistxxx#1{%
7996      \toks0 = \expandafter{\macrolist\definedummyword#1}%
7997      \xdef\macrolist{\the\toks0}%
7998 }
7999
8000 % Utility routines.
8001 % This does \let #1 = #2, with \csnames; that is,
8002 %   \let \csname#1\endcsname = \csname#2\endcsname
8003 % (except of course we have to play expansion games).
8004 %
8005 \def\cslet#1#2{%
8006   \expandafter\let
8007   \csname#1\expandafter\endcsname
8008   \csname#2\endcsname
8009 }
8010
8011 % Trim leading and trailing spaces off a string.
8012 % Concepts from aro-bend problem 15 (see CTAN).
8013 {\catcode`\@=11
8014 \gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
8015 \gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
8016 \gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
8017 \def\unbrace#1{#1}
8018 \unbrace{\gdef\trim@@@ #1 } #2@{#1}
8019 }
8020
8021 % Trim a single trailing ^^M off a string.
8022 {\catcode`\^^M=\other \catcode`\Q=3%
8023 \gdef\eatcr #1{\eatcra #1Q^^MQ}%
8024 \gdef\eatcra#1^^MQ{\eatcrb#1Q}%
8025 \gdef\eatcrb#1Q#2Q{#1}%
8026 }
8027
8028 % Macro bodies are absorbed as an argument in a context where
8029 % all characters are catcode 10, 11 or 12, except \ which is active
8030 % (as in normal texinfo). It is necessary to change the definition of \
8031 % to recognize macro arguments; this is the job of \mbodybackslash.
8032 %
8033 % Non-ASCII encodings make 8-bit characters active, so un-activate
8034 % them to avoid their expansion.  Must do this non-globally, to
8035 % confine the change to the current group.
8036 %
8037 % It's necessary to have hard CRs when the macro is executed. This is
8038 % done by making ^^M (\endlinechar) catcode 12 when reading the macro
8039 % body, and then making it the \newlinechar in \scanmacro.
8040 %
8041 \def\scanctxt{% used as subroutine
8042   \catcode`\"=\other
8043   \catcode`\+=\other
8044   \catcode`\<=\other
8045   \catcode`\>=\other
8046   \catcode`\^=\other
8047   \catcode`\_=\other
8048   \catcode`\|=\other
8049   \catcode`\~=\other
8050   \passthroughcharstrue
8051 }
8052
8053 \def\scanargctxt{% used for copying and captions, not macros.
8054   \scanctxt
8055   \catcode`\@=\other
8056   \catcode`\\=\other
8057   \catcode`\^^M=\other
8058 }
8059
8060 \def\macrobodyctxt{% used for @macro definitions
8061   \scanctxt
8062   \catcode`\ =\other
8063   \catcode`\@=\other
8064   \catcode`\{=\other
8065   \catcode`\}=\other
8066   \catcode`\^^M=\other
8067   \usembodybackslash
8068 }
8069
8070 % Used when scanning braced macro arguments.  Note, however, that catcode
8071 % changes here are ineffectual if the macro invocation was nested inside
8072 % an argument to another Texinfo command.
8073 \def\macroargctxt{%
8074   \scanctxt
8075   \catcode`\ =\active
8076   \catcode`\^^M=\other
8077   \catcode`\\=\active
8078 }
8079
8080 \def\macrolineargctxt{% used for whole-line arguments without braces
8081   \scanctxt
8082   \catcode`\{=\other
8083   \catcode`\}=\other
8084 }
8085
8086 % \mbodybackslash is the definition of \ in @macro bodies.
8087 % It maps \foo\ => \csname macarg.foo\endcsname => #N
8088 % where N is the macro parameter number.
8089 % We define \csname macarg.\endcsname to be \realbackslash, so
8090 % \\ in macro replacement text gets you a backslash.
8091 %
8092 {\catcode`@=0 @catcode`@\=@active
8093  @gdef@usembodybackslash{@let\=@mbodybackslash}
8094  @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
8095 }
8096 \expandafter\def\csname macarg.\endcsname{\realbackslash}
8097
8098 \def\margbackslash#1{\char`\#1 }
8099
8100 \def\macro{\recursivefalse\parsearg\macroxxx}
8101 \def\rmacro{\recursivetrue\parsearg\macroxxx}
8102
8103 \def\macroxxx#1{%
8104   \getargs{#1}% now \macname is the macname and \argl the arglist
8105   \ifx\argl\empty       % no arguments
8106      \paramno=0\relax
8107   \else
8108      \expandafter\parsemargdef \argl;%
8109      \if\paramno>256\relax
8110        \ifx\eTeXversion\thisisundefined
8111          \errhelp = \EMsimple
8112          \errmessage{You need eTeX to compile a file with macros with more than 256 arguments}
8113        \fi
8114      \fi
8115   \fi
8116   \if1\csname ismacro.\the\macname\endcsname
8117      \message{Warning: redefining \the\macname}%
8118   \else
8119      \expandafter\ifx\csname \the\macname\endcsname \relax
8120      \else \errmessage{Macro name \the\macname\space already defined}\fi
8121      \global\cslet{macsave.\the\macname}{\the\macname}%
8122      \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
8123      \addtomacrolist{\the\macname}%
8124   \fi
8125   \begingroup \macrobodyctxt
8126   \ifrecursive \expandafter\parsermacbody
8127   \else \expandafter\parsemacbody
8128   \fi}
8129
8130 \parseargdef\unmacro{%
8131   \if1\csname ismacro.#1\endcsname
8132     \global\cslet{#1}{macsave.#1}%
8133     \global\expandafter\let \csname ismacro.#1\endcsname=0%
8134     % Remove the macro name from \macrolist:
8135     \begingroup
8136       \expandafter\let\csname#1\endcsname \relax
8137       \let\definedummyword\unmacrodo
8138       \xdef\macrolist{\macrolist}%
8139     \endgroup
8140   \else
8141     \errmessage{Macro #1 not defined}%
8142   \fi
8143 }
8144
8145 % Called by \do from \dounmacro on each macro.  The idea is to omit any
8146 % macro definitions that have been changed to \relax.
8147 %
8148 \def\unmacrodo#1{%
8149   \ifx #1\relax
8150     % remove this
8151   \else
8152     \noexpand\definedummyword \noexpand#1%
8153   \fi
8154 }
8155
8156 % \getargs -- Parse the arguments to a @macro line.  Set \macname to
8157 % the name of the macro, and \argl to the braced argument list.
8158 \def\getargs#1{\getargsxxx#1{}}
8159 \def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
8160 \def\getmacname#1 #2\relax{\macname={#1}}
8161 \def\getmacargs#1{\def\argl{#1}}
8162 % This made use of the feature that if the last token of a
8163 % <parameter list> is #, then the preceding argument is delimited by
8164 % an opening brace, and that opening brace is not consumed.
8165
8166 % Parse the optional {params} list to @macro or @rmacro.
8167 % Set \paramno to the number of arguments,
8168 % and \paramlist to a parameter text for the macro (e.g. #1,#2,#3 for a
8169 % three-param macro.)  Define \macarg.BLAH for each BLAH in the params
8170 % list to some hook where the argument is to be expanded.  If there are
8171 % less than 10 arguments that hook is to be replaced by ##N where N
8172 % is the position in that list, that is to say the macro arguments are to be
8173 % defined `a la TeX in the macro body.  
8174 %
8175 % That gets used by \mbodybackslash (above).
8176 %
8177 % If there are 10 or more arguments, a different technique is used: see
8178 % \parsemmanyargdef.
8179 %
8180 \def\parsemargdef#1;{%
8181   \paramno=0\def\paramlist{}%
8182   \let\hash\relax
8183   % \hash is redefined to `#' later to get it into definitions
8184   \let\xeatspaces\relax
8185   \parsemargdefxxx#1,;,%
8186   \ifnum\paramno<10\relax\else
8187     \paramno0\relax
8188     \parsemmanyargdef@@#1,;,% 10 or more arguments
8189   \fi
8190 }
8191 \def\parsemargdefxxx#1,{%
8192   \if#1;\let\next=\relax
8193   \else \let\next=\parsemargdefxxx
8194     \advance\paramno by 1
8195     \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
8196         {\xeatspaces{\hash\the\paramno}}%
8197     \edef\paramlist{\paramlist\hash\the\paramno,}%
8198   \fi\next}
8199
8200 % \parsemacbody, \parsermacbody
8201 %
8202 % Read recursive and nonrecursive macro bodies. (They're different since
8203 % rec and nonrec macros end differently.)
8204
8205 % We are in \macrobodyctxt, and the \xdef causes backslashshes in the macro 
8206 % body to be transformed.
8207 % Set \macrobody to the body of the macro, and call \defmacro.
8208 %
8209 {\catcode`\ =\other\long\gdef\parsemacbody#1@end macro{%
8210 \xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8211 {\catcode`\ =\other\long\gdef\parsermacbody#1@end rmacro{%
8212 \xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8213
8214 % Make @ a letter, so that we can make private-to-Texinfo macro names.
8215 \edef\texiatcatcode{\the\catcode`\@}
8216 \catcode `@=11\relax
8217
8218 %%%%%%%%%%%%%% Code for > 10 arguments only   %%%%%%%%%%%%%%%%%%
8219
8220 % If there are 10 or more arguments, a different technique is used, where the
8221 % hook remains in the body, and when macro is to be expanded the body is
8222 % processed again to replace the arguments.
8223 %
8224 % In that case, the hook is \the\toks N-1, and we simply set \toks N-1 to the
8225 % argument N value and then \edef the body (nothing else will expand because of
8226 % the catcode regime under which the body was input).
8227 %
8228 % If you compile with TeX (not eTeX), and you have macros with 10 or more
8229 % arguments, no macro can have more than 256 arguments (else error).
8230 %
8231 % In case that there are 10 or more arguments we parse again the arguments
8232 % list to set new definitions for the \macarg.BLAH macros corresponding to
8233 % each BLAH argument. It was anyhow needed to parse already once this list
8234 % in order to count the arguments, and as macros with at most 9 arguments
8235 % are by far more frequent than macro with 10 or more arguments, defining
8236 % twice the \macarg.BLAH macros does not cost too much processing power.
8237 \def\parsemmanyargdef@@#1,{%
8238   \if#1;\let\next=\relax
8239   \else 
8240     \let\next=\parsemmanyargdef@@
8241     \edef\tempb{\eatspaces{#1}}%
8242     \expandafter\def\expandafter\tempa
8243        \expandafter{\csname macarg.\tempb\endcsname}%
8244     % Note that we need some extra \noexpand\noexpand, this is because we
8245     % don't want \the  to be expanded in the \parsermacbody  as it uses an
8246     % \xdef .
8247     \expandafter\edef\tempa
8248       {\noexpand\noexpand\noexpand\the\toks\the\paramno}%
8249     \advance\paramno by 1\relax
8250   \fi\next}
8251
8252
8253 \let\endargs@\relax
8254 \let\nil@\relax
8255 \def\nilm@{\nil@}%
8256 \long\def\nillm@{\nil@}%
8257
8258 % This macro is expanded during the Texinfo macro expansion, not during its
8259 % definition.  It gets all the arguments' values and assigns them to macros
8260 % macarg.ARGNAME
8261 %
8262 % #1 is the macro name
8263 % #2 is the list of argument names
8264 % #3 is the list of argument values
8265 \def\getargvals@#1#2#3{%
8266   \def\macargdeflist@{}%
8267   \def\saveparamlist@{#2}% Need to keep a copy for parameter expansion.
8268   \def\paramlist{#2,\nil@}%
8269   \def\macroname{#1}%
8270   \begingroup
8271   \macroargctxt
8272   \def\argvaluelist{#3,\nil@}%
8273   \def\@tempa{#3}%
8274   \ifx\@tempa\empty
8275     \setemptyargvalues@
8276   \else
8277     \getargvals@@
8278   \fi
8279 }
8280 \def\getargvals@@{%
8281   \ifx\paramlist\nilm@
8282       % Some sanity check needed here that \argvaluelist is also empty.
8283       \ifx\argvaluelist\nillm@
8284       \else
8285         \errhelp = \EMsimple
8286         \errmessage{Too many arguments in macro `\macroname'!}%
8287       \fi
8288       \let\next\macargexpandinbody@
8289   \else
8290     \ifx\argvaluelist\nillm@
8291        % No more arguments values passed to macro.  Set remaining named-arg
8292        % macros to empty.
8293        \let\next\setemptyargvalues@
8294     \else
8295       % pop current arg name into \@tempb
8296       \def\@tempa##1{\pop@{\@tempb}{\paramlist}##1\endargs@}%
8297       \expandafter\@tempa\expandafter{\paramlist}%
8298        % pop current argument value into \@tempc
8299       \def\@tempa##1{\longpop@{\@tempc}{\argvaluelist}##1\endargs@}%
8300       \expandafter\@tempa\expandafter{\argvaluelist}%
8301        % Here \@tempb is the current arg name and \@tempc is the current arg value.
8302        % First place the new argument macro definition into \@tempd
8303        \expandafter\macname\expandafter{\@tempc}%
8304        \expandafter\let\csname macarg.\@tempb\endcsname\relax
8305        \expandafter\def\expandafter\@tempe\expandafter{%
8306          \csname macarg.\@tempb\endcsname}%
8307        \edef\@tempd{\long\def\@tempe{\the\macname}}%
8308        \push@\@tempd\macargdeflist@
8309        \let\next\getargvals@@
8310     \fi
8311   \fi
8312   \next
8313 }
8314
8315 \def\push@#1#2{%
8316   \expandafter\expandafter\expandafter\def
8317   \expandafter\expandafter\expandafter#2%
8318   \expandafter\expandafter\expandafter{%
8319   \expandafter#1#2}%
8320 }
8321
8322 % Replace arguments by their values in the macro body, and place the result
8323 % in macro \@tempa.
8324
8325 \def\macvalstoargs@{%
8326   %  To do this we use the property that token registers that are \the'ed
8327   % within an \edef  expand only once. So we are going to place all argument
8328   % values into respective token registers.
8329   %
8330   % First we save the token context, and initialize argument numbering.
8331   \begingroup
8332     \paramno0\relax
8333     % Then, for each argument number #N, we place the corresponding argument
8334     % value into a new token list register \toks#N
8335     \expandafter\putargsintokens@\saveparamlist@,;,%
8336     % Then, we expand the body so that argument are replaced by their
8337     % values. The trick for values not to be expanded themselves is that they
8338     % are within tokens and that tokens expand only once in an \edef .
8339     \edef\@tempc{\csname mac.\macroname .body\endcsname}%
8340     % Now we restore the token stack pointer to free the token list registers
8341     % which we have used, but we make sure that expanded body is saved after
8342     % group.
8343     \expandafter
8344   \endgroup
8345   \expandafter\def\expandafter\@tempa\expandafter{\@tempc}%
8346   }
8347
8348 % Define the named-macro outside of this group and then close this group. 
8349
8350 \def\macargexpandinbody@{% 
8351   \expandafter
8352   \endgroup
8353   \macargdeflist@
8354   % First the replace in body the macro arguments by their values, the result
8355   % is in \@tempa .
8356   \macvalstoargs@
8357   % Then we point at the \norecurse or \gobble (for recursive) macro value
8358   % with \@tempb .
8359   \expandafter\let\expandafter\@tempb\csname mac.\macroname .recurse\endcsname
8360   % Depending on whether it is recursive or not, we need some tailing
8361   % \egroup .
8362   \ifx\@tempb\gobble
8363      \let\@tempc\relax
8364   \else
8365      \let\@tempc\egroup
8366   \fi
8367   % And now we do the real job:
8368   \edef\@tempd{\noexpand\@tempb{\macroname}\noexpand\scanmacro{\@tempa}\@tempc}%
8369   \@tempd
8370 }
8371
8372 \def\putargsintokens@#1,{%
8373   \if#1;\let\next\relax
8374   \else
8375     \let\next\putargsintokens@
8376     % First we allocate the new token list register, and give it a temporary
8377     % alias \@tempb .
8378     \toksdef\@tempb\the\paramno
8379     % Then we place the argument value into that token list register.
8380     \expandafter\let\expandafter\@tempa\csname macarg.#1\endcsname
8381     \expandafter\@tempb\expandafter{\@tempa}%
8382     \advance\paramno by 1\relax
8383   \fi
8384   \next
8385 }
8386
8387 % Trailing missing arguments are set to empty.
8388
8389 \def\setemptyargvalues@{%
8390   \ifx\paramlist\nilm@
8391     \let\next\macargexpandinbody@
8392   \else
8393     \expandafter\setemptyargvaluesparser@\paramlist\endargs@
8394     \let\next\setemptyargvalues@
8395   \fi
8396   \next
8397 }
8398
8399 \def\setemptyargvaluesparser@#1,#2\endargs@{%
8400   \expandafter\def\expandafter\@tempa\expandafter{%
8401     \expandafter\def\csname macarg.#1\endcsname{}}%
8402   \push@\@tempa\macargdeflist@
8403   \def\paramlist{#2}%
8404 }
8405
8406 % #1 is the element target macro
8407 % #2 is the list macro
8408 % #3,#4\endargs@ is the list value
8409 \def\pop@#1#2#3,#4\endargs@{%
8410    \def#1{#3}%
8411    \def#2{#4}%
8412 }
8413 \long\def\longpop@#1#2#3,#4\endargs@{%
8414    \long\def#1{#3}%
8415    \long\def#2{#4}%
8416 }
8417
8418
8419 %%%%%%%%%%%%%% End of code for > 10 arguments %%%%%%%%%%%%%%%%%%
8420
8421
8422 % This defines a Texinfo @macro or @rmacro, called by \parsemacbody.
8423 %    \macrobody has the body of the macro in it, with placeholders for
8424 % its parameters, looking like "\xeatspaces{\hash 1}".
8425 %    \paramno is the number of parameters
8426 %    \paramlist is a TeX parameter text, e.g. "#1,#2,#3,"
8427 % There are eight cases: recursive and nonrecursive macros of zero, one,
8428 % up to nine, and many arguments.
8429 % \xdef is used so that macro definitions will survive the file
8430 % they're defined in: @include reads the file inside a group.
8431 %
8432 \def\defmacro{%
8433   \let\hash=##% convert placeholders to macro parameter chars
8434   \ifnum\paramno=1
8435     \def\xeatspaces##1{##1}%
8436     % This removes the pair of braces around the argument.  We don't
8437     % use \eatspaces, because this can cause ends of lines to be lost
8438     % when the argument to \eatspaces is read, leading to line-based
8439     % commands like "@itemize" not being read correctly.
8440   \else
8441     \let\xeatspaces\relax % suppress expansion
8442   \fi
8443   \ifrecursive   %%%%%%%%%%%%%% Recursive %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8444     \ifcase\paramno
8445     % 0
8446       \expandafter\xdef\csname\the\macname\endcsname{%
8447         \noexpand\scanmacro{\macrobody}}%
8448     \or % 1
8449       \expandafter\xdef\csname\the\macname\endcsname{%
8450          \bgroup
8451          \noexpand\braceorline
8452          \expandafter\noexpand\csname\the\macname @@@\endcsname}%
8453       \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8454         \egroup
8455         \noexpand\scanmacro{\macrobody}%
8456         }%
8457     \else
8458       \ifnum\paramno<10\relax % at most 9
8459         % See non-recursive section below for comments
8460         \expandafter\xdef\csname\the\macname\endcsname{%
8461           \bgroup
8462           \noexpand\expandafter
8463           \noexpand\macroargctxt
8464           \noexpand\expandafter
8465           \expandafter\noexpand\csname\the\macname @@\endcsname}%
8466         \expandafter\xdef\csname\the\macname @@\endcsname##1{%
8467             \noexpand\passargtomacro
8468             \expandafter\noexpand\csname\the\macname @@@\endcsname{##1,}}%
8469         \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8470             \expandafter\noexpand\csname\the\macname @@@@\endcsname ##1}%
8471         \expandafter\expandafter
8472         \expandafter\xdef
8473         \expandafter\expandafter
8474           \csname\the\macname @@@@\endcsname\paramlist{%
8475             \egroup\noexpand\scanmacro{\macrobody}}%
8476       \else % 10 or more
8477         \expandafter\xdef\csname\the\macname\endcsname{%
8478           \noexpand\getargvals@{\the\macname}{\argl}%
8479         }%    
8480         \global\expandafter\let\csname mac.\the\macname .body\endcsname\macrobody
8481         \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\gobble
8482       \fi
8483     \fi
8484   \else  %%%%%%%%%%%%%%%%%%%%%% Non-recursive %%%%%%%%%%%%%%%%%%%%%%%%%%
8485     \ifcase\paramno
8486     % 0
8487       \expandafter\xdef\csname\the\macname\endcsname{%
8488         \noexpand\scanmacro{\macrobody}}%
8489     \or % 1
8490       \expandafter\xdef\csname\the\macname\endcsname{%
8491          \bgroup
8492          \noexpand\braceorline
8493          \expandafter\noexpand\csname\the\macname @@@\endcsname}%
8494       \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8495         \egroup
8496         \noexpand\scanmacro{\macrobody}%
8497         }%
8498     \else % at most 9
8499       \ifnum\paramno<10\relax
8500         % @MACNAME sets the context for reading the macro argument
8501         % @MACNAME@@ gets the argument, processes backslashes and appends a 
8502         % comma.
8503         % @MACNAME@@@ removes braces surrounding the argument list.
8504         % @MACNAME@@@@ scans the macro body with arguments substituted.
8505         \expandafter\xdef\csname\the\macname\endcsname{%
8506           \bgroup
8507           \noexpand\expandafter  % This \expandafter skip any spaces after the
8508           \noexpand\macroargctxt % macro before we change the catcode of space.
8509           \noexpand\expandafter
8510           \expandafter\noexpand\csname\the\macname @@\endcsname}%
8511         \expandafter\xdef\csname\the\macname @@\endcsname##1{%
8512             \noexpand\passargtomacro
8513             \expandafter\noexpand\csname\the\macname @@@\endcsname{##1,}}%
8514         \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8515             \expandafter\noexpand\csname\the\macname @@@@\endcsname ##1}%
8516         \expandafter\expandafter
8517         \expandafter\xdef
8518         \expandafter\expandafter
8519           \csname\the\macname @@@@\endcsname\paramlist{%
8520             \egroup\noexpand\scanmacro{\macrobody}}%
8521       \else % 10 or more:
8522         \expandafter\xdef\csname\the\macname\endcsname{%
8523           \noexpand\getargvals@{\the\macname}{\argl}%
8524         }%
8525         \global\expandafter\let\csname mac.\the\macname .body\endcsname\macrobody
8526         \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\norecurse
8527       \fi
8528     \fi
8529   \fi}
8530
8531 \catcode `\@\texiatcatcode\relax % end private-to-Texinfo catcodes
8532
8533 \def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
8534
8535
8536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8537 %
8538 {\catcode`\@=0 \catcode`\\=13  % We need to manipulate \ so use @ as escape
8539 @catcode`@_=11  % private names
8540 @catcode`@!=11  % used as argument separator
8541
8542 % \passargtomacro#1#2 -
8543 % Call #1 with a list of tokens #2, with any doubled backslashes in #2
8544 % compressed to one.
8545 %
8546 % This implementation works by expansion, and not execution (so we cannot use 
8547 % \def or similar).  This reduces the risk of this failing in contexts where 
8548 % complete expansion is done with no execution (for example, in writing out to 
8549 % an auxiliary file for an index entry).
8550
8551 % State is kept in the input stream: the argument passed to
8552 % @look_ahead, @gobble_and_check_finish and @add_segment is
8553 %
8554 % THE_MACRO ARG_RESULT ! {PENDING_BS} NEXT_TOKEN  (... rest of input)
8555 %
8556 % where:
8557 % THE_MACRO - name of the macro we want to call
8558 % ARG_RESULT - argument list we build to pass to that macro
8559 % PENDING_BS - either a backslash or nothing
8560 % NEXT_TOKEN - used to look ahead in the input stream to see what's coming next
8561
8562 @gdef@passargtomacro#1#2{%
8563   @add_segment #1!{}@relax#2\@_finish\%
8564 }
8565 @gdef@_finish{@_finishx} @global@let@_finishx@relax
8566
8567 % #1 - THE_MACRO ARG_RESULT
8568 % #2 - PENDING_BS
8569 % #3 - NEXT_TOKEN
8570 % #4 used to look ahead
8571 %
8572 % If the next token is not a backslash, process the rest of the argument; 
8573 % otherwise, remove the next token.
8574 @gdef@look_ahead#1!#2#3#4{%
8575   @ifx#4\%
8576    @expandafter@gobble_and_check_finish 
8577   @else
8578    @expandafter@add_segment
8579   @fi#1!{#2}#4#4%
8580 }
8581
8582 % #1 - THE_MACRO ARG_RESULT
8583 % #2 - PENDING_BS
8584 % #3 - NEXT_TOKEN
8585 % #4 should be a backslash, which is gobbled.
8586 % #5 looks ahead
8587 %
8588 % Double backslash found.  Add a single backslash, and look ahead.
8589 @gdef@gobble_and_check_finish#1!#2#3#4#5{%
8590   @add_segment#1\!{}#5#5%
8591 }
8592
8593 @gdef@is_fi{@fi}
8594
8595 % #1 - THE_MACRO ARG_RESULT
8596 % #2 - PENDING_BS
8597 % #3 - NEXT_TOKEN
8598 % #4 is input stream until next backslash
8599 %
8600 % Input stream is either at the start of the argument, or just after a 
8601 % backslash sequence, either a lone backslash, or a doubled backslash.  
8602 % NEXT_TOKEN contains the first token in the input stream: if it is \finish, 
8603 % finish; otherwise, append to ARG_RESULT the segment of the argument up until
8604 % the next backslash.  PENDING_BACKSLASH contains a backslash to represent
8605 % a backslash just before the start of the input stream that has not been
8606 % added to ARG_RESULT.
8607 @gdef@add_segment#1!#2#3#4\{%
8608 @ifx#3@_finish
8609   @call_the_macro#1!%
8610 @else
8611   % append the pending backslash to the result, followed by the next segment
8612   @expandafter@is_fi@look_ahead#1#2#4!{\}@fi
8613   % this @fi is discarded by @look_ahead.
8614   % we can't get rid of it with \expandafter because we don't know how 
8615   % long #4 is.
8616 }
8617
8618 % #1 - THE_MACRO
8619 % #2 - ARG_RESULT
8620 % #3 discards the res of the conditional in @add_segment, and @is_fi ends the 
8621 % conditional.
8622 @gdef@call_the_macro#1#2!#3@fi{@is_fi #1{#2}}
8623
8624 }
8625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8626
8627 % \braceorline MAC is used for a one-argument macro MAC.  It checks
8628 % whether the next non-whitespace character is a {.  It sets the context
8629 % for reading the argument (slightly different in the two cases).  Then,
8630 % to read the argument, in the whole-line case, it then calls the regular
8631 % \parsearg MAC; in the lbrace case, it calls \passargtomacro MAC.
8632
8633 \def\braceorline#1{\let\macnamexxx=#1\futurelet\nchar\braceorlinexxx}
8634 \def\braceorlinexxx{%
8635   \ifx\nchar\bgroup
8636     \macroargctxt
8637     \expandafter\passargtomacro
8638   \else
8639     \macrolineargctxt\expandafter\parsearg
8640   \fi \macnamexxx}
8641
8642
8643 % @alias.
8644 % We need some trickery to remove the optional spaces around the equal
8645 % sign.  Make them active and then expand them all to nothing.
8646 %
8647 \def\alias{\parseargusing\obeyspaces\aliasxxx}
8648 \def\aliasxxx #1{\aliasyyy#1\relax}
8649 \def\aliasyyy #1=#2\relax{%
8650   {%
8651     \expandafter\let\obeyedspace=\empty
8652     \addtomacrolist{#1}%
8653     \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
8654   }%
8655   \next
8656 }
8657
8658
8659 \message{cross references,}
8660
8661 \newwrite\auxfile
8662 \newif\ifhavexrefs    % True if xref values are known.
8663 \newif\ifwarnedxrefs  % True if we warned once that they aren't known.
8664
8665 % @inforef is relatively simple.
8666 \def\inforef #1{\inforefzzz #1,,,,**}
8667 \def\inforefzzz #1,#2,#3,#4**{%
8668   \putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
8669   node \samp{\ignorespaces#1{}}}
8670
8671 % @node's only job in TeX is to define \lastnode, which is used in
8672 % cross-references.  The @node line might or might not have commas, and
8673 % might or might not have spaces before the first comma, like:
8674 % @node foo , bar , ...
8675 % We don't want such trailing spaces in the node name.
8676 %
8677 \parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
8678 %
8679 % also remove a trailing comma, in case of something like this:
8680 % @node Help-Cross,  ,  , Cross-refs
8681 \def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
8682 \def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
8683
8684 \let\nwnode=\node
8685 \let\lastnode=\empty
8686
8687 % Write a cross-reference definition for the current node.  #1 is the
8688 % type (Ynumbered, Yappendix, Ynothing).
8689 %
8690 \def\donoderef#1{%
8691   \ifx\lastnode\empty\else
8692     \setref{\lastnode}{#1}%
8693     \global\let\lastnode=\empty
8694   \fi
8695 }
8696
8697 % @anchor{NAME} -- define xref target at arbitrary point.
8698 %
8699 \newcount\savesfregister
8700 %
8701 \def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
8702 \def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
8703 \def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
8704
8705 % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
8706 % anchor), which consists of three parts:
8707 % 1) NAME-title - the current sectioning name taken from \lastsection,
8708 %                 or the anchor name.
8709 % 2) NAME-snt   - section number and type, passed as the SNT arg, or
8710 %                 empty for anchors.
8711 % 3) NAME-pg    - the page number.
8712 %
8713 % This is called from \donoderef, \anchor, and \dofloat.  In the case of
8714 % floats, there is an additional part, which is not written here:
8715 % 4) NAME-lof   - the text as it should appear in a @listoffloats.
8716 %
8717 \def\setref#1#2{%
8718   \pdfmkdest{#1}%
8719   \iflinks
8720     {%
8721       \requireauxfile
8722       \atdummies  % preserve commands, but don't expand them
8723       % match definition in \xrdef, \refx, \xrefX.
8724       \def\value##1{##1}%
8725       \edef\writexrdef##1##2{%
8726         \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
8727           ##1}{##2}}% these are parameters of \writexrdef
8728       }%
8729       \toks0 = \expandafter{\lastsection}%
8730       \immediate \writexrdef{title}{\the\toks0 }%
8731       \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
8732       \safewhatsit{\writexrdef{pg}{\folio}}% will be written later, at \shipout
8733     }%
8734   \fi
8735 }
8736
8737 % @xrefautosectiontitle on|off says whether @section(ing) names are used
8738 % automatically in xrefs, if the third arg is not explicitly specified.
8739 % This was provided as a "secret" @set xref-automatic-section-title
8740 % variable, now it's official.
8741
8742 \parseargdef\xrefautomaticsectiontitle{%
8743   \def\temp{#1}%
8744   \ifx\temp\onword
8745     \expandafter\let\csname SETxref-automatic-section-title\endcsname
8746       = \empty
8747   \else\ifx\temp\offword
8748     \expandafter\let\csname SETxref-automatic-section-title\endcsname
8749       = \relax
8750   \else
8751     \errhelp = \EMsimple
8752     \errmessage{Unknown @xrefautomaticsectiontitle value `\temp',
8753                 must be on|off}%
8754   \fi\fi
8755 }
8756
8757\f
8758 % @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
8759 % the node name, #2 the name of the Info cross-reference, #3 the printed
8760 % node name, #4 the name of the Info file, #5 the name of the printed
8761 % manual.  All but the node name can be omitted.
8762 %
8763 \def\pxref{\putwordsee{} \xrefXX}
8764 \def\xref{\putwordSee{} \xrefXX}
8765 \def\ref{\xrefXX}
8766
8767 \def\xrefXX#1{\def\xrefXXarg{#1}\futurelet\tokenafterxref\xrefXXX}
8768 \def\xrefXXX{\expandafter\xrefX\expandafter[\xrefXXarg,,,,,,,]}
8769 %
8770 \newbox\toprefbox
8771 \newbox\printedrefnamebox
8772 \newbox\infofilenamebox
8773 \newbox\printedmanualbox
8774 %
8775 \def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
8776   \unsepspaces
8777   %
8778   % Get args without leading/trailing spaces.
8779   \def\printedrefname{\ignorespaces #3}%
8780   \setbox\printedrefnamebox = \hbox{\printedrefname\unskip}%
8781   %
8782   \def\infofilename{\ignorespaces #4}%
8783   \setbox\infofilenamebox = \hbox{\infofilename\unskip}%
8784   %
8785   \def\printedmanual{\ignorespaces #5}%
8786   \setbox\printedmanualbox  = \hbox{\printedmanual\unskip}%
8787   %
8788   % If the printed reference name (arg #3) was not explicitly given in
8789   % the @xref, figure out what we want to use.
8790   \ifdim \wd\printedrefnamebox = 0pt
8791     % No printed node name was explicitly given.
8792     \expandafter\ifx\csname SETxref-automatic-section-title\endcsname \relax
8793       % Not auto section-title: use node name inside the square brackets.
8794       \def\printedrefname{\ignorespaces #1}%
8795     \else
8796       % Auto section-title: use chapter/section title inside
8797       % the square brackets if we have it.
8798       \ifdim \wd\printedmanualbox > 0pt
8799         % It is in another manual, so we don't have it; use node name.
8800         \def\printedrefname{\ignorespaces #1}%
8801       \else
8802         \ifhavexrefs
8803           % We (should) know the real title if we have the xref values.
8804           \def\printedrefname{\refx{#1-title}{}}%
8805         \else
8806           % Otherwise just copy the Info node name.
8807           \def\printedrefname{\ignorespaces #1}%
8808         \fi%
8809       \fi
8810     \fi
8811   \fi
8812   %
8813   % Make link in pdf output.
8814   \ifpdf
8815     % For pdfTeX and LuaTeX
8816     {\indexnofonts
8817      \turnoffactive
8818      \makevalueexpandable
8819      % This expands tokens, so do it after making catcode changes, so _
8820      % etc. don't get their TeX definitions.  This ignores all spaces in
8821      % #4, including (wrongly) those in the middle of the filename.
8822      \getfilename{#4}%
8823      %
8824      % This (wrongly) does not take account of leading or trailing
8825      % spaces in #1, which should be ignored.
8826      \edef\pdfxrefdest{#1}%
8827      \ifx\pdfxrefdest\empty
8828        \def\pdfxrefdest{Top}% no empty targets
8829      \else
8830        \txiescapepdf\pdfxrefdest  % escape PDF special chars
8831      \fi
8832      %
8833      \leavevmode
8834      \startlink attr{/Border [0 0 0]}%
8835      \ifnum\filenamelength>0
8836        goto file{\the\filename.pdf} name{\pdfxrefdest}%
8837      \else
8838        goto name{\pdfmkpgn{\pdfxrefdest}}%
8839      \fi
8840     }%
8841     \setcolor{\linkcolor}%
8842   \else
8843     \ifx\XeTeXrevision\thisisundefined
8844     \else
8845       % For XeTeX
8846       {\indexnofonts
8847        \turnoffactive
8848        \makevalueexpandable
8849        % This expands tokens, so do it after making catcode changes, so _
8850        % etc. don't get their TeX definitions.  This ignores all spaces in
8851        % #4, including (wrongly) those in the middle of the filename.
8852        \getfilename{#4}%
8853        %
8854        % This (wrongly) does not take account of leading or trailing
8855        % spaces in #1, which should be ignored.
8856        \iftxiuseunicodedestname
8857          \def\pdfxrefdest{#1}% Pass through Unicode characters.
8858        \else
8859          \edef\pdfxrefdest{#1}% Replace Unicode characters to ASCII.
8860        \fi
8861        \ifx\pdfxrefdest\empty
8862          \def\pdfxrefdest{Top}% no empty targets
8863        \else
8864          \txiescapepdf\pdfxrefdest  % escape PDF special chars
8865        \fi
8866        %
8867        \leavevmode
8868        \ifnum\filenamelength>0
8869          % By the default settings,
8870          % XeTeX (xdvipdfmx) replaces link destination names with integers.
8871          % In this case, the replaced destination names of
8872          % remote PDF cannot be known. In order to avoid replacement,
8873          % you can use commandline option `-C 0x0010' for xdvipdfmx.
8874          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8875            << /S /GoToR /F (\the\filename.pdf) /D (name\pdfxrefdest) >> >>}%
8876        \else
8877          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8878            << /S /GoTo /D (name\pdfxrefdest) >> >>}%
8879        \fi
8880       }%
8881       \setcolor{\linkcolor}%
8882     \fi
8883   \fi
8884   {%
8885     % Have to otherify everything special to allow the \csname to
8886     % include an _ in the xref name, etc.
8887     \indexnofonts
8888     \turnoffactive
8889     \def\value##1{##1}%
8890     \expandafter\global\expandafter\let\expandafter\Xthisreftitle
8891       \csname XR#1-title\endcsname
8892   }%
8893   %
8894   % Float references are printed completely differently: "Figure 1.2"
8895   % instead of "[somenode], p.3".  \iffloat distinguishes them by
8896   % \Xthisreftitle being set to a magic string.
8897   \iffloat\Xthisreftitle
8898     % If the user specified the print name (third arg) to the ref,
8899     % print it instead of our usual "Figure 1.2".
8900     \ifdim\wd\printedrefnamebox = 0pt
8901       \refx{#1-snt}{}%
8902     \else
8903       \printedrefname
8904     \fi
8905     %
8906     % If the user also gave the printed manual name (fifth arg), append
8907     % "in MANUALNAME".
8908     \ifdim \wd\printedmanualbox > 0pt
8909       \space \putwordin{} \cite{\printedmanual}%
8910     \fi
8911   \else
8912     % node/anchor (non-float) references.
8913     % 
8914     % If we use \unhbox to print the node names, TeX does not insert
8915     % empty discretionaries after hyphens, which means that it will not
8916     % find a line break at a hyphen in a node names.  Since some manuals
8917     % are best written with fairly long node names, containing hyphens,
8918     % this is a loss.  Therefore, we give the text of the node name
8919     % again, so it is as if TeX is seeing it for the first time.
8920     % 
8921     \ifdim \wd\printedmanualbox > 0pt
8922       % Cross-manual reference with a printed manual name.
8923       % 
8924       \crossmanualxref{\cite{\printedmanual\unskip}}%
8925     %
8926     \else\ifdim \wd\infofilenamebox > 0pt
8927       % Cross-manual reference with only an info filename (arg 4), no
8928       % printed manual name (arg 5).  This is essentially the same as
8929       % the case above; we output the filename, since we have nothing else.
8930       % 
8931       \crossmanualxref{\code{\infofilename\unskip}}%
8932     %
8933     \else
8934       % Reference within this manual.
8935       %
8936       % _ (for example) has to be the character _ for the purposes of the
8937       % control sequence corresponding to the node, but it has to expand
8938       % into the usual \leavevmode...\vrule stuff for purposes of
8939       % printing. So we \turnoffactive for the \refx-snt, back on for the
8940       % printing, back off for the \refx-pg.
8941       {\turnoffactive
8942        % Only output a following space if the -snt ref is nonempty; for
8943        % @unnumbered and @anchor, it won't be.
8944        \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
8945        \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
8946       }%
8947       % output the `[mynode]' via the macro below so it can be overridden.
8948       \xrefprintnodename\printedrefname
8949       %
8950       % But we always want a comma and a space:
8951       ,\space
8952       %
8953       % output the `page 3'.
8954       \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
8955       % Add a , if xref followed by a space
8956       \if\space\noexpand\tokenafterxref ,%
8957       \else\ifx\        \tokenafterxref ,% @TAB
8958       \else\ifx\*\tokenafterxref ,%   @*
8959       \else\ifx\ \tokenafterxref ,%   @SPACE
8960       \else\ifx\
8961                 \tokenafterxref ,%    @NL
8962       \else\ifx\tie\tokenafterxref ,% @tie
8963       \fi\fi\fi\fi\fi\fi
8964     \fi\fi
8965   \fi
8966   \endlink
8967 \endgroup}
8968
8969 % Output a cross-manual xref to #1.  Used just above (twice).
8970
8971 % Only include the text "Section ``foo'' in" if the foo is neither
8972 % missing or Top.  Thus, @xref{,,,foo,The Foo Manual} outputs simply
8973 % "see The Foo Manual", the idea being to refer to the whole manual.
8974
8975 % But, this being TeX, we can't easily compare our node name against the
8976 % string "Top" while ignoring the possible spaces before and after in
8977 % the input.  By adding the arbitrary 7sp below, we make it much less
8978 % likely that a real node name would have the same width as "Top" (e.g.,
8979 % in a monospaced font).  Hopefully it will never happen in practice.
8980
8981 % For the same basic reason, we retypeset the "Top" at every
8982 % reference, since the current font is indeterminate.
8983
8984 \def\crossmanualxref#1{%
8985   \setbox\toprefbox = \hbox{Top\kern7sp}%
8986   \setbox2 = \hbox{\ignorespaces \printedrefname \unskip \kern7sp}%
8987   \ifdim \wd2 > 7sp  % nonempty?
8988     \ifdim \wd2 = \wd\toprefbox \else  % same as Top?
8989       \putwordSection{} ``\printedrefname'' \putwordin{}\space
8990     \fi
8991   \fi
8992   #1%
8993 }
8994
8995 % This macro is called from \xrefX for the `[nodename]' part of xref
8996 % output.  It's a separate macro only so it can be changed more easily,
8997 % since square brackets don't work well in some documents.  Particularly
8998 % one that Bob is working on :).
8999 %
9000 \def\xrefprintnodename#1{[#1]}
9001
9002 % Things referred to by \setref.
9003 %
9004 \def\Ynothing{}
9005 \def\Yomitfromtoc{}
9006 \def\Ynumbered{%
9007   \ifnum\secno=0
9008     \putwordChapter@tie \the\chapno
9009   \else \ifnum\subsecno=0
9010     \putwordSection@tie \the\chapno.\the\secno
9011   \else \ifnum\subsubsecno=0
9012     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
9013   \else
9014     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
9015   \fi\fi\fi
9016 }
9017 \def\Yappendix{%
9018   \ifnum\secno=0
9019      \putwordAppendix@tie @char\the\appendixno{}%
9020   \else \ifnum\subsecno=0
9021      \putwordSection@tie @char\the\appendixno.\the\secno
9022   \else \ifnum\subsubsecno=0
9023     \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
9024   \else
9025     \putwordSection@tie
9026       @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
9027   \fi\fi\fi
9028 }
9029
9030 % \refx{NAME}{SUFFIX} - reference a cross-reference string named NAME.  SUFFIX 
9031 % is output afterwards if non-empty.
9032 \def\refx#1#2{%
9033   \requireauxfile
9034   {%
9035     \indexnofonts
9036     \otherbackslash
9037     \def\value##1{##1}%
9038     \expandafter\global\expandafter\let\expandafter\thisrefX
9039       \csname XR#1\endcsname
9040   }%
9041   \ifx\thisrefX\relax
9042     % If not defined, say something at least.
9043     \angleleft un\-de\-fined\angleright
9044     \iflinks
9045       \ifhavexrefs
9046         {\toks0 = {#1}% avoid expansion of possibly-complex value
9047          \message{\linenumber Undefined cross reference `\the\toks0'.}}%
9048       \else
9049         \ifwarnedxrefs\else
9050           \global\warnedxrefstrue
9051           \message{Cross reference values unknown; you must run TeX again.}%
9052         \fi
9053       \fi
9054     \fi
9055   \else
9056     % It's defined, so just use it.
9057     \thisrefX
9058   \fi
9059   #2% Output the suffix in any case.
9060 }
9061
9062 % This is the macro invoked by entries in the aux file.  Define a control 
9063 % sequence for a cross-reference target (we prepend XR to the control sequence 
9064 % name to avoid collisions).  The value is the page number.  If this is a float 
9065 % type, we have more work to do.
9066 %
9067 \def\xrdef#1#2{%
9068   {% Expand the node or anchor name to remove control sequences.
9069    % \turnoffactive stops 8-bit characters being changed to commands
9070    % like @'e.  \refx does the same to retrieve the value in the definition.
9071     \indexnofonts
9072     \turnoffactive
9073     \def\value##1{##1}%
9074     \xdef\safexrefname{#1}%
9075   }%
9076   %
9077   \expandafter\gdef\csname XR\safexrefname\endcsname{#2}% remember this xref
9078   %
9079   % Was that xref control sequence that we just defined for a float?
9080   \expandafter\iffloat\csname XR\safexrefname\endcsname
9081     % it was a float, and we have the (safe) float type in \iffloattype.
9082     \expandafter\let\expandafter\floatlist
9083       \csname floatlist\iffloattype\endcsname
9084     %
9085     % Is this the first time we've seen this float type?
9086     \expandafter\ifx\floatlist\relax
9087       \toks0 = {\do}% yes, so just \do
9088     \else
9089       % had it before, so preserve previous elements in list.
9090       \toks0 = \expandafter{\floatlist\do}%
9091     \fi
9092     %
9093     % Remember this xref in the control sequence \floatlistFLOATTYPE,
9094     % for later use in \listoffloats.
9095     \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0
9096       {\safexrefname}}%
9097   \fi
9098 }
9099
9100 % If working on a large document in chapters, it is convenient to
9101 % be able to disable indexing, cross-referencing, and contents, for test runs.
9102 % This is done with @novalidate at the beginning of the file.
9103 %
9104 \newif\iflinks \linkstrue % by default we want the aux files.
9105 \let\novalidate = \linksfalse
9106
9107 % Used when writing to the aux file, or when using data from it.
9108 \def\requireauxfile{%
9109   \iflinks
9110     \tryauxfile
9111     % Open the new aux file.  TeX will close it automatically at exit.
9112     \immediate\openout\auxfile=\jobname.aux
9113   \fi
9114   \global\let\requireauxfile=\relax   % Only do this once.
9115 }
9116
9117 % Read the last existing aux file, if any.  No error if none exists.
9118 %
9119 \def\tryauxfile{%
9120   \openin 1 \jobname.aux
9121   \ifeof 1 \else
9122     \readdatafile{aux}%
9123     \global\havexrefstrue
9124   \fi
9125   \closein 1
9126 }
9127
9128 \def\setupdatafile{%
9129   \catcode`\^^@=\other
9130   \catcode`\^^A=\other
9131   \catcode`\^^B=\other
9132   \catcode`\^^C=\other
9133   \catcode`\^^D=\other
9134   \catcode`\^^E=\other
9135   \catcode`\^^F=\other
9136   \catcode`\^^G=\other
9137   \catcode`\^^H=\other
9138   \catcode`\^^K=\other
9139   \catcode`\^^L=\other
9140   \catcode`\^^N=\other
9141   \catcode`\^^P=\other
9142   \catcode`\^^Q=\other
9143   \catcode`\^^R=\other
9144   \catcode`\^^S=\other
9145   \catcode`\^^T=\other
9146   \catcode`\^^U=\other
9147   \catcode`\^^V=\other
9148   \catcode`\^^W=\other
9149   \catcode`\^^X=\other
9150   \catcode`\^^Z=\other
9151   \catcode`\^^[=\other
9152   \catcode`\^^\=\other
9153   \catcode`\^^]=\other
9154   \catcode`\^^^=\other
9155   \catcode`\^^_=\other
9156   % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
9157   % in xref tags, i.e., node names.  But since ^^e4 notation isn't
9158   % supported in the main text, it doesn't seem desirable.  Furthermore,
9159   % that is not enough: for node names that actually contain a ^
9160   % character, we would end up writing a line like this: 'xrdef {'hat
9161   % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
9162   % argument, and \hat is not an expandable control sequence.  It could
9163   % all be worked out, but why?  Either we support ^^ or we don't.
9164   %
9165   % The other change necessary for this was to define \auxhat:
9166   % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
9167   % and then to call \auxhat in \setq.
9168   %
9169   \catcode`\^=\other
9170   %
9171   % Special characters.  Should be turned off anyway, but...
9172   \catcode`\~=\other
9173   \catcode`\[=\other
9174   \catcode`\]=\other
9175   \catcode`\"=\other
9176   \catcode`\_=\other
9177   \catcode`\|=\other
9178   \catcode`\<=\other
9179   \catcode`\>=\other
9180   \catcode`\$=\other
9181   \catcode`\#=\other
9182   \catcode`\&=\other
9183   \catcode`\%=\other
9184   \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
9185   %
9186   % This is to support \ in node names and titles, since the \
9187   % characters end up in a \csname.  It's easier than
9188   % leaving it active and making its active definition an actual \
9189   % character.  What I don't understand is why it works in the *value*
9190   % of the xrdef.  Seems like it should be a catcode12 \, and that
9191   % should not typeset properly.  But it works, so I'm moving on for
9192   % now.  --karl, 15jan04.
9193   \catcode`\\=\other
9194   %
9195   % @ is our escape character in .aux files, and we need braces.
9196   \catcode`\{=1
9197   \catcode`\}=2
9198   \catcode`\@=0
9199 }
9200
9201 \def\readdatafile#1{%
9202 \begingroup
9203   \setupdatafile
9204   \input\jobname.#1
9205 \endgroup}
9206
9207
9208 \message{insertions,}
9209 % including footnotes.
9210
9211 \newcount \footnoteno
9212
9213 % The trailing space in the following definition for supereject is
9214 % vital for proper filling; pages come out unaligned when you do a
9215 % pagealignmacro call if that space before the closing brace is
9216 % removed. (Generally, numeric constants should always be followed by a
9217 % space to prevent strange expansion errors.)
9218 \def\supereject{\par\penalty -20000\footnoteno =0 }
9219
9220 % @footnotestyle is meaningful for Info output only.
9221 \let\footnotestyle=\comment
9222
9223 {\catcode `\@=11
9224 %
9225 % Auto-number footnotes.  Otherwise like plain.
9226 \gdef\footnote{%
9227   \global\advance\footnoteno by \@ne
9228   \edef\thisfootno{$^{\the\footnoteno}$}%
9229   %
9230   % In case the footnote comes at the end of a sentence, preserve the
9231   % extra spacing after we do the footnote number.
9232   \let\@sf\empty
9233   \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
9234   %
9235   % Remove inadvertent blank space before typesetting the footnote number.
9236   \unskip
9237   \thisfootno\@sf
9238   \dofootnote
9239 }%
9240
9241 % Don't bother with the trickery in plain.tex to not require the
9242 % footnote text as a parameter.  Our footnotes don't need to be so general.
9243 %
9244 % Oh yes, they do; otherwise, @ifset (and anything else that uses
9245 % \parseargline) fails inside footnotes because the tokens are fixed when
9246 % the footnote is read.  --karl, 16nov96.
9247 %
9248 \gdef\dofootnote{%
9249   \insert\footins\bgroup
9250   %
9251   % Nested footnotes are not supported in TeX, that would take a lot
9252   % more work.  (\startsavinginserts does not suffice.)
9253   \let\footnote=\errfootnotenest
9254   %
9255   % We want to typeset this text as a normal paragraph, even if the
9256   % footnote reference occurs in (for example) a display environment.
9257   % So reset some parameters.
9258   \hsize=\txipagewidth
9259   \interlinepenalty\interfootnotelinepenalty
9260   \splittopskip\ht\strutbox % top baseline for broken footnotes
9261   \splitmaxdepth\dp\strutbox
9262   \floatingpenalty\@MM
9263   \leftskip\z@skip
9264   \rightskip\z@skip
9265   \spaceskip\z@skip
9266   \xspaceskip\z@skip
9267   \parindent\defaultparindent
9268   %
9269   \smallfonts \rm
9270   %
9271   % Because we use hanging indentation in footnotes, a @noindent appears
9272   % to exdent this text, so make it be a no-op.  makeinfo does not use
9273   % hanging indentation so @noindent can still be needed within footnote
9274   % text after an @example or the like (not that this is good style).
9275   \let\noindent = \relax
9276   %
9277   % Hang the footnote text off the number.  Use \everypar in case the
9278   % footnote extends for more than one paragraph.
9279   \everypar = {\hang}%
9280   \textindent{\thisfootno}%
9281   %
9282   % Don't crash into the line above the footnote text.  Since this
9283   % expands into a box, it must come within the paragraph, lest it
9284   % provide a place where TeX can split the footnote.
9285   \footstrut
9286   %
9287   % Invoke rest of plain TeX footnote routine.
9288   \futurelet\next\fo@t
9289 }
9290 }%end \catcode `\@=11
9291
9292 \def\errfootnotenest{%
9293   \errhelp=\EMsimple
9294   \errmessage{Nested footnotes not supported in texinfo.tex,
9295     even though they work in makeinfo; sorry}
9296 }
9297
9298 \def\errfootnoteheading{%
9299   \errhelp=\EMsimple
9300   \errmessage{Footnotes in chapters, sections, etc., are not supported}
9301 }
9302
9303 % In case a @footnote appears in a vbox, save the footnote text and create
9304 % the real \insert just after the vbox finished.  Otherwise, the insertion
9305 % would be lost.
9306 % Similarly, if a @footnote appears inside an alignment, save the footnote
9307 % text to a box and make the \insert when a row of the table is finished.
9308 % And the same can be done for other insert classes.  --kasal, 16nov03.
9309 %
9310 % Replace the \insert primitive by a cheating macro.
9311 % Deeper inside, just make sure that the saved insertions are not spilled
9312 % out prematurely.
9313 %
9314 \def\startsavinginserts{%
9315   \ifx \insert\ptexinsert
9316     \let\insert\saveinsert
9317   \else
9318     \let\checkinserts\relax
9319   \fi
9320 }
9321
9322 % This \insert replacement works for both \insert\footins{foo} and
9323 % \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
9324 %
9325 \def\saveinsert#1{%
9326   \edef\next{\noexpand\savetobox \makeSAVEname#1}%
9327   \afterassignment\next
9328   % swallow the left brace
9329   \let\temp =
9330 }
9331 \def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
9332 \def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
9333
9334 \def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
9335
9336 \def\placesaveins#1{%
9337   \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
9338     {\box#1}%
9339 }
9340
9341 % eat @SAVE -- beware, all of them have catcode \other:
9342 {
9343   \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials  %  ;-)
9344   \gdef\gobblesave @SAVE{}
9345 }
9346
9347 % initialization:
9348 \def\newsaveins #1{%
9349   \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
9350   \next
9351 }
9352 \def\newsaveinsX #1{%
9353   \csname newbox\endcsname #1%
9354   \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
9355     \checksaveins #1}%
9356 }
9357
9358 % initialize:
9359 \let\checkinserts\empty
9360 \newsaveins\footins
9361 \newsaveins\margin
9362
9363
9364 % @image.  We use the macros from epsf.tex to support this.
9365 % If epsf.tex is not installed and @image is used, we complain.
9366 %
9367 % Check for and read epsf.tex up front.  If we read it only at @image
9368 % time, we might be inside a group, and then its definitions would get
9369 % undone and the next image would fail.
9370 \openin 1 = epsf.tex
9371 \ifeof 1 \else
9372   % Do not bother showing banner with epsf.tex v2.7k (available in
9373   % doc/epsf.tex and on ctan).
9374   \def\epsfannounce{\toks0 = }%
9375   \input epsf.tex
9376 \fi
9377 \closein 1
9378 %
9379 % We will only complain once about lack of epsf.tex.
9380 \newif\ifwarnednoepsf
9381 \newhelp\noepsfhelp{epsf.tex must be installed for images to
9382   work.  It is also included in the Texinfo distribution, or you can get
9383   it from ftp://tug.org/tex/epsf.tex.}
9384 %
9385 \def\image#1{%
9386   \ifx\epsfbox\thisisundefined
9387     \ifwarnednoepsf \else
9388       \errhelp = \noepsfhelp
9389       \errmessage{epsf.tex not found, images will be ignored}%
9390       \global\warnednoepsftrue
9391     \fi
9392   \else
9393     \imagexxx #1,,,,,\finish
9394   \fi
9395 }
9396 %
9397 % Arguments to @image:
9398 % #1 is (mandatory) image filename; we tack on .eps extension.
9399 % #2 is (optional) width, #3 is (optional) height.
9400 % #4 is (ignored optional) html alt text.
9401 % #5 is (ignored optional) extension.
9402 % #6 is just the usual extra ignored arg for parsing stuff.
9403 \newif\ifimagevmode
9404 \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
9405   \catcode`\^^M = 5     % in case we're inside an example
9406   \normalturnoffactive  % allow _ et al. in names
9407   \def\xprocessmacroarg{\eatspaces}% in case we are being used via a macro
9408   % If the image is by itself, center it.
9409   \ifvmode
9410     \imagevmodetrue
9411   \else \ifx\centersub\centerV
9412     % for @center @image, we need a vbox so we can have our vertical space
9413     \imagevmodetrue
9414     \vbox\bgroup % vbox has better behavior than vtop herev
9415   \fi\fi
9416   %
9417   \ifimagevmode
9418     \nobreak\medskip
9419     % Usually we'll have text after the image which will insert
9420     % \parskip glue, so insert it here too to equalize the space
9421     % above and below.
9422     \nobreak\vskip\parskip
9423     \nobreak
9424   \fi
9425   %
9426   % Leave vertical mode so that indentation from an enclosing
9427   %  environment such as @quotation is respected.
9428   % However, if we're at the top level, we don't want the
9429   %  normal paragraph indentation.
9430   % On the other hand, if we are in the case of @center @image, we don't
9431   %  want to start a paragraph, which will create a hsize-width box and
9432   %  eradicate the centering.
9433   \ifx\centersub\centerV\else \noindent \fi
9434   %
9435   % Output the image.
9436   \ifpdf
9437     % For pdfTeX and LuaTeX <= 0.80
9438     \dopdfimage{#1}{#2}{#3}%
9439   \else
9440     \ifx\XeTeXrevision\thisisundefined
9441       % For epsf.tex
9442       % \epsfbox itself resets \epsf?size at each figure.
9443       \setbox0 = \hbox{\ignorespaces #2}%
9444         \ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
9445       \setbox0 = \hbox{\ignorespaces #3}%
9446         \ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
9447       \epsfbox{#1.eps}%
9448     \else
9449       % For XeTeX
9450       \doxeteximage{#1}{#2}{#3}%
9451     \fi
9452   \fi
9453   %
9454   \ifimagevmode
9455     \medskip  % space after a standalone image
9456   \fi  
9457   \ifx\centersub\centerV \egroup \fi
9458 \endgroup}
9459
9460
9461 % @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
9462 % etc.  We don't actually implement floating yet, we always include the
9463 % float "here".  But it seemed the best name for the future.
9464 %
9465 \envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
9466
9467 % There may be a space before second and/or third parameter; delete it.
9468 \def\eatcommaspace#1, {#1,}
9469
9470 % #1 is the optional FLOATTYPE, the text label for this float, typically
9471 % "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
9472 % this float will not be numbered and cannot be referred to.
9473 %
9474 % #2 is the optional xref label.  Also must be present for the float to
9475 % be referable.
9476 %
9477 % #3 is the optional positioning argument; for now, it is ignored.  It
9478 % will somehow specify the positions allowed to float to (here, top, bottom).
9479 %
9480 % We keep a separate counter for each FLOATTYPE, which we reset at each
9481 % chapter-level command.
9482 \let\resetallfloatnos=\empty
9483 %
9484 \def\dofloat#1,#2,#3,#4\finish{%
9485   \let\thiscaption=\empty
9486   \let\thisshortcaption=\empty
9487   %
9488   % don't lose footnotes inside @float.
9489   %
9490   % BEWARE: when the floats start float, we have to issue warning whenever an
9491   % insert appears inside a float which could possibly float. --kasal, 26may04
9492   %
9493   \startsavinginserts
9494   %
9495   % We can't be used inside a paragraph.
9496   \par
9497   %
9498   \vtop\bgroup
9499     \def\floattype{#1}%
9500     \def\floatlabel{#2}%
9501     \def\floatloc{#3}% we do nothing with this yet.
9502     %
9503     \ifx\floattype\empty
9504       \let\safefloattype=\empty
9505     \else
9506       {%
9507         % the floattype might have accents or other special characters,
9508         % but we need to use it in a control sequence name.
9509         \indexnofonts
9510         \turnoffactive
9511         \xdef\safefloattype{\floattype}%
9512       }%
9513     \fi
9514     %
9515     % If label is given but no type, we handle that as the empty type.
9516     \ifx\floatlabel\empty \else
9517       % We want each FLOATTYPE to be numbered separately (Figure 1,
9518       % Table 1, Figure 2, ...).  (And if no label, no number.)
9519       %
9520       \expandafter\getfloatno\csname\safefloattype floatno\endcsname
9521       \global\advance\floatno by 1
9522       %
9523       {%
9524         % This magic value for \lastsection is output by \setref as the
9525         % XREFLABEL-title value.  \xrefX uses it to distinguish float
9526         % labels (which have a completely different output format) from
9527         % node and anchor labels.  And \xrdef uses it to construct the
9528         % lists of floats.
9529         %
9530         \edef\lastsection{\floatmagic=\safefloattype}%
9531         \setref{\floatlabel}{Yfloat}%
9532       }%
9533     \fi
9534     %
9535     % start with \parskip glue, I guess.
9536     \vskip\parskip
9537     %
9538     % Don't suppress indentation if a float happens to start a section.
9539     \restorefirstparagraphindent
9540 }
9541
9542 % we have these possibilities:
9543 % @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
9544 % @float Foo,lbl & no caption:    Foo 1.1
9545 % @float Foo & @caption{Cap}:     Foo: Cap
9546 % @float Foo & no caption:        Foo
9547 % @float ,lbl & Caption{Cap}:     1.1: Cap
9548 % @float ,lbl & no caption:       1.1
9549 % @float & @caption{Cap}:         Cap
9550 % @float & no caption:
9551 %
9552 \def\Efloat{%
9553     \let\floatident = \empty
9554     %
9555     % In all cases, if we have a float type, it comes first.
9556     \ifx\floattype\empty \else \def\floatident{\floattype}\fi
9557     %
9558     % If we have an xref label, the number comes next.
9559     \ifx\floatlabel\empty \else
9560       \ifx\floattype\empty \else % if also had float type, need tie first.
9561         \appendtomacro\floatident{\tie}%
9562       \fi
9563       % the number.
9564       \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
9565     \fi
9566     %
9567     % Start the printed caption with what we've constructed in
9568     % \floatident, but keep it separate; we need \floatident again.
9569     \let\captionline = \floatident
9570     %
9571     \ifx\thiscaption\empty \else
9572       \ifx\floatident\empty \else
9573         \appendtomacro\captionline{: }% had ident, so need a colon between
9574       \fi
9575       %
9576       % caption text.
9577       \appendtomacro\captionline{\scanexp\thiscaption}%
9578     \fi
9579     %
9580     % If we have anything to print, print it, with space before.
9581     % Eventually this needs to become an \insert.
9582     \ifx\captionline\empty \else
9583       \vskip.5\parskip
9584       \captionline
9585       %
9586       % Space below caption.
9587       \vskip\parskip
9588     \fi
9589     %
9590     % If have an xref label, write the list of floats info.  Do this
9591     % after the caption, to avoid chance of it being a breakpoint.
9592     \ifx\floatlabel\empty \else
9593       % Write the text that goes in the lof to the aux file as
9594       % \floatlabel-lof.  Besides \floatident, we include the short
9595       % caption if specified, else the full caption if specified, else nothing.
9596       {%
9597         \requireauxfile
9598         \atdummies
9599         %
9600         \ifx\thisshortcaption\empty
9601           \def\gtemp{\thiscaption}%
9602         \else
9603           \def\gtemp{\thisshortcaption}%
9604         \fi
9605         \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
9606           \ifx\gtemp\empty \else : \gtemp \fi}}%
9607       }%
9608     \fi
9609   \egroup  % end of \vtop
9610   %
9611   \checkinserts
9612 }
9613
9614 % Append the tokens #2 to the definition of macro #1, not expanding either.
9615 %
9616 \def\appendtomacro#1#2{%
9617   \expandafter\def\expandafter#1\expandafter{#1#2}%
9618 }
9619
9620 % @caption, @shortcaption
9621 %
9622 \def\caption{\docaption\thiscaption}
9623 \def\shortcaption{\docaption\thisshortcaption}
9624 \def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
9625 \def\defcaption#1#2{\egroup \def#1{#2}}
9626
9627 % The parameter is the control sequence identifying the counter we are
9628 % going to use.  Create it if it doesn't exist and assign it to \floatno.
9629 \def\getfloatno#1{%
9630   \ifx#1\relax
9631       % Haven't seen this figure type before.
9632       \csname newcount\endcsname #1%
9633       %
9634       % Remember to reset this floatno at the next chap.
9635       \expandafter\gdef\expandafter\resetallfloatnos
9636         \expandafter{\resetallfloatnos #1=0 }%
9637   \fi
9638   \let\floatno#1%
9639 }
9640
9641 % \setref calls this to get the XREFLABEL-snt value.  We want an @xref
9642 % to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
9643 % first read the @float command.
9644 %
9645 \def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
9646
9647 % Magic string used for the XREFLABEL-title value, so \xrefX can
9648 % distinguish floats from other xref types.
9649 \def\floatmagic{!!float!!}
9650
9651 % #1 is the control sequence we are passed; we expand into a conditional
9652 % which is true if #1 represents a float ref.  That is, the magic
9653 % \lastsection value which we \setref above.
9654 %
9655 \def\iffloat#1{\expandafter\doiffloat#1==\finish}
9656 %
9657 % #1 is (maybe) the \floatmagic string.  If so, #2 will be the
9658 % (safe) float type for this float.  We set \iffloattype to #2.
9659 %
9660 \def\doiffloat#1=#2=#3\finish{%
9661   \def\temp{#1}%
9662   \def\iffloattype{#2}%
9663   \ifx\temp\floatmagic
9664 }
9665
9666 % @listoffloats FLOATTYPE - print a list of floats like a table of contents.
9667 %
9668 \parseargdef\listoffloats{%
9669   \def\floattype{#1}% floattype
9670   {%
9671     % the floattype might have accents or other special characters,
9672     % but we need to use it in a control sequence name.
9673     \indexnofonts
9674     \turnoffactive
9675     \xdef\safefloattype{\floattype}%
9676   }%
9677   %
9678   % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
9679   \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
9680     \ifhavexrefs
9681       % if the user said @listoffloats foo but never @float foo.
9682       \message{\linenumber No `\safefloattype' floats to list.}%
9683     \fi
9684   \else
9685     \begingroup
9686       \leftskip=\tocindent  % indent these entries like a toc
9687       \let\do=\listoffloatsdo
9688       \csname floatlist\safefloattype\endcsname
9689     \endgroup
9690   \fi
9691 }
9692
9693 % This is called on each entry in a list of floats.  We're passed the
9694 % xref label, in the form LABEL-title, which is how we save it in the
9695 % aux file.  We strip off the -title and look up \XRLABEL-lof, which
9696 % has the text we're supposed to typeset here.
9697 %
9698 % Figures without xref labels will not be included in the list (since
9699 % they won't appear in the aux file).
9700 %
9701 \def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
9702 \def\listoffloatsdoentry#1-title\finish{{%
9703   % Can't fully expand XR#1-lof because it can contain anything.  Just
9704   % pass the control sequence.  On the other hand, XR#1-pg is just the
9705   % page number, and we want to fully expand that so we can get a link
9706   % in pdf output.
9707   \toksA = \expandafter{\csname XR#1-lof\endcsname}%
9708   %
9709   % use the same \entry macro we use to generate the TOC and index.
9710   \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
9711   \writeentry
9712 }}
9713
9714
9715 \message{localization,}
9716
9717 % For single-language documents, @documentlanguage is usually given very
9718 % early, just after @documentencoding.  Single argument is the language
9719 % (de) or locale (de_DE) abbreviation.
9720 %
9721 {
9722   \catcode`\_ = \active
9723   \globaldefs=1
9724 \parseargdef\documentlanguage{%
9725   \tex % read txi-??.tex file in plain TeX.
9726     % Read the file by the name they passed if it exists.
9727     \let_ = \normalunderscore  % normal _ character for filename test
9728     \openin 1 txi-#1.tex
9729     \ifeof 1
9730       \documentlanguagetrywithoutunderscore #1_\finish
9731     \else
9732       \globaldefs = 1  % everything in the txi-LL files needs to persist
9733       \input txi-#1.tex
9734     \fi
9735     \closein 1
9736   \endgroup % end raw TeX
9737 }
9738 %
9739 % If they passed de_DE, and txi-de_DE.tex doesn't exist,
9740 % try txi-de.tex.
9741 %
9742 \gdef\documentlanguagetrywithoutunderscore#1_#2\finish{%
9743   \openin 1 txi-#1.tex
9744   \ifeof 1
9745     \errhelp = \nolanghelp
9746     \errmessage{Cannot read language file txi-#1.tex}%
9747   \else
9748     \globaldefs = 1  % everything in the txi-LL files needs to persist
9749     \input txi-#1.tex
9750   \fi
9751   \closein 1
9752 }
9753 }% end of special _ catcode
9754 %
9755 \newhelp\nolanghelp{The given language definition file cannot be found or
9756 is empty.  Maybe you need to install it?  Putting it in the current
9757 directory should work if nowhere else does.}
9758
9759 % This macro is called from txi-??.tex files; the first argument is the
9760 % \language name to set (without the "\lang@" prefix), the second and
9761 % third args are \{left,right}hyphenmin.
9762 %
9763 % The language names to pass are determined when the format is built.
9764 % See the etex.log file created at that time, e.g.,
9765 % /usr/local/texlive/2008/texmf-var/web2c/pdftex/etex.log.
9766 %
9767 % With TeX Live 2008, etex now includes hyphenation patterns for all
9768 % available languages.  This means we can support hyphenation in
9769 % Texinfo, at least to some extent.  (This still doesn't solve the
9770 % accented characters problem.)
9771 %
9772 \catcode`@=11
9773 \def\txisetlanguage#1#2#3{%
9774   % do not set the language if the name is undefined in the current TeX.
9775   \expandafter\ifx\csname lang@#1\endcsname \relax
9776     \message{no patterns for #1}%
9777   \else
9778     \global\language = \csname lang@#1\endcsname
9779   \fi
9780   % but there is no harm in adjusting the hyphenmin values regardless.
9781   \global\lefthyphenmin = #2\relax
9782   \global\righthyphenmin = #3\relax
9783 }
9784
9785 % XeTeX and LuaTeX can handle native Unicode.
9786 % Their default I/O is UTF-8 sequence instead of byte-wise.
9787 % Other TeX engine (pdfTeX etc.) I/O is byte-wise.
9788 %
9789 \newif\iftxinativeunicodecapable
9790 \newif\iftxiusebytewiseio
9791
9792 \ifx\XeTeXrevision\thisisundefined
9793   \ifx\luatexversion\thisisundefined
9794     \txinativeunicodecapablefalse
9795     \txiusebytewiseiotrue
9796   \else
9797     \txinativeunicodecapabletrue
9798     \txiusebytewiseiofalse
9799   \fi
9800 \else
9801   \txinativeunicodecapabletrue
9802   \txiusebytewiseiofalse
9803 \fi
9804
9805 % Set I/O by bytes instead of UTF-8 sequence for XeTeX and LuaTex
9806 % for non-UTF-8 (byte-wise) encodings.
9807 %
9808 \def\setbytewiseio{%
9809   \ifx\XeTeXrevision\thisisundefined
9810   \else
9811     \XeTeXdefaultencoding "bytes"  % For subsequent files to be read
9812     \XeTeXinputencoding "bytes"  % For document root file
9813     % Unfortunately, there seems to be no corresponding XeTeX command for
9814     % output encoding.  This is a problem for auxiliary index and TOC files.
9815     % The only solution would be perhaps to write out @U{...} sequences in
9816     % place of non-ASCII characters.
9817   \fi
9818
9819   \ifx\luatexversion\thisisundefined
9820   \else
9821     \directlua{
9822     local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub
9823     local function convert_char (char)
9824       return utf8_char(byte(char))
9825     end
9826
9827     local function convert_line (line)
9828       return gsub(line, ".", convert_char)
9829     end
9830
9831     callback.register("process_input_buffer", convert_line)
9832
9833     local function convert_line_out (line)
9834       local line_out = ""
9835       for c in string.utfvalues(line) do
9836          line_out = line_out .. string.char(c)
9837       end
9838       return line_out
9839     end
9840
9841     callback.register("process_output_buffer", convert_line_out)
9842     }
9843   \fi
9844
9845   \txiusebytewiseiotrue
9846 }
9847
9848
9849 % Helpers for encodings.
9850 % Set the catcode of characters 128 through 255 to the specified number.
9851 %
9852 \def\setnonasciicharscatcode#1{%
9853    \count255=128
9854    \loop\ifnum\count255<256
9855       \global\catcode\count255=#1\relax
9856       \advance\count255 by 1
9857    \repeat
9858 }
9859
9860 \def\setnonasciicharscatcodenonglobal#1{%
9861    \count255=128
9862    \loop\ifnum\count255<256
9863       \catcode\count255=#1\relax
9864       \advance\count255 by 1
9865    \repeat
9866 }
9867
9868 % @documentencoding sets the definition of non-ASCII characters
9869 % according to the specified encoding.
9870 %
9871 \def\documentencoding{\parseargusing\filenamecatcodes\documentencodingzzz}
9872 \def\documentencodingzzz#1{%
9873   %
9874   % Encoding being declared for the document.
9875   \def\declaredencoding{\csname #1.enc\endcsname}%
9876   %
9877   % Supported encodings: names converted to tokens in order to be able
9878   % to compare them with \ifx.
9879   \def\ascii{\csname US-ASCII.enc\endcsname}%
9880   \def\latnine{\csname ISO-8859-15.enc\endcsname}%
9881   \def\latone{\csname ISO-8859-1.enc\endcsname}%
9882   \def\lattwo{\csname ISO-8859-2.enc\endcsname}%
9883   \def\utfeight{\csname UTF-8.enc\endcsname}%
9884   %
9885   \ifx \declaredencoding \ascii
9886      \asciichardefs
9887   %
9888   \else \ifx \declaredencoding \lattwo
9889      \iftxinativeunicodecapable
9890        \setbytewiseio
9891      \fi
9892      \setnonasciicharscatcode\active
9893      \lattwochardefs
9894   %
9895   \else \ifx \declaredencoding \latone
9896      \iftxinativeunicodecapable
9897        \setbytewiseio
9898      \fi
9899      \setnonasciicharscatcode\active
9900      \latonechardefs
9901   %
9902   \else \ifx \declaredencoding \latnine
9903      \iftxinativeunicodecapable
9904        \setbytewiseio
9905      \fi
9906      \setnonasciicharscatcode\active
9907      \latninechardefs
9908   %
9909   \else \ifx \declaredencoding \utfeight
9910      \iftxinativeunicodecapable
9911        % For native Unicode (XeTeX and LuaTeX)
9912        \nativeunicodechardefs
9913      \else
9914        % For UTF-8 byte sequence (TeX, eTeX and pdfTeX)
9915        \setnonasciicharscatcode\active
9916        % since we already invoked \utfeightchardefs at the top level
9917        % (below), do not re-invoke it, then our check for duplicated
9918        % definitions triggers.  Making non-ascii chars active is enough.
9919      \fi
9920   %
9921   \else
9922     \message{Ignoring unknown document encoding: #1.}%
9923   %
9924   \fi % utfeight
9925   \fi % latnine
9926   \fi % latone
9927   \fi % lattwo
9928   \fi % ascii
9929 }
9930
9931 % emacs-page
9932 % A message to be logged when using a character that isn't available
9933 % the default font encoding (OT1).
9934 %
9935 \def\missingcharmsg#1{\message{Character missing, sorry: #1.}}
9936
9937 % Take account of \c (plain) vs. \, (Texinfo) difference.
9938 \def\cedilla#1{\ifx\c\ptexc\c{#1}\else\,{#1}\fi}
9939
9940 % First, make active non-ASCII characters in order for them to be
9941 % correctly categorized when TeX reads the replacement text of
9942 % macros containing the character definitions.
9943 \setnonasciicharscatcode\active
9944 %
9945
9946 \def\gdefchar#1#2{%
9947 \gdef#1{%
9948    \ifpassthroughchars
9949      \string#1%
9950    \else
9951      #2%
9952    \fi
9953 }}
9954
9955 % Latin1 (ISO-8859-1) character definitions.
9956 \def\latonechardefs{%
9957   \gdefchar^^a0{\tie}
9958   \gdefchar^^a1{\exclamdown}
9959   \gdefchar^^a2{{\tcfont \char162}} % cent
9960   \gdefchar^^a3{\pounds}
9961   \gdefchar^^a4{{\tcfont \char164}} % currency
9962   \gdefchar^^a5{{\tcfont \char165}} % yen
9963   \gdefchar^^a6{{\tcfont \char166}} % broken bar
9964   \gdefchar^^a7{\S}
9965   \gdefchar^^a8{\"{}}
9966   \gdefchar^^a9{\copyright}
9967   \gdefchar^^aa{\ordf}
9968   \gdefchar^^ab{\guillemetleft}
9969   \gdefchar^^ac{\ensuremath\lnot}
9970   \gdefchar^^ad{\-}
9971   \gdefchar^^ae{\registeredsymbol}
9972   \gdefchar^^af{\={}}
9973   %
9974   \gdefchar^^b0{\textdegree}
9975   \gdefchar^^b1{$\pm$}
9976   \gdefchar^^b2{$^2$}
9977   \gdefchar^^b3{$^3$}
9978   \gdefchar^^b4{\'{}}
9979   \gdefchar^^b5{$\mu$}
9980   \gdefchar^^b6{\P}
9981   \gdefchar^^b7{\ensuremath\cdot}
9982   \gdefchar^^b8{\cedilla\ }
9983   \gdefchar^^b9{$^1$}
9984   \gdefchar^^ba{\ordm}
9985   \gdefchar^^bb{\guillemetright}
9986   \gdefchar^^bc{$1\over4$}
9987   \gdefchar^^bd{$1\over2$}
9988   \gdefchar^^be{$3\over4$}
9989   \gdefchar^^bf{\questiondown}
9990   %
9991   \gdefchar^^c0{\`A}
9992   \gdefchar^^c1{\'A}
9993   \gdefchar^^c2{\^A}
9994   \gdefchar^^c3{\~A}
9995   \gdefchar^^c4{\"A}
9996   \gdefchar^^c5{\ringaccent A}
9997   \gdefchar^^c6{\AE}
9998   \gdefchar^^c7{\cedilla C}
9999   \gdefchar^^c8{\`E}
10000   \gdefchar^^c9{\'E}
10001   \gdefchar^^ca{\^E}
10002   \gdefchar^^cb{\"E}
10003   \gdefchar^^cc{\`I}
10004   \gdefchar^^cd{\'I}
10005   \gdefchar^^ce{\^I}
10006   \gdefchar^^cf{\"I}
10007   %
10008   \gdefchar^^d0{\DH}
10009   \gdefchar^^d1{\~N}
10010   \gdefchar^^d2{\`O}
10011   \gdefchar^^d3{\'O}
10012   \gdefchar^^d4{\^O}
10013   \gdefchar^^d5{\~O}
10014   \gdefchar^^d6{\"O}
10015   \gdefchar^^d7{$\times$}
10016   \gdefchar^^d8{\O}
10017   \gdefchar^^d9{\`U}
10018   \gdefchar^^da{\'U}
10019   \gdefchar^^db{\^U}
10020   \gdefchar^^dc{\"U}
10021   \gdefchar^^dd{\'Y}
10022   \gdefchar^^de{\TH}
10023   \gdefchar^^df{\ss}
10024   %
10025   \gdefchar^^e0{\`a}
10026   \gdefchar^^e1{\'a}
10027   \gdefchar^^e2{\^a}
10028   \gdefchar^^e3{\~a}
10029   \gdefchar^^e4{\"a}
10030   \gdefchar^^e5{\ringaccent a}
10031   \gdefchar^^e6{\ae}
10032   \gdefchar^^e7{\cedilla c}
10033   \gdefchar^^e8{\`e}
10034   \gdefchar^^e9{\'e}
10035   \gdefchar^^ea{\^e}
10036   \gdefchar^^eb{\"e}
10037   \gdefchar^^ec{\`{\dotless i}}
10038   \gdefchar^^ed{\'{\dotless i}}
10039   \gdefchar^^ee{\^{\dotless i}}
10040   \gdefchar^^ef{\"{\dotless i}}
10041   %
10042   \gdefchar^^f0{\dh}
10043   \gdefchar^^f1{\~n}
10044   \gdefchar^^f2{\`o}
10045   \gdefchar^^f3{\'o}
10046   \gdefchar^^f4{\^o}
10047   \gdefchar^^f5{\~o}
10048   \gdefchar^^f6{\"o}
10049   \gdefchar^^f7{$\div$}
10050   \gdefchar^^f8{\o}
10051   \gdefchar^^f9{\`u}
10052   \gdefchar^^fa{\'u}
10053   \gdefchar^^fb{\^u}
10054   \gdefchar^^fc{\"u}
10055   \gdefchar^^fd{\'y}
10056   \gdefchar^^fe{\th}
10057   \gdefchar^^ff{\"y}
10058 }
10059
10060 % Latin9 (ISO-8859-15) encoding character definitions.
10061 \def\latninechardefs{%
10062   % Encoding is almost identical to Latin1.
10063   \latonechardefs
10064   %
10065   \gdefchar^^a4{\euro}
10066   \gdefchar^^a6{\v S}
10067   \gdefchar^^a8{\v s}
10068   \gdefchar^^b4{\v Z}
10069   \gdefchar^^b8{\v z}
10070   \gdefchar^^bc{\OE}
10071   \gdefchar^^bd{\oe}
10072   \gdefchar^^be{\"Y}
10073 }
10074
10075 % Latin2 (ISO-8859-2) character definitions.
10076 \def\lattwochardefs{%
10077   \gdefchar^^a0{\tie}
10078   \gdefchar^^a1{\ogonek{A}}
10079   \gdefchar^^a2{\u{}}
10080   \gdefchar^^a3{\L}
10081   \gdefchar^^a4{\missingcharmsg{CURRENCY SIGN}}
10082   \gdefchar^^a5{\v L}
10083   \gdefchar^^a6{\'S}
10084   \gdefchar^^a7{\S}
10085   \gdefchar^^a8{\"{}}
10086   \gdefchar^^a9{\v S}
10087   \gdefchar^^aa{\cedilla S}
10088   \gdefchar^^ab{\v T}
10089   \gdefchar^^ac{\'Z}
10090   \gdefchar^^ad{\-}
10091   \gdefchar^^ae{\v Z}
10092   \gdefchar^^af{\dotaccent Z}
10093   %
10094   \gdefchar^^b0{\textdegree}
10095   \gdefchar^^b1{\ogonek{a}}
10096   \gdefchar^^b2{\ogonek{ }}
10097   \gdefchar^^b3{\l}
10098   \gdefchar^^b4{\'{}}
10099   \gdefchar^^b5{\v l}
10100   \gdefchar^^b6{\'s}
10101   \gdefchar^^b7{\v{}}
10102   \gdefchar^^b8{\cedilla\ }
10103   \gdefchar^^b9{\v s}
10104   \gdefchar^^ba{\cedilla s}
10105   \gdefchar^^bb{\v t}
10106   \gdefchar^^bc{\'z}
10107   \gdefchar^^bd{\H{}}
10108   \gdefchar^^be{\v z}
10109   \gdefchar^^bf{\dotaccent z}
10110   %
10111   \gdefchar^^c0{\'R}
10112   \gdefchar^^c1{\'A}
10113   \gdefchar^^c2{\^A}
10114   \gdefchar^^c3{\u A}
10115   \gdefchar^^c4{\"A}
10116   \gdefchar^^c5{\'L}
10117   \gdefchar^^c6{\'C}
10118   \gdefchar^^c7{\cedilla C}
10119   \gdefchar^^c8{\v C}
10120   \gdefchar^^c9{\'E}
10121   \gdefchar^^ca{\ogonek{E}}
10122   \gdefchar^^cb{\"E}
10123   \gdefchar^^cc{\v E}
10124   \gdefchar^^cd{\'I}
10125   \gdefchar^^ce{\^I}
10126   \gdefchar^^cf{\v D}
10127   %
10128   \gdefchar^^d0{\DH}
10129   \gdefchar^^d1{\'N}
10130   \gdefchar^^d2{\v N}
10131   \gdefchar^^d3{\'O}
10132   \gdefchar^^d4{\^O}
10133   \gdefchar^^d5{\H O}
10134   \gdefchar^^d6{\"O}
10135   \gdefchar^^d7{$\times$}
10136   \gdefchar^^d8{\v R}
10137   \gdefchar^^d9{\ringaccent U}
10138   \gdefchar^^da{\'U}
10139   \gdefchar^^db{\H U}
10140   \gdefchar^^dc{\"U}
10141   \gdefchar^^dd{\'Y}
10142   \gdefchar^^de{\cedilla T}
10143   \gdefchar^^df{\ss}
10144   %
10145   \gdefchar^^e0{\'r}
10146   \gdefchar^^e1{\'a}
10147   \gdefchar^^e2{\^a}
10148   \gdefchar^^e3{\u a}
10149   \gdefchar^^e4{\"a}
10150   \gdefchar^^e5{\'l}
10151   \gdefchar^^e6{\'c}
10152   \gdefchar^^e7{\cedilla c}
10153   \gdefchar^^e8{\v c}
10154   \gdefchar^^e9{\'e}
10155   \gdefchar^^ea{\ogonek{e}}
10156   \gdefchar^^eb{\"e}
10157   \gdefchar^^ec{\v e}
10158   \gdefchar^^ed{\'{\dotless{i}}}
10159   \gdefchar^^ee{\^{\dotless{i}}}
10160   \gdefchar^^ef{\v d}
10161   %
10162   \gdefchar^^f0{\dh}
10163   \gdefchar^^f1{\'n}
10164   \gdefchar^^f2{\v n}
10165   \gdefchar^^f3{\'o}
10166   \gdefchar^^f4{\^o}
10167   \gdefchar^^f5{\H o}
10168   \gdefchar^^f6{\"o}
10169   \gdefchar^^f7{$\div$}
10170   \gdefchar^^f8{\v r}
10171   \gdefchar^^f9{\ringaccent u}
10172   \gdefchar^^fa{\'u}
10173   \gdefchar^^fb{\H u}
10174   \gdefchar^^fc{\"u}
10175   \gdefchar^^fd{\'y}
10176   \gdefchar^^fe{\cedilla t}
10177   \gdefchar^^ff{\dotaccent{}}
10178 }
10179
10180 % UTF-8 character definitions.
10181 %
10182 % This code to support UTF-8 is based on LaTeX's utf8.def, with some
10183 % changes for Texinfo conventions.  It is included here under the GPL by
10184 % permission from Frank Mittelbach and the LaTeX team.
10185 %
10186 \newcount\countUTFx
10187 \newcount\countUTFy
10188 \newcount\countUTFz
10189
10190 \gdef\UTFviiiTwoOctets#1#2{\expandafter
10191    \UTFviiiDefined\csname u8:#1\string #2\endcsname}
10192 %
10193 \gdef\UTFviiiThreeOctets#1#2#3{\expandafter
10194    \UTFviiiDefined\csname u8:#1\string #2\string #3\endcsname}
10195 %
10196 \gdef\UTFviiiFourOctets#1#2#3#4{\expandafter
10197    \UTFviiiDefined\csname u8:#1\string #2\string #3\string #4\endcsname}
10198
10199 \gdef\UTFviiiDefined#1{%
10200   \ifx #1\relax
10201     \message{\linenumber Unicode char \string #1 not defined for Texinfo}%
10202   \else
10203     \expandafter #1%
10204   \fi
10205 }
10206
10207 % Give non-ASCII bytes the active definitions for processing UTF-8 sequences
10208 \begingroup
10209   \catcode`\~13
10210   \catcode`\$12
10211   \catcode`\"12
10212
10213   % Loop from \countUTFx to \countUTFy, performing \UTFviiiTmp
10214   % substituting ~ and $ with a character token of that value.
10215   \def\UTFviiiLoop{%
10216     \global\catcode\countUTFx\active
10217     \uccode`\~\countUTFx
10218     \uccode`\$\countUTFx
10219     \uppercase\expandafter{\UTFviiiTmp}%
10220     \advance\countUTFx by 1
10221     \ifnum\countUTFx < \countUTFy
10222       \expandafter\UTFviiiLoop
10223     \fi}
10224
10225   % For bytes other than the first in a UTF-8 sequence.  Not expected to
10226   % be expanded except when writing to auxiliary files.
10227   \countUTFx = "80
10228   \countUTFy = "C2
10229   \def\UTFviiiTmp{%
10230     \gdef~{
10231         \ifpassthroughchars $\fi}}%
10232   \UTFviiiLoop
10233
10234   \countUTFx = "C2
10235   \countUTFy = "E0
10236   \def\UTFviiiTmp{%
10237     \gdef~{%
10238         \ifpassthroughchars $%
10239         \else\expandafter\UTFviiiTwoOctets\expandafter$\fi}}%
10240   \UTFviiiLoop
10241
10242   \countUTFx = "E0
10243   \countUTFy = "F0
10244   \def\UTFviiiTmp{%
10245     \gdef~{%
10246         \ifpassthroughchars $%
10247         \else\expandafter\UTFviiiThreeOctets\expandafter$\fi}}%
10248   \UTFviiiLoop
10249
10250   \countUTFx = "F0
10251   \countUTFy = "F4
10252   \def\UTFviiiTmp{%
10253     \gdef~{%
10254         \ifpassthroughchars $%
10255         \else\expandafter\UTFviiiFourOctets\expandafter$\fi
10256         }}%
10257   \UTFviiiLoop
10258 \endgroup
10259
10260 \def\globallet{\global\let} % save some \expandafter's below
10261
10262 % @U{xxxx} to produce U+xxxx, if we support it.
10263 \def\U#1{%
10264   \expandafter\ifx\csname uni:#1\endcsname \relax
10265     \iftxinativeunicodecapable
10266       % Any Unicode characters can be used by native Unicode.
10267       % However, if the font does not have the glyph, the letter will miss.
10268       \begingroup
10269         \uccode`\.="#1\relax
10270         \uppercase{.}
10271       \endgroup
10272     \else
10273       \errhelp = \EMsimple      
10274       \errmessage{Unicode character U+#1 not supported, sorry}%
10275     \fi
10276   \else
10277     \csname uni:#1\endcsname
10278   \fi
10279 }
10280
10281 % For UTF-8 byte sequence (TeX, e-TeX and pdfTeX)
10282 % Definition macro to replace the Unicode character
10283 % Definition macro that is used by @U command
10284 %
10285 \begingroup
10286   \catcode`\"=12
10287   \catcode`\<=12
10288   \catcode`\.=12
10289   \catcode`\,=12
10290   \catcode`\;=12
10291   \catcode`\!=12
10292   \catcode`\~=13
10293   \gdef\DeclareUnicodeCharacterUTFviii#1#2{%
10294     \countUTFz = "#1\relax
10295     \begingroup
10296       \parseXMLCharref
10297       %
10298       % Access definitions of characters given UTF-8 sequences
10299       \def\UTFviiiTwoOctets##1##2{%
10300         \csname u8:##1\string ##2\endcsname}%
10301       \def\UTFviiiThreeOctets##1##2##3{%
10302         \csname u8:##1\string ##2\string ##3\endcsname}%
10303       \def\UTFviiiFourOctets##1##2##3##4{%
10304         \csname u8:##1\string ##2\string ##3\string ##4\endcsname}%
10305       \expandafter\expandafter\expandafter\expandafter
10306        \expandafter\expandafter\expandafter
10307        \gdef\UTFviiiTmp{#2}%
10308       % 
10309       \expandafter\ifx\csname uni:#1\endcsname \relax \else
10310        \message{Internal error, already defined: #1}%
10311       \fi
10312       %
10313       % define an additional control sequence for this code point.
10314       \expandafter\globallet\csname uni:#1\endcsname \UTFviiiTmp
10315     \endgroup}
10316   %
10317   % Given the value in \countUTFz as a Unicode code point, set \UTFviiiTmp.
10318   \gdef\parseXMLCharref{%
10319     \ifnum\countUTFz < "A0\relax
10320       \errhelp = \EMsimple
10321       \errmessage{Cannot define Unicode char value < 00A0}%
10322     \else\ifnum\countUTFz < "800\relax
10323       \parseUTFviiiA,%
10324       \parseUTFviiiB C\UTFviiiTwoOctets.,%
10325     \else\ifnum\countUTFz < "10000\relax
10326       \parseUTFviiiA;%
10327       \parseUTFviiiA,%
10328       \parseUTFviiiB E\UTFviiiThreeOctets.{,;}%
10329     \else
10330       \parseUTFviiiA;%
10331       \parseUTFviiiA,%
10332       \parseUTFviiiA!%
10333       \parseUTFviiiB F\UTFviiiFourOctets.{!,;}%
10334     \fi\fi\fi
10335   }
10336
10337   \gdef\parseUTFviiiA#1{%
10338     \countUTFx = \countUTFz
10339     \divide\countUTFz by 64
10340     \countUTFy = \countUTFz
10341     \multiply\countUTFz by 64
10342     \advance\countUTFx by -\countUTFz
10343     \advance\countUTFx by 128
10344     \uccode `#1\countUTFx
10345     \countUTFz = \countUTFy}
10346
10347   % Used to set \UTFviiiTmp to a UTF-8 byte sequence
10348   \gdef\parseUTFviiiB#1#2#3#4{%
10349     \advance\countUTFz by "#10\relax
10350     \uccode `#3\countUTFz
10351     \uppercase{\gdef\UTFviiiTmp{#2#3#4}}}
10352 \endgroup
10353
10354 % For native Unicode (XeTeX and LuaTeX)
10355 % Definition macro that is set catcode other non global
10356 %
10357 \def\DeclareUnicodeCharacterNativeOther#1#2{%
10358   \catcode"#1=\other
10359 }
10360
10361 % https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_M
10362 % U+0000..U+007F = https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)
10363 % U+0080..U+00FF = https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)
10364 % U+0100..U+017F = https://en.wikipedia.org/wiki/Latin_Extended-A
10365 % U+0180..U+024F = https://en.wikipedia.org/wiki/Latin_Extended-B
10366
10367 % Many of our renditions are less than wonderful, and all the missing
10368 % characters are available somewhere.  Loading the necessary fonts
10369 % awaits user request.  We can't truly support Unicode without
10370 % reimplementing everything that's been done in LaTeX for many years,
10371 % plus probably using luatex or xetex, and who knows what else.
10372 % We won't be doing that here in this simple file.  But we can try to at
10373 % least make most of the characters not bomb out.
10374 %
10375 \def\unicodechardefs{%
10376   \DeclareUnicodeCharacter{00A0}{\tie}%
10377   \DeclareUnicodeCharacter{00A1}{\exclamdown}%
10378   \DeclareUnicodeCharacter{00A2}{{\tcfont \char162}}% 0242=cent
10379   \DeclareUnicodeCharacter{00A3}{\pounds}%
10380   \DeclareUnicodeCharacter{00A4}{{\tcfont \char164}}% 0244=currency
10381   \DeclareUnicodeCharacter{00A5}{{\tcfont \char165}}% 0245=yen
10382   \DeclareUnicodeCharacter{00A6}{{\tcfont \char166}}% 0246=brokenbar
10383   \DeclareUnicodeCharacter{00A7}{\S}%
10384   \DeclareUnicodeCharacter{00A8}{\"{ }}%
10385   \DeclareUnicodeCharacter{00A9}{\copyright}%
10386   \DeclareUnicodeCharacter{00AA}{\ordf}%
10387   \DeclareUnicodeCharacter{00AB}{\guillemetleft}%
10388   \DeclareUnicodeCharacter{00AC}{\ensuremath\lnot}%
10389   \DeclareUnicodeCharacter{00AD}{\-}%
10390   \DeclareUnicodeCharacter{00AE}{\registeredsymbol}%
10391   \DeclareUnicodeCharacter{00AF}{\={ }}%
10392   %
10393   \DeclareUnicodeCharacter{00B0}{\ringaccent{ }}%
10394   \DeclareUnicodeCharacter{00B1}{\ensuremath\pm}%
10395   \DeclareUnicodeCharacter{00B2}{$^2$}%
10396   \DeclareUnicodeCharacter{00B3}{$^3$}%
10397   \DeclareUnicodeCharacter{00B4}{\'{ }}%
10398   \DeclareUnicodeCharacter{00B5}{$\mu$}%
10399   \DeclareUnicodeCharacter{00B6}{\P}%
10400   \DeclareUnicodeCharacter{00B7}{\ensuremath\cdot}%
10401   \DeclareUnicodeCharacter{00B8}{\cedilla{ }}%
10402   \DeclareUnicodeCharacter{00B9}{$^1$}%
10403   \DeclareUnicodeCharacter{00BA}{\ordm}%
10404   \DeclareUnicodeCharacter{00BB}{\guillemetright}%
10405   \DeclareUnicodeCharacter{00BC}{$1\over4$}%
10406   \DeclareUnicodeCharacter{00BD}{$1\over2$}%
10407   \DeclareUnicodeCharacter{00BE}{$3\over4$}%
10408   \DeclareUnicodeCharacter{00BF}{\questiondown}%
10409   %
10410   \DeclareUnicodeCharacter{00C0}{\`A}%
10411   \DeclareUnicodeCharacter{00C1}{\'A}%
10412   \DeclareUnicodeCharacter{00C2}{\^A}%
10413   \DeclareUnicodeCharacter{00C3}{\~A}%
10414   \DeclareUnicodeCharacter{00C4}{\"A}%
10415   \DeclareUnicodeCharacter{00C5}{\AA}%
10416   \DeclareUnicodeCharacter{00C6}{\AE}%
10417   \DeclareUnicodeCharacter{00C7}{\cedilla{C}}%
10418   \DeclareUnicodeCharacter{00C8}{\`E}%
10419   \DeclareUnicodeCharacter{00C9}{\'E}%
10420   \DeclareUnicodeCharacter{00CA}{\^E}%
10421   \DeclareUnicodeCharacter{00CB}{\"E}%
10422   \DeclareUnicodeCharacter{00CC}{\`I}%
10423   \DeclareUnicodeCharacter{00CD}{\'I}%
10424   \DeclareUnicodeCharacter{00CE}{\^I}%
10425   \DeclareUnicodeCharacter{00CF}{\"I}%
10426   %
10427   \DeclareUnicodeCharacter{00D0}{\DH}%
10428   \DeclareUnicodeCharacter{00D1}{\~N}%
10429   \DeclareUnicodeCharacter{00D2}{\`O}%
10430   \DeclareUnicodeCharacter{00D3}{\'O}%
10431   \DeclareUnicodeCharacter{00D4}{\^O}%
10432   \DeclareUnicodeCharacter{00D5}{\~O}%
10433   \DeclareUnicodeCharacter{00D6}{\"O}%
10434   \DeclareUnicodeCharacter{00D7}{\ensuremath\times}%
10435   \DeclareUnicodeCharacter{00D8}{\O}%
10436   \DeclareUnicodeCharacter{00D9}{\`U}%
10437   \DeclareUnicodeCharacter{00DA}{\'U}%
10438   \DeclareUnicodeCharacter{00DB}{\^U}%
10439   \DeclareUnicodeCharacter{00DC}{\"U}%
10440   \DeclareUnicodeCharacter{00DD}{\'Y}%
10441   \DeclareUnicodeCharacter{00DE}{\TH}%
10442   \DeclareUnicodeCharacter{00DF}{\ss}%
10443   %
10444   \DeclareUnicodeCharacter{00E0}{\`a}%
10445   \DeclareUnicodeCharacter{00E1}{\'a}%
10446   \DeclareUnicodeCharacter{00E2}{\^a}%
10447   \DeclareUnicodeCharacter{00E3}{\~a}%
10448   \DeclareUnicodeCharacter{00E4}{\"a}%
10449   \DeclareUnicodeCharacter{00E5}{\aa}%
10450   \DeclareUnicodeCharacter{00E6}{\ae}%
10451   \DeclareUnicodeCharacter{00E7}{\cedilla{c}}%
10452   \DeclareUnicodeCharacter{00E8}{\`e}%
10453   \DeclareUnicodeCharacter{00E9}{\'e}%
10454   \DeclareUnicodeCharacter{00EA}{\^e}%
10455   \DeclareUnicodeCharacter{00EB}{\"e}%
10456   \DeclareUnicodeCharacter{00EC}{\`{\dotless{i}}}%
10457   \DeclareUnicodeCharacter{00ED}{\'{\dotless{i}}}%
10458   \DeclareUnicodeCharacter{00EE}{\^{\dotless{i}}}%
10459   \DeclareUnicodeCharacter{00EF}{\"{\dotless{i}}}%
10460   %
10461   \DeclareUnicodeCharacter{00F0}{\dh}%
10462   \DeclareUnicodeCharacter{00F1}{\~n}%
10463   \DeclareUnicodeCharacter{00F2}{\`o}%
10464   \DeclareUnicodeCharacter{00F3}{\'o}%
10465   \DeclareUnicodeCharacter{00F4}{\^o}%
10466   \DeclareUnicodeCharacter{00F5}{\~o}%
10467   \DeclareUnicodeCharacter{00F6}{\"o}%
10468   \DeclareUnicodeCharacter{00F7}{\ensuremath\div}%
10469   \DeclareUnicodeCharacter{00F8}{\o}%
10470   \DeclareUnicodeCharacter{00F9}{\`u}%
10471   \DeclareUnicodeCharacter{00FA}{\'u}%
10472   \DeclareUnicodeCharacter{00FB}{\^u}%
10473   \DeclareUnicodeCharacter{00FC}{\"u}%
10474   \DeclareUnicodeCharacter{00FD}{\'y}%
10475   \DeclareUnicodeCharacter{00FE}{\th}%
10476   \DeclareUnicodeCharacter{00FF}{\"y}%
10477   %
10478   \DeclareUnicodeCharacter{0100}{\=A}%
10479   \DeclareUnicodeCharacter{0101}{\=a}%
10480   \DeclareUnicodeCharacter{0102}{\u{A}}%
10481   \DeclareUnicodeCharacter{0103}{\u{a}}%
10482   \DeclareUnicodeCharacter{0104}{\ogonek{A}}%
10483   \DeclareUnicodeCharacter{0105}{\ogonek{a}}%
10484   \DeclareUnicodeCharacter{0106}{\'C}%
10485   \DeclareUnicodeCharacter{0107}{\'c}%
10486   \DeclareUnicodeCharacter{0108}{\^C}%
10487   \DeclareUnicodeCharacter{0109}{\^c}%
10488   \DeclareUnicodeCharacter{010A}{\dotaccent{C}}%
10489   \DeclareUnicodeCharacter{010B}{\dotaccent{c}}%
10490   \DeclareUnicodeCharacter{010C}{\v{C}}%
10491   \DeclareUnicodeCharacter{010D}{\v{c}}%
10492   \DeclareUnicodeCharacter{010E}{\v{D}}%
10493   \DeclareUnicodeCharacter{010F}{d'}%
10494   %
10495   \DeclareUnicodeCharacter{0110}{\DH}%
10496   \DeclareUnicodeCharacter{0111}{\dh}%
10497   \DeclareUnicodeCharacter{0112}{\=E}%
10498   \DeclareUnicodeCharacter{0113}{\=e}%
10499   \DeclareUnicodeCharacter{0114}{\u{E}}%
10500   \DeclareUnicodeCharacter{0115}{\u{e}}%
10501   \DeclareUnicodeCharacter{0116}{\dotaccent{E}}%
10502   \DeclareUnicodeCharacter{0117}{\dotaccent{e}}%
10503   \DeclareUnicodeCharacter{0118}{\ogonek{E}}%
10504   \DeclareUnicodeCharacter{0119}{\ogonek{e}}%
10505   \DeclareUnicodeCharacter{011A}{\v{E}}%
10506   \DeclareUnicodeCharacter{011B}{\v{e}}%
10507   \DeclareUnicodeCharacter{011C}{\^G}%
10508   \DeclareUnicodeCharacter{011D}{\^g}%
10509   \DeclareUnicodeCharacter{011E}{\u{G}}%
10510   \DeclareUnicodeCharacter{011F}{\u{g}}%
10511   %
10512   \DeclareUnicodeCharacter{0120}{\dotaccent{G}}%
10513   \DeclareUnicodeCharacter{0121}{\dotaccent{g}}%
10514   \DeclareUnicodeCharacter{0122}{\cedilla{G}}%
10515   \DeclareUnicodeCharacter{0123}{\cedilla{g}}%
10516   \DeclareUnicodeCharacter{0124}{\^H}%
10517   \DeclareUnicodeCharacter{0125}{\^h}%
10518   \DeclareUnicodeCharacter{0126}{\missingcharmsg{H WITH STROKE}}%
10519   \DeclareUnicodeCharacter{0127}{\missingcharmsg{h WITH STROKE}}%
10520   \DeclareUnicodeCharacter{0128}{\~I}%
10521   \DeclareUnicodeCharacter{0129}{\~{\dotless{i}}}%
10522   \DeclareUnicodeCharacter{012A}{\=I}%
10523   \DeclareUnicodeCharacter{012B}{\={\dotless{i}}}%
10524   \DeclareUnicodeCharacter{012C}{\u{I}}%
10525   \DeclareUnicodeCharacter{012D}{\u{\dotless{i}}}%
10526   \DeclareUnicodeCharacter{012E}{\ogonek{I}}%
10527   \DeclareUnicodeCharacter{012F}{\ogonek{i}}%
10528   %
10529   \DeclareUnicodeCharacter{0130}{\dotaccent{I}}%
10530   \DeclareUnicodeCharacter{0131}{\dotless{i}}%
10531   \DeclareUnicodeCharacter{0132}{IJ}%
10532   \DeclareUnicodeCharacter{0133}{ij}%
10533   \DeclareUnicodeCharacter{0134}{\^J}%
10534   \DeclareUnicodeCharacter{0135}{\^{\dotless{j}}}%
10535   \DeclareUnicodeCharacter{0136}{\cedilla{K}}%
10536   \DeclareUnicodeCharacter{0137}{\cedilla{k}}%
10537   \DeclareUnicodeCharacter{0138}{\ensuremath\kappa}%
10538   \DeclareUnicodeCharacter{0139}{\'L}%
10539   \DeclareUnicodeCharacter{013A}{\'l}%
10540   \DeclareUnicodeCharacter{013B}{\cedilla{L}}%
10541   \DeclareUnicodeCharacter{013C}{\cedilla{l}}%
10542   \DeclareUnicodeCharacter{013D}{L'}% should kern
10543   \DeclareUnicodeCharacter{013E}{l'}% should kern
10544   \DeclareUnicodeCharacter{013F}{L\U{00B7}}%
10545   %
10546   \DeclareUnicodeCharacter{0140}{l\U{00B7}}%
10547   \DeclareUnicodeCharacter{0141}{\L}%
10548   \DeclareUnicodeCharacter{0142}{\l}%
10549   \DeclareUnicodeCharacter{0143}{\'N}%
10550   \DeclareUnicodeCharacter{0144}{\'n}%
10551   \DeclareUnicodeCharacter{0145}{\cedilla{N}}%
10552   \DeclareUnicodeCharacter{0146}{\cedilla{n}}%
10553   \DeclareUnicodeCharacter{0147}{\v{N}}%
10554   \DeclareUnicodeCharacter{0148}{\v{n}}%
10555   \DeclareUnicodeCharacter{0149}{'n}%
10556   \DeclareUnicodeCharacter{014A}{\missingcharmsg{ENG}}%
10557   \DeclareUnicodeCharacter{014B}{\missingcharmsg{eng}}%
10558   \DeclareUnicodeCharacter{014C}{\=O}%
10559   \DeclareUnicodeCharacter{014D}{\=o}%
10560   \DeclareUnicodeCharacter{014E}{\u{O}}%
10561   \DeclareUnicodeCharacter{014F}{\u{o}}%
10562   %
10563   \DeclareUnicodeCharacter{0150}{\H{O}}%
10564   \DeclareUnicodeCharacter{0151}{\H{o}}%
10565   \DeclareUnicodeCharacter{0152}{\OE}%
10566   \DeclareUnicodeCharacter{0153}{\oe}%
10567   \DeclareUnicodeCharacter{0154}{\'R}%
10568   \DeclareUnicodeCharacter{0155}{\'r}%
10569   \DeclareUnicodeCharacter{0156}{\cedilla{R}}%
10570   \DeclareUnicodeCharacter{0157}{\cedilla{r}}%
10571   \DeclareUnicodeCharacter{0158}{\v{R}}%
10572   \DeclareUnicodeCharacter{0159}{\v{r}}%
10573   \DeclareUnicodeCharacter{015A}{\'S}%
10574   \DeclareUnicodeCharacter{015B}{\'s}%
10575   \DeclareUnicodeCharacter{015C}{\^S}%
10576   \DeclareUnicodeCharacter{015D}{\^s}%
10577   \DeclareUnicodeCharacter{015E}{\cedilla{S}}%
10578   \DeclareUnicodeCharacter{015F}{\cedilla{s}}%
10579   %
10580   \DeclareUnicodeCharacter{0160}{\v{S}}%
10581   \DeclareUnicodeCharacter{0161}{\v{s}}%
10582   \DeclareUnicodeCharacter{0162}{\cedilla{T}}%
10583   \DeclareUnicodeCharacter{0163}{\cedilla{t}}%
10584   \DeclareUnicodeCharacter{0164}{\v{T}}%
10585   \DeclareUnicodeCharacter{0165}{\v{t}}%
10586   \DeclareUnicodeCharacter{0166}{\missingcharmsg{H WITH STROKE}}%
10587   \DeclareUnicodeCharacter{0167}{\missingcharmsg{h WITH STROKE}}%
10588   \DeclareUnicodeCharacter{0168}{\~U}%
10589   \DeclareUnicodeCharacter{0169}{\~u}%
10590   \DeclareUnicodeCharacter{016A}{\=U}%
10591   \DeclareUnicodeCharacter{016B}{\=u}%
10592   \DeclareUnicodeCharacter{016C}{\u{U}}%
10593   \DeclareUnicodeCharacter{016D}{\u{u}}%
10594   \DeclareUnicodeCharacter{016E}{\ringaccent{U}}%
10595   \DeclareUnicodeCharacter{016F}{\ringaccent{u}}%
10596   %
10597   \DeclareUnicodeCharacter{0170}{\H{U}}%
10598   \DeclareUnicodeCharacter{0171}{\H{u}}%
10599   \DeclareUnicodeCharacter{0172}{\ogonek{U}}%
10600   \DeclareUnicodeCharacter{0173}{\ogonek{u}}%
10601   \DeclareUnicodeCharacter{0174}{\^W}%
10602   \DeclareUnicodeCharacter{0175}{\^w}%
10603   \DeclareUnicodeCharacter{0176}{\^Y}%
10604   \DeclareUnicodeCharacter{0177}{\^y}%
10605   \DeclareUnicodeCharacter{0178}{\"Y}%
10606   \DeclareUnicodeCharacter{0179}{\'Z}%
10607   \DeclareUnicodeCharacter{017A}{\'z}%
10608   \DeclareUnicodeCharacter{017B}{\dotaccent{Z}}%
10609   \DeclareUnicodeCharacter{017C}{\dotaccent{z}}%
10610   \DeclareUnicodeCharacter{017D}{\v{Z}}%
10611   \DeclareUnicodeCharacter{017E}{\v{z}}%
10612   \DeclareUnicodeCharacter{017F}{\missingcharmsg{LONG S}}%
10613   %
10614   \DeclareUnicodeCharacter{01C4}{D\v{Z}}%
10615   \DeclareUnicodeCharacter{01C5}{D\v{z}}%
10616   \DeclareUnicodeCharacter{01C6}{d\v{z}}%
10617   \DeclareUnicodeCharacter{01C7}{LJ}%
10618   \DeclareUnicodeCharacter{01C8}{Lj}%
10619   \DeclareUnicodeCharacter{01C9}{lj}%
10620   \DeclareUnicodeCharacter{01CA}{NJ}%
10621   \DeclareUnicodeCharacter{01CB}{Nj}%
10622   \DeclareUnicodeCharacter{01CC}{nj}%
10623   \DeclareUnicodeCharacter{01CD}{\v{A}}%
10624   \DeclareUnicodeCharacter{01CE}{\v{a}}%
10625   \DeclareUnicodeCharacter{01CF}{\v{I}}%
10626   %
10627   \DeclareUnicodeCharacter{01D0}{\v{\dotless{i}}}%
10628   \DeclareUnicodeCharacter{01D1}{\v{O}}%
10629   \DeclareUnicodeCharacter{01D2}{\v{o}}%
10630   \DeclareUnicodeCharacter{01D3}{\v{U}}%
10631   \DeclareUnicodeCharacter{01D4}{\v{u}}%
10632   %
10633   \DeclareUnicodeCharacter{01E2}{\={\AE}}%
10634   \DeclareUnicodeCharacter{01E3}{\={\ae}}%
10635   \DeclareUnicodeCharacter{01E6}{\v{G}}%
10636   \DeclareUnicodeCharacter{01E7}{\v{g}}%
10637   \DeclareUnicodeCharacter{01E8}{\v{K}}%
10638   \DeclareUnicodeCharacter{01E9}{\v{k}}%
10639   %
10640   \DeclareUnicodeCharacter{01F0}{\v{\dotless{j}}}%
10641   \DeclareUnicodeCharacter{01F1}{DZ}%
10642   \DeclareUnicodeCharacter{01F2}{Dz}%
10643   \DeclareUnicodeCharacter{01F3}{dz}%
10644   \DeclareUnicodeCharacter{01F4}{\'G}%
10645   \DeclareUnicodeCharacter{01F5}{\'g}%
10646   \DeclareUnicodeCharacter{01F8}{\`N}%
10647   \DeclareUnicodeCharacter{01F9}{\`n}%
10648   \DeclareUnicodeCharacter{01FC}{\'{\AE}}%
10649   \DeclareUnicodeCharacter{01FD}{\'{\ae}}%
10650   \DeclareUnicodeCharacter{01FE}{\'{\O}}%
10651   \DeclareUnicodeCharacter{01FF}{\'{\o}}%
10652   %
10653   \DeclareUnicodeCharacter{021E}{\v{H}}%
10654   \DeclareUnicodeCharacter{021F}{\v{h}}%
10655   %
10656   \DeclareUnicodeCharacter{0226}{\dotaccent{A}}%
10657   \DeclareUnicodeCharacter{0227}{\dotaccent{a}}%
10658   \DeclareUnicodeCharacter{0228}{\cedilla{E}}%
10659   \DeclareUnicodeCharacter{0229}{\cedilla{e}}%
10660   \DeclareUnicodeCharacter{022E}{\dotaccent{O}}%
10661   \DeclareUnicodeCharacter{022F}{\dotaccent{o}}%
10662   %
10663   \DeclareUnicodeCharacter{0232}{\=Y}%
10664   \DeclareUnicodeCharacter{0233}{\=y}%
10665   \DeclareUnicodeCharacter{0237}{\dotless{j}}%
10666   %
10667   \DeclareUnicodeCharacter{02DB}{\ogonek{ }}%
10668   %
10669   % Greek letters upper case
10670   \DeclareUnicodeCharacter{0391}{{\it A}}%
10671   \DeclareUnicodeCharacter{0392}{{\it B}}%
10672   \DeclareUnicodeCharacter{0393}{\ensuremath{\mit\Gamma}}%
10673   \DeclareUnicodeCharacter{0394}{\ensuremath{\mit\Delta}}%
10674   \DeclareUnicodeCharacter{0395}{{\it E}}%
10675   \DeclareUnicodeCharacter{0396}{{\it Z}}%
10676   \DeclareUnicodeCharacter{0397}{{\it H}}%
10677   \DeclareUnicodeCharacter{0398}{\ensuremath{\mit\Theta}}%
10678   \DeclareUnicodeCharacter{0399}{{\it I}}%
10679   \DeclareUnicodeCharacter{039A}{{\it K}}%
10680   \DeclareUnicodeCharacter{039B}{\ensuremath{\mit\Lambda}}%
10681   \DeclareUnicodeCharacter{039C}{{\it M}}%
10682   \DeclareUnicodeCharacter{039D}{{\it N}}%
10683   \DeclareUnicodeCharacter{039E}{\ensuremath{\mit\Xi}}%
10684   \DeclareUnicodeCharacter{039F}{{\it O}}%
10685   \DeclareUnicodeCharacter{03A0}{\ensuremath{\mit\Pi}}%
10686   \DeclareUnicodeCharacter{03A1}{{\it P}}%
10687   %\DeclareUnicodeCharacter{03A2}{} % none - corresponds to final sigma
10688   \DeclareUnicodeCharacter{03A3}{\ensuremath{\mit\Sigma}}%
10689   \DeclareUnicodeCharacter{03A4}{{\it T}}%
10690   \DeclareUnicodeCharacter{03A5}{\ensuremath{\mit\Upsilon}}%
10691   \DeclareUnicodeCharacter{03A6}{\ensuremath{\mit\Phi}}%
10692   \DeclareUnicodeCharacter{03A7}{{\it X}}%
10693   \DeclareUnicodeCharacter{03A8}{\ensuremath{\mit\Psi}}%
10694   \DeclareUnicodeCharacter{03A9}{\ensuremath{\mit\Omega}}%
10695   %
10696   % Vowels with accents
10697   \DeclareUnicodeCharacter{0390}{\ensuremath{\ddot{\acute\iota}}}%
10698   \DeclareUnicodeCharacter{03AC}{\ensuremath{\acute\alpha}}%
10699   \DeclareUnicodeCharacter{03AD}{\ensuremath{\acute\epsilon}}%
10700   \DeclareUnicodeCharacter{03AE}{\ensuremath{\acute\eta}}%
10701   \DeclareUnicodeCharacter{03AF}{\ensuremath{\acute\iota}}%
10702   \DeclareUnicodeCharacter{03B0}{\ensuremath{\acute{\ddot\upsilon}}}%
10703   %
10704   % Standalone accent
10705   \DeclareUnicodeCharacter{0384}{\ensuremath{\acute{\ }}}%
10706   %
10707   % Greek letters lower case
10708   \DeclareUnicodeCharacter{03B1}{\ensuremath\alpha}%
10709   \DeclareUnicodeCharacter{03B2}{\ensuremath\beta}%
10710   \DeclareUnicodeCharacter{03B3}{\ensuremath\gamma}%
10711   \DeclareUnicodeCharacter{03B4}{\ensuremath\delta}%
10712   \DeclareUnicodeCharacter{03B5}{\ensuremath\epsilon}%
10713   \DeclareUnicodeCharacter{03B6}{\ensuremath\zeta}%
10714   \DeclareUnicodeCharacter{03B7}{\ensuremath\eta}%
10715   \DeclareUnicodeCharacter{03B8}{\ensuremath\theta}%
10716   \DeclareUnicodeCharacter{03B9}{\ensuremath\iota}%
10717   \DeclareUnicodeCharacter{03BA}{\ensuremath\kappa}%
10718   \DeclareUnicodeCharacter{03BB}{\ensuremath\lambda}%
10719   \DeclareUnicodeCharacter{03BC}{\ensuremath\mu}%
10720   \DeclareUnicodeCharacter{03BD}{\ensuremath\nu}%
10721   \DeclareUnicodeCharacter{03BE}{\ensuremath\xi}%
10722   \DeclareUnicodeCharacter{03BF}{{\it o}}% omicron
10723   \DeclareUnicodeCharacter{03C0}{\ensuremath\pi}%
10724   \DeclareUnicodeCharacter{03C1}{\ensuremath\rho}%
10725   \DeclareUnicodeCharacter{03C2}{\ensuremath\varsigma}%
10726   \DeclareUnicodeCharacter{03C3}{\ensuremath\sigma}%
10727   \DeclareUnicodeCharacter{03C4}{\ensuremath\tau}%
10728   \DeclareUnicodeCharacter{03C5}{\ensuremath\upsilon}%
10729   \DeclareUnicodeCharacter{03C6}{\ensuremath\phi}%
10730   \DeclareUnicodeCharacter{03C7}{\ensuremath\chi}%
10731   \DeclareUnicodeCharacter{03C8}{\ensuremath\psi}%
10732   \DeclareUnicodeCharacter{03C9}{\ensuremath\omega}%
10733   %
10734   % More Greek vowels with accents
10735   \DeclareUnicodeCharacter{03CA}{\ensuremath{\ddot\iota}}%
10736   \DeclareUnicodeCharacter{03CB}{\ensuremath{\ddot\upsilon}}%
10737   \DeclareUnicodeCharacter{03CC}{\ensuremath{\acute o}}%
10738   \DeclareUnicodeCharacter{03CD}{\ensuremath{\acute\upsilon}}%
10739   \DeclareUnicodeCharacter{03CE}{\ensuremath{\acute\omega}}%
10740   %
10741   % Variant Greek letters
10742   \DeclareUnicodeCharacter{03D1}{\ensuremath\vartheta}%
10743   \DeclareUnicodeCharacter{03D6}{\ensuremath\varpi}%
10744   \DeclareUnicodeCharacter{03F1}{\ensuremath\varrho}%
10745   %
10746   \DeclareUnicodeCharacter{1E02}{\dotaccent{B}}%
10747   \DeclareUnicodeCharacter{1E03}{\dotaccent{b}}%
10748   \DeclareUnicodeCharacter{1E04}{\udotaccent{B}}%
10749   \DeclareUnicodeCharacter{1E05}{\udotaccent{b}}%
10750   \DeclareUnicodeCharacter{1E06}{\ubaraccent{B}}%
10751   \DeclareUnicodeCharacter{1E07}{\ubaraccent{b}}%
10752   \DeclareUnicodeCharacter{1E0A}{\dotaccent{D}}%
10753   \DeclareUnicodeCharacter{1E0B}{\dotaccent{d}}%
10754   \DeclareUnicodeCharacter{1E0C}{\udotaccent{D}}%
10755   \DeclareUnicodeCharacter{1E0D}{\udotaccent{d}}%
10756   \DeclareUnicodeCharacter{1E0E}{\ubaraccent{D}}%
10757   \DeclareUnicodeCharacter{1E0F}{\ubaraccent{d}}%
10758   %
10759   \DeclareUnicodeCharacter{1E1E}{\dotaccent{F}}%
10760   \DeclareUnicodeCharacter{1E1F}{\dotaccent{f}}%
10761   %
10762   \DeclareUnicodeCharacter{1E20}{\=G}%
10763   \DeclareUnicodeCharacter{1E21}{\=g}%
10764   \DeclareUnicodeCharacter{1E22}{\dotaccent{H}}%
10765   \DeclareUnicodeCharacter{1E23}{\dotaccent{h}}%
10766   \DeclareUnicodeCharacter{1E24}{\udotaccent{H}}%
10767   \DeclareUnicodeCharacter{1E25}{\udotaccent{h}}%
10768   \DeclareUnicodeCharacter{1E26}{\"H}%
10769   \DeclareUnicodeCharacter{1E27}{\"h}%
10770   %
10771   \DeclareUnicodeCharacter{1E30}{\'K}%
10772   \DeclareUnicodeCharacter{1E31}{\'k}%
10773   \DeclareUnicodeCharacter{1E32}{\udotaccent{K}}%
10774   \DeclareUnicodeCharacter{1E33}{\udotaccent{k}}%
10775   \DeclareUnicodeCharacter{1E34}{\ubaraccent{K}}%
10776   \DeclareUnicodeCharacter{1E35}{\ubaraccent{k}}%
10777   \DeclareUnicodeCharacter{1E36}{\udotaccent{L}}%
10778   \DeclareUnicodeCharacter{1E37}{\udotaccent{l}}%
10779   \DeclareUnicodeCharacter{1E3A}{\ubaraccent{L}}%
10780   \DeclareUnicodeCharacter{1E3B}{\ubaraccent{l}}%
10781   \DeclareUnicodeCharacter{1E3E}{\'M}%
10782   \DeclareUnicodeCharacter{1E3F}{\'m}%
10783   %
10784   \DeclareUnicodeCharacter{1E40}{\dotaccent{M}}%
10785   \DeclareUnicodeCharacter{1E41}{\dotaccent{m}}%
10786   \DeclareUnicodeCharacter{1E42}{\udotaccent{M}}%
10787   \DeclareUnicodeCharacter{1E43}{\udotaccent{m}}%
10788   \DeclareUnicodeCharacter{1E44}{\dotaccent{N}}%
10789   \DeclareUnicodeCharacter{1E45}{\dotaccent{n}}%
10790   \DeclareUnicodeCharacter{1E46}{\udotaccent{N}}%
10791   \DeclareUnicodeCharacter{1E47}{\udotaccent{n}}%
10792   \DeclareUnicodeCharacter{1E48}{\ubaraccent{N}}%
10793   \DeclareUnicodeCharacter{1E49}{\ubaraccent{n}}%
10794   %
10795   \DeclareUnicodeCharacter{1E54}{\'P}%
10796   \DeclareUnicodeCharacter{1E55}{\'p}%
10797   \DeclareUnicodeCharacter{1E56}{\dotaccent{P}}%
10798   \DeclareUnicodeCharacter{1E57}{\dotaccent{p}}%
10799   \DeclareUnicodeCharacter{1E58}{\dotaccent{R}}%
10800   \DeclareUnicodeCharacter{1E59}{\dotaccent{r}}%
10801   \DeclareUnicodeCharacter{1E5A}{\udotaccent{R}}%
10802   \DeclareUnicodeCharacter{1E5B}{\udotaccent{r}}%
10803   \DeclareUnicodeCharacter{1E5E}{\ubaraccent{R}}%
10804   \DeclareUnicodeCharacter{1E5F}{\ubaraccent{r}}%
10805   %
10806   \DeclareUnicodeCharacter{1E60}{\dotaccent{S}}%
10807   \DeclareUnicodeCharacter{1E61}{\dotaccent{s}}%
10808   \DeclareUnicodeCharacter{1E62}{\udotaccent{S}}%
10809   \DeclareUnicodeCharacter{1E63}{\udotaccent{s}}%
10810   \DeclareUnicodeCharacter{1E6A}{\dotaccent{T}}%
10811   \DeclareUnicodeCharacter{1E6B}{\dotaccent{t}}%
10812   \DeclareUnicodeCharacter{1E6C}{\udotaccent{T}}%
10813   \DeclareUnicodeCharacter{1E6D}{\udotaccent{t}}%
10814   \DeclareUnicodeCharacter{1E6E}{\ubaraccent{T}}%
10815   \DeclareUnicodeCharacter{1E6F}{\ubaraccent{t}}%
10816   %
10817   \DeclareUnicodeCharacter{1E7C}{\~V}%
10818   \DeclareUnicodeCharacter{1E7D}{\~v}%
10819   \DeclareUnicodeCharacter{1E7E}{\udotaccent{V}}%
10820   \DeclareUnicodeCharacter{1E7F}{\udotaccent{v}}%
10821   %
10822   \DeclareUnicodeCharacter{1E80}{\`W}%
10823   \DeclareUnicodeCharacter{1E81}{\`w}%
10824   \DeclareUnicodeCharacter{1E82}{\'W}%
10825   \DeclareUnicodeCharacter{1E83}{\'w}%
10826   \DeclareUnicodeCharacter{1E84}{\"W}%
10827   \DeclareUnicodeCharacter{1E85}{\"w}%
10828   \DeclareUnicodeCharacter{1E86}{\dotaccent{W}}%
10829   \DeclareUnicodeCharacter{1E87}{\dotaccent{w}}%
10830   \DeclareUnicodeCharacter{1E88}{\udotaccent{W}}%
10831   \DeclareUnicodeCharacter{1E89}{\udotaccent{w}}%
10832   \DeclareUnicodeCharacter{1E8A}{\dotaccent{X}}%
10833   \DeclareUnicodeCharacter{1E8B}{\dotaccent{x}}%
10834   \DeclareUnicodeCharacter{1E8C}{\"X}%
10835   \DeclareUnicodeCharacter{1E8D}{\"x}%
10836   \DeclareUnicodeCharacter{1E8E}{\dotaccent{Y}}%
10837   \DeclareUnicodeCharacter{1E8F}{\dotaccent{y}}%
10838   %
10839   \DeclareUnicodeCharacter{1E90}{\^Z}%
10840   \DeclareUnicodeCharacter{1E91}{\^z}%
10841   \DeclareUnicodeCharacter{1E92}{\udotaccent{Z}}%
10842   \DeclareUnicodeCharacter{1E93}{\udotaccent{z}}%
10843   \DeclareUnicodeCharacter{1E94}{\ubaraccent{Z}}%
10844   \DeclareUnicodeCharacter{1E95}{\ubaraccent{z}}%
10845   \DeclareUnicodeCharacter{1E96}{\ubaraccent{h}}%
10846   \DeclareUnicodeCharacter{1E97}{\"t}%
10847   \DeclareUnicodeCharacter{1E98}{\ringaccent{w}}%
10848   \DeclareUnicodeCharacter{1E99}{\ringaccent{y}}%
10849   %
10850   \DeclareUnicodeCharacter{1EA0}{\udotaccent{A}}%
10851   \DeclareUnicodeCharacter{1EA1}{\udotaccent{a}}%
10852   %
10853   \DeclareUnicodeCharacter{1EB8}{\udotaccent{E}}%
10854   \DeclareUnicodeCharacter{1EB9}{\udotaccent{e}}%
10855   \DeclareUnicodeCharacter{1EBC}{\~E}%
10856   \DeclareUnicodeCharacter{1EBD}{\~e}%
10857   %
10858   \DeclareUnicodeCharacter{1ECA}{\udotaccent{I}}%
10859   \DeclareUnicodeCharacter{1ECB}{\udotaccent{i}}%
10860   \DeclareUnicodeCharacter{1ECC}{\udotaccent{O}}%
10861   \DeclareUnicodeCharacter{1ECD}{\udotaccent{o}}%
10862   %
10863   \DeclareUnicodeCharacter{1EE4}{\udotaccent{U}}%
10864   \DeclareUnicodeCharacter{1EE5}{\udotaccent{u}}%
10865   %
10866   \DeclareUnicodeCharacter{1EF2}{\`Y}%
10867   \DeclareUnicodeCharacter{1EF3}{\`y}%
10868   \DeclareUnicodeCharacter{1EF4}{\udotaccent{Y}}%
10869   %
10870   \DeclareUnicodeCharacter{1EF8}{\~Y}%
10871   \DeclareUnicodeCharacter{1EF9}{\~y}%
10872   %
10873   % Punctuation
10874   \DeclareUnicodeCharacter{2013}{--}%
10875   \DeclareUnicodeCharacter{2014}{---}%
10876   \DeclareUnicodeCharacter{2018}{\quoteleft}%
10877   \DeclareUnicodeCharacter{2019}{\quoteright}%
10878   \DeclareUnicodeCharacter{201A}{\quotesinglbase}%
10879   \DeclareUnicodeCharacter{201C}{\quotedblleft}%
10880   \DeclareUnicodeCharacter{201D}{\quotedblright}%
10881   \DeclareUnicodeCharacter{201E}{\quotedblbase}%
10882   \DeclareUnicodeCharacter{2020}{\ensuremath\dagger}%
10883   \DeclareUnicodeCharacter{2021}{\ensuremath\ddagger}%
10884   \DeclareUnicodeCharacter{2022}{\bullet}%
10885   \DeclareUnicodeCharacter{202F}{\thinspace}%
10886   \DeclareUnicodeCharacter{2026}{\dots}%
10887   \DeclareUnicodeCharacter{2039}{\guilsinglleft}%
10888   \DeclareUnicodeCharacter{203A}{\guilsinglright}%
10889   %
10890   \DeclareUnicodeCharacter{20AC}{\euro}%
10891   %
10892   \DeclareUnicodeCharacter{2192}{\expansion}%
10893   \DeclareUnicodeCharacter{21D2}{\result}%
10894   %
10895   % Mathematical symbols
10896   \DeclareUnicodeCharacter{2200}{\ensuremath\forall}%
10897   \DeclareUnicodeCharacter{2203}{\ensuremath\exists}%
10898   \DeclareUnicodeCharacter{2208}{\ensuremath\in}%
10899   \DeclareUnicodeCharacter{2212}{\minus}%
10900   \DeclareUnicodeCharacter{2217}{\ast}%
10901   \DeclareUnicodeCharacter{221E}{\ensuremath\infty}%
10902   \DeclareUnicodeCharacter{2225}{\ensuremath\parallel}%
10903   \DeclareUnicodeCharacter{2227}{\ensuremath\wedge}%
10904   \DeclareUnicodeCharacter{2229}{\ensuremath\cap}%
10905   \DeclareUnicodeCharacter{2261}{\equiv}%
10906   \DeclareUnicodeCharacter{2264}{\ensuremath\leq}%
10907   \DeclareUnicodeCharacter{2265}{\ensuremath\geq}%
10908   \DeclareUnicodeCharacter{2282}{\ensuremath\subset}%
10909   \DeclareUnicodeCharacter{2287}{\ensuremath\supseteq}%
10910   %
10911   \DeclareUnicodeCharacter{2016}{\ensuremath\Vert}%
10912   \DeclareUnicodeCharacter{2032}{\ensuremath\prime}%
10913   \DeclareUnicodeCharacter{210F}{\ensuremath\hbar}%
10914   \DeclareUnicodeCharacter{2111}{\ensuremath\Im}%
10915   \DeclareUnicodeCharacter{2113}{\ensuremath\ell}%
10916   \DeclareUnicodeCharacter{2118}{\ensuremath\wp}%
10917   \DeclareUnicodeCharacter{211C}{\ensuremath\Re}%
10918   \DeclareUnicodeCharacter{2127}{\ensuremath\mho}%
10919   \DeclareUnicodeCharacter{2135}{\ensuremath\aleph}%
10920   \DeclareUnicodeCharacter{2190}{\ensuremath\leftarrow}%
10921   \DeclareUnicodeCharacter{2191}{\ensuremath\uparrow}%
10922   \DeclareUnicodeCharacter{2193}{\ensuremath\downarrow}%
10923   \DeclareUnicodeCharacter{2194}{\ensuremath\leftrightarrow}%
10924   \DeclareUnicodeCharacter{2195}{\ensuremath\updownarrow}%
10925   \DeclareUnicodeCharacter{2196}{\ensuremath\nwarrow}%
10926   \DeclareUnicodeCharacter{2197}{\ensuremath\nearrow}%
10927   \DeclareUnicodeCharacter{2198}{\ensuremath\searrow}%
10928   \DeclareUnicodeCharacter{2199}{\ensuremath\swarrow}%
10929   \DeclareUnicodeCharacter{21A6}{\ensuremath\mapsto}%
10930   \DeclareUnicodeCharacter{21A9}{\ensuremath\hookleftarrow}%
10931   \DeclareUnicodeCharacter{21AA}{\ensuremath\hookrightarrow}%
10932   \DeclareUnicodeCharacter{21BC}{\ensuremath\leftharpoonup}%
10933   \DeclareUnicodeCharacter{21BD}{\ensuremath\leftharpoondown}%
10934   \DeclareUnicodeCharacter{21BE}{\ensuremath\upharpoonright}%
10935   \DeclareUnicodeCharacter{21C0}{\ensuremath\rightharpoonup}%
10936   \DeclareUnicodeCharacter{21C1}{\ensuremath\rightharpoondown}%
10937   \DeclareUnicodeCharacter{21CC}{\ensuremath\rightleftharpoons}%
10938   \DeclareUnicodeCharacter{21D0}{\ensuremath\Leftarrow}%
10939   \DeclareUnicodeCharacter{21D1}{\ensuremath\Uparrow}%
10940   \DeclareUnicodeCharacter{21D3}{\ensuremath\Downarrow}%
10941   \DeclareUnicodeCharacter{21D4}{\ensuremath\Leftrightarrow}%
10942   \DeclareUnicodeCharacter{21D5}{\ensuremath\Updownarrow}%
10943   \DeclareUnicodeCharacter{21DD}{\ensuremath\leadsto}%
10944   \DeclareUnicodeCharacter{2201}{\ensuremath\complement}%
10945   \DeclareUnicodeCharacter{2202}{\ensuremath\partial}%
10946   \DeclareUnicodeCharacter{2205}{\ensuremath\emptyset}%
10947   \DeclareUnicodeCharacter{2207}{\ensuremath\nabla}%
10948   \DeclareUnicodeCharacter{2209}{\ensuremath\notin}%
10949   \DeclareUnicodeCharacter{220B}{\ensuremath\owns}%
10950   \DeclareUnicodeCharacter{220F}{\ensuremath\prod}%
10951   \DeclareUnicodeCharacter{2210}{\ensuremath\coprod}%
10952   \DeclareUnicodeCharacter{2211}{\ensuremath\sum}%
10953   \DeclareUnicodeCharacter{2213}{\ensuremath\mp}%
10954   \DeclareUnicodeCharacter{2218}{\ensuremath\circ}%
10955   \DeclareUnicodeCharacter{221A}{\ensuremath\surd}%
10956   \DeclareUnicodeCharacter{221D}{\ensuremath\propto}%
10957   \DeclareUnicodeCharacter{2220}{\ensuremath\angle}%
10958   \DeclareUnicodeCharacter{2223}{\ensuremath\mid}%
10959   \DeclareUnicodeCharacter{2228}{\ensuremath\vee}%
10960   \DeclareUnicodeCharacter{222A}{\ensuremath\cup}%
10961   \DeclareUnicodeCharacter{222B}{\ensuremath\smallint}%
10962   \DeclareUnicodeCharacter{222E}{\ensuremath\oint}%
10963   \DeclareUnicodeCharacter{223C}{\ensuremath\sim}%
10964   \DeclareUnicodeCharacter{2240}{\ensuremath\wr}%
10965   \DeclareUnicodeCharacter{2243}{\ensuremath\simeq}%
10966   \DeclareUnicodeCharacter{2245}{\ensuremath\cong}%
10967   \DeclareUnicodeCharacter{2248}{\ensuremath\approx}%
10968   \DeclareUnicodeCharacter{224D}{\ensuremath\asymp}%
10969   \DeclareUnicodeCharacter{2250}{\ensuremath\doteq}%
10970   \DeclareUnicodeCharacter{2260}{\ensuremath\neq}%
10971   \DeclareUnicodeCharacter{226A}{\ensuremath\ll}%
10972   \DeclareUnicodeCharacter{226B}{\ensuremath\gg}%
10973   \DeclareUnicodeCharacter{227A}{\ensuremath\prec}%
10974   \DeclareUnicodeCharacter{227B}{\ensuremath\succ}%
10975   \DeclareUnicodeCharacter{2283}{\ensuremath\supset}%
10976   \DeclareUnicodeCharacter{2286}{\ensuremath\subseteq}%
10977   \DeclareUnicodeCharacter{228E}{\ensuremath\uplus}%
10978   \DeclareUnicodeCharacter{228F}{\ensuremath\sqsubset}%
10979   \DeclareUnicodeCharacter{2290}{\ensuremath\sqsupset}%
10980   \DeclareUnicodeCharacter{2291}{\ensuremath\sqsubseteq}%
10981   \DeclareUnicodeCharacter{2292}{\ensuremath\sqsupseteq}%
10982   \DeclareUnicodeCharacter{2293}{\ensuremath\sqcap}%
10983   \DeclareUnicodeCharacter{2294}{\ensuremath\sqcup}%
10984   \DeclareUnicodeCharacter{2295}{\ensuremath\oplus}%
10985   \DeclareUnicodeCharacter{2296}{\ensuremath\ominus}%
10986   \DeclareUnicodeCharacter{2297}{\ensuremath\otimes}%
10987   \DeclareUnicodeCharacter{2298}{\ensuremath\oslash}%
10988   \DeclareUnicodeCharacter{2299}{\ensuremath\odot}%
10989   \DeclareUnicodeCharacter{22A2}{\ensuremath\vdash}%
10990   \DeclareUnicodeCharacter{22A3}{\ensuremath\dashv}%
10991   \DeclareUnicodeCharacter{22A4}{\ensuremath\ptextop}%
10992   \DeclareUnicodeCharacter{22A5}{\ensuremath\bot}%
10993   \DeclareUnicodeCharacter{22A8}{\ensuremath\models}%
10994   \DeclareUnicodeCharacter{22B4}{\ensuremath\unlhd}%
10995   \DeclareUnicodeCharacter{22B5}{\ensuremath\unrhd}%
10996   \DeclareUnicodeCharacter{22C0}{\ensuremath\bigwedge}%
10997   \DeclareUnicodeCharacter{22C1}{\ensuremath\bigvee}%
10998   \DeclareUnicodeCharacter{22C2}{\ensuremath\bigcap}%
10999   \DeclareUnicodeCharacter{22C3}{\ensuremath\bigcup}%
11000   \DeclareUnicodeCharacter{22C4}{\ensuremath\diamond}%
11001   \DeclareUnicodeCharacter{22C5}{\ensuremath\cdot}%
11002   \DeclareUnicodeCharacter{22C6}{\ensuremath\star}%
11003   \DeclareUnicodeCharacter{22C8}{\ensuremath\bowtie}%
11004   \DeclareUnicodeCharacter{2308}{\ensuremath\lceil}%
11005   \DeclareUnicodeCharacter{2309}{\ensuremath\rceil}%
11006   \DeclareUnicodeCharacter{230A}{\ensuremath\lfloor}%
11007   \DeclareUnicodeCharacter{230B}{\ensuremath\rfloor}%
11008   \DeclareUnicodeCharacter{2322}{\ensuremath\frown}%
11009   \DeclareUnicodeCharacter{2323}{\ensuremath\smile}%
11010   %
11011   \DeclareUnicodeCharacter{25A1}{\ensuremath\Box}%
11012   \DeclareUnicodeCharacter{25B3}{\ensuremath\triangle}%
11013   \DeclareUnicodeCharacter{25B7}{\ensuremath\triangleright}%
11014   \DeclareUnicodeCharacter{25BD}{\ensuremath\bigtriangledown}%
11015   \DeclareUnicodeCharacter{25C1}{\ensuremath\triangleleft}%
11016   \DeclareUnicodeCharacter{25C7}{\ensuremath\Diamond}%
11017   \DeclareUnicodeCharacter{2660}{\ensuremath\spadesuit}%
11018   \DeclareUnicodeCharacter{2661}{\ensuremath\heartsuit}%
11019   \DeclareUnicodeCharacter{2662}{\ensuremath\diamondsuit}%
11020   \DeclareUnicodeCharacter{2663}{\ensuremath\clubsuit}%
11021   \DeclareUnicodeCharacter{266D}{\ensuremath\flat}%
11022   \DeclareUnicodeCharacter{266E}{\ensuremath\natural}%
11023   \DeclareUnicodeCharacter{266F}{\ensuremath\sharp}%
11024   \DeclareUnicodeCharacter{26AA}{\ensuremath\bigcirc}%
11025   \DeclareUnicodeCharacter{27B9}{\ensuremath\rangle}%
11026   \DeclareUnicodeCharacter{27C2}{\ensuremath\perp}%
11027   \DeclareUnicodeCharacter{27E8}{\ensuremath\langle}%
11028   \DeclareUnicodeCharacter{27F5}{\ensuremath\longleftarrow}%
11029   \DeclareUnicodeCharacter{27F6}{\ensuremath\longrightarrow}%
11030   \DeclareUnicodeCharacter{27F7}{\ensuremath\longleftrightarrow}%
11031   \DeclareUnicodeCharacter{27FC}{\ensuremath\longmapsto}%
11032   \DeclareUnicodeCharacter{29F5}{\ensuremath\setminus}%
11033   \DeclareUnicodeCharacter{2A00}{\ensuremath\bigodot}%
11034   \DeclareUnicodeCharacter{2A01}{\ensuremath\bigoplus}%
11035   \DeclareUnicodeCharacter{2A02}{\ensuremath\bigotimes}%
11036   \DeclareUnicodeCharacter{2A04}{\ensuremath\biguplus}%
11037   \DeclareUnicodeCharacter{2A06}{\ensuremath\bigsqcup}%
11038   \DeclareUnicodeCharacter{2A1D}{\ensuremath\Join}%
11039   \DeclareUnicodeCharacter{2A3F}{\ensuremath\amalg}%
11040   \DeclareUnicodeCharacter{2AAF}{\ensuremath\preceq}%
11041   \DeclareUnicodeCharacter{2AB0}{\ensuremath\succeq}%
11042   %
11043   \global\mathchardef\checkmark="1370% actually the square root sign
11044   \DeclareUnicodeCharacter{2713}{\ensuremath\checkmark}%
11045 }% end of \unicodechardefs
11046
11047 % UTF-8 byte sequence (pdfTeX) definitions (replacing and @U command)
11048 % It makes the setting that replace UTF-8 byte sequence.
11049 \def\utfeightchardefs{%
11050   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterUTFviii
11051   \unicodechardefs
11052 }
11053
11054 % Whether the active definitions of non-ASCII characters expand to
11055 % non-active tokens with the same character code.  This is used to
11056 % write characters literally, instead of using active definitions for
11057 % printing the correct glyphs.
11058 \newif\ifpassthroughchars
11059 \passthroughcharsfalse
11060
11061 % For native Unicode (XeTeX and LuaTeX)
11062 % Definition macro to replace / pass-through the Unicode character
11063 %
11064 \def\DeclareUnicodeCharacterNative#1#2{%
11065   \catcode"#1=\active
11066   \def\dodeclareunicodecharacternative##1##2##3{%
11067     \begingroup
11068       \uccode`\~="##2\relax
11069       \uppercase{\gdef~}{%
11070         \ifpassthroughchars
11071           ##1%
11072         \else
11073           ##3%
11074         \fi
11075       }
11076     \endgroup
11077   }
11078   \begingroup
11079     \uccode`\.="#1\relax
11080     \uppercase{\def\UTFNativeTmp{.}}%
11081     \expandafter\dodeclareunicodecharacternative\UTFNativeTmp{#1}{#2}%
11082   \endgroup
11083 }
11084
11085 % Native Unicode (XeTeX and LuaTeX) character replacing definitions
11086 % It makes the setting that replace the Unicode characters.
11087 \def\nativeunicodechardefs{%
11088   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNative
11089   \unicodechardefs
11090 }
11091
11092 % For native Unicode (XeTeX and LuaTeX).  Make the character token expand
11093 % to the sequences given in \unicodechardefs for printing.
11094 \def\DeclareUnicodeCharacterNativeAtU#1#2{%
11095   \def\UTFAtUTmp{#2}
11096   \expandafter\globallet\csname uni:#1\endcsname \UTFAtUTmp
11097 }
11098
11099 % Native Unicode (XeTeX and LuaTeX) @U command definitions
11100 \def\nativeunicodechardefsatu{%
11101   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNativeAtU
11102   \unicodechardefs
11103 }
11104
11105 % US-ASCII character definitions.
11106 \def\asciichardefs{% nothing need be done
11107    \relax
11108 }
11109
11110 % define all the unicode characters we know about, for the sake of @U.
11111 \iftxinativeunicodecapable
11112   \nativeunicodechardefsatu
11113 \else
11114   \utfeightchardefs
11115 \fi
11116
11117
11118 % Make non-ASCII characters printable again for compatibility with
11119 % existing Texinfo documents that may use them, even without declaring a
11120 % document encoding.
11121 %
11122 \setnonasciicharscatcode \other
11123
11124
11125 \message{formatting,}
11126
11127 \newdimen\defaultparindent \defaultparindent = 15pt
11128
11129 \chapheadingskip = 15pt plus 4pt minus 2pt
11130 \secheadingskip = 12pt plus 3pt minus 2pt
11131 \subsecheadingskip = 9pt plus 2pt minus 2pt
11132
11133 % Prevent underfull vbox error messages.
11134 \vbadness = 10000
11135
11136 % Don't be very finicky about underfull hboxes, either.
11137 \hbadness = 6666
11138
11139 % Following George Bush, get rid of widows and orphans.
11140 \widowpenalty=10000
11141 \clubpenalty=10000
11142
11143 % Use TeX 3.0's \emergencystretch to help line breaking, but if we're
11144 % using an old version of TeX, don't do anything.  We want the amount of
11145 % stretch added to depend on the line length, hence the dependence on
11146 % \hsize.  We call this whenever the paper size is set.
11147 %
11148 \def\setemergencystretch{%
11149   \ifx\emergencystretch\thisisundefined
11150     % Allow us to assign to \emergencystretch anyway.
11151     \def\emergencystretch{\dimen0}%
11152   \else
11153     \emergencystretch = .15\hsize
11154   \fi
11155 }
11156
11157 % Parameters in order: 1) textheight; 2) textwidth;
11158 % 3) voffset; 4) hoffset; 5) binding offset; 6) topskip;
11159 % 7) physical page height; 8) physical page width.
11160 %
11161 % We also call \setleading{\textleading}, so the caller should define
11162 % \textleading.  The caller should also set \parskip.
11163 %
11164 \def\internalpagesizes#1#2#3#4#5#6#7#8{%
11165   \voffset = #3\relax
11166   \topskip = #6\relax
11167   \splittopskip = \topskip
11168   %
11169   \vsize = #1\relax
11170   \advance\vsize by \topskip
11171   \outervsize = \vsize
11172   \advance\outervsize by 2\topandbottommargin
11173   \txipageheight = \vsize
11174   %
11175   \hsize = #2\relax
11176   \outerhsize = \hsize
11177   \advance\outerhsize by 0.5in
11178   \txipagewidth = \hsize
11179   %
11180   \normaloffset = #4\relax
11181   \bindingoffset = #5\relax
11182   %
11183   \ifpdf
11184     \pdfpageheight #7\relax
11185     \pdfpagewidth #8\relax
11186     % if we don't reset these, they will remain at "1 true in" of
11187     % whatever layout pdftex was dumped with.
11188     \pdfhorigin = 1 true in
11189     \pdfvorigin = 1 true in
11190   \else
11191     \ifx\XeTeXrevision\thisisundefined
11192     \else
11193       \pdfpageheight #7\relax
11194       \pdfpagewidth #8\relax
11195       % XeTeX does not have \pdfhorigin and \pdfvorigin.
11196     \fi
11197   \fi
11198   %
11199   \setleading{\textleading}
11200   %
11201   \parindent = \defaultparindent
11202   \setemergencystretch
11203 }
11204
11205 % @letterpaper (the default).
11206 \def\letterpaper{{\globaldefs = 1
11207   \parskip = 3pt plus 2pt minus 1pt
11208   \textleading = 13.2pt
11209   %
11210   % If page is nothing but text, make it come out even.
11211   \internalpagesizes{607.2pt}{6in}% that's 46 lines
11212                     {\voffset}{.25in}%
11213                     {\bindingoffset}{36pt}%
11214                     {11in}{8.5in}%
11215 }}
11216
11217 % Use @smallbook to reset parameters for 7x9.25 trim size.
11218 \def\smallbook{{\globaldefs = 1
11219   \parskip = 2pt plus 1pt
11220   \textleading = 12pt
11221   %
11222   \internalpagesizes{7.5in}{5in}%
11223                     {-.2in}{0in}%
11224                     {\bindingoffset}{16pt}%
11225                     {9.25in}{7in}%
11226   %
11227   \lispnarrowing = 0.3in
11228   \tolerance = 700
11229   \hfuzz = 1pt
11230   \contentsrightmargin = 0pt
11231   \defbodyindent = .5cm
11232 }}
11233
11234 % Use @smallerbook to reset parameters for 6x9 trim size.
11235 % (Just testing, parameters still in flux.)
11236 \def\smallerbook{{\globaldefs = 1
11237   \parskip = 1.5pt plus 1pt
11238   \textleading = 12pt
11239   %
11240   \internalpagesizes{7.4in}{4.8in}%
11241                     {-.2in}{-.4in}%
11242                     {0pt}{14pt}%
11243                     {9in}{6in}%
11244   %
11245   \lispnarrowing = 0.25in
11246   \tolerance = 700
11247   \hfuzz = 1pt
11248   \contentsrightmargin = 0pt
11249   \defbodyindent = .4cm
11250 }}
11251
11252 % Use @afourpaper to print on European A4 paper.
11253 \def\afourpaper{{\globaldefs = 1
11254   \parskip = 3pt plus 2pt minus 1pt
11255   \textleading = 13.2pt
11256   %
11257   % Double-side printing via postscript on Laserjet 4050
11258   % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
11259   % To change the settings for a different printer or situation, adjust
11260   % \normaloffset until the front-side and back-side texts align.  Then
11261   % do the same for \bindingoffset.  You can set these for testing in
11262   % your texinfo source file like this:
11263   % @tex
11264   % \global\normaloffset = -6mm
11265   % \global\bindingoffset = 10mm
11266   % @end tex
11267   \internalpagesizes{673.2pt}{160mm}% that's 51 lines
11268                     {\voffset}{\hoffset}%
11269                     {\bindingoffset}{44pt}%
11270                     {297mm}{210mm}%
11271   %
11272   \tolerance = 700
11273   \hfuzz = 1pt
11274   \contentsrightmargin = 0pt
11275   \defbodyindent = 5mm
11276 }}
11277
11278 % Use @afivepaper to print on European A5 paper.
11279 % From romildo@urano.iceb.ufop.br, 2 July 2000.
11280 % He also recommends making @example and @lisp be small.
11281 \def\afivepaper{{\globaldefs = 1
11282   \parskip = 2pt plus 1pt minus 0.1pt
11283   \textleading = 12.5pt
11284   %
11285   \internalpagesizes{160mm}{120mm}%
11286                     {\voffset}{\hoffset}%
11287                     {\bindingoffset}{8pt}%
11288                     {210mm}{148mm}%
11289   %
11290   \lispnarrowing = 0.2in
11291   \tolerance = 800
11292   \hfuzz = 1.2pt
11293   \contentsrightmargin = 0pt
11294   \defbodyindent = 2mm
11295   \tableindent = 12mm
11296 }}
11297
11298 % A specific text layout, 24x15cm overall, intended for A4 paper.
11299 \def\afourlatex{{\globaldefs = 1
11300   \afourpaper
11301   \internalpagesizes{237mm}{150mm}%
11302                     {\voffset}{4.6mm}%
11303                     {\bindingoffset}{7mm}%
11304                     {297mm}{210mm}%
11305   %
11306   % Must explicitly reset to 0 because we call \afourpaper.
11307   \globaldefs = 0
11308 }}
11309
11310 % Use @afourwide to print on A4 paper in landscape format.
11311 \def\afourwide{{\globaldefs = 1
11312   \afourpaper
11313   \internalpagesizes{241mm}{165mm}%
11314                     {\voffset}{-2.95mm}%
11315                     {\bindingoffset}{7mm}%
11316                     {297mm}{210mm}%
11317   \globaldefs = 0
11318 }}
11319
11320 % @pagesizes TEXTHEIGHT[,TEXTWIDTH]
11321 % Perhaps we should allow setting the margins, \topskip, \parskip,
11322 % and/or leading, also. Or perhaps we should compute them somehow.
11323 %
11324 \parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
11325 \def\pagesizesyyy#1,#2,#3\finish{{%
11326   \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
11327   \globaldefs = 1
11328   %
11329   \parskip = 3pt plus 2pt minus 1pt
11330   \setleading{\textleading}%
11331   %
11332   \dimen0 = #1\relax
11333   \advance\dimen0 by \voffset
11334   %
11335   \dimen2 = \hsize
11336   \advance\dimen2 by \normaloffset
11337   %
11338   \internalpagesizes{#1}{\hsize}%
11339                     {\voffset}{\normaloffset}%
11340                     {\bindingoffset}{44pt}%
11341                     {\dimen0}{\dimen2}%
11342 }}
11343
11344 % Set default to letter.
11345 %
11346 \letterpaper
11347
11348
11349 \message{and turning on texinfo input format.}
11350
11351 \def^^L{\par} % remove \outer, so ^L can appear in an @comment
11352
11353 % DEL is a comment character, in case @c does not suffice.
11354 \catcode`\^^? = 14
11355
11356 % Define macros to output various characters with catcode for normal text.
11357 \catcode`\"=\other \def\normaldoublequote{"}
11358 \catcode`\$=\other \def\normaldollar{$}%$ font-lock fix
11359 \catcode`\+=\other \def\normalplus{+}
11360 \catcode`\<=\other \def\normalless{<}
11361 \catcode`\>=\other \def\normalgreater{>}
11362 \catcode`\^=\other \def\normalcaret{^}
11363 \catcode`\_=\other \def\normalunderscore{_}
11364 \catcode`\|=\other \def\normalverticalbar{|}
11365 \catcode`\~=\other \def\normaltilde{~}
11366
11367 % This macro is used to make a character print one way in \tt
11368 % (where it can probably be output as-is), and another way in other fonts,
11369 % where something hairier probably needs to be done.
11370 %
11371 % #1 is what to print if we are indeed using \tt; #2 is what to print
11372 % otherwise.  Since all the Computer Modern typewriter fonts have zero
11373 % interword stretch (and shrink), and it is reasonable to expect all
11374 % typewriter fonts to have this, we can check that font parameter.
11375 %
11376 \def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
11377
11378 % Same as above, but check for italic font.  Actually this also catches
11379 % non-italic slanted fonts since it is impossible to distinguish them from
11380 % italic fonts.  But since this is only used by $ and it uses \sl anyway
11381 % this is not a problem.
11382 \def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
11383
11384 % Set catcodes for Texinfo file
11385
11386 % Active characters for printing the wanted glyph.
11387 % Most of these we simply print from the \tt font, but for some, we can
11388 % use math or other variants that look better in normal text.
11389 %
11390 \catcode`\"=\active
11391 \def\activedoublequote{{\tt\char34}}
11392 \let"=\activedoublequote
11393 \catcode`\~=\active \def\activetilde{{\tt\char126}} \let~ = \activetilde
11394 \chardef\hatchar=`\^
11395 \catcode`\^=\active \def\activehat{{\tt \hatchar}} \let^ = \activehat
11396
11397 \catcode`\_=\active
11398 \def_{\ifusingtt\normalunderscore\_}
11399 \def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
11400 \let\realunder=_
11401
11402 \catcode`\|=\active \def|{{\tt\char124}}
11403
11404 \chardef \less=`\<
11405 \catcode`\<=\active \def\activeless{{\tt \less}}\let< = \activeless
11406 \chardef \gtr=`\>
11407 \catcode`\>=\active \def\activegtr{{\tt \gtr}}\let> = \activegtr
11408 \catcode`\+=\active \def+{{\tt \char 43}}
11409 \catcode`\$=\active \def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
11410 \catcode`\-=\active \let-=\normaldash
11411
11412
11413 % used for headline/footline in the output routine, in case the page
11414 % breaks in the middle of an @tex block.
11415 \def\texinfochars{%
11416   \let< = \activeless
11417   \let> = \activegtr
11418   \let~ = \activetilde 
11419   \let^ = \activehat
11420   \markupsetuplqdefault \markupsetuprqdefault 
11421   \let\b = \strong
11422   \let\i = \smartitalic
11423   % in principle, all other definitions in \tex have to be undone too.
11424 }
11425
11426 % Used sometimes to turn off (effectively) the active characters even after
11427 % parsing them.
11428 \def\turnoffactive{%
11429   \normalturnoffactive
11430   \otherbackslash
11431 }
11432
11433 \catcode`\@=0
11434
11435 % \backslashcurfont outputs one backslash character in current font,
11436 % as in \char`\\.
11437 \global\chardef\backslashcurfont=`\\
11438 \global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
11439
11440 % \realbackslash is an actual character `\' with catcode other, and
11441 % \doublebackslash is two of them (for the pdf outlines).
11442 {\catcode`\\=\other @gdef@realbackslash{\} @gdef@doublebackslash{\\}}
11443
11444 % In Texinfo, backslash is an active character; it prints the backslash
11445 % in fixed width font.
11446 \catcode`\\=\active  % @ for escape char from now on.
11447
11448 % Print a typewriter backslash.  For math mode, we can't simply use
11449 % \backslashcurfont: the story here is that in math mode, the \char
11450 % of \backslashcurfont ends up printing the roman \ from the math symbol
11451 % font (because \char in math mode uses the \mathcode, and plain.tex
11452 % sets \mathcode`\\="026E).  Hence we use an explicit \mathchar,
11453 % which is the decimal equivalent of "715c (class 7, e.g., use \fam;
11454 % ignored family value; char position "5C).  We can't use " for the
11455 % usual hex value because it has already been made active.
11456
11457 @def@ttbackslash{{@tt @ifmmode @mathchar29020 @else @backslashcurfont @fi}}
11458 @let@backslashchar = @ttbackslash % @backslashchar{} is for user documents.
11459
11460 % \rawbackslash defines an active \ to do \backslashcurfont.
11461 % \otherbackslash defines an active \ to be a literal `\' character with
11462 % catcode other.  We switch back and forth between these.
11463 @gdef@rawbackslash{@let\=@backslashcurfont}
11464 @gdef@otherbackslash{@let\=@realbackslash}
11465
11466 % Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
11467 % the literal character `\'.
11468 %
11469 {@catcode`- = @active
11470  @gdef@normalturnoffactive{%
11471    @passthroughcharstrue
11472    @let-=@normaldash
11473    @let"=@normaldoublequote
11474    @let$=@normaldollar %$ font-lock fix
11475    @let+=@normalplus
11476    @let<=@normalless
11477    @let>=@normalgreater
11478    @let^=@normalcaret
11479    @let_=@normalunderscore
11480    @let|=@normalverticalbar
11481    @let~=@normaltilde
11482    @let\=@ttbackslash
11483    @markupsetuplqdefault
11484    @markupsetuprqdefault
11485    @unsepspaces
11486  }
11487 }
11488
11489 % If a .fmt file is being used, characters that might appear in a file
11490 % name cannot be active until we have parsed the command line.
11491 % So turn them off again, and have @fixbackslash turn them back on.
11492 @catcode`+=@other @catcode`@_=@other
11493
11494 % \enablebackslashhack - allow file to begin `\input texinfo'
11495 %
11496 % If a .fmt file is being used, we don't want the `\input texinfo' to show up.
11497 % That is what \eatinput is for; after that, the `\' should revert to printing
11498 % a backslash.
11499 % If the file did not have a `\input texinfo', then it is turned off after
11500 % the first line; otherwise the first `\' in the file would cause an error.
11501 % This is used on the very last line of this file, texinfo.tex.
11502 % We also use @c to call @fixbackslash, in case ends of lines are hidden.
11503 {
11504 @catcode`@^=7
11505 @catcode`@^^M=13@gdef@enablebackslashhack{%
11506   @global@let\ = @eatinput%
11507   @catcode`@^^M=13%
11508   @def@c{@fixbackslash@c}%
11509   % Definition for the newline at the end of this file.
11510   @def ^^M{@let^^M@secondlinenl}%
11511   % Definition for a newline in the main Texinfo file.
11512   @gdef @secondlinenl{@fixbackslash}%
11513 }}
11514
11515 {@catcode`@^=7 @catcode`@^^M=13%
11516 @gdef@eatinput input texinfo#1^^M{@fixbackslash}}
11517
11518 % Emergency active definition of newline, in case an active newline token
11519 % appears by mistake.
11520 {@catcode`@^=7 @catcode13=13%
11521 @gdef@enableemergencynewline{%
11522   @gdef^^M{%
11523     @par%
11524     %<warning: active newline>@par%
11525 }}}
11526
11527
11528 @gdef@fixbackslash{%
11529   @ifx\@eatinput @let\ = @ttbackslash @fi
11530   @catcode13=5 % regular end of line
11531   @enableemergencynewline
11532   @let@c=@texinfoc
11533   % Also turn back on active characters that might appear in the input
11534   % file name, in case not using a pre-dumped format.
11535   @catcode`+=@active
11536   @catcode`@_=@active
11537   %
11538   % If texinfo.cnf is present on the system, read it.
11539   % Useful for site-wide @afourpaper, etc.  This macro, @fixbackslash, gets
11540   % called at the beginning of every Texinfo file.  Not opening texinfo.cnf
11541   % directly in this file, texinfo.tex, makes it possible to make a format
11542   % file for Texinfo.
11543   %
11544   @openin 1 texinfo.cnf
11545   @ifeof 1 @else @input texinfo.cnf @fi
11546   @closein 1
11547 }
11548
11549
11550 % Say @foo, not \foo, in error messages.
11551 @escapechar = `@@
11552
11553 % These (along with & and #) are made active for url-breaking, so need
11554 % active definitions as the normal characters.
11555 @def@normaldot{.}
11556 @def@normalquest{?}
11557 @def@normalslash{/}
11558
11559 % These look ok in all fonts, so just make them not special.
11560 % @hashchar{} gets its own user-level command, because of #line.
11561 @catcode`@& = @other @def@normalamp{&}
11562 @catcode`@# = @other @def@normalhash{#}
11563 @catcode`@% = @other @def@normalpercent{%}
11564
11565 @let @hashchar = @normalhash
11566
11567 @c Finally, make ` and ' active, so that txicodequoteundirected and
11568 @c txicodequotebacktick work right in, e.g., @w{@code{`foo'}}.  If we
11569 @c don't make ` and ' active, @code will not get them as active chars.
11570 @c Do this last of all since we use ` in the previous @catcode assignments.
11571 @catcode`@'=@active
11572 @catcode`@`=@active
11573 @markupsetuplqdefault
11574 @markupsetuprqdefault
11575
11576 @c Local variables:
11577 @c eval: (add-hook 'write-file-hooks 'time-stamp)
11578 @c page-delimiter: "^\\\\message\\|emacs-page"
11579 @c time-stamp-start: "def\\\\texinfoversion{"
11580 @c time-stamp-format: "%:y-%02m-%02d.%02H"
11581 @c time-stamp-end: "}"
11582 @c End:
11583
11584 @c vim:sw=2:
11585
11586 @ignore
11587    arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
11588 @end ignore
11589 @enablebackslashhack