]> git.donarmstrong.com Git - lilypond.git/blob - tex/texinfo.tex
Merge remote-tracking branch 'origin/release/unstable' into HEAD
[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-07-20.14}
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     \xdef#1{#1}%
1196   \else
1197     % The expandable \pdfescapestring primitive escapes parentheses,
1198     % backslashes, and other special chars.
1199     \xdef#1{\pdfescapestring{#1}}%
1200   \fi
1201 }
1202
1203 \newhelp\nopdfimagehelp{Texinfo supports .png, .jpg, .jpeg, and .pdf images
1204 with PDF output, and none of those formats could be found.  (.eps cannot
1205 be supported due to the design of the PDF format; use regular TeX (DVI
1206 output) for that.)}
1207
1208 \ifpdf
1209   %
1210   % Color manipulation macros using ideas from pdfcolor.tex,
1211   % except using rgb instead of cmyk; the latter is said to render as a
1212   % very dark gray on-screen and a very dark halftone in print, instead
1213   % of actual black. The dark red here is dark enough to print on paper as
1214   % nearly black, but still distinguishable for online viewing.  We use
1215   % black by default, though.
1216   \def\rgbDarkRed{0.50 0.09 0.12}
1217   \def\rgbBlack{0 0 0}
1218   %
1219   % rg sets the color for filling (usual text, etc.);
1220   % RG sets the color for stroking (thin rules, e.g., normal _'s).
1221   \def\pdfsetcolor#1{\pdfliteral{#1 rg  #1 RG}}
1222   %
1223   % Set color, and create a mark which defines \thiscolor accordingly,
1224   % so that \makeheadline knows which color to restore.
1225   \def\setcolor#1{%
1226     \xdef\lastcolordefs{\gdef\noexpand\thiscolor{#1}}%
1227     \domark
1228     \pdfsetcolor{#1}%
1229   }
1230   %
1231   \def\maincolor{\rgbBlack}
1232   \pdfsetcolor{\maincolor}
1233   \edef\thiscolor{\maincolor}
1234   \def\lastcolordefs{}
1235   %
1236   \def\makefootline{%
1237     \baselineskip24pt
1238     \line{\pdfsetcolor{\maincolor}\the\footline}%
1239   }
1240   %
1241   \def\makeheadline{%
1242     \vbox to 0pt{%
1243       \vskip-22.5pt
1244       \line{%
1245         \vbox to8.5pt{}%
1246         % Extract \thiscolor definition from the marks.
1247         \getcolormarks
1248         % Typeset the headline with \maincolor, then restore the color.
1249         \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
1250       }%
1251       \vss
1252     }%
1253     \nointerlineskip
1254   }
1255   %
1256   %
1257   \pdfcatalog{/PageMode /UseOutlines}
1258   %
1259   % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1260   \def\dopdfimage#1#2#3{%
1261     \def\pdfimagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1262     \def\pdfimageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1263     %
1264     % pdftex (and the PDF format) support .pdf, .png, .jpg (among
1265     % others).  Let's try in that order, PDF first since if
1266     % someone has a scalable image, presumably better to use that than a
1267     % bitmap.
1268     \let\pdfimgext=\empty
1269     \begingroup
1270       \openin 1 #1.pdf \ifeof 1
1271         \openin 1 #1.PDF \ifeof 1
1272           \openin 1 #1.png \ifeof 1
1273             \openin 1 #1.jpg \ifeof 1
1274               \openin 1 #1.jpeg \ifeof 1
1275                 \openin 1 #1.JPG \ifeof 1
1276                   \errhelp = \nopdfimagehelp
1277                   \errmessage{Could not find image file #1 for pdf}%
1278                 \else \gdef\pdfimgext{JPG}%
1279                 \fi
1280               \else \gdef\pdfimgext{jpeg}%
1281               \fi
1282             \else \gdef\pdfimgext{jpg}%
1283             \fi
1284           \else \gdef\pdfimgext{png}%
1285           \fi
1286         \else \gdef\pdfimgext{PDF}%
1287         \fi
1288       \else \gdef\pdfimgext{pdf}%
1289       \fi
1290       \closein 1
1291     \endgroup
1292     %
1293     % without \immediate, ancient pdftex seg faults when the same image is
1294     % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
1295     \ifnum\pdftexversion < 14
1296       \immediate\pdfimage
1297     \else
1298       \immediate\pdfximage
1299     \fi
1300       \ifdim \wd0 >0pt width \pdfimagewidth \fi
1301       \ifdim \wd2 >0pt height \pdfimageheight \fi
1302       \ifnum\pdftexversion<13
1303          #1.\pdfimgext
1304        \else
1305          {#1.\pdfimgext}%
1306        \fi
1307     \ifnum\pdftexversion < 14 \else
1308       \pdfrefximage \pdflastximage
1309     \fi}
1310   %
1311   \def\pdfmkdest#1{{%
1312     % We have to set dummies so commands such as @code, and characters
1313     % such as \, aren't expanded when present in a section title.
1314     \indexnofonts
1315     \makevalueexpandable
1316     \turnoffactive
1317     % Use ASCII approximations in destination names.
1318     \passthroughcharsfalse
1319     \def\pdfdestname{#1}%
1320     \txiescapepdf\pdfdestname
1321     \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1322   }}
1323   %
1324   % used to mark target names; must be expandable.
1325   \def\pdfmkpgn#1{#1}
1326   %
1327   % by default, use black for everything.
1328   \def\urlcolor{\rgbBlack}
1329   \def\linkcolor{\rgbBlack}
1330   \def\endlink{\setcolor{\maincolor}\pdfendlink}
1331   %
1332   % Adding outlines to PDF; macros for calculating structure of outlines
1333   % come from Petr Olsak
1334   \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
1335     \else \csname#1\endcsname \fi}
1336   \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
1337     \advance\tempnum by 1
1338     \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
1339   %
1340   % #1 is the section text, which is what will be displayed in the
1341   % outline by the pdf viewer.  #2 is the pdf expression for the number
1342   % of subentries (or empty, for subsubsections).  #3 is the node text,
1343   % which might be empty if this toc entry had no corresponding node.
1344   % #4 is the page number
1345   %
1346   \def\dopdfoutline#1#2#3#4{%
1347     % Generate a link to the node text if that exists; else, use the
1348     % page number.  We could generate a destination for the section
1349     % text in the case where a section has no node, but it doesn't
1350     % seem worth the trouble, since most documents are normally structured.
1351     {
1352       \ifx\luatexversion\thisisundefined \else
1353         \turnoffactive % LuaTeX can use Unicode strings for PDF
1354       \fi
1355       \edef\pdfoutlinedest{#3}%
1356       \ifx\pdfoutlinedest\empty
1357         \def\pdfoutlinedest{#4}%
1358       \else
1359         \txiescapepdf\pdfoutlinedest
1360       \fi
1361       %
1362       % Also escape PDF chars in the display string.
1363       \bgroup
1364         \ifx \declaredencoding \latone
1365           % The PDF format can use an extended form of Latin-1 in bookmark
1366           % strings.  See Appendix D of the PDF Reference, Sixth Edition, for
1367           % the "PDFDocEncoding".
1368           \passthroughcharstrue
1369         \fi
1370         \ifx \declaredencoding \utfeight
1371           % TODO: the PDF format can use UTF-16 in bookmark strings, but the
1372           % code for this isn't done yet.
1373         \fi
1374         \globaldefs=1
1375         \edef\pdfoutlinetext{#1}%
1376         \txiescapepdf\pdfoutlinetext
1377       \egroup
1378       %
1379       \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
1380     }
1381   }
1382   %
1383   \def\pdfmakeoutlines{%
1384     \begingroup
1385       % Read toc silently, to get counts of subentries for \pdfoutline.
1386       \def\partentry##1##2##3##4{}% ignore parts in the outlines
1387       \def\numchapentry##1##2##3##4{%
1388         \def\thischapnum{##2}%
1389         \def\thissecnum{0}%
1390         \def\thissubsecnum{0}%
1391       }%
1392       \def\numsecentry##1##2##3##4{%
1393         \advancenumber{chap\thischapnum}%
1394         \def\thissecnum{##2}%
1395         \def\thissubsecnum{0}%
1396       }%
1397       \def\numsubsecentry##1##2##3##4{%
1398         \advancenumber{sec\thissecnum}%
1399         \def\thissubsecnum{##2}%
1400       }%
1401       \def\numsubsubsecentry##1##2##3##4{%
1402         \advancenumber{subsec\thissubsecnum}%
1403       }%
1404       \def\thischapnum{0}%
1405       \def\thissecnum{0}%
1406       \def\thissubsecnum{0}%
1407       %
1408       % use \def rather than \let here because we redefine \chapentry et
1409       % al. a second time, below.
1410       \def\appentry{\numchapentry}%
1411       \def\appsecentry{\numsecentry}%
1412       \def\appsubsecentry{\numsubsecentry}%
1413       \def\appsubsubsecentry{\numsubsubsecentry}%
1414       \def\unnchapentry{\numchapentry}%
1415       \def\unnsecentry{\numsecentry}%
1416       \def\unnsubsecentry{\numsubsecentry}%
1417       \def\unnsubsubsecentry{\numsubsubsecentry}%
1418       \readdatafile{toc}%
1419       %
1420       % Read toc second time, this time actually producing the outlines.
1421       % The `-' means take the \expnumber as the absolute number of
1422       % subentries, which we calculated on our first read of the .toc above.
1423       %
1424       % We use the node names as the destinations.
1425       \def\numchapentry##1##2##3##4{%
1426         \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
1427       \def\numsecentry##1##2##3##4{%
1428         \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
1429       \def\numsubsecentry##1##2##3##4{%
1430         \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
1431       \def\numsubsubsecentry##1##2##3##4{% count is always zero
1432         \dopdfoutline{##1}{}{##3}{##4}}%
1433       %
1434       % PDF outlines are displayed using system fonts, instead of
1435       % document fonts.  Therefore we cannot use special characters,
1436       % since the encoding is unknown.  For example, the eogonek from
1437       % Latin 2 (0xea) gets translated to a | character.  Info from
1438       % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
1439       %
1440       % TODO this right, we have to translate 8-bit characters to
1441       % their "best" equivalent, based on the @documentencoding.  Too
1442       % much work for too little return.  Just use the ASCII equivalents
1443       % we use for the index sort strings.
1444       % 
1445       \indexnofonts
1446       \setupdatafile
1447       % We can have normal brace characters in the PDF outlines, unlike
1448       % Texinfo index files.  So set that up.
1449       \def\{{\lbracecharliteral}%
1450       \def\}{\rbracecharliteral}%
1451       \catcode`\\=\active \otherbackslash
1452       \input \tocreadfilename
1453     \endgroup
1454   }
1455   {\catcode`[=1 \catcode`]=2
1456    \catcode`{=\other \catcode`}=\other
1457    \gdef\lbracecharliteral[{]%
1458    \gdef\rbracecharliteral[}]%
1459   ]
1460   %
1461   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1462     \ifx\PP\D\let\nextsp\relax
1463     \else\let\nextsp\skipspaces
1464       \addtokens{\filename}{\PP}%
1465       \advance\filenamelength by 1
1466     \fi
1467     \nextsp}
1468   \def\getfilename#1{%
1469     \filenamelength=0
1470     % If we don't expand the argument now, \skipspaces will get
1471     % snagged on things like "@value{foo}".
1472     \edef\temp{#1}%
1473     \expandafter\skipspaces\temp|\relax
1474   }
1475   \ifnum\pdftexversion < 14
1476     \let \startlink \pdfannotlink
1477   \else
1478     \let \startlink \pdfstartlink
1479   \fi
1480   % make a live url in pdf output.
1481   \def\pdfurl#1{%
1482     \begingroup
1483       % it seems we really need yet another set of dummies; have not
1484       % tried to figure out what each command should do in the context
1485       % of @url.  for now, just make @/ a no-op, that's the only one
1486       % people have actually reported a problem with.
1487       %
1488       \normalturnoffactive
1489       \def\@{@}%
1490       \let\/=\empty
1491       \makevalueexpandable
1492       % do we want to go so far as to use \indexnofonts instead of just
1493       % special-casing \var here?
1494       \def\var##1{##1}%
1495       %
1496       \leavevmode\setcolor{\urlcolor}%
1497       \startlink attr{/Border [0 0 0]}%
1498         user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
1499     \endgroup}
1500   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1501   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1502   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1503   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1504   \def\maketoks{%
1505     \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1506     \ifx\first0\adn0
1507     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1508     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1509     \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1510     \else
1511       \ifnum0=\countA\else\makelink\fi
1512       \ifx\first.\let\next=\done\else
1513         \let\next=\maketoks
1514         \addtokens{\toksB}{\the\toksD}
1515         \ifx\first,\addtokens{\toksB}{\space}\fi
1516       \fi
1517     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1518     \next}
1519   \def\makelink{\addtokens{\toksB}%
1520     {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1521   \def\pdflink#1{%
1522     \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
1523     \setcolor{\linkcolor}#1\endlink}
1524   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1525 \else
1526   % non-pdf mode
1527   \let\pdfmkdest = \gobble
1528   \let\pdfurl = \gobble
1529   \let\endlink = \relax
1530   \let\setcolor = \gobble
1531   \let\pdfsetcolor = \gobble
1532   \let\pdfmakeoutlines = \relax
1533 \fi  % \ifx\pdfoutput
1534
1535 %
1536 % For XeTeX
1537 %
1538 \newif\iftxiuseunicodedestname
1539 \ifx\XeTeXrevision\thisisundefined
1540 \else
1541   %
1542   % XeTeX version check
1543   %
1544   \ifnum\strcmp{\the\XeTeXversion\XeTeXrevision}{0.99996}>-1
1545     % TeX Live 2016 contains XeTeX 0.99996 and xdvipdfmx 20160307.
1546     % It can be used `dvipdfmx:config' special (from TeX Live SVN r40941).
1547     % For avoiding PDF destination name replacement, we use the special
1548     % instead of xdvipdfmx commandline option `-C 0x0010'.
1549     \special{dvipdfmx:config C 0x0010}
1550     % XeTeX 0.99995+ contains xdvipdfmx 20160307+.
1551     % It can handle Unicode destination name for PDF.
1552     \txiuseunicodedestnametrue
1553   \else
1554     % XeTeX < 0.99996 (TeX Live < 2016) cannot be used
1555     % `dvipdfmx:config' special.
1556     % So for avoiding PDF destination name replacement,
1557     % xdvipdfmx commandline option `-C 0x0010' is necessary.
1558     %
1559     % XeTeX < 0.99995 can not handle Unicode destination name for PDF
1560     % because xdvipdfmx 20150315 has UTF-16 convert issue.
1561     % It fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1562     \txiuseunicodedestnamefalse
1563   \fi
1564   %
1565   % PDF outline support
1566   %
1567   % Emulate the primitive of pdfTeX
1568   \def\pdfdest name#1 xyz{%
1569     \special{pdf:dest (name#1) [@thispage /XYZ @xpos @ypos null]}%
1570   }
1571   \def\pdfmkdest#1{{%
1572     % We have to set dummies so commands such as @code, and characters
1573     % such as \, aren't expanded when present in a section title.
1574     \indexnofonts
1575     \iftxiuseunicodedestname
1576       \def\pdfdestname{#1}% Pass through Unicode characters.
1577     \else
1578       \edef\pdfdestname{#1}% Replace Unicode characters to ASCII.
1579     \fi
1580     \turnoffactive
1581     \makevalueexpandable
1582     \txiescapepdf\pdfdestname
1583     \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
1584   }}
1585   %
1586   \def\dopdfoutline#1#2#3#4{%
1587     \iftxiuseunicodedestname
1588       \def\pdfoutlinedest{#3}% Pass through Unicode characters.
1589     \else
1590       \edef\pdfoutlinedest{#3}% Replace Unicode characters to ASCII.
1591     \fi
1592     \ifx\pdfoutlinedest\empty
1593       \def\pdfoutlinedest{#4}%
1594     \fi
1595     {
1596       \turnoffactive
1597       \txiescapepdf\pdfoutlinedest
1598       \edef\pdfoutlinetext{#1}%
1599       \txiescapepdf\pdfoutlinetext
1600       %
1601       \special{pdf:out [-] #2 << /Title (\pdfoutlinetext) /A
1602         << /S /GoTo /D (name\pdfoutlinedest) >> >> }%
1603     }
1604   }
1605   %
1606   \def\pdfmakeoutlines{%
1607     \begingroup
1608       %
1609       % In the case of XeTeX, counts of subentries is not necesary.
1610       % Therefore, read toc only once.
1611       %
1612       % We use the node names as the destinations.
1613       \def\partentry##1##2##3##4{}% ignore parts in the outlines
1614       \def\numchapentry##1##2##3##4{%
1615         \dopdfoutline{##1}{1}{##3}{##4}}%
1616       \def\numsecentry##1##2##3##4{%
1617         \dopdfoutline{##1}{2}{##3}{##4}}%
1618       \def\numsubsecentry##1##2##3##4{%
1619         \dopdfoutline{##1}{3}{##3}{##4}}%
1620       \def\numsubsubsecentry##1##2##3##4{%
1621         \dopdfoutline{##1}{4}{##3}{##4}}%
1622       %
1623       \let\appentry\numchapentry%
1624       \let\appsecentry\numsecentry%
1625       \let\appsubsecentry\numsubsecentry%
1626       \let\appsubsubsecentry\numsubsubsecentry%
1627       \let\unnchapentry\numchapentry%
1628       \let\unnsecentry\numsecentry%
1629       \let\unnsubsecentry\numsubsecentry%
1630       \let\unnsubsubsecentry\numsubsubsecentry%
1631       %
1632       % In the case of XeTeX, xdvipdfmx converts strings to UTF-16.
1633       % Therefore, the encoding and the language may not be considered.
1634       %
1635       \indexnofonts
1636       \setupdatafile
1637       % We can have normal brace characters in the PDF outlines, unlike
1638       % Texinfo index files.  So set that up.
1639       \def\{{\lbracecharliteral}%
1640       \def\}{\rbracecharliteral}%
1641       \catcode`\\=\active \otherbackslash
1642       \input \tocreadfilename
1643     \endgroup
1644   }
1645   {\catcode`[=1 \catcode`]=2
1646    \catcode`{=\other \catcode`}=\other
1647    \gdef\lbracecharliteral[{]%
1648    \gdef\rbracecharliteral[}]%
1649   ]
1650
1651   \special{pdf:docview << /PageMode /UseOutlines >> }
1652   % ``\special{pdf:tounicode ...}'' is not necessary
1653   % because xdvipdfmx converts strings from UTF-8 to UTF-16 without it.
1654   % However, due to UTF-16 convert issue of xdvipdfmx 20150315,
1655   % ``\special{pdf:dest ...}'' can not handle non-ASCII strings.
1656   % It fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
1657 %
1658   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
1659     \ifx\PP\D\let\nextsp\relax
1660     \else\let\nextsp\skipspaces
1661       \addtokens{\filename}{\PP}%
1662       \advance\filenamelength by 1
1663     \fi
1664     \nextsp}
1665   \def\getfilename#1{%
1666     \filenamelength=0
1667     % If we don't expand the argument now, \skipspaces will get
1668     % snagged on things like "@value{foo}".
1669     \edef\temp{#1}%
1670     \expandafter\skipspaces\temp|\relax
1671   }
1672   % make a live url in pdf output.
1673   \def\pdfurl#1{%
1674     \begingroup
1675       % it seems we really need yet another set of dummies; have not
1676       % tried to figure out what each command should do in the context
1677       % of @url.  for now, just make @/ a no-op, that's the only one
1678       % people have actually reported a problem with.
1679       %
1680       \normalturnoffactive
1681       \def\@{@}%
1682       \let\/=\empty
1683       \makevalueexpandable
1684       % do we want to go so far as to use \indexnofonts instead of just
1685       % special-casing \var here?
1686       \def\var##1{##1}%
1687       %
1688       \leavevmode\setcolor{\urlcolor}%
1689       \special{pdf:bann << /Border [0 0 0]
1690         /Subtype /Link /A << /S /URI /URI (#1) >> >>}%
1691     \endgroup}
1692   \def\endlink{\setcolor{\maincolor}\special{pdf:eann}}
1693   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
1694   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
1695   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
1696   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
1697   \def\maketoks{%
1698     \expandafter\poptoks\the\toksA|ENDTOKS|\relax
1699     \ifx\first0\adn0
1700     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
1701     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
1702     \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
1703     \else
1704       \ifnum0=\countA\else\makelink\fi
1705       \ifx\first.\let\next=\done\else
1706         \let\next=\maketoks
1707         \addtokens{\toksB}{\the\toksD}
1708         \ifx\first,\addtokens{\toksB}{\space}\fi
1709       \fi
1710     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1711     \next}
1712   \def\makelink{\addtokens{\toksB}%
1713     {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
1714   \def\pdflink#1{%
1715     \special{pdf:bann << /Border [0 0 0]
1716       /Type /Annot /Subtype /Link /A << /S /GoTo /D (name#1) >> >>}%
1717     \setcolor{\linkcolor}#1\endlink}
1718   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
1719 %
1720   %
1721   % @image support
1722   %
1723   % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
1724   \def\doxeteximage#1#2#3{%
1725     \def\xeteximagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
1726     \def\xeteximageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
1727     %
1728     % XeTeX (and the PDF format) support .pdf, .png, .jpg (among
1729     % others).  Let's try in that order, PDF first since if
1730     % someone has a scalable image, presumably better to use that than a
1731     % bitmap.
1732     \let\xeteximgext=\empty
1733     \begingroup
1734       \openin 1 #1.pdf \ifeof 1
1735         \openin 1 #1.PDF \ifeof 1
1736           \openin 1 #1.png \ifeof 1
1737             \openin 1 #1.jpg \ifeof 1
1738               \openin 1 #1.jpeg \ifeof 1
1739                 \openin 1 #1.JPG \ifeof 1
1740                   \errmessage{Could not find image file #1 for XeTeX}%
1741                 \else \gdef\xeteximgext{JPG}%
1742                 \fi
1743               \else \gdef\xeteximgext{jpeg}%
1744               \fi
1745             \else \gdef\xeteximgext{jpg}%
1746             \fi
1747           \else \gdef\xeteximgext{png}%
1748           \fi
1749         \else \gdef\xeteximgext{PDF}%
1750         \fi
1751       \else \gdef\xeteximgext{pdf}%
1752       \fi
1753       \closein 1
1754     \endgroup
1755     %
1756     \def\xetexpdfext{pdf}%
1757     \ifx\xeteximgext\xetexpdfext
1758       \XeTeXpdffile "#1".\xeteximgext ""
1759     \else
1760       \def\xetexpdfext{PDF}%
1761       \ifx\xeteximgext\xetexpdfext
1762         \XeTeXpdffile "#1".\xeteximgext ""
1763       \else
1764         \XeTeXpicfile "#1".\xeteximgext ""
1765       \fi
1766     \fi
1767     \ifdim \wd0 >0pt width \xeteximagewidth \fi
1768     \ifdim \wd2 >0pt height \xeteximageheight \fi \relax
1769   }
1770 \fi
1771
1772 \message{fonts,}
1773
1774 % Change the current font style to #1, remembering it in \curfontstyle.
1775 % For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
1776 % italics, not bold italics.
1777 %
1778 \def\setfontstyle#1{%
1779   \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
1780   \csname ten#1\endcsname  % change the current font
1781 }
1782
1783 % Select #1 fonts with the current style.
1784 %
1785 \def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
1786
1787 \def\rm{\fam=0 \setfontstyle{rm}}
1788 \def\it{\fam=\itfam \setfontstyle{it}}
1789 \def\sl{\fam=\slfam \setfontstyle{sl}}
1790 \def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf}
1791 \def\tt{\fam=\ttfam \setfontstyle{tt}}
1792
1793 % Unfortunately, we have to override this for titles and the like, since
1794 % in those cases "rm" is bold.  Sigh.
1795 \def\rmisbold{\rm\def\curfontstyle{bf}}
1796
1797 % Texinfo sort of supports the sans serif font style, which plain TeX does not.
1798 % So we set up a \sf.
1799 \newfam\sffam
1800 \def\sf{\fam=\sffam \setfontstyle{sf}}
1801 \let\li = \sf % Sometimes we call it \li, not \sf.
1802
1803 % We don't need math for this font style.
1804 \def\ttsl{\setfontstyle{ttsl}}
1805
1806
1807 % Set the baselineskip to #1, and the lineskip and strut size
1808 % correspondingly.  There is no deep meaning behind these magic numbers
1809 % used as factors; they just match (closely enough) what Knuth defined.
1810 %
1811 \def\lineskipfactor{.08333}
1812 \def\strutheightpercent{.70833}
1813 \def\strutdepthpercent {.29167}
1814 %
1815 % can get a sort of poor man's double spacing by redefining this.
1816 \def\baselinefactor{1}
1817 %
1818 \newdimen\textleading
1819 \def\setleading#1{%
1820   \dimen0 = #1\relax
1821   \normalbaselineskip = \baselinefactor\dimen0
1822   \normallineskip = \lineskipfactor\normalbaselineskip
1823   \normalbaselines
1824   \setbox\strutbox =\hbox{%
1825     \vrule width0pt height\strutheightpercent\baselineskip
1826                     depth \strutdepthpercent \baselineskip
1827   }%
1828 }
1829
1830 % PDF CMaps.  See also LaTeX's t1.cmap.
1831 %
1832 % do nothing with this by default.
1833 \expandafter\let\csname cmapOT1\endcsname\gobble
1834 \expandafter\let\csname cmapOT1IT\endcsname\gobble
1835 \expandafter\let\csname cmapOT1TT\endcsname\gobble
1836
1837 % if we are producing pdf, and we have \pdffontattr, then define cmaps.
1838 % (\pdffontattr was introduced many years ago, but people still run
1839 % older pdftex's; it's easy to conditionalize, so we do.)
1840 \ifpdf \ifx\pdffontattr\thisisundefined \else
1841   \begingroup
1842     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1843     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1844 %%DocumentNeededResources: ProcSet (CIDInit)
1845 %%IncludeResource: ProcSet (CIDInit)
1846 %%BeginResource: CMap (TeX-OT1-0)
1847 %%Title: (TeX-OT1-0 TeX OT1 0)
1848 %%Version: 1.000
1849 %%EndComments
1850 /CIDInit /ProcSet findresource begin
1851 12 dict begin
1852 begincmap
1853 /CIDSystemInfo
1854 << /Registry (TeX)
1855 /Ordering (OT1)
1856 /Supplement 0
1857 >> def
1858 /CMapName /TeX-OT1-0 def
1859 /CMapType 2 def
1860 1 begincodespacerange
1861 <00> <7F>
1862 endcodespacerange
1863 8 beginbfrange
1864 <00> <01> <0393>
1865 <09> <0A> <03A8>
1866 <23> <26> <0023>
1867 <28> <3B> <0028>
1868 <3F> <5B> <003F>
1869 <5D> <5E> <005D>
1870 <61> <7A> <0061>
1871 <7B> <7C> <2013>
1872 endbfrange
1873 40 beginbfchar
1874 <02> <0398>
1875 <03> <039B>
1876 <04> <039E>
1877 <05> <03A0>
1878 <06> <03A3>
1879 <07> <03D2>
1880 <08> <03A6>
1881 <0B> <00660066>
1882 <0C> <00660069>
1883 <0D> <0066006C>
1884 <0E> <006600660069>
1885 <0F> <00660066006C>
1886 <10> <0131>
1887 <11> <0237>
1888 <12> <0060>
1889 <13> <00B4>
1890 <14> <02C7>
1891 <15> <02D8>
1892 <16> <00AF>
1893 <17> <02DA>
1894 <18> <00B8>
1895 <19> <00DF>
1896 <1A> <00E6>
1897 <1B> <0153>
1898 <1C> <00F8>
1899 <1D> <00C6>
1900 <1E> <0152>
1901 <1F> <00D8>
1902 <21> <0021>
1903 <22> <201D>
1904 <27> <2019>
1905 <3C> <00A1>
1906 <3D> <003D>
1907 <3E> <00BF>
1908 <5C> <201C>
1909 <5F> <02D9>
1910 <60> <2018>
1911 <7D> <02DD>
1912 <7E> <007E>
1913 <7F> <00A8>
1914 endbfchar
1915 endcmap
1916 CMapName currentdict /CMap defineresource pop
1917 end
1918 end
1919 %%EndResource
1920 %%EOF
1921     }\endgroup
1922   \expandafter\edef\csname cmapOT1\endcsname#1{%
1923     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
1924   }%
1925 %
1926 % \cmapOT1IT
1927   \begingroup
1928     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
1929     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
1930 %%DocumentNeededResources: ProcSet (CIDInit)
1931 %%IncludeResource: ProcSet (CIDInit)
1932 %%BeginResource: CMap (TeX-OT1IT-0)
1933 %%Title: (TeX-OT1IT-0 TeX OT1IT 0)
1934 %%Version: 1.000
1935 %%EndComments
1936 /CIDInit /ProcSet findresource begin
1937 12 dict begin
1938 begincmap
1939 /CIDSystemInfo
1940 << /Registry (TeX)
1941 /Ordering (OT1IT)
1942 /Supplement 0
1943 >> def
1944 /CMapName /TeX-OT1IT-0 def
1945 /CMapType 2 def
1946 1 begincodespacerange
1947 <00> <7F>
1948 endcodespacerange
1949 8 beginbfrange
1950 <00> <01> <0393>
1951 <09> <0A> <03A8>
1952 <25> <26> <0025>
1953 <28> <3B> <0028>
1954 <3F> <5B> <003F>
1955 <5D> <5E> <005D>
1956 <61> <7A> <0061>
1957 <7B> <7C> <2013>
1958 endbfrange
1959 42 beginbfchar
1960 <02> <0398>
1961 <03> <039B>
1962 <04> <039E>
1963 <05> <03A0>
1964 <06> <03A3>
1965 <07> <03D2>
1966 <08> <03A6>
1967 <0B> <00660066>
1968 <0C> <00660069>
1969 <0D> <0066006C>
1970 <0E> <006600660069>
1971 <0F> <00660066006C>
1972 <10> <0131>
1973 <11> <0237>
1974 <12> <0060>
1975 <13> <00B4>
1976 <14> <02C7>
1977 <15> <02D8>
1978 <16> <00AF>
1979 <17> <02DA>
1980 <18> <00B8>
1981 <19> <00DF>
1982 <1A> <00E6>
1983 <1B> <0153>
1984 <1C> <00F8>
1985 <1D> <00C6>
1986 <1E> <0152>
1987 <1F> <00D8>
1988 <21> <0021>
1989 <22> <201D>
1990 <23> <0023>
1991 <24> <00A3>
1992 <27> <2019>
1993 <3C> <00A1>
1994 <3D> <003D>
1995 <3E> <00BF>
1996 <5C> <201C>
1997 <5F> <02D9>
1998 <60> <2018>
1999 <7D> <02DD>
2000 <7E> <007E>
2001 <7F> <00A8>
2002 endbfchar
2003 endcmap
2004 CMapName currentdict /CMap defineresource pop
2005 end
2006 end
2007 %%EndResource
2008 %%EOF
2009     }\endgroup
2010   \expandafter\edef\csname cmapOT1IT\endcsname#1{%
2011     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
2012   }%
2013 %
2014 % \cmapOT1TT
2015   \begingroup
2016     \catcode`\^^M=\active \def^^M{^^J}% Output line endings as the ^^J char.
2017     \catcode`\%=12 \immediate\pdfobj stream {%!PS-Adobe-3.0 Resource-CMap
2018 %%DocumentNeededResources: ProcSet (CIDInit)
2019 %%IncludeResource: ProcSet (CIDInit)
2020 %%BeginResource: CMap (TeX-OT1TT-0)
2021 %%Title: (TeX-OT1TT-0 TeX OT1TT 0)
2022 %%Version: 1.000
2023 %%EndComments
2024 /CIDInit /ProcSet findresource begin
2025 12 dict begin
2026 begincmap
2027 /CIDSystemInfo
2028 << /Registry (TeX)
2029 /Ordering (OT1TT)
2030 /Supplement 0
2031 >> def
2032 /CMapName /TeX-OT1TT-0 def
2033 /CMapType 2 def
2034 1 begincodespacerange
2035 <00> <7F>
2036 endcodespacerange
2037 5 beginbfrange
2038 <00> <01> <0393>
2039 <09> <0A> <03A8>
2040 <21> <26> <0021>
2041 <28> <5F> <0028>
2042 <61> <7E> <0061>
2043 endbfrange
2044 32 beginbfchar
2045 <02> <0398>
2046 <03> <039B>
2047 <04> <039E>
2048 <05> <03A0>
2049 <06> <03A3>
2050 <07> <03D2>
2051 <08> <03A6>
2052 <0B> <2191>
2053 <0C> <2193>
2054 <0D> <0027>
2055 <0E> <00A1>
2056 <0F> <00BF>
2057 <10> <0131>
2058 <11> <0237>
2059 <12> <0060>
2060 <13> <00B4>
2061 <14> <02C7>
2062 <15> <02D8>
2063 <16> <00AF>
2064 <17> <02DA>
2065 <18> <00B8>
2066 <19> <00DF>
2067 <1A> <00E6>
2068 <1B> <0153>
2069 <1C> <00F8>
2070 <1D> <00C6>
2071 <1E> <0152>
2072 <1F> <00D8>
2073 <20> <2423>
2074 <27> <2019>
2075 <60> <2018>
2076 <7F> <00A8>
2077 endbfchar
2078 endcmap
2079 CMapName currentdict /CMap defineresource pop
2080 end
2081 end
2082 %%EndResource
2083 %%EOF
2084     }\endgroup
2085   \expandafter\edef\csname cmapOT1TT\endcsname#1{%
2086     \pdffontattr#1{/ToUnicode \the\pdflastobj\space 0 R}%
2087   }%
2088 \fi\fi
2089
2090
2091 % Set the font macro #1 to the font named \fontprefix#2.
2092 % #3 is the font's design size, #4 is a scale factor, #5 is the CMap
2093 % encoding (only OT1, OT1IT and OT1TT are allowed, or empty to omit).
2094 % Example:
2095 % #1 = \textrm
2096 % #2 = \rmshape
2097 % #3 = 10
2098 % #4 = \mainmagstep
2099 % #5 = OT1
2100 %
2101 \def\setfont#1#2#3#4#5{%
2102   \font#1=\fontprefix#2#3 scaled #4
2103   \csname cmap#5\endcsname#1%
2104 }
2105 % This is what gets called when #5 of \setfont is empty.
2106 \let\cmap\gobble
2107 %
2108 % (end of cmaps)
2109
2110 % Use cm as the default font prefix.
2111 % To specify the font prefix, you must define \fontprefix
2112 % before you read in texinfo.tex.
2113 \ifx\fontprefix\thisisundefined
2114 \def\fontprefix{cm}
2115 \fi
2116 % Support font families that don't use the same naming scheme as CM.
2117 \def\rmshape{r}
2118 \def\rmbshape{bx}               % where the normal face is bold
2119 \def\bfshape{b}
2120 \def\bxshape{bx}
2121 \def\ttshape{tt}
2122 \def\ttbshape{tt}
2123 \def\ttslshape{sltt}
2124 \def\itshape{ti}
2125 \def\itbshape{bxti}
2126 \def\slshape{sl}
2127 \def\slbshape{bxsl}
2128 \def\sfshape{ss}
2129 \def\sfbshape{ss}
2130 \def\scshape{csc}
2131 \def\scbshape{csc}
2132
2133 % Definitions for a main text size of 11pt.  (The default in Texinfo.)
2134 %
2135 \def\definetextfontsizexi{%
2136 % Text fonts (11.2pt, magstep1).
2137 \def\textnominalsize{11pt}
2138 \edef\mainmagstep{\magstephalf}
2139 \setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2140 \setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2141 \setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2142 \setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2143 \setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2144 \setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2145 \setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2146 \setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2147 \font\texti=cmmi10 scaled \mainmagstep
2148 \font\textsy=cmsy10 scaled \mainmagstep
2149 \def\textecsize{1095}
2150
2151 % A few fonts for @defun names and args.
2152 \setfont\defbf\bfshape{10}{\magstep1}{OT1}
2153 \setfont\deftt\ttshape{10}{\magstep1}{OT1TT}
2154 \setfont\defsl\slshape{10}{\magstep1}{OT1TT}
2155 \setfont\defttsl\ttslshape{10}{\magstep1}{OT1TT}
2156 \def\df{\let\tentt=\deftt \let\tenbf = \defbf
2157 \let\tenttsl=\defttsl \let\tensl=\defsl \bf}
2158
2159 % Fonts for indices, footnotes, small examples (9pt).
2160 \def\smallnominalsize{9pt}
2161 \setfont\smallrm\rmshape{9}{1000}{OT1}
2162 \setfont\smalltt\ttshape{9}{1000}{OT1TT}
2163 \setfont\smallbf\bfshape{10}{900}{OT1}
2164 \setfont\smallit\itshape{9}{1000}{OT1IT}
2165 \setfont\smallsl\slshape{9}{1000}{OT1}
2166 \setfont\smallsf\sfshape{9}{1000}{OT1}
2167 \setfont\smallsc\scshape{10}{900}{OT1}
2168 \setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2169 \font\smalli=cmmi9
2170 \font\smallsy=cmsy9
2171 \def\smallecsize{0900}
2172
2173 % Fonts for small examples (8pt).
2174 \def\smallernominalsize{8pt}
2175 \setfont\smallerrm\rmshape{8}{1000}{OT1}
2176 \setfont\smallertt\ttshape{8}{1000}{OT1TT}
2177 \setfont\smallerbf\bfshape{10}{800}{OT1}
2178 \setfont\smallerit\itshape{8}{1000}{OT1IT}
2179 \setfont\smallersl\slshape{8}{1000}{OT1}
2180 \setfont\smallersf\sfshape{8}{1000}{OT1}
2181 \setfont\smallersc\scshape{10}{800}{OT1}
2182 \setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2183 \font\smalleri=cmmi8
2184 \font\smallersy=cmsy8
2185 \def\smallerecsize{0800}
2186
2187 % Fonts for title page (20.4pt):
2188 \def\titlenominalsize{20pt}
2189 \setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2190 \setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2191 \setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2192 \setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2193 \setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2194 \setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2195 \let\titlebf=\titlerm
2196 \setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2197 \font\titlei=cmmi12 scaled \magstep3
2198 \font\titlesy=cmsy10 scaled \magstep4
2199 \def\titleecsize{2074}
2200
2201 % Chapter (and unnumbered) fonts (17.28pt).
2202 \def\chapnominalsize{17pt}
2203 \setfont\chaprm\rmbshape{12}{\magstep2}{OT1}
2204 \setfont\chapit\itbshape{10}{\magstep3}{OT1IT}
2205 \setfont\chapsl\slbshape{10}{\magstep3}{OT1}
2206 \setfont\chaptt\ttbshape{12}{\magstep2}{OT1TT}
2207 \setfont\chapttsl\ttslshape{10}{\magstep3}{OT1TT}
2208 \setfont\chapsf\sfbshape{17}{1000}{OT1}
2209 \let\chapbf=\chaprm
2210 \setfont\chapsc\scbshape{10}{\magstep3}{OT1}
2211 \font\chapi=cmmi12 scaled \magstep2
2212 \font\chapsy=cmsy10 scaled \magstep3
2213 \def\chapecsize{1728}
2214
2215 % Section fonts (14.4pt).
2216 \def\secnominalsize{14pt}
2217 \setfont\secrm\rmbshape{12}{\magstep1}{OT1}
2218 \setfont\secrmnotbold\rmshape{12}{\magstep1}{OT1}
2219 \setfont\secit\itbshape{10}{\magstep2}{OT1IT}
2220 \setfont\secsl\slbshape{10}{\magstep2}{OT1}
2221 \setfont\sectt\ttbshape{12}{\magstep1}{OT1TT}
2222 \setfont\secttsl\ttslshape{10}{\magstep2}{OT1TT}
2223 \setfont\secsf\sfbshape{12}{\magstep1}{OT1}
2224 \let\secbf\secrm
2225 \setfont\secsc\scbshape{10}{\magstep2}{OT1}
2226 \font\seci=cmmi12 scaled \magstep1
2227 \font\secsy=cmsy10 scaled \magstep2
2228 \def\sececsize{1440}
2229
2230 % Subsection fonts (13.15pt).
2231 \def\ssecnominalsize{13pt}
2232 \setfont\ssecrm\rmbshape{12}{\magstephalf}{OT1}
2233 \setfont\ssecit\itbshape{10}{1315}{OT1IT}
2234 \setfont\ssecsl\slbshape{10}{1315}{OT1}
2235 \setfont\ssectt\ttbshape{12}{\magstephalf}{OT1TT}
2236 \setfont\ssecttsl\ttslshape{10}{1315}{OT1TT}
2237 \setfont\ssecsf\sfbshape{12}{\magstephalf}{OT1}
2238 \let\ssecbf\ssecrm
2239 \setfont\ssecsc\scbshape{10}{1315}{OT1}
2240 \font\sseci=cmmi12 scaled \magstephalf
2241 \font\ssecsy=cmsy10 scaled 1315
2242 \def\ssececsize{1200}
2243
2244 % Reduced fonts for @acro in text (10pt).
2245 \def\reducednominalsize{10pt}
2246 \setfont\reducedrm\rmshape{10}{1000}{OT1}
2247 \setfont\reducedtt\ttshape{10}{1000}{OT1TT}
2248 \setfont\reducedbf\bfshape{10}{1000}{OT1}
2249 \setfont\reducedit\itshape{10}{1000}{OT1IT}
2250 \setfont\reducedsl\slshape{10}{1000}{OT1}
2251 \setfont\reducedsf\sfshape{10}{1000}{OT1}
2252 \setfont\reducedsc\scshape{10}{1000}{OT1}
2253 \setfont\reducedttsl\ttslshape{10}{1000}{OT1TT}
2254 \font\reducedi=cmmi10
2255 \font\reducedsy=cmsy10
2256 \def\reducedecsize{1000}
2257
2258 \textleading = 13.2pt % line spacing for 11pt CM
2259 \textfonts            % reset the current fonts
2260 \rm
2261 } % end of 11pt text font size definitions, \definetextfontsizexi
2262
2263
2264 % Definitions to make the main text be 10pt Computer Modern, with
2265 % section, chapter, etc., sizes following suit.  This is for the GNU
2266 % Press printing of the Emacs 22 manual.  Maybe other manuals in the
2267 % future.  Used with @smallbook, which sets the leading to 12pt.
2268 %
2269 \def\definetextfontsizex{%
2270 % Text fonts (10pt).
2271 \def\textnominalsize{10pt}
2272 \edef\mainmagstep{1000}
2273 \setfont\textrm\rmshape{10}{\mainmagstep}{OT1}
2274 \setfont\texttt\ttshape{10}{\mainmagstep}{OT1TT}
2275 \setfont\textbf\bfshape{10}{\mainmagstep}{OT1}
2276 \setfont\textit\itshape{10}{\mainmagstep}{OT1IT}
2277 \setfont\textsl\slshape{10}{\mainmagstep}{OT1}
2278 \setfont\textsf\sfshape{10}{\mainmagstep}{OT1}
2279 \setfont\textsc\scshape{10}{\mainmagstep}{OT1}
2280 \setfont\textttsl\ttslshape{10}{\mainmagstep}{OT1TT}
2281 \font\texti=cmmi10 scaled \mainmagstep
2282 \font\textsy=cmsy10 scaled \mainmagstep
2283 \def\textecsize{1000}
2284
2285 % A few fonts for @defun names and args.
2286 \setfont\defbf\bfshape{10}{\magstephalf}{OT1}
2287 \setfont\deftt\ttshape{10}{\magstephalf}{OT1TT}
2288 \setfont\defsl\slshape{10}{\magstephalf}{OT1TT}
2289 \setfont\defttsl\ttslshape{10}{\magstephalf}{OT1TT}
2290 \def\df{\let\tentt=\deftt \let\tenbf = \defbf
2291 \let\tensl=\defsl \let\tenttsl=\defttsl \bf}
2292
2293 % Fonts for indices, footnotes, small examples (9pt).
2294 \def\smallnominalsize{9pt}
2295 \setfont\smallrm\rmshape{9}{1000}{OT1}
2296 \setfont\smalltt\ttshape{9}{1000}{OT1TT}
2297 \setfont\smallbf\bfshape{10}{900}{OT1}
2298 \setfont\smallit\itshape{9}{1000}{OT1IT}
2299 \setfont\smallsl\slshape{9}{1000}{OT1}
2300 \setfont\smallsf\sfshape{9}{1000}{OT1}
2301 \setfont\smallsc\scshape{10}{900}{OT1}
2302 \setfont\smallttsl\ttslshape{10}{900}{OT1TT}
2303 \font\smalli=cmmi9
2304 \font\smallsy=cmsy9
2305 \def\smallecsize{0900}
2306
2307 % Fonts for small examples (8pt).
2308 \def\smallernominalsize{8pt}
2309 \setfont\smallerrm\rmshape{8}{1000}{OT1}
2310 \setfont\smallertt\ttshape{8}{1000}{OT1TT}
2311 \setfont\smallerbf\bfshape{10}{800}{OT1}
2312 \setfont\smallerit\itshape{8}{1000}{OT1IT}
2313 \setfont\smallersl\slshape{8}{1000}{OT1}
2314 \setfont\smallersf\sfshape{8}{1000}{OT1}
2315 \setfont\smallersc\scshape{10}{800}{OT1}
2316 \setfont\smallerttsl\ttslshape{10}{800}{OT1TT}
2317 \font\smalleri=cmmi8
2318 \font\smallersy=cmsy8
2319 \def\smallerecsize{0800}
2320
2321 % Fonts for title page (20.4pt):
2322 \def\titlenominalsize{20pt}
2323 \setfont\titlerm\rmbshape{12}{\magstep3}{OT1}
2324 \setfont\titleit\itbshape{10}{\magstep4}{OT1IT}
2325 \setfont\titlesl\slbshape{10}{\magstep4}{OT1}
2326 \setfont\titlett\ttbshape{12}{\magstep3}{OT1TT}
2327 \setfont\titlettsl\ttslshape{10}{\magstep4}{OT1TT}
2328 \setfont\titlesf\sfbshape{17}{\magstep1}{OT1}
2329 \let\titlebf=\titlerm
2330 \setfont\titlesc\scbshape{10}{\magstep4}{OT1}
2331 \font\titlei=cmmi12 scaled \magstep3
2332 \font\titlesy=cmsy10 scaled \magstep4
2333 \def\titleecsize{2074}
2334
2335 % Chapter fonts (14.4pt).
2336 \def\chapnominalsize{14pt}
2337 \setfont\chaprm\rmbshape{12}{\magstep1}{OT1}
2338 \setfont\chapit\itbshape{10}{\magstep2}{OT1IT}
2339 \setfont\chapsl\slbshape{10}{\magstep2}{OT1}
2340 \setfont\chaptt\ttbshape{12}{\magstep1}{OT1TT}
2341 \setfont\chapttsl\ttslshape{10}{\magstep2}{OT1TT}
2342 \setfont\chapsf\sfbshape{12}{\magstep1}{OT1}
2343 \let\chapbf\chaprm
2344 \setfont\chapsc\scbshape{10}{\magstep2}{OT1}
2345 \font\chapi=cmmi12 scaled \magstep1
2346 \font\chapsy=cmsy10 scaled \magstep2
2347 \def\chapecsize{1440}
2348
2349 % Section fonts (12pt).
2350 \def\secnominalsize{12pt}
2351 \setfont\secrm\rmbshape{12}{1000}{OT1}
2352 \setfont\secit\itbshape{10}{\magstep1}{OT1IT}
2353 \setfont\secsl\slbshape{10}{\magstep1}{OT1}
2354 \setfont\sectt\ttbshape{12}{1000}{OT1TT}
2355 \setfont\secttsl\ttslshape{10}{\magstep1}{OT1TT}
2356 \setfont\secsf\sfbshape{12}{1000}{OT1}
2357 \let\secbf\secrm
2358 \setfont\secsc\scbshape{10}{\magstep1}{OT1}
2359 \font\seci=cmmi12
2360 \font\secsy=cmsy10 scaled \magstep1
2361 \def\sececsize{1200}
2362
2363 % Subsection fonts (10pt).
2364 \def\ssecnominalsize{10pt}
2365 \setfont\ssecrm\rmbshape{10}{1000}{OT1}
2366 \setfont\ssecit\itbshape{10}{1000}{OT1IT}
2367 \setfont\ssecsl\slbshape{10}{1000}{OT1}
2368 \setfont\ssectt\ttbshape{10}{1000}{OT1TT}
2369 \setfont\ssecttsl\ttslshape{10}{1000}{OT1TT}
2370 \setfont\ssecsf\sfbshape{10}{1000}{OT1}
2371 \let\ssecbf\ssecrm
2372 \setfont\ssecsc\scbshape{10}{1000}{OT1}
2373 \font\sseci=cmmi10
2374 \font\ssecsy=cmsy10
2375 \def\ssececsize{1000}
2376
2377 % Reduced fonts for @acro in text (9pt).
2378 \def\reducednominalsize{9pt}
2379 \setfont\reducedrm\rmshape{9}{1000}{OT1}
2380 \setfont\reducedtt\ttshape{9}{1000}{OT1TT}
2381 \setfont\reducedbf\bfshape{10}{900}{OT1}
2382 \setfont\reducedit\itshape{9}{1000}{OT1IT}
2383 \setfont\reducedsl\slshape{9}{1000}{OT1}
2384 \setfont\reducedsf\sfshape{9}{1000}{OT1}
2385 \setfont\reducedsc\scshape{10}{900}{OT1}
2386 \setfont\reducedttsl\ttslshape{10}{900}{OT1TT}
2387 \font\reducedi=cmmi9
2388 \font\reducedsy=cmsy9
2389 \def\reducedecsize{0900}
2390
2391 \divide\parskip by 2  % reduce space between paragraphs
2392 \textleading = 12pt   % line spacing for 10pt CM
2393 \textfonts            % reset the current fonts
2394 \rm
2395 } % end of 10pt text font size definitions, \definetextfontsizex
2396
2397
2398 % We provide the user-level command
2399 %   @fonttextsize 10
2400 % (or 11) to redefine the text font size.  pt is assumed.
2401 %
2402 \def\xiword{11}
2403 \def\xword{10}
2404 \def\xwordpt{10pt}
2405 %
2406 \parseargdef\fonttextsize{%
2407   \def\textsizearg{#1}%
2408   %\wlog{doing @fonttextsize \textsizearg}%
2409   %
2410   % Set \globaldefs so that documents can use this inside @tex, since
2411   % makeinfo 4.8 does not support it, but we need it nonetheless.
2412   %
2413  \begingroup \globaldefs=1
2414   \ifx\textsizearg\xword \definetextfontsizex
2415   \else \ifx\textsizearg\xiword \definetextfontsizexi
2416   \else
2417     \errhelp=\EMsimple
2418     \errmessage{@fonttextsize only supports `10' or `11', not `\textsizearg'}
2419   \fi\fi
2420  \endgroup
2421 }
2422
2423 % In order for the font changes to affect most math symbols and letters,
2424 % we have to define the \textfont of the standard families.  We don't
2425 % bother to reset \scriptfont and \scriptscriptfont; awaiting user need.
2426 %
2427 \def\resetmathfonts{%
2428   \textfont0=\tenrm \textfont1=\teni \textfont2=\tensy
2429   \textfont\itfam=\tenit \textfont\slfam=\tensl \textfont\bffam=\tenbf
2430   \textfont\ttfam=\tentt \textfont\sffam=\tensf
2431 }
2432
2433 % The font-changing commands redefine the meanings of \tenSTYLE, instead
2434 % of just \STYLE.  We do this because \STYLE needs to also set the
2435 % current \fam for math mode.  Our \STYLE (e.g., \rm) commands hardwire
2436 % \tenSTYLE to set the current font.
2437 %
2438 % Each font-changing command also sets the names \lsize (one size lower)
2439 % and \lllsize (three sizes lower).  These relative commands are used
2440 % in, e.g., the LaTeX logo and acronyms.
2441 %
2442 % This all needs generalizing, badly.
2443 %
2444 \def\textfonts{%
2445   \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
2446   \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
2447   \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
2448   \let\tenttsl=\textttsl
2449   \def\curfontsize{text}%
2450   \def\lsize{reduced}\def\lllsize{smaller}%
2451   \resetmathfonts \setleading{\textleading}}
2452 \def\titlefonts{%
2453   \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
2454   \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
2455   \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
2456   \let\tenttsl=\titlettsl
2457   \def\curfontsize{title}%
2458   \def\lsize{chap}\def\lllsize{subsec}%
2459   \resetmathfonts \setleading{27pt}}
2460 \def\titlefont#1{{\titlefonts\rmisbold #1}}
2461 \def\chapfonts{%
2462   \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
2463   \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
2464   \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy
2465   \let\tenttsl=\chapttsl
2466   \def\curfontsize{chap}%
2467   \def\lsize{sec}\def\lllsize{text}%
2468   \resetmathfonts \setleading{19pt}}
2469 \def\secfonts{%
2470   \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
2471   \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
2472   \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
2473   \let\tenttsl=\secttsl
2474   \def\curfontsize{sec}%
2475   \def\lsize{subsec}\def\lllsize{reduced}%
2476   \resetmathfonts \setleading{17pt}}
2477 \def\subsecfonts{%
2478   \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
2479   \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
2480   \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
2481   \let\tenttsl=\ssecttsl
2482   \def\curfontsize{ssec}%
2483   \def\lsize{text}\def\lllsize{small}%
2484   \resetmathfonts \setleading{15pt}}
2485 \let\subsubsecfonts = \subsecfonts
2486 \def\reducedfonts{%
2487   \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
2488   \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
2489   \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
2490   \let\tenttsl=\reducedttsl
2491   \def\curfontsize{reduced}%
2492   \def\lsize{small}\def\lllsize{smaller}%
2493   \resetmathfonts \setleading{10.5pt}}
2494 \def\smallfonts{%
2495   \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
2496   \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
2497   \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
2498   \let\tenttsl=\smallttsl
2499   \def\curfontsize{small}%
2500   \def\lsize{smaller}\def\lllsize{smaller}%
2501   \resetmathfonts \setleading{10.5pt}}
2502 \def\smallerfonts{%
2503   \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
2504   \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
2505   \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
2506   \let\tenttsl=\smallerttsl
2507   \def\curfontsize{smaller}%
2508   \def\lsize{smaller}\def\lllsize{smaller}%
2509   \resetmathfonts \setleading{9.5pt}}
2510
2511 % Fonts for short table of contents.
2512 \setfont\shortcontrm\rmshape{12}{1000}{OT1}
2513 \setfont\shortcontbf\bfshape{10}{\magstep1}{OT1}  % no cmb12
2514 \setfont\shortcontsl\slshape{12}{1000}{OT1}
2515 \setfont\shortconttt\ttshape{12}{1000}{OT1TT}
2516
2517 % Define these just so they can be easily changed for other fonts.
2518 \def\angleleft{$\langle$}
2519 \def\angleright{$\rangle$}
2520
2521 % Set the fonts to use with the @small... environments.
2522 \let\smallexamplefonts = \smallfonts
2523
2524 % About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
2525 % can fit this many characters:
2526 %   8.5x11=86   smallbook=72  a4=90  a5=69
2527 % If we use \scriptfonts (8pt), then we can fit this many characters:
2528 %   8.5x11=90+  smallbook=80  a4=90+  a5=77
2529 % For me, subjectively, the few extra characters that fit aren't worth
2530 % the additional smallness of 8pt.  So I'm making the default 9pt.
2531 %
2532 % By the way, for comparison, here's what fits with @example (10pt):
2533 %   8.5x11=71  smallbook=60  a4=75  a5=58
2534 % --karl, 24jan03.
2535
2536 % Set up the default fonts, so we can use them for creating boxes.
2537 %
2538 \definetextfontsizexi
2539
2540
2541 \message{markup,}
2542
2543 % Check if we are currently using a typewriter font.  Since all the
2544 % Computer Modern typewriter fonts have zero interword stretch (and
2545 % shrink), and it is reasonable to expect all typewriter fonts to have
2546 % this property, we can check that font parameter.
2547 %
2548 \def\ifmonospace{\ifdim\fontdimen3\font=0pt }
2549
2550 % Markup style infrastructure.  \defmarkupstylesetup\INITMACRO will
2551 % define and register \INITMACRO to be called on markup style changes.
2552 % \INITMACRO can check \currentmarkupstyle for the innermost
2553 % style and the set of \ifmarkupSTYLE switches for all styles
2554 % currently in effect.
2555 \newif\ifmarkupvar
2556 \newif\ifmarkupsamp
2557 \newif\ifmarkupkey
2558 %\newif\ifmarkupfile % @file == @samp.
2559 %\newif\ifmarkupoption % @option == @samp.
2560 \newif\ifmarkupcode
2561 \newif\ifmarkupkbd
2562 %\newif\ifmarkupenv % @env == @code.
2563 %\newif\ifmarkupcommand % @command == @code.
2564 \newif\ifmarkuptex % @tex (and part of @math, for now).
2565 \newif\ifmarkupexample
2566 \newif\ifmarkupverb
2567 \newif\ifmarkupverbatim
2568
2569 \let\currentmarkupstyle\empty
2570
2571 \def\setupmarkupstyle#1{%
2572   \csname markup#1true\endcsname
2573   \def\currentmarkupstyle{#1}%
2574   \markupstylesetup
2575 }
2576
2577 \let\markupstylesetup\empty
2578
2579 \def\defmarkupstylesetup#1{%
2580   \expandafter\def\expandafter\markupstylesetup
2581     \expandafter{\markupstylesetup #1}%
2582   \def#1%
2583 }
2584
2585 % Markup style setup for left and right quotes.
2586 \defmarkupstylesetup\markupsetuplq{%
2587   \expandafter\let\expandafter \temp
2588     \csname markupsetuplq\currentmarkupstyle\endcsname
2589   \ifx\temp\relax \markupsetuplqdefault \else \temp \fi
2590 }
2591
2592 \defmarkupstylesetup\markupsetuprq{%
2593   \expandafter\let\expandafter \temp
2594     \csname markupsetuprq\currentmarkupstyle\endcsname
2595   \ifx\temp\relax \markupsetuprqdefault \else \temp \fi
2596 }
2597
2598 {
2599 \catcode`\'=\active
2600 \catcode`\`=\active
2601
2602 \gdef\markupsetuplqdefault{\let`\lq}
2603 \gdef\markupsetuprqdefault{\let'\rq}
2604
2605 \gdef\markupsetcodequoteleft{\let`\codequoteleft}
2606 \gdef\markupsetcodequoteright{\let'\codequoteright}
2607 }
2608
2609 \let\markupsetuplqcode \markupsetcodequoteleft
2610 \let\markupsetuprqcode \markupsetcodequoteright
2611 %
2612 \let\markupsetuplqexample \markupsetcodequoteleft
2613 \let\markupsetuprqexample \markupsetcodequoteright
2614 %
2615 \let\markupsetuplqkbd     \markupsetcodequoteleft
2616 \let\markupsetuprqkbd     \markupsetcodequoteright
2617 %
2618 \let\markupsetuplqsamp \markupsetcodequoteleft
2619 \let\markupsetuprqsamp \markupsetcodequoteright
2620 %
2621 \let\markupsetuplqverb \markupsetcodequoteleft
2622 \let\markupsetuprqverb \markupsetcodequoteright
2623 %
2624 \let\markupsetuplqverbatim \markupsetcodequoteleft
2625 \let\markupsetuprqverbatim \markupsetcodequoteright
2626
2627 % Allow an option to not use regular directed right quote/apostrophe
2628 % (char 0x27), but instead the undirected quote from cmtt (char 0x0d).
2629 % The undirected quote is ugly, so don't make it the default, but it
2630 % works for pasting with more pdf viewers (at least evince), the
2631 % lilypond developers report.  xpdf does work with the regular 0x27.
2632 %
2633 \def\codequoteright{%
2634   \expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax
2635     \expandafter\ifx\csname SETcodequoteundirected\endcsname\relax
2636       '%
2637     \else \char'15 \fi
2638   \else \char'15 \fi
2639 }
2640 %
2641 % and a similar option for the left quote char vs. a grave accent.
2642 % Modern fonts display ASCII 0x60 as a grave accent, so some people like
2643 % the code environments to do likewise.
2644 %
2645 \def\codequoteleft{%
2646   \expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax
2647     \expandafter\ifx\csname SETcodequotebacktick\endcsname\relax
2648       % [Knuth] pp. 380,381,391
2649       % \relax disables Spanish ligatures ?` and !` of \tt font.
2650       \relax`%
2651     \else \char'22 \fi
2652   \else \char'22 \fi
2653 }
2654
2655 % Commands to set the quote options.
2656
2657 \parseargdef\codequoteundirected{%
2658   \def\temp{#1}%
2659   \ifx\temp\onword
2660     \expandafter\let\csname SETtxicodequoteundirected\endcsname
2661       = t%
2662   \else\ifx\temp\offword
2663     \expandafter\let\csname SETtxicodequoteundirected\endcsname
2664       = \relax
2665   \else
2666     \errhelp = \EMsimple
2667     \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}%
2668   \fi\fi
2669 }
2670 %
2671 \parseargdef\codequotebacktick{%
2672   \def\temp{#1}%
2673   \ifx\temp\onword
2674     \expandafter\let\csname SETtxicodequotebacktick\endcsname
2675       = t%
2676   \else\ifx\temp\offword
2677     \expandafter\let\csname SETtxicodequotebacktick\endcsname
2678       = \relax
2679   \else
2680     \errhelp = \EMsimple
2681     \errmessage{Unknown @codequotebacktick value `\temp', must be on|off}%
2682   \fi\fi
2683 }
2684
2685 % [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font.
2686 \def\noligaturesquoteleft{\relax\lq}
2687
2688 % Count depth in font-changes, for error checks
2689 \newcount\fontdepth \fontdepth=0
2690
2691 % Font commands.
2692
2693 % #1 is the font command (\sl or \it), #2 is the text to slant.
2694 % If we are in a monospaced environment, however, 1) always use \ttsl,
2695 % and 2) do not add an italic correction.
2696 \def\dosmartslant#1#2{%
2697   \ifusingtt 
2698     {{\ttsl #2}\let\next=\relax}%
2699     {\def\next{{#1#2}\futurelet\next\smartitaliccorrection}}%
2700   \next
2701 }
2702 \def\smartslanted{\dosmartslant\sl}
2703 \def\smartitalic{\dosmartslant\it}
2704
2705 % Output an italic correction unless \next (presumed to be the following
2706 % character) is such as not to need one.
2707 \def\smartitaliccorrection{%
2708   \ifx\next,%
2709   \else\ifx\next-%
2710   \else\ifx\next.%
2711   \else\ifx\next\.%
2712   \else\ifx\next\comma%
2713   \else\ptexslash
2714   \fi\fi\fi\fi\fi
2715   \aftersmartic
2716 }
2717
2718 % Unconditional use \ttsl, and no ic.  @var is set to this for defuns.
2719 \def\ttslanted#1{{\ttsl #1}}
2720
2721 % @cite is like \smartslanted except unconditionally use \sl.  We never want
2722 % ttsl for book titles, do we?
2723 \def\cite#1{{\sl #1}\futurelet\next\smartitaliccorrection}
2724
2725 \def\aftersmartic{}
2726 \def\var#1{%
2727   \let\saveaftersmartic = \aftersmartic
2728   \def\aftersmartic{\null\let\aftersmartic=\saveaftersmartic}%
2729   \smartslanted{#1}%
2730 }
2731
2732 \let\i=\smartitalic
2733 \let\slanted=\smartslanted
2734 \let\dfn=\smartslanted
2735 \let\emph=\smartitalic
2736
2737 % Explicit font changes: @r, @sc, undocumented @ii.
2738 \def\r#1{{\rm #1}}              % roman font
2739 \def\sc#1{{\smallcaps#1}}       % smallcaps font
2740 \def\ii#1{{\it #1}}             % italic font
2741
2742 % @b, explicit bold.  Also @strong.
2743 \def\b#1{{\bf #1}}
2744 \let\strong=\b
2745
2746 % @sansserif, explicit sans.
2747 \def\sansserif#1{{\sf #1}}
2748
2749 % We can't just use \exhyphenpenalty, because that only has effect at
2750 % the end of a paragraph.  Restore normal hyphenation at the end of the
2751 % group within which \nohyphenation is presumably called.
2752 %
2753 \def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
2754 \def\restorehyphenation{\hyphenchar\font = `- }
2755
2756 % Set sfcode to normal for the chars that usually have another value.
2757 % Can't use plain's \frenchspacing because it uses the `\x notation, and
2758 % sometimes \x has an active definition that messes things up.
2759 %
2760 \catcode`@=11
2761   \def\plainfrenchspacing{%
2762     \sfcode`\.=\@m \sfcode`\?=\@m \sfcode`\!=\@m
2763     \sfcode`\:=\@m \sfcode`\;=\@m \sfcode`\,=\@m
2764     \def\endofsentencespacefactor{1000}% for @. and friends
2765   }
2766   \def\plainnonfrenchspacing{%
2767     \sfcode`\.3000\sfcode`\?3000\sfcode`\!3000
2768     \sfcode`\:2000\sfcode`\;1500\sfcode`\,1250
2769     \def\endofsentencespacefactor{3000}% for @. and friends
2770   }
2771 \catcode`@=\other
2772 \def\endofsentencespacefactor{3000}% default
2773
2774 % @t, explicit typewriter.
2775 \def\t#1{%
2776   {\tt \rawbackslash \plainfrenchspacing #1}%
2777   \null
2778 }
2779
2780 % @samp.
2781 \def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}}
2782
2783 % @indicateurl is \samp, that is, with quotes.
2784 \let\indicateurl=\samp
2785
2786 % @code (and similar) prints in typewriter, but with spaces the same
2787 % size as normal in the surrounding text, without hyphenation, etc.
2788 % This is a subroutine for that.
2789 \def\tclose#1{%
2790   {%
2791     % Change normal interword space to be same as for the current font.
2792     \spaceskip = \fontdimen2\font
2793     %
2794     % Switch to typewriter.
2795     \tt
2796     %
2797     % But `\ ' produces the large typewriter interword space.
2798     \def\ {{\spaceskip = 0pt{} }}%
2799     %
2800     % Turn off hyphenation.
2801     \nohyphenation
2802     %
2803     \rawbackslash
2804     \plainfrenchspacing
2805     #1%
2806   }%
2807   \null % reset spacefactor to 1000
2808 }
2809
2810 % We *must* turn on hyphenation at `-' and `_' in @code.
2811 % (But see \codedashfinish below.)
2812 % Otherwise, it is too hard to avoid overfull hboxes
2813 % in the Emacs manual, the Library manual, etc.
2814 %
2815 % Unfortunately, TeX uses one parameter (\hyphenchar) to control
2816 % both hyphenation at - and hyphenation within words.
2817 % We must therefore turn them both off (\tclose does that)
2818 % and arrange explicitly to hyphenate at a dash. -- rms.
2819 {
2820   \catcode`\-=\active \catcode`\_=\active
2821   \catcode`\'=\active \catcode`\`=\active
2822   \global\let'=\rq \global\let`=\lq  % default definitions
2823   %
2824   \global\def\code{\begingroup
2825     \setupmarkupstyle{code}%
2826     % The following should really be moved into \setupmarkupstyle handlers.
2827     \catcode\dashChar=\active  \catcode\underChar=\active
2828     \ifallowcodebreaks
2829      \let-\codedash
2830      \let_\codeunder
2831     \else
2832      \let-\normaldash
2833      \let_\realunder
2834     \fi
2835     % Given -foo (with a single dash), we do not want to allow a break
2836     % after the hyphen.
2837     \global\let\codedashprev=\codedash
2838     %
2839     \codex
2840   }
2841   %
2842   \gdef\codedash{\futurelet\next\codedashfinish}
2843   \gdef\codedashfinish{%
2844     \normaldash % always output the dash character itself.
2845     % 
2846     % Now, output a discretionary to allow a line break, unless
2847     % (a) the next character is a -, or
2848     % (b) the preceding character is a -.
2849     % E.g., given --posix, we do not want to allow a break after either -.
2850     % Given --foo-bar, we do want to allow a break between the - and the b.
2851     \ifx\next\codedash \else
2852       \ifx\codedashprev\codedash 
2853       \else \discretionary{}{}{}\fi
2854     \fi
2855     % we need the space after the = for the case when \next itself is a
2856     % space token; it would get swallowed otherwise.  As in @code{- a}.
2857     \global\let\codedashprev= \next
2858   }
2859 }
2860 \def\normaldash{-}
2861 %
2862 \def\codex #1{\tclose{#1}\endgroup}
2863
2864 \def\codeunder{%
2865   % this is all so @math{@code{var_name}+1} can work.  In math mode, _
2866   % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
2867   % will therefore expand the active definition of _, which is us
2868   % (inside @code that is), therefore an endless loop.
2869   \ifusingtt{\ifmmode
2870                \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
2871              \else\normalunderscore \fi
2872              \discretionary{}{}{}}%
2873             {\_}%
2874 }
2875
2876 % An additional complication: the above will allow breaks after, e.g.,
2877 % each of the four underscores in __typeof__.  This is bad.
2878 % @allowcodebreaks provides a document-level way to turn breaking at -
2879 % and _ on and off.
2880 %
2881 \newif\ifallowcodebreaks  \allowcodebreakstrue
2882
2883 \def\keywordtrue{true}
2884 \def\keywordfalse{false}
2885
2886 \parseargdef\allowcodebreaks{%
2887   \def\txiarg{#1}%
2888   \ifx\txiarg\keywordtrue
2889     \allowcodebreakstrue
2890   \else\ifx\txiarg\keywordfalse
2891     \allowcodebreaksfalse
2892   \else
2893     \errhelp = \EMsimple
2894     \errmessage{Unknown @allowcodebreaks option `\txiarg', must be true|false}%
2895   \fi\fi
2896 }
2897
2898 % For @command, @env, @file, @option quotes seem unnecessary,
2899 % so use \code rather than \samp.
2900 \let\command=\code
2901 \let\env=\code
2902 \let\file=\code
2903 \let\option=\code
2904
2905 % @uref (abbreviation for `urlref') aka @url takes an optional
2906 % (comma-separated) second argument specifying the text to display and
2907 % an optional third arg as text to display instead of (rather than in
2908 % addition to) the url itself.  First (mandatory) arg is the url.
2909
2910 % TeX-only option to allow changing PDF output to show only the second
2911 % arg (if given), and not the url (which is then just the link target).
2912 \newif\ifurefurlonlylink
2913
2914 % The main macro is \urefbreak, which allows breaking at expected
2915 % places within the url.  (There used to be another version, which
2916 % didn't support automatic breaking.)
2917 \def\urefbreak{\begingroup \urefcatcodes \dourefbreak}
2918 \let\uref=\urefbreak
2919 %
2920 \def\dourefbreak#1{\urefbreakfinish #1,,,\finish}
2921 \def\urefbreakfinish#1,#2,#3,#4\finish{% doesn't work in @example
2922   \unsepspaces
2923   \pdfurl{#1}%
2924   \setbox0 = \hbox{\ignorespaces #3}%
2925   \ifdim\wd0 > 0pt
2926     \unhbox0 % third arg given, show only that
2927   \else
2928     \setbox0 = \hbox{\ignorespaces #2}% look for second arg
2929     \ifdim\wd0 > 0pt
2930       \ifpdf
2931         % For pdfTeX and LuaTeX
2932         \ifurefurlonlylink
2933           % PDF plus option to not display url, show just arg
2934           \unhbox0             
2935         \else
2936           % PDF, normally display both arg and url for consistency,
2937           % visibility, if the pdf is eventually used to print, etc.
2938           \unhbox0\ (\urefcode{#1})%
2939         \fi
2940       \else
2941         \ifx\XeTeXrevision\thisisundefined
2942           \unhbox0\ (\urefcode{#1})% DVI, always show arg and url
2943         \else
2944           % For XeTeX
2945           \ifurefurlonlylink
2946             % PDF plus option to not display url, show just arg
2947             \unhbox0             
2948           \else
2949             % PDF, normally display both arg and url for consistency,
2950             % visibility, if the pdf is eventually used to print, etc.
2951             \unhbox0\ (\urefcode{#1})%
2952           \fi
2953         \fi
2954       \fi
2955     \else
2956       \urefcode{#1}% only url given, so show it
2957     \fi
2958   \fi
2959   \endlink
2960 \endgroup}
2961
2962 % Allow line breaks around only a few characters (only).
2963 \def\urefcatcodes{%
2964   \catcode`\&=\active \catcode`\.=\active
2965   \catcode`\#=\active \catcode`\?=\active
2966   \catcode`\/=\active
2967 }
2968 {
2969   \urefcatcodes
2970   %
2971   \global\def\urefcode{\begingroup
2972     \setupmarkupstyle{code}%
2973     \urefcatcodes
2974     \let&\urefcodeamp
2975     \let.\urefcodedot
2976     \let#\urefcodehash
2977     \let?\urefcodequest
2978     \let/\urefcodeslash
2979     \codex
2980   }
2981   %
2982   % By default, they are just regular characters.
2983   \global\def&{\normalamp}
2984   \global\def.{\normaldot}
2985   \global\def#{\normalhash}
2986   \global\def?{\normalquest}
2987   \global\def/{\normalslash}
2988 }
2989
2990 % we put a little stretch before and after the breakable chars, to help
2991 % line breaking of long url's.  The unequal skips make look better in
2992 % cmtt at least, especially for dots.
2993 \def\urefprestretchamount{.13em}
2994 \def\urefpoststretchamount{.1em}
2995 \def\urefprestretch{\urefprebreak \hskip0pt plus\urefprestretchamount\relax}
2996 \def\urefpoststretch{\urefpostbreak \hskip0pt plus\urefprestretchamount\relax}
2997 %
2998 \def\urefcodeamp{\urefprestretch \&\urefpoststretch}
2999 \def\urefcodedot{\urefprestretch .\urefpoststretch}
3000 \def\urefcodehash{\urefprestretch \#\urefpoststretch}
3001 \def\urefcodequest{\urefprestretch ?\urefpoststretch}
3002 \def\urefcodeslash{\futurelet\next\urefcodeslashfinish}
3003 {
3004   \catcode`\/=\active
3005   \global\def\urefcodeslashfinish{%
3006     \urefprestretch \slashChar
3007     % Allow line break only after the final / in a sequence of
3008     % slashes, to avoid line break between the slashes in http://.
3009     \ifx\next/\else \urefpoststretch \fi
3010   }
3011 }
3012
3013 % One more complication: by default we'll break after the special
3014 % characters, but some people like to break before the special chars, so
3015 % allow that.  Also allow no breaking at all, for manual control.
3016
3017 \parseargdef\urefbreakstyle{%
3018   \def\txiarg{#1}%
3019   \ifx\txiarg\wordnone
3020     \def\urefprebreak{\nobreak}\def\urefpostbreak{\nobreak}
3021   \else\ifx\txiarg\wordbefore
3022     \def\urefprebreak{\allowbreak}\def\urefpostbreak{\nobreak}
3023   \else\ifx\txiarg\wordafter
3024     \def\urefprebreak{\nobreak}\def\urefpostbreak{\allowbreak}
3025   \else
3026     \errhelp = \EMsimple
3027     \errmessage{Unknown @urefbreakstyle setting `\txiarg'}%
3028   \fi\fi\fi
3029 }
3030 \def\wordafter{after}
3031 \def\wordbefore{before}
3032 \def\wordnone{none}
3033
3034 \urefbreakstyle after
3035
3036 % @url synonym for @uref, since that's how everyone uses it.
3037 %
3038 \let\url=\uref
3039
3040 % rms does not like angle brackets --karl, 17may97.
3041 % So now @email is just like @uref, unless we are pdf.
3042 %
3043 %\def\email#1{\angleleft{\tt #1}\angleright}
3044 \ifpdf
3045   \def\email#1{\doemail#1,,\finish}
3046   \def\doemail#1,#2,#3\finish{\begingroup
3047     \unsepspaces
3048     \pdfurl{mailto:#1}%
3049     \setbox0 = \hbox{\ignorespaces #2}%
3050     \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3051     \endlink
3052   \endgroup}
3053 \else
3054   \ifx\XeTeXrevision\thisisundefined
3055     \let\email=\uref
3056   \else
3057     \def\email#1{\doemail#1,,\finish}
3058     \def\doemail#1,#2,#3\finish{\begingroup
3059       \unsepspaces
3060       \pdfurl{mailto:#1}%
3061       \setbox0 = \hbox{\ignorespaces #2}%
3062       \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
3063       \endlink
3064     \endgroup}
3065   \fi
3066 \fi
3067
3068 % @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
3069 %   `example' (@kbd uses ttsl only inside of @example and friends),
3070 %   or `code' (@kbd uses normal tty font always).
3071 \parseargdef\kbdinputstyle{%
3072   \def\txiarg{#1}%
3073   \ifx\txiarg\worddistinct
3074     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
3075   \else\ifx\txiarg\wordexample
3076     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
3077   \else\ifx\txiarg\wordcode
3078     \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
3079   \else
3080     \errhelp = \EMsimple
3081     \errmessage{Unknown @kbdinputstyle setting `\txiarg'}%
3082   \fi\fi\fi
3083 }
3084 \def\worddistinct{distinct}
3085 \def\wordexample{example}
3086 \def\wordcode{code}
3087
3088 % Default is `distinct'.
3089 \kbdinputstyle distinct
3090
3091 % @kbd is like @code, except that if the argument is just one @key command,
3092 % then @kbd has no effect.
3093 \def\kbd#1{{\def\look{#1}\expandafter\kbdsub\look??\par}}
3094
3095 \def\xkey{\key}
3096 \def\kbdsub#1#2#3\par{%
3097   \def\one{#1}\def\three{#3}\def\threex{??}%
3098   \ifx\one\xkey\ifx\threex\three \key{#2}%
3099   \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3100   \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi
3101 }
3102
3103 % definition of @key that produces a lozenge.  Doesn't adjust to text size.
3104 %\setfont\keyrm\rmshape{8}{1000}{OT1}
3105 %\font\keysy=cmsy9
3106 %\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
3107 %  \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
3108 %    \vbox{\hrule\kern-0.4pt
3109 %     \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
3110 %    \kern-0.4pt\hrule}%
3111 %  \kern-.06em\raise0.4pt\hbox{\angleright}}}}
3112
3113 % definition of @key with no lozenge.  If the current font is already
3114 % monospace, don't change it; that way, we respect @kbdinputstyle.  But
3115 % if it isn't monospace, then use \tt.
3116 %
3117 \def\key#1{{\setupmarkupstyle{key}%
3118   \nohyphenation
3119   \ifmonospace\else\tt\fi
3120   #1}\null}
3121
3122 % @clicksequence{File @click{} Open ...}
3123 \def\clicksequence#1{\begingroup #1\endgroup}
3124
3125 % @clickstyle @arrow   (by default)
3126 \parseargdef\clickstyle{\def\click{#1}}
3127 \def\click{\arrow}
3128
3129 % Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
3130 % argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
3131 %
3132 \def\dmn#1{\thinspace #1}
3133
3134 % @acronym for "FBI", "NATO", and the like.
3135 % We print this one point size smaller, since it's intended for
3136 % all-uppercase.
3137 %
3138 \def\acronym#1{\doacronym #1,,\finish}
3139 \def\doacronym#1,#2,#3\finish{%
3140   {\selectfonts\lsize #1}%
3141   \def\temp{#2}%
3142   \ifx\temp\empty \else
3143     \space ({\unsepspaces \ignorespaces \temp \unskip})%
3144   \fi
3145   \null % reset \spacefactor=1000
3146 }
3147
3148 % @abbr for "Comput. J." and the like.
3149 % No font change, but don't do end-of-sentence spacing.
3150 %
3151 \def\abbr#1{\doabbr #1,,\finish}
3152 \def\doabbr#1,#2,#3\finish{%
3153   {\plainfrenchspacing #1}%
3154   \def\temp{#2}%
3155   \ifx\temp\empty \else
3156     \space ({\unsepspaces \ignorespaces \temp \unskip})%
3157   \fi
3158   \null % reset \spacefactor=1000
3159 }
3160
3161 % @asis just yields its argument.  Used with @table, for example.
3162 %
3163 \def\asis#1{#1}
3164
3165 % @math outputs its argument in math mode.
3166 %
3167 % One complication: _ usually means subscripts, but it could also mean
3168 % an actual _ character, as in @math{@var{some_variable} + 1}.  So make
3169 % _ active, and distinguish by seeing if the current family is \slfam,
3170 % which is what @var uses.
3171 {
3172   \catcode`\_ = \active
3173   \gdef\mathunderscore{%
3174     \catcode`\_=\active
3175     \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
3176   }
3177 }
3178 % Another complication: we want \\ (and @\) to output a math (or tt) \.
3179 % FYI, plain.tex uses \\ as a temporary control sequence (for no
3180 % particular reason), but this is not advertised and we don't care.
3181 %
3182 % The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
3183 \def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
3184 %
3185 \def\math{%
3186   \ifmmode\else % only go into math if not in math mode already
3187     \tex
3188     \mathunderscore
3189     \let\\ = \mathbackslash
3190     \mathactive
3191     % make the texinfo accent commands work in math mode
3192     \let\"=\ddot
3193     \let\'=\acute
3194     \let\==\bar
3195     \let\^=\hat
3196     \let\`=\grave
3197     \let\u=\breve
3198     \let\v=\check
3199     \let\~=\tilde
3200     \let\dotaccent=\dot
3201     % have to provide another name for sup operator
3202     \let\mathopsup=\sup
3203   $\expandafter\finishmath\fi
3204 }
3205 \def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
3206
3207 % Some active characters (such as <) are spaced differently in math.
3208 % We have to reset their definitions in case the @math was an argument
3209 % to a command which sets the catcodes (such as @item or @section).
3210 %
3211 {
3212   \catcode`^ = \active
3213   \catcode`< = \active
3214   \catcode`> = \active
3215   \catcode`+ = \active
3216   \catcode`' = \active
3217   \gdef\mathactive{%
3218     \let^ = \ptexhat
3219     \let< = \ptexless
3220     \let> = \ptexgtr
3221     \let+ = \ptexplus
3222     \let' = \ptexquoteright
3223   }
3224 }
3225
3226 % for @sub and @sup, if in math mode, just do a normal sub/superscript.
3227 % If in text, use math to place as sub/superscript, but switch
3228 % into text mode, with smaller fonts.  This is a different font than the
3229 % one used for real math sub/superscripts (8pt vs. 7pt), but let's not
3230 % fix it (significant additions to font machinery) until someone notices.
3231 %
3232 \def\sub{\ifmmode \expandafter\sb \else \expandafter\finishsub\fi}
3233 \def\finishsub#1{$\sb{\hbox{\selectfonts\lllsize #1}}$}%
3234 %
3235 \def\sup{\ifmmode \expandafter\ptexsp \else \expandafter\finishsup\fi}
3236 \def\finishsup#1{$\ptexsp{\hbox{\selectfonts\lllsize #1}}$}%
3237
3238 % @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}.
3239 % Ignore unless FMTNAME == tex; then it is like @iftex and @tex,
3240 % except specified as a normal braced arg, so no newlines to worry about.
3241
3242 \def\outfmtnametex{tex}
3243 %
3244 \long\def\inlinefmt#1{\doinlinefmt #1,\finish}
3245 \long\def\doinlinefmt#1,#2,\finish{%
3246   \def\inlinefmtname{#1}%
3247   \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\fi
3248 }
3249
3250 % @inlinefmtifelse{FMTNAME,THEN-TEXT,ELSE-TEXT} expands THEN-TEXT if
3251 % FMTNAME is tex, else ELSE-TEXT.
3252 \long\def\inlinefmtifelse#1{\doinlinefmtifelse #1,,,\finish}
3253 \long\def\doinlinefmtifelse#1,#2,#3,#4,\finish{%
3254   \def\inlinefmtname{#1}%
3255   \ifx\inlinefmtname\outfmtnametex \ignorespaces #2\else \ignorespaces #3\fi
3256 }
3257 %
3258 % For raw, must switch into @tex before parsing the argument, to avoid
3259 % setting catcodes prematurely.  Doing it this way means that, for
3260 % example, @inlineraw{html, foo{bar} gets a parse error instead of being
3261 % ignored.  But this isn't important because if people want a literal
3262 % *right* brace they would have to use a command anyway, so they may as
3263 % well use a command to get a left brace too.  We could re-use the
3264 % delimiter character idea from \verb, but it seems like overkill.
3265
3266 \long\def\inlineraw{\tex \doinlineraw}
3267 \long\def\doinlineraw#1{\doinlinerawtwo #1,\finish}
3268 \def\doinlinerawtwo#1,#2,\finish{%
3269   \def\inlinerawname{#1}%
3270   \ifx\inlinerawname\outfmtnametex \ignorespaces #2\fi
3271   \endgroup % close group opened by \tex.
3272 }
3273
3274 % @inlineifset{VAR, TEXT} expands TEXT if VAR is @set.
3275 %
3276 \long\def\inlineifset#1{\doinlineifset #1,\finish}
3277 \long\def\doinlineifset#1,#2,\finish{%
3278   \def\inlinevarname{#1}%
3279   \expandafter\ifx\csname SET\inlinevarname\endcsname\relax
3280   \else\ignorespaces#2\fi
3281 }
3282
3283 % @inlineifclear{VAR, TEXT} expands TEXT if VAR is not @set.
3284 %
3285 \long\def\inlineifclear#1{\doinlineifclear #1,\finish}
3286 \long\def\doinlineifclear#1,#2,\finish{%
3287   \def\inlinevarname{#1}%
3288   \expandafter\ifx\csname SET\inlinevarname\endcsname\relax \ignorespaces#2\fi
3289 }
3290
3291
3292 \message{glyphs,}
3293 % and logos.
3294
3295 % @@ prints an @, as does @atchar{}.
3296 \def\@{\char64 }
3297 \let\atchar=\@
3298
3299 % @{ @} @lbracechar{} @rbracechar{} all generate brace characters.
3300 % Unless we're in typewriter, use \ecfont because the CM text fonts do
3301 % not have braces, and we don't want to switch into math.
3302 \def\mylbrace{{\ifmonospace\char123\else\ensuremath\lbrace\fi}}
3303 \def\myrbrace{{\ifmonospace\char125\else\ensuremath\rbrace\fi}}
3304 \let\{=\mylbrace \let\lbracechar=\{
3305 \let\}=\myrbrace \let\rbracechar=\}
3306 \begingroup
3307   % Definitions to produce \{ and \} commands for indices,
3308   % and @{ and @} for the aux/toc files.
3309   \catcode`\{ = \other \catcode`\} = \other
3310   \catcode`\[ = 1 \catcode`\] = 2
3311   \catcode`\! = 0 \catcode`\\ = \other
3312   !gdef!lbracecmd[\{]%
3313   !gdef!rbracecmd[\}]%
3314   !gdef!lbraceatcmd[@{]%
3315   !gdef!rbraceatcmd[@}]%
3316 !endgroup
3317
3318 % @comma{} to avoid , parsing problems.
3319 \let\comma = ,
3320
3321 % Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
3322 % Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
3323 \let\, = \ptexc
3324 \let\dotaccent = \ptexdot
3325 \def\ringaccent#1{{\accent23 #1}}
3326 \let\tieaccent = \ptext
3327 \let\ubaraccent = \ptexb
3328 \let\udotaccent = \d
3329
3330 % Other special characters: @questiondown @exclamdown @ordf @ordm
3331 % Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
3332 \def\questiondown{?`}
3333 \def\exclamdown{!`}
3334 \def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
3335 \def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
3336
3337 % Dotless i and dotless j, used for accents.
3338 \def\imacro{i}
3339 \def\jmacro{j}
3340 \def\dotless#1{%
3341   \def\temp{#1}%
3342   \ifx\temp\imacro \ifmmode\imath \else\ptexi \fi
3343   \else\ifx\temp\jmacro \ifmmode\jmath \else\j \fi
3344   \else \errmessage{@dotless can be used only with i or j}%
3345   \fi\fi
3346 }
3347
3348 % The \TeX{} logo, as in plain, but resetting the spacing so that a
3349 % period following counts as ending a sentence.  (Idea found in latex.)
3350 %
3351 \edef\TeX{\TeX \spacefactor=1000 }
3352
3353 % @LaTeX{} logo.  Not quite the same results as the definition in
3354 % latex.ltx, since we use a different font for the raised A; it's most
3355 % convenient for us to use an explicitly smaller font, rather than using
3356 % the \scriptstyle font (since we don't reset \scriptstyle and
3357 % \scriptscriptstyle).
3358 %
3359 \def\LaTeX{%
3360   L\kern-.36em
3361   {\setbox0=\hbox{T}%
3362    \vbox to \ht0{\hbox{%
3363      \ifx\textnominalsize\xwordpt
3364        % for 10pt running text, \lllsize (8pt) is too small for the A in LaTeX.
3365        % Revert to plain's \scriptsize, which is 7pt.
3366        \count255=\the\fam $\fam\count255 \scriptstyle A$%
3367      \else
3368        % For 11pt, we can use our lllsize.
3369        \selectfonts\lllsize A%
3370      \fi
3371      }%
3372      \vss
3373   }}%
3374   \kern-.15em
3375   \TeX
3376 }
3377
3378 % Some math mode symbols.  Define \ensuremath to switch into math mode
3379 % unless we are already there.  Expansion tricks may not be needed here,
3380 % but safer, and can't hurt.
3381 \def\ensuremath{\ifmmode \expandafter\asis \else\expandafter\ensuredmath \fi}
3382 \def\ensuredmath#1{$\relax#1$}
3383 %
3384 \def\bullet{\ensuremath\ptexbullet}
3385 \def\geq{\ensuremath\ge}
3386 \def\leq{\ensuremath\le}
3387 \def\minus{\ensuremath-}
3388
3389 % @dots{} outputs an ellipsis using the current font.
3390 % We do .5em per period so that it has the same spacing in the cm
3391 % typewriter fonts as three actual period characters; on the other hand,
3392 % in other typewriter fonts three periods are wider than 1.5em.  So do
3393 % whichever is larger.
3394 %
3395 \def\dots{%
3396   \leavevmode
3397   \setbox0=\hbox{...}% get width of three periods
3398   \ifdim\wd0 > 1.5em
3399     \dimen0 = \wd0
3400   \else
3401     \dimen0 = 1.5em
3402   \fi
3403   \hbox to \dimen0{%
3404     \hskip 0pt plus.25fil
3405     .\hskip 0pt plus1fil
3406     .\hskip 0pt plus1fil
3407     .\hskip 0pt plus.5fil
3408   }%
3409 }
3410
3411 % @enddots{} is an end-of-sentence ellipsis.
3412 %
3413 \def\enddots{%
3414   \dots
3415   \spacefactor=\endofsentencespacefactor
3416 }
3417
3418 % @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
3419 %
3420 % Since these characters are used in examples, they should be an even number of
3421 % \tt widths. Each \tt character is 1en, so two makes it 1em.
3422 %
3423 \def\point{$\star$}
3424 \def\arrow{\leavevmode\raise.05ex\hbox to 1em{\hfil$\rightarrow$\hfil}}
3425 \def\result{\leavevmode\raise.05ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
3426 \def\expansion{\leavevmode\hbox to 1em{\hfil$\mapsto$\hfil}}
3427 \def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
3428 \def\equiv{\leavevmode\hbox to 1em{\hfil$\ptexequiv$\hfil}}
3429
3430 % The @error{} command.
3431 % Adapted from the TeXbook's \boxit.
3432 %
3433 \newbox\errorbox
3434 %
3435 {\tentt \global\dimen0 = 3em}% Width of the box.
3436 \dimen2 = .55pt % Thickness of rules
3437 % The text. (`r' is open on the right, `e' somewhat less so on the left.)
3438 \setbox0 = \hbox{\kern-.75pt \reducedsf \putworderror\kern-1.5pt}
3439 %
3440 \setbox\errorbox=\hbox to \dimen0{\hfil
3441    \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
3442    \advance\hsize by -2\dimen2 % Rules.
3443    \vbox{%
3444       \hrule height\dimen2
3445       \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
3446          \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
3447          \kern3pt\vrule width\dimen2}% Space to right.
3448       \hrule height\dimen2}
3449     \hfil}
3450 %
3451 \def\error{\leavevmode\lower.7ex\copy\errorbox}
3452
3453 % @pounds{} is a sterling sign, which Knuth put in the CM italic font.
3454 %
3455 \def\pounds{{\it\$}}
3456
3457 % @euro{} comes from a separate font, depending on the current style.
3458 % We use the free feym* fonts from the eurosym package by Henrik
3459 % Theiling, which support regular, slanted, bold and bold slanted (and
3460 % "outlined" (blackboard board, sort of) versions, which we don't need).
3461 % It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
3462 %
3463 % Although only regular is the truly official Euro symbol, we ignore
3464 % that.  The Euro is designed to be slightly taller than the regular
3465 % font height.
3466 %
3467 % feymr - regular
3468 % feymo - slanted
3469 % feybr - bold
3470 % feybo - bold slanted
3471 %
3472 % There is no good (free) typewriter version, to my knowledge.
3473 % A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
3474 % Hmm.
3475 %
3476 % Also doesn't work in math.  Do we need to do math with euro symbols?
3477 % Hope not.
3478 %
3479 %
3480 \def\euro{{\eurofont e}}
3481 \def\eurofont{%
3482   % We set the font at each command, rather than predefining it in
3483   % \textfonts and the other font-switching commands, so that
3484   % installations which never need the symbol don't have to have the
3485   % font installed.
3486   %
3487   % There is only one designed size (nominal 10pt), so we always scale
3488   % that to the current nominal size.
3489   %
3490   % By the way, simply using "at 1em" works for cmr10 and the like, but
3491   % does not work for cmbx10 and other extended/shrunken fonts.
3492   %
3493   \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
3494   %
3495   \ifx\curfontstyle\bfstylename
3496     % bold:
3497     \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
3498   \else
3499     % regular:
3500     \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
3501   \fi
3502   \thiseurofont
3503 }
3504
3505 % Glyphs from the EC fonts.  We don't use \let for the aliases, because
3506 % sometimes we redefine the original macro, and the alias should reflect
3507 % the redefinition.
3508 %
3509 % Use LaTeX names for the Icelandic letters.
3510 \def\DH{{\ecfont \char"D0}} % Eth
3511 \def\dh{{\ecfont \char"F0}} % eth
3512 \def\TH{{\ecfont \char"DE}} % Thorn
3513 \def\th{{\ecfont \char"FE}} % thorn
3514 %
3515 \def\guillemetleft{{\ecfont \char"13}}
3516 \def\guillemotleft{\guillemetleft}
3517 \def\guillemetright{{\ecfont \char"14}}
3518 \def\guillemotright{\guillemetright}
3519 \def\guilsinglleft{{\ecfont \char"0E}}
3520 \def\guilsinglright{{\ecfont \char"0F}}
3521 \def\quotedblbase{{\ecfont \char"12}}
3522 \def\quotesinglbase{{\ecfont \char"0D}}
3523 %
3524 % This positioning is not perfect (see the ogonek LaTeX package), but
3525 % we have the precomposed glyphs for the most common cases.  We put the
3526 % tests to use those glyphs in the single \ogonek macro so we have fewer
3527 % dummy definitions to worry about for index entries, etc.
3528 %
3529 % ogonek is also used with other letters in Lithuanian (IOU), but using
3530 % the precomposed glyphs for those is not so easy since they aren't in
3531 % the same EC font.
3532 \def\ogonek#1{{%
3533   \def\temp{#1}%
3534   \ifx\temp\macrocharA\Aogonek
3535   \else\ifx\temp\macrochara\aogonek
3536   \else\ifx\temp\macrocharE\Eogonek
3537   \else\ifx\temp\macrochare\eogonek
3538   \else
3539     \ecfont \setbox0=\hbox{#1}%
3540     \ifdim\ht0=1ex\accent"0C #1%
3541     \else\ooalign{\unhbox0\crcr\hidewidth\char"0C \hidewidth}%
3542     \fi
3543   \fi\fi\fi\fi
3544   }%
3545 }
3546 \def\Aogonek{{\ecfont \char"81}}\def\macrocharA{A}
3547 \def\aogonek{{\ecfont \char"A1}}\def\macrochara{a}
3548 \def\Eogonek{{\ecfont \char"86}}\def\macrocharE{E}
3549 \def\eogonek{{\ecfont \char"A6}}\def\macrochare{e}
3550 %
3551 % Use the European Computer Modern fonts (cm-super in outline format)
3552 % for non-CM glyphs.  That is ec* for regular text and tc* for the text
3553 % companion symbols (LaTeX TS1 encoding).  Both are part of the ec
3554 % package and follow the same conventions.
3555
3556 \def\ecfont{\etcfont{e}}
3557 \def\tcfont{\etcfont{t}}
3558 %
3559 \def\etcfont#1{%
3560   % We can't distinguish serif/sans and italic/slanted, but this
3561   % is used for crude hacks anyway (like adding French and German
3562   % quotes to documents typeset with CM, where we lose kerning), so
3563   % hopefully nobody will notice/care.
3564   \edef\ecsize{\csname\curfontsize ecsize\endcsname}%
3565   \edef\nominalsize{\csname\curfontsize nominalsize\endcsname}%
3566   \ifmonospace
3567     % typewriter:
3568     \font\thisecfont = #1ctt\ecsize \space at \nominalsize
3569   \else
3570     \ifx\curfontstyle\bfstylename
3571       % bold:
3572       \font\thisecfont = #1cb\ifusingit{i}{x}\ecsize \space at \nominalsize
3573     \else
3574       % regular:
3575       \font\thisecfont = #1c\ifusingit{ti}{rm}\ecsize \space at \nominalsize
3576     \fi
3577   \fi
3578   \thisecfont
3579 }
3580
3581 % @registeredsymbol - R in a circle.  The font for the R should really
3582 % be smaller yet, but lllsize is the best we can do for now.
3583 % Adapted from the plain.tex definition of \copyright.
3584 %
3585 \def\registeredsymbol{%
3586   $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
3587                \hfil\crcr\Orb}}%
3588     }$%
3589 }
3590
3591 % @textdegree - the normal degrees sign.
3592 %
3593 \def\textdegree{$^\circ$}
3594
3595 % Laurent Siebenmann reports \Orb undefined with:
3596 %  Textures 1.7.7 (preloaded format=plain 93.10.14)  (68K)  16 APR 2004 02:38
3597 % so we'll define it if necessary.
3598 %
3599 \ifx\Orb\thisisundefined
3600 \def\Orb{\mathhexbox20D}
3601 \fi
3602
3603 % Quotes.
3604 \chardef\quotedblleft="5C
3605 \chardef\quotedblright=`\"
3606 \chardef\quoteleft=`\`
3607 \chardef\quoteright=`\'
3608
3609
3610 \message{page headings,}
3611
3612 \newskip\titlepagetopglue \titlepagetopglue = 1.5in
3613 \newskip\titlepagebottomglue \titlepagebottomglue = 2pc
3614
3615 % First the title page.  Must do @settitle before @titlepage.
3616 \newif\ifseenauthor
3617 \newif\iffinishedtitlepage
3618
3619 % @setcontentsaftertitlepage used to do an implicit @contents or
3620 % @shortcontents after @end titlepage, but it is now obsolete.
3621 \def\setcontentsaftertitlepage{%
3622   \errmessage{@setcontentsaftertitlepage has been removed as a Texinfo
3623               command; move your @contents command if you want the contents
3624               after the title page.}}%
3625 \def\setshortcontentsaftertitlepage{%
3626   \errmessage{@setshortcontentsaftertitlepage has been removed as a Texinfo
3627               command; move your @shortcontents and @contents commands if you 
3628               want the contents after the title page.}}%
3629
3630 \parseargdef\shorttitlepage{%
3631   \begingroup \hbox{}\vskip 1.5in \chaprm \centerline{#1}%
3632   \endgroup\page\hbox{}\page}
3633
3634 \envdef\titlepage{%
3635   % Open one extra group, as we want to close it in the middle of \Etitlepage.
3636   \begingroup
3637     \parindent=0pt \textfonts
3638     % Leave some space at the very top of the page.
3639     \vglue\titlepagetopglue
3640     % No rule at page bottom unless we print one at the top with @title.
3641     \finishedtitlepagetrue
3642     %
3643     % Most title ``pages'' are actually two pages long, with space
3644     % at the top of the second.  We don't want the ragged left on the second.
3645     \let\oldpage = \page
3646     \def\page{%
3647       \iffinishedtitlepage\else
3648          \finishtitlepage
3649       \fi
3650       \let\page = \oldpage
3651       \page
3652       \null
3653     }%
3654 }
3655
3656 \def\Etitlepage{%
3657     \iffinishedtitlepage\else
3658         \finishtitlepage
3659     \fi
3660     % It is important to do the page break before ending the group,
3661     % because the headline and footline are only empty inside the group.
3662     % If we use the new definition of \page, we always get a blank page
3663     % after the title page, which we certainly don't want.
3664     \oldpage
3665   \endgroup
3666   %
3667   % Need this before the \...aftertitlepage checks so that if they are
3668   % in effect the toc pages will come out with page numbers.
3669   \HEADINGSon
3670 }
3671
3672 \def\finishtitlepage{%
3673   \vskip4pt \hrule height 2pt width \hsize
3674   \vskip\titlepagebottomglue
3675   \finishedtitlepagetrue
3676 }
3677
3678 % Settings used for typesetting titles: no hyphenation, no indentation,
3679 % don't worry much about spacing, ragged right.  This should be used
3680 % inside a \vbox, and fonts need to be set appropriately first.  Because
3681 % it is always used for titles, nothing else, we call \rmisbold.  \par
3682 % should be specified before the end of the \vbox, since a vbox is a group.
3683
3684 \def\raggedtitlesettings{%
3685   \rmisbold
3686   \hyphenpenalty=10000
3687   \parindent=0pt
3688   \tolerance=5000
3689   \ptexraggedright
3690 }
3691
3692 % Macros to be used within @titlepage:
3693
3694 \let\subtitlerm=\tenrm
3695 \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
3696
3697 \parseargdef\title{%
3698   \checkenv\titlepage
3699   \vbox{\titlefonts \raggedtitlesettings #1\par}%
3700   % print a rule at the page bottom also.
3701   \finishedtitlepagefalse
3702   \vskip4pt \hrule height 4pt width \hsize \vskip4pt
3703 }
3704
3705 \parseargdef\subtitle{%
3706   \checkenv\titlepage
3707   {\subtitlefont \rightline{#1}}%
3708 }
3709
3710 % @author should come last, but may come many times.
3711 % It can also be used inside @quotation.
3712 %
3713 \parseargdef\author{%
3714   \def\temp{\quotation}%
3715   \ifx\thisenv\temp
3716     \def\quotationauthor{#1}% printed in \Equotation.
3717   \else
3718     \checkenv\titlepage
3719     \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
3720     {\secfonts\rmisbold \leftline{#1}}%
3721   \fi
3722 }
3723
3724
3725 % Set up page headings and footings.
3726
3727 \let\thispage=\folio
3728
3729 \newtoks\evenheadline    % headline on even pages
3730 \newtoks\oddheadline     % headline on odd pages
3731 \newtoks\evenfootline    % footline on even pages
3732 \newtoks\oddfootline     % footline on odd pages
3733
3734 % Now make \makeheadline and \makefootline in Plain TeX use those variables
3735 \headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
3736                             \else \the\evenheadline \fi}}
3737 \footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
3738                             \else \the\evenfootline \fi}\HEADINGShook}
3739 \let\HEADINGShook=\relax
3740
3741 % Commands to set those variables.
3742 % For example, this is what  @headings on  does
3743 % @evenheading @thistitle|@thispage|@thischapter
3744 % @oddheading @thischapter|@thispage|@thistitle
3745 % @evenfooting @thisfile||
3746 % @oddfooting ||@thisfile
3747
3748
3749 \def\evenheading{\parsearg\evenheadingxxx}
3750 \def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
3751 \def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
3752 \global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3753
3754 \def\oddheading{\parsearg\oddheadingxxx}
3755 \def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
3756 \def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
3757 \global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3758
3759 \parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
3760
3761 \def\evenfooting{\parsearg\evenfootingxxx}
3762 \def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
3763 \def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
3764 \global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
3765
3766 \def\oddfooting{\parsearg\oddfootingxxx}
3767 \def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
3768 \def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
3769   \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
3770   %
3771   % Leave some space for the footline.  Hopefully ok to assume
3772   % @evenfooting will not be used by itself.
3773   \global\advance\txipageheight by -12pt
3774   \global\advance\vsize by -12pt
3775 }
3776
3777 \parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
3778
3779 % @evenheadingmarks top     \thischapter <- chapter at the top of a page
3780 % @evenheadingmarks bottom  \thischapter <- chapter at the bottom of a page
3781 %
3782 % The same set of arguments for:
3783 %
3784 % @oddheadingmarks
3785 % @evenfootingmarks
3786 % @oddfootingmarks
3787 % @everyheadingmarks
3788 % @everyfootingmarks
3789
3790 % These define \getoddheadingmarks, \getevenheadingmarks,
3791 % \getoddfootingmarks, and \getevenfootingmarks, each to one of
3792 % \gettopheadingmarks, \getbottomheadingmarks.
3793 %
3794 \def\evenheadingmarks{\headingmarks{even}{heading}}
3795 \def\oddheadingmarks{\headingmarks{odd}{heading}}
3796 \def\evenfootingmarks{\headingmarks{even}{footing}}
3797 \def\oddfootingmarks{\headingmarks{odd}{footing}}
3798 \parseargdef\everyheadingmarks{\headingmarks{even}{heading}{#1}
3799                           \headingmarks{odd}{heading}{#1} }
3800 \parseargdef\everyfootingmarks{\headingmarks{even}{footing}{#1}
3801                           \headingmarks{odd}{footing}{#1} }
3802 % #1 = even/odd, #2 = heading/footing, #3 = top/bottom.
3803 \def\headingmarks#1#2#3 {%
3804   \expandafter\let\expandafter\temp \csname get#3headingmarks\endcsname
3805   \global\expandafter\let\csname get#1#2marks\endcsname \temp
3806 }
3807
3808 \everyheadingmarks bottom
3809 \everyfootingmarks bottom
3810
3811 % @headings double      turns headings on for double-sided printing.
3812 % @headings single      turns headings on for single-sided printing.
3813 % @headings off         turns them off.
3814 % @headings on          same as @headings double, retained for compatibility.
3815 % @headings after       turns on double-sided headings after this page.
3816 % @headings doubleafter turns on double-sided headings after this page.
3817 % @headings singleafter turns on single-sided headings after this page.
3818 % By default, they are off at the start of a document,
3819 % and turned `on' after @end titlepage.
3820
3821 \parseargdef\headings{\csname HEADINGS#1\endcsname}
3822
3823 \def\headingsoff{% non-global headings elimination
3824   \evenheadline={\hfil}\evenfootline={\hfil}%
3825    \oddheadline={\hfil}\oddfootline={\hfil}%
3826 }
3827
3828 \def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting
3829 \HEADINGSoff  % it's the default
3830
3831 % When we turn headings on, set the page number to 1.
3832 % For double-sided printing, put current file name in lower left corner,
3833 % chapter name on inside top of right hand pages, document
3834 % title on inside top of left hand pages, and page numbers on outside top
3835 % edge of all pages.
3836 \def\HEADINGSdouble{%
3837 \global\pageno=1
3838 \global\evenfootline={\hfil}
3839 \global\oddfootline={\hfil}
3840 \global\evenheadline={\line{\folio\hfil\thistitle}}
3841 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3842 \global\let\contentsalignmacro = \chapoddpage
3843 }
3844 \let\contentsalignmacro = \chappager
3845
3846 % For single-sided printing, chapter title goes across top left of page,
3847 % page number on top right.
3848 \def\HEADINGSsingle{%
3849 \global\pageno=1
3850 \global\evenfootline={\hfil}
3851 \global\oddfootline={\hfil}
3852 \global\evenheadline={\line{\thischapterheading\hfil\folio}}
3853 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3854 \global\let\contentsalignmacro = \chappager
3855 }
3856 \def\HEADINGSon{\HEADINGSdouble}
3857
3858 \def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
3859 \let\HEADINGSdoubleafter=\HEADINGSafter
3860 \def\HEADINGSdoublex{%
3861 \global\evenfootline={\hfil}
3862 \global\oddfootline={\hfil}
3863 \global\evenheadline={\line{\folio\hfil\thistitle}}
3864 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3865 \global\let\contentsalignmacro = \chapoddpage
3866 }
3867
3868 \def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
3869 \def\HEADINGSsinglex{%
3870 \global\evenfootline={\hfil}
3871 \global\oddfootline={\hfil}
3872 \global\evenheadline={\line{\thischapterheading\hfil\folio}}
3873 \global\oddheadline={\line{\thischapterheading\hfil\folio}}
3874 \global\let\contentsalignmacro = \chappager
3875 }
3876
3877 % Subroutines used in generating headings
3878 % This produces Day Month Year style of output.
3879 % Only define if not already defined, in case a txi-??.tex file has set
3880 % up a different format (e.g., txi-cs.tex does this).
3881 \ifx\today\thisisundefined
3882 \def\today{%
3883   \number\day\space
3884   \ifcase\month
3885   \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
3886   \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
3887   \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
3888   \fi
3889   \space\number\year}
3890 \fi
3891
3892 % @settitle line...  specifies the title of the document, for headings.
3893 % It generates no output of its own.
3894 \def\thistitle{\putwordNoTitle}
3895 \def\settitle{\parsearg{\gdef\thistitle}}
3896
3897
3898 \message{tables,}
3899 % Tables -- @table, @ftable, @ktable, @vtable, @item(x).
3900
3901 % default indentation of table text
3902 \newdimen\tableindent \tableindent=.8in
3903 % default indentation of @itemize and @enumerate text
3904 \newdimen\itemindent  \itemindent=.3in
3905 % margin between end of table item and start of table text.
3906 \newdimen\itemmargin  \itemmargin=.1in
3907
3908 % used internally for \itemindent minus \itemmargin
3909 \newdimen\itemmax
3910
3911 % Note @table, @ftable, @ktable and @vtable define @item, @itemx, etc., with
3912 % these defs.
3913 % They also define \itemindex
3914 % to index the item name in whatever manner is desired (perhaps none).
3915
3916 \newif\ifitemxneedsnegativevskip
3917
3918 \def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
3919
3920 \def\internalBitem{\smallbreak \parsearg\itemzzz}
3921 \def\internalBitemx{\itemxpar \parsearg\itemzzz}
3922
3923 \def\itemzzz #1{\begingroup %
3924   \advance\hsize by -\rightskip
3925   \advance\hsize by -\tableindent
3926   \setbox0=\hbox{\itemindicate{#1}}%
3927   \itemindex{#1}%
3928   \nobreak % This prevents a break before @itemx.
3929   %
3930   % If the item text does not fit in the space we have, put it on a line
3931   % by itself, and do not allow a page break either before or after that
3932   % line.  We do not start a paragraph here because then if the next
3933   % command is, e.g., @kindex, the whatsit would get put into the
3934   % horizontal list on a line by itself, resulting in extra blank space.
3935   \ifdim \wd0>\itemmax
3936     %
3937     % Make this a paragraph so we get the \parskip glue and wrapping,
3938     % but leave it ragged-right.
3939     \begingroup
3940       \advance\leftskip by-\tableindent
3941       \advance\hsize by\tableindent
3942       \advance\rightskip by0pt plus1fil\relax
3943       \leavevmode\unhbox0\par
3944     \endgroup
3945     %
3946     % We're going to be starting a paragraph, but we don't want the
3947     % \parskip glue -- logically it's part of the @item we just started.
3948     \nobreak \vskip-\parskip
3949     %
3950     % Stop a page break at the \parskip glue coming up.  However, if
3951     % what follows is an environment such as @example, there will be no
3952     % \parskip glue; then the negative vskip we just inserted would
3953     % cause the example and the item to crash together.  So we use this
3954     % bizarre value of 10001 as a signal to \aboveenvbreak to insert
3955     % \parskip glue after all.  Section titles are handled this way also.
3956     %
3957     \penalty 10001
3958     \endgroup
3959     \itemxneedsnegativevskipfalse
3960   \else
3961     % The item text fits into the space.  Start a paragraph, so that the
3962     % following text (if any) will end up on the same line.
3963     \noindent
3964     % Do this with kerns and \unhbox so that if there is a footnote in
3965     % the item text, it can migrate to the main vertical list and
3966     % eventually be printed.
3967     \nobreak\kern-\tableindent
3968     \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
3969     \unhbox0
3970     \nobreak\kern\dimen0
3971     \endgroup
3972     \itemxneedsnegativevskiptrue
3973   \fi
3974 }
3975
3976 \def\item{\errmessage{@item while not in a list environment}}
3977 \def\itemx{\errmessage{@itemx while not in a list environment}}
3978
3979 % @table, @ftable, @ktable, @vtable.
3980 \envdef\table{%
3981   \let\itemindex\gobble
3982   \tablecheck{table}%
3983 }
3984 \envdef\ftable{%
3985   \def\itemindex ##1{\doind {fn}{\code{##1}}}%
3986   \tablecheck{ftable}%
3987 }
3988 \envdef\ktable{%
3989   \def\itemindex ##1{\doind {ky}{\code{##1}}}%
3990   \tablecheck{ktable}%
3991 }
3992 \envdef\vtable{%
3993   \def\itemindex ##1{\doind {vr}{\code{##1}}}%
3994   \tablecheck{vtable}%
3995 }
3996 \def\tablecheck#1{%
3997   \ifnum \the\catcode`\^^M=\active
3998     \endgroup
3999     \errmessage{This command won't work in this context; perhaps the problem is
4000       that we are \inenvironment\thisenv}%
4001     \def\next{\doignore{#1}}%
4002   \else
4003     \let\next\tablex
4004   \fi
4005   \next
4006 }
4007 \def\tablex#1{%
4008   \def\itemindicate{#1}%
4009   \parsearg\tabley
4010 }
4011 \def\tabley#1{%
4012   {%
4013     \makevalueexpandable
4014     \edef\temp{\noexpand\tablez #1\space\space\space}%
4015     \expandafter
4016   }\temp \endtablez
4017 }
4018 \def\tablez #1 #2 #3 #4\endtablez{%
4019   \aboveenvbreak
4020   \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
4021   \ifnum 0#2>0 \tableindent=#2\mil \fi
4022   \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
4023   \itemmax=\tableindent
4024   \advance \itemmax by -\itemmargin
4025   \advance \leftskip by \tableindent
4026   \exdentamount=\tableindent
4027   \parindent = 0pt
4028   \parskip = \smallskipamount
4029   \ifdim \parskip=0pt \parskip=2pt \fi
4030   \let\item = \internalBitem
4031   \let\itemx = \internalBitemx
4032 }
4033 \def\Etable{\endgraf\afterenvbreak}
4034 \let\Eftable\Etable
4035 \let\Ektable\Etable
4036 \let\Evtable\Etable
4037 \let\Eitemize\Etable
4038 \let\Eenumerate\Etable
4039
4040 % This is the counter used by @enumerate, which is really @itemize
4041
4042 \newcount \itemno
4043
4044 \envdef\itemize{\parsearg\doitemize}
4045
4046 \def\doitemize#1{%
4047   \aboveenvbreak
4048   \itemmax=\itemindent
4049   \advance\itemmax by -\itemmargin
4050   \advance\leftskip by \itemindent
4051   \exdentamount=\itemindent
4052   \parindent=0pt
4053   \parskip=\smallskipamount
4054   \ifdim\parskip=0pt \parskip=2pt \fi
4055   %
4056   % Try typesetting the item mark so that if the document erroneously says
4057   % something like @itemize @samp (intending @table), there's an error
4058   % right away at the @itemize.  It's not the best error message in the
4059   % world, but it's better than leaving it to the @item.  This means if
4060   % the user wants an empty mark, they have to say @w{} not just @w.
4061   \def\itemcontents{#1}%
4062   \setbox0 = \hbox{\itemcontents}%
4063   %
4064   % @itemize with no arg is equivalent to @itemize @bullet.
4065   \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
4066   %
4067   \let\item=\itemizeitem
4068 }
4069
4070 % Definition of @item while inside @itemize and @enumerate.
4071 %
4072 \def\itemizeitem{%
4073   \advance\itemno by 1  % for enumerations
4074   {\let\par=\endgraf \smallbreak}% reasonable place to break
4075   {%
4076    % If the document has an @itemize directly after a section title, a
4077    % \nobreak will be last on the list, and \sectionheading will have
4078    % done a \vskip-\parskip.  In that case, we don't want to zero
4079    % parskip, or the item text will crash with the heading.  On the
4080    % other hand, when there is normal text preceding the item (as there
4081    % usually is), we do want to zero parskip, or there would be too much
4082    % space.  In that case, we won't have a \nobreak before.  At least
4083    % that's the theory.
4084    \ifnum\lastpenalty<10000 \parskip=0in \fi
4085    \noindent
4086    \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
4087    %
4088    \ifinner\else
4089      \vadjust{\penalty 1200}% not good to break after first line of item.
4090    \fi
4091    % We can be in inner vertical mode in a footnote, although an
4092    % @itemize looks awful there.
4093   }%
4094   \flushcr
4095 }
4096
4097 % \splitoff TOKENS\endmark defines \first to be the first token in
4098 % TOKENS, and \rest to be the remainder.
4099 %
4100 \def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
4101
4102 % Allow an optional argument of an uppercase letter, lowercase letter,
4103 % or number, to specify the first label in the enumerated list.  No
4104 % argument is the same as `1'.
4105 %
4106 \envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
4107 \def\enumeratey #1 #2\endenumeratey{%
4108   % If we were given no argument, pretend we were given `1'.
4109   \def\thearg{#1}%
4110   \ifx\thearg\empty \def\thearg{1}\fi
4111   %
4112   % Detect if the argument is a single token.  If so, it might be a
4113   % letter.  Otherwise, the only valid thing it can be is a number.
4114   % (We will always have one token, because of the test we just made.
4115   % This is a good thing, since \splitoff doesn't work given nothing at
4116   % all -- the first parameter is undelimited.)
4117   \expandafter\splitoff\thearg\endmark
4118   \ifx\rest\empty
4119     % Only one token in the argument.  It could still be anything.
4120     % A ``lowercase letter'' is one whose \lccode is nonzero.
4121     % An ``uppercase letter'' is one whose \lccode is both nonzero, and
4122     %   not equal to itself.
4123     % Otherwise, we assume it's a number.
4124     %
4125     % We need the \relax at the end of the \ifnum lines to stop TeX from
4126     % continuing to look for a <number>.
4127     %
4128     \ifnum\lccode\expandafter`\thearg=0\relax
4129       \numericenumerate % a number (we hope)
4130     \else
4131       % It's a letter.
4132       \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
4133         \lowercaseenumerate % lowercase letter
4134       \else
4135         \uppercaseenumerate % uppercase letter
4136       \fi
4137     \fi
4138   \else
4139     % Multiple tokens in the argument.  We hope it's a number.
4140     \numericenumerate
4141   \fi
4142 }
4143
4144 % An @enumerate whose labels are integers.  The starting integer is
4145 % given in \thearg.
4146 %
4147 \def\numericenumerate{%
4148   \itemno = \thearg
4149   \startenumeration{\the\itemno}%
4150 }
4151
4152 % The starting (lowercase) letter is in \thearg.
4153 \def\lowercaseenumerate{%
4154   \itemno = \expandafter`\thearg
4155   \startenumeration{%
4156     % Be sure we're not beyond the end of the alphabet.
4157     \ifnum\itemno=0
4158       \errmessage{No more lowercase letters in @enumerate; get a bigger
4159                   alphabet}%
4160     \fi
4161     \char\lccode\itemno
4162   }%
4163 }
4164
4165 % The starting (uppercase) letter is in \thearg.
4166 \def\uppercaseenumerate{%
4167   \itemno = \expandafter`\thearg
4168   \startenumeration{%
4169     % Be sure we're not beyond the end of the alphabet.
4170     \ifnum\itemno=0
4171       \errmessage{No more uppercase letters in @enumerate; get a bigger
4172                   alphabet}
4173     \fi
4174     \char\uccode\itemno
4175   }%
4176 }
4177
4178 % Call \doitemize, adding a period to the first argument and supplying the
4179 % common last two arguments.  Also subtract one from the initial value in
4180 % \itemno, since @item increments \itemno.
4181 %
4182 \def\startenumeration#1{%
4183   \advance\itemno by -1
4184   \doitemize{#1.}\flushcr
4185 }
4186
4187 % @alphaenumerate and @capsenumerate are abbreviations for giving an arg
4188 % to @enumerate.
4189 %
4190 \def\alphaenumerate{\enumerate{a}}
4191 \def\capsenumerate{\enumerate{A}}
4192 \def\Ealphaenumerate{\Eenumerate}
4193 \def\Ecapsenumerate{\Eenumerate}
4194
4195
4196 % @multitable macros
4197 % Amy Hendrickson, 8/18/94, 3/6/96
4198 %
4199 % @multitable ... @end multitable will make as many columns as desired.
4200 % Contents of each column will wrap at width given in preamble.  Width
4201 % can be specified either with sample text given in a template line,
4202 % or in percent of \hsize, the current width of text on page.
4203
4204 % Table can continue over pages but will only break between lines.
4205
4206 % To make preamble:
4207 %
4208 % Either define widths of columns in terms of percent of \hsize:
4209 %   @multitable @columnfractions .25 .3 .45
4210 %   @item ...
4211 %
4212 %   Numbers following @columnfractions are the percent of the total
4213 %   current hsize to be used for each column. You may use as many
4214 %   columns as desired.
4215
4216
4217 % Or use a template:
4218 %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4219 %   @item ...
4220 %   using the widest term desired in each column.
4221
4222 % Each new table line starts with @item, each subsequent new column
4223 % starts with @tab. Empty columns may be produced by supplying @tab's
4224 % with nothing between them for as many times as empty columns are needed,
4225 % ie, @tab@tab@tab will produce two empty columns.
4226
4227 % @item, @tab do not need to be on their own lines, but it will not hurt
4228 % if they are.
4229
4230 % Sample multitable:
4231
4232 %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
4233 %   @item first col stuff @tab second col stuff @tab third col
4234 %   @item
4235 %   first col stuff
4236 %   @tab
4237 %   second col stuff
4238 %   @tab
4239 %   third col
4240 %   @item first col stuff @tab second col stuff
4241 %   @tab Many paragraphs of text may be used in any column.
4242 %
4243 %         They will wrap at the width determined by the template.
4244 %   @item@tab@tab This will be in third column.
4245 %   @end multitable
4246
4247 % Default dimensions may be reset by user.
4248 % @multitableparskip is vertical space between paragraphs in table.
4249 % @multitableparindent is paragraph indent in table.
4250 % @multitablecolmargin is horizontal space to be left between columns.
4251 % @multitablelinespace is space to leave between table items, baseline
4252 %                                                            to baseline.
4253 %   0pt means it depends on current normal line spacing.
4254 %
4255 \newskip\multitableparskip
4256 \newskip\multitableparindent
4257 \newdimen\multitablecolspace
4258 \newskip\multitablelinespace
4259 \multitableparskip=0pt
4260 \multitableparindent=6pt
4261 \multitablecolspace=12pt
4262 \multitablelinespace=0pt
4263
4264 % Macros used to set up halign preamble:
4265 %
4266 \let\endsetuptable\relax
4267 \def\xendsetuptable{\endsetuptable}
4268 \let\columnfractions\relax
4269 \def\xcolumnfractions{\columnfractions}
4270 \newif\ifsetpercent
4271
4272 % #1 is the @columnfraction, usually a decimal number like .5, but might
4273 % be just 1.  We just use it, whatever it is.
4274 %
4275 \def\pickupwholefraction#1 {%
4276   \global\advance\colcount by 1
4277   \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
4278   \setuptable
4279 }
4280
4281 \newcount\colcount
4282 \def\setuptable#1{%
4283   \def\firstarg{#1}%
4284   \ifx\firstarg\xendsetuptable
4285     \let\go = \relax
4286   \else
4287     \ifx\firstarg\xcolumnfractions
4288       \global\setpercenttrue
4289     \else
4290       \ifsetpercent
4291          \let\go\pickupwholefraction
4292       \else
4293          \global\advance\colcount by 1
4294          \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
4295                    % separator; typically that is always in the input, anyway.
4296          \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
4297       \fi
4298     \fi
4299     \ifx\go\pickupwholefraction
4300       % Put the argument back for the \pickupwholefraction call, so
4301       % we'll always have a period there to be parsed.
4302       \def\go{\pickupwholefraction#1}%
4303     \else
4304       \let\go = \setuptable
4305     \fi%
4306   \fi
4307   \go
4308 }
4309
4310 % multitable-only commands.
4311
4312 % @headitem starts a heading row, which we typeset in bold.  Assignments
4313 % have to be global since we are inside the implicit group of an
4314 % alignment entry.  \everycr below resets \everytab so we don't have to
4315 % undo it ourselves.
4316 \def\headitemfont{\b}% for people to use in the template row; not changeable
4317 \def\headitem{%
4318   \checkenv\multitable
4319   \crcr
4320   \gdef\headitemcrhook{\nobreak}% attempt to avoid page break after headings
4321   \global\everytab={\bf}% can't use \headitemfont since the parsing differs
4322   \the\everytab % for the first item
4323 }%
4324 %
4325 % default for tables with no headings.
4326 \let\headitemcrhook=\relax
4327 %
4328 % A \tab used to include \hskip1sp.  But then the space in a template
4329 % line is not enough.  That is bad.  So let's go back to just `&' until
4330 % we again encounter the problem the 1sp was intended to solve.
4331 %                                       --karl, nathan@acm.org, 20apr99.
4332 \def\tab{\checkenv\multitable &\the\everytab}%
4333
4334 % @multitable ... @end multitable definitions:
4335 %
4336 \newtoks\everytab  % insert after every tab.
4337 %
4338 \envdef\multitable{%
4339   \vskip\parskip
4340   \startsavinginserts
4341   %
4342   % @item within a multitable starts a normal row.
4343   % We use \def instead of \let so that if one of the multitable entries
4344   % contains an @itemize, we don't choke on the \item (seen as \crcr aka
4345   % \endtemplate) expanding \doitemize.
4346   \def\item{\crcr}%
4347   %
4348   \tolerance=9500
4349   \hbadness=9500
4350   \setmultitablespacing
4351   \parskip=\multitableparskip
4352   \parindent=\multitableparindent
4353   \overfullrule=0pt
4354   \global\colcount=0
4355   %
4356   \everycr = {%
4357     \noalign{%
4358       \global\everytab={}% Reset from possible headitem.
4359       \global\colcount=0 % Reset the column counter.
4360       %
4361       % Check for saved footnotes, etc.:
4362       \checkinserts
4363       %
4364       % Perhaps a \nobreak, then reset:
4365       \headitemcrhook
4366       \global\let\headitemcrhook=\relax
4367     }%
4368   }%
4369   %
4370   \parsearg\domultitable
4371 }
4372 \def\domultitable#1{%
4373   % To parse everything between @multitable and @item:
4374   \setuptable#1 \endsetuptable
4375   %
4376   % This preamble sets up a generic column definition, which will
4377   % be used as many times as user calls for columns.
4378   % \vtop will set a single line and will also let text wrap and
4379   % continue for many paragraphs if desired.
4380   \halign\bgroup &%
4381     \global\advance\colcount by 1
4382     \multistrut
4383     \vtop{%
4384       % Use the current \colcount to find the correct column width:
4385       \hsize=\expandafter\csname col\the\colcount\endcsname
4386       %
4387       % In order to keep entries from bumping into each other
4388       % we will add a \leftskip of \multitablecolspace to all columns after
4389       % the first one.
4390       %
4391       % If a template has been used, we will add \multitablecolspace
4392       % to the width of each template entry.
4393       %
4394       % If the user has set preamble in terms of percent of \hsize we will
4395       % use that dimension as the width of the column, and the \leftskip
4396       % will keep entries from bumping into each other.  Table will start at
4397       % left margin and final column will justify at right margin.
4398       %
4399       % Make sure we don't inherit \rightskip from the outer environment.
4400       \rightskip=0pt
4401       \ifnum\colcount=1
4402         % The first column will be indented with the surrounding text.
4403         \advance\hsize by\leftskip
4404       \else
4405         \ifsetpercent \else
4406           % If user has not set preamble in terms of percent of \hsize
4407           % we will advance \hsize by \multitablecolspace.
4408           \advance\hsize by \multitablecolspace
4409         \fi
4410        % In either case we will make \leftskip=\multitablecolspace:
4411       \leftskip=\multitablecolspace
4412       \fi
4413       % Ignoring space at the beginning and end avoids an occasional spurious
4414       % blank line, when TeX decides to break the line at the space before the
4415       % box from the multistrut, so the strut ends up on a line by itself.
4416       % For example:
4417       % @multitable @columnfractions .11 .89
4418       % @item @code{#}
4419       % @tab Legal holiday which is valid in major parts of the whole country.
4420       % Is automatically provided with highlighting sequences respectively
4421       % marking characters.
4422       \noindent\ignorespaces##\unskip\multistrut
4423     }\cr
4424 }
4425 \def\Emultitable{%
4426   \crcr
4427   \egroup % end the \halign
4428   \global\setpercentfalse
4429 }
4430
4431 \def\setmultitablespacing{%
4432   \def\multistrut{\strut}% just use the standard line spacing
4433   %
4434   % Compute \multitablelinespace (if not defined by user) for use in
4435   % \multitableparskip calculation.  We used define \multistrut based on
4436   % this, but (ironically) that caused the spacing to be off.
4437   % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
4438 \ifdim\multitablelinespace=0pt
4439 \setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
4440 \global\advance\multitablelinespace by-\ht0
4441 \fi
4442 % Test to see if parskip is larger than space between lines of
4443 % table. If not, do nothing.
4444 %        If so, set to same dimension as multitablelinespace.
4445 \ifdim\multitableparskip>\multitablelinespace
4446 \global\multitableparskip=\multitablelinespace
4447 \global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4448                                       % than skip between lines in the table.
4449 \fi%
4450 \ifdim\multitableparskip=0pt
4451 \global\multitableparskip=\multitablelinespace
4452 \global\advance\multitableparskip-7pt % to keep parskip somewhat smaller
4453                                       % than skip between lines in the table.
4454 \fi}
4455
4456
4457 \message{conditionals,}
4458
4459 % @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
4460 % @ifnotxml always succeed.  They currently do nothing; we don't
4461 % attempt to check whether the conditionals are properly nested.  But we
4462 % have to remember that they are conditionals, so that @end doesn't
4463 % attempt to close an environment group.
4464 %
4465 \def\makecond#1{%
4466   \expandafter\let\csname #1\endcsname = \relax
4467   \expandafter\let\csname iscond.#1\endcsname = 1
4468 }
4469 \makecond{iftex}
4470 \makecond{ifnotdocbook}
4471 \makecond{ifnothtml}
4472 \makecond{ifnotinfo}
4473 \makecond{ifnotplaintext}
4474 \makecond{ifnotxml}
4475
4476 % Ignore @ignore, @ifhtml, @ifinfo, and the like.
4477 %
4478 \def\direntry{\doignore{direntry}}
4479 \def\documentdescription{\doignore{documentdescription}}
4480 \def\docbook{\doignore{docbook}}
4481 \def\html{\doignore{html}}
4482 \def\ifdocbook{\doignore{ifdocbook}}
4483 \def\ifhtml{\doignore{ifhtml}}
4484 \def\ifinfo{\doignore{ifinfo}}
4485 \def\ifnottex{\doignore{ifnottex}}
4486 \def\ifplaintext{\doignore{ifplaintext}}
4487 \def\ifxml{\doignore{ifxml}}
4488 \def\ignore{\doignore{ignore}}
4489 \def\menu{\doignore{menu}}
4490 \def\xml{\doignore{xml}}
4491
4492 % Ignore text until a line `@end #1', keeping track of nested conditionals.
4493 %
4494 % A count to remember the depth of nesting.
4495 \newcount\doignorecount
4496
4497 \def\doignore#1{\begingroup
4498   % Scan in ``verbatim'' mode:
4499   \obeylines
4500   \catcode`\@ = \other
4501   \catcode`\{ = \other
4502   \catcode`\} = \other
4503   %
4504   % Make sure that spaces turn into tokens that match what \doignoretext wants.
4505   \spaceisspace
4506   %
4507   % Count number of #1's that we've seen.
4508   \doignorecount = 0
4509   %
4510   % Swallow text until we reach the matching `@end #1'.
4511   \dodoignore{#1}%
4512 }
4513
4514 { \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
4515   \obeylines %
4516   %
4517   \gdef\dodoignore#1{%
4518     % #1 contains the command name as a string, e.g., `ifinfo'.
4519     %
4520     % Define a command to find the next `@end #1'.
4521     \long\def\doignoretext##1^^M@end #1{%
4522       \doignoretextyyy##1^^M@#1\_STOP_}%
4523     %
4524     % And this command to find another #1 command, at the beginning of a
4525     % line.  (Otherwise, we would consider a line `@c @ifset', for
4526     % example, to count as an @ifset for nesting.)
4527     \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
4528     %
4529     % And now expand that command.
4530     \doignoretext ^^M%
4531   }%
4532 }
4533
4534 \def\doignoreyyy#1{%
4535   \def\temp{#1}%
4536   \ifx\temp\empty                       % Nothing found.
4537     \let\next\doignoretextzzz
4538   \else                                 % Found a nested condition, ...
4539     \advance\doignorecount by 1
4540     \let\next\doignoretextyyy           % ..., look for another.
4541     % If we're here, #1 ends with ^^M\ifinfo (for example).
4542   \fi
4543   \next #1% the token \_STOP_ is present just after this macro.
4544 }
4545
4546 % We have to swallow the remaining "\_STOP_".
4547 %
4548 \def\doignoretextzzz#1{%
4549   \ifnum\doignorecount = 0      % We have just found the outermost @end.
4550     \let\next\enddoignore
4551   \else                         % Still inside a nested condition.
4552     \advance\doignorecount by -1
4553     \let\next\doignoretext      % Look for the next @end.
4554   \fi
4555   \next
4556 }
4557
4558 % Finish off ignored text.
4559 { \obeylines%
4560   % Ignore anything after the last `@end #1'; this matters in verbatim
4561   % environments, where otherwise the newline after an ignored conditional
4562   % would result in a blank line in the output.
4563   \gdef\enddoignore#1^^M{\endgroup\ignorespaces}%
4564 }
4565
4566
4567 % @set VAR sets the variable VAR to an empty value.
4568 % @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
4569 %
4570 % Since we want to separate VAR from REST-OF-LINE (which might be
4571 % empty), we can't just use \parsearg; we have to insert a space of our
4572 % own to delimit the rest of the line, and then take it out again if we
4573 % didn't need it.
4574 % We rely on the fact that \parsearg sets \catcode`\ =10.
4575 %
4576 \parseargdef\set{\setyyy#1 \endsetyyy}
4577 \def\setyyy#1 #2\endsetyyy{%
4578   {%
4579     \makevalueexpandable
4580     \def\temp{#2}%
4581     \edef\next{\gdef\makecsname{SET#1}}%
4582     \ifx\temp\empty
4583       \next{}%
4584     \else
4585       \setzzz#2\endsetzzz
4586     \fi
4587   }%
4588 }
4589 % Remove the trailing space \setxxx inserted.
4590 \def\setzzz#1 \endsetzzz{\next{#1}}
4591
4592 % @clear VAR clears (i.e., unsets) the variable VAR.
4593 %
4594 \parseargdef\clear{%
4595   {%
4596     \makevalueexpandable
4597     \global\expandafter\let\csname SET#1\endcsname=\relax
4598   }%
4599 }
4600
4601 % @value{foo} gets the text saved in variable foo.
4602 \def\value{\begingroup\makevalueexpandable\valuexxx}
4603 \def\valuexxx#1{\expandablevalue{#1}\endgroup}
4604 {
4605   \catcode`\-=\active \catcode`\_=\active
4606   %
4607   \gdef\makevalueexpandable{%
4608     \let\value = \expandablevalue
4609     % We don't want these characters active, ...
4610     \catcode`\-=\other \catcode`\_=\other
4611     % ..., but we might end up with active ones in the argument if
4612     % we're called from @code, as @code{@value{foo-bar_}}, though.
4613     % So \let them to their normal equivalents.
4614     \let-\normaldash \let_\normalunderscore
4615   }
4616 }
4617
4618 % We have this subroutine so that we can handle at least some @value's
4619 % properly in indexes (we call \makevalueexpandable in \indexdummies).
4620 % The command has to be fully expandable (if the variable is set), since
4621 % the result winds up in the index file.  This means that if the
4622 % variable's value contains other Texinfo commands, it's almost certain
4623 % it will fail (although perhaps we could fix that with sufficient work
4624 % to do a one-level expansion on the result, instead of complete).
4625
4626 % Unfortunately, this has the consequence that when _ is in the *value*
4627 % of an @set, it does not print properly in the roman fonts (get the cmr
4628 % dot accent at position 126 instead).  No fix comes to mind, and it's
4629 % been this way since 2003 or earlier, so just ignore it.
4630
4631 \def\expandablevalue#1{%
4632   \expandafter\ifx\csname SET#1\endcsname\relax
4633     {[No value for ``#1'']}%
4634     \message{Variable `#1', used in @value, is not set.}%
4635   \else
4636     \csname SET#1\endcsname
4637   \fi
4638 }
4639
4640 % Like \expandablevalue, but completely expandable (the \message in the
4641 % definition above operates at the execution level of TeX).  Used when
4642 % writing to auxiliary files, due to the expansion that \write does.
4643 % If flag is undefined, pass through an unexpanded @value command: maybe it 
4644 % will be set by the time it is read back in.
4645 %
4646 % NB flag names containing - or _ may not work here.
4647 \def\dummyvalue#1{%
4648   \expandafter\ifx\csname SET#1\endcsname\relax
4649     \noexpand\value{#1}%
4650   \else
4651     \csname SET#1\endcsname
4652   \fi
4653 }
4654
4655 % Used for @value's in index entries to form the sort key: expand the @value
4656 % if possible, otherwise sort late.
4657 \def\indexnofontsvalue#1{%
4658   \expandafter\ifx\csname SET#1\endcsname\relax
4659     ZZZZZZZ
4660   \else
4661     \csname SET#1\endcsname
4662   \fi
4663 }
4664
4665 % @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
4666 % with @set.
4667
4668 % To get the special treatment we need for `@end ifset,' we call
4669 % \makecond and then redefine.
4670 %
4671 \makecond{ifset}
4672 \def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
4673 \def\doifset#1#2{%
4674   {%
4675     \makevalueexpandable
4676     \let\next=\empty
4677     \expandafter\ifx\csname SET#2\endcsname\relax
4678       #1% If not set, redefine \next.
4679     \fi
4680     \expandafter
4681   }\next
4682 }
4683 \def\ifsetfail{\doignore{ifset}}
4684
4685 % @ifclear VAR ... @end executes the `...' iff VAR has never been
4686 % defined with @set, or has been undefined with @clear.
4687 %
4688 % The `\else' inside the `\doifset' parameter is a trick to reuse the
4689 % above code: if the variable is not set, do nothing, if it is set,
4690 % then redefine \next to \ifclearfail.
4691 %
4692 \makecond{ifclear}
4693 \def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
4694 \def\ifclearfail{\doignore{ifclear}}
4695
4696 % @ifcommandisdefined CMD ... @end executes the `...' if CMD (written
4697 % without the @) is in fact defined.  We can only feasibly check at the
4698 % TeX level, so something like `mathcode' is going to considered
4699 % defined even though it is not a Texinfo command.
4700
4701 \makecond{ifcommanddefined}
4702 \def\ifcommanddefined{\parsearg{\doifcmddefined{\let\next=\ifcmddefinedfail}}}
4703 %
4704 \def\doifcmddefined#1#2{{%
4705     \makevalueexpandable
4706     \let\next=\empty
4707     \expandafter\ifx\csname #2\endcsname\relax
4708       #1% If not defined, \let\next as above.
4709     \fi
4710     \expandafter
4711   }\next
4712 }
4713 \def\ifcmddefinedfail{\doignore{ifcommanddefined}}
4714
4715 % @ifcommandnotdefined CMD ... handled similar to @ifclear above.
4716 \makecond{ifcommandnotdefined}
4717 \def\ifcommandnotdefined{%
4718   \parsearg{\doifcmddefined{\else \let\next=\ifcmdnotdefinedfail}}}
4719 \def\ifcmdnotdefinedfail{\doignore{ifcommandnotdefined}}
4720
4721 % Set the `txicommandconditionals' variable, so documents have a way to
4722 % test if the @ifcommand...defined conditionals are available.
4723 \set txicommandconditionals
4724
4725 % @dircategory CATEGORY  -- specify a category of the dir file
4726 % which this file should belong to.  Ignore this in TeX.
4727 \let\dircategory=\comment
4728
4729 % @defininfoenclose.
4730 \let\definfoenclose=\comment
4731
4732
4733 \message{indexing,}
4734 % Index generation facilities
4735
4736 % Define \newwrite to be identical to plain tex's \newwrite
4737 % except not \outer, so it can be used within macros and \if's.
4738 \edef\newwrite{\makecsname{ptexnewwrite}}
4739
4740 % \newindex {foo} defines an index named IX.
4741 % It automatically defines \IXindex such that
4742 % \IXindex ...rest of line... puts an entry in the index IX.
4743 % It also defines \IXindfile to be the number of the output channel for
4744 % the file that accumulates this index.  The file's extension is IX.
4745 % The name of an index should be no more than 2 characters long
4746 % for the sake of vms.
4747 %
4748 \def\newindex#1{%
4749   \expandafter\chardef\csname#1indfile\endcsname=0
4750   \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
4751     \noexpand\doindex{#1}}
4752 }
4753
4754 % @defindex foo  ==  \newindex{foo}
4755 %
4756 \def\defindex{\parsearg\newindex}
4757
4758 % Define @defcodeindex, like @defindex except put all entries in @code.
4759 %
4760 \def\defcodeindex{\parsearg\newcodeindex}
4761 %
4762 \def\newcodeindex#1{%
4763   \expandafter\chardef\csname#1indfile\endcsname=0
4764   \expandafter\xdef\csname#1index\endcsname{%
4765     \noexpand\docodeindex{#1}}%
4766 }
4767
4768 % The default indices:
4769 \newindex{cp}%      concepts,
4770 \newcodeindex{fn}%  functions,
4771 \newcodeindex{vr}%  variables,
4772 \newcodeindex{tp}%  types,
4773 \newcodeindex{ky}%  keys
4774 \newcodeindex{pg}%  and programs.
4775
4776
4777 % @synindex foo bar    makes index foo feed into index bar.
4778 % Do this instead of @defindex foo if you don't want it as a separate index.
4779 %
4780 % @syncodeindex foo bar   similar, but put all entries made for index foo
4781 % inside @code.
4782 %
4783 \def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
4784 \def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
4785
4786 % #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
4787 % #3 the target index (bar).
4788 \def\dosynindex#1#2#3{%
4789   % Only do \closeout if we haven't already done it, else we'll end up
4790   % closing the target index.
4791   \expandafter \ifx\csname donesynindex#2\endcsname \relax
4792     % The \closeout helps reduce unnecessary open files; the limit on the
4793     % Acorn RISC OS is a mere 16 files.
4794     \expandafter\closeout\csname#2indfile\endcsname
4795     \expandafter\let\csname donesynindex#2\endcsname = 1
4796   \fi
4797   % redefine \fooindfile:
4798   \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
4799   \expandafter\let\csname#2indfile\endcsname=\temp
4800   % redefine \fooindex:
4801   \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
4802 }
4803
4804 % Define \doindex, the driver for all index macros.
4805 % Argument #1 is generated by the calling \fooindex macro,
4806 % and it is the two-letter name of the index.
4807
4808 \def\doindex#1{\edef\indexname{#1}\parsearg\doindexxxx}
4809 \def\doindexxxx #1{\doind{\indexname}{#1}}
4810
4811 % like the previous two, but they put @code around the argument.
4812 \def\docodeindex#1{\edef\indexname{#1}\parsearg\docodeindexxxx}
4813 \def\docodeindexxxx #1{\doind{\indexname}{\code{#1}}}
4814
4815 \f
4816 % Used when writing an index entry out to an index file to prevent
4817 % expansion of Texinfo commands that can appear in an index entry.
4818 %
4819 \def\indexdummies{%
4820   \escapechar = `\\     % use backslash in output files.
4821   \def\@{@}% change to @@ when we switch to @ as escape char in index files.
4822   \def\ {\realbackslash\space }%
4823   %
4824   % Need these unexpandable (because we define \tt as a dummy)
4825   % definitions when @{ or @} appear in index entry text.  Also, more
4826   % complicated, when \tex is in effect and \{ is a \delimiter again.
4827   % We can't use \lbracecmd and \rbracecmd because texindex assumes
4828   % braces and backslashes are used only as delimiters.  Perhaps we
4829   % should use @lbracechar and @rbracechar?
4830   \def\{{{\tt\char123}}%
4831   \def\}{{\tt\char125}}%
4832   %
4833   % Do the redefinitions.
4834   \definedummies
4835 }
4836
4837 % Used for the aux and toc files, where @ is the escape character.
4838 %
4839 % For the aux and toc files, @ is the escape character.  So we want to
4840 % redefine everything using @ as the escape character (instead of
4841 % \realbackslash, still used for index files).  When everything uses @,
4842 % this will be simpler.
4843 %
4844 \def\atdummies{%
4845   \def\@{@@}%
4846   \def\ {@ }%
4847   \let\{ = \lbraceatcmd
4848   \let\} = \rbraceatcmd
4849   %
4850   % Do the redefinitions.
4851   \definedummies
4852   \otherbackslash
4853 }
4854
4855 % \definedummyword defines \#1 as \string\#1\space, thus effectively
4856 % preventing its expansion.  This is used only for control words,
4857 % not control letters, because the \space would be incorrect for
4858 % control characters, but is needed to separate the control word
4859 % from whatever follows.
4860 %
4861 % These can be used both for control words that take an argument and
4862 % those that do not.  If it is followed by {arg} in the input, then
4863 % that will dutifully get written to the index (or wherever).
4864 %
4865 % For control letters, we have \definedummyletter, which omits the
4866 % space.
4867 %
4868 \def\definedummyword  #1{\def#1{\string#1\space}}%
4869 \def\definedummyletter#1{\def#1{\string#1}}%
4870 \let\definedummyaccent\definedummyletter
4871
4872 % Called from \indexdummies and \atdummies, to effectively prevent
4873 % the expansion of commands.
4874 %
4875 \def\definedummies{%
4876   %
4877   \let\commondummyword\definedummyword
4878   \let\commondummyletter\definedummyletter
4879   \let\commondummyaccent\definedummyaccent
4880   \commondummiesnofonts
4881   %
4882   \definedummyletter\_%
4883   \definedummyletter\-%
4884   %
4885   % Non-English letters.
4886   \definedummyword\AA
4887   \definedummyword\AE
4888   \definedummyword\DH
4889   \definedummyword\L
4890   \definedummyword\O
4891   \definedummyword\OE
4892   \definedummyword\TH
4893   \definedummyword\aa
4894   \definedummyword\ae
4895   \definedummyword\dh
4896   \definedummyword\exclamdown
4897   \definedummyword\l
4898   \definedummyword\o
4899   \definedummyword\oe
4900   \definedummyword\ordf
4901   \definedummyword\ordm
4902   \definedummyword\questiondown
4903   \definedummyword\ss
4904   \definedummyword\th
4905   %
4906   % Although these internal commands shouldn't show up, sometimes they do.
4907   \definedummyword\bf
4908   \definedummyword\gtr
4909   \definedummyword\hat
4910   \definedummyword\less
4911   \definedummyword\sf
4912   \definedummyword\sl
4913   \definedummyword\tclose
4914   \definedummyword\tt
4915   %
4916   \definedummyword\LaTeX
4917   \definedummyword\TeX
4918   %
4919   % Assorted special characters.
4920   \definedummyword\arrow
4921   \definedummyword\bullet
4922   \definedummyword\comma
4923   \definedummyword\copyright
4924   \definedummyword\registeredsymbol
4925   \definedummyword\dots
4926   \definedummyword\enddots
4927   \definedummyword\entrybreak
4928   \definedummyword\equiv
4929   \definedummyword\error
4930   \definedummyword\euro
4931   \definedummyword\expansion
4932   \definedummyword\geq
4933   \definedummyword\guillemetleft
4934   \definedummyword\guillemetright
4935   \definedummyword\guilsinglleft
4936   \definedummyword\guilsinglright
4937   \definedummyword\lbracechar
4938   \definedummyword\leq
4939   \definedummyword\mathopsup
4940   \definedummyword\minus
4941   \definedummyword\ogonek
4942   \definedummyword\pounds
4943   \definedummyword\point
4944   \definedummyword\print
4945   \definedummyword\quotedblbase
4946   \definedummyword\quotedblleft
4947   \definedummyword\quotedblright
4948   \definedummyword\quoteleft
4949   \definedummyword\quoteright
4950   \definedummyword\quotesinglbase
4951   \definedummyword\rbracechar
4952   \definedummyword\result
4953   \definedummyword\sub
4954   \definedummyword\sup
4955   \definedummyword\textdegree
4956   %
4957   % We want to disable all macros so that they are not expanded by \write.
4958   \macrolist
4959   \let\value\dummyvalue
4960   %
4961   \normalturnoffactive
4962 }
4963
4964 % \commondummiesnofonts: common to \definedummies and \indexnofonts.
4965 % Define \commondummyletter, \commondummyaccent and \commondummyword before
4966 % using.  Used for accents, font commands, and various control letters.
4967 %
4968 \def\commondummiesnofonts{%
4969   % Control letters and accents.
4970   \commondummyletter\!%
4971   \commondummyaccent\"%
4972   \commondummyaccent\'%
4973   \commondummyletter\*%
4974   \commondummyaccent\,%
4975   \commondummyletter\.%
4976   \commondummyletter\/%
4977   \commondummyletter\:%
4978   \commondummyaccent\=%
4979   \commondummyletter\?%
4980   \commondummyaccent\^%
4981   \commondummyaccent\`%
4982   \commondummyaccent\~%
4983   \commondummyword\u
4984   \commondummyword\v
4985   \commondummyword\H
4986   \commondummyword\dotaccent
4987   \commondummyword\ogonek
4988   \commondummyword\ringaccent
4989   \commondummyword\tieaccent
4990   \commondummyword\ubaraccent
4991   \commondummyword\udotaccent
4992   \commondummyword\dotless
4993   %
4994   % Texinfo font commands.
4995   \commondummyword\b
4996   \commondummyword\i
4997   \commondummyword\r
4998   \commondummyword\sansserif
4999   \commondummyword\sc
5000   \commondummyword\slanted
5001   \commondummyword\t
5002   %
5003   % Commands that take arguments.
5004   \commondummyword\abbr
5005   \commondummyword\acronym
5006   \commondummyword\anchor
5007   \commondummyword\cite
5008   \commondummyword\code
5009   \commondummyword\command
5010   \commondummyword\dfn
5011   \commondummyword\dmn
5012   \commondummyword\email
5013   \commondummyword\emph
5014   \commondummyword\env
5015   \commondummyword\file
5016   \commondummyword\image
5017   \commondummyword\indicateurl
5018   \commondummyword\inforef
5019   \commondummyword\kbd
5020   \commondummyword\key
5021   \commondummyword\math
5022   \commondummyword\option
5023   \commondummyword\pxref
5024   \commondummyword\ref
5025   \commondummyword\samp
5026   \commondummyword\strong
5027   \commondummyword\tie
5028   \commondummyword\U
5029   \commondummyword\uref
5030   \commondummyword\url
5031   \commondummyword\var
5032   \commondummyword\verb
5033   \commondummyword\w
5034   \commondummyword\xref
5035 }
5036
5037 % For testing: output @{ and @} in index sort strings as \{ and \}.
5038 \newif\ifusebracesinindexes
5039
5040 \let\indexlbrace\relax
5041 \let\indexrbrace\relax
5042
5043 {\catcode`\@=0
5044 \catcode`\\=13
5045   @gdef@backslashdisappear{@def\{}}
5046 }
5047
5048 {
5049 \catcode`\<=13
5050 \catcode`\-=13
5051 \catcode`\`=13
5052   \gdef\indexnonalnumdisappear{%
5053     \expandafter\ifx\csname SETtxiindexlquoteignore\endcsname\relax\else
5054       % @set txiindexlquoteignore makes us ignore left quotes in the sort term.
5055       % (Introduced for FSFS 2nd ed.)
5056       \let`=\empty
5057     \fi
5058     %
5059     \expandafter\ifx\csname SETtxiindexbackslashignore\endcsname\relax\else
5060       \backslashdisappear
5061     \fi
5062     %
5063     \expandafter\ifx\csname SETtxiindexhyphenignore\endcsname\relax\else
5064       \def-{}%
5065     \fi
5066     \expandafter\ifx\csname SETtxiindexlessthanignore\endcsname\relax\else
5067       \def<{}%
5068     \fi
5069     \expandafter\ifx\csname SETtxiindexatsignignore\endcsname\relax\else
5070       \def\@{}%
5071     \fi
5072   }
5073
5074   \gdef\indexnonalnumreappear{%
5075     \useindexbackslash
5076     \let-\normaldash
5077     \let<\normalless
5078     \def\@{@}%
5079   }
5080 }
5081
5082
5083 % \indexnofonts is used when outputting the strings to sort the index
5084 % by, and when constructing control sequence names.  It eliminates all
5085 % control sequences and just writes whatever the best ASCII sort string
5086 % would be for a given command (usually its argument).
5087 %
5088 \def\indexnofonts{%
5089   % Accent commands should become @asis.
5090   \def\commondummyaccent##1{\let##1\asis}%
5091   % We can just ignore other control letters.
5092   \def\commondummyletter##1{\let##1\empty}%
5093   % All control words become @asis by default; overrides below.
5094   \let\commondummyword\commondummyaccent
5095   \commondummiesnofonts
5096   %
5097   % Don't no-op \tt, since it isn't a user-level command
5098   % and is used in the definitions of the active chars like <, >, |, etc.
5099   % Likewise with the other plain tex font commands.
5100   %\let\tt=\asis
5101   %
5102   \def\ { }%
5103   \def\@{@}%
5104   \def\_{\normalunderscore}%
5105   \def\-{}% @- shouldn't affect sorting
5106   %
5107   \uccode`\1=`\{ \uppercase{\def\{{1}}%
5108   \uccode`\1=`\} \uppercase{\def\}{1}}%
5109   \let\lbracechar\{%
5110   \let\rbracechar\}%
5111   %
5112   % Non-English letters.
5113   \def\AA{AA}%
5114   \def\AE{AE}%
5115   \def\DH{DZZ}%
5116   \def\L{L}%
5117   \def\OE{OE}%
5118   \def\O{O}%
5119   \def\TH{TH}%
5120   \def\aa{aa}%
5121   \def\ae{ae}%
5122   \def\dh{dzz}%
5123   \def\exclamdown{!}%
5124   \def\l{l}%
5125   \def\oe{oe}%
5126   \def\ordf{a}%
5127   \def\ordm{o}%
5128   \def\o{o}%
5129   \def\questiondown{?}%
5130   \def\ss{ss}%
5131   \def\th{th}%
5132   %
5133   \def\LaTeX{LaTeX}%
5134   \def\TeX{TeX}%
5135   %
5136   % Assorted special characters.
5137   % (The following {} will end up in the sort string, but that's ok.)
5138   \def\arrow{->}%
5139   \def\bullet{bullet}%
5140   \def\comma{,}%
5141   \def\copyright{copyright}%
5142   \def\dots{...}%
5143   \def\enddots{...}%
5144   \def\equiv{==}%
5145   \def\error{error}%
5146   \def\euro{euro}%
5147   \def\expansion{==>}%
5148   \def\geq{>=}%
5149   \def\guillemetleft{<<}%
5150   \def\guillemetright{>>}%
5151   \def\guilsinglleft{<}%
5152   \def\guilsinglright{>}%
5153   \def\leq{<=}%
5154   \def\minus{-}%
5155   \def\point{.}%
5156   \def\pounds{pounds}%
5157   \def\print{-|}%
5158   \def\quotedblbase{"}%
5159   \def\quotedblleft{"}%
5160   \def\quotedblright{"}%
5161   \def\quoteleft{`}%
5162   \def\quoteright{'}%
5163   \def\quotesinglbase{,}%
5164   \def\registeredsymbol{R}%
5165   \def\result{=>}%
5166   \def\textdegree{o}%
5167   %
5168   % We need to get rid of all macros, leaving only the arguments (if present).
5169   % Of course this is not nearly correct, but it is the best we can do for now.
5170   % makeinfo does not expand macros in the argument to @deffn, which ends up
5171   % writing an index entry, and texindex isn't prepared for an index sort entry
5172   % that starts with \.
5173   %
5174   % Since macro invocations are followed by braces, we can just redefine them
5175   % to take a single TeX argument.  The case of a macro invocation that
5176   % goes to end-of-line is not handled.
5177   %
5178   \macrolist
5179   \let\value\indexnofontsvalue
5180 }
5181
5182 \f
5183
5184
5185 \let\SETmarginindex=\relax % put index entries in margin (undocumented)?
5186
5187 % Most index entries go through here, but \dosubind is the general case.
5188 % #1 is the index name, #2 is the entry text.
5189 \def\doind#1#2{\dosubind{#1}{#2}{}}
5190
5191 % There is also \dosubind {index}{topic}{subtopic}
5192 % which makes an entry in a two-level index such as the operation index.
5193 % TODO: Two-level index?  Operation index?
5194
5195 % Workhorse for all indexes.
5196 % #1 is name of index, #2 is stuff to put there, #3 is subentry --
5197 % empty if called from \doind, as we usually are (the main exception
5198 % is with most defuns, which call us directly).
5199 %
5200 \def\dosubind#1#2#3{%
5201   \iflinks
5202   {%
5203     \requireopenindexfile{#1}%
5204     % Store the main index entry text (including the third arg).
5205     \toks0 = {#2}%
5206     % If third arg is present, precede it with a space.
5207     \def\thirdarg{#3}%
5208     \ifx\thirdarg\empty \else
5209       \toks0 = \expandafter{\the\toks0 \space #3}%
5210     \fi
5211     %
5212     \edef\writeto{\csname#1indfile\endcsname}%
5213     %
5214     \safewhatsit\dosubindwrite
5215   }%
5216   \fi
5217 }
5218
5219 % Check if an index file has been opened, and if not, open it.
5220 \def\requireopenindexfile#1{%
5221 \ifnum\csname #1indfile\endcsname=0
5222   \expandafter\newwrite \csname#1indfile\endcsname
5223   \edef\suffix{#1}%
5224   % A .fls suffix would conflict with the file extension for the output
5225   % of -recorder, so use .f1s instead.
5226   \ifx\suffix\indexisfl\def\suffix{f1}\fi
5227   % Open the file
5228   \immediate\openout\csname#1indfile\endcsname \jobname.\suffix
5229   % Using \immediate above here prevents an object entering into the current 
5230   % box, which could confound checks such as those in \safewhatsit for
5231   % preceding skips.
5232   \typeout{Writing index file \jobname.\suffix}%
5233 \fi}
5234 \def\indexisfl{fl}
5235
5236 % Output \ as {\indexbackslash}, because \ is an escape character in
5237 % the index files.
5238 \let\indexbackslash=\relax
5239 {\catcode`\@=0 \catcode`\\=\active
5240   @gdef@useindexbackslash{@def\{{@indexbackslash}}}
5241 }
5242
5243 % Definition for writing index entry text.
5244 \def\sortas#1{\ignorespaces}%
5245
5246 % Definition for writing index entry sort key.  Should occur at the at
5247 % the beginning of the index entry, like
5248 %     @cindex @sortas{september} \september
5249 % The \ignorespaces takes care of following space, but there's no way
5250 % to remove space before it.
5251 {
5252 \catcode`\-=13
5253 \gdef\indexwritesortas{%
5254   \begingroup
5255   \indexnonalnumreappear
5256   \indexwritesortasxxx}
5257 \gdef\indexwritesortasxxx#1{%
5258   \xdef\indexsortkey{#1}\endgroup}
5259 }
5260
5261
5262 % Write the entry in \toks0 to the index file.
5263 %
5264 \def\dosubindwrite{%
5265   % Put the index entry in the margin if desired.
5266   \ifx\SETmarginindex\relax\else
5267     \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
5268   \fi
5269   %
5270   % Remember, we are within a group.
5271   \indexdummies % Must do this here, since \bf, etc expand at this stage
5272   \useindexbackslash % \indexbackslash isn't defined now so it will be output 
5273                      % as is; and it will print as backslash.
5274   % The braces around \indexbrace are recognized by texindex.
5275   %
5276   % Get the string to sort by, by processing the index entry with all
5277   % font commands turned off.
5278   {\indexnofonts
5279    \def\lbracechar{{\indexlbrace}}%
5280    \def\rbracechar{{\indexrbrace}}%
5281    \let\{=\lbracechar
5282    \let\}=\rbracechar
5283    \indexnonalnumdisappear
5284    \xdef\indexsortkey{}%
5285    \let\sortas=\indexwritesortas
5286    \edef\temp{\the\toks0}%
5287    \setbox\dummybox = \hbox{\temp}% Make sure to execute any \sortas
5288    \ifx\indexsortkey\empty
5289      \xdef\indexsortkey{\temp}%
5290      \ifx\indexsortkey\empty\xdef\indexsortkey{ }\fi
5291    \fi
5292   }%
5293   %
5294   % Set up the complete index entry, with both the sort key and
5295   % the original text, including any font commands.  We write
5296   % three arguments to \entry to the .?? file (four in the
5297   % subentry case), texindex reduces to two when writing the .??s
5298   % sorted result.
5299   \edef\temp{%
5300     \write\writeto{%
5301       \string\entry{\indexsortkey}{\noexpand\folio}{\the\toks0}}%
5302   }%
5303   \temp
5304 }
5305 \newbox\dummybox % used above
5306
5307 % Take care of unwanted page breaks/skips around a whatsit:
5308 %
5309 % If a skip is the last thing on the list now, preserve it
5310 % by backing up by \lastskip, doing the \write, then inserting
5311 % the skip again.  Otherwise, the whatsit generated by the
5312 % \write or \pdfdest will make \lastskip zero.  The result is that
5313 % sequences like this:
5314 % @end defun
5315 % @tindex whatever
5316 % @defun ...
5317 % will have extra space inserted, because the \medbreak in the
5318 % start of the @defun won't see the skip inserted by the @end of
5319 % the previous defun.
5320 %
5321 % But don't do any of this if we're not in vertical mode.  We
5322 % don't want to do a \vskip and prematurely end a paragraph.
5323 %
5324 % Avoid page breaks due to these extra skips, too.
5325 %
5326 % But wait, there is a catch there:
5327 % We'll have to check whether \lastskip is zero skip.  \ifdim is not
5328 % sufficient for this purpose, as it ignores stretch and shrink parts
5329 % of the skip.  The only way seems to be to check the textual
5330 % representation of the skip.
5331 %
5332 % The following is almost like \def\zeroskipmacro{0.0pt} except that
5333 % the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
5334 %
5335 \edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
5336 %
5337 \newskip\whatsitskip
5338 \newcount\whatsitpenalty
5339 %
5340 % ..., ready, GO:
5341 %
5342 \def\safewhatsit#1{\ifhmode
5343   #1%
5344  \else
5345   % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
5346   \whatsitskip = \lastskip
5347   \edef\lastskipmacro{\the\lastskip}%
5348   \whatsitpenalty = \lastpenalty
5349   %
5350   % If \lastskip is nonzero, that means the last item was a
5351   % skip.  And since a skip is discardable, that means this
5352   % -\whatsitskip glue we're inserting is preceded by a
5353   % non-discardable item, therefore it is not a potential
5354   % breakpoint, therefore no \nobreak needed.
5355   \ifx\lastskipmacro\zeroskipmacro
5356   \else
5357     \vskip-\whatsitskip
5358   \fi
5359   %
5360   #1%
5361   %
5362   \ifx\lastskipmacro\zeroskipmacro
5363     % If \lastskip was zero, perhaps the last item was a penalty, and
5364     % perhaps it was >=10000, e.g., a \nobreak.  In that case, we want
5365     % to re-insert the same penalty (values >10000 are used for various
5366     % signals); since we just inserted a non-discardable item, any
5367     % following glue (such as a \parskip) would be a breakpoint.  For example:
5368     %   @deffn deffn-whatever
5369     %   @vindex index-whatever
5370     %   Description.
5371     % would allow a break between the index-whatever whatsit
5372     % and the "Description." paragraph.
5373     \ifnum\whatsitpenalty>9999 \penalty\whatsitpenalty \fi
5374   \else
5375     % On the other hand, if we had a nonzero \lastskip,
5376     % this make-up glue would be preceded by a non-discardable item
5377     % (the whatsit from the \write), so we must insert a \nobreak.
5378     \nobreak\vskip\whatsitskip
5379   \fi
5380 \fi}
5381
5382 % The index entry written in the file actually looks like
5383 %  \entry {sortstring}{page}{topic}
5384 % or
5385 %  \entry {sortstring}{page}{topic}{subtopic}
5386 % The texindex program reads in these files and writes files
5387 % containing these kinds of lines:
5388 %  \initial {c}
5389 %     before the first topic whose initial is c
5390 %  \entry {topic}{pagelist}
5391 %     for a topic that is used without subtopics
5392 %  \primary {topic}
5393 %     for the beginning of a topic that is used with subtopics
5394 %  \secondary {subtopic}{pagelist}
5395 %     for each subtopic.
5396
5397 % Define the user-accessible indexing commands
5398 % @findex, @vindex, @kindex, @cindex.
5399
5400 \def\findex {\fnindex}
5401 \def\kindex {\kyindex}
5402 \def\cindex {\cpindex}
5403 \def\vindex {\vrindex}
5404 \def\tindex {\tpindex}
5405 \def\pindex {\pgindex}
5406
5407 \def\cindexsub {\begingroup\obeylines\cindexsub}
5408 {\obeylines %
5409 \gdef\cindexsub "#1" #2^^M{\endgroup %
5410 \dosubind{cp}{#2}{#1}}}
5411
5412 % Define the macros used in formatting output of the sorted index material.
5413
5414 % @printindex causes a particular index (the ??s file) to get printed.
5415 % It does not print any chapter heading (usually an @unnumbered).
5416 %
5417 \parseargdef\printindex{\begingroup
5418   \dobreak \chapheadingskip{10000}%
5419   %
5420   \smallfonts \rm
5421   \tolerance = 9500
5422   \plainfrenchspacing
5423   \everypar = {}% don't want the \kern\-parindent from indentation suppression.
5424   %
5425   % See if the index file exists and is nonempty.
5426   % Change catcode of @ here so that if the index file contains
5427   % \initial {@}
5428   % as its first line, TeX doesn't complain about mismatched braces
5429   % (because it thinks @} is a control sequence).
5430   \catcode`\@ = 11
5431   % See comment in \requireopenindexfile.
5432   \def\indexname{#1}\ifx\indexname\indexisfl\def\indexname{f1}\fi
5433   \openin 1 \jobname.\indexname s
5434   \ifeof 1
5435     % \enddoublecolumns gets confused if there is no text in the index,
5436     % and it loses the chapter title and the aux file entries for the
5437     % index.  The easiest way to prevent this problem is to make sure
5438     % there is some text.
5439     \putwordIndexNonexistent
5440     \typeout{No file \jobname.\indexname s.}%
5441   \else
5442     \catcode`\\ = 0
5443     %
5444     % If the index file exists but is empty, then \openin leaves \ifeof
5445     % false.  We have to make TeX try to read something from the file, so
5446     % it can discover if there is anything in it.
5447     \read 1 to \thisline
5448     \ifeof 1
5449       \putwordIndexIsEmpty
5450     \else
5451       % Index files are almost Texinfo source, but we use \ as the escape
5452       % character.  It would be better to use @, but that's too big a change
5453       % to make right now.
5454       \def\indexbackslash{\ttbackslash}%
5455       \let\indexlbrace\{   % Likewise, set these sequences for braces
5456       \let\indexrbrace\}   % used in the sort key.
5457       \begindoublecolumns
5458       \let\entryorphanpenalty=\indexorphanpenalty
5459       %
5460       % Read input from the index file line by line.
5461       \loopdo
5462         \ifeof1
5463           \let\firsttoken\relax
5464         \else
5465           \read 1 to \nextline
5466           \edef\act{\gdef\noexpand\firsttoken{\getfirsttoken\nextline}}%
5467           \act
5468         \fi
5469         \thisline
5470         %
5471         \ifeof1\else
5472         \let\thisline\nextline
5473       \repeat
5474       %%
5475       \enddoublecolumns
5476     \fi
5477   \fi
5478   \closein 1
5479 \endgroup}
5480
5481 \def\getfirsttoken#1{\expandafter\getfirsttokenx#1\endfirsttoken}
5482 \long\def\getfirsttokenx#1#2\endfirsttoken{\noexpand#1}
5483
5484 \def\loopdo#1\repeat{\def\body{#1}\loopdoxxx}
5485 \def\loopdoxxx{\let\next=\relax\body\let\next=\loopdoxxx\fi\next}
5486
5487 % These macros are used by the sorted index file itself.
5488 % Change them to control the appearance of the index.
5489
5490 {\catcode`\/=13 \catcode`\-=13 \catcode`\^=13 \catcode`\~=13 \catcode`\_=13
5491 \catcode`\|=13 \catcode`\<=13 \catcode`\>=13 \catcode`\+=13 \catcode`\"=13
5492 \catcode`\$=3
5493 \gdef\initialglyphs{%
5494   % Some changes for non-alphabetic characters.  Using the glyphs from the
5495   % math fonts looks more consistent than the typewriter font used elsewhere
5496   % for these characters.
5497   \def\indexbackslash{\math{\backslash}}%
5498   \let\\=\indexbackslash
5499   %
5500   % Can't get bold backslash so don't use bold forward slash
5501   \catcode`\/=13
5502   \def/{{\secrmnotbold \normalslash}}%
5503   \def-{{\normaldash\normaldash}}% en dash `--'
5504   \def^{{\chapbf \normalcaret}}%
5505   \def~{{\chapbf \normaltilde}}%
5506   \def\_{%
5507      \leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }%
5508   \def|{$\vert$}%
5509   \def<{$\less$}%
5510   \def>{$\gtr$}%
5511   \def+{$\normalplus$}%
5512 }}
5513
5514 \def\initial{%
5515   \bgroup
5516   \initialglyphs
5517   \initialx
5518 }
5519
5520 \def\initialx#1{%
5521   % Remove any glue we may have, we'll be inserting our own.
5522   \removelastskip
5523   %
5524   % We like breaks before the index initials, so insert a bonus.
5525   % The glue before the bonus allows a little bit of space at the
5526   % bottom of a column to reduce an increase in inter-line spacing.
5527   \nobreak
5528   \vskip 0pt plus 5\baselineskip
5529   \penalty -300 
5530   \vskip 0pt plus -5\baselineskip
5531   %
5532   % Typeset the initial.  Making this add up to a whole number of
5533   % baselineskips increases the chance of the dots lining up from column
5534   % to column.  It still won't often be perfect, because of the stretch
5535   % we need before each entry, but it's better.
5536   %
5537   % No shrink because it confuses \balancecolumns.
5538   \vskip 1.67\baselineskip plus 1\baselineskip
5539   \leftline{\secfonts \kern-0.05em \secbf #1}%
5540   % \secfonts is inside the argument of \leftline so that the change of
5541   % \baselineskip will not affect any glue inserted before the vbox that
5542   % \leftline creates.
5543   % Do our best not to break after the initial.
5544   \nobreak
5545   \vskip .33\baselineskip plus .1\baselineskip
5546   \egroup % \initialglyphs
5547 }
5548
5549 \newdimen\entryrightmargin
5550 \entryrightmargin=0pt
5551
5552 % \entry typesets a paragraph consisting of the text (#1), dot leaders, and
5553 % then page number (#2) flushed to the right margin.  It is used for index
5554 % and table of contents entries.  The paragraph is indented by \leftskip.
5555 %
5556 \def\entry{%
5557   \begingroup
5558     %
5559     % Start a new paragraph if necessary, so our assignments below can't
5560     % affect previous text.
5561     \par
5562     %
5563     % No extra space above this paragraph.
5564     \parskip = 0in
5565     %
5566     % When reading the text of entry, convert explicit line breaks
5567     % from @* into spaces.  The user might give these in long section
5568     % titles, for instance.
5569     \def\*{\unskip\space\ignorespaces}%
5570     \def\entrybreak{\hfil\break}% An undocumented command
5571     %
5572     % A bit of stretch before each entry for the benefit of balancing
5573     % columns.
5574     \vskip 0pt plus0.5pt
5575     %
5576     % Swallow the left brace of the text (first parameter):
5577     \afterassignment\doentry
5578     \let\temp =
5579 }
5580 \def\entrybreak{\unskip\space\ignorespaces}%
5581 \def\doentry{%
5582     % Save the text of the entry
5583     \global\setbox\boxA=\hbox\bgroup
5584     \bgroup % Instead of the swallowed brace.
5585       \noindent
5586       \aftergroup\finishentry
5587       % And now comes the text of the entry.
5588       % Not absorbing as a macro argument reduces the chance of problems
5589       % with catcodes occurring.
5590 }
5591 {\catcode`\@=11
5592 \gdef\finishentry#1{%
5593     \egroup % end box A
5594     \dimen@ = \wd\boxA % Length of text of entry
5595     \global\setbox\boxA=\hbox\bgroup\unhbox\boxA
5596     % #1 is the page number.
5597     %
5598     % Get the width of the page numbers, and only use
5599     % leaders if they are present.
5600     \global\setbox\boxB = \hbox{#1}%
5601     \ifdim\wd\boxB = 0pt
5602       \null\nobreak\hfill\ %
5603     \else
5604       %
5605       \null\nobreak\indexdotfill % Have leaders before the page number.
5606       %
5607       \ifpdf
5608         \pdfgettoks#1.%
5609         \bgroup\let\domark\relax
5610           \hskip\skip\thinshrinkable\the\toksA
5611         \egroup
5612         % The redefinion of \domark stops marks being added in \pdflink to 
5613         % preserve coloured links across page boundaries.  Otherwise the marks
5614         % would get in the way of \lastbox in \insertindexentrybox.
5615       \else
5616         \ifx\XeTeXrevision\thisisundefined
5617           \hskip\skip\thinshrinkable #1%
5618         \else
5619           \pdfgettoks#1.%
5620           \bgroup\let\domark\relax
5621             \hskip\skip\thinshrinkable\the\toksA
5622           \egroup
5623         \fi
5624       \fi
5625     \fi
5626     \egroup % end \boxA
5627     \ifdim\wd\boxB = 0pt
5628       \global\setbox\entryindexbox=\vbox{\unhbox\boxA}%
5629     \else
5630     \global\setbox\entryindexbox=\vbox\bgroup
5631       \prevdepth=\entrylinedepth
5632       \noindent
5633       % We want the text of the entries to be aligned to the left, and the
5634       % page numbers to be aligned to the right.
5635       %
5636       \advance\leftskip by 0pt plus 1fil
5637       \advance\leftskip by 0pt plus -1fill
5638       \rightskip = 0pt plus -1fil
5639       \advance\rightskip by 0pt plus 1fill
5640       % Cause last line, which could consist of page numbers on their own
5641       % if the list of page numbers is long, to be aligned to the right.
5642       \parfillskip=0pt plus -1fill
5643       %
5644       \hangindent=1em
5645       %
5646       \advance\rightskip by \entryrightmargin
5647       % Determine how far we can stretch into the margin.
5648       % This allows, e.g., "Appendix H  GNU Free Documentation License" to
5649       % fit on one line in @letterpaper format.
5650       \ifdim\entryrightmargin>2.1em
5651         \dimen@i=2.1em
5652       \else
5653         \dimen@i=0em
5654       \fi
5655       \advance \parfillskip by 0pt minus 1\dimen@i
5656       %
5657       \dimen@ii = \hsize
5658       \advance\dimen@ii by -1\leftskip
5659       \advance\dimen@ii by -1\entryrightmargin
5660       \advance\dimen@ii by 1\dimen@i
5661       \ifdim\wd\boxA > \dimen@ii % If the entry doesn't fit in one line
5662       \ifdim\dimen@ > 0.8\dimen@ii   % due to long index text
5663         \dimen@ = 0.7\dimen@ % Try to split the text roughly evenly
5664         \dimen@ii = \hsize
5665         \advance \dimen@ii by -1em
5666         \ifnum\dimen@>\dimen@ii
5667           % If the entry is too long, use the whole line
5668           \dimen@ = \dimen@ii
5669         \fi
5670         \advance\leftskip by 0pt plus 1fill % ragged right
5671         \advance \dimen@ by 1\rightskip
5672         \parshape = 2 0pt \dimen@ 1em \dimen@ii
5673         % Ideally we'd add a finite glue at the end of the first line only, but
5674         % TeX doesn't seem to provide a way to do such a thing.
5675       \fi\fi
5676       \unhbox\boxA
5677       %
5678       % Do not prefer a separate line ending with a hyphen to fewer lines.
5679       \finalhyphendemerits = 0
5680       %
5681       % Word spacing - no stretch
5682       \spaceskip=\fontdimen2\font minus \fontdimen4\font
5683       %
5684       \linepenalty=1000  % Discourage line breaks.
5685       \hyphenpenalty=5000  % Discourage hyphenation.
5686       %
5687       \par % format the paragraph
5688     \egroup % The \vbox
5689     \fi
5690   \endgroup
5691   % delay text of entry until after penalty
5692   \bgroup\aftergroup\insertindexentrybox
5693   \entryorphanpenalty
5694 }}
5695
5696 \newskip\thinshrinkable
5697 \skip\thinshrinkable=.15em minus .15em
5698
5699 \newbox\entryindexbox
5700 \def\insertindexentrybox{%
5701   \copy\entryindexbox
5702   % The following gets the depth of the last box.  This is for even
5703   % line spacing when entries span several lines.
5704   \setbox\dummybox\vbox{%
5705     \unvbox\entryindexbox
5706     \nointerlineskip
5707     \lastbox
5708     \global\entrylinedepth=\prevdepth
5709   }%
5710   % Note that we couldn't simply \unvbox\entryindexbox followed by 
5711   % \nointerlineskip\lastbox to remove the last box and then reinstate it, 
5712   % because this resets how far the box has been \moveleft'ed to 0.  \unvbox
5713   % doesn't affect \prevdepth either.
5714 }
5715 \newdimen\entrylinedepth
5716
5717 % Default is no penalty
5718 \let\entryorphanpenalty\egroup
5719
5720 % Used from \printindex.  \firsttoken should be the first token
5721 % after the \entry.  If it's not another \entry, we are at the last
5722 % line of a group of index entries, so insert a penalty to discourage
5723 % orphaned index entries.
5724 \long\def\indexorphanpenalty{%
5725   \def\isentry{\entry}%
5726   \ifx\firsttoken\isentry
5727   \else
5728     \unskip\penalty 9000
5729     % The \unskip here stops breaking before the glue.  It relies on the
5730     % \vskip above being there, otherwise there is an error
5731     % "You can't use `\unskip' in vertical mode".  There has to be glue
5732     % in the current vertical list that hasn't been added to the
5733     % "current page".  See Chapter 24 of the TeXbook.  This contradicts
5734     % Section 8.3.7 in "TeX by Topic," though.
5735   \fi
5736   \egroup % now comes the box added with \aftergroup
5737 }
5738
5739 % Like plain.tex's \dotfill, except uses up at least 1 em.
5740 % The filll stretch here overpowers both the fil and fill stretch to push
5741 % the page number to the right.
5742 \def\indexdotfill{\cleaders
5743   \hbox{$\mathsurround=0pt \mkern1.5mu.\mkern1.5mu$}\hskip 1em plus 1filll}
5744
5745
5746 \def\primary #1{\line{#1\hfil}}
5747
5748 \newskip\secondaryindent \secondaryindent=0.5cm
5749 \def\secondary#1#2{{%
5750   \parfillskip=0in
5751   \parskip=0in
5752   \hangindent=1in
5753   \hangafter=1
5754   \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
5755   \ifpdf
5756     \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5757   \else
5758     \ifx\XeTeXrevision\thisisundefined
5759       #2
5760     \else
5761       \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
5762     \fi
5763   \fi
5764   \par
5765 }}
5766
5767 % Define two-column mode, which we use to typeset indexes.
5768 % Adapted from the TeXbook, page 416, which is to say,
5769 % the manmac.tex format used to print the TeXbook itself.
5770 \catcode`\@=11  % private names
5771
5772 \newbox\partialpage
5773 \newdimen\doublecolumnhsize
5774 \newdimen\doublecolumntopgap
5775 \doublecolumntopgap = 0pt
5776
5777 % Use inside an output routine to save \topmark and \firstmark
5778 \def\savemarks{%
5779   \global\savedtopmark=\expandafter{\topmark }%
5780   \global\savedfirstmark=\expandafter{\firstmark }%
5781 }
5782 \newtoks\savedtopmark
5783 \newtoks\savedfirstmark
5784
5785 % Set \topmark and \firstmark for next time \output runs.
5786 % Can't be run from withinside \output (because any material
5787 % added while an output routine is active, including 
5788 % penalties, is saved for after it finishes).  The page so far
5789 % should be empty, otherwise what's on it will be thrown away.
5790 \def\restoremarks{%
5791   \mark{\the\savedtopmark}%
5792   \bgroup\output = {%
5793     \setbox\dummybox=\box\PAGE
5794   }abc\eject\egroup
5795   % "abc" because output routine doesn't fire for a completely empty page.
5796   \mark{\the\savedfirstmark}%
5797 }
5798
5799 \def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
5800   % If not much space left on page, start a new page.
5801   \ifdim\pagetotal>0.8\vsize\vfill\eject\fi
5802   %
5803   % Grab any single-column material above us.
5804   \output = {%
5805     %
5806     % Here is a possibility not foreseen in manmac: if we accumulate a
5807     % whole lot of material, we might end up calling this \output
5808     % routine twice in a row (see the doublecol-lose test, which is
5809     % essentially a couple of indexes with @setchapternewpage off).  In
5810     % that case we just ship out what is in \partialpage with the normal
5811     % output routine.  Generally, \partialpage will be empty when this
5812     % runs and this will be a no-op.  See the indexspread.tex test case.
5813     \ifvoid\partialpage \else
5814       \onepageout{\pagecontents\partialpage}%
5815     \fi
5816     %
5817     \global\setbox\partialpage = \vbox{%
5818       % Unvbox the main output page.
5819       \unvbox\PAGE
5820       \kern-\topskip \kern\baselineskip
5821     }%
5822     \savemarks
5823   }%
5824   \eject % run that output routine to set \partialpage
5825   \restoremarks
5826   %
5827   % We recover the two marks that the last output routine saved in order
5828   % to propagate the information in marks added around a chapter heading,
5829   % which could be otherwise be lost by the time the final page is output.
5830   %
5831   %
5832   % Use the double-column output routine for subsequent pages.
5833   \output = {\doublecolumnout}%
5834   %
5835   % Change the page size parameters.  We could do this once outside this
5836   % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
5837   % format, but then we repeat the same computation.  Repeating a couple
5838   % of assignments once per index is clearly meaningless for the
5839   % execution time, so we may as well do it in one place.
5840   %
5841   % First we halve the line length, less a little for the gutter between
5842   % the columns.  We compute the gutter based on the line length, so it
5843   % changes automatically with the paper format.  The magic constant
5844   % below is chosen so that the gutter has the same value (well, +-<1pt)
5845   % as it did when we hard-coded it.
5846   %
5847   % We put the result in a separate register, \doublecolumhsize, so we
5848   % can restore it in \pagesofar, after \hsize itself has (potentially)
5849   % been clobbered.
5850   %
5851   \doublecolumnhsize = \hsize
5852     \advance\doublecolumnhsize by -.04154\hsize
5853     \divide\doublecolumnhsize by 2
5854   \hsize = \doublecolumnhsize
5855   %
5856   % Double the \vsize as well.  (We don't need a separate register here,
5857   % since nobody clobbers \vsize.)
5858   \global\doublecolumntopgap = \topskip
5859   \global\advance\doublecolumntopgap by -1\baselineskip
5860   \advance\vsize by -1\doublecolumntopgap
5861   \vsize = 2\vsize
5862   \topskip=0pt
5863   \global\entrylinedepth=0pt\relax
5864 }
5865
5866 % The double-column output routine for all double-column pages except
5867 % the last, which is done by \balancecolumns.
5868 %
5869 \def\doublecolumnout{%
5870   %
5871   \splittopskip=\topskip \splitmaxdepth=\maxdepth
5872   % Get the available space for the double columns -- the normal
5873   % (undoubled) page height minus any material left over from the
5874   % previous page.
5875   \dimen@ = \vsize
5876   \divide\dimen@ by 2
5877   \advance\dimen@ by -\ht\partialpage
5878   %
5879   % box0 will be the left-hand column, box2 the right.
5880   \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
5881   \onepageout\pagesofar
5882   \unvbox255
5883   \penalty\outputpenalty
5884 }
5885 %
5886 % Re-output the contents of the output page -- any previous material,
5887 % followed by the two boxes we just split, in box0 and box2.
5888 \def\pagesofar{%
5889   \unvbox\partialpage
5890   %
5891   \hsize = \doublecolumnhsize
5892   \wd0=\hsize \wd2=\hsize
5893   \vbox{%
5894     \vskip\doublecolumntopgap
5895     \hbox to\txipagewidth{\box0\hfil\box2}}%
5896 }
5897
5898
5899 % Finished with with double columns.
5900 \def\enddoublecolumns{%
5901   % The following penalty ensures that the page builder is exercised
5902   % _before_ we change the output routine.  This is necessary in the
5903   % following situation:
5904   %
5905   % The last section of the index consists only of a single entry.
5906   % Before this section, \pagetotal is less than \pagegoal, so no
5907   % break occurs before the last section starts.  However, the last
5908   % section, consisting of \initial and the single \entry, does not
5909   % fit on the page and has to be broken off.  Without the following
5910   % penalty the page builder will not be exercised until \eject
5911   % below, and by that time we'll already have changed the output
5912   % routine to the \balancecolumns version, so the next-to-last
5913   % double-column page will be processed with \balancecolumns, which
5914   % is wrong:  The two columns will go to the main vertical list, with
5915   % the broken-off section in the recent contributions.  As soon as
5916   % the output routine finishes, TeX starts reconsidering the page
5917   % break.  The two columns and the broken-off section both fit on the
5918   % page, because the two columns now take up only half of the page
5919   % goal.  When TeX sees \eject from below which follows the final
5920   % section, it invokes the new output routine that we've set after
5921   % \balancecolumns below; \onepageout will try to fit the two columns
5922   % and the final section into the vbox of \txipageheight (see
5923   % \pagebody), causing an overfull box.
5924   %
5925   % Note that glue won't work here, because glue does not exercise the
5926   % page builder, unlike penalties (see The TeXbook, pp. 280-281).
5927   \penalty0
5928   %
5929   \output = {%
5930     % Split the last of the double-column material.
5931     \savemarks
5932     \balancecolumns
5933     %
5934     % Having called \balancecolumns once, we do not
5935     % want to call it again.  Therefore, reset \output to its normal
5936     % definition right away.
5937     \global\output = {\onepageout{\pagecontents\PAGE}}%
5938   }%
5939   \eject
5940   \endgroup % started in \begindoublecolumns
5941   \restoremarks
5942   % Leave the double-column material on the current page, no automatic
5943   % page break.
5944   \box\balancedcolumns
5945   %
5946   % \pagegoal was set to the doubled \vsize above, since we restarted
5947   % the current page.  We're now back to normal single-column
5948   % typesetting, so reset \pagegoal to the normal \vsize (after the
5949   % \endgroup where \vsize got restored).
5950   \pagegoal = \vsize
5951 }
5952 \newbox\balancedcolumns
5953 \setbox\balancedcolumns=\vbox{shouldnt see this}%
5954 %
5955 % Only called for the last of the double column material.  \doublecolumnout 
5956 % does the others.
5957 \def\balancecolumns{%
5958   \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
5959   \dimen@ = \ht0
5960   \advance\dimen@ by \topskip
5961   \advance\dimen@ by-\baselineskip
5962   \ifdim\dimen@<14\baselineskip
5963     % Don't split a short final column in two.
5964     \setbox2=\vbox{}%
5965   \else
5966     \divide\dimen@ by 2 % target to split to
5967     \dimen@ii = \dimen@
5968     \splittopskip = \topskip
5969     % Loop until the second column is no higher than the first
5970     {%
5971       \vbadness = 10000
5972       \loop
5973         \global\setbox3 = \copy0
5974         \global\setbox1 = \vsplit3 to \dimen@
5975         % Remove glue from bottom of first column to
5976         % make sure it is higher than the second.
5977         \global\setbox1 = \vbox{\unvbox1\unpenalty\unskip}%
5978       \ifdim\ht3>\ht1
5979         \global\advance\dimen@ by 1pt
5980       \repeat
5981     }%
5982     \ifdim2\ht1>\vsize
5983       % The left column has come out longer than the page itself.  (Note
5984       % that we have doubled \vsize for the double columns, so
5985       % the actual height of the page is 0.5\vsize).  Just split the last
5986       % of the double column material roughly in half.
5987       \setbox2=\box0
5988       \setbox0 = \vsplit2 to \dimen@ii
5989       \setbox0=\vbox to\dimen@ii{\unvbox0}%
5990       \setbox2=\vbox to\dimen@ii{\unvbox2}%
5991     \else
5992       \multiply\dimen@ii by 5
5993       \divide\dimen@ii by 4
5994       \global\setbox3 = \copy0
5995       \global\setbox1 = \vsplit3 to \dimen@ii
5996       \global\setbox\balancedcolumns=\vbox{\pagesofar}%
5997       \ifdim\ht3<\dimen@ii
5998         % Column heights are too different, so don't make their bottoms
5999         % flush with each other.  The glue at the end of the second column
6000         % allows a second column to stretch, reducing the difference in
6001         % height between the two.
6002         \setbox0=\vbox to\dimen@{\unvbox1\vfill}%
6003         \setbox2=\vbox to\dimen@{\unvbox3\vskip 0pt plus 0.3\ht0}%
6004       \else
6005         \setbox0=\vbox to\dimen@{\unvbox1}%
6006         \setbox2=\vbox to\dimen@{\unvbox3}%
6007       \fi
6008     \fi
6009   \fi
6010   %
6011   \global\setbox\balancedcolumns=\vbox{\pagesofar}%
6012 }
6013 \catcode`\@ = \other
6014
6015
6016 \message{sectioning,}
6017 % Chapters, sections, etc.
6018
6019 % Let's start with @part.
6020 \outer\parseargdef\part{\partzzz{#1}}
6021 \def\partzzz#1{%
6022   \chapoddpage
6023   \null
6024   \vskip.3\vsize  % move it down on the page a bit
6025   \begingroup
6026     \noindent \titlefonts\rmisbold #1\par % the text
6027     \let\lastnode=\empty      % no node to associate with
6028     \writetocentry{part}{#1}{}% but put it in the toc
6029     \headingsoff              % no headline or footline on the part page
6030     % This outputs a mark at the end of the page that clears \thischapter
6031     % and \thissection, as is done in \startcontents.
6032     \let\pchapsepmacro\relax
6033     \chapmacro{}{Yomitfromtoc}{}%
6034     \chapoddpage
6035   \endgroup
6036 }
6037
6038 % \unnumberedno is an oxymoron.  But we count the unnumbered
6039 % sections so that we can refer to them unambiguously in the pdf
6040 % outlines by their "section number".  We avoid collisions with chapter
6041 % numbers by starting them at 10000.  (If a document ever has 10000
6042 % chapters, we're in trouble anyway, I'm sure.)
6043 \newcount\unnumberedno \unnumberedno = 10000
6044 \newcount\chapno
6045 \newcount\secno        \secno=0
6046 \newcount\subsecno     \subsecno=0
6047 \newcount\subsubsecno  \subsubsecno=0
6048
6049 % This counter is funny since it counts through charcodes of letters A, B, ...
6050 \newcount\appendixno  \appendixno = `\@
6051 %
6052 % \def\appendixletter{\char\the\appendixno}
6053 % We do the following ugly conditional instead of the above simple
6054 % construct for the sake of pdftex, which needs the actual
6055 % letter in the expansion, not just typeset.
6056 %
6057 \def\appendixletter{%
6058   \ifnum\appendixno=`A A%
6059   \else\ifnum\appendixno=`B B%
6060   \else\ifnum\appendixno=`C C%
6061   \else\ifnum\appendixno=`D D%
6062   \else\ifnum\appendixno=`E E%
6063   \else\ifnum\appendixno=`F F%
6064   \else\ifnum\appendixno=`G G%
6065   \else\ifnum\appendixno=`H H%
6066   \else\ifnum\appendixno=`I I%
6067   \else\ifnum\appendixno=`J J%
6068   \else\ifnum\appendixno=`K K%
6069   \else\ifnum\appendixno=`L L%
6070   \else\ifnum\appendixno=`M M%
6071   \else\ifnum\appendixno=`N N%
6072   \else\ifnum\appendixno=`O O%
6073   \else\ifnum\appendixno=`P P%
6074   \else\ifnum\appendixno=`Q Q%
6075   \else\ifnum\appendixno=`R R%
6076   \else\ifnum\appendixno=`S S%
6077   \else\ifnum\appendixno=`T T%
6078   \else\ifnum\appendixno=`U U%
6079   \else\ifnum\appendixno=`V V%
6080   \else\ifnum\appendixno=`W W%
6081   \else\ifnum\appendixno=`X X%
6082   \else\ifnum\appendixno=`Y Y%
6083   \else\ifnum\appendixno=`Z Z%
6084   % The \the is necessary, despite appearances, because \appendixletter is
6085   % expanded while writing the .toc file.  \char\appendixno is not
6086   % expandable, thus it is written literally, thus all appendixes come out
6087   % with the same letter (or @) in the toc without it.
6088   \else\char\the\appendixno
6089   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
6090   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
6091
6092 % Each @chapter defines these (using marks) as the number+name, number
6093 % and name of the chapter.  Page headings and footings can use
6094 % these.  @section does likewise.
6095 \def\thischapter{}
6096 \def\thischapternum{}
6097 \def\thischaptername{}
6098 \def\thissection{}
6099 \def\thissectionnum{}
6100 \def\thissectionname{}
6101
6102 \newcount\absseclevel % used to calculate proper heading level
6103 \newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
6104
6105 % @raisesections: treat @section as chapter, @subsection as section, etc.
6106 \def\raisesections{\global\advance\secbase by -1}
6107 \let\up=\raisesections % original BFox name
6108
6109 % @lowersections: treat @chapter as section, @section as subsection, etc.
6110 \def\lowersections{\global\advance\secbase by 1}
6111 \let\down=\lowersections % original BFox name
6112
6113 % we only have subsub.
6114 \chardef\maxseclevel = 3
6115 %
6116 % A numbered section within an unnumbered changes to unnumbered too.
6117 % To achieve this, remember the "biggest" unnum. sec. we are currently in:
6118 \chardef\unnlevel = \maxseclevel
6119 %
6120 % Trace whether the current chapter is an appendix or not:
6121 % \chapheadtype is "N" or "A", unnumbered chapters are ignored.
6122 \def\chapheadtype{N}
6123
6124 % Choose a heading macro
6125 % #1 is heading type
6126 % #2 is heading level
6127 % #3 is text for heading
6128 \def\genhead#1#2#3{%
6129   % Compute the abs. sec. level:
6130   \absseclevel=#2
6131   \advance\absseclevel by \secbase
6132   % Make sure \absseclevel doesn't fall outside the range:
6133   \ifnum \absseclevel < 0
6134     \absseclevel = 0
6135   \else
6136     \ifnum \absseclevel > 3
6137       \absseclevel = 3
6138     \fi
6139   \fi
6140   % The heading type:
6141   \def\headtype{#1}%
6142   \if \headtype U%
6143     \ifnum \absseclevel < \unnlevel
6144       \chardef\unnlevel = \absseclevel
6145     \fi
6146   \else
6147     % Check for appendix sections:
6148     \ifnum \absseclevel = 0
6149       \edef\chapheadtype{\headtype}%
6150     \else
6151       \if \headtype A\if \chapheadtype N%
6152         \errmessage{@appendix... within a non-appendix chapter}%
6153       \fi\fi
6154     \fi
6155     % Check for numbered within unnumbered:
6156     \ifnum \absseclevel > \unnlevel
6157       \def\headtype{U}%
6158     \else
6159       \chardef\unnlevel = 3
6160     \fi
6161   \fi
6162   % Now print the heading:
6163   \if \headtype U%
6164     \ifcase\absseclevel
6165         \unnumberedzzz{#3}%
6166     \or \unnumberedseczzz{#3}%
6167     \or \unnumberedsubseczzz{#3}%
6168     \or \unnumberedsubsubseczzz{#3}%
6169     \fi
6170   \else
6171     \if \headtype A%
6172       \ifcase\absseclevel
6173           \appendixzzz{#3}%
6174       \or \appendixsectionzzz{#3}%
6175       \or \appendixsubseczzz{#3}%
6176       \or \appendixsubsubseczzz{#3}%
6177       \fi
6178     \else
6179       \ifcase\absseclevel
6180           \chapterzzz{#3}%
6181       \or \seczzz{#3}%
6182       \or \numberedsubseczzz{#3}%
6183       \or \numberedsubsubseczzz{#3}%
6184       \fi
6185     \fi
6186   \fi
6187   \suppressfirstparagraphindent
6188 }
6189
6190 % an interface:
6191 \def\numhead{\genhead N}
6192 \def\apphead{\genhead A}
6193 \def\unnmhead{\genhead U}
6194
6195 % @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
6196 % all lower-level sectioning counters to zero.
6197 %
6198 % Also set \chaplevelprefix, which we prepend to @float sequence numbers
6199 % (e.g., figures), q.v.  By default (before any chapter), that is empty.
6200 \let\chaplevelprefix = \empty
6201 %
6202 \outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
6203 \def\chapterzzz#1{%
6204   % section resetting is \global in case the chapter is in a group, such
6205   % as an @include file.
6206   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6207     \global\advance\chapno by 1
6208   %
6209   % Used for \float.
6210   \gdef\chaplevelprefix{\the\chapno.}%
6211   \resetallfloatnos
6212   %
6213   % \putwordChapter can contain complex things in translations.
6214   \toks0=\expandafter{\putwordChapter}%
6215   \message{\the\toks0 \space \the\chapno}%
6216   %
6217   % Write the actual heading.
6218   \chapmacro{#1}{Ynumbered}{\the\chapno}%
6219   %
6220   % So @section and the like are numbered underneath this chapter.
6221   \global\let\section = \numberedsec
6222   \global\let\subsection = \numberedsubsec
6223   \global\let\subsubsection = \numberedsubsubsec
6224 }
6225
6226 \outer\parseargdef\appendix{\apphead0{#1}} % normally calls appendixzzz
6227 %
6228 \def\appendixzzz#1{%
6229   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6230     \global\advance\appendixno by 1
6231   \gdef\chaplevelprefix{\appendixletter.}%
6232   \resetallfloatnos
6233   %
6234   % \putwordAppendix can contain complex things in translations.
6235   \toks0=\expandafter{\putwordAppendix}%
6236   \message{\the\toks0 \space \appendixletter}%
6237   %
6238   \chapmacro{#1}{Yappendix}{\appendixletter}%
6239   %
6240   \global\let\section = \appendixsec
6241   \global\let\subsection = \appendixsubsec
6242   \global\let\subsubsection = \appendixsubsubsec
6243 }
6244
6245 % normally unnmhead0 calls unnumberedzzz:
6246 \outer\parseargdef\unnumbered{\unnmhead0{#1}}
6247 \def\unnumberedzzz#1{%
6248   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
6249     \global\advance\unnumberedno by 1
6250   %
6251   % Since an unnumbered has no number, no prefix for figures.
6252   \global\let\chaplevelprefix = \empty
6253   \resetallfloatnos
6254   %
6255   % This used to be simply \message{#1}, but TeX fully expands the
6256   % argument to \message.  Therefore, if #1 contained @-commands, TeX
6257   % expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
6258   % expanded @cite (which turns out to cause errors because \cite is meant
6259   % to be executed, not expanded).
6260   %
6261   % Anyway, we don't want the fully-expanded definition of @cite to appear
6262   % as a result of the \message, we just want `@cite' itself.  We use
6263   % \the<toks register> to achieve this: TeX expands \the<toks> only once,
6264   % simply yielding the contents of <toks register>.  (We also do this for
6265   % the toc entries.)
6266   \toks0 = {#1}%
6267   \message{(\the\toks0)}%
6268   %
6269   \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
6270   %
6271   \global\let\section = \unnumberedsec
6272   \global\let\subsection = \unnumberedsubsec
6273   \global\let\subsubsection = \unnumberedsubsubsec
6274 }
6275
6276 % @centerchap is like @unnumbered, but the heading is centered.
6277 \outer\parseargdef\centerchap{%
6278   \let\centerparametersmaybe = \centerparameters
6279   \unnmhead0{#1}%
6280   \let\centerparametersmaybe = \relax
6281 }
6282
6283 % @top is like @unnumbered.
6284 \let\top\unnumbered
6285
6286 % Sections.
6287
6288 \outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
6289 \def\seczzz#1{%
6290   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6291   \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
6292 }
6293
6294 % normally calls appendixsectionzzz:
6295 \outer\parseargdef\appendixsection{\apphead1{#1}}
6296 \def\appendixsectionzzz#1{%
6297   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6298   \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
6299 }
6300 \let\appendixsec\appendixsection
6301
6302 % normally calls unnumberedseczzz:
6303 \outer\parseargdef\unnumberedsec{\unnmhead1{#1}}
6304 \def\unnumberedseczzz#1{%
6305   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
6306   \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
6307 }
6308
6309 % Subsections.
6310
6311 % normally calls numberedsubseczzz:
6312 \outer\parseargdef\numberedsubsec{\numhead2{#1}}
6313 \def\numberedsubseczzz#1{%
6314   \global\subsubsecno=0  \global\advance\subsecno by 1
6315   \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
6316 }
6317
6318 % normally calls appendixsubseczzz:
6319 \outer\parseargdef\appendixsubsec{\apphead2{#1}}
6320 \def\appendixsubseczzz#1{%
6321   \global\subsubsecno=0  \global\advance\subsecno by 1
6322   \sectionheading{#1}{subsec}{Yappendix}%
6323                  {\appendixletter.\the\secno.\the\subsecno}%
6324 }
6325
6326 % normally calls unnumberedsubseczzz:
6327 \outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}}
6328 \def\unnumberedsubseczzz#1{%
6329   \global\subsubsecno=0  \global\advance\subsecno by 1
6330   \sectionheading{#1}{subsec}{Ynothing}%
6331                  {\the\unnumberedno.\the\secno.\the\subsecno}%
6332 }
6333
6334 % Subsubsections.
6335
6336 % normally numberedsubsubseczzz:
6337 \outer\parseargdef\numberedsubsubsec{\numhead3{#1}}
6338 \def\numberedsubsubseczzz#1{%
6339   \global\advance\subsubsecno by 1
6340   \sectionheading{#1}{subsubsec}{Ynumbered}%
6341                  {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
6342 }
6343
6344 % normally appendixsubsubseczzz:
6345 \outer\parseargdef\appendixsubsubsec{\apphead3{#1}}
6346 \def\appendixsubsubseczzz#1{%
6347   \global\advance\subsubsecno by 1
6348   \sectionheading{#1}{subsubsec}{Yappendix}%
6349                  {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
6350 }
6351
6352 % normally unnumberedsubsubseczzz:
6353 \outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}}
6354 \def\unnumberedsubsubseczzz#1{%
6355   \global\advance\subsubsecno by 1
6356   \sectionheading{#1}{subsubsec}{Ynothing}%
6357                  {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
6358 }
6359
6360 % These macros control what the section commands do, according
6361 % to what kind of chapter we are in (ordinary, appendix, or unnumbered).
6362 % Define them by default for a numbered chapter.
6363 \let\section = \numberedsec
6364 \let\subsection = \numberedsubsec
6365 \let\subsubsection = \numberedsubsubsec
6366
6367 % Define @majorheading, @heading and @subheading
6368
6369 \def\majorheading{%
6370   {\advance\chapheadingskip by 10pt \chapbreak }%
6371   \parsearg\chapheadingzzz
6372 }
6373
6374 \def\chapheading{\chapbreak \parsearg\chapheadingzzz}
6375 \def\chapheadingzzz#1{%
6376   \vbox{\chapfonts \raggedtitlesettings #1\par}%
6377   \nobreak\bigskip \nobreak
6378   \suppressfirstparagraphindent
6379 }
6380
6381 % @heading, @subheading, @subsubheading.
6382 \parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
6383   \suppressfirstparagraphindent}
6384 \parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
6385   \suppressfirstparagraphindent}
6386 \parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
6387   \suppressfirstparagraphindent}
6388
6389 % These macros generate a chapter, section, etc. heading only
6390 % (including whitespace, linebreaking, etc. around it),
6391 % given all the information in convenient, parsed form.
6392
6393 % Args are the skip and penalty (usually negative)
6394 \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
6395
6396 % Parameter controlling skip before chapter headings (if needed)
6397 \newskip\chapheadingskip
6398
6399 % Define plain chapter starts, and page on/off switching for it.
6400 \def\chapbreak{\dobreak \chapheadingskip {-4000}}
6401
6402 % Start a new page
6403 \def\chappager{\par\vfill\supereject}
6404
6405 % \chapoddpage - start on an odd page for a new chapter
6406 % Because \domark is called before \chapoddpage, the filler page will
6407 % get the headings for the next chapter, which is wrong.  But we don't
6408 % care -- we just disable all headings on the filler page.
6409 \def\chapoddpage{%
6410   \chappager
6411   \ifodd\pageno \else
6412     \begingroup
6413       \headingsoff
6414       \null
6415       \chappager
6416     \endgroup
6417   \fi
6418 }
6419
6420 \parseargdef\setchapternewpage{\csname CHAPPAG#1\endcsname}
6421
6422 \def\CHAPPAGoff{%
6423 \global\let\contentsalignmacro = \chappager
6424 \global\let\pchapsepmacro=\chapbreak
6425 \global\let\pagealignmacro=\chappager}
6426
6427 \def\CHAPPAGon{%
6428 \global\let\contentsalignmacro = \chappager
6429 \global\let\pchapsepmacro=\chappager
6430 \global\let\pagealignmacro=\chappager
6431 \global\def\HEADINGSon{\HEADINGSsingle}}
6432
6433 \def\CHAPPAGodd{%
6434 \global\let\contentsalignmacro = \chapoddpage
6435 \global\let\pchapsepmacro=\chapoddpage
6436 \global\let\pagealignmacro=\chapoddpage
6437 \global\def\HEADINGSon{\HEADINGSdouble}}
6438
6439 \CHAPPAGon
6440
6441 % \chapmacro - Chapter opening.
6442 %
6443 % #1 is the text, #2 is the section type (Ynumbered, Ynothing,
6444 % Yappendix, Yomitfromtoc), #3 the chapter number.
6445 % Not used for @heading series.
6446 %
6447 % To test against our argument.
6448 \def\Ynothingkeyword{Ynothing}
6449 \def\Yappendixkeyword{Yappendix}
6450 \def\Yomitfromtockeyword{Yomitfromtoc}
6451 %
6452 \def\chapmacro#1#2#3{%
6453   \expandafter\ifx\thisenv\titlepage\else
6454     \checkenv{}% chapters, etc., should not start inside an environment.
6455   \fi
6456   % FIXME: \chapmacro is currently called from inside \titlepage when
6457   % \setcontentsaftertitlepage to print the "Table of Contents" heading, but
6458   % this should probably be done by \sectionheading with an option to print
6459   % in chapter size.
6460   %
6461   % Insert the first mark before the heading break (see notes for \domark).
6462   \let\prevchapterdefs=\lastchapterdefs
6463   \let\prevsectiondefs=\lastsectiondefs
6464   \gdef\lastsectiondefs{\gdef\thissectionname{}\gdef\thissectionnum{}%
6465                         \gdef\thissection{}}%
6466   %
6467   \def\temptype{#2}%
6468   \ifx\temptype\Ynothingkeyword
6469     \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6470                           \gdef\thischapter{\thischaptername}}%
6471   \else\ifx\temptype\Yomitfromtockeyword
6472     \gdef\lastchapterdefs{\gdef\thischaptername{#1}\gdef\thischapternum{}%
6473                           \gdef\thischapter{}}%
6474   \else\ifx\temptype\Yappendixkeyword
6475     \toks0={#1}%
6476     \xdef\lastchapterdefs{%
6477       \gdef\noexpand\thischaptername{\the\toks0}%
6478       \gdef\noexpand\thischapternum{\appendixletter}%
6479       % \noexpand\putwordAppendix avoids expanding indigestible
6480       % commands in some of the translations.
6481       \gdef\noexpand\thischapter{\noexpand\putwordAppendix{}
6482                                  \noexpand\thischapternum:
6483                                  \noexpand\thischaptername}%
6484     }%
6485   \else
6486     \toks0={#1}%
6487     \xdef\lastchapterdefs{%
6488       \gdef\noexpand\thischaptername{\the\toks0}%
6489       \gdef\noexpand\thischapternum{\the\chapno}%
6490       % \noexpand\putwordChapter avoids expanding indigestible
6491       % commands in some of the translations.
6492       \gdef\noexpand\thischapter{\noexpand\putwordChapter{}
6493                                  \noexpand\thischapternum:
6494                                  \noexpand\thischaptername}%
6495     }%
6496   \fi\fi\fi
6497   %
6498   % Output the mark.  Pass it through \safewhatsit, to take care of
6499   % the preceding space.
6500   \safewhatsit\domark
6501   %
6502   % Insert the chapter heading break.
6503   \pchapsepmacro
6504   %
6505   % Now the second mark, after the heading break.  No break points
6506   % between here and the heading.
6507   \let\prevchapterdefs=\lastchapterdefs
6508   \let\prevsectiondefs=\lastsectiondefs
6509   \domark
6510   %
6511   {%
6512     \chapfonts \rmisbold
6513     \let\footnote=\errfootnoteheading % give better error message
6514     %
6515     % Have to define \lastsection before calling \donoderef, because the
6516     % xref code eventually uses it.  On the other hand, it has to be called
6517     % after \pchapsepmacro, or the headline will change too soon.
6518     \gdef\lastsection{#1}%
6519     %
6520     % Only insert the separating space if we have a chapter/appendix
6521     % number, and don't print the unnumbered ``number''.
6522     \ifx\temptype\Ynothingkeyword
6523       \setbox0 = \hbox{}%
6524       \def\toctype{unnchap}%
6525     \else\ifx\temptype\Yomitfromtockeyword
6526       \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
6527       \def\toctype{omit}%
6528     \else\ifx\temptype\Yappendixkeyword
6529       \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
6530       \def\toctype{app}%
6531     \else
6532       \setbox0 = \hbox{#3\enspace}%
6533       \def\toctype{numchap}%
6534     \fi\fi\fi
6535     %
6536     % Write the toc entry for this chapter.  Must come before the
6537     % \donoderef, because we include the current node name in the toc
6538     % entry, and \donoderef resets it to empty.
6539     \writetocentry{\toctype}{#1}{#3}%
6540     %
6541     % For pdftex, we have to write out the node definition (aka, make
6542     % the pdfdest) after any page break, but before the actual text has
6543     % been typeset.  If the destination for the pdf outline is after the
6544     % text, then jumping from the outline may wind up with the text not
6545     % being visible, for instance under high magnification.
6546     \donoderef{#2}%
6547     %
6548     % Typeset the actual heading.
6549     \nobreak % Avoid page breaks at the interline glue.
6550     \vbox{\raggedtitlesettings \hangindent=\wd0 \centerparametersmaybe
6551           \unhbox0 #1\par}%
6552   }%
6553   \nobreak\bigskip % no page break after a chapter title
6554   \nobreak
6555 }
6556
6557 % @centerchap -- centered and unnumbered.
6558 \let\centerparametersmaybe = \relax
6559 \def\centerparameters{%
6560   \advance\rightskip by 3\rightskip
6561   \leftskip = \rightskip
6562   \parfillskip = 0pt
6563 }
6564
6565
6566 % Section titles.  These macros combine the section number parts and
6567 % call the generic \sectionheading to do the printing.
6568 %
6569 \newskip\secheadingskip
6570 \def\secheadingbreak{\dobreak \secheadingskip{-1000}}
6571
6572 % Subsection titles.
6573 \newskip\subsecheadingskip
6574 \def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
6575
6576 % Subsubsection titles.
6577 \def\subsubsecheadingskip{\subsecheadingskip}
6578 \def\subsubsecheadingbreak{\subsecheadingbreak}
6579
6580
6581 % Print any size, any type, section title.
6582 %
6583 % #1 is the text of the title,
6584 % #2 is the section level (sec/subsec/subsubsec),
6585 % #3 is the section type (Ynumbered, Ynothing, Yappendix, Yomitfromtoc),
6586 % #4 is the section number.
6587 %
6588 \def\seckeyword{sec}
6589 %
6590 \def\sectionheading#1#2#3#4{%
6591   {%
6592     \def\sectionlevel{#2}%
6593     \def\temptype{#3}%
6594     %
6595     % It is ok for the @heading series commands to appear inside an
6596     % environment (it's been historically allowed, though the logic is
6597     % dubious), but not the others.
6598     \ifx\temptype\Yomitfromtockeyword\else
6599       \checkenv{}% non-@*heading should not be in an environment.
6600     \fi
6601     \let\footnote=\errfootnoteheading
6602     %
6603     % Switch to the right set of fonts.
6604     \csname #2fonts\endcsname \rmisbold
6605     %
6606     % Insert first mark before the heading break (see notes for \domark).
6607     \let\prevsectiondefs=\lastsectiondefs
6608     \ifx\temptype\Ynothingkeyword
6609       \ifx\sectionlevel\seckeyword
6610         \gdef\lastsectiondefs{\gdef\thissectionname{#1}\gdef\thissectionnum{}%
6611                               \gdef\thissection{\thissectionname}}%
6612       \fi
6613     \else\ifx\temptype\Yomitfromtockeyword
6614       % Don't redefine \thissection.
6615     \else\ifx\temptype\Yappendixkeyword
6616       \ifx\sectionlevel\seckeyword
6617         \toks0={#1}%
6618         \xdef\lastsectiondefs{%
6619           \gdef\noexpand\thissectionname{\the\toks0}%
6620           \gdef\noexpand\thissectionnum{#4}%
6621           % \noexpand\putwordSection avoids expanding indigestible
6622           % commands in some of the translations.
6623           \gdef\noexpand\thissection{\noexpand\putwordSection{}
6624                                      \noexpand\thissectionnum:
6625                                      \noexpand\thissectionname}%
6626         }%
6627       \fi
6628     \else
6629       \ifx\sectionlevel\seckeyword
6630         \toks0={#1}%
6631         \xdef\lastsectiondefs{%
6632           \gdef\noexpand\thissectionname{\the\toks0}%
6633           \gdef\noexpand\thissectionnum{#4}%
6634           % \noexpand\putwordSection avoids expanding indigestible
6635           % commands in some of the translations.
6636           \gdef\noexpand\thissection{\noexpand\putwordSection{}
6637                                      \noexpand\thissectionnum:
6638                                      \noexpand\thissectionname}%
6639         }%
6640       \fi
6641     \fi\fi\fi
6642     %
6643     % Go into vertical mode.  Usually we'll already be there, but we
6644     % don't want the following whatsit to end up in a preceding paragraph
6645     % if the document didn't happen to have a blank line.
6646     \par
6647     %
6648     % Output the mark.  Pass it through \safewhatsit, to take care of
6649     % the preceding space.
6650     \safewhatsit\domark
6651     %
6652     % Insert space above the heading.
6653     \csname #2headingbreak\endcsname
6654     %
6655     % Now the second mark, after the heading break.  No break points
6656     % between here and the heading.
6657     \global\let\prevsectiondefs=\lastsectiondefs
6658     \domark
6659     %
6660     % Only insert the space after the number if we have a section number.
6661     \ifx\temptype\Ynothingkeyword
6662       \setbox0 = \hbox{}%
6663       \def\toctype{unn}%
6664       \gdef\lastsection{#1}%
6665     \else\ifx\temptype\Yomitfromtockeyword
6666       % for @headings -- no section number, don't include in toc,
6667       % and don't redefine \lastsection.
6668       \setbox0 = \hbox{}%
6669       \def\toctype{omit}%
6670       \let\sectionlevel=\empty
6671     \else\ifx\temptype\Yappendixkeyword
6672       \setbox0 = \hbox{#4\enspace}%
6673       \def\toctype{app}%
6674       \gdef\lastsection{#1}%
6675     \else
6676       \setbox0 = \hbox{#4\enspace}%
6677       \def\toctype{num}%
6678       \gdef\lastsection{#1}%
6679     \fi\fi\fi
6680     %
6681     % Write the toc entry (before \donoderef).  See comments in \chapmacro.
6682     \writetocentry{\toctype\sectionlevel}{#1}{#4}%
6683     %
6684     % Write the node reference (= pdf destination for pdftex).
6685     % Again, see comments in \chapmacro.
6686     \donoderef{#3}%
6687     %
6688     % Interline glue will be inserted when the vbox is completed.
6689     % That glue will be a valid breakpoint for the page, since it'll be
6690     % preceded by a whatsit (usually from the \donoderef, or from the
6691     % \writetocentry if there was no node).  We don't want to allow that
6692     % break, since then the whatsits could end up on page n while the
6693     % section is on page n+1, thus toc/etc. are wrong.  Debian bug 276000.
6694     \nobreak
6695     %
6696     % Output the actual section heading.
6697     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \ptexraggedright
6698           \hangindent=\wd0  % zero if no section number
6699           \unhbox0 #1}%
6700   }%
6701   % Add extra space after the heading -- half of whatever came above it.
6702   % Don't allow stretch, though.
6703   \kern .5 \csname #2headingskip\endcsname
6704   %
6705   % Do not let the kern be a potential breakpoint, as it would be if it
6706   % was followed by glue.
6707   \nobreak
6708   %
6709   % We'll almost certainly start a paragraph next, so don't let that
6710   % glue accumulate.  (Not a breakpoint because it's preceded by a
6711   % discardable item.)  However, when a paragraph is not started next
6712   % (\startdefun, \cartouche, \center, etc.), this needs to be wiped out
6713   % or the negative glue will cause weirdly wrong output, typically
6714   % obscuring the section heading with something else.
6715   \vskip-\parskip
6716   %
6717   % This is so the last item on the main vertical list is a known
6718   % \penalty > 10000, so \startdefun, etc., can recognize the situation
6719   % and do the needful.
6720   \penalty 10001
6721 }
6722
6723
6724 \message{toc,}
6725 % Table of contents.
6726 \newwrite\tocfile
6727
6728 % Write an entry to the toc file, opening it if necessary.
6729 % Called from @chapter, etc.
6730 %
6731 % Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
6732 % We append the current node name (if any) and page number as additional
6733 % arguments for the \{chap,sec,...}entry macros which will eventually
6734 % read this.  The node name is used in the pdf outlines as the
6735 % destination to jump to.
6736 %
6737 % We open the .toc file for writing here instead of at @setfilename (or
6738 % any other fixed time) so that @contents can be anywhere in the document.
6739 % But if #1 is `omit', then we don't do anything.  This is used for the
6740 % table of contents chapter openings themselves.
6741 %
6742 \newif\iftocfileopened
6743 \def\omitkeyword{omit}%
6744 %
6745 \def\writetocentry#1#2#3{%
6746   \edef\writetoctype{#1}%
6747   \ifx\writetoctype\omitkeyword \else
6748     \iftocfileopened\else
6749       \immediate\openout\tocfile = \jobname.toc
6750       \global\tocfileopenedtrue
6751     \fi
6752     %
6753     \iflinks
6754       {\atdummies
6755        \edef\temp{%
6756          \write\tocfile{@#1entry{#2}{#3}{\lastnode}{\noexpand\folio}}}%
6757        \temp
6758       }%
6759     \fi
6760   \fi
6761   %
6762   % Tell \shipout to create a pdf destination on each page, if we're
6763   % writing pdf.  These are used in the table of contents.  We can't
6764   % just write one on every page because the title pages are numbered
6765   % 1 and 2 (the page numbers aren't printed), and so are the first
6766   % two pages of the document.  Thus, we'd have two destinations named
6767   % `1', and two named `2'.
6768   \ifpdf
6769     \global\pdfmakepagedesttrue
6770   \else
6771     \ifx\XeTeXrevision\thisisundefined
6772     \else
6773       \global\pdfmakepagedesttrue
6774     \fi
6775   \fi
6776 }
6777
6778
6779 % These characters do not print properly in the Computer Modern roman
6780 % fonts, so we must take special care.  This is more or less redundant
6781 % with the Texinfo input format setup at the end of this file.
6782 %
6783 \def\activecatcodes{%
6784   \catcode`\"=\active
6785   \catcode`\$=\active
6786   \catcode`\<=\active
6787   \catcode`\>=\active
6788   \catcode`\\=\active
6789   \catcode`\^=\active
6790   \catcode`\_=\active
6791   \catcode`\|=\active
6792   \catcode`\~=\active
6793 }
6794
6795
6796 % Read the toc file, which is essentially Texinfo input.
6797 \def\readtocfile{%
6798   \setupdatafile
6799   \activecatcodes
6800   \input \tocreadfilename
6801 }
6802
6803 \newskip\contentsrightmargin \contentsrightmargin=1in
6804 \newcount\savepageno
6805 \newcount\lastnegativepageno \lastnegativepageno = -1
6806
6807 % Prepare to read what we've written to \tocfile.
6808 %
6809 \def\startcontents#1{%
6810   % If @setchapternewpage on, and @headings double, the contents should
6811   % start on an odd page, unlike chapters.  Thus, we maintain
6812   % \contentsalignmacro in parallel with \pagealignmacro.
6813   % From: Torbjorn Granlund <tege@matematik.su.se>
6814   \contentsalignmacro
6815   \immediate\closeout\tocfile
6816   %
6817   % Don't need to put `Contents' or `Short Contents' in the headline.
6818   % It is abundantly clear what they are.
6819   \chapmacro{#1}{Yomitfromtoc}{}%
6820   %
6821   \savepageno = \pageno
6822   \begingroup                  % Set up to handle contents files properly.
6823     \raggedbottom              % Worry more about breakpoints than the bottom.
6824     \entryrightmargin=\contentsrightmargin % Don't use the full line length.
6825     %
6826     % Roman numerals for page numbers.
6827     \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
6828 }
6829
6830 % redefined for the two-volume lispref.  We always output on
6831 % \jobname.toc even if this is redefined.
6832 %
6833 \def\tocreadfilename{\jobname.toc}
6834
6835 % Normal (long) toc.
6836 %
6837 \def\contents{%
6838   \startcontents{\putwordTOC}%
6839     \openin 1 \tocreadfilename\space
6840     \ifeof 1 \else
6841       \readtocfile
6842     \fi
6843     \vfill \eject
6844     \contentsalignmacro % in case @setchapternewpage odd is in effect
6845     \ifeof 1 \else
6846       \pdfmakeoutlines
6847     \fi
6848     \closein 1
6849   \endgroup
6850   \lastnegativepageno = \pageno
6851   \global\pageno = \savepageno
6852 }
6853
6854 % And just the chapters.
6855 \def\summarycontents{%
6856   \startcontents{\putwordShortTOC}%
6857     %
6858     \let\partentry = \shortpartentry
6859     \let\numchapentry = \shortchapentry
6860     \let\appentry = \shortchapentry
6861     \let\unnchapentry = \shortunnchapentry
6862     % We want a true roman here for the page numbers.
6863     \secfonts
6864     \let\rm=\shortcontrm \let\bf=\shortcontbf
6865     \let\sl=\shortcontsl \let\tt=\shortconttt
6866     \rm
6867     \hyphenpenalty = 10000
6868     \advance\baselineskip by 1pt % Open it up a little.
6869     \def\numsecentry##1##2##3##4{}
6870     \let\appsecentry = \numsecentry
6871     \let\unnsecentry = \numsecentry
6872     \let\numsubsecentry = \numsecentry
6873     \let\appsubsecentry = \numsecentry
6874     \let\unnsubsecentry = \numsecentry
6875     \let\numsubsubsecentry = \numsecentry
6876     \let\appsubsubsecentry = \numsecentry
6877     \let\unnsubsubsecentry = \numsecentry
6878     \openin 1 \tocreadfilename\space
6879     \ifeof 1 \else
6880       \readtocfile
6881     \fi
6882     \closein 1
6883     \vfill \eject
6884     \contentsalignmacro % in case @setchapternewpage odd is in effect
6885   \endgroup
6886   \lastnegativepageno = \pageno
6887   \global\pageno = \savepageno
6888 }
6889 \let\shortcontents = \summarycontents
6890
6891 % Typeset the label for a chapter or appendix for the short contents.
6892 % The arg is, e.g., `A' for an appendix, or `3' for a chapter.
6893 %
6894 \def\shortchaplabel#1{%
6895   % This space should be enough, since a single number is .5em, and the
6896   % widest letter (M) is 1em, at least in the Computer Modern fonts.
6897   % But use \hss just in case.
6898   % (This space doesn't include the extra space that gets added after
6899   % the label; that gets put in by \shortchapentry above.)
6900   %
6901   % We'd like to right-justify chapter numbers, but that looks strange
6902   % with appendix letters.  And right-justifying numbers and
6903   % left-justifying letters looks strange when there is less than 10
6904   % chapters.  Have to read the whole toc once to know how many chapters
6905   % there are before deciding ...
6906   \hbox to 1em{#1\hss}%
6907 }
6908
6909 % These macros generate individual entries in the table of contents.
6910 % The first argument is the chapter or section name.
6911 % The last argument is the page number.
6912 % The arguments in between are the chapter number, section number, ...
6913
6914 % Parts, in the main contents.  Replace the part number, which doesn't
6915 % exist, with an empty box.  Let's hope all the numbers have the same width.
6916 % Also ignore the page number, which is conventionally not printed.
6917 \def\numeralbox{\setbox0=\hbox{8}\hbox to \wd0{\hfil}}
6918 \def\partentry#1#2#3#4{\dochapentry{\numeralbox\labelspace#1}{}}
6919 %
6920 % Parts, in the short toc.
6921 \def\shortpartentry#1#2#3#4{%
6922   \penalty-300
6923   \vskip.5\baselineskip plus.15\baselineskip minus.1\baselineskip
6924   \shortchapentry{{\bf #1}}{\numeralbox}{}{}%
6925 }
6926
6927 % Chapters, in the main contents.
6928 \def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
6929
6930 % Chapters, in the short toc.
6931 % See comments in \dochapentry re vbox and related settings.
6932 \def\shortchapentry#1#2#3#4{%
6933   \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
6934 }
6935
6936 % Appendices, in the main contents.
6937 % Need the word Appendix, and a fixed-size box.
6938 %
6939 \def\appendixbox#1{%
6940   % We use M since it's probably the widest letter.
6941   \setbox0 = \hbox{\putwordAppendix{} M}%
6942   \hbox to \wd0{\putwordAppendix{} #1\hss}}
6943 %
6944 \def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\hskip.7em#1}{#4}}
6945
6946 % Unnumbered chapters.
6947 \def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
6948 \def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
6949
6950 % Sections.
6951 \def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
6952 \let\appsecentry=\numsecentry
6953 \def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
6954
6955 % Subsections.
6956 \def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
6957 \let\appsubsecentry=\numsubsecentry
6958 \def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
6959
6960 % And subsubsections.
6961 \def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
6962 \let\appsubsubsecentry=\numsubsubsecentry
6963 \def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
6964
6965 % This parameter controls the indentation of the various levels.
6966 % Same as \defaultparindent.
6967 \newdimen\tocindent \tocindent = 15pt
6968
6969 % Now for the actual typesetting. In all these, #1 is the text and #2 is the
6970 % page number.
6971 %
6972 % If the toc has to be broken over pages, we want it to be at chapters
6973 % if at all possible; hence the \penalty.
6974 \def\dochapentry#1#2{%
6975    \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
6976    \begingroup
6977      % Move the page numbers slightly to the right
6978      \advance\entryrightmargin by -0.05em
6979      \chapentryfonts
6980      \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6981    \endgroup
6982    \nobreak\vskip .25\baselineskip plus.1\baselineskip
6983 }
6984
6985 \def\dosecentry#1#2{\begingroup
6986   \secentryfonts \leftskip=\tocindent
6987   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6988 \endgroup}
6989
6990 \def\dosubsecentry#1#2{\begingroup
6991   \subsecentryfonts \leftskip=2\tocindent
6992   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6993 \endgroup}
6994
6995 \def\dosubsubsecentry#1#2{\begingroup
6996   \subsubsecentryfonts \leftskip=3\tocindent
6997   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
6998 \endgroup}
6999
7000 % We use the same \entry macro as for the index entries.
7001 \let\tocentry = \entry
7002
7003 % Space between chapter (or whatever) number and the title.
7004 \def\labelspace{\hskip1em \relax}
7005
7006 \def\dopageno#1{{\rm #1}}
7007 \def\doshortpageno#1{{\rm #1}}
7008
7009 \def\chapentryfonts{\secfonts \rm}
7010 \def\secentryfonts{\textfonts}
7011 \def\subsecentryfonts{\textfonts}
7012 \def\subsubsecentryfonts{\textfonts}
7013
7014
7015 \message{environments,}
7016 % @foo ... @end foo.
7017
7018 % @tex ... @end tex    escapes into raw TeX temporarily.
7019 % One exception: @ is still an escape character, so that @end tex works.
7020 % But \@ or @@ will get a plain @ character.
7021
7022 \envdef\tex{%
7023   \setupmarkupstyle{tex}%
7024   \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
7025   \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
7026   \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
7027   \catcode `\%=14
7028   \catcode `\+=\other
7029   \catcode `\"=\other
7030   \catcode `\|=\other
7031   \catcode `\<=\other
7032   \catcode `\>=\other
7033   \catcode `\`=\other
7034   \catcode `\'=\other
7035   %
7036   % ' is active in math mode (mathcode"8000).  So reset it, and all our
7037   % other math active characters (just in case), to plain's definitions.
7038   \mathactive
7039   %
7040   % Inverse of the list at the beginning of the file.
7041   \let\b=\ptexb
7042   \let\bullet=\ptexbullet
7043   \let\c=\ptexc
7044   \let\,=\ptexcomma
7045   \let\.=\ptexdot
7046   \let\dots=\ptexdots
7047   \let\equiv=\ptexequiv
7048   \let\!=\ptexexclam
7049   \let\i=\ptexi
7050   \let\indent=\ptexindent
7051   \let\noindent=\ptexnoindent
7052   \let\{=\ptexlbrace
7053   \let\+=\tabalign
7054   \let\}=\ptexrbrace
7055   \let\/=\ptexslash
7056   \let\sp=\ptexsp
7057   \let\*=\ptexstar
7058   %\let\sup=\ptexsup % do not redefine, we want @sup to work in math mode
7059   \let\t=\ptext
7060   \expandafter \let\csname top\endcsname=\ptextop  % we've made it outer
7061   \let\frenchspacing=\plainfrenchspacing
7062   %
7063   \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
7064   \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
7065   \def\@{@}%
7066 }
7067 % There is no need to define \Etex.
7068
7069 % Define @lisp ... @end lisp.
7070 % @lisp environment forms a group so it can rebind things,
7071 % including the definition of @end lisp (which normally is erroneous).
7072
7073 % Amount to narrow the margins by for @lisp.
7074 \newskip\lispnarrowing \lispnarrowing=0.4in
7075
7076 % This is the definition that ^^M gets inside @lisp, @example, and other
7077 % such environments.  \null is better than a space, since it doesn't
7078 % have any width.
7079 \def\lisppar{\null\endgraf}
7080
7081 % This space is always present above and below environments.
7082 \newskip\envskipamount \envskipamount = 0pt
7083
7084 % Make spacing and below environment symmetrical.  We use \parskip here
7085 % to help in doing that, since in @example-like environments \parskip
7086 % is reset to zero; thus the \afterenvbreak inserts no space -- but the
7087 % start of the next paragraph will insert \parskip.
7088 %
7089 \def\aboveenvbreak{{%
7090   % =10000 instead of <10000 because of a special case in \itemzzz and
7091   % \sectionheading, q.v.
7092   \ifnum \lastpenalty=10000 \else
7093     \advance\envskipamount by \parskip
7094     \endgraf
7095     \ifdim\lastskip<\envskipamount
7096       \removelastskip
7097       \ifnum\lastpenalty<10000
7098         % Penalize breaking before the environment, because preceding text
7099         % often leads into it.
7100         \penalty100
7101       \fi
7102       \vskip\envskipamount
7103     \fi
7104   \fi
7105 }}
7106
7107 \def\afterenvbreak{{%
7108   % =10000 instead of <10000 because of a special case in \itemzzz and
7109   % \sectionheading, q.v.
7110   \ifnum \lastpenalty=10000 \else
7111     \advance\envskipamount by \parskip
7112     \endgraf
7113     \ifdim\lastskip<\envskipamount
7114       \removelastskip
7115       % it's not a good place to break if the last penalty was \nobreak
7116       % or better ...
7117       \ifnum\lastpenalty<10000 \penalty-50 \fi
7118       \vskip\envskipamount
7119     \fi
7120   \fi
7121 }}
7122
7123 % \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins; it will
7124 % also clear it, so that its embedded environments do the narrowing again.
7125 \let\nonarrowing=\relax
7126
7127 % @cartouche ... @end cartouche: draw rectangle w/rounded corners around
7128 % environment contents.
7129 \font\circle=lcircle10
7130 \newdimen\circthick
7131 \newdimen\cartouter\newdimen\cartinner
7132 \newskip\normbskip\newskip\normpskip\newskip\normlskip
7133 \circthick=\fontdimen8\circle
7134 %
7135 \def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
7136 \def\ctr{{\hskip 6pt\circle\char'010}}
7137 \def\cbl{{\circle\char'012\hskip -6pt}}
7138 \def\cbr{{\hskip 6pt\circle\char'011}}
7139 \def\carttop{\hbox to \cartouter{\hskip\lskip
7140         \ctl\leaders\hrule height\circthick\hfil\ctr
7141         \hskip\rskip}}
7142 \def\cartbot{\hbox to \cartouter{\hskip\lskip
7143         \cbl\leaders\hrule height\circthick\hfil\cbr
7144         \hskip\rskip}}
7145 %
7146 \newskip\lskip\newskip\rskip
7147
7148 \envdef\cartouche{%
7149   \ifhmode\par\fi  % can't be in the midst of a paragraph.
7150   \startsavinginserts
7151   \lskip=\leftskip \rskip=\rightskip
7152   \leftskip=0pt\rightskip=0pt % we want these *outside*.
7153   \cartinner=\hsize \advance\cartinner by-\lskip
7154   \advance\cartinner by-\rskip
7155   \cartouter=\hsize
7156   \advance\cartouter by 18.4pt  % allow for 3pt kerns on either
7157                                 % side, and for 6pt waste from
7158                                 % each corner char, and rule thickness
7159   \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
7160   %
7161   % If this cartouche directly follows a sectioning command, we need the
7162   % \parskip glue (backspaced over by default) or the cartouche can
7163   % collide with the section heading.
7164   \ifnum\lastpenalty>10000 \vskip\parskip \penalty\lastpenalty \fi
7165   %
7166   \setbox\groupbox=\vbox\bgroup
7167       \baselineskip=0pt\parskip=0pt\lineskip=0pt
7168       \carttop
7169       \hbox\bgroup
7170           \hskip\lskip
7171           \vrule\kern3pt
7172           \vbox\bgroup
7173               \kern3pt
7174               \hsize=\cartinner
7175               \baselineskip=\normbskip
7176               \lineskip=\normlskip
7177               \parskip=\normpskip
7178               \vskip -\parskip
7179               \comment % For explanation, see the end of def\group.
7180 }
7181 \def\Ecartouche{%
7182               \ifhmode\par\fi
7183               \kern3pt
7184           \egroup
7185           \kern3pt\vrule
7186           \hskip\rskip
7187       \egroup
7188       \cartbot
7189   \egroup
7190   \addgroupbox
7191   \checkinserts
7192 }
7193
7194
7195 % This macro is called at the beginning of all the @example variants,
7196 % inside a group.
7197 \newdimen\nonfillparindent
7198 \def\nonfillstart{%
7199   \aboveenvbreak
7200   \ifdim\hfuzz < 12pt \hfuzz = 12pt \fi % Don't be fussy
7201   \sepspaces % Make spaces be word-separators rather than space tokens.
7202   \let\par = \lisppar % don't ignore blank lines
7203   \obeylines % each line of input is a line of output
7204   \parskip = 0pt
7205   % Turn off paragraph indentation but redefine \indent to emulate
7206   % the normal \indent.
7207   \nonfillparindent=\parindent
7208   \parindent = 0pt
7209   \let\indent\nonfillindent
7210   %
7211   \emergencystretch = 0pt % don't try to avoid overfull boxes
7212   \ifx\nonarrowing\relax
7213     \advance \leftskip by \lispnarrowing
7214     \exdentamount=\lispnarrowing
7215   \else
7216     \let\nonarrowing = \relax
7217   \fi
7218   \let\exdent=\nofillexdent
7219 }
7220
7221 \begingroup
7222 \obeyspaces
7223 % We want to swallow spaces (but not other tokens) after the fake
7224 % @indent in our nonfill-environments, where spaces are normally
7225 % active and set to @tie, resulting in them not being ignored after
7226 % @indent.
7227 \gdef\nonfillindent{\futurelet\temp\nonfillindentcheck}%
7228 \gdef\nonfillindentcheck{%
7229 \ifx\temp %
7230 \expandafter\nonfillindentgobble%
7231 \else%
7232 \leavevmode\nonfillindentbox%
7233 \fi%
7234 }%
7235 \endgroup
7236 \def\nonfillindentgobble#1{\nonfillindent}
7237 \def\nonfillindentbox{\hbox to \nonfillparindent{\hss}}
7238
7239 % If you want all examples etc. small: @set dispenvsize small.
7240 % If you want even small examples the full size: @set dispenvsize nosmall.
7241 % This affects the following displayed environments:
7242 %    @example, @display, @format, @lisp
7243 %
7244 \def\smallword{small}
7245 \def\nosmallword{nosmall}
7246 \let\SETdispenvsize\relax
7247 \def\setnormaldispenv{%
7248   \ifx\SETdispenvsize\smallword
7249     % end paragraph for sake of leading, in case document has no blank
7250     % line.  This is redundant with what happens in \aboveenvbreak, but
7251     % we need to do it before changing the fonts, and it's inconvenient
7252     % to change the fonts afterward.
7253     \ifnum \lastpenalty=10000 \else \endgraf \fi
7254     \smallexamplefonts \rm
7255   \fi
7256 }
7257 \def\setsmalldispenv{%
7258   \ifx\SETdispenvsize\nosmallword
7259   \else
7260     \ifnum \lastpenalty=10000 \else \endgraf \fi
7261     \smallexamplefonts \rm
7262   \fi
7263 }
7264
7265 % We often define two environments, @foo and @smallfoo.
7266 % Let's do it in one command.  #1 is the env name, #2 the definition.
7267 \def\makedispenvdef#1#2{%
7268   \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}%
7269   \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}%
7270   \expandafter\let\csname E#1\endcsname \afterenvbreak
7271   \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
7272 }
7273
7274 % Define two environment synonyms (#1 and #2) for an environment.
7275 \def\maketwodispenvdef#1#2#3{%
7276   \makedispenvdef{#1}{#3}%
7277   \makedispenvdef{#2}{#3}%
7278 }
7279 %
7280 % @lisp: indented, narrowed, typewriter font;
7281 % @example: same as @lisp.
7282 %
7283 % @smallexample and @smalllisp: use smaller fonts.
7284 % Originally contributed by Pavel@xerox.
7285 %
7286 \maketwodispenvdef{lisp}{example}{%
7287   \nonfillstart
7288   \tt\setupmarkupstyle{example}%
7289   \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
7290   \gobble % eat return
7291 }
7292 % @display/@smalldisplay: same as @lisp except keep current font.
7293 %
7294 \makedispenvdef{display}{%
7295   \nonfillstart
7296   \gobble
7297 }
7298
7299 % @format/@smallformat: same as @display except don't narrow margins.
7300 %
7301 \makedispenvdef{format}{%
7302   \let\nonarrowing = t%
7303   \nonfillstart
7304   \gobble
7305 }
7306
7307 % @flushleft: same as @format, but doesn't obey \SETdispenvsize.
7308 \envdef\flushleft{%
7309   \let\nonarrowing = t%
7310   \nonfillstart
7311   \gobble
7312 }
7313 \let\Eflushleft = \afterenvbreak
7314
7315 % @flushright.
7316 %
7317 \envdef\flushright{%
7318   \let\nonarrowing = t%
7319   \nonfillstart
7320   \advance\leftskip by 0pt plus 1fill\relax
7321   \gobble
7322 }
7323 \let\Eflushright = \afterenvbreak
7324
7325
7326 % @raggedright does more-or-less normal line breaking but no right
7327 % justification.  From plain.tex.  Don't stretch around special
7328 % characters in urls in this environment, since the stretch at the right
7329 % should be enough.
7330 \envdef\raggedright{%
7331   \rightskip0pt plus2.4em \spaceskip.3333em \xspaceskip.5em\relax
7332   \def\urefprestretchamount{0pt}%
7333   \def\urefpoststretchamount{0pt}%
7334 }
7335 \let\Eraggedright\par
7336
7337 \envdef\raggedleft{%
7338   \parindent=0pt \leftskip0pt plus2em
7339   \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7340   \hbadness=10000 % Last line will usually be underfull, so turn off
7341                   % badness reporting.
7342 }
7343 \let\Eraggedleft\par
7344
7345 \envdef\raggedcenter{%
7346   \parindent=0pt \rightskip0pt plus1em \leftskip0pt plus1em
7347   \spaceskip.3333em \xspaceskip.5em \parfillskip=0pt
7348   \hbadness=10000 % Last line will usually be underfull, so turn off
7349                   % badness reporting.
7350 }
7351 \let\Eraggedcenter\par
7352
7353
7354 % @quotation does normal linebreaking (hence we can't use \nonfillstart)
7355 % and narrows the margins.  We keep \parskip nonzero in general, since
7356 % we're doing normal filling.  So, when using \aboveenvbreak and
7357 % \afterenvbreak, temporarily make \parskip 0.
7358 %
7359 \makedispenvdef{quotation}{\quotationstart}
7360 %
7361 \def\quotationstart{%
7362   \indentedblockstart % same as \indentedblock, but increase right margin too.
7363   \ifx\nonarrowing\relax
7364     \advance\rightskip by \lispnarrowing
7365   \fi
7366   \parsearg\quotationlabel
7367 }
7368
7369 % We have retained a nonzero parskip for the environment, since we're
7370 % doing normal filling.
7371 %
7372 \def\Equotation{%
7373   \par
7374   \ifx\quotationauthor\thisisundefined\else
7375     % indent a bit.
7376     \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
7377   \fi
7378   {\parskip=0pt \afterenvbreak}%
7379 }
7380 \def\Esmallquotation{\Equotation}
7381
7382 % If we're given an argument, typeset it in bold with a colon after.
7383 \def\quotationlabel#1{%
7384   \def\temp{#1}%
7385   \ifx\temp\empty \else
7386     {\bf #1: }%
7387   \fi
7388 }
7389
7390 % @indentedblock is like @quotation, but indents only on the left and
7391 % has no optional argument.
7392
7393 \makedispenvdef{indentedblock}{\indentedblockstart}
7394 %
7395 \def\indentedblockstart{%
7396   {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
7397   \parindent=0pt
7398   %
7399   % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
7400   \ifx\nonarrowing\relax
7401     \advance\leftskip by \lispnarrowing
7402     \exdentamount = \lispnarrowing
7403   \else
7404     \let\nonarrowing = \relax
7405   \fi
7406 }
7407
7408 % Keep a nonzero parskip for the environment, since we're doing normal filling.
7409 %
7410 \def\Eindentedblock{%
7411   \par
7412   {\parskip=0pt \afterenvbreak}%
7413 }
7414 \def\Esmallindentedblock{\Eindentedblock}
7415
7416
7417 % LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
7418 % If we want to allow any <char> as delimiter,
7419 % we need the curly braces so that makeinfo sees the @verb command, eg:
7420 % `@verbx...x' would look like the '@verbx' command.  --janneke@gnu.org
7421 %
7422 % [Knuth]: Donald Ervin Knuth, 1996.  The TeXbook.
7423 %
7424 % [Knuth] p.344; only we need to do the other characters Texinfo sets
7425 % active too.  Otherwise, they get lost as the first character on a
7426 % verbatim line.
7427 \def\dospecials{%
7428   \do\ \do\\\do\{\do\}\do\$\do\&%
7429   \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
7430   \do\<\do\>\do\|\do\@\do+\do\"%
7431   % Don't do the quotes -- if we do, @set txicodequoteundirected and
7432   % @set txicodequotebacktick will not have effect on @verb and
7433   % @verbatim, and ?` and !` ligatures won't get disabled.
7434   %\do\`\do\'%
7435 }
7436 %
7437 % [Knuth] p. 380
7438 \def\uncatcodespecials{%
7439   \def\do##1{\catcode`##1=\other}\dospecials}
7440 %
7441 % Setup for the @verb command.
7442 %
7443 % Eight spaces for a tab
7444 \begingroup
7445   \catcode`\^^I=\active
7446   \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
7447 \endgroup
7448 %
7449 \def\setupverb{%
7450   \tt  % easiest (and conventionally used) font for verbatim
7451   \def\par{\leavevmode\endgraf}%
7452   \setupmarkupstyle{verb}%
7453   \tabeightspaces
7454   % Respect line breaks,
7455   % print special symbols as themselves, and
7456   % make each space count
7457   % must do in this order:
7458   \obeylines \uncatcodespecials \sepspaces
7459 }
7460
7461 % Setup for the @verbatim environment
7462 %
7463 % Real tab expansion.
7464 \newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
7465 %
7466 % We typeset each line of the verbatim in an \hbox, so we can handle
7467 % tabs.  The \global is in case the verbatim line starts with an accent,
7468 % or some other command that starts with a begin-group.  Otherwise, the
7469 % entire \verbbox would disappear at the corresponding end-group, before
7470 % it is typeset.  Meanwhile, we can't have nested verbatim commands
7471 % (can we?), so the \global won't be overwriting itself.
7472 \newbox\verbbox
7473 \def\starttabbox{\global\setbox\verbbox=\hbox\bgroup}
7474 %
7475 \begingroup
7476   \catcode`\^^I=\active
7477   \gdef\tabexpand{%
7478     \catcode`\^^I=\active
7479     \def^^I{\leavevmode\egroup
7480       \dimen\verbbox=\wd\verbbox % the width so far, or since the previous tab
7481       \divide\dimen\verbbox by\tabw
7482       \multiply\dimen\verbbox by\tabw % compute previous multiple of \tabw
7483       \advance\dimen\verbbox by\tabw  % advance to next multiple of \tabw
7484       \wd\verbbox=\dimen\verbbox \box\verbbox \starttabbox
7485     }%
7486   }
7487 \endgroup
7488
7489 % start the verbatim environment.
7490 \def\setupverbatim{%
7491   \let\nonarrowing = t%
7492   \nonfillstart
7493   \tt % easiest (and conventionally used) font for verbatim
7494   % The \leavevmode here is for blank lines.  Otherwise, we would
7495   % never \starttabox and the \egroup would end verbatim mode.
7496   \def\par{\leavevmode\egroup\box\verbbox\endgraf}%
7497   \tabexpand
7498   \setupmarkupstyle{verbatim}%
7499   % Respect line breaks,
7500   % print special symbols as themselves, and
7501   % make each space count.
7502   % Must do in this order:
7503   \obeylines \uncatcodespecials \sepspaces
7504   \everypar{\starttabbox}%
7505 }
7506
7507 % Do the @verb magic: verbatim text is quoted by unique
7508 % delimiter characters.  Before first delimiter expect a
7509 % right brace, after last delimiter expect closing brace:
7510 %
7511 %    \def\doverb'{'<char>#1<char>'}'{#1}
7512 %
7513 % [Knuth] p. 382; only eat outer {}
7514 \begingroup
7515   \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
7516   \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
7517 \endgroup
7518 %
7519 \def\verb{\begingroup\setupverb\doverb}
7520 %
7521 %
7522 % Do the @verbatim magic: define the macro \doverbatim so that
7523 % the (first) argument ends when '@end verbatim' is reached, ie:
7524 %
7525 %     \def\doverbatim#1@end verbatim{#1}
7526 %
7527 % For Texinfo it's a lot easier than for LaTeX,
7528 % because texinfo's \verbatim doesn't stop at '\end{verbatim}':
7529 % we need not redefine '\', '{' and '}'.
7530 %
7531 % Inspired by LaTeX's verbatim command set [latex.ltx]
7532 %
7533 \begingroup
7534   \catcode`\ =\active
7535   \obeylines %
7536   % ignore everything up to the first ^^M, that's the newline at the end
7537   % of the @verbatim input line itself.  Otherwise we get an extra blank
7538   % line in the output.
7539   \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
7540   % We really want {...\end verbatim} in the body of the macro, but
7541   % without the active space; thus we have to use \xdef and \gobble.
7542 \endgroup
7543 %
7544 \envdef\verbatim{%
7545     \setupverbatim\doverbatim
7546 }
7547 \let\Everbatim = \afterenvbreak
7548
7549
7550 % @verbatiminclude FILE - insert text of file in verbatim environment.
7551 %
7552 \def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
7553 %
7554 \def\doverbatiminclude#1{%
7555   {%
7556     \makevalueexpandable
7557     \setupverbatim
7558     \indexnofonts       % Allow `@@' and other weird things in file names.
7559     \wlog{texinfo.tex: doing @verbatiminclude of #1^^J}%
7560     \input #1
7561     \afterenvbreak
7562   }%
7563 }
7564
7565 % @copying ... @end copying.
7566 % Save the text away for @insertcopying later.
7567 %
7568 % We save the uninterpreted tokens, rather than creating a box.
7569 % Saving the text in a box would be much easier, but then all the
7570 % typesetting commands (@smallbook, font changes, etc.) have to be done
7571 % beforehand -- and a) we want @copying to be done first in the source
7572 % file; b) letting users define the frontmatter in as flexible order as
7573 % possible is desirable.
7574 %
7575 \def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
7576 \def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
7577 %
7578 \def\insertcopying{%
7579   \begingroup
7580     \parindent = 0pt  % paragraph indentation looks wrong on title page
7581     \scanexp\copyingtext
7582   \endgroup
7583 }
7584
7585
7586 \message{defuns,}
7587 % @defun etc.
7588
7589 \newskip\defbodyindent \defbodyindent=.4in
7590 \newskip\defargsindent \defargsindent=50pt
7591 \newskip\deflastargmargin \deflastargmargin=18pt
7592 \newcount\defunpenalty
7593
7594 % Start the processing of @deffn:
7595 \def\startdefun{%
7596   \ifnum\lastpenalty<10000
7597     \medbreak
7598     \defunpenalty=10003 % Will keep this @deffn together with the
7599                         % following @def command, see below.
7600   \else
7601     % If there are two @def commands in a row, we'll have a \nobreak,
7602     % which is there to keep the function description together with its
7603     % header.  But if there's nothing but headers, we need to allow a
7604     % break somewhere.  Check specifically for penalty 10002, inserted
7605     % by \printdefunline, instead of 10000, since the sectioning
7606     % commands also insert a nobreak penalty, and we don't want to allow
7607     % a break between a section heading and a defun.
7608     %
7609     % As a further refinement, we avoid "club" headers by signalling
7610     % with penalty of 10003 after the very first @deffn in the
7611     % sequence (see above), and penalty of 10002 after any following
7612     % @def command.
7613     \ifnum\lastpenalty=10002 \penalty2000 \else \defunpenalty=10002 \fi
7614     %
7615     % Similarly, after a section heading, do not allow a break.
7616     % But do insert the glue.
7617     \medskip  % preceded by discardable penalty, so not a breakpoint
7618   \fi
7619   %
7620   \parindent=0in
7621   \advance\leftskip by \defbodyindent
7622   \exdentamount=\defbodyindent
7623 }
7624
7625 \def\dodefunx#1{%
7626   % First, check whether we are in the right environment:
7627   \checkenv#1%
7628   %
7629   % As above, allow line break if we have multiple x headers in a row.
7630   % It's not a great place, though.
7631   \ifnum\lastpenalty=10002 \penalty3000 \else \defunpenalty=10002 \fi
7632   %
7633   % And now, it's time to reuse the body of the original defun:
7634   \expandafter\gobbledefun#1%
7635 }
7636 \def\gobbledefun#1\startdefun{}
7637
7638 % \printdefunline \deffnheader{text}
7639 %
7640 \def\printdefunline#1#2{%
7641   \begingroup
7642     % call \deffnheader:
7643     #1#2 \endheader
7644     % common ending:
7645     \interlinepenalty = 10000
7646     \advance\rightskip by 0pt plus 1fil\relax
7647     \endgraf
7648     \nobreak\vskip -\parskip
7649     \penalty\defunpenalty  % signal to \startdefun and \dodefunx
7650     % Some of the @defun-type tags do not enable magic parentheses,
7651     % rendering the following check redundant.  But we don't optimize.
7652     \checkparencounts
7653   \endgroup
7654 }
7655
7656 \def\Edefun{\endgraf\medbreak}
7657
7658 % \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
7659 % the only thing remaining is to define \deffnheader.
7660 %
7661 \def\makedefun#1{%
7662   \expandafter\let\csname E#1\endcsname = \Edefun
7663   \edef\temp{\noexpand\domakedefun
7664     \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
7665   \temp
7666 }
7667
7668 % \domakedefun \deffn \deffnx \deffnheader { (defn. of \deffnheader) }
7669 %
7670 % Define \deffn and \deffnx, without parameters.
7671 % \deffnheader has to be defined explicitly.
7672 %
7673 \def\domakedefun#1#2#3{%
7674   \envdef#1{%
7675     \startdefun
7676     \doingtypefnfalse    % distinguish typed functions from all else
7677     \parseargusing\activeparens{\printdefunline#3}%
7678   }%
7679   \def#2{\dodefunx#1}%
7680   \def#3%
7681 }
7682
7683 \newif\ifdoingtypefn       % doing typed function?
7684 \newif\ifrettypeownline    % typeset return type on its own line?
7685
7686 % @deftypefnnewline on|off says whether the return type of typed functions
7687 % are printed on their own line.  This affects @deftypefn, @deftypefun,
7688 % @deftypeop, and @deftypemethod.
7689
7690 \parseargdef\deftypefnnewline{%
7691   \def\temp{#1}%
7692   \ifx\temp\onword
7693     \expandafter\let\csname SETtxideftypefnnl\endcsname
7694       = \empty
7695   \else\ifx\temp\offword
7696     \expandafter\let\csname SETtxideftypefnnl\endcsname
7697       = \relax
7698   \else
7699     \errhelp = \EMsimple
7700     \errmessage{Unknown @txideftypefnnl value `\temp',
7701                 must be on|off}%
7702   \fi\fi
7703 }
7704
7705 % Untyped functions:
7706
7707 % @deffn category name args
7708 \makedefun{deffn}{\deffngeneral{}}
7709
7710 % @deffn category class name args
7711 \makedefun{defop}#1 {\defopon{#1\ \putwordon}}
7712
7713 % \defopon {category on}class name args
7714 \def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7715
7716 % \deffngeneral {subind}category name args
7717 %
7718 \def\deffngeneral#1#2 #3 #4\endheader{%
7719   % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
7720   \dosubind{fn}{\code{#3}}{#1}%
7721   \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
7722 }
7723
7724 % Typed functions:
7725
7726 % @deftypefn category type name args
7727 \makedefun{deftypefn}{\deftypefngeneral{}}
7728
7729 % @deftypeop category class type name args
7730 \makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
7731
7732 % \deftypeopon {category on}class type name args
7733 \def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
7734
7735 % \deftypefngeneral {subind}category type name args
7736 %
7737 \def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
7738   \dosubind{fn}{\code{#4}}{#1}%
7739   \doingtypefntrue
7740   \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7741 }
7742
7743 % Typed variables:
7744
7745 % @deftypevr category type var args
7746 \makedefun{deftypevr}{\deftypecvgeneral{}}
7747
7748 % @deftypecv category class type var args
7749 \makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
7750
7751 % \deftypecvof {category of}class type var args
7752 \def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
7753
7754 % \deftypecvgeneral {subind}category type var args
7755 %
7756 \def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
7757   \dosubind{vr}{\code{#4}}{#1}%
7758   \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
7759 }
7760
7761 % Untyped variables:
7762
7763 % @defvr category var args
7764 \makedefun{defvr}#1 {\deftypevrheader{#1} {} }
7765
7766 % @defcv category class var args
7767 \makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
7768
7769 % \defcvof {category of}class var args
7770 \def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
7771
7772 % Types:
7773
7774 % @deftp category name args
7775 \makedefun{deftp}#1 #2 #3\endheader{%
7776   \doind{tp}{\code{#2}}%
7777   \defname{#1}{}{#2}\defunargs{#3\unskip}%
7778 }
7779
7780 % Remaining @defun-like shortcuts:
7781 \makedefun{defun}{\deffnheader{\putwordDeffunc} }
7782 \makedefun{defmac}{\deffnheader{\putwordDefmac} }
7783 \makedefun{defspec}{\deffnheader{\putwordDefspec} }
7784 \makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
7785 \makedefun{defvar}{\defvrheader{\putwordDefvar} }
7786 \makedefun{defopt}{\defvrheader{\putwordDefopt} }
7787 \makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
7788 \makedefun{defmethod}{\defopon\putwordMethodon}
7789 \makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
7790 \makedefun{defivar}{\defcvof\putwordInstanceVariableof}
7791 \makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
7792
7793 % \defname, which formats the name of the @def (not the args).
7794 % #1 is the category, such as "Function".
7795 % #2 is the return type, if any.
7796 % #3 is the function name.
7797 %
7798 % We are followed by (but not passed) the arguments, if any.
7799 %
7800 \def\defname#1#2#3{%
7801   \par
7802   % Get the values of \leftskip and \rightskip as they were outside the @def...
7803   \advance\leftskip by -\defbodyindent
7804   %
7805   % Determine if we are typesetting the return type of a typed function
7806   % on a line by itself.
7807   \rettypeownlinefalse
7808   \ifdoingtypefn  % doing a typed function specifically?
7809     % then check user option for putting return type on its own line:
7810     \expandafter\ifx\csname SETtxideftypefnnl\endcsname\relax \else
7811       \rettypeownlinetrue
7812     \fi
7813   \fi
7814   %
7815   % How we'll format the category name.  Putting it in brackets helps
7816   % distinguish it from the body text that may end up on the next line
7817   % just below it.
7818   \def\temp{#1}%
7819   \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
7820   %
7821   % Figure out line sizes for the paragraph shape.  We'll always have at
7822   % least two.
7823   \tempnum = 2
7824   %
7825   % The first line needs space for \box0; but if \rightskip is nonzero,
7826   % we need only space for the part of \box0 which exceeds it:
7827   \dimen0=\hsize  \advance\dimen0 by -\wd0  \advance\dimen0 by \rightskip
7828   %
7829   % If doing a return type on its own line, we'll have another line.
7830   \ifrettypeownline
7831     \advance\tempnum by 1
7832     \def\maybeshapeline{0in \hsize}%
7833   \else
7834     \def\maybeshapeline{}%
7835   \fi
7836   %
7837   % The continuations:
7838   \dimen2=\hsize  \advance\dimen2 by -\defargsindent
7839   %
7840   % The final paragraph shape:
7841   \parshape \tempnum  0in \dimen0  \maybeshapeline  \defargsindent \dimen2
7842   %
7843   % Put the category name at the right margin.
7844   \noindent
7845   \hbox to 0pt{%
7846     \hfil\box0 \kern-\hsize
7847     % \hsize has to be shortened this way:
7848     \kern\leftskip
7849     % Intentionally do not respect \rightskip, since we need the space.
7850   }%
7851   %
7852   % Allow all lines to be underfull without complaint:
7853   \tolerance=10000 \hbadness=10000
7854   \exdentamount=\defbodyindent
7855   {%
7856     % defun fonts. We use typewriter by default (used to be bold) because:
7857     % . we're printing identifiers, they should be in tt in principle.
7858     % . in languages with many accents, such as Czech or French, it's
7859     %   common to leave accents off identifiers.  The result looks ok in
7860     %   tt, but exceedingly strange in rm.
7861     % . we don't want -- and --- to be treated as ligatures.
7862     % . this still does not fix the ?` and !` ligatures, but so far no
7863     %   one has made identifiers using them :).
7864     \df \tt
7865     \def\temp{#2}% text of the return type
7866     \ifx\temp\empty\else
7867       \tclose{\temp}% typeset the return type
7868       \ifrettypeownline
7869         % put return type on its own line; prohibit line break following:
7870         \hfil\vadjust{\nobreak}\break  
7871       \else
7872         \space  % type on same line, so just followed by a space
7873       \fi
7874     \fi           % no return type
7875     #3% output function name
7876   }%
7877   {\rm\enskip}% hskip 0.5 em of \tenrm
7878   %
7879   \boldbrax
7880   % arguments will be output next, if any.
7881 }
7882
7883 % Print arguments in slanted roman (not ttsl), inconsistently with using
7884 % tt for the name.  This is because literal text is sometimes needed in
7885 % the argument list (groff manual), and ttsl and tt are not very
7886 % distinguishable.  Prevent hyphenation at `-' chars.
7887 %
7888 \def\defunargs#1{%
7889   % use sl by default (not ttsl),
7890   % tt for the names.
7891   \df \sl \hyphenchar\font=0
7892   %
7893   % On the other hand, if an argument has two dashes (for instance), we
7894   % want a way to get ttsl.  We used to recommend @var for that, so
7895   % leave the code in, but it's strange for @var to lead to typewriter.
7896   % Nowadays we recommend @code, since the difference between a ttsl hyphen
7897   % and a tt hyphen is pretty tiny.  @code also disables ?` !`.
7898   \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}%
7899   #1%
7900   \sl\hyphenchar\font=45
7901 }
7902
7903 % We want ()&[] to print specially on the defun line.
7904 %
7905 \def\activeparens{%
7906   \catcode`\(=\active \catcode`\)=\active
7907   \catcode`\[=\active \catcode`\]=\active
7908   \catcode`\&=\active
7909 }
7910
7911 % Make control sequences which act like normal parenthesis chars.
7912 \let\lparen = ( \let\rparen = )
7913
7914 % Be sure that we always have a definition for `(', etc.  For example,
7915 % if the fn name has parens in it, \boldbrax will not be in effect yet,
7916 % so TeX would otherwise complain about undefined control sequence.
7917 {
7918   \activeparens
7919   \global\let(=\lparen \global\let)=\rparen
7920   \global\let[=\lbrack \global\let]=\rbrack
7921   \global\let& = \&
7922
7923   \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
7924   \gdef\magicamp{\let&=\amprm}
7925 }
7926
7927 \newcount\parencount
7928
7929 % If we encounter &foo, then turn on ()-hacking afterwards
7930 \newif\ifampseen
7931 \def\amprm#1 {\ampseentrue{\bf\&#1 }}
7932
7933 \def\parenfont{%
7934   \ifampseen
7935     % At the first level, print parens in roman,
7936     % otherwise use the default font.
7937     \ifnum \parencount=1 \rm \fi
7938   \else
7939     % The \sf parens (in \boldbrax) actually are a little bolder than
7940     % the contained text.  This is especially needed for [ and ] .
7941     \sf
7942   \fi
7943 }
7944 \def\infirstlevel#1{%
7945   \ifampseen
7946     \ifnum\parencount=1
7947       #1%
7948     \fi
7949   \fi
7950 }
7951 \def\bfafterword#1 {#1 \bf}
7952
7953 \def\opnr{%
7954   \global\advance\parencount by 1
7955   {\parenfont(}%
7956   \infirstlevel \bfafterword
7957 }
7958 \def\clnr{%
7959   {\parenfont)}%
7960   \infirstlevel \sl
7961   \global\advance\parencount by -1
7962 }
7963
7964 \newcount\brackcount
7965 \def\lbrb{%
7966   \global\advance\brackcount by 1
7967   {\bf[}%
7968 }
7969 \def\rbrb{%
7970   {\bf]}%
7971   \global\advance\brackcount by -1
7972 }
7973
7974 \def\checkparencounts{%
7975   \ifnum\parencount=0 \else \badparencount \fi
7976   \ifnum\brackcount=0 \else \badbrackcount \fi
7977 }
7978 % these should not use \errmessage; the glibc manual, at least, actually
7979 % has such constructs (when documenting function pointers).
7980 \def\badparencount{%
7981   \message{Warning: unbalanced parentheses in @def...}%
7982   \global\parencount=0
7983 }
7984 \def\badbrackcount{%
7985   \message{Warning: unbalanced square brackets in @def...}%
7986   \global\brackcount=0
7987 }
7988
7989
7990 \message{macros,}
7991 % @macro.
7992
7993 % To do this right we need a feature of e-TeX, \scantokens,
7994 % which we arrange to emulate with a temporary file in ordinary TeX.
7995 \ifx\eTeXversion\thisisundefined
7996   \newwrite\macscribble
7997   \def\scantokens#1{%
7998     \toks0={#1}%
7999     \immediate\openout\macscribble=\jobname.tmp
8000     \immediate\write\macscribble{\the\toks0}%
8001     \immediate\closeout\macscribble
8002     \input \jobname.tmp
8003   }
8004 \fi
8005
8006 \let\aftermacroxxx\relax
8007 \def\aftermacro{\aftermacroxxx}
8008
8009 % alias because \c means cedilla in @tex or @math
8010 \let\texinfoc=\c
8011
8012 \newcount\savedcatcodeone
8013 \newcount\savedcatcodetwo
8014
8015 % Used at the time of macro expansion.
8016 % Argument is macro body with arguments substituted
8017 \def\scanmacro#1{%
8018   \newlinechar`\^^M
8019   \def\xeatspaces{\eatspaces}%
8020   %
8021   % Temporarily undo catcode changes of \printindex.  Set catcode of @ to
8022   % 0 so that @-commands in macro expansions aren't printed literally when 
8023   % formatting an index file, where \ is used as the escape character.
8024   \savedcatcodeone=\catcode`\@
8025   \savedcatcodetwo=\catcode`\\
8026   \catcode`\@=0
8027   \catcode`\\=\active
8028   %
8029   % Process the macro body under the current catcode regime.
8030   \scantokens{#1@texinfoc}\aftermacro%
8031   %
8032   \catcode`\@=\savedcatcodeone
8033   \catcode`\\=\savedcatcodetwo
8034   %
8035   % The \texinfoc is to remove the \newlinechar added by \scantokens, and
8036   % can be noticed by \parsearg.
8037   %   The \aftermacro allows a \comment at the end of the macro definition
8038   % to duplicate itself past the final \newlinechar added by \scantokens:
8039   % this is used in the definition of \group to comment out a newline.  We
8040   % don't do the same for \c to support Texinfo files with macros that ended
8041   % with a @c, which should no longer be necessary.
8042   %   We avoid surrounding the call to \scantokens with \bgroup and \egroup
8043   % to allow macros to open or close groups themselves.
8044 }
8045
8046 % Used for copying and captions
8047 \def\scanexp#1{%
8048   \expandafter\scanmacro\expandafter{#1}%
8049 }
8050
8051 \newcount\paramno   % Count of parameters
8052 \newtoks\macname    % Macro name
8053 \newif\ifrecursive  % Is it recursive?
8054
8055 % List of all defined macros in the form
8056 %    \commondummyword\macro1\commondummyword\macro2...
8057 % Currently is also contains all @aliases; the list can be split
8058 % if there is a need.
8059 \def\macrolist{}
8060
8061 % Add the macro to \macrolist
8062 \def\addtomacrolist#1{\expandafter \addtomacrolistxxx \csname#1\endcsname}
8063 \def\addtomacrolistxxx#1{%
8064      \toks0 = \expandafter{\macrolist\commondummyword#1}%
8065      \xdef\macrolist{\the\toks0}%
8066 }
8067
8068 % Utility routines.
8069 % This does \let #1 = #2, with \csnames; that is,
8070 %   \let \csname#1\endcsname = \csname#2\endcsname
8071 % (except of course we have to play expansion games).
8072 %
8073 \def\cslet#1#2{%
8074   \expandafter\let
8075   \csname#1\expandafter\endcsname
8076   \csname#2\endcsname
8077 }
8078
8079 % Trim leading and trailing spaces off a string.
8080 % Concepts from aro-bend problem 15 (see CTAN).
8081 {\catcode`\@=11
8082 \gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
8083 \gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
8084 \gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
8085 \def\unbrace#1{#1}
8086 \unbrace{\gdef\trim@@@ #1 } #2@{#1}
8087 }
8088
8089 % Trim a single trailing ^^M off a string.
8090 {\catcode`\^^M=\other \catcode`\Q=3%
8091 \gdef\eatcr #1{\eatcra #1Q^^MQ}%
8092 \gdef\eatcra#1^^MQ{\eatcrb#1Q}%
8093 \gdef\eatcrb#1Q#2Q{#1}%
8094 }
8095
8096 % Macro bodies are absorbed as an argument in a context where
8097 % all characters are catcode 10, 11 or 12, except \ which is active
8098 % (as in normal texinfo). It is necessary to change the definition of \
8099 % to recognize macro arguments; this is the job of \mbodybackslash.
8100 %
8101 % Non-ASCII encodings make 8-bit characters active, so un-activate
8102 % them to avoid their expansion.  Must do this non-globally, to
8103 % confine the change to the current group.
8104 %
8105 % It's necessary to have hard CRs when the macro is executed. This is
8106 % done by making ^^M (\endlinechar) catcode 12 when reading the macro
8107 % body, and then making it the \newlinechar in \scanmacro.
8108 %
8109 \def\scanctxt{% used as subroutine
8110   \catcode`\"=\other
8111   \catcode`\+=\other
8112   \catcode`\<=\other
8113   \catcode`\>=\other
8114   \catcode`\^=\other
8115   \catcode`\_=\other
8116   \catcode`\|=\other
8117   \catcode`\~=\other
8118   \passthroughcharstrue
8119 }
8120
8121 \def\scanargctxt{% used for copying and captions, not macros.
8122   \scanctxt
8123   \catcode`\@=\other
8124   \catcode`\\=\other
8125   \catcode`\^^M=\other
8126 }
8127
8128 \def\macrobodyctxt{% used for @macro definitions
8129   \scanctxt
8130   \catcode`\ =\other
8131   \catcode`\@=\other
8132   \catcode`\{=\other
8133   \catcode`\}=\other
8134   \catcode`\^^M=\other
8135   \usembodybackslash
8136 }
8137
8138 % Used when scanning braced macro arguments.  Note, however, that catcode
8139 % changes here are ineffectual if the macro invocation was nested inside
8140 % an argument to another Texinfo command.
8141 \def\macroargctxt{%
8142   \scanctxt
8143   \catcode`\ =\active
8144   \catcode`\^^M=\other
8145   \catcode`\\=\active
8146 }
8147
8148 \def\macrolineargctxt{% used for whole-line arguments without braces
8149   \scanctxt
8150   \catcode`\{=\other
8151   \catcode`\}=\other
8152 }
8153
8154 % \mbodybackslash is the definition of \ in @macro bodies.
8155 % It maps \foo\ => \csname macarg.foo\endcsname => #N
8156 % where N is the macro parameter number.
8157 % We define \csname macarg.\endcsname to be \realbackslash, so
8158 % \\ in macro replacement text gets you a backslash.
8159 %
8160 {\catcode`@=0 @catcode`@\=@active
8161  @gdef@usembodybackslash{@let\=@mbodybackslash}
8162  @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
8163 }
8164 \expandafter\def\csname macarg.\endcsname{\realbackslash}
8165
8166 \def\margbackslash#1{\char`\#1 }
8167
8168 \def\macro{\recursivefalse\parsearg\macroxxx}
8169 \def\rmacro{\recursivetrue\parsearg\macroxxx}
8170
8171 \def\macroxxx#1{%
8172   \getargs{#1}% now \macname is the macname and \argl the arglist
8173   \ifx\argl\empty       % no arguments
8174      \paramno=0\relax
8175   \else
8176      \expandafter\parsemargdef \argl;%
8177      \if\paramno>256\relax
8178        \ifx\eTeXversion\thisisundefined
8179          \errhelp = \EMsimple
8180          \errmessage{You need eTeX to compile a file with macros with more than 256 arguments}
8181        \fi
8182      \fi
8183   \fi
8184   \if1\csname ismacro.\the\macname\endcsname
8185      \message{Warning: redefining \the\macname}%
8186   \else
8187      \expandafter\ifx\csname \the\macname\endcsname \relax
8188      \else \errmessage{Macro name \the\macname\space already defined}\fi
8189      \global\cslet{macsave.\the\macname}{\the\macname}%
8190      \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
8191      \addtomacrolist{\the\macname}%
8192   \fi
8193   \begingroup \macrobodyctxt
8194   \ifrecursive \expandafter\parsermacbody
8195   \else \expandafter\parsemacbody
8196   \fi}
8197
8198 \parseargdef\unmacro{%
8199   \if1\csname ismacro.#1\endcsname
8200     \global\cslet{#1}{macsave.#1}%
8201     \global\expandafter\let \csname ismacro.#1\endcsname=0%
8202     % Remove the macro name from \macrolist:
8203     \begingroup
8204       \expandafter\let\csname#1\endcsname \relax
8205       \let\commondummyword\unmacrodo
8206       \xdef\macrolist{\macrolist}%
8207     \endgroup
8208   \else
8209     \errmessage{Macro #1 not defined}%
8210   \fi
8211 }
8212
8213 % Called by \do from \dounmacro on each macro.  The idea is to omit any
8214 % macro definitions that have been changed to \relax.
8215 %
8216 \def\unmacrodo#1{%
8217   \ifx #1\relax
8218     % remove this
8219   \else
8220     \noexpand\commondummyword \noexpand#1%
8221   \fi
8222 }
8223
8224 % \getargs -- Parse the arguments to a @macro line.  Set \macname to
8225 % the name of the macro, and \argl to the braced argument list.
8226 \def\getargs#1{\getargsxxx#1{}}
8227 \def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
8228 \def\getmacname#1 #2\relax{\macname={#1}}
8229 \def\getmacargs#1{\def\argl{#1}}
8230 % This made use of the feature that if the last token of a
8231 % <parameter list> is #, then the preceding argument is delimited by
8232 % an opening brace, and that opening brace is not consumed.
8233
8234 % Parse the optional {params} list to @macro or @rmacro.
8235 % Set \paramno to the number of arguments,
8236 % and \paramlist to a parameter text for the macro (e.g. #1,#2,#3 for a
8237 % three-param macro.)  Define \macarg.BLAH for each BLAH in the params
8238 % list to some hook where the argument is to be expanded.  If there are
8239 % less than 10 arguments that hook is to be replaced by ##N where N
8240 % is the position in that list, that is to say the macro arguments are to be
8241 % defined `a la TeX in the macro body.  
8242 %
8243 % That gets used by \mbodybackslash (above).
8244 %
8245 % If there are 10 or more arguments, a different technique is used: see
8246 % \parsemmanyargdef.
8247 %
8248 \def\parsemargdef#1;{%
8249   \paramno=0\def\paramlist{}%
8250   \let\hash\relax
8251   % \hash is redefined to `#' later to get it into definitions
8252   \let\xeatspaces\relax
8253   \parsemargdefxxx#1,;,%
8254   \ifnum\paramno<10\relax\else
8255     \paramno0\relax
8256     \parsemmanyargdef@@#1,;,% 10 or more arguments
8257   \fi
8258 }
8259 \def\parsemargdefxxx#1,{%
8260   \if#1;\let\next=\relax
8261   \else \let\next=\parsemargdefxxx
8262     \advance\paramno by 1
8263     \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
8264         {\xeatspaces{\hash\the\paramno}}%
8265     \edef\paramlist{\paramlist\hash\the\paramno,}%
8266   \fi\next}
8267
8268 % \parsemacbody, \parsermacbody
8269 %
8270 % Read recursive and nonrecursive macro bodies. (They're different since
8271 % rec and nonrec macros end differently.)
8272
8273 % We are in \macrobodyctxt, and the \xdef causes backslashshes in the macro 
8274 % body to be transformed.
8275 % Set \macrobody to the body of the macro, and call \defmacro.
8276 %
8277 {\catcode`\ =\other\long\gdef\parsemacbody#1@end macro{%
8278 \xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8279 {\catcode`\ =\other\long\gdef\parsermacbody#1@end rmacro{%
8280 \xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}%
8281
8282 % Make @ a letter, so that we can make private-to-Texinfo macro names.
8283 \edef\texiatcatcode{\the\catcode`\@}
8284 \catcode `@=11\relax
8285
8286 %%%%%%%%%%%%%% Code for > 10 arguments only   %%%%%%%%%%%%%%%%%%
8287
8288 % If there are 10 or more arguments, a different technique is used, where the
8289 % hook remains in the body, and when macro is to be expanded the body is
8290 % processed again to replace the arguments.
8291 %
8292 % In that case, the hook is \the\toks N-1, and we simply set \toks N-1 to the
8293 % argument N value and then \edef the body (nothing else will expand because of
8294 % the catcode regime under which the body was input).
8295 %
8296 % If you compile with TeX (not eTeX), and you have macros with 10 or more
8297 % arguments, no macro can have more than 256 arguments (else error).
8298 %
8299 % In case that there are 10 or more arguments we parse again the arguments
8300 % list to set new definitions for the \macarg.BLAH macros corresponding to
8301 % each BLAH argument. It was anyhow needed to parse already once this list
8302 % in order to count the arguments, and as macros with at most 9 arguments
8303 % are by far more frequent than macro with 10 or more arguments, defining
8304 % twice the \macarg.BLAH macros does not cost too much processing power.
8305 \def\parsemmanyargdef@@#1,{%
8306   \if#1;\let\next=\relax
8307   \else 
8308     \let\next=\parsemmanyargdef@@
8309     \edef\tempb{\eatspaces{#1}}%
8310     \expandafter\def\expandafter\tempa
8311        \expandafter{\csname macarg.\tempb\endcsname}%
8312     % Note that we need some extra \noexpand\noexpand, this is because we
8313     % don't want \the  to be expanded in the \parsermacbody  as it uses an
8314     % \xdef .
8315     \expandafter\edef\tempa
8316       {\noexpand\noexpand\noexpand\the\toks\the\paramno}%
8317     \advance\paramno by 1\relax
8318   \fi\next}
8319
8320
8321 \let\endargs@\relax
8322 \let\nil@\relax
8323 \def\nilm@{\nil@}%
8324 \long\def\nillm@{\nil@}%
8325
8326 % This macro is expanded during the Texinfo macro expansion, not during its
8327 % definition.  It gets all the arguments' values and assigns them to macros
8328 % macarg.ARGNAME
8329 %
8330 % #1 is the macro name
8331 % #2 is the list of argument names
8332 % #3 is the list of argument values
8333 \def\getargvals@#1#2#3{%
8334   \def\macargdeflist@{}%
8335   \def\saveparamlist@{#2}% Need to keep a copy for parameter expansion.
8336   \def\paramlist{#2,\nil@}%
8337   \def\macroname{#1}%
8338   \begingroup
8339   \macroargctxt
8340   \def\argvaluelist{#3,\nil@}%
8341   \def\@tempa{#3}%
8342   \ifx\@tempa\empty
8343     \setemptyargvalues@
8344   \else
8345     \getargvals@@
8346   \fi
8347 }
8348 \def\getargvals@@{%
8349   \ifx\paramlist\nilm@
8350       % Some sanity check needed here that \argvaluelist is also empty.
8351       \ifx\argvaluelist\nillm@
8352       \else
8353         \errhelp = \EMsimple
8354         \errmessage{Too many arguments in macro `\macroname'!}%
8355       \fi
8356       \let\next\macargexpandinbody@
8357   \else
8358     \ifx\argvaluelist\nillm@
8359        % No more arguments values passed to macro.  Set remaining named-arg
8360        % macros to empty.
8361        \let\next\setemptyargvalues@
8362     \else
8363       % pop current arg name into \@tempb
8364       \def\@tempa##1{\pop@{\@tempb}{\paramlist}##1\endargs@}%
8365       \expandafter\@tempa\expandafter{\paramlist}%
8366        % pop current argument value into \@tempc
8367       \def\@tempa##1{\longpop@{\@tempc}{\argvaluelist}##1\endargs@}%
8368       \expandafter\@tempa\expandafter{\argvaluelist}%
8369        % Here \@tempb is the current arg name and \@tempc is the current arg value.
8370        % First place the new argument macro definition into \@tempd
8371        \expandafter\macname\expandafter{\@tempc}%
8372        \expandafter\let\csname macarg.\@tempb\endcsname\relax
8373        \expandafter\def\expandafter\@tempe\expandafter{%
8374          \csname macarg.\@tempb\endcsname}%
8375        \edef\@tempd{\long\def\@tempe{\the\macname}}%
8376        \push@\@tempd\macargdeflist@
8377        \let\next\getargvals@@
8378     \fi
8379   \fi
8380   \next
8381 }
8382
8383 \def\push@#1#2{%
8384   \expandafter\expandafter\expandafter\def
8385   \expandafter\expandafter\expandafter#2%
8386   \expandafter\expandafter\expandafter{%
8387   \expandafter#1#2}%
8388 }
8389
8390 % Replace arguments by their values in the macro body, and place the result
8391 % in macro \@tempa.
8392
8393 \def\macvalstoargs@{%
8394   %  To do this we use the property that token registers that are \the'ed
8395   % within an \edef  expand only once. So we are going to place all argument
8396   % values into respective token registers.
8397   %
8398   % First we save the token context, and initialize argument numbering.
8399   \begingroup
8400     \paramno0\relax
8401     % Then, for each argument number #N, we place the corresponding argument
8402     % value into a new token list register \toks#N
8403     \expandafter\putargsintokens@\saveparamlist@,;,%
8404     % Then, we expand the body so that argument are replaced by their
8405     % values. The trick for values not to be expanded themselves is that they
8406     % are within tokens and that tokens expand only once in an \edef .
8407     \edef\@tempc{\csname mac.\macroname .body\endcsname}%
8408     % Now we restore the token stack pointer to free the token list registers
8409     % which we have used, but we make sure that expanded body is saved after
8410     % group.
8411     \expandafter
8412   \endgroup
8413   \expandafter\def\expandafter\@tempa\expandafter{\@tempc}%
8414   }
8415
8416 % Define the named-macro outside of this group and then close this group. 
8417
8418 \def\macargexpandinbody@{% 
8419   \expandafter
8420   \endgroup
8421   \macargdeflist@
8422   % First the replace in body the macro arguments by their values, the result
8423   % is in \@tempa .
8424   \macvalstoargs@
8425   % Then we point at the \norecurse or \gobble (for recursive) macro value
8426   % with \@tempb .
8427   \expandafter\let\expandafter\@tempb\csname mac.\macroname .recurse\endcsname
8428   % Depending on whether it is recursive or not, we need some tailing
8429   % \egroup .
8430   \ifx\@tempb\gobble
8431      \let\@tempc\relax
8432   \else
8433      \let\@tempc\egroup
8434   \fi
8435   % And now we do the real job:
8436   \edef\@tempd{\noexpand\@tempb{\macroname}\noexpand\scanmacro{\@tempa}\@tempc}%
8437   \@tempd
8438 }
8439
8440 \def\putargsintokens@#1,{%
8441   \if#1;\let\next\relax
8442   \else
8443     \let\next\putargsintokens@
8444     % First we allocate the new token list register, and give it a temporary
8445     % alias \@tempb .
8446     \toksdef\@tempb\the\paramno
8447     % Then we place the argument value into that token list register.
8448     \expandafter\let\expandafter\@tempa\csname macarg.#1\endcsname
8449     \expandafter\@tempb\expandafter{\@tempa}%
8450     \advance\paramno by 1\relax
8451   \fi
8452   \next
8453 }
8454
8455 % Trailing missing arguments are set to empty.
8456
8457 \def\setemptyargvalues@{%
8458   \ifx\paramlist\nilm@
8459     \let\next\macargexpandinbody@
8460   \else
8461     \expandafter\setemptyargvaluesparser@\paramlist\endargs@
8462     \let\next\setemptyargvalues@
8463   \fi
8464   \next
8465 }
8466
8467 \def\setemptyargvaluesparser@#1,#2\endargs@{%
8468   \expandafter\def\expandafter\@tempa\expandafter{%
8469     \expandafter\def\csname macarg.#1\endcsname{}}%
8470   \push@\@tempa\macargdeflist@
8471   \def\paramlist{#2}%
8472 }
8473
8474 % #1 is the element target macro
8475 % #2 is the list macro
8476 % #3,#4\endargs@ is the list value
8477 \def\pop@#1#2#3,#4\endargs@{%
8478    \def#1{#3}%
8479    \def#2{#4}%
8480 }
8481 \long\def\longpop@#1#2#3,#4\endargs@{%
8482    \long\def#1{#3}%
8483    \long\def#2{#4}%
8484 }
8485
8486
8487 %%%%%%%%%%%%%% End of code for > 10 arguments %%%%%%%%%%%%%%%%%%
8488
8489
8490 % This defines a Texinfo @macro or @rmacro, called by \parsemacbody.
8491 %    \macrobody has the body of the macro in it, with placeholders for
8492 % its parameters, looking like "\xeatspaces{\hash 1}".
8493 %    \paramno is the number of parameters
8494 %    \paramlist is a TeX parameter text, e.g. "#1,#2,#3,"
8495 % There are four cases: macros of zero, one, up to nine, and many arguments.
8496 % \xdef is used so that macro definitions will survive the file
8497 % they're defined in: @include reads the file inside a group.
8498 %
8499 \def\defmacro{%
8500   \let\hash=##% convert placeholders to macro parameter chars
8501   \ifnum\paramno=1
8502     \def\xeatspaces##1{##1}%
8503     % This removes the pair of braces around the argument.  We don't
8504     % use \eatspaces, because this can cause ends of lines to be lost
8505     % when the argument to \eatspaces is read, leading to line-based
8506     % commands like "@itemize" not being read correctly.
8507   \else
8508     \let\xeatspaces\relax % suppress expansion
8509   \fi
8510   \ifcase\paramno
8511   % 0
8512     \expandafter\xdef\csname\the\macname\endcsname{%
8513       \noexpand\scanmacro{\macrobody}}%
8514   \or % 1
8515     \expandafter\xdef\csname\the\macname\endcsname{%
8516        \bgroup
8517        \noexpand\braceorline
8518        \expandafter\noexpand\csname\the\macname @@@\endcsname}%
8519     \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8520       \egroup
8521       \noexpand\scanmacro{\macrobody}%
8522       }%
8523   \else % at most 9
8524     \ifnum\paramno<10\relax
8525       % @MACNAME sets the context for reading the macro argument
8526       % @MACNAME@@ gets the argument, processes backslashes and appends a 
8527       % comma.
8528       % @MACNAME@@@ removes braces surrounding the argument list.
8529       % @MACNAME@@@@ scans the macro body with arguments substituted.
8530       \expandafter\xdef\csname\the\macname\endcsname{%
8531         \bgroup
8532         \noexpand\expandafter  % This \expandafter skip any spaces after the
8533         \noexpand\macroargctxt % macro before we change the catcode of space.
8534         \noexpand\expandafter
8535         \expandafter\noexpand\csname\the\macname @@\endcsname}%
8536       \expandafter\xdef\csname\the\macname @@\endcsname##1{%
8537           \noexpand\passargtomacro
8538           \expandafter\noexpand\csname\the\macname @@@\endcsname{##1,}}%
8539       \expandafter\xdef\csname\the\macname @@@\endcsname##1{%
8540           \expandafter\noexpand\csname\the\macname @@@@\endcsname ##1}%
8541       \expandafter\expandafter
8542       \expandafter\xdef
8543       \expandafter\expandafter
8544         \csname\the\macname @@@@\endcsname\paramlist{%
8545           \egroup\noexpand\scanmacro{\macrobody}}%
8546     \else % 10 or more:
8547       \expandafter\xdef\csname\the\macname\endcsname{%
8548         \noexpand\getargvals@{\the\macname}{\argl}%
8549       }%
8550       \global\expandafter\let\csname mac.\the\macname .body\endcsname\macrobody
8551       \global\expandafter\let\csname mac.\the\macname .recurse\endcsname\gobble
8552     \fi
8553   \fi}
8554
8555 \catcode `\@\texiatcatcode\relax % end private-to-Texinfo catcodes
8556
8557 \def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
8558
8559
8560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8561 %
8562 {\catcode`\@=0 \catcode`\\=13  % We need to manipulate \ so use @ as escape
8563 @catcode`@_=11  % private names
8564 @catcode`@!=11  % used as argument separator
8565
8566 % \passargtomacro#1#2 -
8567 % Call #1 with a list of tokens #2, with any doubled backslashes in #2
8568 % compressed to one.
8569 %
8570 % This implementation works by expansion, and not execution (so we cannot use 
8571 % \def or similar).  This reduces the risk of this failing in contexts where 
8572 % complete expansion is done with no execution (for example, in writing out to 
8573 % an auxiliary file for an index entry).
8574
8575 % State is kept in the input stream: the argument passed to
8576 % @look_ahead, @gobble_and_check_finish and @add_segment is
8577 %
8578 % THE_MACRO ARG_RESULT ! {PENDING_BS} NEXT_TOKEN  (... rest of input)
8579 %
8580 % where:
8581 % THE_MACRO - name of the macro we want to call
8582 % ARG_RESULT - argument list we build to pass to that macro
8583 % PENDING_BS - either a backslash or nothing
8584 % NEXT_TOKEN - used to look ahead in the input stream to see what's coming next
8585
8586 @gdef@passargtomacro#1#2{%
8587   @add_segment #1!{}@relax#2\@_finish\%
8588 }
8589 @gdef@_finish{@_finishx} @global@let@_finishx@relax
8590
8591 % #1 - THE_MACRO ARG_RESULT
8592 % #2 - PENDING_BS
8593 % #3 - NEXT_TOKEN
8594 % #4 used to look ahead
8595 %
8596 % If the next token is not a backslash, process the rest of the argument; 
8597 % otherwise, remove the next token.
8598 @gdef@look_ahead#1!#2#3#4{%
8599   @ifx#4\%
8600    @expandafter@gobble_and_check_finish 
8601   @else
8602    @expandafter@add_segment
8603   @fi#1!{#2}#4#4%
8604 }
8605
8606 % #1 - THE_MACRO ARG_RESULT
8607 % #2 - PENDING_BS
8608 % #3 - NEXT_TOKEN
8609 % #4 should be a backslash, which is gobbled.
8610 % #5 looks ahead
8611 %
8612 % Double backslash found.  Add a single backslash, and look ahead.
8613 @gdef@gobble_and_check_finish#1!#2#3#4#5{%
8614   @add_segment#1\!{}#5#5%
8615 }
8616
8617 @gdef@is_fi{@fi}
8618
8619 % #1 - THE_MACRO ARG_RESULT
8620 % #2 - PENDING_BS
8621 % #3 - NEXT_TOKEN
8622 % #4 is input stream until next backslash
8623 %
8624 % Input stream is either at the start of the argument, or just after a 
8625 % backslash sequence, either a lone backslash, or a doubled backslash.  
8626 % NEXT_TOKEN contains the first token in the input stream: if it is \finish, 
8627 % finish; otherwise, append to ARG_RESULT the segment of the argument up until
8628 % the next backslash.  PENDING_BACKSLASH contains a backslash to represent
8629 % a backslash just before the start of the input stream that has not been
8630 % added to ARG_RESULT.
8631 @gdef@add_segment#1!#2#3#4\{%
8632 @ifx#3@_finish
8633   @call_the_macro#1!%
8634 @else
8635   % append the pending backslash to the result, followed by the next segment
8636   @expandafter@is_fi@look_ahead#1#2#4!{\}@fi
8637   % this @fi is discarded by @look_ahead.
8638   % we can't get rid of it with \expandafter because we don't know how 
8639   % long #4 is.
8640 }
8641
8642 % #1 - THE_MACRO
8643 % #2 - ARG_RESULT
8644 % #3 discards the res of the conditional in @add_segment, and @is_fi ends the 
8645 % conditional.
8646 @gdef@call_the_macro#1#2!#3@fi{@is_fi #1{#2}}
8647
8648 }
8649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8650
8651 % \braceorline MAC is used for a one-argument macro MAC.  It checks
8652 % whether the next non-whitespace character is a {.  It sets the context
8653 % for reading the argument (slightly different in the two cases).  Then,
8654 % to read the argument, in the whole-line case, it then calls the regular
8655 % \parsearg MAC; in the lbrace case, it calls \passargtomacro MAC.
8656
8657 \def\braceorline#1{\let\macnamexxx=#1\futurelet\nchar\braceorlinexxx}
8658 \def\braceorlinexxx{%
8659   \ifx\nchar\bgroup
8660     \macroargctxt
8661     \expandafter\passargtomacro
8662   \else
8663     \macrolineargctxt\expandafter\parsearg
8664   \fi \macnamexxx}
8665
8666
8667 % @alias.
8668 % We need some trickery to remove the optional spaces around the equal
8669 % sign.  Make them active and then expand them all to nothing.
8670 %
8671 \def\alias{\parseargusing\obeyspaces\aliasxxx}
8672 \def\aliasxxx #1{\aliasyyy#1\relax}
8673 \def\aliasyyy #1=#2\relax{%
8674   {%
8675     \expandafter\let\obeyedspace=\empty
8676     \addtomacrolist{#1}%
8677     \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
8678   }%
8679   \next
8680 }
8681
8682
8683 \message{cross references,}
8684
8685 \newwrite\auxfile
8686 \newif\ifhavexrefs    % True if xref values are known.
8687 \newif\ifwarnedxrefs  % True if we warned once that they aren't known.
8688
8689 % @inforef is relatively simple.
8690 \def\inforef #1{\inforefzzz #1,,,,**}
8691 \def\inforefzzz #1,#2,#3,#4**{%
8692   \putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
8693   node \samp{\ignorespaces#1{}}}
8694
8695 % @node's only job in TeX is to define \lastnode, which is used in
8696 % cross-references.  The @node line might or might not have commas, and
8697 % might or might not have spaces before the first comma, like:
8698 % @node foo , bar , ...
8699 % We don't want such trailing spaces in the node name.
8700 %
8701 \parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
8702 %
8703 % also remove a trailing comma, in case of something like this:
8704 % @node Help-Cross,  ,  , Cross-refs
8705 \def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
8706 \def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
8707
8708 \let\nwnode=\node
8709 \let\lastnode=\empty
8710
8711 % Write a cross-reference definition for the current node.  #1 is the
8712 % type (Ynumbered, Yappendix, Ynothing).
8713 %
8714 \def\donoderef#1{%
8715   \ifx\lastnode\empty\else
8716     \setref{\lastnode}{#1}%
8717     \global\let\lastnode=\empty
8718   \fi
8719 }
8720
8721 % @anchor{NAME} -- define xref target at arbitrary point.
8722 %
8723 \newcount\savesfregister
8724 %
8725 \def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
8726 \def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
8727 \def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
8728
8729 % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
8730 % anchor), which consists of three parts:
8731 % 1) NAME-title - the current sectioning name taken from \lastsection,
8732 %                 or the anchor name.
8733 % 2) NAME-snt   - section number and type, passed as the SNT arg, or
8734 %                 empty for anchors.
8735 % 3) NAME-pg    - the page number.
8736 %
8737 % This is called from \donoderef, \anchor, and \dofloat.  In the case of
8738 % floats, there is an additional part, which is not written here:
8739 % 4) NAME-lof   - the text as it should appear in a @listoffloats.
8740 %
8741 \def\setref#1#2{%
8742   \pdfmkdest{#1}%
8743   \iflinks
8744     {%
8745       \requireauxfile
8746       \atdummies  % preserve commands, but don't expand them
8747       % match definition in \xrdef, \refx, \xrefX.
8748       \def\value##1{##1}%
8749       \edef\writexrdef##1##2{%
8750         \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
8751           ##1}{##2}}% these are parameters of \writexrdef
8752       }%
8753       \toks0 = \expandafter{\lastsection}%
8754       \immediate \writexrdef{title}{\the\toks0 }%
8755       \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
8756       \safewhatsit{\writexrdef{pg}{\folio}}% will be written later, at \shipout
8757     }%
8758   \fi
8759 }
8760
8761 % @xrefautosectiontitle on|off says whether @section(ing) names are used
8762 % automatically in xrefs, if the third arg is not explicitly specified.
8763 % This was provided as a "secret" @set xref-automatic-section-title
8764 % variable, now it's official.
8765
8766 \parseargdef\xrefautomaticsectiontitle{%
8767   \def\temp{#1}%
8768   \ifx\temp\onword
8769     \expandafter\let\csname SETxref-automatic-section-title\endcsname
8770       = \empty
8771   \else\ifx\temp\offword
8772     \expandafter\let\csname SETxref-automatic-section-title\endcsname
8773       = \relax
8774   \else
8775     \errhelp = \EMsimple
8776     \errmessage{Unknown @xrefautomaticsectiontitle value `\temp',
8777                 must be on|off}%
8778   \fi\fi
8779 }
8780
8781\f
8782 % @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
8783 % the node name, #2 the name of the Info cross-reference, #3 the printed
8784 % node name, #4 the name of the Info file, #5 the name of the printed
8785 % manual.  All but the node name can be omitted.
8786 %
8787 \def\pxref{\putwordsee{} \xrefXX}
8788 \def\xref{\putwordSee{} \xrefXX}
8789 \def\ref{\xrefXX}
8790
8791 \def\xrefXX#1{\def\xrefXXarg{#1}\futurelet\tokenafterxref\xrefXXX}
8792 \def\xrefXXX{\expandafter\xrefX\expandafter[\xrefXXarg,,,,,,,]}
8793 %
8794 \newbox\toprefbox
8795 \newbox\printedrefnamebox
8796 \newbox\infofilenamebox
8797 \newbox\printedmanualbox
8798 %
8799 \def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
8800   \unsepspaces
8801   %
8802   % Get args without leading/trailing spaces.
8803   \def\printedrefname{\ignorespaces #3}%
8804   \setbox\printedrefnamebox = \hbox{\printedrefname\unskip}%
8805   %
8806   \def\infofilename{\ignorespaces #4}%
8807   \setbox\infofilenamebox = \hbox{\infofilename\unskip}%
8808   %
8809   \def\printedmanual{\ignorespaces #5}%
8810   \setbox\printedmanualbox  = \hbox{\printedmanual\unskip}%
8811   %
8812   % If the printed reference name (arg #3) was not explicitly given in
8813   % the @xref, figure out what we want to use.
8814   \ifdim \wd\printedrefnamebox = 0pt
8815     % No printed node name was explicitly given.
8816     \expandafter\ifx\csname SETxref-automatic-section-title\endcsname \relax
8817       % Not auto section-title: use node name inside the square brackets.
8818       \def\printedrefname{\ignorespaces #1}%
8819     \else
8820       % Auto section-title: use chapter/section title inside
8821       % the square brackets if we have it.
8822       \ifdim \wd\printedmanualbox > 0pt
8823         % It is in another manual, so we don't have it; use node name.
8824         \def\printedrefname{\ignorespaces #1}%
8825       \else
8826         \ifhavexrefs
8827           % We (should) know the real title if we have the xref values.
8828           \def\printedrefname{\refx{#1-title}{}}%
8829         \else
8830           % Otherwise just copy the Info node name.
8831           \def\printedrefname{\ignorespaces #1}%
8832         \fi%
8833       \fi
8834     \fi
8835   \fi
8836   %
8837   % Make link in pdf output.
8838   \ifpdf
8839     % For pdfTeX and LuaTeX
8840     {\indexnofonts
8841      \turnoffactive
8842      \makevalueexpandable
8843      % This expands tokens, so do it after making catcode changes, so _
8844      % etc. don't get their TeX definitions.  This ignores all spaces in
8845      % #4, including (wrongly) those in the middle of the filename.
8846      \getfilename{#4}%
8847      %
8848      % This (wrongly) does not take account of leading or trailing
8849      % spaces in #1, which should be ignored.
8850      \edef\pdfxrefdest{#1}%
8851      \ifx\pdfxrefdest\empty
8852        \def\pdfxrefdest{Top}% no empty targets
8853      \else
8854        \txiescapepdf\pdfxrefdest  % escape PDF special chars
8855      \fi
8856      %
8857      \leavevmode
8858      \startlink attr{/Border [0 0 0]}%
8859      \ifnum\filenamelength>0
8860        goto file{\the\filename.pdf} name{\pdfxrefdest}%
8861      \else
8862        goto name{\pdfmkpgn{\pdfxrefdest}}%
8863      \fi
8864     }%
8865     \setcolor{\linkcolor}%
8866   \else
8867     \ifx\XeTeXrevision\thisisundefined
8868     \else
8869       % For XeTeX
8870       {\indexnofonts
8871        \turnoffactive
8872        \makevalueexpandable
8873        % This expands tokens, so do it after making catcode changes, so _
8874        % etc. don't get their TeX definitions.  This ignores all spaces in
8875        % #4, including (wrongly) those in the middle of the filename.
8876        \getfilename{#4}%
8877        %
8878        % This (wrongly) does not take account of leading or trailing
8879        % spaces in #1, which should be ignored.
8880        \iftxiuseunicodedestname
8881          \def\pdfxrefdest{#1}% Pass through Unicode characters.
8882        \else
8883          \edef\pdfxrefdest{#1}% Replace Unicode characters to ASCII.
8884        \fi
8885        \ifx\pdfxrefdest\empty
8886          \def\pdfxrefdest{Top}% no empty targets
8887        \else
8888          \txiescapepdf\pdfxrefdest  % escape PDF special chars
8889        \fi
8890        %
8891        \leavevmode
8892        \ifnum\filenamelength>0
8893          % By the default settings,
8894          % XeTeX (xdvipdfmx) replaces link destination names with integers.
8895          % In this case, the replaced destination names of
8896          % remote PDF cannot be known. In order to avoid replacement,
8897          % you can use commandline option `-C 0x0010' for xdvipdfmx.
8898          % If you use XeTeX 0.99996+ (TeX Live 2016+),
8899          % the commandline option is not neccesary
8900          % because we can use `dvipdfmx:config' special.
8901          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8902            << /S /GoToR /F (\the\filename.pdf) /D (name\pdfxrefdest) >> >>}%
8903        \else
8904          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
8905            << /S /GoTo /D (name\pdfxrefdest) >> >>}%
8906        \fi
8907       }%
8908       \setcolor{\linkcolor}%
8909     \fi
8910   \fi
8911   {%
8912     % Have to otherify everything special to allow the \csname to
8913     % include an _ in the xref name, etc.
8914     \indexnofonts
8915     \turnoffactive
8916     \def\value##1{##1}%
8917     \expandafter\global\expandafter\let\expandafter\Xthisreftitle
8918       \csname XR#1-title\endcsname
8919   }%
8920   %
8921   % Float references are printed completely differently: "Figure 1.2"
8922   % instead of "[somenode], p.3".  \iffloat distinguishes them by
8923   % \Xthisreftitle being set to a magic string.
8924   \iffloat\Xthisreftitle
8925     % If the user specified the print name (third arg) to the ref,
8926     % print it instead of our usual "Figure 1.2".
8927     \ifdim\wd\printedrefnamebox = 0pt
8928       \refx{#1-snt}{}%
8929     \else
8930       \printedrefname
8931     \fi
8932     %
8933     % If the user also gave the printed manual name (fifth arg), append
8934     % "in MANUALNAME".
8935     \ifdim \wd\printedmanualbox > 0pt
8936       \space \putwordin{} \cite{\printedmanual}%
8937     \fi
8938   \else
8939     % node/anchor (non-float) references.
8940     % 
8941     % If we use \unhbox to print the node names, TeX does not insert
8942     % empty discretionaries after hyphens, which means that it will not
8943     % find a line break at a hyphen in a node names.  Since some manuals
8944     % are best written with fairly long node names, containing hyphens,
8945     % this is a loss.  Therefore, we give the text of the node name
8946     % again, so it is as if TeX is seeing it for the first time.
8947     % 
8948     \ifdim \wd\printedmanualbox > 0pt
8949       % Cross-manual reference with a printed manual name.
8950       % 
8951       \crossmanualxref{\cite{\printedmanual\unskip}}%
8952     %
8953     \else\ifdim \wd\infofilenamebox > 0pt
8954       % Cross-manual reference with only an info filename (arg 4), no
8955       % printed manual name (arg 5).  This is essentially the same as
8956       % the case above; we output the filename, since we have nothing else.
8957       % 
8958       \crossmanualxref{\code{\infofilename\unskip}}%
8959     %
8960     \else
8961       % Reference within this manual.
8962       %
8963       % _ (for example) has to be the character _ for the purposes of the
8964       % control sequence corresponding to the node, but it has to expand
8965       % into the usual \leavevmode...\vrule stuff for purposes of
8966       % printing. So we \turnoffactive for the \refx-snt, back on for the
8967       % printing, back off for the \refx-pg.
8968       {\turnoffactive
8969        % Only output a following space if the -snt ref is nonempty; for
8970        % @unnumbered and @anchor, it won't be.
8971        \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
8972        \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
8973       }%
8974       % output the `[mynode]' via the macro below so it can be overridden.
8975       \xrefprintnodename\printedrefname
8976       %
8977       % But we always want a comma and a space:
8978       ,\space
8979       %
8980       % output the `page 3'.
8981       \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
8982       % Add a , if xref followed by a space
8983       \if\space\noexpand\tokenafterxref ,%
8984       \else\ifx\        \tokenafterxref ,% @TAB
8985       \else\ifx\*\tokenafterxref ,%   @*
8986       \else\ifx\ \tokenafterxref ,%   @SPACE
8987       \else\ifx\
8988                 \tokenafterxref ,%    @NL
8989       \else\ifx\tie\tokenafterxref ,% @tie
8990       \fi\fi\fi\fi\fi\fi
8991     \fi\fi
8992   \fi
8993   \endlink
8994 \endgroup}
8995
8996 % Output a cross-manual xref to #1.  Used just above (twice).
8997
8998 % Only include the text "Section ``foo'' in" if the foo is neither
8999 % missing or Top.  Thus, @xref{,,,foo,The Foo Manual} outputs simply
9000 % "see The Foo Manual", the idea being to refer to the whole manual.
9001
9002 % But, this being TeX, we can't easily compare our node name against the
9003 % string "Top" while ignoring the possible spaces before and after in
9004 % the input.  By adding the arbitrary 7sp below, we make it much less
9005 % likely that a real node name would have the same width as "Top" (e.g.,
9006 % in a monospaced font).  Hopefully it will never happen in practice.
9007
9008 % For the same basic reason, we retypeset the "Top" at every
9009 % reference, since the current font is indeterminate.
9010
9011 \def\crossmanualxref#1{%
9012   \setbox\toprefbox = \hbox{Top\kern7sp}%
9013   \setbox2 = \hbox{\ignorespaces \printedrefname \unskip \kern7sp}%
9014   \ifdim \wd2 > 7sp  % nonempty?
9015     \ifdim \wd2 = \wd\toprefbox \else  % same as Top?
9016       \putwordSection{} ``\printedrefname'' \putwordin{}\space
9017     \fi
9018   \fi
9019   #1%
9020 }
9021
9022 % This macro is called from \xrefX for the `[nodename]' part of xref
9023 % output.  It's a separate macro only so it can be changed more easily,
9024 % since square brackets don't work well in some documents.  Particularly
9025 % one that Bob is working on :).
9026 %
9027 \def\xrefprintnodename#1{[#1]}
9028
9029 % Things referred to by \setref.
9030 %
9031 \def\Ynothing{}
9032 \def\Yomitfromtoc{}
9033 \def\Ynumbered{%
9034   \ifnum\secno=0
9035     \putwordChapter@tie \the\chapno
9036   \else \ifnum\subsecno=0
9037     \putwordSection@tie \the\chapno.\the\secno
9038   \else \ifnum\subsubsecno=0
9039     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
9040   \else
9041     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
9042   \fi\fi\fi
9043 }
9044 \def\Yappendix{%
9045   \ifnum\secno=0
9046      \putwordAppendix@tie @char\the\appendixno{}%
9047   \else \ifnum\subsecno=0
9048      \putwordSection@tie @char\the\appendixno.\the\secno
9049   \else \ifnum\subsubsecno=0
9050     \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
9051   \else
9052     \putwordSection@tie
9053       @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
9054   \fi\fi\fi
9055 }
9056
9057 % \refx{NAME}{SUFFIX} - reference a cross-reference string named NAME.  SUFFIX 
9058 % is output afterwards if non-empty.
9059 \def\refx#1#2{%
9060   \requireauxfile
9061   {%
9062     \indexnofonts
9063     \otherbackslash
9064     \def\value##1{##1}%
9065     \expandafter\global\expandafter\let\expandafter\thisrefX
9066       \csname XR#1\endcsname
9067   }%
9068   \ifx\thisrefX\relax
9069     % If not defined, say something at least.
9070     \angleleft un\-de\-fined\angleright
9071     \iflinks
9072       \ifhavexrefs
9073         {\toks0 = {#1}% avoid expansion of possibly-complex value
9074          \message{\linenumber Undefined cross reference `\the\toks0'.}}%
9075       \else
9076         \ifwarnedxrefs\else
9077           \global\warnedxrefstrue
9078           \message{Cross reference values unknown; you must run TeX again.}%
9079         \fi
9080       \fi
9081     \fi
9082   \else
9083     % It's defined, so just use it.
9084     \thisrefX
9085   \fi
9086   #2% Output the suffix in any case.
9087 }
9088
9089 % This is the macro invoked by entries in the aux file.  Define a control 
9090 % sequence for a cross-reference target (we prepend XR to the control sequence 
9091 % name to avoid collisions).  The value is the page number.  If this is a float 
9092 % type, we have more work to do.
9093 %
9094 \def\xrdef#1#2{%
9095   {% Expand the node or anchor name to remove control sequences.
9096    % \turnoffactive stops 8-bit characters being changed to commands
9097    % like @'e.  \refx does the same to retrieve the value in the definition.
9098     \indexnofonts
9099     \turnoffactive
9100     \def\value##1{##1}%
9101     \xdef\safexrefname{#1}%
9102   }%
9103   %
9104   \expandafter\gdef\csname XR\safexrefname\endcsname{#2}% remember this xref
9105   %
9106   % Was that xref control sequence that we just defined for a float?
9107   \expandafter\iffloat\csname XR\safexrefname\endcsname
9108     % it was a float, and we have the (safe) float type in \iffloattype.
9109     \expandafter\let\expandafter\floatlist
9110       \csname floatlist\iffloattype\endcsname
9111     %
9112     % Is this the first time we've seen this float type?
9113     \expandafter\ifx\floatlist\relax
9114       \toks0 = {\do}% yes, so just \do
9115     \else
9116       % had it before, so preserve previous elements in list.
9117       \toks0 = \expandafter{\floatlist\do}%
9118     \fi
9119     %
9120     % Remember this xref in the control sequence \floatlistFLOATTYPE,
9121     % for later use in \listoffloats.
9122     \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0
9123       {\safexrefname}}%
9124   \fi
9125 }
9126
9127 % If working on a large document in chapters, it is convenient to
9128 % be able to disable indexing, cross-referencing, and contents, for test runs.
9129 % This is done with @novalidate at the beginning of the file.
9130 %
9131 \newif\iflinks \linkstrue % by default we want the aux files.
9132 \let\novalidate = \linksfalse
9133
9134 % Used when writing to the aux file, or when using data from it.
9135 \def\requireauxfile{%
9136   \iflinks
9137     \tryauxfile
9138     % Open the new aux file.  TeX will close it automatically at exit.
9139     \immediate\openout\auxfile=\jobname.aux
9140   \fi
9141   \global\let\requireauxfile=\relax   % Only do this once.
9142 }
9143
9144 % Read the last existing aux file, if any.  No error if none exists.
9145 %
9146 \def\tryauxfile{%
9147   \openin 1 \jobname.aux
9148   \ifeof 1 \else
9149     \readdatafile{aux}%
9150     \global\havexrefstrue
9151   \fi
9152   \closein 1
9153 }
9154
9155 \def\setupdatafile{%
9156   \catcode`\^^@=\other
9157   \catcode`\^^A=\other
9158   \catcode`\^^B=\other
9159   \catcode`\^^C=\other
9160   \catcode`\^^D=\other
9161   \catcode`\^^E=\other
9162   \catcode`\^^F=\other
9163   \catcode`\^^G=\other
9164   \catcode`\^^H=\other
9165   \catcode`\^^K=\other
9166   \catcode`\^^L=\other
9167   \catcode`\^^N=\other
9168   \catcode`\^^P=\other
9169   \catcode`\^^Q=\other
9170   \catcode`\^^R=\other
9171   \catcode`\^^S=\other
9172   \catcode`\^^T=\other
9173   \catcode`\^^U=\other
9174   \catcode`\^^V=\other
9175   \catcode`\^^W=\other
9176   \catcode`\^^X=\other
9177   \catcode`\^^Z=\other
9178   \catcode`\^^[=\other
9179   \catcode`\^^\=\other
9180   \catcode`\^^]=\other
9181   \catcode`\^^^=\other
9182   \catcode`\^^_=\other
9183   % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
9184   % in xref tags, i.e., node names.  But since ^^e4 notation isn't
9185   % supported in the main text, it doesn't seem desirable.  Furthermore,
9186   % that is not enough: for node names that actually contain a ^
9187   % character, we would end up writing a line like this: 'xrdef {'hat
9188   % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
9189   % argument, and \hat is not an expandable control sequence.  It could
9190   % all be worked out, but why?  Either we support ^^ or we don't.
9191   %
9192   % The other change necessary for this was to define \auxhat:
9193   % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
9194   % and then to call \auxhat in \setq.
9195   %
9196   \catcode`\^=\other
9197   %
9198   % Special characters.  Should be turned off anyway, but...
9199   \catcode`\~=\other
9200   \catcode`\[=\other
9201   \catcode`\]=\other
9202   \catcode`\"=\other
9203   \catcode`\_=\other
9204   \catcode`\|=\other
9205   \catcode`\<=\other
9206   \catcode`\>=\other
9207   \catcode`\$=\other
9208   \catcode`\#=\other
9209   \catcode`\&=\other
9210   \catcode`\%=\other
9211   \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
9212   %
9213   % This is to support \ in node names and titles, since the \
9214   % characters end up in a \csname.  It's easier than
9215   % leaving it active and making its active definition an actual \
9216   % character.  What I don't understand is why it works in the *value*
9217   % of the xrdef.  Seems like it should be a catcode12 \, and that
9218   % should not typeset properly.  But it works, so I'm moving on for
9219   % now.  --karl, 15jan04.
9220   \catcode`\\=\other
9221   %
9222   % @ is our escape character in .aux files, and we need braces.
9223   \catcode`\{=1
9224   \catcode`\}=2
9225   \catcode`\@=0
9226 }
9227
9228 \def\readdatafile#1{%
9229 \begingroup
9230   \setupdatafile
9231   \input\jobname.#1
9232 \endgroup}
9233
9234
9235 \message{insertions,}
9236 % including footnotes.
9237
9238 \newcount \footnoteno
9239
9240 % The trailing space in the following definition for supereject is
9241 % vital for proper filling; pages come out unaligned when you do a
9242 % pagealignmacro call if that space before the closing brace is
9243 % removed. (Generally, numeric constants should always be followed by a
9244 % space to prevent strange expansion errors.)
9245 \def\supereject{\par\penalty -20000\footnoteno =0 }
9246
9247 % @footnotestyle is meaningful for Info output only.
9248 \let\footnotestyle=\comment
9249
9250 {\catcode `\@=11
9251 %
9252 % Auto-number footnotes.  Otherwise like plain.
9253 \gdef\footnote{%
9254   \global\advance\footnoteno by \@ne
9255   \edef\thisfootno{$^{\the\footnoteno}$}%
9256   %
9257   % In case the footnote comes at the end of a sentence, preserve the
9258   % extra spacing after we do the footnote number.
9259   \let\@sf\empty
9260   \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
9261   %
9262   % Remove inadvertent blank space before typesetting the footnote number.
9263   \unskip
9264   \thisfootno\@sf
9265   \dofootnote
9266 }%
9267
9268 % Don't bother with the trickery in plain.tex to not require the
9269 % footnote text as a parameter.  Our footnotes don't need to be so general.
9270 %
9271 % Oh yes, they do; otherwise, @ifset (and anything else that uses
9272 % \parseargline) fails inside footnotes because the tokens are fixed when
9273 % the footnote is read.  --karl, 16nov96.
9274 %
9275 \gdef\dofootnote{%
9276   \insert\footins\bgroup
9277   %
9278   % Nested footnotes are not supported in TeX, that would take a lot
9279   % more work.  (\startsavinginserts does not suffice.)
9280   \let\footnote=\errfootnotenest
9281   %
9282   % We want to typeset this text as a normal paragraph, even if the
9283   % footnote reference occurs in (for example) a display environment.
9284   % So reset some parameters.
9285   \hsize=\txipagewidth
9286   \interlinepenalty\interfootnotelinepenalty
9287   \splittopskip\ht\strutbox % top baseline for broken footnotes
9288   \splitmaxdepth\dp\strutbox
9289   \floatingpenalty\@MM
9290   \leftskip\z@skip
9291   \rightskip\z@skip
9292   \spaceskip\z@skip
9293   \xspaceskip\z@skip
9294   \parindent\defaultparindent
9295   %
9296   \smallfonts \rm
9297   %
9298   % Because we use hanging indentation in footnotes, a @noindent appears
9299   % to exdent this text, so make it be a no-op.  makeinfo does not use
9300   % hanging indentation so @noindent can still be needed within footnote
9301   % text after an @example or the like (not that this is good style).
9302   \let\noindent = \relax
9303   %
9304   % Hang the footnote text off the number.  Use \everypar in case the
9305   % footnote extends for more than one paragraph.
9306   \everypar = {\hang}%
9307   \textindent{\thisfootno}%
9308   %
9309   % Don't crash into the line above the footnote text.  Since this
9310   % expands into a box, it must come within the paragraph, lest it
9311   % provide a place where TeX can split the footnote.
9312   \footstrut
9313   %
9314   % Invoke rest of plain TeX footnote routine.
9315   \futurelet\next\fo@t
9316 }
9317 }%end \catcode `\@=11
9318
9319 \def\errfootnotenest{%
9320   \errhelp=\EMsimple
9321   \errmessage{Nested footnotes not supported in texinfo.tex,
9322     even though they work in makeinfo; sorry}
9323 }
9324
9325 \def\errfootnoteheading{%
9326   \errhelp=\EMsimple
9327   \errmessage{Footnotes in chapters, sections, etc., are not supported}
9328 }
9329
9330 % In case a @footnote appears in a vbox, save the footnote text and create
9331 % the real \insert just after the vbox finished.  Otherwise, the insertion
9332 % would be lost.
9333 % Similarly, if a @footnote appears inside an alignment, save the footnote
9334 % text to a box and make the \insert when a row of the table is finished.
9335 % And the same can be done for other insert classes.  --kasal, 16nov03.
9336 %
9337 % Replace the \insert primitive by a cheating macro.
9338 % Deeper inside, just make sure that the saved insertions are not spilled
9339 % out prematurely.
9340 %
9341 \def\startsavinginserts{%
9342   \ifx \insert\ptexinsert
9343     \let\insert\saveinsert
9344   \else
9345     \let\checkinserts\relax
9346   \fi
9347 }
9348
9349 % This \insert replacement works for both \insert\footins{foo} and
9350 % \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
9351 %
9352 \def\saveinsert#1{%
9353   \edef\next{\noexpand\savetobox \makeSAVEname#1}%
9354   \afterassignment\next
9355   % swallow the left brace
9356   \let\temp =
9357 }
9358 \def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
9359 \def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
9360
9361 \def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
9362
9363 \def\placesaveins#1{%
9364   \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
9365     {\box#1}%
9366 }
9367
9368 % eat @SAVE -- beware, all of them have catcode \other:
9369 {
9370   \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials  %  ;-)
9371   \gdef\gobblesave @SAVE{}
9372 }
9373
9374 % initialization:
9375 \def\newsaveins #1{%
9376   \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
9377   \next
9378 }
9379 \def\newsaveinsX #1{%
9380   \csname newbox\endcsname #1%
9381   \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
9382     \checksaveins #1}%
9383 }
9384
9385 % initialize:
9386 \let\checkinserts\empty
9387 \newsaveins\footins
9388 \newsaveins\margin
9389
9390
9391 % @image.  We use the macros from epsf.tex to support this.
9392 % If epsf.tex is not installed and @image is used, we complain.
9393 %
9394 % Check for and read epsf.tex up front.  If we read it only at @image
9395 % time, we might be inside a group, and then its definitions would get
9396 % undone and the next image would fail.
9397 \openin 1 = epsf.tex
9398 \ifeof 1 \else
9399   % Do not bother showing banner with epsf.tex v2.7k (available in
9400   % doc/epsf.tex and on ctan).
9401   \def\epsfannounce{\toks0 = }%
9402   \input epsf.tex
9403 \fi
9404 \closein 1
9405 %
9406 % We will only complain once about lack of epsf.tex.
9407 \newif\ifwarnednoepsf
9408 \newhelp\noepsfhelp{epsf.tex must be installed for images to
9409   work.  It is also included in the Texinfo distribution, or you can get
9410   it from ftp://tug.org/tex/epsf.tex.}
9411 %
9412 \def\image#1{%
9413   \ifx\epsfbox\thisisundefined
9414     \ifwarnednoepsf \else
9415       \errhelp = \noepsfhelp
9416       \errmessage{epsf.tex not found, images will be ignored}%
9417       \global\warnednoepsftrue
9418     \fi
9419   \else
9420     \imagexxx #1,,,,,\finish
9421   \fi
9422 }
9423 %
9424 % Arguments to @image:
9425 % #1 is (mandatory) image filename; we tack on .eps extension.
9426 % #2 is (optional) width, #3 is (optional) height.
9427 % #4 is (ignored optional) html alt text.
9428 % #5 is (ignored optional) extension.
9429 % #6 is just the usual extra ignored arg for parsing stuff.
9430 \newif\ifimagevmode
9431 \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
9432   \catcode`\^^M = 5     % in case we're inside an example
9433   \normalturnoffactive  % allow _ et al. in names
9434   \def\xprocessmacroarg{\eatspaces}% in case we are being used via a macro
9435   % If the image is by itself, center it.
9436   \ifvmode
9437     \imagevmodetrue
9438   \else \ifx\centersub\centerV
9439     % for @center @image, we need a vbox so we can have our vertical space
9440     \imagevmodetrue
9441     \vbox\bgroup % vbox has better behavior than vtop herev
9442   \fi\fi
9443   %
9444   \ifimagevmode
9445     \nobreak\medskip
9446     % Usually we'll have text after the image which will insert
9447     % \parskip glue, so insert it here too to equalize the space
9448     % above and below.
9449     \nobreak\vskip\parskip
9450     \nobreak
9451   \fi
9452   %
9453   % Leave vertical mode so that indentation from an enclosing
9454   %  environment such as @quotation is respected.
9455   % However, if we're at the top level, we don't want the
9456   %  normal paragraph indentation.
9457   % On the other hand, if we are in the case of @center @image, we don't
9458   %  want to start a paragraph, which will create a hsize-width box and
9459   %  eradicate the centering.
9460   \ifx\centersub\centerV\else \noindent \fi
9461   %
9462   % Output the image.
9463   \ifpdf
9464     % For pdfTeX and LuaTeX <= 0.80
9465     \dopdfimage{#1}{#2}{#3}%
9466   \else
9467     \ifx\XeTeXrevision\thisisundefined
9468       % For epsf.tex
9469       % \epsfbox itself resets \epsf?size at each figure.
9470       \setbox0 = \hbox{\ignorespaces #2}%
9471         \ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
9472       \setbox0 = \hbox{\ignorespaces #3}%
9473         \ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
9474       \epsfbox{#1.eps}%
9475     \else
9476       % For XeTeX
9477       \doxeteximage{#1}{#2}{#3}%
9478     \fi
9479   \fi
9480   %
9481   \ifimagevmode
9482     \medskip  % space after a standalone image
9483   \fi  
9484   \ifx\centersub\centerV \egroup \fi
9485 \endgroup}
9486
9487
9488 % @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
9489 % etc.  We don't actually implement floating yet, we always include the
9490 % float "here".  But it seemed the best name for the future.
9491 %
9492 \envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
9493
9494 % There may be a space before second and/or third parameter; delete it.
9495 \def\eatcommaspace#1, {#1,}
9496
9497 % #1 is the optional FLOATTYPE, the text label for this float, typically
9498 % "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
9499 % this float will not be numbered and cannot be referred to.
9500 %
9501 % #2 is the optional xref label.  Also must be present for the float to
9502 % be referable.
9503 %
9504 % #3 is the optional positioning argument; for now, it is ignored.  It
9505 % will somehow specify the positions allowed to float to (here, top, bottom).
9506 %
9507 % We keep a separate counter for each FLOATTYPE, which we reset at each
9508 % chapter-level command.
9509 \let\resetallfloatnos=\empty
9510 %
9511 \def\dofloat#1,#2,#3,#4\finish{%
9512   \let\thiscaption=\empty
9513   \let\thisshortcaption=\empty
9514   %
9515   % don't lose footnotes inside @float.
9516   %
9517   % BEWARE: when the floats start float, we have to issue warning whenever an
9518   % insert appears inside a float which could possibly float. --kasal, 26may04
9519   %
9520   \startsavinginserts
9521   %
9522   % We can't be used inside a paragraph.
9523   \par
9524   %
9525   \vtop\bgroup
9526     \def\floattype{#1}%
9527     \def\floatlabel{#2}%
9528     \def\floatloc{#3}% we do nothing with this yet.
9529     %
9530     \ifx\floattype\empty
9531       \let\safefloattype=\empty
9532     \else
9533       {%
9534         % the floattype might have accents or other special characters,
9535         % but we need to use it in a control sequence name.
9536         \indexnofonts
9537         \turnoffactive
9538         \xdef\safefloattype{\floattype}%
9539       }%
9540     \fi
9541     %
9542     % If label is given but no type, we handle that as the empty type.
9543     \ifx\floatlabel\empty \else
9544       % We want each FLOATTYPE to be numbered separately (Figure 1,
9545       % Table 1, Figure 2, ...).  (And if no label, no number.)
9546       %
9547       \expandafter\getfloatno\csname\safefloattype floatno\endcsname
9548       \global\advance\floatno by 1
9549       %
9550       {%
9551         % This magic value for \lastsection is output by \setref as the
9552         % XREFLABEL-title value.  \xrefX uses it to distinguish float
9553         % labels (which have a completely different output format) from
9554         % node and anchor labels.  And \xrdef uses it to construct the
9555         % lists of floats.
9556         %
9557         \edef\lastsection{\floatmagic=\safefloattype}%
9558         \setref{\floatlabel}{Yfloat}%
9559       }%
9560     \fi
9561     %
9562     % start with \parskip glue, I guess.
9563     \vskip\parskip
9564     %
9565     % Don't suppress indentation if a float happens to start a section.
9566     \restorefirstparagraphindent
9567 }
9568
9569 % we have these possibilities:
9570 % @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
9571 % @float Foo,lbl & no caption:    Foo 1.1
9572 % @float Foo & @caption{Cap}:     Foo: Cap
9573 % @float Foo & no caption:        Foo
9574 % @float ,lbl & Caption{Cap}:     1.1: Cap
9575 % @float ,lbl & no caption:       1.1
9576 % @float & @caption{Cap}:         Cap
9577 % @float & no caption:
9578 %
9579 \def\Efloat{%
9580     \let\floatident = \empty
9581     %
9582     % In all cases, if we have a float type, it comes first.
9583     \ifx\floattype\empty \else \def\floatident{\floattype}\fi
9584     %
9585     % If we have an xref label, the number comes next.
9586     \ifx\floatlabel\empty \else
9587       \ifx\floattype\empty \else % if also had float type, need tie first.
9588         \appendtomacro\floatident{\tie}%
9589       \fi
9590       % the number.
9591       \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
9592     \fi
9593     %
9594     % Start the printed caption with what we've constructed in
9595     % \floatident, but keep it separate; we need \floatident again.
9596     \let\captionline = \floatident
9597     %
9598     \ifx\thiscaption\empty \else
9599       \ifx\floatident\empty \else
9600         \appendtomacro\captionline{: }% had ident, so need a colon between
9601       \fi
9602       %
9603       % caption text.
9604       \appendtomacro\captionline{\scanexp\thiscaption}%
9605     \fi
9606     %
9607     % If we have anything to print, print it, with space before.
9608     % Eventually this needs to become an \insert.
9609     \ifx\captionline\empty \else
9610       \vskip.5\parskip
9611       \captionline
9612       %
9613       % Space below caption.
9614       \vskip\parskip
9615     \fi
9616     %
9617     % If have an xref label, write the list of floats info.  Do this
9618     % after the caption, to avoid chance of it being a breakpoint.
9619     \ifx\floatlabel\empty \else
9620       % Write the text that goes in the lof to the aux file as
9621       % \floatlabel-lof.  Besides \floatident, we include the short
9622       % caption if specified, else the full caption if specified, else nothing.
9623       {%
9624         \requireauxfile
9625         \atdummies
9626         %
9627         \ifx\thisshortcaption\empty
9628           \def\gtemp{\thiscaption}%
9629         \else
9630           \def\gtemp{\thisshortcaption}%
9631         \fi
9632         \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
9633           \ifx\gtemp\empty \else : \gtemp \fi}}%
9634       }%
9635     \fi
9636   \egroup  % end of \vtop
9637   %
9638   \checkinserts
9639 }
9640
9641 % Append the tokens #2 to the definition of macro #1, not expanding either.
9642 %
9643 \def\appendtomacro#1#2{%
9644   \expandafter\def\expandafter#1\expandafter{#1#2}%
9645 }
9646
9647 % @caption, @shortcaption
9648 %
9649 \def\caption{\docaption\thiscaption}
9650 \def\shortcaption{\docaption\thisshortcaption}
9651 \def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
9652 \def\defcaption#1#2{\egroup \def#1{#2}}
9653
9654 % The parameter is the control sequence identifying the counter we are
9655 % going to use.  Create it if it doesn't exist and assign it to \floatno.
9656 \def\getfloatno#1{%
9657   \ifx#1\relax
9658       % Haven't seen this figure type before.
9659       \csname newcount\endcsname #1%
9660       %
9661       % Remember to reset this floatno at the next chap.
9662       \expandafter\gdef\expandafter\resetallfloatnos
9663         \expandafter{\resetallfloatnos #1=0 }%
9664   \fi
9665   \let\floatno#1%
9666 }
9667
9668 % \setref calls this to get the XREFLABEL-snt value.  We want an @xref
9669 % to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
9670 % first read the @float command.
9671 %
9672 \def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
9673
9674 % Magic string used for the XREFLABEL-title value, so \xrefX can
9675 % distinguish floats from other xref types.
9676 \def\floatmagic{!!float!!}
9677
9678 % #1 is the control sequence we are passed; we expand into a conditional
9679 % which is true if #1 represents a float ref.  That is, the magic
9680 % \lastsection value which we \setref above.
9681 %
9682 \def\iffloat#1{\expandafter\doiffloat#1==\finish}
9683 %
9684 % #1 is (maybe) the \floatmagic string.  If so, #2 will be the
9685 % (safe) float type for this float.  We set \iffloattype to #2.
9686 %
9687 \def\doiffloat#1=#2=#3\finish{%
9688   \def\temp{#1}%
9689   \def\iffloattype{#2}%
9690   \ifx\temp\floatmagic
9691 }
9692
9693 % @listoffloats FLOATTYPE - print a list of floats like a table of contents.
9694 %
9695 \parseargdef\listoffloats{%
9696   \def\floattype{#1}% floattype
9697   {%
9698     % the floattype might have accents or other special characters,
9699     % but we need to use it in a control sequence name.
9700     \indexnofonts
9701     \turnoffactive
9702     \xdef\safefloattype{\floattype}%
9703   }%
9704   %
9705   % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
9706   \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
9707     \ifhavexrefs
9708       % if the user said @listoffloats foo but never @float foo.
9709       \message{\linenumber No `\safefloattype' floats to list.}%
9710     \fi
9711   \else
9712     \begingroup
9713       \leftskip=\tocindent  % indent these entries like a toc
9714       \let\do=\listoffloatsdo
9715       \csname floatlist\safefloattype\endcsname
9716     \endgroup
9717   \fi
9718 }
9719
9720 % This is called on each entry in a list of floats.  We're passed the
9721 % xref label, in the form LABEL-title, which is how we save it in the
9722 % aux file.  We strip off the -title and look up \XRLABEL-lof, which
9723 % has the text we're supposed to typeset here.
9724 %
9725 % Figures without xref labels will not be included in the list (since
9726 % they won't appear in the aux file).
9727 %
9728 \def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
9729 \def\listoffloatsdoentry#1-title\finish{{%
9730   % Can't fully expand XR#1-lof because it can contain anything.  Just
9731   % pass the control sequence.  On the other hand, XR#1-pg is just the
9732   % page number, and we want to fully expand that so we can get a link
9733   % in pdf output.
9734   \toksA = \expandafter{\csname XR#1-lof\endcsname}%
9735   %
9736   % use the same \entry macro we use to generate the TOC and index.
9737   \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
9738   \writeentry
9739 }}
9740
9741
9742 \message{localization,}
9743
9744 % For single-language documents, @documentlanguage is usually given very
9745 % early, just after @documentencoding.  Single argument is the language
9746 % (de) or locale (de_DE) abbreviation.
9747 %
9748 {
9749   \catcode`\_ = \active
9750   \globaldefs=1
9751 \parseargdef\documentlanguage{%
9752   \tex % read txi-??.tex file in plain TeX.
9753     % Read the file by the name they passed if it exists.
9754     \let_ = \normalunderscore  % normal _ character for filename test
9755     \openin 1 txi-#1.tex
9756     \ifeof 1
9757       \documentlanguagetrywithoutunderscore #1_\finish
9758     \else
9759       \globaldefs = 1  % everything in the txi-LL files needs to persist
9760       \input txi-#1.tex
9761     \fi
9762     \closein 1
9763   \endgroup % end raw TeX
9764 }
9765 %
9766 % If they passed de_DE, and txi-de_DE.tex doesn't exist,
9767 % try txi-de.tex.
9768 %
9769 \gdef\documentlanguagetrywithoutunderscore#1_#2\finish{%
9770   \openin 1 txi-#1.tex
9771   \ifeof 1
9772     \errhelp = \nolanghelp
9773     \errmessage{Cannot read language file txi-#1.tex}%
9774   \else
9775     \globaldefs = 1  % everything in the txi-LL files needs to persist
9776     \input txi-#1.tex
9777   \fi
9778   \closein 1
9779 }
9780 }% end of special _ catcode
9781 %
9782 \newhelp\nolanghelp{The given language definition file cannot be found or
9783 is empty.  Maybe you need to install it?  Putting it in the current
9784 directory should work if nowhere else does.}
9785
9786 % This macro is called from txi-??.tex files; the first argument is the
9787 % \language name to set (without the "\lang@" prefix), the second and
9788 % third args are \{left,right}hyphenmin.
9789 %
9790 % The language names to pass are determined when the format is built.
9791 % See the etex.log file created at that time, e.g.,
9792 % /usr/local/texlive/2008/texmf-var/web2c/pdftex/etex.log.
9793 %
9794 % With TeX Live 2008, etex now includes hyphenation patterns for all
9795 % available languages.  This means we can support hyphenation in
9796 % Texinfo, at least to some extent.  (This still doesn't solve the
9797 % accented characters problem.)
9798 %
9799 \catcode`@=11
9800 \def\txisetlanguage#1#2#3{%
9801   % do not set the language if the name is undefined in the current TeX.
9802   \expandafter\ifx\csname lang@#1\endcsname \relax
9803     \message{no patterns for #1}%
9804   \else
9805     \global\language = \csname lang@#1\endcsname
9806   \fi
9807   % but there is no harm in adjusting the hyphenmin values regardless.
9808   \global\lefthyphenmin = #2\relax
9809   \global\righthyphenmin = #3\relax
9810 }
9811
9812 % XeTeX and LuaTeX can handle native Unicode.
9813 % Their default I/O is UTF-8 sequence instead of byte-wise.
9814 % Other TeX engine (pdfTeX etc.) I/O is byte-wise.
9815 %
9816 \newif\iftxinativeunicodecapable
9817 \newif\iftxiusebytewiseio
9818
9819 \ifx\XeTeXrevision\thisisundefined
9820   \ifx\luatexversion\thisisundefined
9821     \txinativeunicodecapablefalse
9822     \txiusebytewiseiotrue
9823   \else
9824     \txinativeunicodecapabletrue
9825     \txiusebytewiseiofalse
9826   \fi
9827 \else
9828   \txinativeunicodecapabletrue
9829   \txiusebytewiseiofalse
9830 \fi
9831
9832 % Set I/O by bytes instead of UTF-8 sequence for XeTeX and LuaTex
9833 % for non-UTF-8 (byte-wise) encodings.
9834 %
9835 \def\setbytewiseio{%
9836   \ifx\XeTeXrevision\thisisundefined
9837   \else
9838     \XeTeXdefaultencoding "bytes"  % For subsequent files to be read
9839     \XeTeXinputencoding "bytes"  % For document root file
9840     % Unfortunately, there seems to be no corresponding XeTeX command for
9841     % output encoding.  This is a problem for auxiliary index and TOC files.
9842     % The only solution would be perhaps to write out @U{...} sequences in
9843     % place of non-ASCII characters.
9844   \fi
9845
9846   \ifx\luatexversion\thisisundefined
9847   \else
9848     \directlua{
9849     local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub
9850     local function convert_char (char)
9851       return utf8_char(byte(char))
9852     end
9853
9854     local function convert_line (line)
9855       return gsub(line, ".", convert_char)
9856     end
9857
9858     callback.register("process_input_buffer", convert_line)
9859
9860     local function convert_line_out (line)
9861       local line_out = ""
9862       for c in string.utfvalues(line) do
9863          line_out = line_out .. string.char(c)
9864       end
9865       return line_out
9866     end
9867
9868     callback.register("process_output_buffer", convert_line_out)
9869     }
9870   \fi
9871
9872   \txiusebytewiseiotrue
9873 }
9874
9875
9876 % Helpers for encodings.
9877 % Set the catcode of characters 128 through 255 to the specified number.
9878 %
9879 \def\setnonasciicharscatcode#1{%
9880    \count255=128
9881    \loop\ifnum\count255<256
9882       \global\catcode\count255=#1\relax
9883       \advance\count255 by 1
9884    \repeat
9885 }
9886
9887 \def\setnonasciicharscatcodenonglobal#1{%
9888    \count255=128
9889    \loop\ifnum\count255<256
9890       \catcode\count255=#1\relax
9891       \advance\count255 by 1
9892    \repeat
9893 }
9894
9895 % @documentencoding sets the definition of non-ASCII characters
9896 % according to the specified encoding.
9897 %
9898 \def\documentencoding{\parseargusing\filenamecatcodes\documentencodingzzz}
9899 \def\documentencodingzzz#1{%
9900   %
9901   % Encoding being declared for the document.
9902   \def\declaredencoding{\csname #1.enc\endcsname}%
9903   %
9904   % Supported encodings: names converted to tokens in order to be able
9905   % to compare them with \ifx.
9906   \def\ascii{\csname US-ASCII.enc\endcsname}%
9907   \def\latnine{\csname ISO-8859-15.enc\endcsname}%
9908   \def\latone{\csname ISO-8859-1.enc\endcsname}%
9909   \def\lattwo{\csname ISO-8859-2.enc\endcsname}%
9910   \def\utfeight{\csname UTF-8.enc\endcsname}%
9911   %
9912   \ifx \declaredencoding \ascii
9913      \asciichardefs
9914   %
9915   \else \ifx \declaredencoding \lattwo
9916      \iftxinativeunicodecapable
9917        \setbytewiseio
9918      \fi
9919      \setnonasciicharscatcode\active
9920      \lattwochardefs
9921   %
9922   \else \ifx \declaredencoding \latone
9923      \iftxinativeunicodecapable
9924        \setbytewiseio
9925      \fi
9926      \setnonasciicharscatcode\active
9927      \latonechardefs
9928   %
9929   \else \ifx \declaredencoding \latnine
9930      \iftxinativeunicodecapable
9931        \setbytewiseio
9932      \fi
9933      \setnonasciicharscatcode\active
9934      \latninechardefs
9935   %
9936   \else \ifx \declaredencoding \utfeight
9937      \iftxinativeunicodecapable
9938        % For native Unicode (XeTeX and LuaTeX)
9939        \nativeunicodechardefs
9940      \else
9941        % For UTF-8 byte sequence (TeX, eTeX and pdfTeX)
9942        \setnonasciicharscatcode\active
9943        % since we already invoked \utfeightchardefs at the top level
9944        % (below), do not re-invoke it, then our check for duplicated
9945        % definitions triggers.  Making non-ascii chars active is enough.
9946      \fi
9947   %
9948   \else
9949     \message{Ignoring unknown document encoding: #1.}%
9950   %
9951   \fi % utfeight
9952   \fi % latnine
9953   \fi % latone
9954   \fi % lattwo
9955   \fi % ascii
9956 }
9957
9958 % emacs-page
9959 % A message to be logged when using a character that isn't available
9960 % the default font encoding (OT1).
9961 %
9962 \def\missingcharmsg#1{\message{Character missing, sorry: #1.}}
9963
9964 % Take account of \c (plain) vs. \, (Texinfo) difference.
9965 \def\cedilla#1{\ifx\c\ptexc\c{#1}\else\,{#1}\fi}
9966
9967 % First, make active non-ASCII characters in order for them to be
9968 % correctly categorized when TeX reads the replacement text of
9969 % macros containing the character definitions.
9970 \setnonasciicharscatcode\active
9971 %
9972
9973 \def\gdefchar#1#2{%
9974 \gdef#1{%
9975    \ifpassthroughchars
9976      \string#1%
9977    \else
9978      #2%
9979    \fi
9980 }}
9981
9982 % Latin1 (ISO-8859-1) character definitions.
9983 \def\latonechardefs{%
9984   \gdefchar^^a0{\tie}
9985   \gdefchar^^a1{\exclamdown}
9986   \gdefchar^^a2{{\tcfont \char162}} % cent
9987   \gdefchar^^a3{\pounds}
9988   \gdefchar^^a4{{\tcfont \char164}} % currency
9989   \gdefchar^^a5{{\tcfont \char165}} % yen
9990   \gdefchar^^a6{{\tcfont \char166}} % broken bar
9991   \gdefchar^^a7{\S}
9992   \gdefchar^^a8{\"{}}
9993   \gdefchar^^a9{\copyright}
9994   \gdefchar^^aa{\ordf}
9995   \gdefchar^^ab{\guillemetleft}
9996   \gdefchar^^ac{\ensuremath\lnot}
9997   \gdefchar^^ad{\-}
9998   \gdefchar^^ae{\registeredsymbol}
9999   \gdefchar^^af{\={}}
10000   %
10001   \gdefchar^^b0{\textdegree}
10002   \gdefchar^^b1{$\pm$}
10003   \gdefchar^^b2{$^2$}
10004   \gdefchar^^b3{$^3$}
10005   \gdefchar^^b4{\'{}}
10006   \gdefchar^^b5{$\mu$}
10007   \gdefchar^^b6{\P}
10008   \gdefchar^^b7{\ensuremath\cdot}
10009   \gdefchar^^b8{\cedilla\ }
10010   \gdefchar^^b9{$^1$}
10011   \gdefchar^^ba{\ordm}
10012   \gdefchar^^bb{\guillemetright}
10013   \gdefchar^^bc{$1\over4$}
10014   \gdefchar^^bd{$1\over2$}
10015   \gdefchar^^be{$3\over4$}
10016   \gdefchar^^bf{\questiondown}
10017   %
10018   \gdefchar^^c0{\`A}
10019   \gdefchar^^c1{\'A}
10020   \gdefchar^^c2{\^A}
10021   \gdefchar^^c3{\~A}
10022   \gdefchar^^c4{\"A}
10023   \gdefchar^^c5{\ringaccent A}
10024   \gdefchar^^c6{\AE}
10025   \gdefchar^^c7{\cedilla C}
10026   \gdefchar^^c8{\`E}
10027   \gdefchar^^c9{\'E}
10028   \gdefchar^^ca{\^E}
10029   \gdefchar^^cb{\"E}
10030   \gdefchar^^cc{\`I}
10031   \gdefchar^^cd{\'I}
10032   \gdefchar^^ce{\^I}
10033   \gdefchar^^cf{\"I}
10034   %
10035   \gdefchar^^d0{\DH}
10036   \gdefchar^^d1{\~N}
10037   \gdefchar^^d2{\`O}
10038   \gdefchar^^d3{\'O}
10039   \gdefchar^^d4{\^O}
10040   \gdefchar^^d5{\~O}
10041   \gdefchar^^d6{\"O}
10042   \gdefchar^^d7{$\times$}
10043   \gdefchar^^d8{\O}
10044   \gdefchar^^d9{\`U}
10045   \gdefchar^^da{\'U}
10046   \gdefchar^^db{\^U}
10047   \gdefchar^^dc{\"U}
10048   \gdefchar^^dd{\'Y}
10049   \gdefchar^^de{\TH}
10050   \gdefchar^^df{\ss}
10051   %
10052   \gdefchar^^e0{\`a}
10053   \gdefchar^^e1{\'a}
10054   \gdefchar^^e2{\^a}
10055   \gdefchar^^e3{\~a}
10056   \gdefchar^^e4{\"a}
10057   \gdefchar^^e5{\ringaccent a}
10058   \gdefchar^^e6{\ae}
10059   \gdefchar^^e7{\cedilla c}
10060   \gdefchar^^e8{\`e}
10061   \gdefchar^^e9{\'e}
10062   \gdefchar^^ea{\^e}
10063   \gdefchar^^eb{\"e}
10064   \gdefchar^^ec{\`{\dotless i}}
10065   \gdefchar^^ed{\'{\dotless i}}
10066   \gdefchar^^ee{\^{\dotless i}}
10067   \gdefchar^^ef{\"{\dotless i}}
10068   %
10069   \gdefchar^^f0{\dh}
10070   \gdefchar^^f1{\~n}
10071   \gdefchar^^f2{\`o}
10072   \gdefchar^^f3{\'o}
10073   \gdefchar^^f4{\^o}
10074   \gdefchar^^f5{\~o}
10075   \gdefchar^^f6{\"o}
10076   \gdefchar^^f7{$\div$}
10077   \gdefchar^^f8{\o}
10078   \gdefchar^^f9{\`u}
10079   \gdefchar^^fa{\'u}
10080   \gdefchar^^fb{\^u}
10081   \gdefchar^^fc{\"u}
10082   \gdefchar^^fd{\'y}
10083   \gdefchar^^fe{\th}
10084   \gdefchar^^ff{\"y}
10085 }
10086
10087 % Latin9 (ISO-8859-15) encoding character definitions.
10088 \def\latninechardefs{%
10089   % Encoding is almost identical to Latin1.
10090   \latonechardefs
10091   %
10092   \gdefchar^^a4{\euro}
10093   \gdefchar^^a6{\v S}
10094   \gdefchar^^a8{\v s}
10095   \gdefchar^^b4{\v Z}
10096   \gdefchar^^b8{\v z}
10097   \gdefchar^^bc{\OE}
10098   \gdefchar^^bd{\oe}
10099   \gdefchar^^be{\"Y}
10100 }
10101
10102 % Latin2 (ISO-8859-2) character definitions.
10103 \def\lattwochardefs{%
10104   \gdefchar^^a0{\tie}
10105   \gdefchar^^a1{\ogonek{A}}
10106   \gdefchar^^a2{\u{}}
10107   \gdefchar^^a3{\L}
10108   \gdefchar^^a4{\missingcharmsg{CURRENCY SIGN}}
10109   \gdefchar^^a5{\v L}
10110   \gdefchar^^a6{\'S}
10111   \gdefchar^^a7{\S}
10112   \gdefchar^^a8{\"{}}
10113   \gdefchar^^a9{\v S}
10114   \gdefchar^^aa{\cedilla S}
10115   \gdefchar^^ab{\v T}
10116   \gdefchar^^ac{\'Z}
10117   \gdefchar^^ad{\-}
10118   \gdefchar^^ae{\v Z}
10119   \gdefchar^^af{\dotaccent Z}
10120   %
10121   \gdefchar^^b0{\textdegree}
10122   \gdefchar^^b1{\ogonek{a}}
10123   \gdefchar^^b2{\ogonek{ }}
10124   \gdefchar^^b3{\l}
10125   \gdefchar^^b4{\'{}}
10126   \gdefchar^^b5{\v l}
10127   \gdefchar^^b6{\'s}
10128   \gdefchar^^b7{\v{}}
10129   \gdefchar^^b8{\cedilla\ }
10130   \gdefchar^^b9{\v s}
10131   \gdefchar^^ba{\cedilla s}
10132   \gdefchar^^bb{\v t}
10133   \gdefchar^^bc{\'z}
10134   \gdefchar^^bd{\H{}}
10135   \gdefchar^^be{\v z}
10136   \gdefchar^^bf{\dotaccent z}
10137   %
10138   \gdefchar^^c0{\'R}
10139   \gdefchar^^c1{\'A}
10140   \gdefchar^^c2{\^A}
10141   \gdefchar^^c3{\u A}
10142   \gdefchar^^c4{\"A}
10143   \gdefchar^^c5{\'L}
10144   \gdefchar^^c6{\'C}
10145   \gdefchar^^c7{\cedilla C}
10146   \gdefchar^^c8{\v C}
10147   \gdefchar^^c9{\'E}
10148   \gdefchar^^ca{\ogonek{E}}
10149   \gdefchar^^cb{\"E}
10150   \gdefchar^^cc{\v E}
10151   \gdefchar^^cd{\'I}
10152   \gdefchar^^ce{\^I}
10153   \gdefchar^^cf{\v D}
10154   %
10155   \gdefchar^^d0{\DH}
10156   \gdefchar^^d1{\'N}
10157   \gdefchar^^d2{\v N}
10158   \gdefchar^^d3{\'O}
10159   \gdefchar^^d4{\^O}
10160   \gdefchar^^d5{\H O}
10161   \gdefchar^^d6{\"O}
10162   \gdefchar^^d7{$\times$}
10163   \gdefchar^^d8{\v R}
10164   \gdefchar^^d9{\ringaccent U}
10165   \gdefchar^^da{\'U}
10166   \gdefchar^^db{\H U}
10167   \gdefchar^^dc{\"U}
10168   \gdefchar^^dd{\'Y}
10169   \gdefchar^^de{\cedilla T}
10170   \gdefchar^^df{\ss}
10171   %
10172   \gdefchar^^e0{\'r}
10173   \gdefchar^^e1{\'a}
10174   \gdefchar^^e2{\^a}
10175   \gdefchar^^e3{\u a}
10176   \gdefchar^^e4{\"a}
10177   \gdefchar^^e5{\'l}
10178   \gdefchar^^e6{\'c}
10179   \gdefchar^^e7{\cedilla c}
10180   \gdefchar^^e8{\v c}
10181   \gdefchar^^e9{\'e}
10182   \gdefchar^^ea{\ogonek{e}}
10183   \gdefchar^^eb{\"e}
10184   \gdefchar^^ec{\v e}
10185   \gdefchar^^ed{\'{\dotless{i}}}
10186   \gdefchar^^ee{\^{\dotless{i}}}
10187   \gdefchar^^ef{\v d}
10188   %
10189   \gdefchar^^f0{\dh}
10190   \gdefchar^^f1{\'n}
10191   \gdefchar^^f2{\v n}
10192   \gdefchar^^f3{\'o}
10193   \gdefchar^^f4{\^o}
10194   \gdefchar^^f5{\H o}
10195   \gdefchar^^f6{\"o}
10196   \gdefchar^^f7{$\div$}
10197   \gdefchar^^f8{\v r}
10198   \gdefchar^^f9{\ringaccent u}
10199   \gdefchar^^fa{\'u}
10200   \gdefchar^^fb{\H u}
10201   \gdefchar^^fc{\"u}
10202   \gdefchar^^fd{\'y}
10203   \gdefchar^^fe{\cedilla t}
10204   \gdefchar^^ff{\dotaccent{}}
10205 }
10206
10207 % UTF-8 character definitions.
10208 %
10209 % This code to support UTF-8 is based on LaTeX's utf8.def, with some
10210 % changes for Texinfo conventions.  It is included here under the GPL by
10211 % permission from Frank Mittelbach and the LaTeX team.
10212 %
10213 \newcount\countUTFx
10214 \newcount\countUTFy
10215 \newcount\countUTFz
10216
10217 \gdef\UTFviiiTwoOctets#1#2{\expandafter
10218    \UTFviiiDefined\csname u8:#1\string #2\endcsname}
10219 %
10220 \gdef\UTFviiiThreeOctets#1#2#3{\expandafter
10221    \UTFviiiDefined\csname u8:#1\string #2\string #3\endcsname}
10222 %
10223 \gdef\UTFviiiFourOctets#1#2#3#4{\expandafter
10224    \UTFviiiDefined\csname u8:#1\string #2\string #3\string #4\endcsname}
10225
10226 \gdef\UTFviiiDefined#1{%
10227   \ifx #1\relax
10228     \message{\linenumber Unicode char \string #1 not defined for Texinfo}%
10229   \else
10230     \expandafter #1%
10231   \fi
10232 }
10233
10234 % Give non-ASCII bytes the active definitions for processing UTF-8 sequences
10235 \begingroup
10236   \catcode`\~13
10237   \catcode`\$12
10238   \catcode`\"12
10239
10240   % Loop from \countUTFx to \countUTFy, performing \UTFviiiTmp
10241   % substituting ~ and $ with a character token of that value.
10242   \def\UTFviiiLoop{%
10243     \global\catcode\countUTFx\active
10244     \uccode`\~\countUTFx
10245     \uccode`\$\countUTFx
10246     \uppercase\expandafter{\UTFviiiTmp}%
10247     \advance\countUTFx by 1
10248     \ifnum\countUTFx < \countUTFy
10249       \expandafter\UTFviiiLoop
10250     \fi}
10251
10252   % For bytes other than the first in a UTF-8 sequence.  Not expected to
10253   % be expanded except when writing to auxiliary files.
10254   \countUTFx = "80
10255   \countUTFy = "C2
10256   \def\UTFviiiTmp{%
10257     \gdef~{%
10258         \ifpassthroughchars $\fi}}%
10259   \UTFviiiLoop
10260
10261   \countUTFx = "C2
10262   \countUTFy = "E0
10263   \def\UTFviiiTmp{%
10264     \gdef~{%
10265         \ifpassthroughchars $%
10266         \else\expandafter\UTFviiiTwoOctets\expandafter$\fi}}%
10267   \UTFviiiLoop
10268
10269   \countUTFx = "E0
10270   \countUTFy = "F0
10271   \def\UTFviiiTmp{%
10272     \gdef~{%
10273         \ifpassthroughchars $%
10274         \else\expandafter\UTFviiiThreeOctets\expandafter$\fi}}%
10275   \UTFviiiLoop
10276
10277   \countUTFx = "F0
10278   \countUTFy = "F4
10279   \def\UTFviiiTmp{%
10280     \gdef~{%
10281         \ifpassthroughchars $%
10282         \else\expandafter\UTFviiiFourOctets\expandafter$\fi
10283         }}%
10284   \UTFviiiLoop
10285 \endgroup
10286
10287 \def\globallet{\global\let} % save some \expandafter's below
10288
10289 % @U{xxxx} to produce U+xxxx, if we support it.
10290 \def\U#1{%
10291   \expandafter\ifx\csname uni:#1\endcsname \relax
10292     \iftxinativeunicodecapable
10293       % Any Unicode characters can be used by native Unicode.
10294       % However, if the font does not have the glyph, the letter will miss.
10295       \begingroup
10296         \uccode`\.="#1\relax
10297         \uppercase{.}
10298       \endgroup
10299     \else
10300       \errhelp = \EMsimple      
10301       \errmessage{Unicode character U+#1 not supported, sorry}%
10302     \fi
10303   \else
10304     \csname uni:#1\endcsname
10305   \fi
10306 }
10307
10308 % These macros are used here to construct the name of a control
10309 % sequence to be defined.
10310 \def\UTFviiiTwoOctetsName#1#2{%
10311   \csname u8:#1\string #2\endcsname}%
10312 \def\UTFviiiThreeOctetsName#1#2#3{%
10313   \csname u8:#1\string #2\string #3\endcsname}%
10314 \def\UTFviiiFourOctetsName#1#2#3#4{%
10315   \csname u8:#1\string #2\string #3\string #4\endcsname}%
10316
10317 % For UTF-8 byte sequence (TeX, e-TeX and pdfTeX)
10318 % Definition macro to replace the Unicode character
10319 % Definition macro that is used by @U command
10320 %
10321 \begingroup
10322   \catcode`\"=12
10323   \catcode`\<=12
10324   \catcode`\.=12
10325   \catcode`\,=12
10326   \catcode`\;=12
10327   \catcode`\!=12
10328   \catcode`\~=13
10329   \gdef\DeclareUnicodeCharacterUTFviii#1#2{%
10330     \countUTFz = "#1\relax
10331     \begingroup
10332       \parseXMLCharref
10333     
10334       % Give \u8:... its definition.  The sequence of seven \expandafter's
10335       % expands after the \gdef three times, e.g.
10336       %
10337       % 1.  \UTFviiTwoOctetsName B1 B2
10338       % 2.  \csname u8:B1 \string B2 \endcsname
10339       % 3.  \u8: B1 B2  (a single control sequence token)
10340       %
10341       \expandafter\expandafter
10342       \expandafter\expandafter
10343       \expandafter\expandafter
10344       \expandafter\gdef       \UTFviiiTmp{#2}%
10345       % 
10346       \expandafter\ifx\csname uni:#1\endcsname \relax \else
10347        \message{Internal error, already defined: #1}%
10348       \fi
10349       %
10350       % define an additional control sequence for this code point.
10351       \expandafter\globallet\csname uni:#1\endcsname \UTFviiiTmp
10352     \endgroup}
10353   %
10354   % Given the value in \countUTFz as a Unicode code point, set \UTFviiiTmp
10355   % to the corresponding UTF-8 sequence.
10356   \gdef\parseXMLCharref{%
10357     \ifnum\countUTFz < "A0\relax
10358       \errhelp = \EMsimple
10359       \errmessage{Cannot define Unicode char value < 00A0}%
10360     \else\ifnum\countUTFz < "800\relax
10361       \parseUTFviiiA,%
10362       \parseUTFviiiB C\UTFviiiTwoOctetsName.,%
10363     \else\ifnum\countUTFz < "10000\relax
10364       \parseUTFviiiA;%
10365       \parseUTFviiiA,%
10366       \parseUTFviiiB E\UTFviiiThreeOctetsName.{,;}%
10367     \else
10368       \parseUTFviiiA;%
10369       \parseUTFviiiA,%
10370       \parseUTFviiiA!%
10371       \parseUTFviiiB F\UTFviiiFourOctetsName.{!,;}%
10372     \fi\fi\fi
10373   }
10374
10375   % Extract a byte from the end of the UTF-8 representation of \countUTFx.
10376   % It must be a non-initial byte in the sequence.
10377   % Change \uccode of #1 for it to be used in \parseUTFviiiB as one
10378   % of the bytes.
10379   \gdef\parseUTFviiiA#1{%
10380     \countUTFx = \countUTFz
10381     \divide\countUTFz by 64
10382     \countUTFy = \countUTFz  % Save to be the future value of \countUTFz.
10383     \multiply\countUTFz by 64
10384     
10385     % \countUTFz is now \countUTFx with the last 5 bits cleared.  Subtract
10386     % in order to get the last five bits.
10387     \advance\countUTFx by -\countUTFz
10388
10389     % Convert this to the byte in the UTF-8 sequence.
10390     \advance\countUTFx by 128
10391     \uccode `#1\countUTFx
10392     \countUTFz = \countUTFy}
10393
10394   % Used to put a UTF-8 byte sequence into \UTFviiiTmp
10395   % #1 is the increment for \countUTFz to yield a the first byte of the UTF-8
10396   %    sequence.
10397   % #2 is one of the \UTFviii*OctetsName macros.
10398   % #3 is always a full stop (.)
10399   % #4 is a template for the other bytes in the sequence.  The values for these
10400   %    bytes is substituted in here with \uppercase using the \uccode's.
10401   \gdef\parseUTFviiiB#1#2#3#4{%
10402     \advance\countUTFz by "#10\relax
10403     \uccode `#3\countUTFz
10404     \uppercase{\gdef\UTFviiiTmp{#2#3#4}}}
10405 \endgroup
10406
10407 % For native Unicode (XeTeX and LuaTeX)
10408 % Definition macro that is set catcode other non global
10409 %
10410 \def\DeclareUnicodeCharacterNativeOther#1#2{%
10411   \catcode"#1=\other
10412 }
10413
10414 % https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_M
10415 % U+0000..U+007F = https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)
10416 % U+0080..U+00FF = https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)
10417 % U+0100..U+017F = https://en.wikipedia.org/wiki/Latin_Extended-A
10418 % U+0180..U+024F = https://en.wikipedia.org/wiki/Latin_Extended-B
10419
10420 % Many of our renditions are less than wonderful, and all the missing
10421 % characters are available somewhere.  Loading the necessary fonts
10422 % awaits user request.  We can't truly support Unicode without
10423 % reimplementing everything that's been done in LaTeX for many years,
10424 % plus probably using luatex or xetex, and who knows what else.
10425 % We won't be doing that here in this simple file.  But we can try to at
10426 % least make most of the characters not bomb out.
10427 %
10428 \def\unicodechardefs{%
10429   \DeclareUnicodeCharacter{00A0}{\tie}%
10430   \DeclareUnicodeCharacter{00A1}{\exclamdown}%
10431   \DeclareUnicodeCharacter{00A2}{{\tcfont \char162}}% 0242=cent
10432   \DeclareUnicodeCharacter{00A3}{\pounds}%
10433   \DeclareUnicodeCharacter{00A4}{{\tcfont \char164}}% 0244=currency
10434   \DeclareUnicodeCharacter{00A5}{{\tcfont \char165}}% 0245=yen
10435   \DeclareUnicodeCharacter{00A6}{{\tcfont \char166}}% 0246=brokenbar
10436   \DeclareUnicodeCharacter{00A7}{\S}%
10437   \DeclareUnicodeCharacter{00A8}{\"{ }}%
10438   \DeclareUnicodeCharacter{00A9}{\copyright}%
10439   \DeclareUnicodeCharacter{00AA}{\ordf}%
10440   \DeclareUnicodeCharacter{00AB}{\guillemetleft}%
10441   \DeclareUnicodeCharacter{00AC}{\ensuremath\lnot}%
10442   \DeclareUnicodeCharacter{00AD}{\-}%
10443   \DeclareUnicodeCharacter{00AE}{\registeredsymbol}%
10444   \DeclareUnicodeCharacter{00AF}{\={ }}%
10445   %
10446   \DeclareUnicodeCharacter{00B0}{\ringaccent{ }}%
10447   \DeclareUnicodeCharacter{00B1}{\ensuremath\pm}%
10448   \DeclareUnicodeCharacter{00B2}{$^2$}%
10449   \DeclareUnicodeCharacter{00B3}{$^3$}%
10450   \DeclareUnicodeCharacter{00B4}{\'{ }}%
10451   \DeclareUnicodeCharacter{00B5}{$\mu$}%
10452   \DeclareUnicodeCharacter{00B6}{\P}%
10453   \DeclareUnicodeCharacter{00B7}{\ensuremath\cdot}%
10454   \DeclareUnicodeCharacter{00B8}{\cedilla{ }}%
10455   \DeclareUnicodeCharacter{00B9}{$^1$}%
10456   \DeclareUnicodeCharacter{00BA}{\ordm}%
10457   \DeclareUnicodeCharacter{00BB}{\guillemetright}%
10458   \DeclareUnicodeCharacter{00BC}{$1\over4$}%
10459   \DeclareUnicodeCharacter{00BD}{$1\over2$}%
10460   \DeclareUnicodeCharacter{00BE}{$3\over4$}%
10461   \DeclareUnicodeCharacter{00BF}{\questiondown}%
10462   %
10463   \DeclareUnicodeCharacter{00C0}{\`A}%
10464   \DeclareUnicodeCharacter{00C1}{\'A}%
10465   \DeclareUnicodeCharacter{00C2}{\^A}%
10466   \DeclareUnicodeCharacter{00C3}{\~A}%
10467   \DeclareUnicodeCharacter{00C4}{\"A}%
10468   \DeclareUnicodeCharacter{00C5}{\AA}%
10469   \DeclareUnicodeCharacter{00C6}{\AE}%
10470   \DeclareUnicodeCharacter{00C7}{\cedilla{C}}%
10471   \DeclareUnicodeCharacter{00C8}{\`E}%
10472   \DeclareUnicodeCharacter{00C9}{\'E}%
10473   \DeclareUnicodeCharacter{00CA}{\^E}%
10474   \DeclareUnicodeCharacter{00CB}{\"E}%
10475   \DeclareUnicodeCharacter{00CC}{\`I}%
10476   \DeclareUnicodeCharacter{00CD}{\'I}%
10477   \DeclareUnicodeCharacter{00CE}{\^I}%
10478   \DeclareUnicodeCharacter{00CF}{\"I}%
10479   %
10480   \DeclareUnicodeCharacter{00D0}{\DH}%
10481   \DeclareUnicodeCharacter{00D1}{\~N}%
10482   \DeclareUnicodeCharacter{00D2}{\`O}%
10483   \DeclareUnicodeCharacter{00D3}{\'O}%
10484   \DeclareUnicodeCharacter{00D4}{\^O}%
10485   \DeclareUnicodeCharacter{00D5}{\~O}%
10486   \DeclareUnicodeCharacter{00D6}{\"O}%
10487   \DeclareUnicodeCharacter{00D7}{\ensuremath\times}%
10488   \DeclareUnicodeCharacter{00D8}{\O}%
10489   \DeclareUnicodeCharacter{00D9}{\`U}%
10490   \DeclareUnicodeCharacter{00DA}{\'U}%
10491   \DeclareUnicodeCharacter{00DB}{\^U}%
10492   \DeclareUnicodeCharacter{00DC}{\"U}%
10493   \DeclareUnicodeCharacter{00DD}{\'Y}%
10494   \DeclareUnicodeCharacter{00DE}{\TH}%
10495   \DeclareUnicodeCharacter{00DF}{\ss}%
10496   %
10497   \DeclareUnicodeCharacter{00E0}{\`a}%
10498   \DeclareUnicodeCharacter{00E1}{\'a}%
10499   \DeclareUnicodeCharacter{00E2}{\^a}%
10500   \DeclareUnicodeCharacter{00E3}{\~a}%
10501   \DeclareUnicodeCharacter{00E4}{\"a}%
10502   \DeclareUnicodeCharacter{00E5}{\aa}%
10503   \DeclareUnicodeCharacter{00E6}{\ae}%
10504   \DeclareUnicodeCharacter{00E7}{\cedilla{c}}%
10505   \DeclareUnicodeCharacter{00E8}{\`e}%
10506   \DeclareUnicodeCharacter{00E9}{\'e}%
10507   \DeclareUnicodeCharacter{00EA}{\^e}%
10508   \DeclareUnicodeCharacter{00EB}{\"e}%
10509   \DeclareUnicodeCharacter{00EC}{\`{\dotless{i}}}%
10510   \DeclareUnicodeCharacter{00ED}{\'{\dotless{i}}}%
10511   \DeclareUnicodeCharacter{00EE}{\^{\dotless{i}}}%
10512   \DeclareUnicodeCharacter{00EF}{\"{\dotless{i}}}%
10513   %
10514   \DeclareUnicodeCharacter{00F0}{\dh}%
10515   \DeclareUnicodeCharacter{00F1}{\~n}%
10516   \DeclareUnicodeCharacter{00F2}{\`o}%
10517   \DeclareUnicodeCharacter{00F3}{\'o}%
10518   \DeclareUnicodeCharacter{00F4}{\^o}%
10519   \DeclareUnicodeCharacter{00F5}{\~o}%
10520   \DeclareUnicodeCharacter{00F6}{\"o}%
10521   \DeclareUnicodeCharacter{00F7}{\ensuremath\div}%
10522   \DeclareUnicodeCharacter{00F8}{\o}%
10523   \DeclareUnicodeCharacter{00F9}{\`u}%
10524   \DeclareUnicodeCharacter{00FA}{\'u}%
10525   \DeclareUnicodeCharacter{00FB}{\^u}%
10526   \DeclareUnicodeCharacter{00FC}{\"u}%
10527   \DeclareUnicodeCharacter{00FD}{\'y}%
10528   \DeclareUnicodeCharacter{00FE}{\th}%
10529   \DeclareUnicodeCharacter{00FF}{\"y}%
10530   %
10531   \DeclareUnicodeCharacter{0100}{\=A}%
10532   \DeclareUnicodeCharacter{0101}{\=a}%
10533   \DeclareUnicodeCharacter{0102}{\u{A}}%
10534   \DeclareUnicodeCharacter{0103}{\u{a}}%
10535   \DeclareUnicodeCharacter{0104}{\ogonek{A}}%
10536   \DeclareUnicodeCharacter{0105}{\ogonek{a}}%
10537   \DeclareUnicodeCharacter{0106}{\'C}%
10538   \DeclareUnicodeCharacter{0107}{\'c}%
10539   \DeclareUnicodeCharacter{0108}{\^C}%
10540   \DeclareUnicodeCharacter{0109}{\^c}%
10541   \DeclareUnicodeCharacter{010A}{\dotaccent{C}}%
10542   \DeclareUnicodeCharacter{010B}{\dotaccent{c}}%
10543   \DeclareUnicodeCharacter{010C}{\v{C}}%
10544   \DeclareUnicodeCharacter{010D}{\v{c}}%
10545   \DeclareUnicodeCharacter{010E}{\v{D}}%
10546   \DeclareUnicodeCharacter{010F}{d'}%
10547   %
10548   \DeclareUnicodeCharacter{0110}{\DH}%
10549   \DeclareUnicodeCharacter{0111}{\dh}%
10550   \DeclareUnicodeCharacter{0112}{\=E}%
10551   \DeclareUnicodeCharacter{0113}{\=e}%
10552   \DeclareUnicodeCharacter{0114}{\u{E}}%
10553   \DeclareUnicodeCharacter{0115}{\u{e}}%
10554   \DeclareUnicodeCharacter{0116}{\dotaccent{E}}%
10555   \DeclareUnicodeCharacter{0117}{\dotaccent{e}}%
10556   \DeclareUnicodeCharacter{0118}{\ogonek{E}}%
10557   \DeclareUnicodeCharacter{0119}{\ogonek{e}}%
10558   \DeclareUnicodeCharacter{011A}{\v{E}}%
10559   \DeclareUnicodeCharacter{011B}{\v{e}}%
10560   \DeclareUnicodeCharacter{011C}{\^G}%
10561   \DeclareUnicodeCharacter{011D}{\^g}%
10562   \DeclareUnicodeCharacter{011E}{\u{G}}%
10563   \DeclareUnicodeCharacter{011F}{\u{g}}%
10564   %
10565   \DeclareUnicodeCharacter{0120}{\dotaccent{G}}%
10566   \DeclareUnicodeCharacter{0121}{\dotaccent{g}}%
10567   \DeclareUnicodeCharacter{0122}{\cedilla{G}}%
10568   \DeclareUnicodeCharacter{0123}{\cedilla{g}}%
10569   \DeclareUnicodeCharacter{0124}{\^H}%
10570   \DeclareUnicodeCharacter{0125}{\^h}%
10571   \DeclareUnicodeCharacter{0126}{\missingcharmsg{H WITH STROKE}}%
10572   \DeclareUnicodeCharacter{0127}{\missingcharmsg{h WITH STROKE}}%
10573   \DeclareUnicodeCharacter{0128}{\~I}%
10574   \DeclareUnicodeCharacter{0129}{\~{\dotless{i}}}%
10575   \DeclareUnicodeCharacter{012A}{\=I}%
10576   \DeclareUnicodeCharacter{012B}{\={\dotless{i}}}%
10577   \DeclareUnicodeCharacter{012C}{\u{I}}%
10578   \DeclareUnicodeCharacter{012D}{\u{\dotless{i}}}%
10579   \DeclareUnicodeCharacter{012E}{\ogonek{I}}%
10580   \DeclareUnicodeCharacter{012F}{\ogonek{i}}%
10581   %
10582   \DeclareUnicodeCharacter{0130}{\dotaccent{I}}%
10583   \DeclareUnicodeCharacter{0131}{\dotless{i}}%
10584   \DeclareUnicodeCharacter{0132}{IJ}%
10585   \DeclareUnicodeCharacter{0133}{ij}%
10586   \DeclareUnicodeCharacter{0134}{\^J}%
10587   \DeclareUnicodeCharacter{0135}{\^{\dotless{j}}}%
10588   \DeclareUnicodeCharacter{0136}{\cedilla{K}}%
10589   \DeclareUnicodeCharacter{0137}{\cedilla{k}}%
10590   \DeclareUnicodeCharacter{0138}{\ensuremath\kappa}%
10591   \DeclareUnicodeCharacter{0139}{\'L}%
10592   \DeclareUnicodeCharacter{013A}{\'l}%
10593   \DeclareUnicodeCharacter{013B}{\cedilla{L}}%
10594   \DeclareUnicodeCharacter{013C}{\cedilla{l}}%
10595   \DeclareUnicodeCharacter{013D}{L'}% should kern
10596   \DeclareUnicodeCharacter{013E}{l'}% should kern
10597   \DeclareUnicodeCharacter{013F}{L\U{00B7}}%
10598   %
10599   \DeclareUnicodeCharacter{0140}{l\U{00B7}}%
10600   \DeclareUnicodeCharacter{0141}{\L}%
10601   \DeclareUnicodeCharacter{0142}{\l}%
10602   \DeclareUnicodeCharacter{0143}{\'N}%
10603   \DeclareUnicodeCharacter{0144}{\'n}%
10604   \DeclareUnicodeCharacter{0145}{\cedilla{N}}%
10605   \DeclareUnicodeCharacter{0146}{\cedilla{n}}%
10606   \DeclareUnicodeCharacter{0147}{\v{N}}%
10607   \DeclareUnicodeCharacter{0148}{\v{n}}%
10608   \DeclareUnicodeCharacter{0149}{'n}%
10609   \DeclareUnicodeCharacter{014A}{\missingcharmsg{ENG}}%
10610   \DeclareUnicodeCharacter{014B}{\missingcharmsg{eng}}%
10611   \DeclareUnicodeCharacter{014C}{\=O}%
10612   \DeclareUnicodeCharacter{014D}{\=o}%
10613   \DeclareUnicodeCharacter{014E}{\u{O}}%
10614   \DeclareUnicodeCharacter{014F}{\u{o}}%
10615   %
10616   \DeclareUnicodeCharacter{0150}{\H{O}}%
10617   \DeclareUnicodeCharacter{0151}{\H{o}}%
10618   \DeclareUnicodeCharacter{0152}{\OE}%
10619   \DeclareUnicodeCharacter{0153}{\oe}%
10620   \DeclareUnicodeCharacter{0154}{\'R}%
10621   \DeclareUnicodeCharacter{0155}{\'r}%
10622   \DeclareUnicodeCharacter{0156}{\cedilla{R}}%
10623   \DeclareUnicodeCharacter{0157}{\cedilla{r}}%
10624   \DeclareUnicodeCharacter{0158}{\v{R}}%
10625   \DeclareUnicodeCharacter{0159}{\v{r}}%
10626   \DeclareUnicodeCharacter{015A}{\'S}%
10627   \DeclareUnicodeCharacter{015B}{\'s}%
10628   \DeclareUnicodeCharacter{015C}{\^S}%
10629   \DeclareUnicodeCharacter{015D}{\^s}%
10630   \DeclareUnicodeCharacter{015E}{\cedilla{S}}%
10631   \DeclareUnicodeCharacter{015F}{\cedilla{s}}%
10632   %
10633   \DeclareUnicodeCharacter{0160}{\v{S}}%
10634   \DeclareUnicodeCharacter{0161}{\v{s}}%
10635   \DeclareUnicodeCharacter{0162}{\cedilla{T}}%
10636   \DeclareUnicodeCharacter{0163}{\cedilla{t}}%
10637   \DeclareUnicodeCharacter{0164}{\v{T}}%
10638   \DeclareUnicodeCharacter{0165}{\v{t}}%
10639   \DeclareUnicodeCharacter{0166}{\missingcharmsg{H WITH STROKE}}%
10640   \DeclareUnicodeCharacter{0167}{\missingcharmsg{h WITH STROKE}}%
10641   \DeclareUnicodeCharacter{0168}{\~U}%
10642   \DeclareUnicodeCharacter{0169}{\~u}%
10643   \DeclareUnicodeCharacter{016A}{\=U}%
10644   \DeclareUnicodeCharacter{016B}{\=u}%
10645   \DeclareUnicodeCharacter{016C}{\u{U}}%
10646   \DeclareUnicodeCharacter{016D}{\u{u}}%
10647   \DeclareUnicodeCharacter{016E}{\ringaccent{U}}%
10648   \DeclareUnicodeCharacter{016F}{\ringaccent{u}}%
10649   %
10650   \DeclareUnicodeCharacter{0170}{\H{U}}%
10651   \DeclareUnicodeCharacter{0171}{\H{u}}%
10652   \DeclareUnicodeCharacter{0172}{\ogonek{U}}%
10653   \DeclareUnicodeCharacter{0173}{\ogonek{u}}%
10654   \DeclareUnicodeCharacter{0174}{\^W}%
10655   \DeclareUnicodeCharacter{0175}{\^w}%
10656   \DeclareUnicodeCharacter{0176}{\^Y}%
10657   \DeclareUnicodeCharacter{0177}{\^y}%
10658   \DeclareUnicodeCharacter{0178}{\"Y}%
10659   \DeclareUnicodeCharacter{0179}{\'Z}%
10660   \DeclareUnicodeCharacter{017A}{\'z}%
10661   \DeclareUnicodeCharacter{017B}{\dotaccent{Z}}%
10662   \DeclareUnicodeCharacter{017C}{\dotaccent{z}}%
10663   \DeclareUnicodeCharacter{017D}{\v{Z}}%
10664   \DeclareUnicodeCharacter{017E}{\v{z}}%
10665   \DeclareUnicodeCharacter{017F}{\missingcharmsg{LONG S}}%
10666   %
10667   \DeclareUnicodeCharacter{01C4}{D\v{Z}}%
10668   \DeclareUnicodeCharacter{01C5}{D\v{z}}%
10669   \DeclareUnicodeCharacter{01C6}{d\v{z}}%
10670   \DeclareUnicodeCharacter{01C7}{LJ}%
10671   \DeclareUnicodeCharacter{01C8}{Lj}%
10672   \DeclareUnicodeCharacter{01C9}{lj}%
10673   \DeclareUnicodeCharacter{01CA}{NJ}%
10674   \DeclareUnicodeCharacter{01CB}{Nj}%
10675   \DeclareUnicodeCharacter{01CC}{nj}%
10676   \DeclareUnicodeCharacter{01CD}{\v{A}}%
10677   \DeclareUnicodeCharacter{01CE}{\v{a}}%
10678   \DeclareUnicodeCharacter{01CF}{\v{I}}%
10679   %
10680   \DeclareUnicodeCharacter{01D0}{\v{\dotless{i}}}%
10681   \DeclareUnicodeCharacter{01D1}{\v{O}}%
10682   \DeclareUnicodeCharacter{01D2}{\v{o}}%
10683   \DeclareUnicodeCharacter{01D3}{\v{U}}%
10684   \DeclareUnicodeCharacter{01D4}{\v{u}}%
10685   %
10686   \DeclareUnicodeCharacter{01E2}{\={\AE}}%
10687   \DeclareUnicodeCharacter{01E3}{\={\ae}}%
10688   \DeclareUnicodeCharacter{01E6}{\v{G}}%
10689   \DeclareUnicodeCharacter{01E7}{\v{g}}%
10690   \DeclareUnicodeCharacter{01E8}{\v{K}}%
10691   \DeclareUnicodeCharacter{01E9}{\v{k}}%
10692   %
10693   \DeclareUnicodeCharacter{01F0}{\v{\dotless{j}}}%
10694   \DeclareUnicodeCharacter{01F1}{DZ}%
10695   \DeclareUnicodeCharacter{01F2}{Dz}%
10696   \DeclareUnicodeCharacter{01F3}{dz}%
10697   \DeclareUnicodeCharacter{01F4}{\'G}%
10698   \DeclareUnicodeCharacter{01F5}{\'g}%
10699   \DeclareUnicodeCharacter{01F8}{\`N}%
10700   \DeclareUnicodeCharacter{01F9}{\`n}%
10701   \DeclareUnicodeCharacter{01FC}{\'{\AE}}%
10702   \DeclareUnicodeCharacter{01FD}{\'{\ae}}%
10703   \DeclareUnicodeCharacter{01FE}{\'{\O}}%
10704   \DeclareUnicodeCharacter{01FF}{\'{\o}}%
10705   %
10706   \DeclareUnicodeCharacter{021E}{\v{H}}%
10707   \DeclareUnicodeCharacter{021F}{\v{h}}%
10708   %
10709   \DeclareUnicodeCharacter{0226}{\dotaccent{A}}%
10710   \DeclareUnicodeCharacter{0227}{\dotaccent{a}}%
10711   \DeclareUnicodeCharacter{0228}{\cedilla{E}}%
10712   \DeclareUnicodeCharacter{0229}{\cedilla{e}}%
10713   \DeclareUnicodeCharacter{022E}{\dotaccent{O}}%
10714   \DeclareUnicodeCharacter{022F}{\dotaccent{o}}%
10715   %
10716   \DeclareUnicodeCharacter{0232}{\=Y}%
10717   \DeclareUnicodeCharacter{0233}{\=y}%
10718   \DeclareUnicodeCharacter{0237}{\dotless{j}}%
10719   %
10720   \DeclareUnicodeCharacter{02DB}{\ogonek{ }}%
10721   %
10722   % Greek letters upper case
10723   \DeclareUnicodeCharacter{0391}{{\it A}}%
10724   \DeclareUnicodeCharacter{0392}{{\it B}}%
10725   \DeclareUnicodeCharacter{0393}{\ensuremath{\mit\Gamma}}%
10726   \DeclareUnicodeCharacter{0394}{\ensuremath{\mit\Delta}}%
10727   \DeclareUnicodeCharacter{0395}{{\it E}}%
10728   \DeclareUnicodeCharacter{0396}{{\it Z}}%
10729   \DeclareUnicodeCharacter{0397}{{\it H}}%
10730   \DeclareUnicodeCharacter{0398}{\ensuremath{\mit\Theta}}%
10731   \DeclareUnicodeCharacter{0399}{{\it I}}%
10732   \DeclareUnicodeCharacter{039A}{{\it K}}%
10733   \DeclareUnicodeCharacter{039B}{\ensuremath{\mit\Lambda}}%
10734   \DeclareUnicodeCharacter{039C}{{\it M}}%
10735   \DeclareUnicodeCharacter{039D}{{\it N}}%
10736   \DeclareUnicodeCharacter{039E}{\ensuremath{\mit\Xi}}%
10737   \DeclareUnicodeCharacter{039F}{{\it O}}%
10738   \DeclareUnicodeCharacter{03A0}{\ensuremath{\mit\Pi}}%
10739   \DeclareUnicodeCharacter{03A1}{{\it P}}%
10740   %\DeclareUnicodeCharacter{03A2}{} % none - corresponds to final sigma
10741   \DeclareUnicodeCharacter{03A3}{\ensuremath{\mit\Sigma}}%
10742   \DeclareUnicodeCharacter{03A4}{{\it T}}%
10743   \DeclareUnicodeCharacter{03A5}{\ensuremath{\mit\Upsilon}}%
10744   \DeclareUnicodeCharacter{03A6}{\ensuremath{\mit\Phi}}%
10745   \DeclareUnicodeCharacter{03A7}{{\it X}}%
10746   \DeclareUnicodeCharacter{03A8}{\ensuremath{\mit\Psi}}%
10747   \DeclareUnicodeCharacter{03A9}{\ensuremath{\mit\Omega}}%
10748   %
10749   % Vowels with accents
10750   \DeclareUnicodeCharacter{0390}{\ensuremath{\ddot{\acute\iota}}}%
10751   \DeclareUnicodeCharacter{03AC}{\ensuremath{\acute\alpha}}%
10752   \DeclareUnicodeCharacter{03AD}{\ensuremath{\acute\epsilon}}%
10753   \DeclareUnicodeCharacter{03AE}{\ensuremath{\acute\eta}}%
10754   \DeclareUnicodeCharacter{03AF}{\ensuremath{\acute\iota}}%
10755   \DeclareUnicodeCharacter{03B0}{\ensuremath{\acute{\ddot\upsilon}}}%
10756   %
10757   % Standalone accent
10758   \DeclareUnicodeCharacter{0384}{\ensuremath{\acute{\ }}}%
10759   %
10760   % Greek letters lower case
10761   \DeclareUnicodeCharacter{03B1}{\ensuremath\alpha}%
10762   \DeclareUnicodeCharacter{03B2}{\ensuremath\beta}%
10763   \DeclareUnicodeCharacter{03B3}{\ensuremath\gamma}%
10764   \DeclareUnicodeCharacter{03B4}{\ensuremath\delta}%
10765   \DeclareUnicodeCharacter{03B5}{\ensuremath\epsilon}%
10766   \DeclareUnicodeCharacter{03B6}{\ensuremath\zeta}%
10767   \DeclareUnicodeCharacter{03B7}{\ensuremath\eta}%
10768   \DeclareUnicodeCharacter{03B8}{\ensuremath\theta}%
10769   \DeclareUnicodeCharacter{03B9}{\ensuremath\iota}%
10770   \DeclareUnicodeCharacter{03BA}{\ensuremath\kappa}%
10771   \DeclareUnicodeCharacter{03BB}{\ensuremath\lambda}%
10772   \DeclareUnicodeCharacter{03BC}{\ensuremath\mu}%
10773   \DeclareUnicodeCharacter{03BD}{\ensuremath\nu}%
10774   \DeclareUnicodeCharacter{03BE}{\ensuremath\xi}%
10775   \DeclareUnicodeCharacter{03BF}{{\it o}}% omicron
10776   \DeclareUnicodeCharacter{03C0}{\ensuremath\pi}%
10777   \DeclareUnicodeCharacter{03C1}{\ensuremath\rho}%
10778   \DeclareUnicodeCharacter{03C2}{\ensuremath\varsigma}%
10779   \DeclareUnicodeCharacter{03C3}{\ensuremath\sigma}%
10780   \DeclareUnicodeCharacter{03C4}{\ensuremath\tau}%
10781   \DeclareUnicodeCharacter{03C5}{\ensuremath\upsilon}%
10782   \DeclareUnicodeCharacter{03C6}{\ensuremath\phi}%
10783   \DeclareUnicodeCharacter{03C7}{\ensuremath\chi}%
10784   \DeclareUnicodeCharacter{03C8}{\ensuremath\psi}%
10785   \DeclareUnicodeCharacter{03C9}{\ensuremath\omega}%
10786   %
10787   % More Greek vowels with accents
10788   \DeclareUnicodeCharacter{03CA}{\ensuremath{\ddot\iota}}%
10789   \DeclareUnicodeCharacter{03CB}{\ensuremath{\ddot\upsilon}}%
10790   \DeclareUnicodeCharacter{03CC}{\ensuremath{\acute o}}%
10791   \DeclareUnicodeCharacter{03CD}{\ensuremath{\acute\upsilon}}%
10792   \DeclareUnicodeCharacter{03CE}{\ensuremath{\acute\omega}}%
10793   %
10794   % Variant Greek letters
10795   \DeclareUnicodeCharacter{03D1}{\ensuremath\vartheta}%
10796   \DeclareUnicodeCharacter{03D6}{\ensuremath\varpi}%
10797   \DeclareUnicodeCharacter{03F1}{\ensuremath\varrho}%
10798   %
10799   \DeclareUnicodeCharacter{1E02}{\dotaccent{B}}%
10800   \DeclareUnicodeCharacter{1E03}{\dotaccent{b}}%
10801   \DeclareUnicodeCharacter{1E04}{\udotaccent{B}}%
10802   \DeclareUnicodeCharacter{1E05}{\udotaccent{b}}%
10803   \DeclareUnicodeCharacter{1E06}{\ubaraccent{B}}%
10804   \DeclareUnicodeCharacter{1E07}{\ubaraccent{b}}%
10805   \DeclareUnicodeCharacter{1E0A}{\dotaccent{D}}%
10806   \DeclareUnicodeCharacter{1E0B}{\dotaccent{d}}%
10807   \DeclareUnicodeCharacter{1E0C}{\udotaccent{D}}%
10808   \DeclareUnicodeCharacter{1E0D}{\udotaccent{d}}%
10809   \DeclareUnicodeCharacter{1E0E}{\ubaraccent{D}}%
10810   \DeclareUnicodeCharacter{1E0F}{\ubaraccent{d}}%
10811   %
10812   \DeclareUnicodeCharacter{1E1E}{\dotaccent{F}}%
10813   \DeclareUnicodeCharacter{1E1F}{\dotaccent{f}}%
10814   %
10815   \DeclareUnicodeCharacter{1E20}{\=G}%
10816   \DeclareUnicodeCharacter{1E21}{\=g}%
10817   \DeclareUnicodeCharacter{1E22}{\dotaccent{H}}%
10818   \DeclareUnicodeCharacter{1E23}{\dotaccent{h}}%
10819   \DeclareUnicodeCharacter{1E24}{\udotaccent{H}}%
10820   \DeclareUnicodeCharacter{1E25}{\udotaccent{h}}%
10821   \DeclareUnicodeCharacter{1E26}{\"H}%
10822   \DeclareUnicodeCharacter{1E27}{\"h}%
10823   %
10824   \DeclareUnicodeCharacter{1E30}{\'K}%
10825   \DeclareUnicodeCharacter{1E31}{\'k}%
10826   \DeclareUnicodeCharacter{1E32}{\udotaccent{K}}%
10827   \DeclareUnicodeCharacter{1E33}{\udotaccent{k}}%
10828   \DeclareUnicodeCharacter{1E34}{\ubaraccent{K}}%
10829   \DeclareUnicodeCharacter{1E35}{\ubaraccent{k}}%
10830   \DeclareUnicodeCharacter{1E36}{\udotaccent{L}}%
10831   \DeclareUnicodeCharacter{1E37}{\udotaccent{l}}%
10832   \DeclareUnicodeCharacter{1E3A}{\ubaraccent{L}}%
10833   \DeclareUnicodeCharacter{1E3B}{\ubaraccent{l}}%
10834   \DeclareUnicodeCharacter{1E3E}{\'M}%
10835   \DeclareUnicodeCharacter{1E3F}{\'m}%
10836   %
10837   \DeclareUnicodeCharacter{1E40}{\dotaccent{M}}%
10838   \DeclareUnicodeCharacter{1E41}{\dotaccent{m}}%
10839   \DeclareUnicodeCharacter{1E42}{\udotaccent{M}}%
10840   \DeclareUnicodeCharacter{1E43}{\udotaccent{m}}%
10841   \DeclareUnicodeCharacter{1E44}{\dotaccent{N}}%
10842   \DeclareUnicodeCharacter{1E45}{\dotaccent{n}}%
10843   \DeclareUnicodeCharacter{1E46}{\udotaccent{N}}%
10844   \DeclareUnicodeCharacter{1E47}{\udotaccent{n}}%
10845   \DeclareUnicodeCharacter{1E48}{\ubaraccent{N}}%
10846   \DeclareUnicodeCharacter{1E49}{\ubaraccent{n}}%
10847   %
10848   \DeclareUnicodeCharacter{1E54}{\'P}%
10849   \DeclareUnicodeCharacter{1E55}{\'p}%
10850   \DeclareUnicodeCharacter{1E56}{\dotaccent{P}}%
10851   \DeclareUnicodeCharacter{1E57}{\dotaccent{p}}%
10852   \DeclareUnicodeCharacter{1E58}{\dotaccent{R}}%
10853   \DeclareUnicodeCharacter{1E59}{\dotaccent{r}}%
10854   \DeclareUnicodeCharacter{1E5A}{\udotaccent{R}}%
10855   \DeclareUnicodeCharacter{1E5B}{\udotaccent{r}}%
10856   \DeclareUnicodeCharacter{1E5E}{\ubaraccent{R}}%
10857   \DeclareUnicodeCharacter{1E5F}{\ubaraccent{r}}%
10858   %
10859   \DeclareUnicodeCharacter{1E60}{\dotaccent{S}}%
10860   \DeclareUnicodeCharacter{1E61}{\dotaccent{s}}%
10861   \DeclareUnicodeCharacter{1E62}{\udotaccent{S}}%
10862   \DeclareUnicodeCharacter{1E63}{\udotaccent{s}}%
10863   \DeclareUnicodeCharacter{1E6A}{\dotaccent{T}}%
10864   \DeclareUnicodeCharacter{1E6B}{\dotaccent{t}}%
10865   \DeclareUnicodeCharacter{1E6C}{\udotaccent{T}}%
10866   \DeclareUnicodeCharacter{1E6D}{\udotaccent{t}}%
10867   \DeclareUnicodeCharacter{1E6E}{\ubaraccent{T}}%
10868   \DeclareUnicodeCharacter{1E6F}{\ubaraccent{t}}%
10869   %
10870   \DeclareUnicodeCharacter{1E7C}{\~V}%
10871   \DeclareUnicodeCharacter{1E7D}{\~v}%
10872   \DeclareUnicodeCharacter{1E7E}{\udotaccent{V}}%
10873   \DeclareUnicodeCharacter{1E7F}{\udotaccent{v}}%
10874   %
10875   \DeclareUnicodeCharacter{1E80}{\`W}%
10876   \DeclareUnicodeCharacter{1E81}{\`w}%
10877   \DeclareUnicodeCharacter{1E82}{\'W}%
10878   \DeclareUnicodeCharacter{1E83}{\'w}%
10879   \DeclareUnicodeCharacter{1E84}{\"W}%
10880   \DeclareUnicodeCharacter{1E85}{\"w}%
10881   \DeclareUnicodeCharacter{1E86}{\dotaccent{W}}%
10882   \DeclareUnicodeCharacter{1E87}{\dotaccent{w}}%
10883   \DeclareUnicodeCharacter{1E88}{\udotaccent{W}}%
10884   \DeclareUnicodeCharacter{1E89}{\udotaccent{w}}%
10885   \DeclareUnicodeCharacter{1E8A}{\dotaccent{X}}%
10886   \DeclareUnicodeCharacter{1E8B}{\dotaccent{x}}%
10887   \DeclareUnicodeCharacter{1E8C}{\"X}%
10888   \DeclareUnicodeCharacter{1E8D}{\"x}%
10889   \DeclareUnicodeCharacter{1E8E}{\dotaccent{Y}}%
10890   \DeclareUnicodeCharacter{1E8F}{\dotaccent{y}}%
10891   %
10892   \DeclareUnicodeCharacter{1E90}{\^Z}%
10893   \DeclareUnicodeCharacter{1E91}{\^z}%
10894   \DeclareUnicodeCharacter{1E92}{\udotaccent{Z}}%
10895   \DeclareUnicodeCharacter{1E93}{\udotaccent{z}}%
10896   \DeclareUnicodeCharacter{1E94}{\ubaraccent{Z}}%
10897   \DeclareUnicodeCharacter{1E95}{\ubaraccent{z}}%
10898   \DeclareUnicodeCharacter{1E96}{\ubaraccent{h}}%
10899   \DeclareUnicodeCharacter{1E97}{\"t}%
10900   \DeclareUnicodeCharacter{1E98}{\ringaccent{w}}%
10901   \DeclareUnicodeCharacter{1E99}{\ringaccent{y}}%
10902   %
10903   \DeclareUnicodeCharacter{1EA0}{\udotaccent{A}}%
10904   \DeclareUnicodeCharacter{1EA1}{\udotaccent{a}}%
10905   %
10906   \DeclareUnicodeCharacter{1EB8}{\udotaccent{E}}%
10907   \DeclareUnicodeCharacter{1EB9}{\udotaccent{e}}%
10908   \DeclareUnicodeCharacter{1EBC}{\~E}%
10909   \DeclareUnicodeCharacter{1EBD}{\~e}%
10910   %
10911   \DeclareUnicodeCharacter{1ECA}{\udotaccent{I}}%
10912   \DeclareUnicodeCharacter{1ECB}{\udotaccent{i}}%
10913   \DeclareUnicodeCharacter{1ECC}{\udotaccent{O}}%
10914   \DeclareUnicodeCharacter{1ECD}{\udotaccent{o}}%
10915   %
10916   \DeclareUnicodeCharacter{1EE4}{\udotaccent{U}}%
10917   \DeclareUnicodeCharacter{1EE5}{\udotaccent{u}}%
10918   %
10919   \DeclareUnicodeCharacter{1EF2}{\`Y}%
10920   \DeclareUnicodeCharacter{1EF3}{\`y}%
10921   \DeclareUnicodeCharacter{1EF4}{\udotaccent{Y}}%
10922   %
10923   \DeclareUnicodeCharacter{1EF8}{\~Y}%
10924   \DeclareUnicodeCharacter{1EF9}{\~y}%
10925   %
10926   % Punctuation
10927   \DeclareUnicodeCharacter{2013}{--}%
10928   \DeclareUnicodeCharacter{2014}{---}%
10929   \DeclareUnicodeCharacter{2018}{\quoteleft}%
10930   \DeclareUnicodeCharacter{2019}{\quoteright}%
10931   \DeclareUnicodeCharacter{201A}{\quotesinglbase}%
10932   \DeclareUnicodeCharacter{201C}{\quotedblleft}%
10933   \DeclareUnicodeCharacter{201D}{\quotedblright}%
10934   \DeclareUnicodeCharacter{201E}{\quotedblbase}%
10935   \DeclareUnicodeCharacter{2020}{\ensuremath\dagger}%
10936   \DeclareUnicodeCharacter{2021}{\ensuremath\ddagger}%
10937   \DeclareUnicodeCharacter{2022}{\bullet}%
10938   \DeclareUnicodeCharacter{202F}{\thinspace}%
10939   \DeclareUnicodeCharacter{2026}{\dots}%
10940   \DeclareUnicodeCharacter{2039}{\guilsinglleft}%
10941   \DeclareUnicodeCharacter{203A}{\guilsinglright}%
10942   %
10943   \DeclareUnicodeCharacter{20AC}{\euro}%
10944   %
10945   \DeclareUnicodeCharacter{2192}{\expansion}%
10946   \DeclareUnicodeCharacter{21D2}{\result}%
10947   %
10948   % Mathematical symbols
10949   \DeclareUnicodeCharacter{2200}{\ensuremath\forall}%
10950   \DeclareUnicodeCharacter{2203}{\ensuremath\exists}%
10951   \DeclareUnicodeCharacter{2208}{\ensuremath\in}%
10952   \DeclareUnicodeCharacter{2212}{\minus}%
10953   \DeclareUnicodeCharacter{2217}{\ast}%
10954   \DeclareUnicodeCharacter{221E}{\ensuremath\infty}%
10955   \DeclareUnicodeCharacter{2225}{\ensuremath\parallel}%
10956   \DeclareUnicodeCharacter{2227}{\ensuremath\wedge}%
10957   \DeclareUnicodeCharacter{2229}{\ensuremath\cap}%
10958   \DeclareUnicodeCharacter{2261}{\equiv}%
10959   \DeclareUnicodeCharacter{2264}{\ensuremath\leq}%
10960   \DeclareUnicodeCharacter{2265}{\ensuremath\geq}%
10961   \DeclareUnicodeCharacter{2282}{\ensuremath\subset}%
10962   \DeclareUnicodeCharacter{2287}{\ensuremath\supseteq}%
10963   %
10964   \DeclareUnicodeCharacter{2016}{\ensuremath\Vert}%
10965   \DeclareUnicodeCharacter{2032}{\ensuremath\prime}%
10966   \DeclareUnicodeCharacter{210F}{\ensuremath\hbar}%
10967   \DeclareUnicodeCharacter{2111}{\ensuremath\Im}%
10968   \DeclareUnicodeCharacter{2113}{\ensuremath\ell}%
10969   \DeclareUnicodeCharacter{2118}{\ensuremath\wp}%
10970   \DeclareUnicodeCharacter{211C}{\ensuremath\Re}%
10971   \DeclareUnicodeCharacter{2127}{\ensuremath\mho}%
10972   \DeclareUnicodeCharacter{2135}{\ensuremath\aleph}%
10973   \DeclareUnicodeCharacter{2190}{\ensuremath\leftarrow}%
10974   \DeclareUnicodeCharacter{2191}{\ensuremath\uparrow}%
10975   \DeclareUnicodeCharacter{2193}{\ensuremath\downarrow}%
10976   \DeclareUnicodeCharacter{2194}{\ensuremath\leftrightarrow}%
10977   \DeclareUnicodeCharacter{2195}{\ensuremath\updownarrow}%
10978   \DeclareUnicodeCharacter{2196}{\ensuremath\nwarrow}%
10979   \DeclareUnicodeCharacter{2197}{\ensuremath\nearrow}%
10980   \DeclareUnicodeCharacter{2198}{\ensuremath\searrow}%
10981   \DeclareUnicodeCharacter{2199}{\ensuremath\swarrow}%
10982   \DeclareUnicodeCharacter{21A6}{\ensuremath\mapsto}%
10983   \DeclareUnicodeCharacter{21A9}{\ensuremath\hookleftarrow}%
10984   \DeclareUnicodeCharacter{21AA}{\ensuremath\hookrightarrow}%
10985   \DeclareUnicodeCharacter{21BC}{\ensuremath\leftharpoonup}%
10986   \DeclareUnicodeCharacter{21BD}{\ensuremath\leftharpoondown}%
10987   \DeclareUnicodeCharacter{21BE}{\ensuremath\upharpoonright}%
10988   \DeclareUnicodeCharacter{21C0}{\ensuremath\rightharpoonup}%
10989   \DeclareUnicodeCharacter{21C1}{\ensuremath\rightharpoondown}%
10990   \DeclareUnicodeCharacter{21CC}{\ensuremath\rightleftharpoons}%
10991   \DeclareUnicodeCharacter{21D0}{\ensuremath\Leftarrow}%
10992   \DeclareUnicodeCharacter{21D1}{\ensuremath\Uparrow}%
10993   \DeclareUnicodeCharacter{21D3}{\ensuremath\Downarrow}%
10994   \DeclareUnicodeCharacter{21D4}{\ensuremath\Leftrightarrow}%
10995   \DeclareUnicodeCharacter{21D5}{\ensuremath\Updownarrow}%
10996   \DeclareUnicodeCharacter{21DD}{\ensuremath\leadsto}%
10997   \DeclareUnicodeCharacter{2201}{\ensuremath\complement}%
10998   \DeclareUnicodeCharacter{2202}{\ensuremath\partial}%
10999   \DeclareUnicodeCharacter{2205}{\ensuremath\emptyset}%
11000   \DeclareUnicodeCharacter{2207}{\ensuremath\nabla}%
11001   \DeclareUnicodeCharacter{2209}{\ensuremath\notin}%
11002   \DeclareUnicodeCharacter{220B}{\ensuremath\owns}%
11003   \DeclareUnicodeCharacter{220F}{\ensuremath\prod}%
11004   \DeclareUnicodeCharacter{2210}{\ensuremath\coprod}%
11005   \DeclareUnicodeCharacter{2211}{\ensuremath\sum}%
11006   \DeclareUnicodeCharacter{2213}{\ensuremath\mp}%
11007   \DeclareUnicodeCharacter{2218}{\ensuremath\circ}%
11008   \DeclareUnicodeCharacter{221A}{\ensuremath\surd}%
11009   \DeclareUnicodeCharacter{221D}{\ensuremath\propto}%
11010   \DeclareUnicodeCharacter{2220}{\ensuremath\angle}%
11011   \DeclareUnicodeCharacter{2223}{\ensuremath\mid}%
11012   \DeclareUnicodeCharacter{2228}{\ensuremath\vee}%
11013   \DeclareUnicodeCharacter{222A}{\ensuremath\cup}%
11014   \DeclareUnicodeCharacter{222B}{\ensuremath\smallint}%
11015   \DeclareUnicodeCharacter{222E}{\ensuremath\oint}%
11016   \DeclareUnicodeCharacter{223C}{\ensuremath\sim}%
11017   \DeclareUnicodeCharacter{2240}{\ensuremath\wr}%
11018   \DeclareUnicodeCharacter{2243}{\ensuremath\simeq}%
11019   \DeclareUnicodeCharacter{2245}{\ensuremath\cong}%
11020   \DeclareUnicodeCharacter{2248}{\ensuremath\approx}%
11021   \DeclareUnicodeCharacter{224D}{\ensuremath\asymp}%
11022   \DeclareUnicodeCharacter{2250}{\ensuremath\doteq}%
11023   \DeclareUnicodeCharacter{2260}{\ensuremath\neq}%
11024   \DeclareUnicodeCharacter{226A}{\ensuremath\ll}%
11025   \DeclareUnicodeCharacter{226B}{\ensuremath\gg}%
11026   \DeclareUnicodeCharacter{227A}{\ensuremath\prec}%
11027   \DeclareUnicodeCharacter{227B}{\ensuremath\succ}%
11028   \DeclareUnicodeCharacter{2283}{\ensuremath\supset}%
11029   \DeclareUnicodeCharacter{2286}{\ensuremath\subseteq}%
11030   \DeclareUnicodeCharacter{228E}{\ensuremath\uplus}%
11031   \DeclareUnicodeCharacter{228F}{\ensuremath\sqsubset}%
11032   \DeclareUnicodeCharacter{2290}{\ensuremath\sqsupset}%
11033   \DeclareUnicodeCharacter{2291}{\ensuremath\sqsubseteq}%
11034   \DeclareUnicodeCharacter{2292}{\ensuremath\sqsupseteq}%
11035   \DeclareUnicodeCharacter{2293}{\ensuremath\sqcap}%
11036   \DeclareUnicodeCharacter{2294}{\ensuremath\sqcup}%
11037   \DeclareUnicodeCharacter{2295}{\ensuremath\oplus}%
11038   \DeclareUnicodeCharacter{2296}{\ensuremath\ominus}%
11039   \DeclareUnicodeCharacter{2297}{\ensuremath\otimes}%
11040   \DeclareUnicodeCharacter{2298}{\ensuremath\oslash}%
11041   \DeclareUnicodeCharacter{2299}{\ensuremath\odot}%
11042   \DeclareUnicodeCharacter{22A2}{\ensuremath\vdash}%
11043   \DeclareUnicodeCharacter{22A3}{\ensuremath\dashv}%
11044   \DeclareUnicodeCharacter{22A4}{\ensuremath\ptextop}%
11045   \DeclareUnicodeCharacter{22A5}{\ensuremath\bot}%
11046   \DeclareUnicodeCharacter{22A8}{\ensuremath\models}%
11047   \DeclareUnicodeCharacter{22B4}{\ensuremath\unlhd}%
11048   \DeclareUnicodeCharacter{22B5}{\ensuremath\unrhd}%
11049   \DeclareUnicodeCharacter{22C0}{\ensuremath\bigwedge}%
11050   \DeclareUnicodeCharacter{22C1}{\ensuremath\bigvee}%
11051   \DeclareUnicodeCharacter{22C2}{\ensuremath\bigcap}%
11052   \DeclareUnicodeCharacter{22C3}{\ensuremath\bigcup}%
11053   \DeclareUnicodeCharacter{22C4}{\ensuremath\diamond}%
11054   \DeclareUnicodeCharacter{22C5}{\ensuremath\cdot}%
11055   \DeclareUnicodeCharacter{22C6}{\ensuremath\star}%
11056   \DeclareUnicodeCharacter{22C8}{\ensuremath\bowtie}%
11057   \DeclareUnicodeCharacter{2308}{\ensuremath\lceil}%
11058   \DeclareUnicodeCharacter{2309}{\ensuremath\rceil}%
11059   \DeclareUnicodeCharacter{230A}{\ensuremath\lfloor}%
11060   \DeclareUnicodeCharacter{230B}{\ensuremath\rfloor}%
11061   \DeclareUnicodeCharacter{2322}{\ensuremath\frown}%
11062   \DeclareUnicodeCharacter{2323}{\ensuremath\smile}%
11063   %
11064   \DeclareUnicodeCharacter{25A1}{\ensuremath\Box}%
11065   \DeclareUnicodeCharacter{25B3}{\ensuremath\triangle}%
11066   \DeclareUnicodeCharacter{25B7}{\ensuremath\triangleright}%
11067   \DeclareUnicodeCharacter{25BD}{\ensuremath\bigtriangledown}%
11068   \DeclareUnicodeCharacter{25C1}{\ensuremath\triangleleft}%
11069   \DeclareUnicodeCharacter{25C7}{\ensuremath\Diamond}%
11070   \DeclareUnicodeCharacter{2660}{\ensuremath\spadesuit}%
11071   \DeclareUnicodeCharacter{2661}{\ensuremath\heartsuit}%
11072   \DeclareUnicodeCharacter{2662}{\ensuremath\diamondsuit}%
11073   \DeclareUnicodeCharacter{2663}{\ensuremath\clubsuit}%
11074   \DeclareUnicodeCharacter{266D}{\ensuremath\flat}%
11075   \DeclareUnicodeCharacter{266E}{\ensuremath\natural}%
11076   \DeclareUnicodeCharacter{266F}{\ensuremath\sharp}%
11077   \DeclareUnicodeCharacter{26AA}{\ensuremath\bigcirc}%
11078   \DeclareUnicodeCharacter{27B9}{\ensuremath\rangle}%
11079   \DeclareUnicodeCharacter{27C2}{\ensuremath\perp}%
11080   \DeclareUnicodeCharacter{27E8}{\ensuremath\langle}%
11081   \DeclareUnicodeCharacter{27F5}{\ensuremath\longleftarrow}%
11082   \DeclareUnicodeCharacter{27F6}{\ensuremath\longrightarrow}%
11083   \DeclareUnicodeCharacter{27F7}{\ensuremath\longleftrightarrow}%
11084   \DeclareUnicodeCharacter{27FC}{\ensuremath\longmapsto}%
11085   \DeclareUnicodeCharacter{29F5}{\ensuremath\setminus}%
11086   \DeclareUnicodeCharacter{2A00}{\ensuremath\bigodot}%
11087   \DeclareUnicodeCharacter{2A01}{\ensuremath\bigoplus}%
11088   \DeclareUnicodeCharacter{2A02}{\ensuremath\bigotimes}%
11089   \DeclareUnicodeCharacter{2A04}{\ensuremath\biguplus}%
11090   \DeclareUnicodeCharacter{2A06}{\ensuremath\bigsqcup}%
11091   \DeclareUnicodeCharacter{2A1D}{\ensuremath\Join}%
11092   \DeclareUnicodeCharacter{2A3F}{\ensuremath\amalg}%
11093   \DeclareUnicodeCharacter{2AAF}{\ensuremath\preceq}%
11094   \DeclareUnicodeCharacter{2AB0}{\ensuremath\succeq}%
11095   %
11096   \global\mathchardef\checkmark="1370% actually the square root sign
11097   \DeclareUnicodeCharacter{2713}{\ensuremath\checkmark}%
11098 }% end of \unicodechardefs
11099
11100 % UTF-8 byte sequence (pdfTeX) definitions (replacing and @U command)
11101 % It makes the setting that replace UTF-8 byte sequence.
11102 \def\utfeightchardefs{%
11103   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterUTFviii
11104   \unicodechardefs
11105 }
11106
11107 % Whether the active definitions of non-ASCII characters expand to
11108 % non-active tokens with the same character code.  This is used to
11109 % write characters literally, instead of using active definitions for
11110 % printing the correct glyphs.
11111 \newif\ifpassthroughchars
11112 \passthroughcharsfalse
11113
11114 % For native Unicode (XeTeX and LuaTeX)
11115 % Definition macro to replace / pass-through the Unicode character
11116 %
11117 \def\DeclareUnicodeCharacterNative#1#2{%
11118   \catcode"#1=\active
11119   \def\dodeclareunicodecharacternative##1##2##3{%
11120     \begingroup
11121       \uccode`\~="##2\relax
11122       \uppercase{\gdef~}{%
11123         \ifpassthroughchars
11124           ##1%
11125         \else
11126           ##3%
11127         \fi
11128       }
11129     \endgroup
11130   }
11131   \begingroup
11132     \uccode`\.="#1\relax
11133     \uppercase{\def\UTFNativeTmp{.}}%
11134     \expandafter\dodeclareunicodecharacternative\UTFNativeTmp{#1}{#2}%
11135   \endgroup
11136 }
11137
11138 % Native Unicode (XeTeX and LuaTeX) character replacing definitions
11139 % It makes the setting that replace the Unicode characters.
11140 \def\nativeunicodechardefs{%
11141   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNative
11142   \unicodechardefs
11143 }
11144
11145 % For native Unicode (XeTeX and LuaTeX).  Make the character token expand
11146 % to the sequences given in \unicodechardefs for printing.
11147 \def\DeclareUnicodeCharacterNativeAtU#1#2{%
11148   \def\UTFAtUTmp{#2}
11149   \expandafter\globallet\csname uni:#1\endcsname \UTFAtUTmp
11150 }
11151
11152 % Native Unicode (XeTeX and LuaTeX) @U command definitions
11153 \def\nativeunicodechardefsatu{%
11154   \let\DeclareUnicodeCharacter\DeclareUnicodeCharacterNativeAtU
11155   \unicodechardefs
11156 }
11157
11158 % US-ASCII character definitions.
11159 \def\asciichardefs{% nothing need be done
11160    \relax
11161 }
11162
11163 % define all the unicode characters we know about, for the sake of @U.
11164 \iftxinativeunicodecapable
11165   \nativeunicodechardefsatu
11166 \else
11167   \utfeightchardefs
11168 \fi
11169
11170
11171 % Make non-ASCII characters printable again for compatibility with
11172 % existing Texinfo documents that may use them, even without declaring a
11173 % document encoding.
11174 %
11175 \setnonasciicharscatcode \other
11176
11177
11178 \message{formatting,}
11179
11180 \newdimen\defaultparindent \defaultparindent = 15pt
11181
11182 \chapheadingskip = 15pt plus 4pt minus 2pt
11183 \secheadingskip = 12pt plus 3pt minus 2pt
11184 \subsecheadingskip = 9pt plus 2pt minus 2pt
11185
11186 % Prevent underfull vbox error messages.
11187 \vbadness = 10000
11188
11189 % Don't be very finicky about underfull hboxes, either.
11190 \hbadness = 6666
11191
11192 % Following George Bush, get rid of widows and orphans.
11193 \widowpenalty=10000
11194 \clubpenalty=10000
11195
11196 % Use TeX 3.0's \emergencystretch to help line breaking, but if we're
11197 % using an old version of TeX, don't do anything.  We want the amount of
11198 % stretch added to depend on the line length, hence the dependence on
11199 % \hsize.  We call this whenever the paper size is set.
11200 %
11201 \def\setemergencystretch{%
11202   \ifx\emergencystretch\thisisundefined
11203     % Allow us to assign to \emergencystretch anyway.
11204     \def\emergencystretch{\dimen0}%
11205   \else
11206     \emergencystretch = .15\hsize
11207   \fi
11208 }
11209
11210 % Parameters in order: 1) textheight; 2) textwidth;
11211 % 3) voffset; 4) hoffset; 5) binding offset; 6) topskip;
11212 % 7) physical page height; 8) physical page width.
11213 %
11214 % We also call \setleading{\textleading}, so the caller should define
11215 % \textleading.  The caller should also set \parskip.
11216 %
11217 \def\internalpagesizes#1#2#3#4#5#6#7#8{%
11218   \voffset = #3\relax
11219   \topskip = #6\relax
11220   \splittopskip = \topskip
11221   %
11222   \vsize = #1\relax
11223   \advance\vsize by \topskip
11224   \outervsize = \vsize
11225   \advance\outervsize by 2\topandbottommargin
11226   \txipageheight = \vsize
11227   %
11228   \hsize = #2\relax
11229   \outerhsize = \hsize
11230   \advance\outerhsize by 0.5in
11231   \txipagewidth = \hsize
11232   %
11233   \normaloffset = #4\relax
11234   \bindingoffset = #5\relax
11235   %
11236   \ifpdf
11237     \pdfpageheight #7\relax
11238     \pdfpagewidth #8\relax
11239     % if we don't reset these, they will remain at "1 true in" of
11240     % whatever layout pdftex was dumped with.
11241     \pdfhorigin = 1 true in
11242     \pdfvorigin = 1 true in
11243   \else
11244     \ifx\XeTeXrevision\thisisundefined
11245     \else
11246       \pdfpageheight #7\relax
11247       \pdfpagewidth #8\relax
11248       % XeTeX does not have \pdfhorigin and \pdfvorigin.
11249     \fi
11250   \fi
11251   %
11252   \setleading{\textleading}
11253   %
11254   \parindent = \defaultparindent
11255   \setemergencystretch
11256 }
11257
11258 % @letterpaper (the default).
11259 \def\letterpaper{{\globaldefs = 1
11260   \parskip = 3pt plus 2pt minus 1pt
11261   \textleading = 13.2pt
11262   %
11263   % If page is nothing but text, make it come out even.
11264   \internalpagesizes{607.2pt}{6in}% that's 46 lines
11265                     {\voffset}{.25in}%
11266                     {\bindingoffset}{36pt}%
11267                     {11in}{8.5in}%
11268 }}
11269
11270 % Use @smallbook to reset parameters for 7x9.25 trim size.
11271 \def\smallbook{{\globaldefs = 1
11272   \parskip = 2pt plus 1pt
11273   \textleading = 12pt
11274   %
11275   \internalpagesizes{7.5in}{5in}%
11276                     {-.2in}{0in}%
11277                     {\bindingoffset}{16pt}%
11278                     {9.25in}{7in}%
11279   %
11280   \lispnarrowing = 0.3in
11281   \tolerance = 700
11282   \hfuzz = 1pt
11283   \contentsrightmargin = 0pt
11284   \defbodyindent = .5cm
11285 }}
11286
11287 % Use @smallerbook to reset parameters for 6x9 trim size.
11288 % (Just testing, parameters still in flux.)
11289 \def\smallerbook{{\globaldefs = 1
11290   \parskip = 1.5pt plus 1pt
11291   \textleading = 12pt
11292   %
11293   \internalpagesizes{7.4in}{4.8in}%
11294                     {-.2in}{-.4in}%
11295                     {0pt}{14pt}%
11296                     {9in}{6in}%
11297   %
11298   \lispnarrowing = 0.25in
11299   \tolerance = 700
11300   \hfuzz = 1pt
11301   \contentsrightmargin = 0pt
11302   \defbodyindent = .4cm
11303 }}
11304
11305 % Use @afourpaper to print on European A4 paper.
11306 \def\afourpaper{{\globaldefs = 1
11307   \parskip = 3pt plus 2pt minus 1pt
11308   \textleading = 13.2pt
11309   %
11310   % Double-side printing via postscript on Laserjet 4050
11311   % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
11312   % To change the settings for a different printer or situation, adjust
11313   % \normaloffset until the front-side and back-side texts align.  Then
11314   % do the same for \bindingoffset.  You can set these for testing in
11315   % your texinfo source file like this:
11316   % @tex
11317   % \global\normaloffset = -6mm
11318   % \global\bindingoffset = 10mm
11319   % @end tex
11320   \internalpagesizes{673.2pt}{160mm}% that's 51 lines
11321                     {\voffset}{\hoffset}%
11322                     {\bindingoffset}{44pt}%
11323                     {297mm}{210mm}%
11324   %
11325   \tolerance = 700
11326   \hfuzz = 1pt
11327   \contentsrightmargin = 0pt
11328   \defbodyindent = 5mm
11329 }}
11330
11331 % Use @afivepaper to print on European A5 paper.
11332 % From romildo@urano.iceb.ufop.br, 2 July 2000.
11333 % He also recommends making @example and @lisp be small.
11334 \def\afivepaper{{\globaldefs = 1
11335   \parskip = 2pt plus 1pt minus 0.1pt
11336   \textleading = 12.5pt
11337   %
11338   \internalpagesizes{160mm}{120mm}%
11339                     {\voffset}{\hoffset}%
11340                     {\bindingoffset}{8pt}%
11341                     {210mm}{148mm}%
11342   %
11343   \lispnarrowing = 0.2in
11344   \tolerance = 800
11345   \hfuzz = 1.2pt
11346   \contentsrightmargin = 0pt
11347   \defbodyindent = 2mm
11348   \tableindent = 12mm
11349 }}
11350
11351 % A specific text layout, 24x15cm overall, intended for A4 paper.
11352 \def\afourlatex{{\globaldefs = 1
11353   \afourpaper
11354   \internalpagesizes{237mm}{150mm}%
11355                     {\voffset}{4.6mm}%
11356                     {\bindingoffset}{7mm}%
11357                     {297mm}{210mm}%
11358   %
11359   % Must explicitly reset to 0 because we call \afourpaper.
11360   \globaldefs = 0
11361 }}
11362
11363 % Use @afourwide to print on A4 paper in landscape format.
11364 \def\afourwide{{\globaldefs = 1
11365   \afourpaper
11366   \internalpagesizes{241mm}{165mm}%
11367                     {\voffset}{-2.95mm}%
11368                     {\bindingoffset}{7mm}%
11369                     {297mm}{210mm}%
11370   \globaldefs = 0
11371 }}
11372
11373 % @pagesizes TEXTHEIGHT[,TEXTWIDTH]
11374 % Perhaps we should allow setting the margins, \topskip, \parskip,
11375 % and/or leading, also. Or perhaps we should compute them somehow.
11376 %
11377 \parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
11378 \def\pagesizesyyy#1,#2,#3\finish{{%
11379   \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
11380   \globaldefs = 1
11381   %
11382   \parskip = 3pt plus 2pt minus 1pt
11383   \setleading{\textleading}%
11384   %
11385   \dimen0 = #1\relax
11386   \advance\dimen0 by \voffset
11387   %
11388   \dimen2 = \hsize
11389   \advance\dimen2 by \normaloffset
11390   %
11391   \internalpagesizes{#1}{\hsize}%
11392                     {\voffset}{\normaloffset}%
11393                     {\bindingoffset}{44pt}%
11394                     {\dimen0}{\dimen2}%
11395 }}
11396
11397 % Set default to letter.
11398 %
11399 \letterpaper
11400
11401
11402 \message{and turning on texinfo input format.}
11403
11404 \def^^L{\par} % remove \outer, so ^L can appear in an @comment
11405
11406 % DEL is a comment character, in case @c does not suffice.
11407 \catcode`\^^? = 14
11408
11409 % Define macros to output various characters with catcode for normal text.
11410 \catcode`\"=\other \def\normaldoublequote{"}
11411 \catcode`\$=\other \def\normaldollar{$}%$ font-lock fix
11412 \catcode`\+=\other \def\normalplus{+}
11413 \catcode`\<=\other \def\normalless{<}
11414 \catcode`\>=\other \def\normalgreater{>}
11415 \catcode`\^=\other \def\normalcaret{^}
11416 \catcode`\_=\other \def\normalunderscore{_}
11417 \catcode`\|=\other \def\normalverticalbar{|}
11418 \catcode`\~=\other \def\normaltilde{~}
11419
11420 % This macro is used to make a character print one way in \tt
11421 % (where it can probably be output as-is), and another way in other fonts,
11422 % where something hairier probably needs to be done.
11423 %
11424 % #1 is what to print if we are indeed using \tt; #2 is what to print
11425 % otherwise.  Since all the Computer Modern typewriter fonts have zero
11426 % interword stretch (and shrink), and it is reasonable to expect all
11427 % typewriter fonts to have this, we can check that font parameter.
11428 %
11429 \def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
11430
11431 % Same as above, but check for italic font.  Actually this also catches
11432 % non-italic slanted fonts since it is impossible to distinguish them from
11433 % italic fonts.  But since this is only used by $ and it uses \sl anyway
11434 % this is not a problem.
11435 \def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
11436
11437 % Set catcodes for Texinfo file
11438
11439 % Active characters for printing the wanted glyph.
11440 % Most of these we simply print from the \tt font, but for some, we can
11441 % use math or other variants that look better in normal text.
11442 %
11443 \catcode`\"=\active
11444 \def\activedoublequote{{\tt\char34}}
11445 \let"=\activedoublequote
11446 \catcode`\~=\active \def\activetilde{{\tt\char126}} \let~ = \activetilde
11447 \chardef\hatchar=`\^
11448 \catcode`\^=\active \def\activehat{{\tt \hatchar}} \let^ = \activehat
11449
11450 \catcode`\_=\active
11451 \def_{\ifusingtt\normalunderscore\_}
11452 \def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
11453 \let\realunder=_
11454
11455 \catcode`\|=\active \def|{{\tt\char124}}
11456
11457 \chardef \less=`\<
11458 \catcode`\<=\active \def\activeless{{\tt \less}}\let< = \activeless
11459 \chardef \gtr=`\>
11460 \catcode`\>=\active \def\activegtr{{\tt \gtr}}\let> = \activegtr
11461 \catcode`\+=\active \def+{{\tt \char 43}}
11462 \catcode`\$=\active \def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
11463 \catcode`\-=\active \let-=\normaldash
11464
11465
11466 % used for headline/footline in the output routine, in case the page
11467 % breaks in the middle of an @tex block.
11468 \def\texinfochars{%
11469   \let< = \activeless
11470   \let> = \activegtr
11471   \let~ = \activetilde 
11472   \let^ = \activehat
11473   \markupsetuplqdefault \markupsetuprqdefault 
11474   \let\b = \strong
11475   \let\i = \smartitalic
11476   % in principle, all other definitions in \tex have to be undone too.
11477 }
11478
11479 % Used sometimes to turn off (effectively) the active characters even after
11480 % parsing them.
11481 \def\turnoffactive{%
11482   \normalturnoffactive
11483   \otherbackslash
11484 }
11485
11486 \catcode`\@=0
11487
11488 % \backslashcurfont outputs one backslash character in current font,
11489 % as in \char`\\.
11490 \global\chardef\backslashcurfont=`\\
11491 \global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
11492
11493 % \realbackslash is an actual character `\' with catcode other, and
11494 % \doublebackslash is two of them (for the pdf outlines).
11495 {\catcode`\\=\other @gdef@realbackslash{\} @gdef@doublebackslash{\\}}
11496
11497 % In Texinfo, backslash is an active character; it prints the backslash
11498 % in fixed width font.
11499 \catcode`\\=\active  % @ for escape char from now on.
11500
11501 % Print a typewriter backslash.  For math mode, we can't simply use
11502 % \backslashcurfont: the story here is that in math mode, the \char
11503 % of \backslashcurfont ends up printing the roman \ from the math symbol
11504 % font (because \char in math mode uses the \mathcode, and plain.tex
11505 % sets \mathcode`\\="026E).  Hence we use an explicit \mathchar,
11506 % which is the decimal equivalent of "715c (class 7, e.g., use \fam;
11507 % ignored family value; char position "5C).  We can't use " for the
11508 % usual hex value because it has already been made active.
11509
11510 @def@ttbackslash{{@tt @ifmmode @mathchar29020 @else @backslashcurfont @fi}}
11511 @let@backslashchar = @ttbackslash % @backslashchar{} is for user documents.
11512
11513 % \rawbackslash defines an active \ to do \backslashcurfont.
11514 % \otherbackslash defines an active \ to be a literal `\' character with
11515 % catcode other.  We switch back and forth between these.
11516 @gdef@rawbackslash{@let\=@backslashcurfont}
11517 @gdef@otherbackslash{@let\=@realbackslash}
11518
11519 % Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
11520 % the literal character `\'.
11521 %
11522 {@catcode`- = @active
11523  @gdef@normalturnoffactive{%
11524    @passthroughcharstrue
11525    @let-=@normaldash
11526    @let"=@normaldoublequote
11527    @let$=@normaldollar %$ font-lock fix
11528    @let+=@normalplus
11529    @let<=@normalless
11530    @let>=@normalgreater
11531    @let^=@normalcaret
11532    @let_=@normalunderscore
11533    @let|=@normalverticalbar
11534    @let~=@normaltilde
11535    @let\=@ttbackslash
11536    @markupsetuplqdefault
11537    @markupsetuprqdefault
11538    @unsepspaces
11539  }
11540 }
11541
11542 % If a .fmt file is being used, characters that might appear in a file
11543 % name cannot be active until we have parsed the command line.
11544 % So turn them off again, and have @fixbackslash turn them back on.
11545 @catcode`+=@other @catcode`@_=@other
11546
11547 % \enablebackslashhack - allow file to begin `\input texinfo'
11548 %
11549 % If a .fmt file is being used, we don't want the `\input texinfo' to show up.
11550 % That is what \eatinput is for; after that, the `\' should revert to printing
11551 % a backslash.
11552 % If the file did not have a `\input texinfo', then it is turned off after
11553 % the first line; otherwise the first `\' in the file would cause an error.
11554 % This is used on the very last line of this file, texinfo.tex.
11555 % We also use @c to call @fixbackslash, in case ends of lines are hidden.
11556 {
11557 @catcode`@^=7
11558 @catcode`@^^M=13@gdef@enablebackslashhack{%
11559   @global@let\ = @eatinput%
11560   @catcode`@^^M=13%
11561   @def@c{@fixbackslash@c}%
11562   % Definition for the newline at the end of this file.
11563   @def ^^M{@let^^M@secondlinenl}%
11564   % Definition for a newline in the main Texinfo file.
11565   @gdef @secondlinenl{@fixbackslash}%
11566 }}
11567
11568 {@catcode`@^=7 @catcode`@^^M=13%
11569 @gdef@eatinput input texinfo#1^^M{@fixbackslash}}
11570
11571 % Emergency active definition of newline, in case an active newline token
11572 % appears by mistake.
11573 {@catcode`@^=7 @catcode13=13%
11574 @gdef@enableemergencynewline{%
11575   @gdef^^M{%
11576     @par%
11577     %<warning: active newline>@par%
11578 }}}
11579
11580
11581 @gdef@fixbackslash{%
11582   @ifx\@eatinput @let\ = @ttbackslash @fi
11583   @catcode13=5 % regular end of line
11584   @enableemergencynewline
11585   @let@c=@texinfoc
11586   % Also turn back on active characters that might appear in the input
11587   % file name, in case not using a pre-dumped format.
11588   @catcode`+=@active
11589   @catcode`@_=@active
11590   %
11591   % If texinfo.cnf is present on the system, read it.
11592   % Useful for site-wide @afourpaper, etc.  This macro, @fixbackslash, gets
11593   % called at the beginning of every Texinfo file.  Not opening texinfo.cnf
11594   % directly in this file, texinfo.tex, makes it possible to make a format
11595   % file for Texinfo.
11596   %
11597   @openin 1 texinfo.cnf
11598   @ifeof 1 @else @input texinfo.cnf @fi
11599   @closein 1
11600 }
11601
11602
11603 % Say @foo, not \foo, in error messages.
11604 @escapechar = `@@
11605
11606 % These (along with & and #) are made active for url-breaking, so need
11607 % active definitions as the normal characters.
11608 @def@normaldot{.}
11609 @def@normalquest{?}
11610 @def@normalslash{/}
11611
11612 % These look ok in all fonts, so just make them not special.
11613 % @hashchar{} gets its own user-level command, because of #line.
11614 @catcode`@& = @other @def@normalamp{&}
11615 @catcode`@# = @other @def@normalhash{#}
11616 @catcode`@% = @other @def@normalpercent{%}
11617
11618 @let @hashchar = @normalhash
11619
11620 @c Finally, make ` and ' active, so that txicodequoteundirected and
11621 @c txicodequotebacktick work right in, e.g., @w{@code{`foo'}}.  If we
11622 @c don't make ` and ' active, @code will not get them as active chars.
11623 @c Do this last of all since we use ` in the previous @catcode assignments.
11624 @catcode`@'=@active
11625 @catcode`@`=@active
11626 @markupsetuplqdefault
11627 @markupsetuprqdefault
11628
11629 @c Local variables:
11630 @c eval: (add-hook 'write-file-hooks 'time-stamp)
11631 @c page-delimiter: "^\\\\message\\|emacs-page"
11632 @c time-stamp-start: "def\\\\texinfoversion{"
11633 @c time-stamp-format: "%:y-%02m-%02d.%02H"
11634 @c time-stamp-end: "}"
11635 @c End:
11636
11637 @c vim:sw=2:
11638
11639 @ignore
11640    arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
11641 @end ignore
11642 @enablebackslashhack