texinfo.tex 373 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1
% texinfo.tex -- TeX macros to handle Texinfo files.
2
% 
Glenn Morris's avatar
Glenn Morris committed
3 4 5
% Load plain if necessary, i.e., if running under initex.
\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
%
Paul Eggert's avatar
Paul Eggert committed
6
\def\texinfoversion{2016-08-03.13}
Glenn Morris's avatar
Glenn Morris committed
7
%
8 9
% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
Paul Eggert's avatar
Paul Eggert committed
10
% 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
11
% Free Software Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
12
%
13
% This texinfo.tex file is free software: you can redistribute it and/or
Glenn Morris's avatar
Glenn Morris committed
14
% modify it under the terms of the GNU General Public License as
15 16
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
Glenn Morris's avatar
Glenn Morris committed
17 18 19 20 21 22 23
%
% This texinfo.tex file is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% General Public License for more details.
%
% 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/>.
Glenn Morris's avatar
Glenn Morris committed
25 26 27
%
% As a special exception, when this file is read by TeX when processing
% a Texinfo source document, you may use the result without
Paul Eggert's avatar
Paul Eggert committed
28 29
% restriction. This Exception is an additional permission under section 7
% of the GNU General Public License, version 3 ("GPLv3").
Glenn Morris's avatar
Glenn Morris committed
30 31 32
%
% Please try the latest version of texinfo.tex before submitting bug
% reports; you can get the latest version from:
Paul Eggert's avatar
Paul Eggert committed
33 34 35
%   http://ftp.gnu.org/gnu/texinfo/ (the Texinfo release area), or
%   http://ftpmirror.gnu.org/texinfo/ (same, via a mirror), or
%   http://www.gnu.org/software/texinfo/ (the Texinfo home page)
Glenn Morris's avatar
Glenn Morris committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
% The texinfo.tex in any given distribution could well be out
% of date, so if that's what you're using, please check.
%
% Send bug reports to bug-texinfo@gnu.org.  Please include including a
% complete document in each bug report with which we can reproduce the
% problem.  Patches are, of course, greatly appreciated.
%
% To process a Texinfo manual with TeX, it's most reliable to use the
% texi2dvi shell script that comes with the distribution.  For a simple
% manual foo.texi, however, you can get away with this:
%   tex foo.texi
%   texindex foo.??
%   tex foo.texi
%   tex foo.texi
%   dvips foo.dvi -o  # or whatever; this makes foo.ps.
% The extra TeX runs get the cross-reference information correct.
% Sometimes one run after texindex suffices, and sometimes you need more
% than two; texi2dvi does it as many times as necessary.
%
% It is possible to adapt texinfo.tex for other languages, to some
% extent.  You can get the existing language-specific files from the
% full Texinfo distribution.
%
% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.


\message{Loading texinfo [version \texinfoversion]:}

% If in a .fmt file, print the version number
% and turn on active characters that we couldn't do earlier because
% they might have appeared in the input file name.
\everyjob{\message{[Texinfo version \texinfoversion]}%
  \catcode`+=\active \catcode`\_=\active}

Paul Eggert's avatar
Paul Eggert committed
70 71 72 73
% LaTeX's \typeout.  This ensures that the messages it is used for
% are identical in format to the corresponding ones from latex/pdflatex.
\def\typeout{\immediate\write17}%

Glenn Morris's avatar
Glenn Morris committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
\chardef\other=12

% We never want plain's \outer definition of \+ in Texinfo.
% For @tex, we can use \tabalign.
\let\+ = \relax

% Save some plain tex macros whose names we will redefine.
\let\ptexb=\b
\let\ptexbullet=\bullet
\let\ptexc=\c
\let\ptexcomma=\,
\let\ptexdot=\.
\let\ptexdots=\dots
\let\ptexend=\end
\let\ptexequiv=\equiv
\let\ptexexclam=\!
\let\ptexfootnote=\footnote
\let\ptexgtr=>
\let\ptexhat=^
\let\ptexi=\i
\let\ptexindent=\indent
\let\ptexinsert=\insert
\let\ptexlbrace=\{
\let\ptexless=<
\let\ptexnewwrite\newwrite
\let\ptexnoindent=\noindent
\let\ptexplus=+
101
\let\ptexraggedright=\raggedright
Glenn Morris's avatar
Glenn Morris committed
102 103
\let\ptexrbrace=\}
\let\ptexslash=\/
104
\let\ptexsp=\sp
Glenn Morris's avatar
Glenn Morris committed
105
\let\ptexstar=\*
106
\let\ptexsup=\sup
Glenn Morris's avatar
Glenn Morris committed
107
\let\ptext=\t
108
\let\ptextop=\top
109
{\catcode`\'=\active \global\let\ptexquoteright'}% active in plain's math mode
Glenn Morris's avatar
Glenn Morris committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

% If this character appears in an error message or help string, it
% starts a new line in the output.
\newlinechar = `^^J

% Use TeX 3.0's \inputlineno to get the line number, for better error
% messages, but if we're using an old version of TeX, don't do anything.
%
\ifx\inputlineno\thisisundefined
  \let\linenumber = \empty % Pre-3.0.
\else
  \def\linenumber{l.\the\inputlineno:\space}
\fi

% Set up fixed words for English if not already set.
\ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
\ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
Paul Eggert's avatar
Paul Eggert committed
127
\ifx\putworderror\undefined     \gdef\putworderror{error}\fi
Glenn Morris's avatar
Glenn Morris committed
128 129
\ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
\ifx\putwordin\undefined        \gdef\putwordin{in}\fi
130 131
\ifx\putwordIndexIsEmpty\undefined       \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
\ifx\putwordIndexNonexistent\undefined   \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
Glenn Morris's avatar
Glenn Morris committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
\ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
\ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
\ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
\ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
\ifx\putwordof\undefined        \gdef\putwordof{of}\fi
\ifx\putwordon\undefined        \gdef\putwordon{on}\fi
\ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
\ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
\ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
\ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
\ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
\ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
\ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
%
\ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
\ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
\ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
\ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
\ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
\ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
\ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
\ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
\ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
\ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
\ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
\ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
%
\ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
\ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
\ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
\ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
\ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi

Paul Eggert's avatar
Paul Eggert committed
165 166
% Give the space character the catcode for a space.
\def\spaceisspace{\catcode`\ =10\relax}
Glenn Morris's avatar
Glenn Morris committed
167 168

\chardef\dashChar  = `\-
169
\chardef\slashChar = `\/
Glenn Morris's avatar
Glenn Morris committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
\chardef\underChar = `\_

% Ignore a token.
%
\def\gobble#1{}

% The following is used inside several \edef's.
\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}

% Hyphenation fixes.
\hyphenation{
  Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
  ap-pen-dix bit-map bit-maps
  data-base data-bases eshell fall-ing half-way long-est man-u-script
  man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
  par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
  spell-ing spell-ings
  stand-alone strong-est time-stamp time-stamps which-ever white-space
  wide-spread wrap-around
}

% Sometimes it is convenient to have everything in the transcript file
% and nothing on the terminal.  We don't just call \tracingall here,
% since that produces some useless output on the terminal.  We also make
% some effort to order the tracing commands to reduce output in the log
% file; cf. trace.sty in LaTeX.
%
\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
\def\loggingall{%
  \tracingstats2
  \tracingpages1
  \tracinglostchars2  % 2 gives us more in etex
  \tracingparagraphs1
  \tracingoutput1
  \tracingmacros2
  \tracingrestores1
  \showboxbreadth\maxdimen \showboxdepth\maxdimen
207
  \ifx\eTeXversion\thisisundefined\else % etex gives us more logging
Glenn Morris's avatar
Glenn Morris committed
208 209 210 211 212 213 214 215 216 217
    \tracingscantokens1
    \tracingifs1
    \tracinggroups1
    \tracingnesting2
    \tracingassigns1
  \fi
  \tracingcommands3  % 3 gives us more in etex
  \errorcontextlines16
}%

Paul Eggert's avatar
Paul Eggert committed
218 219 220 221 222 223 224
% @errormsg{MSG}.  Do the index-like expansions on MSG, but if things
% aren't perfect, it's not the end of the world, being an error message,
% after all.
% 
\def\errormsg{\begingroup \indexnofonts \doerrormsg}
\def\doerrormsg#1{\errmessage{#1}}

Glenn Morris's avatar
Glenn Morris committed
225 226 227 228 229 230 231 232 233 234
% add check for \lastpenalty to plain's definitions.  If the last thing
% we did was a \nobreak, we don't want to insert more space.
%
\def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
  \removelastskip\penalty-50\smallskip\fi\fi}
\def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
  \removelastskip\penalty-100\medskip\fi\fi}
\def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
  \removelastskip\penalty-200\bigskip\fi\fi}

Paul Eggert's avatar
Paul Eggert committed
235 236 237 238 239 240 241 242 243
% Output routine
%

% For a final copy, take out the rectangles
% that mark overfull boxes (in case you have decided
% that the text looks ok even though it passes the margin).
%
\def\finalout{\overfullrule=0pt }

Glenn Morris's avatar
Glenn Morris committed
244 245 246 247 248 249 250 251 252 253 254 255 256
% Do @cropmarks to get crop marks.
%
\newif\ifcropmarks
\let\cropmarks = \cropmarkstrue
%
% Dimensions to add cropmarks at corners.
% Added by P. A. MacKay, 12 Nov. 1986
%
\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
\newdimen\cornerlong  \cornerlong=1pc
\newdimen\cornerthick \cornerthick=.3pt
\newdimen\topandbottommargin \topandbottommargin=.75in

257 258 259 260 261 262 263 264 265
% Output a mark which sets \thischapter, \thissection and \thiscolor.
% We dump everything together because we only have one kind of mark.
% This works because we only use \botmark / \topmark, not \firstmark.
%
% A mark contains a subexpression of the \ifcase ... \fi construct.
% \get*marks macros below extract the needed part using \ifcase.
%
% Another complication is to let the user choose whether \thischapter
% (\thissection) refers to the chapter (section) in effect at the top
Paul Eggert's avatar
Paul Eggert committed
266 267 268 269 270 271 272 273 274 275 276 277
% of a page, or that at the bottom of a page.

% \domark is called twice inside \chapmacro, to add one
% mark before the section break, and one after.
%   In the second call \prevchapterdefs is the same as \lastchapterdefs,
% and \prevsectiondefs is the same as \lastsectiondefs.
%   Then if the page is not broken at the mark, some of the previous
% section appears on the page, and we can get the name of this section
% from \firstmark for @everyheadingmarks top.
%   @everyheadingmarks bottom uses \botmark.
%
% See page 260 of The TeXbook.
278 279 280 281 282 283 284
\def\domark{%
  \toks0=\expandafter{\lastchapterdefs}%
  \toks2=\expandafter{\lastsectiondefs}%
  \toks4=\expandafter{\prevchapterdefs}%
  \toks6=\expandafter{\prevsectiondefs}%
  \toks8=\expandafter{\lastcolordefs}%
  \mark{%
Paul Eggert's avatar
Paul Eggert committed
285 286
                   \the\toks0 \the\toks2  % 0: marks for @everyheadingmarks top
      \noexpand\or \the\toks4 \the\toks6  % 1: for @everyheadingmarks bottom
287
    \noexpand\else \the\toks8             % 2: color marks
288 289
  }%
}
Paul Eggert's avatar
Paul Eggert committed
290

Paul Eggert's avatar
Paul Eggert committed
291 292
% \gettopheadingmarks, \getbottomheadingmarks,
% \getcolormarks - extract needed part of mark.
Paul Eggert's avatar
Paul Eggert committed
293
%
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
% \topmark doesn't work for the very first chapter (after the title
% page or the contents), so we use \firstmark there -- this gets us
% the mark with the chapter defs, unless the user sneaks in, e.g.,
% @setcolor (or @url, or @link, etc.) between @contents and the very
% first @chapter.
\def\gettopheadingmarks{%
  \ifcase0\topmark\fi
  \ifx\thischapter\empty \ifcase0\firstmark\fi \fi
}
\def\getbottomheadingmarks{\ifcase1\botmark\fi}
\def\getcolormarks{\ifcase2\topmark\fi}

% Avoid "undefined control sequence" errors.
\def\lastchapterdefs{}
\def\lastsectiondefs{}
Paul Eggert's avatar
Paul Eggert committed
309
\def\lastsection{}
310 311 312 313
\def\prevchapterdefs{}
\def\prevsectiondefs{}
\def\lastcolordefs{}

Paul Eggert's avatar
Paul Eggert committed
314 315 316
% Margin to add to right of even pages, to left of odd pages.
\newdimen\bindingoffset
\newdimen\normaloffset
Paul Eggert's avatar
Paul Eggert committed
317
\newdimen\txipagewidth \newdimen\txipageheight
Paul Eggert's avatar
Paul Eggert committed
318

Glenn Morris's avatar
Glenn Morris committed
319
% Main output routine.
Paul Eggert's avatar
Paul Eggert committed
320
%
Glenn Morris's avatar
Glenn Morris committed
321 322 323 324 325 326
\chardef\PAGE = 255
\output = {\onepageout{\pagecontents\PAGE}}

\newbox\headlinebox
\newbox\footlinebox

Paul Eggert's avatar
Paul Eggert committed
327 328 329 330 331
% \onepageout takes a vbox as an argument.
% \shipout a vbox for a single page, adding an optional header, footer,
% cropmarks, and footnote.  This also causes index entries for this page
% to be written to the auxiliary files.
%
Glenn Morris's avatar
Glenn Morris committed
332 333 334 335 336 337
\def\onepageout#1{%
  \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
  %
  \ifodd\pageno  \advance\hoffset by \bindingoffset
  \else \advance\hoffset by -\bindingoffset\fi
  %
Paul Eggert's avatar
Paul Eggert committed
338
  % Common context changes for both heading and footing.
Glenn Morris's avatar
Glenn Morris committed
339 340
  % Do this outside of the \shipout so @code etc. will be expanded in
  % the headline as they should be, not taken literally (outputting ''code).
Paul Eggert's avatar
Paul Eggert committed
341
  \def\commmonheadfootline{\let\hsize=\txipagewidth \texinfochars}
Paul Eggert's avatar
Paul Eggert committed
342
  %
Paul Eggert's avatar
Paul Eggert committed
343 344 345 346 347
  % Retrieve the information for the headings from the marks in the page,
  % and call Plain TeX's \makeheadline and \makefootline, which use the
  % values in \headline and \footline.
  %
  % This is used to check if we are on the first page of a chapter.
Paul Eggert's avatar
Paul Eggert committed
348 349 350 351
  \ifcase1\topmark\fi
  \let\prevchaptername\thischaptername
  \ifcase0\firstmark\fi
  \let\curchaptername\thischaptername
Paul Eggert's avatar
Paul Eggert committed
352
  %
Paul Eggert's avatar
Paul Eggert committed
353
  \ifodd\pageno \getoddheadingmarks \else \getevenheadingmarks \fi
354
  \ifodd\pageno \getoddfootingmarks \else \getevenfootingmarks \fi
Paul Eggert's avatar
Paul Eggert committed
355 356
  %
  \ifx\curchaptername\prevchaptername
Paul Eggert's avatar
Paul Eggert committed
357
    \let\thischapterheading\thischapter
Paul Eggert's avatar
Paul Eggert committed
358
  \else
Paul Eggert's avatar
Paul Eggert committed
359 360 361 362
    % \thischapterheading is the same as \thischapter except it is blank
    % for the first page of a chapter.  This is to prevent the chapter name 
    % being shown twice.
    \def\thischapterheading{}%
Paul Eggert's avatar
Paul Eggert committed
363 364 365
  \fi
  %
  \global\setbox\headlinebox = \vbox{\commmonheadfootline \makeheadline}%
Paul Eggert's avatar
Paul Eggert committed
366
  \global\setbox\footlinebox = \vbox{\commmonheadfootline \makefootline}%
Glenn Morris's avatar
Glenn Morris committed
367 368
  %
  {%
Paul Eggert's avatar
Paul Eggert committed
369
    % Set context for writing to auxiliary files like index files.
Glenn Morris's avatar
Glenn Morris committed
370 371 372 373 374 375 376 377
    % Have to do this stuff outside the \shipout because we want it to
    % take effect in \write's, yet the group defined by the \vbox ends
    % before the \shipout runs.
    %
    \indexdummies         % don't expand commands in the output.
    \normalturnoffactive  % \ in index entries must not stay \, e.g., if
               % the page break happens to be in the middle of an example.
               % We don't want .vr (or whatever) entries like this:
Paul Eggert's avatar
Paul Eggert committed
378
               % \entry{{\indexbackslash }acronym}{32}{\code {\acronym}}
Glenn Morris's avatar
Glenn Morris committed
379
               % "\acronym" won't work when it's read back in;
380
               % it needs to be
Paul Eggert's avatar
Paul Eggert committed
381
               % {\code {{\backslashcurfont }acronym}
Glenn Morris's avatar
Glenn Morris committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    \shipout\vbox{%
      % Do this early so pdf references go to the beginning of the page.
      \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
      %
      \ifcropmarks \vbox to \outervsize\bgroup
        \hsize = \outerhsize
        \vskip-\topandbottommargin
        \vtop to0pt{%
          \line{\ewtop\hfil\ewtop}%
          \nointerlineskip
          \line{%
            \vbox{\moveleft\cornerthick\nstop}%
            \hfill
            \vbox{\moveright\cornerthick\nstop}%
          }%
          \vss}%
        \vskip\topandbottommargin
        \line\bgroup
          \hfil % center the page within the outer (page) hsize.
          \ifodd\pageno\hskip\bindingoffset\fi
          \vbox\bgroup
      \fi
      %
      \unvbox\headlinebox
      \pagebody{#1}%
      \ifdim\ht\footlinebox > 0pt
        % Only leave this space if the footline is nonempty.
        % (We lessened \vsize for it in \oddfootingyyy.)
        % The \baselineskip=24pt in plain's \makefootline has no effect.
        \vskip 24pt
        \unvbox\footlinebox
      \fi
      %
      \ifcropmarks
          \egroup % end of \vbox\bgroup
        \hfil\egroup % end of (centering) \line\bgroup
        \vskip\topandbottommargin plus1fill minus1fill
        \boxmaxdepth = \cornerthick
        \vbox to0pt{\vss
          \line{%
            \vbox{\moveleft\cornerthick\nsbot}%
            \hfill
            \vbox{\moveright\cornerthick\nsbot}%
          }%
          \nointerlineskip
          \line{\ewbot\hfil\ewbot}%
        }%
      \egroup % \vbox from first cropmarks clause
      \fi
    }% end of \shipout\vbox
  }% end of group with \indexdummies
  \advancepageno
  \ifnum\outputpenalty>-20000 \else\dosupereject\fi
}

\newinsert\margin \dimen\margin=\maxdimen

Paul Eggert's avatar
Paul Eggert committed
439
% Main part of page, including any footnotes
Paul Eggert's avatar
Paul Eggert committed
440
\def\pagebody#1{\vbox to\txipageheight{\boxmaxdepth=\maxdepth #1}}
Glenn Morris's avatar
Glenn Morris committed
441 442 443 444 445
{\catcode`\@ =11
\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
% marginal hacks, juha@viisa.uucp (Juha Takala)
\ifvoid\margin\else % marginal info is present
  \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
446
\dimen@=\dp#1\relax \unvbox#1\relax
Glenn Morris's avatar
Glenn Morris committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
}

% Here are the rules for the cropmarks.  Note that they are
% offset so that the space between them is truly \outerhsize or \outervsize
% (P. A. MacKay, 12 November, 1986)
%
\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
\def\nstop{\vbox
  {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
\def\nsbot{\vbox
  {\hrule height\cornerlong depth\cornerthick width\cornerthick}}

Paul Eggert's avatar
Paul Eggert committed
462 463 464

% Argument parsing

Glenn Morris's avatar
Glenn Morris committed
465 466 467
% Parse an argument, then pass it to #1.  The argument is the rest of
% the input line (except we remove a trailing comment).  #1 should be a
% macro which expects an ordinary undelimited TeX argument.
Paul Eggert's avatar
Paul Eggert committed
468
% For example, \def\foo{\parsearg\fooxxx}.
Glenn Morris's avatar
Glenn Morris committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
%
\def\parsearg{\parseargusing{}}
\def\parseargusing#1#2{%
  \def\argtorun{#2}%
  \begingroup
    \obeylines
    \spaceisspace
    #1%
    \parseargline\empty% Insert the \empty token, see \finishparsearg below.
}

{\obeylines %
  \gdef\parseargline#1^^M{%
    \endgroup % End of the group started in \parsearg.
    \argremovecomment #1\comment\ArgTerm%
  }%
}

Paul Eggert's avatar
Paul Eggert committed
487 488
% First remove any @comment, then any @c comment.  Also remove a @texinfoc
% comment (see \scanmacro for details).  Pass the result on to \argcheckspaces.
Glenn Morris's avatar
Glenn Morris committed
489
\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
Paul Eggert's avatar
Paul Eggert committed
490 491
\def\argremovec#1\c#2\ArgTerm{\argremovetexinfoc #1\texinfoc\ArgTerm}
\def\argremovetexinfoc#1\texinfoc#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
Glenn Morris's avatar
Glenn Morris committed
492

493
% Each occurrence of `\^^M' or `<space>\^^M' is replaced by a single space.
Glenn Morris's avatar
Glenn Morris committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
%
% \argremovec might leave us with trailing space, e.g.,
%    @end itemize  @c foo
% This space token undergoes the same procedure and is eventually removed
% by \finishparsearg.
%
\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
  \def\temp{#3}%
  \ifx\temp\empty
    % Do not use \next, perhaps the caller of \parsearg uses it; reuse \temp:
    \let\temp\finishparsearg
  \else
    \let\temp\argcheckspaces
  \fi
  % Put the space token in:
  \temp#1 #3\ArgTerm
}

% If a _delimited_ argument is enclosed in braces, they get stripped; so
% to get _exactly_ the rest of the line, we had to prevent such situation.
% We prepended an \empty token at the very beginning and we expand it now,
% just before passing the control to \argtorun.
518
% (Similarly, we have to think about #3 of \argcheckspacesY above: it is
Glenn Morris's avatar
Glenn Morris committed
519 520 521 522 523 524 525
% either the null string, or it ends with \^^M---thus there is no danger
% that a pair of braces would be stripped.
%
% But first, we have to remove the trailing space token.
%
\def\finishparsearg#1 \ArgTerm{\expandafter\argtorun\expandafter{#1}}

Paul Eggert's avatar
Paul Eggert committed
526 527 528

% \parseargdef - define a command taking an argument on the line
%
Glenn Morris's avatar
Glenn Morris committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
% \parseargdef\foo{...}
%	is roughly equivalent to
% \def\foo{\parsearg\Xfoo}
% \def\Xfoo#1{...}
\def\parseargdef#1{%
  \expandafter \doparseargdef \csname\string#1\endcsname #1%
}
\def\doparseargdef#1#2{%
  \def#2{\parsearg#1}%
  \def#1##1%
}

% Several utility definitions with active space:
{
  \obeyspaces
  \gdef\obeyedspace{ }

  % Make each space character in the input produce a normal interword
  % space in the output.  Don't allow a line break at this space, as this
  % is used only in environments like @example, where each line of input
  % should produce a line of output anyway.
  %
  \gdef\sepspaces{\obeyspaces\let =\tie}

  % If an index command is used in an @example environment, any spaces
  % therein should become regular spaces in the raw index file, not the
  % expansion of \tie (\leavevmode \penalty \@M \ ).
  \gdef\unsepspaces{\let =\space}
}


\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}

% Define the framework for environments in texinfo.tex.  It's used like this:
%
%   \envdef\foo{...}
%   \def\Efoo{...}
%
% It's the responsibility of \envdef to insert \begingroup before the
% actual body; @end closes the group after calling \Efoo.  \envdef also
% defines \thisenv, so the current environment is known; @end checks
% whether the environment name matches.  The \checkenv macro can also be
% used to check whether the current environment is the one expected.
%
% 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
Glenn Morris's avatar
Glenn Morris committed
575 576 577 578
% implementation of @end takes care not to call \endgroup in this
% special case.)


579
% At run-time, environments start with this:
Glenn Morris's avatar
Glenn Morris committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
\def\startenvironment#1{\begingroup\def\thisenv{#1}}
% initialize
\let\thisenv\empty

% ... but they get defined via ``\envdef\foo{...}'':
\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}

% Check whether we're in the right environment:
\def\checkenv#1{%
  \def\temp{#1}%
  \ifx\thisenv\temp
  \else
    \badenverr
  \fi
}

597
% Environment mismatch, #1 expected:
Glenn Morris's avatar
Glenn Morris committed
598 599 600 601 602 603 604
\def\badenverr{%
  \errhelp = \EMsimple
  \errmessage{This command can appear only \inenvironment\temp,
    not \inenvironment\thisenv}%
}
\def\inenvironment#1{%
  \ifx#1\empty
Paul Eggert's avatar
Paul Eggert committed
605
    outside of any environment%
Glenn Morris's avatar
Glenn Morris committed
606 607 608 609 610 611 612 613 614 615 616
  \else
    in environment \expandafter\string#1%
  \fi
}

% @end foo executes the definition of \Efoo.
% But first, it executes a specialized version of \checkenv
%
\parseargdef\end{%
  \if 1\csname iscond.#1\endcsname
  \else
617
    % The general wording of \badenverr may not be ideal.
Glenn Morris's avatar
Glenn Morris committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
    \expandafter\checkenv\csname#1\endcsname
    \csname E#1\endcsname
    \endgroup
  \fi
}

\newhelp\EMsimple{Press RETURN to continue.}


% Be sure we're in horizontal mode when doing a tie, since we make space
% equivalent to this in @example-like environments. Otherwise, a space
% at the beginning of a line will start with \penalty -- and
% since \penalty is valid in vertical mode, we'd end up putting the
% penalty on the vertical list instead of in the new paragraph.
{\catcode`@ = 11
 % Avoid using \@M directly, because that causes trouble
 % if the definition is written into an index file.
 \global\let\tiepenalty = \@M
 \gdef\tie{\leavevmode\penalty\tiepenalty\ }
}

% @: forces normal size whitespace following.
\def\:{\spacefactor=1000 }

% @* forces a line break.
643
\def\*{\unskip\hfil\break\hbox{}\ignorespaces}
Glenn Morris's avatar
Glenn Morris committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657

% @/ allows a line break.
\let\/=\allowbreak

% @. is an end-of-sentence period.
\def\.{.\spacefactor=\endofsentencespacefactor\space}

% @! is an end-of-sentence bang.
\def\!{!\spacefactor=\endofsentencespacefactor\space}

% @? is an end-of-sentence query.
\def\?{?\spacefactor=\endofsentencespacefactor\space}

% @frenchspacing on|off  says whether to put extra space after punctuation.
658
%
Glenn Morris's avatar
Glenn Morris committed
659 660 661 662 663 664 665 666 667
\def\onword{on}
\def\offword{off}
%
\parseargdef\frenchspacing{%
  \def\temp{#1}%
  \ifx\temp\onword \plainfrenchspacing
  \else\ifx\temp\offword \plainnonfrenchspacing
  \else
    \errhelp = \EMsimple
668
    \errmessage{Unknown @frenchspacing option `\temp', must be on|off}%
Glenn Morris's avatar
Glenn Morris committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
  \fi\fi
}

% @w prevents a word break.  Without the \leavevmode, @w at the
% beginning of a paragraph, when TeX is still in vertical mode, would
% produce a whole line of output instead of starting the paragraph.
\def\w#1{\leavevmode\hbox{#1}}

% @group ... @end group forces ... to be all on one page, by enclosing
% it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
% to keep its height that of a normal line.  According to the rules for
% \topskip (p.114 of the TeXbook), the glue inserted is
% max (\topskip - \ht (first item), 0).  If that height is large,
% therefore, no glue is inserted, and the space between the headline and
% the text is small, which looks bad.
%
% Another complication is that the group might be very large.  This can
% cause the glue on the previous page to be unduly stretched, because it
% does not have much material.  In this case, it's better to add an
% explicit \vfill so that the extra space is at the bottom.  The
% threshold for doing this is if the group is more than \vfilllimit
% percent of a page (\vfilllimit can be changed inside of @tex).
%
\newbox\groupbox
\def\vfilllimit{0.7}
%
\envdef\group{%
  \ifnum\catcode`\^^M=\active \else
    \errhelp = \groupinvalidhelp
    \errmessage{@group invalid in context where filling is enabled}%
  \fi
  \startsavinginserts
  %
  \setbox\groupbox = \vtop\bgroup
    % Do @comment since we are called inside an environment such as
    % @example, where each end-of-line in the input causes an
    % end-of-line in the output.  We don't want the end-of-line after
    % the `@group' to put extra space in the output.  Since @group
    % should appear on a line by itself (according to the Texinfo
    % manual), we don't worry about eating any user text.
    \comment
}
%
% The \vtop produces a box with normal height and large depth; thus, TeX puts
% \baselineskip glue before it, and (when the next line of text is done)
% \lineskip glue after it.  Thus, space below is not quite equal to space
% above.  But it's pretty close.
\def\Egroup{%
    % To get correct interline space between the last line of the group
    % and the first line afterwards, we have to propagate \prevdepth.
    \endgraf % Not \par, as it may have been set to \lisppar.
    \global\dimen1 = \prevdepth
  \egroup           % End the \vtop.
Paul Eggert's avatar
Paul Eggert committed
722 723 724 725 726 727
  \addgroupbox
  \prevdepth = \dimen1
  \checkinserts
}

\def\addgroupbox{
Glenn Morris's avatar
Glenn Morris committed
728 729 730
  % \dimen0 is the vertical size of the group's box.
  \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
  % \dimen2 is how much space is left on the page (more or less).
Paul Eggert's avatar
Paul Eggert committed
731
  \dimen2 = \txipageheight   \advance\dimen2 by -\pagetotal
Glenn Morris's avatar
Glenn Morris committed
732 733 734
  % if the group doesn't fit on the current page, and it's a big big
  % group, force a page break.
  \ifdim \dimen0 > \dimen2
Paul Eggert's avatar
Paul Eggert committed
735
    \ifdim \pagetotal < \vfilllimit\txipageheight
Glenn Morris's avatar
Glenn Morris committed
736 737 738 739 740
      \page
    \fi
  \fi
  \box\groupbox
}
Paul Eggert's avatar
Paul Eggert committed
741

Glenn Morris's avatar
Glenn Morris committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
%
% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
% message, so this ends up printing `@group can only ...'.
%
\newhelp\groupinvalidhelp{%
group can only be used in environments such as @example,^^J%
where each line of input produces a line of output.}

% @need space-in-mils
% forces a page break if there is not space-in-mils remaining.

\newdimen\mil  \mil=0.001in

\parseargdef\need{%
  % Ensure vertical mode, so we don't make a big box in the middle of a
  % paragraph.
  \par
  %
  % If the @need value is less than one line space, it's useless.
  \dimen0 = #1\mil
  \dimen2 = \ht\strutbox
  \advance\dimen2 by \dp\strutbox
  \ifdim\dimen0 > \dimen2
    %
    % Do a \strut just to make the height of this box be normal, so the
    % normal leading is inserted relative to the preceding line.
    % And a page break here is fine.
    \vtop to #1\mil{\strut\vfil}%
    %
    % TeX does not even consider page breaks if a penalty added to the
    % main vertical list is 10000 or more.  But in order to see if the
    % empty box we just added fits on the page, we must make it consider
    % page breaks.  On the other hand, we don't want to actually break the
    % page after the empty box.  So we use a penalty of 9999.
    %
    % There is an extremely small chance that TeX will actually break the
    % page at this \penalty, if there are no other feasible breakpoints in
    % sight.  (If the user is using lots of big @group commands, which
    % almost-but-not-quite fill up a page, TeX will have a hard time doing
    % good page breaking, for example.)  However, I could not construct an
    % example where a page broke at this \penalty; if it happens in a real
    % document, then we can reconsider our strategy.
    \penalty9999
    %
    % Back up by the size of the box, whether we did a page break or not.
    \kern -#1\mil
    %
    % Do not allow a page break right after this kern.
    \nobreak
  \fi
}

% @br   forces paragraph break (and is undocumented).

\let\br = \par

% @page forces the start of a new page.
%
\def\page{\par\vfill\supereject}

% @exdent text....
% outputs text on separate line in roman font, starting at standard page margin

% This records the amount of indent in the innermost environment.
% That's how much \exdent should take out.
\newskip\exdentamount

% This defn is used inside fill environments such as @defun.
\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}

% This defn is used inside nofill environments such as @example.
\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
  \leftline{\hskip\leftskip{\rm#1}}}}

% @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
% paragraph.  For more general purposes, use the \margin insertion
818
% class.  WHICH is `l' or `r'.  Not documented, written for gawk manual.
Glenn Morris's avatar
Glenn Morris committed
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
%
\newskip\inmarginspacing \inmarginspacing=1cm
\def\strutdepth{\dp\strutbox}
%
\def\doinmargin#1#2{\strut\vadjust{%
  \nobreak
  \kern-\strutdepth
  \vtop to \strutdepth{%
    \baselineskip=\strutdepth
    \vss
    % if you have multiple lines of stuff to put here, you'll need to
    % make the vbox yourself of the appropriate size.
    \ifx#1l%
      \llap{\ignorespaces #2\hskip\inmarginspacing}%
    \else
      \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
    \fi
    \null
  }%
}}
\def\inleftmargin{\doinmargin l}
\def\inrightmargin{\doinmargin r}
%
% @inmargin{TEXT [, RIGHT-TEXT]}
% (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
% else use TEXT for both).
%
\def\inmargin#1{\parseinmargin #1,,\finish}
\def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
  \setbox0 = \hbox{\ignorespaces #2}%
  \ifdim\wd0 > 0pt
    \def\lefttext{#1}%  have both texts
    \def\righttext{#2}%
  \else
    \def\lefttext{#1}%  have only one text
    \def\righttext{#1}%
  \fi
  %
  \ifodd\pageno
    \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
  \else
    \def\temp{\inleftmargin\lefttext}%
  \fi
  \temp
}

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
% @| inserts a changebar to the left of the current line.  It should
% surround any changed text.  This approach does *not* work if the
% change spans more than two lines of output.  To handle that, we would
% have adopt a much more difficult approach (putting marks into the main
% vertical list for the beginning and end of each change).  This command
% is not documented, not supported, and doesn't work.
%
\def\|{%
  % \vadjust can only be used in horizontal mode.
  \leavevmode
  %
  % Append this vertical mode material after the current line in the output.
  \vadjust{%
    % We want to insert a rule with the height and depth of the current
    % leading; that is exactly what \strutbox is supposed to record.
    \vskip-\baselineskip
    %
    % \vadjust-items are inserted at the left edge of the type.  So
    % the \llap here moves out into the left-hand margin.
    \llap{%
      %
      % For a thicker or thinner bar, change the `1pt'.
      \vrule height\baselineskip width1pt
      %
      % This is the space between the bar and the text.
      \hskip 12pt
    }%
  }%
}

895
% @include FILE -- \input text of FILE.
Glenn Morris's avatar
Glenn Morris committed
896 897 898 899 900 901
%
\def\include{\parseargusing\filenamecatcodes\includezzz}
\def\includezzz#1{%
  \pushthisfilestack
  \def\thisfile{#1}%
  {%
902 903 904
    \makevalueexpandable  % we want to expand any @value in FILE.
    \turnoffactive        % and allow special characters in the expansion
    \indexnofonts         % Allow `@@' and other weird things in file names.
Paul Eggert's avatar
Paul Eggert committed
905
    \wlog{texinfo.tex: doing @include of #1^^J}%
906 907 908 909
    \edef\temp{\noexpand\input #1 }%
    %
    % This trickery is to read FILE outside of a group, in case it makes
    % definitions, etc.
Glenn Morris's avatar
Glenn Morris committed
910 911 912 913 914 915 916 917 918 919 920 921 922 923
    \expandafter
  }\temp
  \popthisfilestack
}
\def\filenamecatcodes{%
  \catcode`\\=\other
  \catcode`~=\other
  \catcode`^=\other
  \catcode`_=\other
  \catcode`|=\other
  \catcode`<=\other
  \catcode`>=\other
  \catcode`+=\other
  \catcode`-=\other
924 925
  \catcode`\`=\other
  \catcode`\'=\other
Glenn Morris's avatar
Glenn Morris committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
}

\def\pushthisfilestack{%
  \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
}
\def\pushthisfilestackX{%
  \expandafter\pushthisfilestackY\thisfile\StackTerm
}
\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
  \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
}

\def\popthisfilestack{\errthisfilestackempty}
\def\errthisfilestackempty{\errmessage{Internal error:
  the stack of filenames is empty.}}
Paul Eggert's avatar
Paul Eggert committed
941
%
Glenn Morris's avatar
Glenn Morris committed
942 943 944 945 946 947 948
\def\thisfile{}

% @center line
% outputs that line, centered.
%
\parseargdef\center{%
  \ifhmode
Paul Eggert's avatar
Paul Eggert committed
949
    \let\centersub\centerH
Glenn Morris's avatar
Glenn Morris committed
950
  \else
Paul Eggert's avatar
Paul Eggert committed
951
    \let\centersub\centerV
Glenn Morris's avatar
Glenn Morris committed
952
  \fi
Paul Eggert's avatar
Paul Eggert committed
953 954
  \centersub{\hfil \ignorespaces#1\unskip \hfil}%
  \let\centersub\relax % don't let the definition persist, just in case
Glenn Morris's avatar
Glenn Morris committed
955
}
Paul Eggert's avatar
Paul Eggert committed
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
\def\centerH#1{{%
  \hfil\break
  \advance\hsize by -\leftskip
  \advance\hsize by -\rightskip
  \line{#1}%
  \break
}}
%
\newcount\centerpenalty
\def\centerV#1{%
  % The idea here is the same as in \startdefun, \cartouche, etc.: if
  % @center is the first thing after a section heading, we need to wipe
  % out the negative parskip inserted by \sectionheading, but still
  % prevent a page break here.
  \centerpenalty = \lastpenalty
  \ifnum\centerpenalty>10000 \vskip\parskip \fi
  \ifnum\centerpenalty>9999 \penalty\centerpenalty \fi
  \line{\kern\leftskip #1\kern\rightskip}%
Glenn Morris's avatar
Glenn Morris committed
974 975 976
}

% @sp n   outputs n lines of vertical space
Paul Eggert's avatar
Paul Eggert committed
977
%
Glenn Morris's avatar
Glenn Morris committed
978 979 980 981 982
\parseargdef\sp{\vskip #1\baselineskip}

% @comment ...line which is ignored...
% @c is the same as @comment
% @ignore ... @end ignore  is another way to write a comment
Paul Eggert's avatar
Paul Eggert committed
983
%
Paul Eggert's avatar
Paul Eggert committed
984 985 986 987 988 989 990 991 992 993
\def\comment{\begingroup \catcode`\^^M=\active%
\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other\commentxxx}%

{\catcode`\^^M=\active%
\gdef\commentxxx#1^^M{\endgroup%
\futurelet\nexttoken\commentxxxx}%
\gdef\commentxxxx{\ifx\nexttoken\aftermacro\expandafter\comment\fi}%
}

\def\c{\begingroup \catcode`\^^M=\active%
Glenn Morris's avatar
Glenn Morris committed
994
\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
Paul Eggert's avatar
Paul Eggert committed
995 996 997
\cxxx}
{\catcode`\^^M=\active \gdef\cxxx#1^^M{\endgroup}}
% See comment in \scanmacro about why the definitions of @c and @comment differ
Glenn Morris's avatar
Glenn Morris committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067

% @paragraphindent NCHARS
% We'll use ems for NCHARS, close enough.
% NCHARS can also be the word `asis' or `none'.
% We cannot feasibly implement @paragraphindent asis, though.
%
\def\asisword{asis} % no translation, these are keywords
\def\noneword{none}
%
\parseargdef\paragraphindent{%
  \def\temp{#1}%
  \ifx\temp\asisword
  \else
    \ifx\temp\noneword
      \defaultparindent = 0pt
    \else
      \defaultparindent = #1em
    \fi
  \fi
  \parindent = \defaultparindent
}

% @exampleindent NCHARS
% We'll use ems for NCHARS like @paragraphindent.
% It seems @exampleindent asis isn't necessary, but
% I preserve it to make it similar to @paragraphindent.
\parseargdef\exampleindent{%
  \def\temp{#1}%
  \ifx\temp\asisword
  \else
    \ifx\temp\noneword
      \lispnarrowing = 0pt
    \else
      \lispnarrowing = #1em
    \fi
  \fi
}

% @firstparagraphindent WORD
% If WORD is `none', then suppress indentation of the first paragraph
% after a section heading.  If WORD is `insert', then do indent at such
% paragraphs.
%
% The paragraph indentation is suppressed or not by calling
% \suppressfirstparagraphindent, which the sectioning commands do.
% We switch the definition of this back and forth according to WORD.
% By default, we suppress indentation.
%
\def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
\def\insertword{insert}
%
\parseargdef\firstparagraphindent{%
  \def\temp{#1}%
  \ifx\temp\noneword
    \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
  \else\ifx\temp\insertword
    \let\suppressfirstparagraphindent = \relax
  \else
    \errhelp = \EMsimple
    \errmessage{Unknown @firstparagraphindent option `\temp'}%
  \fi\fi
}

% Here is how we actually suppress indentation.  Redefine \everypar to
% \kern backwards by \parindent, and then reset itself to empty.
%
% We also make \indent itself not actually do anything until the next
% paragraph.
%
\gdef\dosuppressfirstparagraphindent{%
Paul Eggert's avatar
Paul Eggert committed
1068 1069 1070
  \gdef\indent  {\restorefirstparagraphindent \indent}%
  \gdef\noindent{\restorefirstparagraphindent \noindent}%
  \global\everypar = {\kern -\parindent \restorefirstparagraphindent}%
Glenn Morris's avatar
Glenn Morris committed
1071
}
Paul Eggert's avatar
Paul Eggert committed
1072
%
Glenn Morris's avatar
Glenn Morris committed
1073
\gdef\restorefirstparagraphindent{%
Paul Eggert's avatar
Paul Eggert committed
1074 1075 1076
  \global\let\indent = \ptexindent
  \global\let\noindent = \ptexnoindent
  \global\everypar = {}%
Glenn Morris's avatar
Glenn Morris committed
1077 1078 1079 1080 1081 1082
}


% @refill is a no-op.
\let\refill=\relax

Paul Eggert's avatar
Paul Eggert committed
1083 1084
% @setfilename INFO-FILENAME - ignored
\let\setfilename=\comment
Glenn Morris's avatar
Glenn Morris committed
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101

% @bye.
\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}


\message{pdf,}
% adobe `portable' document format
\newcount\tempnum
\newcount\lnkcount
\newtoks\filename
\newcount\filenamelength
\newcount\pgn
\newtoks\toksA
\newtoks\toksB
\newtoks\toksC
\newtoks\toksD
\newbox\boxA
Paul Eggert's avatar
Paul Eggert committed
1102
\newbox\boxB
Glenn Morris's avatar
Glenn Morris committed
1103 1104 1105 1106
\newcount\countA
\newif\ifpdf
\newif\ifpdfmakepagedest

Paul Eggert's avatar
Paul Eggert committed
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
%
% For LuaTeX
%

\ifx\luatexversion\thisisundefined
\else
  % Escape PDF strings UTF-8 to UTF-16
  \begingroup
    \catcode`\%=12
    \directlua{
      function UTF16oct(str)
        tex.sprint(string.char(0x5c) .. '376' .. string.char(0x5c) .. '377')
        for c in string.utfvalues(str) do
          if c < 0x10000 then
            tex.sprint(
              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
                            string.char(0x5c) .. string.char(0x25) .. '03o',
                            (c / 256), (c % 256)))
          else
            c = c - 0x10000
            local c_hi = c / 1024 + 0xd800
            local c_lo = c % 1024 + 0xdc00
            tex.sprint(
              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
                            string.char(0x5c) .. string.char(0x25) .. '03o',
                            (c_hi / 256), (c_hi % 256),
                            (c_lo / 256), (c_lo % 256)))
          end
        end
      end
    }
  \endgroup
  \def\pdfescapestring#1{\directlua{UTF16oct('\luaescapestring{#1}')}}
  \ifnum\luatexversion>84
    % For LuaTeX >= 0.85
    \def\pdfdest{\pdfextension dest}
    \let\pdfoutput\outputmode
    \def\pdfliteral{\pdfextension literal}
    \def\pdfcatalog{\pdfextension catalog}
    \def\pdftexversion{\numexpr\pdffeedback version\relax}
    \let\pdfximage\saveimageresource
    \let\pdfrefximage\useimageresource
    \let\pdflastximage\lastsavedimageresourceindex
    \def\pdfendlink{\pdfextension endlink\relax}
    \def\pdfoutline{\pdfextension outline}
    \def\pdfstartlink{\pdfextension startlink}
    \def\pdffontattr{\pdfextension fontattr}
    \def\pdfobj{\pdfextension obj}
    \def\pdflastobj{\numexpr\pdffeedback lastobj\relax}
    \let\pdfpagewidth\pagewidth
    \let\pdfpageheight\pageheight
    \edef\pdfhorigin{\pdfvariable horigin}
    \edef\pdfvorigin{\pdfvariable vorigin}
  \fi
\fi

Glenn Morris's avatar
Glenn Morris committed
1165
% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
1166 1167
% can be set).  So we test for \relax and 0 as well as being undefined.
\ifx\pdfoutput\thisisundefined
Glenn Morris's avatar
Glenn Morris committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
\else
  \ifx\pdfoutput\relax
  \else
    \ifcase\pdfoutput
    \else
      \pdftrue
    \fi
  \fi
\fi

% PDF uses PostScript string constants for the names of xref targets,
% for display in the outlines, and in other places.  Thus, we have to
% double any backslashes.  Otherwise, a name like "\node" will be
% interpreted as a newline (\n), followed by o, d, e.  Not good.
Paul Eggert's avatar
Paul Eggert committed
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
% 
% See http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html and
% related messages.  The final outcome is that it is up to the TeX user
% to double the backslashes and otherwise make the string valid, so
% that's what we do.  pdftex 1.30.0 (ca.2005) introduced a primitive to
% do this reliably, so we use it.

% #1 is a control sequence in which to do the replacements,
% which we \xdef.
\def\txiescapepdf#1{%
1192
  \ifx\pdfescapestring\thisisundefined
Paul Eggert's avatar
Paul Eggert committed
1193 1194
    % No primitive available; should we give a warning or log?
    % Many times it won't matter.
Paul Eggert's avatar
Paul Eggert committed
1195
    \xdef#1{#1}%
Paul Eggert's avatar
Paul Eggert committed
1196 1197 1198 1199 1200
  \else
    % The expandable \pdfescapestring primitive escapes parentheses,
    % backslashes, and other special chars.
    \xdef#1{\pdfescapestring{#1}}%
  \fi
Glenn Morris's avatar
Glenn Morris committed
1201 1202 1203 1204 1205 1206 1207 1208
}

\newhelp\nopdfimagehelp{Texinfo supports .png, .jpg, .jpeg, and .pdf images
with PDF output, and none of those formats could be found.  (.eps cannot
be supported due to the design of the PDF format; use regular TeX (DVI
output) for that.)}

\ifpdf
1209
  %
Paul Eggert's avatar
Paul Eggert committed
1210
  % Color manipulation macros using ideas from pdfcolor.tex,
1211 1212
  % except using rgb instead of cmyk; the latter is said to render as a
  % very dark gray on-screen and a very dark halftone in print, instead
Paul Eggert's avatar
Paul Eggert committed
1213 1214 1215
  % of actual black. The dark red here is dark enough to print on paper as
  % nearly black, but still distinguishable for online viewing.  We use
  % black by default, though.
1216 1217 1218
  \def\rgbDarkRed{0.50 0.09 0.12}
  \def\rgbBlack{0 0 0}
  %
Paul Eggert's avatar
Paul Eggert committed
1219 1220
  % rg sets the color for filling (usual text, etc.);
  % RG sets the color for stroking (thin rules, e.g., normal _'s).
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
  \def\pdfsetcolor#1{\pdfliteral{#1 rg  #1 RG}}
  %
  % Set color, and create a mark which defines \thiscolor accordingly,
  % so that \makeheadline knows which color to restore.
  \def\setcolor#1{%
    \xdef\lastcolordefs{\gdef\noexpand\thiscolor{#1}}%
    \domark
    \pdfsetcolor{#1}%
  }
  %
  \def\maincolor{\rgbBlack}
  \pdfsetcolor{\maincolor}
  \edef\thiscolor{\maincolor}
  \def\lastcolordefs{}
  %
  \def\makefootline{%
    \baselineskip24pt
    \line{\pdfsetcolor{\maincolor}\the\footline}%
  }
  %
  \def\makeheadline{%
    \vbox to 0pt{%
      \vskip-22.5pt
      \line{%
        \vbox to8.5pt{}%
        % Extract \thiscolor definition from the marks.
        \getcolormarks
        % Typeset the headline with \maincolor, then restore the color.
        \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
      }%
      \vss
    }%
    \nointerlineskip
  }
  %
  %
Glenn Morris's avatar
Glenn Morris committed
1257 1258 1259 1260
  \pdfcatalog{/PageMode /UseOutlines}
  %
  % #1 is image name, #2 width (might be empty/whitespace), #3 height (ditto).
  \def\dopdfimage#1#2#3{%
Paul Eggert's avatar
Paul Eggert committed
1261 1262
    \def\pdfimagewidth{#2}\setbox0 = \hbox{\ignorespaces #2}%
    \def\pdfimageheight{#3}\setbox2 = \hbox{\ignorespaces #3}%
Glenn Morris's avatar
Glenn Morris committed
1263
    %
Paul Eggert's avatar
Paul Eggert committed
1264 1265 1266 1267
    % pdftex (and the PDF format) support .pdf, .png, .jpg (among
    % others).  Let's try in that order, PDF first since if
    % someone has a scalable image, presumably better to use that than a
    % bitmap.
Glenn Morris's avatar
Glenn Morris committed
1268 1269
    \let\pdfimgext=\empty
    \begingroup
Paul Eggert's avatar
Paul Eggert committed
1270 1271 1272 1273 1274 1275
      \openin 1 #1.pdf \ifeof 1
        \openin 1 #1.PDF \ifeof 1
          \openin 1 #1.png \ifeof 1
            \openin 1 #1.jpg \ifeof 1
              \openin 1 #1.jpeg \ifeof 1
                \openin 1 #1.JPG \ifeof 1
1276 1277
                  \errhelp = \nopdfimagehelp
                  \errmessage{Could not find image file #1 for pdf}%
Paul Eggert's avatar
Paul Eggert committed
1278
                \else \gdef\pdfimgext{JPG}%
1279
                \fi
Paul Eggert's avatar
Paul Eggert committed
1280
              \else \gdef\pdfimgext{jpeg}%
Glenn Morris's avatar
Glenn Morris committed
1281
              \fi
Paul Eggert's avatar
Paul Eggert committed
1282
            \else \gdef\pdfimgext{jpg}%
Glenn Morris's avatar
Glenn Morris committed
1283
            \fi
Paul Eggert's avatar
Paul Eggert committed
1284
          \else \gdef\pdfimgext{png}%
Glenn Morris's avatar
Glenn Morris committed
1285
          \fi
Paul Eggert's avatar
Paul Eggert committed
1286
        \else \gdef\pdfimgext{PDF}%
Glenn Morris's avatar
Glenn Morris committed
1287
        \fi
Paul Eggert's avatar
Paul Eggert committed
1288
      \else \gdef\pdfimgext{pdf}%
Glenn Morris's avatar
Glenn Morris committed
1289 1290 1291 1292
      \fi
      \closein 1
    \endgroup
    %
1293
    % without \immediate, ancient pdftex seg faults when the same image is
Glenn Morris's avatar
Glenn Morris committed
1294 1295 1296 1297 1298 1299
    % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
    \ifnum\pdftexversion < 14
      \immediate\pdfimage
    \else
      \immediate\pdfximage
    \fi
Paul Eggert's avatar
Paul Eggert committed
1300 1301
      \ifdim \wd0 >0pt width \pdfimagewidth \fi
      \ifdim \wd2 >0pt height \pdfimageheight \fi
Glenn Morris's avatar
Glenn Morris committed
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
      \ifnum\pdftexversion<13
         #1.\pdfimgext
       \else
         {#1.\pdfimgext}%
       \fi
    \ifnum\pdftexversion < 14 \else
      \pdfrefximage \pdflastximage
    \fi}
  %
  \def\pdfmkdest#1{{%
    % We have to set dummies so commands such as @code, and characters
    % such as \, aren't expanded when present in a section title.
    \indexnofonts
    \makevalueexpandable
Paul Eggert's avatar
Paul Eggert committed
1316 1317 1318
    \turnoffactive
    % Use ASCII approximations in destination names.
    \passthroughcharsfalse
Glenn Morris's avatar
Glenn Morris committed
1319
    \def\pdfdestname{#1}%
Paul Eggert's avatar
Paul Eggert committed
1320
    \txiescapepdf\pdfdestname
Glenn Morris's avatar
Glenn Morris committed
1321 1322 1323 1324 1325 1326
    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
  }}
  %
  % used to mark target names; must be expandable.
  \def\pdfmkpgn#1{#1}
  %
Paul Eggert's avatar
Paul Eggert committed
1327 1328 1329
  % by default, use black for everything.
  \def\urlcolor{\rgbBlack}
  \def\linkcolor{\rgbBlack}
1330
  \def\endlink{\setcolor{\maincolor}\pdfendlink}
Glenn Morris's avatar
Glenn Morris committed
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
  %
  % Adding outlines to PDF; macros for calculating structure of outlines
  % come from Petr Olsak
  \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
    \else \csname#1\endcsname \fi}
  \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
    \advance\tempnum by 1
    \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
  %
  % #1 is the section text, which is what will be displayed in the
  % outline by the pdf viewer.  #2 is the pdf expression for the number
  % of subentries (or empty, for subsubsections).  #3 is the node text,
  % which might be empty if this toc entry had no corresponding node.
  % #4 is the page number
  %
  \def\dopdfoutline#1#2#3#4{%
    % Generate a link to the node text if that exists; else, use the
    % page number.  We could generate a destination for the section
    % text in the case where a section has no node, but it doesn't
    % seem worth the trouble, since most documents are normally structured.
Paul Eggert's avatar
Paul Eggert committed
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
    {
      \ifx\luatexversion\thisisundefined \else
        \turnoffactive % LuaTeX can use Unicode strings for PDF
      \fi
      \edef\pdfoutlinedest{#3}%
      \ifx\pdfoutlinedest\empty
        \def\pdfoutlinedest{#4}%
      \else
        \txiescapepdf\pdfoutlinedest
      \fi
      %
      % Also escape PDF chars in the display string.
Paul Eggert's avatar
Paul Eggert committed
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
      \bgroup
        \ifx \declaredencoding \latone
          % The PDF format can use an extended form of Latin-1 in bookmark
          % strings.  See Appendix D of the PDF Reference, Sixth Edition, for
          % the "PDFDocEncoding".
          \passthroughcharstrue
        \fi
        \ifx \declaredencoding \utfeight
          % TODO: the PDF format can use UTF-16 in bookmark strings, but the
          % code for this isn't done yet.
        \fi
        \globaldefs=1
        \edef\pdfoutlinetext{#1}%
        \txiescapepdf\pdfoutlinetext
      \egroup
Paul Eggert's avatar
Paul Eggert committed
1378 1379 1380
      %
      \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
    }
Glenn Morris's avatar
Glenn Morris committed
1381 1382 1383 1384 1385
  }
  %
  \def\pdfmakeoutlines{%
    \begingroup
      % Read toc silently, to get counts of subentries for \pdfoutline.
1386
      \def\partentry##1##2##3##4{}% ignore parts in the outlines
Glenn Morris's avatar
Glenn Morris committed
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
      \def\numchapentry##1##2##3##4{%
	\def\thischapnum{##2}%
	\def\thissecnum{0}%
	\def\thissubsecnum{0}%
      }%
      \def\numsecentry##1##2##3##4{%
	\advancenumber{chap\thischapnum}%
	\def\thissecnum{##2}%
	\def\thissubsecnum{0}%
      }%
      \def\numsubsecentry##1##2##3##4{%
	\advancenumber{sec\thissecnum}%
	\def\thissubsecnum{##2}%
      }%
      \def\numsubsubsecentry##1##2##3##4{%
	\advancenumber{subsec\thissubsecnum}%
      }%
      \def\thischapnum{0}%
      \def\thissecnum{0}%
      \def\thissubsecnum{0}%
      %
      % use \def rather than \let here because we redefine \chapentry et
      % al. a second time, below.
      \def\appentry{\numchapentry}%
      \def\appsecentry{\numsecentry}%
      \def\appsubsecentry{\numsubsecentry}%
      \def\appsubsubsecentry{\numsubsubsecentry}%
      \def\unnchapentry{\numchapentry}%
      \def\unnsecentry{\numsecentry}%
      \def\unnsubsecentry{\numsubsecentry}%
      \def\unnsubsubsecentry{\numsubsubsecentry}%
      \readdatafile{toc}%
      %
      % Read toc second time, this time actually producing the outlines.
      % The `-' means take the \expnumber as the absolute number of
      % subentries, which we calculated on our first read of the .toc above.
      %
      % We use the node names as the destinations.
      \def\numchapentry##1##2##3##4{%
        \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
      \def\numsecentry##1##2##3##4{%
        \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
      \def\numsubsecentry##1##2##3##4{%
        \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
      \def\numsubsubsecentry##1##2##3##4{% count is always zero
        \dopdfoutline{##1}{}{##3}{##4}}%
      %
      % PDF outlines are displayed using system fonts, instead of
      % document fonts.  Therefore we cannot use special characters,
      % since the encoding is unknown.  For example, the eogonek from
      % Latin 2 (0xea) gets translated to a | character.  Info from
      % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
      %
Paul Eggert's avatar
Paul Eggert committed
1440 1441 1442 1443 1444
      % TODO this right, we have to translate 8-bit characters to
      % their "best" equivalent, based on the @documentencoding.  Too
      % much work for too little return.  Just use the ASCII equivalents
      % we use for the index sort strings.
      % 
Glenn Morris's avatar
Glenn Morris committed
1445 1446
      \indexnofonts
      \setupdatafile
Paul Eggert's avatar
Paul Eggert committed
1447 1448 1449 1450
      % We can have normal brace characters in the PDF outlines, unlike
      % Texinfo index files.  So set that up.
      \def\{{\lbracecharliteral}%
      \def\}{\rbracecharliteral}%
Glenn Morris's avatar
Glenn Morris committed
1451 1452 1453 1454
      \catcode`\\=\active \otherbackslash
      \input \tocreadfilename
    \endgroup
  }
Paul Eggert's avatar
Paul Eggert committed
1455 1456 1457 1458 1459
  {\catcode`[=1 \catcode`]=2
   \catcode`{=\other \catcode`}=\other
   \gdef\lbracecharliteral[{]%
   \gdef\rbracecharliteral[}]%
  ]
Glenn Morris's avatar
Glenn Morris committed
1460 1461 1462 1463
  %
  \def\skipspaces#1{\def\PP{#1}\def\D{|}%
    \ifx\PP\D\let\nextsp\relax
    \else\let\nextsp\skipspaces
Paul Eggert's avatar
Paul Eggert committed
1464 1465
      \addtokens{\filename}{\PP}%
      \advance\filenamelength by 1
Glenn Morris's avatar
Glenn Morris committed
1466 1467
    \fi
    \nextsp}
Paul Eggert's avatar
Paul Eggert committed
1468 1469 1470 1471 1472 1473 1474
  \def\getfilename#1{%
    \filenamelength=0
    % If we don't expand the argument now, \skipspaces will get
    % snagged on things like "@value{foo}".
    \edef\temp{#1}%
    \expandafter\skipspaces\temp|\relax
  }
Glenn Morris's avatar
Glenn Morris committed
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
  \ifnum\pdftexversion < 14
    \let \startlink \pdfannotlink
  \else
    \let \startlink \pdfstartlink
  \fi
  % make a live url in pdf output.
  \def\pdfurl#1{%
    \begingroup
      % it seems we really need yet another set of dummies; have not
      % tried to figure out what each command should do in the context
      % of @url.  for now, just make @/ a no-op, that's the only one
      % people have actually reported a problem with.
1487
      %
Glenn Morris's avatar
Glenn Morris committed
1488 1489 1490 1491
      \normalturnoffactive
      \def\@{@}%
      \let\/=\empty
      \makevalueexpandable
1492 1493 1494 1495 1496
      % do we want to go so far as to use \indexnofonts instead of just
      % special-casing \var here?
      \def\var##1{##1}%
      %
      \leavevmode\setcolor{\urlcolor}%
Glenn Morris's avatar
Glenn Morris committed
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
      \startlink attr{/Border [0 0 0]}%
        user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
    \endgroup}
  \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
  \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
  \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
  \def\maketoks{%
    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
    \ifx\first0\adn0
    \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
    \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
    \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
    \else
      \ifnum0=\countA\else\makelink\fi
      \ifx\first.\let\next=\done\else
        \let\next=\maketoks
        \addtokens{\toksB}{\the\toksD}
        \ifx\first,\addtokens{\toksB}{\space}\fi
      \fi
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \next}
  \def\makelink{\addtokens{\toksB}%
    {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
  \def\pdflink#1{%
    \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
1523
    \setcolor{\linkcolor}#1\endlink}
Glenn Morris's avatar
Glenn Morris committed
1524 1525
  \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
\else
1526
  % non-pdf mode
Glenn Morris's avatar
Glenn Morris committed
1527 1528 1529
  \let\pdfmkdest = \gobble
  \let\pdfurl = \gobble
  \let\endlink = \relax
1530 1531
  \let\setcolor = \gobble
  \let\pdfsetcolor = \gobble
Glenn Morris's avatar
Glenn Morris committed
1532 1533 1534
  \let\pdfmakeoutlines = \relax
\fi  % \ifx\pdfoutput

Paul Eggert's avatar
Paul Eggert committed
1535
%
Paul Eggert's avatar
Paul Eggert committed
1536
% For XeTeX
Paul Eggert's avatar
Paul Eggert committed
1537
%
Paul Eggert's avatar
Paul Eggert committed
1538
\newif\iftxiuseunicodedestname
Paul Eggert's avatar
Paul Eggert committed
1539 1540
\ifx\XeTeXrevision\thisisundefined
\else
Paul Eggert's avatar
Paul Eggert committed
1541 1542 1543
  %
  % XeTeX version check
  %
Paul Eggert's avatar
Paul Eggert committed
1544 1545 1546 1547 1548 1549 1550 1551
  \ifnum\strcmp{\the\XeTeXversion\XeTeXrevision}{0.99996}>-1
    % TeX Live 2016 contains XeTeX 0.99996 and xdvipdfmx 20160307.
    % It can use the `dvipdfmx:config' special (from TeX Live SVN r40941).
    % For avoiding PDF destination name replacement, we use this special
    % instead of xdvipdfmx's command line option `-C 0x0010'.
    \special{dvipdfmx:config C 0x0010}
    % XeTeX 0.99995+ comes with xdvipdfmx 20160307+.
    % It can handle Unicode destination names for PDF.
Paul Eggert's avatar
Paul Eggert committed
1552 1553
    \txiuseunicodedestnametrue
  \else
Paul Eggert's avatar
Paul Eggert committed
1554 1555 1556 1557 1558 1559 1560 1561
    % XeTeX < 0.99996 (TeX Live < 2016) cannot use the
    % `dvipdfmx:config' special.
    % So for avoiding PDF destination name replacement,
    % xdvipdfmx's command line option `-C 0x0010' is necessary.
    %
    % XeTeX < 0.99995 can not handle Unicode destination names for PDF
    % because xdvipdfmx 20150315 has a UTF-16 conversion issue.
    % It is fixed by xdvipdfmx 20160106 (TeX Live SVN r39753).
Paul Eggert's avatar
Paul Eggert committed
1562 1563 1564
    \txiuseunicodedestnamefalse
  \fi
  %
Paul Eggert's avatar
Paul Eggert committed
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
  % Color support
  %
  \def\rgbDarkRed{0.50 0.09 0.12}
  \def\rgbBlack{0 0 0}
  %
  \def\pdfsetcolor#1{\special{pdf:scolor [#1]}}
  %
  % Set color, and create a mark which defines \thiscolor accordingly,
  % so that \makeheadline knows which color to restore.
  \def\setcolor#1{%
    \xdef\lastcolordefs{\gdef\noexpand\thiscolor{#1}}%
    \domark
    \pdfsetcolor{#1}%
  }
  %
  \def\maincolor{\rgbBlack}
  \pdfsetcolor{\maincolor}
  \edef\thiscolor{\maincolor}
  \def\lastcolordefs{}
  %
  \def\makefootline{%
    \baselineskip24pt
    \line{\pdfsetcolor{\maincolor}\the\footline}%
  }
  %
  \def\makeheadline{%
    \vbox to 0pt{%
      \vskip-22.5pt
      \line{%
        \vbox to8.5pt{}%
        % Extract \thiscolor definition from the marks.
        \getcolormarks
        % Typeset the headline with \maincolor, then restore the color.
        \pdfsetcolor{\maincolor}\the\headline\pdfsetcolor{\thiscolor}%
      }%
      \vss
    }%
    \nointerlineskip
  }
  %
Paul Eggert's avatar
Paul Eggert committed
1605 1606
  % PDF outline support
  %
Paul Eggert's avatar
Paul Eggert committed
1607
  % Emulate pdfTeX primitive
Paul Eggert's avatar
Paul Eggert committed
1608
  \def\pdfdest name#1 xyz{%
Paul Eggert's avatar
Paul Eggert committed
1609
    \special{pdf:dest (#1) [@thispage /XYZ @xpos @ypos null]}%
Paul Eggert's avatar
Paul Eggert committed
1610 1611 1612 1613
  }
  \def\pdfmkdest#1{{%
    % We have to set dummies so commands such as @code, and characters
    % such as \, aren't expanded when present in a section title.
Paul Eggert's avatar
Paul Eggert committed
1614 1615 1616 1617
    \indexnofonts
    \iftxiuseunicodedestname
      \def\pdfdestname{#1}% Pass through Unicode characters.
    \else
Paul Eggert's avatar
Paul Eggert committed
1618
      \edef\pdfdestname{#1}% Replace Unicode characters with ASCII.
Paul Eggert's avatar
Paul Eggert committed
1619 1620
    \fi
    \turnoffactive
Paul Eggert's avatar
Paul Eggert committed
1621
    \makevalueexpandable
Paul Eggert's avatar
Paul Eggert committed
1622
    \txiescapepdf\pdfdestname
Paul Eggert's avatar
Paul Eggert committed
1623
    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
Paul Eggert's avatar
Paul Eggert committed
1624 1625
  }}
  %
Paul Eggert's avatar
Paul Eggert committed
1626 1627 1628 1629 1630
  % by default, use black for everything.
  \def\urlcolor{\rgbBlack}
  \def\linkcolor{\rgbBlack}
  \def\endlink{\setcolor{\maincolor}\pdfendlink}
  %
Paul Eggert's avatar
Paul Eggert committed
1631
  \def\dopdfoutline#1#2#3#4{%
Paul Eggert's avatar
Paul Eggert committed
1632 1633 1634
    \iftxiuseunicodedestname
      \def\pdfoutlinedest{#3}% Pass through Unicode characters.
    \else
Paul Eggert's avatar
Paul Eggert committed