alpar@464: % texinfo.tex -- TeX macros to handle Texinfo files.
alpar@464: %
alpar@464: % Load plain if necessary, i.e., if running under initex.
alpar@464: \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
alpar@464: %
alpar@464: \def\texinfoversion{2003-07-28.08}
alpar@464: %
alpar@464: % Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
alpar@464: % 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
alpar@464: %
alpar@464: % This texinfo.tex file is free software; you can redistribute it and/or
alpar@464: % modify it under the terms of the GNU General Public License as
alpar@464: % published by the Free Software Foundation; either version 2, or (at
alpar@464: % your option) any later version.
alpar@464: %
alpar@464: % This texinfo.tex file is distributed in the hope that it will be
alpar@464: % useful, but WITHOUT ANY WARRANTY; without even the implied warranty
alpar@464: % of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
alpar@464: % General Public License for more details.
alpar@464: %
alpar@464: % You should have received a copy of the GNU General Public License
alpar@464: % along with this texinfo.tex file; see the file COPYING.  If not, write
alpar@464: % to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
alpar@464: % Boston, MA 02111-1307, USA.
alpar@464: %
alpar@464: % In other words, you are welcome to use, share and improve this program.
alpar@464: % You are forbidden to forbid anyone else to use, share and improve
alpar@464: % what you give them.   Help stamp out software-hoarding!
alpar@464: %
alpar@464: % Please try the latest version of texinfo.tex before submitting bug
alpar@464: % reports; you can get the latest version from:
alpar@464: %   ftp://ftp.gnu.org/gnu/texinfo/texinfo.tex
alpar@464: %     (and all GNU mirrors, see http://www.gnu.org/order/ftp.html)
alpar@464: %   ftp://tug.org/tex/texinfo.tex
alpar@464: %     (and all CTAN mirrors, see http://www.ctan.org),
alpar@464: %   and /home/gd/gnu/doc/texinfo.tex on the GNU machines.
alpar@464: %
alpar@464: % The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
alpar@464: %
alpar@464: % The texinfo.tex in any given Texinfo distribution could well be out
alpar@464: % of date, so if that's what you're using, please check.
alpar@464: %
alpar@464: % Send bug reports to bug-texinfo@gnu.org.  Please include including a
alpar@464: % complete document in each bug report with which we can reproduce the
alpar@464: % problem.  Patches are, of course, greatly appreciated.
alpar@464: %
alpar@464: % To process a Texinfo manual with TeX, it's most reliable to use the
alpar@464: % texi2dvi shell script that comes with the distribution.  For a simple
alpar@464: % manual foo.texi, however, you can get away with this:
alpar@464: %   tex foo.texi
alpar@464: %   texindex foo.??
alpar@464: %   tex foo.texi
alpar@464: %   tex foo.texi
alpar@464: %   dvips foo.dvi -o  # or whatever; this makes foo.ps.
alpar@464: % The extra TeX runs get the cross-reference information correct.
alpar@464: % Sometimes one run after texindex suffices, and sometimes you need more
alpar@464: % than two; texi2dvi does it as many times as necessary.
alpar@464: %
alpar@464: % It is possible to adapt texinfo.tex for other languages, to some
alpar@464: % extent.  You can get the existing language-specific files from the
alpar@464: % full Texinfo distribution.
alpar@464: 
alpar@464: \message{Loading texinfo [version \texinfoversion]:}
alpar@464: 
alpar@464: % If in a .fmt file, print the version number
alpar@464: % and turn on active characters that we couldn't do earlier because
alpar@464: % they might have appeared in the input file name.
alpar@464: \everyjob{\message{[Texinfo version \texinfoversion]}%
alpar@464:   \catcode`+=\active \catcode`\_=\active}
alpar@464: 
alpar@464: \message{Basics,}
alpar@464: \chardef\other=12
alpar@464: 
alpar@464: % We never want plain's \outer definition of \+ in Texinfo.
alpar@464: % For @tex, we can use \tabalign.
alpar@464: \let\+ = \relax
alpar@464: 
alpar@464: % Save some plain tex macros whose names we will redefine.
alpar@464: \let\ptexb=\b
alpar@464: \let\ptexbullet=\bullet
alpar@464: \let\ptexc=\c
alpar@464: \let\ptexcomma=\,
alpar@464: \let\ptexdot=\.
alpar@464: \let\ptexdots=\dots
alpar@464: \let\ptexend=\end
alpar@464: \let\ptexequiv=\equiv
alpar@464: \let\ptexexclam=\!
alpar@464: \let\ptexgtr=>
alpar@464: \let\ptexhat=^
alpar@464: \let\ptexi=\i
alpar@464: \let\ptexindent=\indent
alpar@464: \let\ptexlbrace=\{
alpar@464: \let\ptexless=<
alpar@464: \let\ptexplus=+
alpar@464: \let\ptexrbrace=\}
alpar@464: \let\ptexslash=\/
alpar@464: \let\ptexstar=\*
alpar@464: \let\ptext=\t
alpar@464: 
alpar@464: % If this character appears in an error message or help string, it
alpar@464: % starts a new line in the output.
alpar@464: \newlinechar = `^^J
alpar@464: 
alpar@464: % Set up fixed words for English if not already set.
alpar@464: \ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
alpar@464: \ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
alpar@464: \ifx\putwordfile\undefined      \gdef\putwordfile{file}\fi
alpar@464: \ifx\putwordin\undefined        \gdef\putwordin{in}\fi
alpar@464: \ifx\putwordIndexIsEmpty\undefined     \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
alpar@464: \ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
alpar@464: \ifx\putwordInfo\undefined      \gdef\putwordInfo{Info}\fi
alpar@464: \ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
alpar@464: \ifx\putwordMethodon\undefined  \gdef\putwordMethodon{Method on}\fi
alpar@464: \ifx\putwordNoTitle\undefined   \gdef\putwordNoTitle{No Title}\fi
alpar@464: \ifx\putwordof\undefined        \gdef\putwordof{of}\fi
alpar@464: \ifx\putwordon\undefined        \gdef\putwordon{on}\fi
alpar@464: \ifx\putwordpage\undefined      \gdef\putwordpage{page}\fi
alpar@464: \ifx\putwordsection\undefined   \gdef\putwordsection{section}\fi
alpar@464: \ifx\putwordSection\undefined   \gdef\putwordSection{Section}\fi
alpar@464: \ifx\putwordsee\undefined       \gdef\putwordsee{see}\fi
alpar@464: \ifx\putwordSee\undefined       \gdef\putwordSee{See}\fi
alpar@464: \ifx\putwordShortTOC\undefined  \gdef\putwordShortTOC{Short Contents}\fi
alpar@464: \ifx\putwordTOC\undefined       \gdef\putwordTOC{Table of Contents}\fi
alpar@464: %
alpar@464: \ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
alpar@464: \ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
alpar@464: \ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
alpar@464: \ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
alpar@464: \ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
alpar@464: \ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
alpar@464: \ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
alpar@464: \ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
alpar@464: \ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
alpar@464: \ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
alpar@464: \ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
alpar@464: \ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
alpar@464: %
alpar@464: \ifx\putwordDefmac\undefined    \gdef\putwordDefmac{Macro}\fi
alpar@464: \ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
alpar@464: \ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
alpar@464: \ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
alpar@464: \ifx\putwordDeftypevar\undefined\gdef\putwordDeftypevar{Variable}\fi
alpar@464: \ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
alpar@464: \ifx\putwordDeftypefun\undefined\gdef\putwordDeftypefun{Function}\fi
alpar@464: 
alpar@464: % In some macros, we cannot use the `\? notation---the left quote is
alpar@464: % in some cases the escape char.
alpar@464: \chardef\colonChar = `\:
alpar@464: \chardef\commaChar = `\,
alpar@464: \chardef\dotChar   = `\.
alpar@464: \chardef\equalChar = `\=
alpar@464: \chardef\exclamChar= `\!
alpar@464: \chardef\questChar = `\?
alpar@464: \chardef\semiChar  = `\;
alpar@464: \chardef\spaceChar = `\ %
alpar@464: \chardef\underChar = `\_
alpar@464: 
alpar@464: % Ignore a token.
alpar@464: %
alpar@464: \def\gobble#1{}
alpar@464: 
alpar@464: % True if #1 is the empty string, i.e., called like `\ifempty{}'.
alpar@464: %
alpar@464: \def\ifempty#1{\ifemptyx #1\emptymarkA\emptymarkB}%
alpar@464: \def\ifemptyx#1#2\emptymarkB{\ifx #1\emptymarkA}%
alpar@464: 
alpar@464: % Hyphenation fixes.
alpar@464: \hyphenation{ap-pen-dix}
alpar@464: \hyphenation{eshell}
alpar@464: \hyphenation{mini-buf-fer mini-buf-fers}
alpar@464: \hyphenation{time-stamp}
alpar@464: \hyphenation{white-space}
alpar@464: 
alpar@464: % Margin to add to right of even pages, to left of odd pages.
alpar@464: \newdimen\bindingoffset
alpar@464: \newdimen\normaloffset
alpar@464: \newdimen\pagewidth \newdimen\pageheight
alpar@464: 
alpar@464: % Sometimes it is convenient to have everything in the transcript file
alpar@464: % and nothing on the terminal.  We don't just call \tracingall here,
alpar@464: % since that produces some useless output on the terminal.  We also make
alpar@464: % some effort to order the tracing commands to reduce output in the log
alpar@464: % file; cf. trace.sty in LaTeX.
alpar@464: %
alpar@464: \def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
alpar@464: \def\loggingall{%
alpar@464:   \tracingstats2
alpar@464:   \tracingpages1
alpar@464:   \tracinglostchars2  % 2 gives us more in etex
alpar@464:   \tracingparagraphs1
alpar@464:   \tracingoutput1
alpar@464:   \tracingmacros2
alpar@464:   \tracingrestores1
alpar@464:   \showboxbreadth\maxdimen \showboxdepth\maxdimen
alpar@464:   \ifx\eTeXversion\undefined\else % etex gives us more logging
alpar@464:     \tracingscantokens1
alpar@464:     \tracingifs1
alpar@464:     \tracinggroups1
alpar@464:     \tracingnesting2
alpar@464:     \tracingassigns1
alpar@464:   \fi
alpar@464:   \tracingcommands3  % 3 gives us more in etex
alpar@464:   \errorcontextlines\maxdimen
alpar@464: }%
alpar@464: 
alpar@464: % add check for \lastpenalty to plain's definitions.  If the last thing
alpar@464: % we did was a \nobreak, we don't want to insert more space.
alpar@464: %
alpar@464: \def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
alpar@464:   \removelastskip\penalty-50\smallskip\fi\fi}
alpar@464: \def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
alpar@464:   \removelastskip\penalty-100\medskip\fi\fi}
alpar@464: \def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
alpar@464:   \removelastskip\penalty-200\bigskip\fi\fi}
alpar@464: 
alpar@464: % For @cropmarks command.
alpar@464: % Do @cropmarks to get crop marks.
alpar@464: %
alpar@464: \newif\ifcropmarks
alpar@464: \let\cropmarks = \cropmarkstrue
alpar@464: %
alpar@464: % Dimensions to add cropmarks at corners.
alpar@464: % Added by P. A. MacKay, 12 Nov. 1986
alpar@464: %
alpar@464: \newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
alpar@464: \newdimen\cornerlong  \cornerlong=1pc
alpar@464: \newdimen\cornerthick \cornerthick=.3pt
alpar@464: \newdimen\topandbottommargin \topandbottommargin=.75in
alpar@464: 
alpar@464: % Main output routine.
alpar@464: \chardef\PAGE = 255
alpar@464: \output = {\onepageout{\pagecontents\PAGE}}
alpar@464: 
alpar@464: \newbox\headlinebox
alpar@464: \newbox\footlinebox
alpar@464: 
alpar@464: % \onepageout takes a vbox as an argument.  Note that \pagecontents
alpar@464: % does insertions, but you have to call it yourself.
alpar@464: \def\onepageout#1{%
alpar@464:   \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
alpar@464:   %
alpar@464:   \ifodd\pageno  \advance\hoffset by \bindingoffset
alpar@464:   \else \advance\hoffset by -\bindingoffset\fi
alpar@464:   %
alpar@464:   % Do this outside of the \shipout so @code etc. will be expanded in
alpar@464:   % the headline as they should be, not taken literally (outputting ''code).
alpar@464:   \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}%
alpar@464:   \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}%
alpar@464:   %
alpar@464:   {%
alpar@464:     % Have to do this stuff outside the \shipout because we want it to
alpar@464:     % take effect in \write's, yet the group defined by the \vbox ends
alpar@464:     % before the \shipout runs.
alpar@464:     %
alpar@464:     \escapechar = `\\     % use backslash in output files.
alpar@464:     \indexdummies         % don't expand commands in the output.
alpar@464:     \normalturnoffactive  % \ in index entries must not stay \, e.g., if
alpar@464:                    % the page break happens to be in the middle of an example.
alpar@464:     \shipout\vbox{%
alpar@464:       % Do this early so pdf references go to the beginning of the page.
alpar@464:       \ifpdfmakepagedest \pdfmkdest{\the\pageno} \fi
alpar@464:       %
alpar@464:       \ifcropmarks \vbox to \outervsize\bgroup
alpar@464:         \hsize = \outerhsize
alpar@464:         \vskip-\topandbottommargin
alpar@464:         \vtop to0pt{%
alpar@464:           \line{\ewtop\hfil\ewtop}%
alpar@464:           \nointerlineskip
alpar@464:           \line{%
alpar@464:             \vbox{\moveleft\cornerthick\nstop}%
alpar@464:             \hfill
alpar@464:             \vbox{\moveright\cornerthick\nstop}%
alpar@464:           }%
alpar@464:           \vss}%
alpar@464:         \vskip\topandbottommargin
alpar@464:         \line\bgroup
alpar@464:           \hfil % center the page within the outer (page) hsize.
alpar@464:           \ifodd\pageno\hskip\bindingoffset\fi
alpar@464:           \vbox\bgroup
alpar@464:       \fi
alpar@464:       %
alpar@464:       \unvbox\headlinebox
alpar@464:       \pagebody{#1}%
alpar@464:       \ifdim\ht\footlinebox > 0pt
alpar@464:         % Only leave this space if the footline is nonempty.
alpar@464:         % (We lessened \vsize for it in \oddfootingxxx.)
alpar@464:         % The \baselineskip=24pt in plain's \makefootline has no effect.
alpar@464:         \vskip 2\baselineskip
alpar@464:         \unvbox\footlinebox
alpar@464:       \fi
alpar@464:       %
alpar@464:       \ifcropmarks
alpar@464:           \egroup % end of \vbox\bgroup
alpar@464:         \hfil\egroup % end of (centering) \line\bgroup
alpar@464:         \vskip\topandbottommargin plus1fill minus1fill
alpar@464:         \boxmaxdepth = \cornerthick
alpar@464:         \vbox to0pt{\vss
alpar@464:           \line{%
alpar@464:             \vbox{\moveleft\cornerthick\nsbot}%
alpar@464:             \hfill
alpar@464:             \vbox{\moveright\cornerthick\nsbot}%
alpar@464:           }%
alpar@464:           \nointerlineskip
alpar@464:           \line{\ewbot\hfil\ewbot}%
alpar@464:         }%
alpar@464:       \egroup % \vbox from first cropmarks clause
alpar@464:       \fi
alpar@464:     }% end of \shipout\vbox
alpar@464:   }% end of group with \normalturnoffactive
alpar@464:   \advancepageno
alpar@464:   \ifnum\outputpenalty>-20000 \else\dosupereject\fi
alpar@464: }
alpar@464: 
alpar@464: \newinsert\margin \dimen\margin=\maxdimen
alpar@464: 
alpar@464: \def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}}
alpar@464: {\catcode`\@ =11
alpar@464: \gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
alpar@464: % marginal hacks, juha@viisa.uucp (Juha Takala)
alpar@464: \ifvoid\margin\else % marginal info is present
alpar@464:   \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
alpar@464: \dimen@=\dp#1 \unvbox#1
alpar@464: \ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
alpar@464: \ifr@ggedbottom \kern-\dimen@ \vfil \fi}
alpar@464: }
alpar@464: 
alpar@464: % Here are the rules for the cropmarks.  Note that they are
alpar@464: % offset so that the space between them is truly \outerhsize or \outervsize
alpar@464: % (P. A. MacKay, 12 November, 1986)
alpar@464: %
alpar@464: \def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
alpar@464: \def\nstop{\vbox
alpar@464:   {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
alpar@464: \def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
alpar@464: \def\nsbot{\vbox
alpar@464:   {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
alpar@464: 
alpar@464: % Parse an argument, then pass it to #1.  The argument is the rest of
alpar@464: % the input line (except we remove a trailing comment).  #1 should be a
alpar@464: % macro which expects an ordinary undelimited TeX argument.
alpar@464: %
alpar@464: \def\parsearg#1{%
alpar@464:   \let\next = #1%
alpar@464:   \begingroup
alpar@464:     \obeylines
alpar@464:     \futurelet\temp\parseargx
alpar@464: }
alpar@464: 
alpar@464: % If the next token is an obeyed space (from an @example environment or
alpar@464: % the like), remove it and recurse.  Otherwise, we're done.
alpar@464: \def\parseargx{%
alpar@464:   % \obeyedspace is defined far below, after the definition of \sepspaces.
alpar@464:   \ifx\obeyedspace\temp
alpar@464:     \expandafter\parseargdiscardspace
alpar@464:   \else
alpar@464:     \expandafter\parseargline
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % Remove a single space (as the delimiter token to the macro call).
alpar@464: {\obeyspaces %
alpar@464:  \gdef\parseargdiscardspace {\futurelet\temp\parseargx}}
alpar@464: 
alpar@464: {\obeylines %
alpar@464:   \gdef\parseargline#1^^M{%
alpar@464:     \endgroup % End of the group started in \parsearg.
alpar@464:     %
alpar@464:     % First remove any @c comment, then any @comment.
alpar@464:     % Result of each macro is put in \toks0.
alpar@464:     \argremovec #1\c\relax %
alpar@464:     \expandafter\argremovecomment \the\toks0 \comment\relax %
alpar@464:     %
alpar@464:     % Call the caller's macro, saved as \next in \parsearg.
alpar@464:     \expandafter\next\expandafter{\the\toks0}%
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % Since all \c{,omment} does is throw away the argument, we can let TeX
alpar@464: % do that for us.  The \relax here is matched by the \relax in the call
alpar@464: % in \parseargline; it could be more or less anything, its purpose is
alpar@464: % just to delimit the argument to the \c.
alpar@464: \def\argremovec#1\c#2\relax{\toks0 = {#1}}
alpar@464: \def\argremovecomment#1\comment#2\relax{\toks0 = {#1}}
alpar@464: 
alpar@464: % \argremovec{,omment} might leave us with trailing spaces, though; e.g.,
alpar@464: %    @end itemize  @c foo
alpar@464: % will have two active spaces as part of the argument with the
alpar@464: % `itemize'.  Here we remove all active spaces from #1, and assign the
alpar@464: % result to \toks0.
alpar@464: %
alpar@464: % This loses if there are any *other* active characters besides spaces
alpar@464: % in the argument -- _ ^ +, for example -- since they get expanded.
alpar@464: % Fortunately, Texinfo does not define any such commands.  (If it ever
alpar@464: % does, the catcode of the characters in questionwill have to be changed
alpar@464: % here.)  But this means we cannot call \removeactivespaces as part of
alpar@464: % \argremovec{,omment}, since @c uses \parsearg, and thus the argument
alpar@464: % that \parsearg gets might well have any character at all in it.
alpar@464: %
alpar@464: \def\removeactivespaces#1{%
alpar@464:   \begingroup
alpar@464:     \ignoreactivespaces
alpar@464:     \edef\temp{#1}%
alpar@464:     \global\toks0 = \expandafter{\temp}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % Change the active space to expand to nothing.
alpar@464: %
alpar@464: \begingroup
alpar@464:   \obeyspaces
alpar@464:   \gdef\ignoreactivespaces{\obeyspaces\let =\empty}
alpar@464: \endgroup
alpar@464: 
alpar@464: 
alpar@464: \def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
alpar@464: 
alpar@464: %% These are used to keep @begin/@end levels from running away
alpar@464: %% Call \inENV within environments (after a \begingroup)
alpar@464: \newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
alpar@464: \def\ENVcheck{%
alpar@464: \ifENV\errmessage{Still within an environment; press RETURN to continue}
alpar@464: \endgroup\fi} % This is not perfect, but it should reduce lossage
alpar@464: 
alpar@464: % @begin foo  is the same as @foo, for now.
alpar@464: \newhelp\EMsimple{Press RETURN to continue.}
alpar@464: 
alpar@464: \outer\def\begin{\parsearg\beginxxx}
alpar@464: 
alpar@464: \def\beginxxx #1{%
alpar@464: \expandafter\ifx\csname #1\endcsname\relax
alpar@464: {\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else
alpar@464: \csname #1\endcsname\fi}
alpar@464: 
alpar@464: % @end foo executes the definition of \Efoo.
alpar@464: %
alpar@464: \def\end{\parsearg\endxxx}
alpar@464: \def\endxxx #1{%
alpar@464:   \removeactivespaces{#1}%
alpar@464:   \edef\endthing{\the\toks0}%
alpar@464:   %
alpar@464:   \expandafter\ifx\csname E\endthing\endcsname\relax
alpar@464:     \expandafter\ifx\csname \endthing\endcsname\relax
alpar@464:       % There's no \foo, i.e., no ``environment'' foo.
alpar@464:       \errhelp = \EMsimple
alpar@464:       \errmessage{Undefined command `@end \endthing'}%
alpar@464:     \else
alpar@464:       \unmatchedenderror\endthing
alpar@464:     \fi
alpar@464:   \else
alpar@464:     % Everything's ok; the right environment has been started.
alpar@464:     \csname E\endthing\endcsname
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % There is an environment #1, but it hasn't been started.  Give an error.
alpar@464: %
alpar@464: \def\unmatchedenderror#1{%
alpar@464:   \errhelp = \EMsimple
alpar@464:   \errmessage{This `@end #1' doesn't have a matching `@#1'}%
alpar@464: }
alpar@464: 
alpar@464: % Define the control sequence \E#1 to give an unmatched @end error.
alpar@464: %
alpar@464: \def\defineunmatchedend#1{%
alpar@464:   \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: %% Simple single-character @ commands
alpar@464: 
alpar@464: % @@ prints an @
alpar@464: % Kludge this until the fonts are right (grr).
alpar@464: \def\@{{\tt\char64}}
alpar@464: 
alpar@464: % This is turned off because it was never documented
alpar@464: % and you can use @w{...} around a quote to suppress ligatures.
alpar@464: %% Define @` and @' to be the same as ` and '
alpar@464: %% but suppressing ligatures.
alpar@464: %\def\`{{`}}
alpar@464: %\def\'{{'}}
alpar@464: 
alpar@464: % Used to generate quoted braces.
alpar@464: \def\mylbrace {{\tt\char123}}
alpar@464: \def\myrbrace {{\tt\char125}}
alpar@464: \let\{=\mylbrace
alpar@464: \let\}=\myrbrace
alpar@464: \begingroup
alpar@464:   % Definitions to produce \{ and \} commands for indices,
alpar@464:   % and @{ and @} for the aux file.
alpar@464:   \catcode`\{ = \other \catcode`\} = \other
alpar@464:   \catcode`\[ = 1 \catcode`\] = 2
alpar@464:   \catcode`\! = 0 \catcode`\\ = \other
alpar@464:   !gdef!lbracecmd[\{]%
alpar@464:   !gdef!rbracecmd[\}]%
alpar@464:   !gdef!lbraceatcmd[@{]%
alpar@464:   !gdef!rbraceatcmd[@}]%
alpar@464: !endgroup
alpar@464: 
alpar@464: % Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
alpar@464: % Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
alpar@464: \let\, = \c
alpar@464: \let\dotaccent = \.
alpar@464: \def\ringaccent#1{{\accent23 #1}}
alpar@464: \let\tieaccent = \t
alpar@464: \let\ubaraccent = \b
alpar@464: \let\udotaccent = \d
alpar@464: 
alpar@464: % Other special characters: @questiondown @exclamdown
alpar@464: % Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
alpar@464: \def\questiondown{?`}
alpar@464: \def\exclamdown{!`}
alpar@464: 
alpar@464: % Dotless i and dotless j, used for accents.
alpar@464: \def\imacro{i}
alpar@464: \def\jmacro{j}
alpar@464: \def\dotless#1{%
alpar@464:   \def\temp{#1}%
alpar@464:   \ifx\temp\imacro \ptexi
alpar@464:   \else\ifx\temp\jmacro \j
alpar@464:   \else \errmessage{@dotless can be used only with i or j}%
alpar@464:   \fi\fi
alpar@464: }
alpar@464: 
alpar@464: % Be sure we're in horizontal mode when doing a tie, since we make space
alpar@464: % equivalent to this in @example-like environments. Otherwise, a space
alpar@464: % at the beginning of a line will start with \penalty -- and
alpar@464: % since \penalty is valid in vertical mode, we'd end up putting the
alpar@464: % penalty on the vertical list instead of in the new paragraph.
alpar@464: {\catcode`@ = 11
alpar@464:  % Avoid using \@M directly, because that causes trouble
alpar@464:  % if the definition is written into an index file.
alpar@464:  \global\let\tiepenalty = \@M
alpar@464:  \gdef\tie{\leavevmode\penalty\tiepenalty\ }
alpar@464: }
alpar@464: 
alpar@464: % @: forces normal size whitespace following.
alpar@464: \def\:{\spacefactor=1000 }
alpar@464: 
alpar@464: % @* forces a line break.
alpar@464: \def\*{\hfil\break\hbox{}\ignorespaces}
alpar@464: 
alpar@464: % @/ allows a line break.
alpar@464: \let\/=\allowbreak
alpar@464: 
alpar@464: % @. is an end-of-sentence period.
alpar@464: \def\.{.\spacefactor=3000 }
alpar@464: 
alpar@464: % @! is an end-of-sentence bang.
alpar@464: \def\!{!\spacefactor=3000 }
alpar@464: 
alpar@464: % @? is an end-of-sentence query.
alpar@464: \def\?{?\spacefactor=3000 }
alpar@464: 
alpar@464: % @w prevents a word break.  Without the \leavevmode, @w at the
alpar@464: % beginning of a paragraph, when TeX is still in vertical mode, would
alpar@464: % produce a whole line of output instead of starting the paragraph.
alpar@464: \def\w#1{\leavevmode\hbox{#1}}
alpar@464: 
alpar@464: % @group ... @end group forces ... to be all on one page, by enclosing
alpar@464: % it in a TeX vbox.  We use \vtop instead of \vbox to construct the box
alpar@464: % to keep its height that of a normal line.  According to the rules for
alpar@464: % \topskip (p.114 of the TeXbook), the glue inserted is
alpar@464: % max (\topskip - \ht (first item), 0).  If that height is large,
alpar@464: % therefore, no glue is inserted, and the space between the headline and
alpar@464: % the text is small, which looks bad.
alpar@464: %
alpar@464: % Another complication is that the group might be very large.  This can
alpar@464: % cause the glue on the previous page to be unduly stretched, because it
alpar@464: % does not have much material.  In this case, it's better to add an
alpar@464: % explicit \vfill so that the extra space is at the bottom.  The
alpar@464: % threshold for doing this is if the group is more than \vfilllimit
alpar@464: % percent of a page (\vfilllimit can be changed inside of @tex).
alpar@464: %
alpar@464: \newbox\groupbox
alpar@464: \def\vfilllimit{0.7}
alpar@464: %
alpar@464: \def\group{\begingroup
alpar@464:   \ifnum\catcode13=\active \else
alpar@464:     \errhelp = \groupinvalidhelp
alpar@464:     \errmessage{@group invalid in context where filling is enabled}%
alpar@464:   \fi
alpar@464:   %
alpar@464:   % The \vtop we start below produces a box with normal height and large
alpar@464:   % depth; thus, TeX puts \baselineskip glue before it, and (when the
alpar@464:   % next line of text is done) \lineskip glue after it.  (See p.82 of
alpar@464:   % the TeXbook.)  Thus, space below is not quite equal to space
alpar@464:   % above.  But it's pretty close.
alpar@464:   \def\Egroup{%
alpar@464:     \egroup           % End the \vtop.
alpar@464:     % \dimen0 is the vertical size of the group's box.
alpar@464:     \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
alpar@464:     % \dimen2 is how much space is left on the page (more or less).
alpar@464:     \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
alpar@464:     % if the group doesn't fit on the current page, and it's a big big
alpar@464:     % group, force a page break.
alpar@464:     \ifdim \dimen0 > \dimen2
alpar@464:       \ifdim \pagetotal < \vfilllimit\pageheight
alpar@464:         \page
alpar@464:       \fi
alpar@464:     \fi
alpar@464:     \copy\groupbox
alpar@464:     \endgroup         % End the \group.
alpar@464:   }%
alpar@464:   %
alpar@464:   \setbox\groupbox = \vtop\bgroup
alpar@464:     % We have to put a strut on the last line in case the @group is in
alpar@464:     % the midst of an example, rather than completely enclosing it.
alpar@464:     % Otherwise, the interline space between the last line of the group
alpar@464:     % and the first line afterwards is too small.  But we can't put the
alpar@464:     % strut in \Egroup, since there it would be on a line by itself.
alpar@464:     % Hence this just inserts a strut at the beginning of each line.
alpar@464:     \everypar = {\strut}%
alpar@464:     %
alpar@464:     % Since we have a strut on every line, we don't need any of TeX's
alpar@464:     % normal interline spacing.
alpar@464:     \offinterlineskip
alpar@464:     %
alpar@464:     % OK, but now we have to do something about blank
alpar@464:     % lines in the input in @example-like environments, which normally
alpar@464:     % just turn into \lisppar, which will insert no space now that we've
alpar@464:     % turned off the interline space.  Simplest is to make them be an
alpar@464:     % empty paragraph.
alpar@464:     \ifx\par\lisppar
alpar@464:       \edef\par{\leavevmode \par}%
alpar@464:       %
alpar@464:       % Reset ^^M's definition to new definition of \par.
alpar@464:       \obeylines
alpar@464:     \fi
alpar@464:     %
alpar@464:     % Do @comment since we are called inside an environment such as
alpar@464:     % @example, where each end-of-line in the input causes an
alpar@464:     % end-of-line in the output.  We don't want the end-of-line after
alpar@464:     % the `@group' to put extra space in the output.  Since @group
alpar@464:     % should appear on a line by itself (according to the Texinfo
alpar@464:     % manual), we don't worry about eating any user text.
alpar@464:     \comment
alpar@464: }
alpar@464: %
alpar@464: % TeX puts in an \escapechar (i.e., `@') at the beginning of the help
alpar@464: % message, so this ends up printing `@group can only ...'.
alpar@464: %
alpar@464: \newhelp\groupinvalidhelp{%
alpar@464: group can only be used in environments such as @example,^^J%
alpar@464: where each line of input produces a line of output.}
alpar@464: 
alpar@464: % @need space-in-mils
alpar@464: % forces a page break if there is not space-in-mils remaining.
alpar@464: 
alpar@464: \newdimen\mil  \mil=0.001in
alpar@464: 
alpar@464: \def\need{\parsearg\needx}
alpar@464: 
alpar@464: % Old definition--didn't work.
alpar@464: %\def\needx #1{\par %
alpar@464: %% This method tries to make TeX break the page naturally
alpar@464: %% if the depth of the box does not fit.
alpar@464: %{\baselineskip=0pt%
alpar@464: %\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak
alpar@464: %\prevdepth=-1000pt
alpar@464: %}}
alpar@464: 
alpar@464: \def\needx#1{%
alpar@464:   % Ensure vertical mode, so we don't make a big box in the middle of a
alpar@464:   % paragraph.
alpar@464:   \par
alpar@464:   %
alpar@464:   % If the @need value is less than one line space, it's useless.
alpar@464:   \dimen0 = #1\mil
alpar@464:   \dimen2 = \ht\strutbox
alpar@464:   \advance\dimen2 by \dp\strutbox
alpar@464:   \ifdim\dimen0 > \dimen2
alpar@464:     %
alpar@464:     % Do a \strut just to make the height of this box be normal, so the
alpar@464:     % normal leading is inserted relative to the preceding line.
alpar@464:     % And a page break here is fine.
alpar@464:     \vtop to #1\mil{\strut\vfil}%
alpar@464:     %
alpar@464:     % TeX does not even consider page breaks if a penalty added to the
alpar@464:     % main vertical list is 10000 or more.  But in order to see if the
alpar@464:     % empty box we just added fits on the page, we must make it consider
alpar@464:     % page breaks.  On the other hand, we don't want to actually break the
alpar@464:     % page after the empty box.  So we use a penalty of 9999.
alpar@464:     %
alpar@464:     % There is an extremely small chance that TeX will actually break the
alpar@464:     % page at this \penalty, if there are no other feasible breakpoints in
alpar@464:     % sight.  (If the user is using lots of big @group commands, which
alpar@464:     % almost-but-not-quite fill up a page, TeX will have a hard time doing
alpar@464:     % good page breaking, for example.)  However, I could not construct an
alpar@464:     % example where a page broke at this \penalty; if it happens in a real
alpar@464:     % document, then we can reconsider our strategy.
alpar@464:     \penalty9999
alpar@464:     %
alpar@464:     % Back up by the size of the box, whether we did a page break or not.
alpar@464:     \kern -#1\mil
alpar@464:     %
alpar@464:     % Do not allow a page break right after this kern.
alpar@464:     \nobreak
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % @br   forces paragraph break
alpar@464: 
alpar@464: \let\br = \par
alpar@464: 
alpar@464: % @dots{} output an ellipsis using the current font.
alpar@464: % We do .5em per period so that it has the same spacing in a typewriter
alpar@464: % font as three actual period characters.
alpar@464: %
alpar@464: \def\dots{%
alpar@464:   \leavevmode
alpar@464:   \hbox to 1.5em{%
alpar@464:     \hskip 0pt plus 0.25fil minus 0.25fil
alpar@464:     .\hss.\hss.%
alpar@464:     \hskip 0pt plus 0.5fil minus 0.5fil
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % @enddots{} is an end-of-sentence ellipsis.
alpar@464: %
alpar@464: \def\enddots{%
alpar@464:   \leavevmode
alpar@464:   \hbox to 2em{%
alpar@464:     \hskip 0pt plus 0.25fil minus 0.25fil
alpar@464:     .\hss.\hss.\hss.%
alpar@464:     \hskip 0pt plus 0.5fil minus 0.5fil
alpar@464:   }%
alpar@464:   \spacefactor=3000
alpar@464: }
alpar@464: 
alpar@464: % @page forces the start of a new page.
alpar@464: %
alpar@464: \def\page{\par\vfill\supereject}
alpar@464: 
alpar@464: % @exdent text....
alpar@464: % outputs text on separate line in roman font, starting at standard page margin
alpar@464: 
alpar@464: % This records the amount of indent in the innermost environment.
alpar@464: % That's how much \exdent should take out.
alpar@464: \newskip\exdentamount
alpar@464: 
alpar@464: % This defn is used inside fill environments such as @defun.
alpar@464: \def\exdent{\parsearg\exdentyyy}
alpar@464: \def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}}
alpar@464: 
alpar@464: % This defn is used inside nofill environments such as @example.
alpar@464: \def\nofillexdent{\parsearg\nofillexdentyyy}
alpar@464: \def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount
alpar@464: \leftline{\hskip\leftskip{\rm#1}}}}
alpar@464: 
alpar@464: % @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
alpar@464: % paragraph.  For more general purposes, use the \margin insertion
alpar@464: % class.  WHICH is `l' or `r'.
alpar@464: %
alpar@464: \newskip\inmarginspacing \inmarginspacing=1cm
alpar@464: \def\strutdepth{\dp\strutbox}
alpar@464: %
alpar@464: \def\doinmargin#1#2{\strut\vadjust{%
alpar@464:   \nobreak
alpar@464:   \kern-\strutdepth
alpar@464:   \vtop to \strutdepth{%
alpar@464:     \baselineskip=\strutdepth
alpar@464:     \vss
alpar@464:     % if you have multiple lines of stuff to put here, you'll need to
alpar@464:     % make the vbox yourself of the appropriate size.
alpar@464:     \ifx#1l%
alpar@464:       \llap{\ignorespaces #2\hskip\inmarginspacing}%
alpar@464:     \else
alpar@464:       \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
alpar@464:     \fi
alpar@464:     \null
alpar@464:   }%
alpar@464: }}
alpar@464: \def\inleftmargin{\doinmargin l}
alpar@464: \def\inrightmargin{\doinmargin r}
alpar@464: %
alpar@464: % @inmargin{TEXT [, RIGHT-TEXT]}
alpar@464: % (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
alpar@464: % else use TEXT for both).
alpar@464: %
alpar@464: \def\inmargin#1{\parseinmargin #1,,\finish}
alpar@464: \def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
alpar@464:   \setbox0 = \hbox{\ignorespaces #2}%
alpar@464:   \ifdim\wd0 > 0pt
alpar@464:     \def\lefttext{#1}%  have both texts
alpar@464:     \def\righttext{#2}%
alpar@464:   \else
alpar@464:     \def\lefttext{#1}%  have only one text
alpar@464:     \def\righttext{#1}%
alpar@464:   \fi
alpar@464:   %
alpar@464:   \ifodd\pageno
alpar@464:     \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
alpar@464:   \else
alpar@464:     \def\temp{\inleftmargin\lefttext}%
alpar@464:   \fi
alpar@464:   \temp
alpar@464: }
alpar@464: 
alpar@464: % @include file    insert text of that file as input.
alpar@464: % Allow normal characters that  we make active in the argument (a file name).
alpar@464: \def\include{\begingroup
alpar@464:   \catcode`\\=\other
alpar@464:   \catcode`~=\other
alpar@464:   \catcode`^=\other
alpar@464:   \catcode`_=\other
alpar@464:   \catcode`|=\other
alpar@464:   \catcode`<=\other
alpar@464:   \catcode`>=\other
alpar@464:   \catcode`+=\other
alpar@464:   \parsearg\includezzz}
alpar@464: % Restore active chars for included file.
alpar@464: \def\includezzz#1{\endgroup\begingroup
alpar@464:   % Read the included file in a group so nested @include's work.
alpar@464:   \def\thisfile{#1}%
alpar@464:   \let\value=\expandablevalue
alpar@464:   \input\thisfile
alpar@464: \endgroup}
alpar@464: 
alpar@464: \def\thisfile{}
alpar@464: 
alpar@464: % @center line
alpar@464: % outputs that line, centered.
alpar@464: %
alpar@464: \def\center{\parsearg\docenter}
alpar@464: \def\docenter#1{{%
alpar@464:   \ifhmode \hfil\break \fi
alpar@464:   \advance\hsize by -\leftskip
alpar@464:   \advance\hsize by -\rightskip
alpar@464:   \line{\hfil \ignorespaces#1\unskip \hfil}%
alpar@464:   \ifhmode \break \fi
alpar@464: }}
alpar@464: 
alpar@464: % @sp n   outputs n lines of vertical space
alpar@464: 
alpar@464: \def\sp{\parsearg\spxxx}
alpar@464: \def\spxxx #1{\vskip #1\baselineskip}
alpar@464: 
alpar@464: % @comment ...line which is ignored...
alpar@464: % @c is the same as @comment
alpar@464: % @ignore ... @end ignore  is another way to write a comment
alpar@464: 
alpar@464: \def\comment{\begingroup \catcode`\^^M=\other%
alpar@464: \catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
alpar@464: \commentxxx}
alpar@464: {\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}}
alpar@464: 
alpar@464: \let\c=\comment
alpar@464: 
alpar@464: % @paragraphindent NCHARS
alpar@464: % We'll use ems for NCHARS, close enough.
alpar@464: % NCHARS can also be the word `asis' or `none'.
alpar@464: % We cannot feasibly implement @paragraphindent asis, though.
alpar@464: %
alpar@464: \def\asisword{asis} % no translation, these are keywords
alpar@464: \def\noneword{none}
alpar@464: %
alpar@464: \def\paragraphindent{\parsearg\doparagraphindent}
alpar@464: \def\doparagraphindent#1{%
alpar@464:   \def\temp{#1}%
alpar@464:   \ifx\temp\asisword
alpar@464:   \else
alpar@464:     \ifx\temp\noneword
alpar@464:       \defaultparindent = 0pt
alpar@464:     \else
alpar@464:       \defaultparindent = #1em
alpar@464:     \fi
alpar@464:   \fi
alpar@464:   \parindent = \defaultparindent
alpar@464: }
alpar@464: 
alpar@464: % @exampleindent NCHARS
alpar@464: % We'll use ems for NCHARS like @paragraphindent.
alpar@464: % It seems @exampleindent asis isn't necessary, but
alpar@464: % I preserve it to make it similar to @paragraphindent.
alpar@464: \def\exampleindent{\parsearg\doexampleindent}
alpar@464: \def\doexampleindent#1{%
alpar@464:   \def\temp{#1}%
alpar@464:   \ifx\temp\asisword
alpar@464:   \else
alpar@464:     \ifx\temp\noneword
alpar@464:       \lispnarrowing = 0pt
alpar@464:     \else
alpar@464:       \lispnarrowing = #1em
alpar@464:     \fi
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % @firstparagraphindent WORD
alpar@464: % If WORD is `none', then suppress indentation of the first paragraph
alpar@464: % after a section heading.  If WORD is `insert', then do indent at such
alpar@464: % paragraphs.
alpar@464: %
alpar@464: % The paragraph indentation is suppressed or not by calling
alpar@464: % \suppressfirstparagraphindent, which the sectioning commands do.
alpar@464: % We switch the definition of this back and forth according to WORD.
alpar@464: % By default, we suppress indentation.
alpar@464: %
alpar@464: \def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
alpar@464: \newdimen\currentparindent
alpar@464: %
alpar@464: \def\insertword{insert}
alpar@464: %
alpar@464: \def\firstparagraphindent{\parsearg\dofirstparagraphindent}
alpar@464: \def\dofirstparagraphindent#1{%
alpar@464:   \def\temp{#1}%
alpar@464:   \ifx\temp\noneword
alpar@464:     \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
alpar@464:   \else\ifx\temp\insertword
alpar@464:     \let\suppressfirstparagraphindent = \relax
alpar@464:   \else
alpar@464:     \errhelp = \EMsimple
alpar@464:     \errmessage{Unknown @firstparagraphindent option `\temp'}%
alpar@464:   \fi\fi
alpar@464: }
alpar@464: 
alpar@464: % Here is how we actually suppress indentation.  Redefine \everypar to
alpar@464: % \kern backwards by \parindent, and then reset itself to empty.
alpar@464: %
alpar@464: % We also make \indent itself not actually do anything until the next
alpar@464: % paragraph.
alpar@464: %
alpar@464: \gdef\dosuppressfirstparagraphindent{%
alpar@464:   \gdef\indent{%
alpar@464:     \global\let\indent=\ptexindent
alpar@464:     \global\everypar = {}%
alpar@464:   }%
alpar@464:   \global\everypar = {%
alpar@464:     \kern-\parindent
alpar@464:     \global\let\indent=\ptexindent
alpar@464:     \global\everypar = {}%
alpar@464:   }%
alpar@464: }%
alpar@464: 
alpar@464: 
alpar@464: % @asis just yields its argument.  Used with @table, for example.
alpar@464: %
alpar@464: \def\asis#1{#1}
alpar@464: 
alpar@464: % @math outputs its argument in math mode.
alpar@464: % We don't use $'s directly in the definition of \math because we need
alpar@464: % to set catcodes according to plain TeX first, to allow for subscripts,
alpar@464: % superscripts, special math chars, etc.
alpar@464: %
alpar@464: \let\implicitmath = $%$ font-lock fix
alpar@464: %
alpar@464: % One complication: _ usually means subscripts, but it could also mean
alpar@464: % an actual _ character, as in @math{@var{some_variable} + 1}.  So make
alpar@464: % _ within @math be active (mathcode "8000), and distinguish by seeing
alpar@464: % if the current family is \slfam, which is what @var uses.
alpar@464: %
alpar@464: {\catcode\underChar = \active
alpar@464: \gdef\mathunderscore{%
alpar@464:   \catcode\underChar=\active
alpar@464:   \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
alpar@464: }}
alpar@464: %
alpar@464: % Another complication: we want \\ (and @\) to output a \ character.
alpar@464: % FYI, plain.tex uses \\ as a temporary control sequence (why?), but
alpar@464: % this is not advertised and we don't care.  Texinfo does not
alpar@464: % otherwise define @\.
alpar@464: %
alpar@464: % The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
alpar@464: \def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
alpar@464: %
alpar@464: \def\math{%
alpar@464:   \tex
alpar@464:   \mathcode`\_="8000 \mathunderscore
alpar@464:   \let\\ = \mathbackslash
alpar@464:   \mathactive
alpar@464:   \implicitmath\finishmath}
alpar@464: \def\finishmath#1{#1\implicitmath\Etex}
alpar@464: 
alpar@464: % Some active characters (such as <) are spaced differently in math.
alpar@464: % We have to reset their definitions in case the @math was an
alpar@464: % argument to a command which set the catcodes (such as @item or @section).
alpar@464: %
alpar@464: {
alpar@464:   \catcode`^ = \active
alpar@464:   \catcode`< = \active
alpar@464:   \catcode`> = \active
alpar@464:   \catcode`+ = \active
alpar@464:   \gdef\mathactive{%
alpar@464:     \let^ = \ptexhat
alpar@464:     \let< = \ptexless
alpar@464:     \let> = \ptexgtr
alpar@464:     \let+ = \ptexplus
alpar@464:   }
alpar@464: }
alpar@464: 
alpar@464: % @bullet and @minus need the same treatment as @math, just above.
alpar@464: \def\bullet{\implicitmath\ptexbullet\implicitmath}
alpar@464: \def\minus{\implicitmath-\implicitmath}
alpar@464: 
alpar@464: % @refill is a no-op.
alpar@464: \let\refill=\relax
alpar@464: 
alpar@464: % If working on a large document in chapters, it is convenient to
alpar@464: % be able to disable indexing, cross-referencing, and contents, for test runs.
alpar@464: % This is done with @novalidate (before @setfilename).
alpar@464: %
alpar@464: \newif\iflinks \linkstrue % by default we want the aux files.
alpar@464: \let\novalidate = \linksfalse
alpar@464: 
alpar@464: % @setfilename is done at the beginning of every texinfo file.
alpar@464: % So open here the files we need to have open while reading the input.
alpar@464: % This makes it possible to make a .fmt file for texinfo.
alpar@464: \def\setfilename{%
alpar@464:    \iflinks
alpar@464:      \readauxfile
alpar@464:    \fi % \openindices needs to do some work in any case.
alpar@464:    \openindices
alpar@464:    \fixbackslash  % Turn off hack to swallow `\input texinfo'.
alpar@464:    \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
alpar@464:    %
alpar@464:    % If texinfo.cnf is present on the system, read it.
alpar@464:    % Useful for site-wide @afourpaper, etc.
alpar@464:    % Just to be on the safe side, close the input stream before the \input.
alpar@464:    \openin 1 texinfo.cnf
alpar@464:    \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
alpar@464:    \closein1
alpar@464:    \temp
alpar@464:    %
alpar@464:    \comment % Ignore the actual filename.
alpar@464: }
alpar@464: 
alpar@464: % Called from \setfilename.
alpar@464: %
alpar@464: \def\openindices{%
alpar@464:   \newindex{cp}%
alpar@464:   \newcodeindex{fn}%
alpar@464:   \newcodeindex{vr}%
alpar@464:   \newcodeindex{tp}%
alpar@464:   \newcodeindex{ky}%
alpar@464:   \newcodeindex{pg}%
alpar@464: }
alpar@464: 
alpar@464: % @bye.
alpar@464: \outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
alpar@464: 
alpar@464: 
alpar@464: \message{pdf,}
alpar@464: % adobe `portable' document format
alpar@464: \newcount\tempnum
alpar@464: \newcount\lnkcount
alpar@464: \newtoks\filename
alpar@464: \newcount\filenamelength
alpar@464: \newcount\pgn
alpar@464: \newtoks\toksA
alpar@464: \newtoks\toksB
alpar@464: \newtoks\toksC
alpar@464: \newtoks\toksD
alpar@464: \newbox\boxA
alpar@464: \newcount\countA
alpar@464: \newif\ifpdf
alpar@464: \newif\ifpdfmakepagedest
alpar@464: 
alpar@464: \ifx\pdfoutput\undefined
alpar@464:   \pdffalse
alpar@464:   \let\pdfmkdest = \gobble
alpar@464:   \let\pdfurl = \gobble
alpar@464:   \let\endlink = \relax
alpar@464:   \let\linkcolor = \relax
alpar@464:   \let\pdfmakeoutlines = \relax
alpar@464: \else
alpar@464:   \pdftrue
alpar@464:   \pdfoutput = 1
alpar@464:   \input pdfcolor
alpar@464:   \def\dopdfimage#1#2#3{%
alpar@464:     \def\imagewidth{#2}%
alpar@464:     \def\imageheight{#3}%
alpar@464:     % without \immediate, pdftex seg faults when the same image is
alpar@464:     % included twice.  (Version 3.14159-pre-1.0-unofficial-20010704.)
alpar@464:     \ifnum\pdftexversion < 14
alpar@464:       \immediate\pdfimage
alpar@464:     \else
alpar@464:       \immediate\pdfximage
alpar@464:     \fi
alpar@464:       \ifx\empty\imagewidth\else width \imagewidth \fi
alpar@464:       \ifx\empty\imageheight\else height \imageheight \fi
alpar@464:       \ifnum\pdftexversion<13
alpar@464:          #1.pdf%
alpar@464:        \else
alpar@464:          {#1.pdf}%
alpar@464:        \fi
alpar@464:     \ifnum\pdftexversion < 14 \else
alpar@464:       \pdfrefximage \pdflastximage
alpar@464:     \fi}
alpar@464:   \def\pdfmkdest#1{{\normalturnoffactive \pdfdest name{#1} xyz}}
alpar@464:   \def\pdfmkpgn#1{#1}
alpar@464:   \let\linkcolor = \Blue  % was Cyan, but that seems light?
alpar@464:   \def\endlink{\Black\pdfendlink}
alpar@464:   % Adding outlines to PDF; macros for calculating structure of outlines
alpar@464:   % come from Petr Olsak
alpar@464:   \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
alpar@464:     \else \csname#1\endcsname \fi}
alpar@464:   \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
alpar@464:     \advance\tempnum by1
alpar@464:     \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
alpar@464:   \def\pdfmakeoutlines{{%
alpar@464:     \openin 1 \jobname.toc
alpar@464:     \ifeof 1\else\begingroup
alpar@464:       \closein 1
alpar@464:       % Thanh's hack / proper braces in bookmarks
alpar@464:       \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
alpar@464:       \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
alpar@464:       %
alpar@464:       \def\chapentry ##1##2##3{}
alpar@464:       \def\secentry ##1##2##3##4{\advancenumber{chap##2}}
alpar@464:       \def\subsecentry ##1##2##3##4##5{\advancenumber{sec##2.##3}}
alpar@464:       \def\subsubsecentry ##1##2##3##4##5##6{\advancenumber{subsec##2.##3.##4}}
alpar@464:       \let\appendixentry = \chapentry
alpar@464:       \let\unnumbchapentry = \chapentry
alpar@464:       \let\unnumbsecentry = \secentry
alpar@464:       \let\unnumbsubsecentry = \subsecentry
alpar@464:       \let\unnumbsubsubsecentry = \subsubsecentry
alpar@464:       \input \jobname.toc
alpar@464:       \def\chapentry ##1##2##3{%
alpar@464:         \pdfoutline goto name{\pdfmkpgn{##3}}count-\expnumber{chap##2}{##1}}
alpar@464:       \def\secentry ##1##2##3##4{%
alpar@464:         \pdfoutline goto name{\pdfmkpgn{##4}}count-\expnumber{sec##2.##3}{##1}}
alpar@464:       \def\subsecentry ##1##2##3##4##5{%
alpar@464:         \pdfoutline goto name{\pdfmkpgn{##5}}count-\expnumber{subsec##2.##3.##4}{##1}}
alpar@464:       \def\subsubsecentry ##1##2##3##4##5##6{%
alpar@464:         \pdfoutline goto name{\pdfmkpgn{##6}}{##1}}
alpar@464:       \let\appendixentry = \chapentry
alpar@464:       \let\unnumbchapentry = \chapentry
alpar@464:       \let\unnumbsecentry = \secentry
alpar@464:       \let\unnumbsubsecentry = \subsecentry
alpar@464:       \let\unnumbsubsubsecentry = \subsubsecentry
alpar@464:       %
alpar@464:       % Make special characters normal for writing to the pdf file.
alpar@464:       %
alpar@464:       \indexnofonts
alpar@464:       \let\tt=\relax
alpar@464:       \turnoffactive
alpar@464:       \input \jobname.toc
alpar@464:     \endgroup\fi
alpar@464:   }}
alpar@464:   \def\makelinks #1,{%
alpar@464:     \def\params{#1}\def\E{END}%
alpar@464:     \ifx\params\E
alpar@464:       \let\nextmakelinks=\relax
alpar@464:     \else
alpar@464:       \let\nextmakelinks=\makelinks
alpar@464:       \ifnum\lnkcount>0,\fi
alpar@464:       \picknum{#1}%
alpar@464:       \startlink attr{/Border [0 0 0]}
alpar@464:         goto name{\pdfmkpgn{\the\pgn}}%
alpar@464:       \linkcolor #1%
alpar@464:       \advance\lnkcount by 1%
alpar@464:       \endlink
alpar@464:     \fi
alpar@464:     \nextmakelinks
alpar@464:   }
alpar@464:   \def\picknum#1{\expandafter\pn#1}
alpar@464:   \def\pn#1{%
alpar@464:     \def\p{#1}%
alpar@464:     \ifx\p\lbrace
alpar@464:       \let\nextpn=\ppn
alpar@464:     \else
alpar@464:       \let\nextpn=\ppnn
alpar@464:       \def\first{#1}
alpar@464:     \fi
alpar@464:     \nextpn
alpar@464:   }
alpar@464:   \def\ppn#1{\pgn=#1\gobble}
alpar@464:   \def\ppnn{\pgn=\first}
alpar@464:   \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
alpar@464:   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
alpar@464:   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
alpar@464:     \ifx\PP\D\let\nextsp\relax
alpar@464:     \else\let\nextsp\skipspaces
alpar@464:       \ifx\p\space\else\addtokens{\filename}{\PP}%
alpar@464:         \advance\filenamelength by 1
alpar@464:       \fi
alpar@464:     \fi
alpar@464:     \nextsp}
alpar@464:   \def\getfilename#1{\filenamelength=0\expandafter\skipspaces#1|\relax}
alpar@464:   \ifnum\pdftexversion < 14
alpar@464:     \let \startlink \pdfannotlink
alpar@464:   \else
alpar@464:     \let \startlink \pdfstartlink
alpar@464:   \fi
alpar@464:   \def\pdfurl#1{%
alpar@464:     \begingroup
alpar@464:       \normalturnoffactive\def\@{@}%
alpar@464:       \let\value=\expandablevalue
alpar@464:       \leavevmode\Red
alpar@464:       \startlink attr{/Border [0 0 0]}%
alpar@464:         user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
alpar@464:         % #1
alpar@464:     \endgroup}
alpar@464:   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
alpar@464:   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
alpar@464:   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
alpar@464:   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
alpar@464:   \def\maketoks{%
alpar@464:     \expandafter\poptoks\the\toksA|ENDTOKS|
alpar@464:     \ifx\first0\adn0
alpar@464:     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
alpar@464:     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
alpar@464:     \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
alpar@464:     \else
alpar@464:       \ifnum0=\countA\else\makelink\fi
alpar@464:       \ifx\first.\let\next=\done\else
alpar@464:         \let\next=\maketoks
alpar@464:         \addtokens{\toksB}{\the\toksD}
alpar@464:         \ifx\first,\addtokens{\toksB}{\space}\fi
alpar@464:       \fi
alpar@464:     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
alpar@464:     \next}
alpar@464:   \def\makelink{\addtokens{\toksB}%
alpar@464:     {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
alpar@464:   \def\pdflink#1{%
alpar@464:     \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
alpar@464:     \linkcolor #1\endlink}
alpar@464:   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
alpar@464: \fi % \ifx\pdfoutput
alpar@464: 
alpar@464: 
alpar@464: \message{fonts,}
alpar@464: % Font-change commands.
alpar@464: 
alpar@464: % Texinfo sort of supports the sans serif font style, which plain TeX does not.
alpar@464: % So we set up a \sf analogous to plain's \rm, etc.
alpar@464: \newfam\sffam
alpar@464: \def\sf{\fam=\sffam \tensf}
alpar@464: \let\li = \sf % Sometimes we call it \li, not \sf.
alpar@464: 
alpar@464: % We don't need math for this one.
alpar@464: \def\ttsl{\tenttsl}
alpar@464: 
alpar@464: % Default leading.
alpar@464: \newdimen\textleading  \textleading = 13.2pt
alpar@464: 
alpar@464: % Set the baselineskip to #1, and the lineskip and strut size
alpar@464: % correspondingly.  There is no deep meaning behind these magic numbers
alpar@464: % used as factors; they just match (closely enough) what Knuth defined.
alpar@464: %
alpar@464: \def\lineskipfactor{.08333}
alpar@464: \def\strutheightpercent{.70833}
alpar@464: \def\strutdepthpercent {.29167}
alpar@464: %
alpar@464: \def\setleading#1{%
alpar@464:   \normalbaselineskip = #1\relax
alpar@464:   \normallineskip = \lineskipfactor\normalbaselineskip
alpar@464:   \normalbaselines
alpar@464:   \setbox\strutbox =\hbox{%
alpar@464:     \vrule width0pt height\strutheightpercent\baselineskip
alpar@464:                     depth \strutdepthpercent \baselineskip
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % Set the font macro #1 to the font named #2, adding on the
alpar@464: % specified font prefix (normally `cm').
alpar@464: % #3 is the font's design size, #4 is a scale factor
alpar@464: \def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4}
alpar@464: 
alpar@464: % Use cm as the default font prefix.
alpar@464: % To specify the font prefix, you must define \fontprefix
alpar@464: % before you read in texinfo.tex.
alpar@464: \ifx\fontprefix\undefined
alpar@464: \def\fontprefix{cm}
alpar@464: \fi
alpar@464: % Support font families that don't use the same naming scheme as CM.
alpar@464: \def\rmshape{r}
alpar@464: \def\rmbshape{bx}               %where the normal face is bold
alpar@464: \def\bfshape{b}
alpar@464: \def\bxshape{bx}
alpar@464: \def\ttshape{tt}
alpar@464: \def\ttbshape{tt}
alpar@464: \def\ttslshape{sltt}
alpar@464: \def\itshape{ti}
alpar@464: \def\itbshape{bxti}
alpar@464: \def\slshape{sl}
alpar@464: \def\slbshape{bxsl}
alpar@464: \def\sfshape{ss}
alpar@464: \def\sfbshape{ss}
alpar@464: \def\scshape{csc}
alpar@464: \def\scbshape{csc}
alpar@464: 
alpar@464: \newcount\mainmagstep
alpar@464: \ifx\bigger\relax
alpar@464:   % not really supported.
alpar@464:   \mainmagstep=\magstep1
alpar@464:   \setfont\textrm\rmshape{12}{1000}
alpar@464:   \setfont\texttt\ttshape{12}{1000}
alpar@464: \else
alpar@464:   \mainmagstep=\magstephalf
alpar@464:   \setfont\textrm\rmshape{10}{\mainmagstep}
alpar@464:   \setfont\texttt\ttshape{10}{\mainmagstep}
alpar@464: \fi
alpar@464: % Instead of cmb10, you may want to use cmbx10.
alpar@464: % cmbx10 is a prettier font on its own, but cmb10
alpar@464: % looks better when embedded in a line with cmr10
alpar@464: % (in Bob's opinion).
alpar@464: \setfont\textbf\bfshape{10}{\mainmagstep}
alpar@464: \setfont\textit\itshape{10}{\mainmagstep}
alpar@464: \setfont\textsl\slshape{10}{\mainmagstep}
alpar@464: \setfont\textsf\sfshape{10}{\mainmagstep}
alpar@464: \setfont\textsc\scshape{10}{\mainmagstep}
alpar@464: \setfont\textttsl\ttslshape{10}{\mainmagstep}
alpar@464: \font\texti=cmmi10 scaled \mainmagstep
alpar@464: \font\textsy=cmsy10 scaled \mainmagstep
alpar@464: 
alpar@464: % A few fonts for @defun, etc.
alpar@464: \setfont\defbf\bxshape{10}{\magstep1} %was 1314
alpar@464: \setfont\deftt\ttshape{10}{\magstep1}
alpar@464: \def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf}
alpar@464: 
alpar@464: % Fonts for indices, footnotes, small examples (9pt).
alpar@464: \setfont\smallrm\rmshape{9}{1000}
alpar@464: \setfont\smalltt\ttshape{9}{1000}
alpar@464: \setfont\smallbf\bfshape{10}{900}
alpar@464: \setfont\smallit\itshape{9}{1000}
alpar@464: \setfont\smallsl\slshape{9}{1000}
alpar@464: \setfont\smallsf\sfshape{9}{1000}
alpar@464: \setfont\smallsc\scshape{10}{900}
alpar@464: \setfont\smallttsl\ttslshape{10}{900}
alpar@464: \font\smalli=cmmi9
alpar@464: \font\smallsy=cmsy9
alpar@464: 
alpar@464: % Fonts for small examples (8pt).
alpar@464: \setfont\smallerrm\rmshape{8}{1000}
alpar@464: \setfont\smallertt\ttshape{8}{1000}
alpar@464: \setfont\smallerbf\bfshape{10}{800}
alpar@464: \setfont\smallerit\itshape{8}{1000}
alpar@464: \setfont\smallersl\slshape{8}{1000}
alpar@464: \setfont\smallersf\sfshape{8}{1000}
alpar@464: \setfont\smallersc\scshape{10}{800}
alpar@464: \setfont\smallerttsl\ttslshape{10}{800}
alpar@464: \font\smalleri=cmmi8
alpar@464: \font\smallersy=cmsy8
alpar@464: 
alpar@464: % Fonts for title page:
alpar@464: \setfont\titlerm\rmbshape{12}{\magstep3}
alpar@464: \setfont\titleit\itbshape{10}{\magstep4}
alpar@464: \setfont\titlesl\slbshape{10}{\magstep4}
alpar@464: \setfont\titlett\ttbshape{12}{\magstep3}
alpar@464: \setfont\titlettsl\ttslshape{10}{\magstep4}
alpar@464: \setfont\titlesf\sfbshape{17}{\magstep1}
alpar@464: \let\titlebf=\titlerm
alpar@464: \setfont\titlesc\scbshape{10}{\magstep4}
alpar@464: \font\titlei=cmmi12 scaled \magstep3
alpar@464: \font\titlesy=cmsy10 scaled \magstep4
alpar@464: \def\authorrm{\secrm}
alpar@464: \def\authortt{\sectt}
alpar@464: 
alpar@464: % Chapter (and unnumbered) fonts (17.28pt).
alpar@464: \setfont\chaprm\rmbshape{12}{\magstep2}
alpar@464: \setfont\chapit\itbshape{10}{\magstep3}
alpar@464: \setfont\chapsl\slbshape{10}{\magstep3}
alpar@464: \setfont\chaptt\ttbshape{12}{\magstep2}
alpar@464: \setfont\chapttsl\ttslshape{10}{\magstep3}
alpar@464: \setfont\chapsf\sfbshape{17}{1000}
alpar@464: \let\chapbf=\chaprm
alpar@464: \setfont\chapsc\scbshape{10}{\magstep3}
alpar@464: \font\chapi=cmmi12 scaled \magstep2
alpar@464: \font\chapsy=cmsy10 scaled \magstep3
alpar@464: 
alpar@464: % Section fonts (14.4pt).
alpar@464: \setfont\secrm\rmbshape{12}{\magstep1}
alpar@464: \setfont\secit\itbshape{10}{\magstep2}
alpar@464: \setfont\secsl\slbshape{10}{\magstep2}
alpar@464: \setfont\sectt\ttbshape{12}{\magstep1}
alpar@464: \setfont\secttsl\ttslshape{10}{\magstep2}
alpar@464: \setfont\secsf\sfbshape{12}{\magstep1}
alpar@464: \let\secbf\secrm
alpar@464: \setfont\secsc\scbshape{10}{\magstep2}
alpar@464: \font\seci=cmmi12 scaled \magstep1
alpar@464: \font\secsy=cmsy10 scaled \magstep2
alpar@464: 
alpar@464: % Subsection fonts (13.15pt).
alpar@464: \setfont\ssecrm\rmbshape{12}{\magstephalf}
alpar@464: \setfont\ssecit\itbshape{10}{1315}
alpar@464: \setfont\ssecsl\slbshape{10}{1315}
alpar@464: \setfont\ssectt\ttbshape{12}{\magstephalf}
alpar@464: \setfont\ssecttsl\ttslshape{10}{1315}
alpar@464: \setfont\ssecsf\sfbshape{12}{\magstephalf}
alpar@464: \let\ssecbf\ssecrm
alpar@464: \setfont\ssecsc\scbshape{10}{\magstep1}
alpar@464: \font\sseci=cmmi12 scaled \magstephalf
alpar@464: \font\ssecsy=cmsy10 scaled 1315
alpar@464: % The smallcaps and symbol fonts should actually be scaled \magstep1.5,
alpar@464: % but that is not a standard magnification.
alpar@464: 
alpar@464: % In order for the font changes to affect most math symbols and letters,
alpar@464: % we have to define the \textfont of the standard families.  Since
alpar@464: % texinfo doesn't allow for producing subscripts and superscripts except
alpar@464: % in the main text, we don't bother to reset \scriptfont and
alpar@464: % \scriptscriptfont (which would also require loading a lot more fonts).
alpar@464: %
alpar@464: \def\resetmathfonts{%
alpar@464:   \textfont0=\tenrm \textfont1=\teni \textfont2=\tensy
alpar@464:   \textfont\itfam=\tenit \textfont\slfam=\tensl \textfont\bffam=\tenbf
alpar@464:   \textfont\ttfam=\tentt \textfont\sffam=\tensf
alpar@464: }
alpar@464: 
alpar@464: % The font-changing commands redefine the meanings of \tenSTYLE, instead
alpar@464: % of just \STYLE.  We do this so that font changes will continue to work
alpar@464: % in math mode, where it is the current \fam that is relevant in most
alpar@464: % cases, not the current font.  Plain TeX does \def\bf{\fam=\bffam
alpar@464: % \tenbf}, for example.  By redefining \tenbf, we obviate the need to
alpar@464: % redefine \bf itself.
alpar@464: \def\textfonts{%
alpar@464:   \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
alpar@464:   \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
alpar@464:   \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
alpar@464:   \resetmathfonts \setleading{\textleading}}
alpar@464: \def\titlefonts{%
alpar@464:   \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
alpar@464:   \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
alpar@464:   \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
alpar@464:   \let\tenttsl=\titlettsl
alpar@464:   \resetmathfonts \setleading{25pt}}
alpar@464: \def\titlefont#1{{\titlefonts\rm #1}}
alpar@464: \def\chapfonts{%
alpar@464:   \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
alpar@464:   \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
alpar@464:   \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
alpar@464:   \resetmathfonts \setleading{19pt}}
alpar@464: \def\secfonts{%
alpar@464:   \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
alpar@464:   \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
alpar@464:   \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
alpar@464:   \resetmathfonts \setleading{16pt}}
alpar@464: \def\subsecfonts{%
alpar@464:   \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
alpar@464:   \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
alpar@464:   \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
alpar@464:   \resetmathfonts \setleading{15pt}}
alpar@464: \let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
alpar@464: \def\smallfonts{%
alpar@464:   \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
alpar@464:   \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
alpar@464:   \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
alpar@464:   \let\tenttsl=\smallttsl
alpar@464:   \resetmathfonts \setleading{10.5pt}}
alpar@464: \def\smallerfonts{%
alpar@464:   \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
alpar@464:   \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
alpar@464:   \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
alpar@464:   \let\tenttsl=\smallerttsl
alpar@464:   \resetmathfonts \setleading{9.5pt}}
alpar@464: 
alpar@464: % Set the fonts to use with the @small... environments.
alpar@464: \let\smallexamplefonts = \smallfonts
alpar@464: 
alpar@464: % About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
alpar@464: % can fit this many characters:
alpar@464: %   8.5x11=86   smallbook=72  a4=90  a5=69
alpar@464: % If we use \smallerfonts (8pt), then we can fit this many characters:
alpar@464: %   8.5x11=90+  smallbook=80  a4=90+  a5=77
alpar@464: % For me, subjectively, the few extra characters that fit aren't worth
alpar@464: % the additional smallness of 8pt.  So I'm making the default 9pt.
alpar@464: %
alpar@464: % By the way, for comparison, here's what fits with @example (10pt):
alpar@464: %   8.5x11=71  smallbook=60  a4=75  a5=58
alpar@464: %
alpar@464: % I wish we used A4 paper on this side of the Atlantic.
alpar@464: %
alpar@464: % --karl, 24jan03.
alpar@464: 
alpar@464: 
alpar@464: % Set up the default fonts, so we can use them for creating boxes.
alpar@464: %
alpar@464: \textfonts
alpar@464: 
alpar@464: % Define these so they can be easily changed for other fonts.
alpar@464: \def\angleleft{$\langle$}
alpar@464: \def\angleright{$\rangle$}
alpar@464: 
alpar@464: % Count depth in font-changes, for error checks
alpar@464: \newcount\fontdepth \fontdepth=0
alpar@464: 
alpar@464: % Fonts for short table of contents.
alpar@464: \setfont\shortcontrm\rmshape{12}{1000}
alpar@464: \setfont\shortcontbf\bxshape{12}{1000}
alpar@464: \setfont\shortcontsl\slshape{12}{1000}
alpar@464: \setfont\shortconttt\ttshape{12}{1000}
alpar@464: 
alpar@464: %% Add scribe-like font environments, plus @l for inline lisp (usually sans
alpar@464: %% serif) and @ii for TeX italic
alpar@464: 
alpar@464: % \smartitalic{ARG} outputs arg in italics, followed by an italic correction
alpar@464: % unless the following character is such as not to need one.
alpar@464: \def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else
alpar@464:                     \ptexslash\fi\fi\fi}
alpar@464: \def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx}
alpar@464: \def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx}
alpar@464: 
alpar@464: \let\i=\smartitalic
alpar@464: \let\var=\smartslanted
alpar@464: \let\dfn=\smartslanted
alpar@464: \let\emph=\smartitalic
alpar@464: \let\cite=\smartslanted
alpar@464: 
alpar@464: \def\b#1{{\bf #1}}
alpar@464: \let\strong=\b
alpar@464: 
alpar@464: % We can't just use \exhyphenpenalty, because that only has effect at
alpar@464: % the end of a paragraph.  Restore normal hyphenation at the end of the
alpar@464: % group within which \nohyphenation is presumably called.
alpar@464: %
alpar@464: \def\nohyphenation{\hyphenchar\font = -1  \aftergroup\restorehyphenation}
alpar@464: \def\restorehyphenation{\hyphenchar\font = `- }
alpar@464: 
alpar@464: % Set sfcode to normal for the chars that usually have another value.
alpar@464: % Can't use plain's \frenchspacing because it uses the `\x notation, and
alpar@464: % sometimes \x has an active definition that messes things up.
alpar@464: %
alpar@464: \catcode`@=11
alpar@464:   \def\frenchspacing{%
alpar@464:     \sfcode\dotChar  =\@m \sfcode\questChar=\@m \sfcode\exclamChar=\@m
alpar@464:     \sfcode\colonChar=\@m \sfcode\semiChar =\@m \sfcode\commaChar =\@m
alpar@464:   }
alpar@464: \catcode`@=\other
alpar@464: 
alpar@464: \def\t#1{%
alpar@464:   {\tt \rawbackslash \frenchspacing #1}%
alpar@464:   \null
alpar@464: }
alpar@464: \let\ttfont=\t
alpar@464: \def\samp#1{`\tclose{#1}'\null}
alpar@464: \setfont\keyrm\rmshape{8}{1000}
alpar@464: \font\keysy=cmsy9
alpar@464: \def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
alpar@464:   \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
alpar@464:     \vbox{\hrule\kern-0.4pt
alpar@464:      \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
alpar@464:     \kern-0.4pt\hrule}%
alpar@464:   \kern-.06em\raise0.4pt\hbox{\angleright}}}}
alpar@464: % The old definition, with no lozenge:
alpar@464: %\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null}
alpar@464: \def\ctrl #1{{\tt \rawbackslash \hat}#1}
alpar@464: 
alpar@464: % @file, @option are the same as @samp.
alpar@464: \let\file=\samp
alpar@464: \let\option=\samp
alpar@464: 
alpar@464: % @code is a modification of @t,
alpar@464: % which makes spaces the same size as normal in the surrounding text.
alpar@464: \def\tclose#1{%
alpar@464:   {%
alpar@464:     % Change normal interword space to be same as for the current font.
alpar@464:     \spaceskip = \fontdimen2\font
alpar@464:     %
alpar@464:     % Switch to typewriter.
alpar@464:     \tt
alpar@464:     %
alpar@464:     % But `\ ' produces the large typewriter interword space.
alpar@464:     \def\ {{\spaceskip = 0pt{} }}%
alpar@464:     %
alpar@464:     % Turn off hyphenation.
alpar@464:     \nohyphenation
alpar@464:     %
alpar@464:     \rawbackslash
alpar@464:     \frenchspacing
alpar@464:     #1%
alpar@464:   }%
alpar@464:   \null
alpar@464: }
alpar@464: 
alpar@464: % We *must* turn on hyphenation at `-' and `_' in \code.
alpar@464: % Otherwise, it is too hard to avoid overfull hboxes
alpar@464: % in the Emacs manual, the Library manual, etc.
alpar@464: 
alpar@464: % Unfortunately, TeX uses one parameter (\hyphenchar) to control
alpar@464: % both hyphenation at - and hyphenation within words.
alpar@464: % We must therefore turn them both off (\tclose does that)
alpar@464: % and arrange explicitly to hyphenate at a dash.
alpar@464: %  -- rms.
alpar@464: {
alpar@464:   \catcode`\-=\active
alpar@464:   \catcode`\_=\active
alpar@464:   %
alpar@464:   \global\def\code{\begingroup
alpar@464:     \catcode`\-=\active \let-\codedash
alpar@464:     \catcode`\_=\active \let_\codeunder
alpar@464:     \codex
alpar@464:   }
alpar@464:   %
alpar@464:   % If we end up with any active - characters when handling the index,
alpar@464:   % just treat them as a normal -.
alpar@464:   \global\def\indexbreaks{\catcode`\-=\active \let-\realdash}
alpar@464: }
alpar@464: 
alpar@464: \def\realdash{-}
alpar@464: \def\codedash{-\discretionary{}{}{}}
alpar@464: \def\codeunder{%
alpar@464:   % this is all so @math{@code{var_name}+1} can work.  In math mode, _
alpar@464:   % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
alpar@464:   % will therefore expand the active definition of _, which is us
alpar@464:   % (inside @code that is), therefore an endless loop.
alpar@464:   \ifusingtt{\ifmmode
alpar@464:                \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
alpar@464:              \else\normalunderscore \fi
alpar@464:              \discretionary{}{}{}}%
alpar@464:             {\_}%
alpar@464: }
alpar@464: \def\codex #1{\tclose{#1}\endgroup}
alpar@464: 
alpar@464: % @kbd is like @code, except that if the argument is just one @key command,
alpar@464: % then @kbd has no effect.
alpar@464: 
alpar@464: % @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
alpar@464: %   `example' (@kbd uses ttsl only inside of @example and friends),
alpar@464: %   or `code' (@kbd uses normal tty font always).
alpar@464: \def\kbdinputstyle{\parsearg\kbdinputstylexxx}
alpar@464: \def\kbdinputstylexxx#1{%
alpar@464:   \def\arg{#1}%
alpar@464:   \ifx\arg\worddistinct
alpar@464:     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
alpar@464:   \else\ifx\arg\wordexample
alpar@464:     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
alpar@464:   \else\ifx\arg\wordcode
alpar@464:     \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
alpar@464:   \else
alpar@464:     \errhelp = \EMsimple
alpar@464:     \errmessage{Unknown @kbdinputstyle option `\arg'}%
alpar@464:   \fi\fi\fi
alpar@464: }
alpar@464: \def\worddistinct{distinct}
alpar@464: \def\wordexample{example}
alpar@464: \def\wordcode{code}
alpar@464: 
alpar@464: % Default is `distinct.'
alpar@464: \kbdinputstyle distinct
alpar@464: 
alpar@464: \def\xkey{\key}
alpar@464: \def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}%
alpar@464: \ifx\one\xkey\ifx\threex\three \key{#2}%
alpar@464: \else{\tclose{\kbdfont\look}}\fi
alpar@464: \else{\tclose{\kbdfont\look}}\fi}
alpar@464: 
alpar@464: % For @url, @env, @command quotes seem unnecessary, so use \code.
alpar@464: \let\url=\code
alpar@464: \let\env=\code
alpar@464: \let\command=\code
alpar@464: 
alpar@464: % @uref (abbreviation for `urlref') takes an optional (comma-separated)
alpar@464: % second argument specifying the text to display and an optional third
alpar@464: % arg as text to display instead of (rather than in addition to) the url
alpar@464: % itself.  First (mandatory) arg is the url.  Perhaps eventually put in
alpar@464: % a hypertex \special here.
alpar@464: %
alpar@464: \def\uref#1{\douref #1,,,\finish}
alpar@464: \def\douref#1,#2,#3,#4\finish{\begingroup
alpar@464:   \unsepspaces
alpar@464:   \pdfurl{#1}%
alpar@464:   \setbox0 = \hbox{\ignorespaces #3}%
alpar@464:   \ifdim\wd0 > 0pt
alpar@464:     \unhbox0 % third arg given, show only that
alpar@464:   \else
alpar@464:     \setbox0 = \hbox{\ignorespaces #2}%
alpar@464:     \ifdim\wd0 > 0pt
alpar@464:       \ifpdf
alpar@464:         \unhbox0             % PDF: 2nd arg given, show only it
alpar@464:       \else
alpar@464:         \unhbox0\ (\code{#1})% DVI: 2nd arg given, show both it and url
alpar@464:       \fi
alpar@464:     \else
alpar@464:       \code{#1}% only url given, so show it
alpar@464:     \fi
alpar@464:   \fi
alpar@464:   \endlink
alpar@464: \endgroup}
alpar@464: 
alpar@464: % rms does not like angle brackets --karl, 17may97.
alpar@464: % So now @email is just like @uref, unless we are pdf.
alpar@464: %
alpar@464: %\def\email#1{\angleleft{\tt #1}\angleright}
alpar@464: \ifpdf
alpar@464:   \def\email#1{\doemail#1,,\finish}
alpar@464:   \def\doemail#1,#2,#3\finish{\begingroup
alpar@464:     \unsepspaces
alpar@464:     \pdfurl{mailto:#1}%
alpar@464:     \setbox0 = \hbox{\ignorespaces #2}%
alpar@464:     \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
alpar@464:     \endlink
alpar@464:   \endgroup}
alpar@464: \else
alpar@464:   \let\email=\uref
alpar@464: \fi
alpar@464: 
alpar@464: % Check if we are currently using a typewriter font.  Since all the
alpar@464: % Computer Modern typewriter fonts have zero interword stretch (and
alpar@464: % shrink), and it is reasonable to expect all typewriter fonts to have
alpar@464: % this property, we can check that font parameter.
alpar@464: %
alpar@464: \def\ifmonospace{\ifdim\fontdimen3\font=0pt }
alpar@464: 
alpar@464: % Typeset a dimension, e.g., `in' or `pt'.  The only reason for the
alpar@464: % argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
alpar@464: %
alpar@464: \def\dmn#1{\thinspace #1}
alpar@464: 
alpar@464: \def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par}
alpar@464: 
alpar@464: % @l was never documented to mean ``switch to the Lisp font'',
alpar@464: % and it is not used as such in any manual I can find.  We need it for
alpar@464: % Polish suppressed-l.  --karl, 22sep96.
alpar@464: %\def\l#1{{\li #1}\null}
alpar@464: 
alpar@464: % Explicit font changes: @r, @sc, undocumented @ii.
alpar@464: \def\r#1{{\rm #1}}              % roman font
alpar@464: \def\sc#1{{\smallcaps#1}}       % smallcaps font
alpar@464: \def\ii#1{{\it #1}}             % italic font
alpar@464: 
alpar@464: % @acronym downcases the argument and prints in smallcaps.
alpar@464: \def\acronym#1{{\smallcaps \lowercase{#1}}}
alpar@464: 
alpar@464: % @pounds{} is a sterling sign.
alpar@464: \def\pounds{{\it\$}}
alpar@464: 
alpar@464: % @registeredsymbol - R in a circle.  For now, only works in text size;
alpar@464: % we'd have to redo the font mechanism to change the \scriptstyle and
alpar@464: % \scriptscriptstyle font sizes to make it look right in headings.
alpar@464: % Adapted from the plain.tex definition of \copyright.
alpar@464: %
alpar@464: \def\registeredsymbol{%
alpar@464:   $^{{\ooalign{\hfil\raise.07ex\hbox{$\scriptstyle\rm R$}\hfil\crcr\Orb}}%
alpar@464:     }$%
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: \message{page headings,}
alpar@464: 
alpar@464: \newskip\titlepagetopglue \titlepagetopglue = 1.5in
alpar@464: \newskip\titlepagebottomglue \titlepagebottomglue = 2pc
alpar@464: 
alpar@464: % First the title page.  Must do @settitle before @titlepage.
alpar@464: \newif\ifseenauthor
alpar@464: \newif\iffinishedtitlepage
alpar@464: 
alpar@464: % Do an implicit @contents or @shortcontents after @end titlepage if the
alpar@464: % user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage.
alpar@464: %
alpar@464: \newif\ifsetcontentsaftertitlepage
alpar@464:  \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue
alpar@464: \newif\ifsetshortcontentsaftertitlepage
alpar@464:  \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
alpar@464: 
alpar@464: \def\shorttitlepage{\parsearg\shorttitlepagezzz}
alpar@464: \def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
alpar@464:         \endgroup\page\hbox{}\page}
alpar@464: 
alpar@464: \def\titlepage{\begingroup \parindent=0pt \textfonts
alpar@464:    \let\subtitlerm=\tenrm
alpar@464:    \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}%
alpar@464:    %
alpar@464:    \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
alpar@464:                    \let\tt=\authortt}%
alpar@464:    %
alpar@464:    % Leave some space at the very top of the page.
alpar@464:    \vglue\titlepagetopglue
alpar@464:    %
alpar@464:    % Now you can print the title using @title.
alpar@464:    \def\title{\parsearg\titlezzz}%
alpar@464:    \def\titlezzz##1{\leftline{\titlefonts\rm ##1}
alpar@464:                     % print a rule at the page bottom also.
alpar@464:                     \finishedtitlepagefalse
alpar@464:                     \vskip4pt \hrule height 4pt width \hsize \vskip4pt}%
alpar@464:    % No rule at page bottom unless we print one at the top with @title.
alpar@464:    \finishedtitlepagetrue
alpar@464:    %
alpar@464:    % Now you can put text using @subtitle.
alpar@464:    \def\subtitle{\parsearg\subtitlezzz}%
alpar@464:    \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}%
alpar@464:    %
alpar@464:    % @author should come last, but may come many times.
alpar@464:    \def\author{\parsearg\authorzzz}%
alpar@464:    \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
alpar@464:       {\authorfont \leftline{##1}}}%
alpar@464:    %
alpar@464:    % Most title ``pages'' are actually two pages long, with space
alpar@464:    % at the top of the second.  We don't want the ragged left on the second.
alpar@464:    \let\oldpage = \page
alpar@464:    \def\page{%
alpar@464:       \iffinishedtitlepage\else
alpar@464:          \finishtitlepage
alpar@464:       \fi
alpar@464:       \oldpage
alpar@464:       \let\page = \oldpage
alpar@464:       \hbox{}}%
alpar@464: %   \def\page{\oldpage \hbox{}}
alpar@464: }
alpar@464: 
alpar@464: \def\Etitlepage{%
alpar@464:    \iffinishedtitlepage\else
alpar@464:       \finishtitlepage
alpar@464:    \fi
alpar@464:    % It is important to do the page break before ending the group,
alpar@464:    % because the headline and footline are only empty inside the group.
alpar@464:    % If we use the new definition of \page, we always get a blank page
alpar@464:    % after the title page, which we certainly don't want.
alpar@464:    \oldpage
alpar@464:    \endgroup
alpar@464:    %
alpar@464:    % Need this before the \...aftertitlepage checks so that if they are
alpar@464:    % in effect the toc pages will come out with page numbers.
alpar@464:    \HEADINGSon
alpar@464:    %
alpar@464:    % If they want short, they certainly want long too.
alpar@464:    \ifsetshortcontentsaftertitlepage
alpar@464:      \shortcontents
alpar@464:      \contents
alpar@464:      \global\let\shortcontents = \relax
alpar@464:      \global\let\contents = \relax
alpar@464:    \fi
alpar@464:    %
alpar@464:    \ifsetcontentsaftertitlepage
alpar@464:      \contents
alpar@464:      \global\let\contents = \relax
alpar@464:      \global\let\shortcontents = \relax
alpar@464:    \fi
alpar@464: }
alpar@464: 
alpar@464: \def\finishtitlepage{%
alpar@464:    \vskip4pt \hrule height 2pt width \hsize
alpar@464:    \vskip\titlepagebottomglue
alpar@464:    \finishedtitlepagetrue
alpar@464: }
alpar@464: 
alpar@464: %%% Set up page headings and footings.
alpar@464: 
alpar@464: \let\thispage=\folio
alpar@464: 
alpar@464: \newtoks\evenheadline    % headline on even pages
alpar@464: \newtoks\oddheadline     % headline on odd pages
alpar@464: \newtoks\evenfootline    % footline on even pages
alpar@464: \newtoks\oddfootline     % footline on odd pages
alpar@464: 
alpar@464: % Now make Tex use those variables
alpar@464: \headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
alpar@464:                             \else \the\evenheadline \fi}}
alpar@464: \footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
alpar@464:                             \else \the\evenfootline \fi}\HEADINGShook}
alpar@464: \let\HEADINGShook=\relax
alpar@464: 
alpar@464: % Commands to set those variables.
alpar@464: % For example, this is what  @headings on  does
alpar@464: % @evenheading @thistitle|@thispage|@thischapter
alpar@464: % @oddheading @thischapter|@thispage|@thistitle
alpar@464: % @evenfooting @thisfile||
alpar@464: % @oddfooting ||@thisfile
alpar@464: 
alpar@464: \def\evenheading{\parsearg\evenheadingxxx}
alpar@464: \def\oddheading{\parsearg\oddheadingxxx}
alpar@464: \def\everyheading{\parsearg\everyheadingxxx}
alpar@464: 
alpar@464: \def\evenfooting{\parsearg\evenfootingxxx}
alpar@464: \def\oddfooting{\parsearg\oddfootingxxx}
alpar@464: \def\everyfooting{\parsearg\everyfootingxxx}
alpar@464: 
alpar@464: {\catcode`\@=0 %
alpar@464: 
alpar@464: \gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish}
alpar@464: \gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{%
alpar@464: \global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
alpar@464: 
alpar@464: \gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish}
alpar@464: \gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{%
alpar@464: \global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
alpar@464: 
alpar@464: \gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
alpar@464: 
alpar@464: \gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish}
alpar@464: \gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{%
alpar@464: \global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
alpar@464: 
alpar@464: \gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish}
alpar@464: \gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{%
alpar@464:   \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
alpar@464:   %
alpar@464:   % Leave some space for the footline.  Hopefully ok to assume
alpar@464:   % @evenfooting will not be used by itself.
alpar@464:   \global\advance\pageheight by -\baselineskip
alpar@464:   \global\advance\vsize by -\baselineskip
alpar@464: }
alpar@464: 
alpar@464: \gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}}
alpar@464: %
alpar@464: }% unbind the catcode of @.
alpar@464: 
alpar@464: % @headings double      turns headings on for double-sided printing.
alpar@464: % @headings single      turns headings on for single-sided printing.
alpar@464: % @headings off         turns them off.
alpar@464: % @headings on          same as @headings double, retained for compatibility.
alpar@464: % @headings after       turns on double-sided headings after this page.
alpar@464: % @headings doubleafter turns on double-sided headings after this page.
alpar@464: % @headings singleafter turns on single-sided headings after this page.
alpar@464: % By default, they are off at the start of a document,
alpar@464: % and turned `on' after @end titlepage.
alpar@464: 
alpar@464: \def\headings #1 {\csname HEADINGS#1\endcsname}
alpar@464: 
alpar@464: \def\HEADINGSoff{
alpar@464: \global\evenheadline={\hfil} \global\evenfootline={\hfil}
alpar@464: \global\oddheadline={\hfil} \global\oddfootline={\hfil}}
alpar@464: \HEADINGSoff
alpar@464: % When we turn headings on, set the page number to 1.
alpar@464: % For double-sided printing, put current file name in lower left corner,
alpar@464: % chapter name on inside top of right hand pages, document
alpar@464: % title on inside top of left hand pages, and page numbers on outside top
alpar@464: % edge of all pages.
alpar@464: \def\HEADINGSdouble{
alpar@464: \global\pageno=1
alpar@464: \global\evenfootline={\hfil}
alpar@464: \global\oddfootline={\hfil}
alpar@464: \global\evenheadline={\line{\folio\hfil\thistitle}}
alpar@464: \global\oddheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\let\contentsalignmacro = \chapoddpage
alpar@464: }
alpar@464: \let\contentsalignmacro = \chappager
alpar@464: 
alpar@464: % For single-sided printing, chapter title goes across top left of page,
alpar@464: % page number on top right.
alpar@464: \def\HEADINGSsingle{
alpar@464: \global\pageno=1
alpar@464: \global\evenfootline={\hfil}
alpar@464: \global\oddfootline={\hfil}
alpar@464: \global\evenheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\oddheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\let\contentsalignmacro = \chappager
alpar@464: }
alpar@464: \def\HEADINGSon{\HEADINGSdouble}
alpar@464: 
alpar@464: \def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
alpar@464: \let\HEADINGSdoubleafter=\HEADINGSafter
alpar@464: \def\HEADINGSdoublex{%
alpar@464: \global\evenfootline={\hfil}
alpar@464: \global\oddfootline={\hfil}
alpar@464: \global\evenheadline={\line{\folio\hfil\thistitle}}
alpar@464: \global\oddheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\let\contentsalignmacro = \chapoddpage
alpar@464: }
alpar@464: 
alpar@464: \def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
alpar@464: \def\HEADINGSsinglex{%
alpar@464: \global\evenfootline={\hfil}
alpar@464: \global\oddfootline={\hfil}
alpar@464: \global\evenheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\oddheadline={\line{\thischapter\hfil\folio}}
alpar@464: \global\let\contentsalignmacro = \chappager
alpar@464: }
alpar@464: 
alpar@464: % Subroutines used in generating headings
alpar@464: % This produces Day Month Year style of output.
alpar@464: % Only define if not already defined, in case a txi-??.tex file has set
alpar@464: % up a different format (e.g., txi-cs.tex does this).
alpar@464: \ifx\today\undefined
alpar@464: \def\today{%
alpar@464:   \number\day\space
alpar@464:   \ifcase\month
alpar@464:   \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
alpar@464:   \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
alpar@464:   \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
alpar@464:   \fi
alpar@464:   \space\number\year}
alpar@464: \fi
alpar@464: 
alpar@464: % @settitle line...  specifies the title of the document, for headings.
alpar@464: % It generates no output of its own.
alpar@464: \def\thistitle{\putwordNoTitle}
alpar@464: \def\settitle{\parsearg\settitlezzz}
alpar@464: \def\settitlezzz #1{\gdef\thistitle{#1}}
alpar@464: 
alpar@464: 
alpar@464: \message{tables,}
alpar@464: % Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x).
alpar@464: 
alpar@464: % default indentation of table text
alpar@464: \newdimen\tableindent \tableindent=.8in
alpar@464: % default indentation of @itemize and @enumerate text
alpar@464: \newdimen\itemindent  \itemindent=.3in
alpar@464: % margin between end of table item and start of table text.
alpar@464: \newdimen\itemmargin  \itemmargin=.1in
alpar@464: 
alpar@464: % used internally for \itemindent minus \itemmargin
alpar@464: \newdimen\itemmax
alpar@464: 
alpar@464: % Note @table, @vtable, and @vtable define @item, @itemx, etc., with
alpar@464: % these defs.
alpar@464: % They also define \itemindex
alpar@464: % to index the item name in whatever manner is desired (perhaps none).
alpar@464: 
alpar@464: \newif\ifitemxneedsnegativevskip
alpar@464: 
alpar@464: \def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
alpar@464: 
alpar@464: \def\internalBitem{\smallbreak \parsearg\itemzzz}
alpar@464: \def\internalBitemx{\itemxpar \parsearg\itemzzz}
alpar@464: 
alpar@464: \def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz}
alpar@464: \def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz}
alpar@464: 
alpar@464: \def\internalBkitem{\smallbreak \parsearg\kitemzzz}
alpar@464: \def\internalBkitemx{\itemxpar \parsearg\kitemzzz}
alpar@464: 
alpar@464: \def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}%
alpar@464:                  \itemzzz {#1}}
alpar@464: 
alpar@464: \def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}%
alpar@464:                  \itemzzz {#1}}
alpar@464: 
alpar@464: \def\itemzzz #1{\begingroup %
alpar@464:   \advance\hsize by -\rightskip
alpar@464:   \advance\hsize by -\tableindent
alpar@464:   \setbox0=\hbox{\itemfont{#1}}%
alpar@464:   \itemindex{#1}%
alpar@464:   \nobreak % This prevents a break before @itemx.
alpar@464:   %
alpar@464:   % If the item text does not fit in the space we have, put it on a line
alpar@464:   % by itself, and do not allow a page break either before or after that
alpar@464:   % line.  We do not start a paragraph here because then if the next
alpar@464:   % command is, e.g., @kindex, the whatsit would get put into the
alpar@464:   % horizontal list on a line by itself, resulting in extra blank space.
alpar@464:   \ifdim \wd0>\itemmax
alpar@464:     %
alpar@464:     % Make this a paragraph so we get the \parskip glue and wrapping,
alpar@464:     % but leave it ragged-right.
alpar@464:     \begingroup
alpar@464:       \advance\leftskip by-\tableindent
alpar@464:       \advance\hsize by\tableindent
alpar@464:       \advance\rightskip by0pt plus1fil
alpar@464:       \leavevmode\unhbox0\par
alpar@464:     \endgroup
alpar@464:     %
alpar@464:     % We're going to be starting a paragraph, but we don't want the
alpar@464:     % \parskip glue -- logically it's part of the @item we just started.
alpar@464:     \nobreak \vskip-\parskip
alpar@464:     %
alpar@464:     % Stop a page break at the \parskip glue coming up.  (Unfortunately
alpar@464:     % we can't prevent a possible page break at the following
alpar@464:     % \baselineskip glue.)  However, if what follows is an environment
alpar@464:     % such as @example, there will be no \parskip glue; then
alpar@464:     % the negative vskip we just would cause the example and the item to
alpar@464:     % crash together.  So we use this bizarre value of 10001 as a signal
alpar@464:     % to \aboveenvbreak to insert \parskip glue after all.
alpar@464:     % (Possibly there are other commands that could be followed by
alpar@464:     % @example which need the same treatment, but not section titles; or
alpar@464:     % maybe section titles are the only special case and they should be
alpar@464:     % penalty 10001...)
alpar@464:     \penalty 10001
alpar@464:     \endgroup
alpar@464:     \itemxneedsnegativevskipfalse
alpar@464:   \else
alpar@464:     % The item text fits into the space.  Start a paragraph, so that the
alpar@464:     % following text (if any) will end up on the same line.
alpar@464:     \noindent
alpar@464:     % Do this with kerns and \unhbox so that if there is a footnote in
alpar@464:     % the item text, it can migrate to the main vertical list and
alpar@464:     % eventually be printed.
alpar@464:     \nobreak\kern-\tableindent
alpar@464:     \dimen0 = \itemmax  \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
alpar@464:     \unhbox0
alpar@464:     \nobreak\kern\dimen0
alpar@464:     \endgroup
alpar@464:     \itemxneedsnegativevskiptrue
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: \def\item{\errmessage{@item while not in a table}}
alpar@464: \def\itemx{\errmessage{@itemx while not in a table}}
alpar@464: \def\kitem{\errmessage{@kitem while not in a table}}
alpar@464: \def\kitemx{\errmessage{@kitemx while not in a table}}
alpar@464: \def\xitem{\errmessage{@xitem while not in a table}}
alpar@464: \def\xitemx{\errmessage{@xitemx while not in a table}}
alpar@464: 
alpar@464: % Contains a kludge to get @end[description] to work.
alpar@464: \def\description{\tablez{\dontindex}{1}{}{}{}{}}
alpar@464: 
alpar@464: % @table, @ftable, @vtable.
alpar@464: \def\table{\begingroup\inENV\obeylines\obeyspaces\tablex}
alpar@464: {\obeylines\obeyspaces%
alpar@464: \gdef\tablex #1^^M{%
alpar@464: \tabley\dontindex#1        \endtabley}}
alpar@464: 
alpar@464: \def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex}
alpar@464: {\obeylines\obeyspaces%
alpar@464: \gdef\ftablex #1^^M{%
alpar@464: \tabley\fnitemindex#1        \endtabley
alpar@464: \def\Eftable{\endgraf\afterenvbreak\endgroup}%
alpar@464: \let\Etable=\relax}}
alpar@464: 
alpar@464: \def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex}
alpar@464: {\obeylines\obeyspaces%
alpar@464: \gdef\vtablex #1^^M{%
alpar@464: \tabley\vritemindex#1        \endtabley
alpar@464: \def\Evtable{\endgraf\afterenvbreak\endgroup}%
alpar@464: \let\Etable=\relax}}
alpar@464: 
alpar@464: \def\dontindex #1{}
alpar@464: \def\fnitemindex #1{\doind {fn}{\code{#1}}}%
alpar@464: \def\vritemindex #1{\doind {vr}{\code{#1}}}%
alpar@464: 
alpar@464: {\obeyspaces %
alpar@464: \gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup%
alpar@464: \tablez{#1}{#2}{#3}{#4}{#5}{#6}}}
alpar@464: 
alpar@464: \def\tablez #1#2#3#4#5#6{%
alpar@464: \aboveenvbreak %
alpar@464: \begingroup %
alpar@464: \def\Edescription{\Etable}% Necessary kludge.
alpar@464: \let\itemindex=#1%
alpar@464: \ifnum 0#3>0 \advance \leftskip by #3\mil \fi %
alpar@464: \ifnum 0#4>0 \tableindent=#4\mil \fi %
alpar@464: \ifnum 0#5>0 \advance \rightskip by #5\mil \fi %
alpar@464: \def\itemfont{#2}%
alpar@464: \itemmax=\tableindent %
alpar@464: \advance \itemmax by -\itemmargin %
alpar@464: \advance \leftskip by \tableindent %
alpar@464: \exdentamount=\tableindent
alpar@464: \parindent = 0pt
alpar@464: \parskip = \smallskipamount
alpar@464: \ifdim \parskip=0pt \parskip=2pt \fi%
alpar@464: \def\Etable{\endgraf\afterenvbreak\endgroup}%
alpar@464: \let\item = \internalBitem %
alpar@464: \let\itemx = \internalBitemx %
alpar@464: \let\kitem = \internalBkitem %
alpar@464: \let\kitemx = \internalBkitemx %
alpar@464: \let\xitem = \internalBxitem %
alpar@464: \let\xitemx = \internalBxitemx %
alpar@464: }
alpar@464: 
alpar@464: % This is the counter used by @enumerate, which is really @itemize
alpar@464: 
alpar@464: \newcount \itemno
alpar@464: 
alpar@464: \def\itemize{\parsearg\itemizezzz}
alpar@464: 
alpar@464: \def\itemizezzz #1{%
alpar@464:   \begingroup % ended by the @end itemize
alpar@464:   \itemizey {#1}{\Eitemize}
alpar@464: }
alpar@464: 
alpar@464: \def\itemizey#1#2{%
alpar@464:   \aboveenvbreak
alpar@464:   \itemmax=\itemindent
alpar@464:   \advance\itemmax by -\itemmargin
alpar@464:   \advance\leftskip by \itemindent
alpar@464:   \exdentamount=\itemindent
alpar@464:   \parindent=0pt
alpar@464:   \parskip=\smallskipamount
alpar@464:   \ifdim\parskip=0pt \parskip=2pt \fi
alpar@464:   \def#2{\endgraf\afterenvbreak\endgroup}%
alpar@464:   \def\itemcontents{#1}%
alpar@464:   % @itemize with no arg is equivalent to @itemize @bullet.
alpar@464:   \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
alpar@464:   \let\item=\itemizeitem
alpar@464: }
alpar@464: 
alpar@464: % \splitoff TOKENS\endmark defines \first to be the first token in
alpar@464: % TOKENS, and \rest to be the remainder.
alpar@464: %
alpar@464: \def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
alpar@464: 
alpar@464: % Allow an optional argument of an uppercase letter, lowercase letter,
alpar@464: % or number, to specify the first label in the enumerated list.  No
alpar@464: % argument is the same as `1'.
alpar@464: %
alpar@464: \def\enumerate{\parsearg\enumeratezzz}
alpar@464: \def\enumeratezzz #1{\enumeratey #1  \endenumeratey}
alpar@464: \def\enumeratey #1 #2\endenumeratey{%
alpar@464:   \begingroup % ended by the @end enumerate
alpar@464:   %
alpar@464:   % If we were given no argument, pretend we were given `1'.
alpar@464:   \def\thearg{#1}%
alpar@464:   \ifx\thearg\empty \def\thearg{1}\fi
alpar@464:   %
alpar@464:   % Detect if the argument is a single token.  If so, it might be a
alpar@464:   % letter.  Otherwise, the only valid thing it can be is a number.
alpar@464:   % (We will always have one token, because of the test we just made.
alpar@464:   % This is a good thing, since \splitoff doesn't work given nothing at
alpar@464:   % all -- the first parameter is undelimited.)
alpar@464:   \expandafter\splitoff\thearg\endmark
alpar@464:   \ifx\rest\empty
alpar@464:     % Only one token in the argument.  It could still be anything.
alpar@464:     % A ``lowercase letter'' is one whose \lccode is nonzero.
alpar@464:     % An ``uppercase letter'' is one whose \lccode is both nonzero, and
alpar@464:     %   not equal to itself.
alpar@464:     % Otherwise, we assume it's a number.
alpar@464:     %
alpar@464:     % We need the \relax at the end of the \ifnum lines to stop TeX from
alpar@464:     % continuing to look for a <number>.
alpar@464:     %
alpar@464:     \ifnum\lccode\expandafter`\thearg=0\relax
alpar@464:       \numericenumerate % a number (we hope)
alpar@464:     \else
alpar@464:       % It's a letter.
alpar@464:       \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
alpar@464:         \lowercaseenumerate % lowercase letter
alpar@464:       \else
alpar@464:         \uppercaseenumerate % uppercase letter
alpar@464:       \fi
alpar@464:     \fi
alpar@464:   \else
alpar@464:     % Multiple tokens in the argument.  We hope it's a number.
alpar@464:     \numericenumerate
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % An @enumerate whose labels are integers.  The starting integer is
alpar@464: % given in \thearg.
alpar@464: %
alpar@464: \def\numericenumerate{%
alpar@464:   \itemno = \thearg
alpar@464:   \startenumeration{\the\itemno}%
alpar@464: }
alpar@464: 
alpar@464: % The starting (lowercase) letter is in \thearg.
alpar@464: \def\lowercaseenumerate{%
alpar@464:   \itemno = \expandafter`\thearg
alpar@464:   \startenumeration{%
alpar@464:     % Be sure we're not beyond the end of the alphabet.
alpar@464:     \ifnum\itemno=0
alpar@464:       \errmessage{No more lowercase letters in @enumerate; get a bigger
alpar@464:                   alphabet}%
alpar@464:     \fi
alpar@464:     \char\lccode\itemno
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % The starting (uppercase) letter is in \thearg.
alpar@464: \def\uppercaseenumerate{%
alpar@464:   \itemno = \expandafter`\thearg
alpar@464:   \startenumeration{%
alpar@464:     % Be sure we're not beyond the end of the alphabet.
alpar@464:     \ifnum\itemno=0
alpar@464:       \errmessage{No more uppercase letters in @enumerate; get a bigger
alpar@464:                   alphabet}
alpar@464:     \fi
alpar@464:     \char\uccode\itemno
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % Call itemizey, adding a period to the first argument and supplying the
alpar@464: % common last two arguments.  Also subtract one from the initial value in
alpar@464: % \itemno, since @item increments \itemno.
alpar@464: %
alpar@464: \def\startenumeration#1{%
alpar@464:   \advance\itemno by -1
alpar@464:   \itemizey{#1.}\Eenumerate\flushcr
alpar@464: }
alpar@464: 
alpar@464: % @alphaenumerate and @capsenumerate are abbreviations for giving an arg
alpar@464: % to @enumerate.
alpar@464: %
alpar@464: \def\alphaenumerate{\enumerate{a}}
alpar@464: \def\capsenumerate{\enumerate{A}}
alpar@464: \def\Ealphaenumerate{\Eenumerate}
alpar@464: \def\Ecapsenumerate{\Eenumerate}
alpar@464: 
alpar@464: % Definition of @item while inside @itemize.
alpar@464: 
alpar@464: \def\itemizeitem{%
alpar@464: \advance\itemno by 1
alpar@464: {\let\par=\endgraf \smallbreak}%
alpar@464: \ifhmode \errmessage{In hmode at itemizeitem}\fi
alpar@464: {\parskip=0in \hskip 0pt
alpar@464: \hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
alpar@464: \vadjust{\penalty 1200}}%
alpar@464: \flushcr}
alpar@464: 
alpar@464: % @multitable macros
alpar@464: % Amy Hendrickson, 8/18/94, 3/6/96
alpar@464: %
alpar@464: % @multitable ... @end multitable will make as many columns as desired.
alpar@464: % Contents of each column will wrap at width given in preamble.  Width
alpar@464: % can be specified either with sample text given in a template line,
alpar@464: % or in percent of \hsize, the current width of text on page.
alpar@464: 
alpar@464: % Table can continue over pages but will only break between lines.
alpar@464: 
alpar@464: % To make preamble:
alpar@464: %
alpar@464: % Either define widths of columns in terms of percent of \hsize:
alpar@464: %   @multitable @columnfractions .25 .3 .45
alpar@464: %   @item ...
alpar@464: %
alpar@464: %   Numbers following @columnfractions are the percent of the total
alpar@464: %   current hsize to be used for each column. You may use as many
alpar@464: %   columns as desired.
alpar@464: 
alpar@464: 
alpar@464: % Or use a template:
alpar@464: %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
alpar@464: %   @item ...
alpar@464: %   using the widest term desired in each column.
alpar@464: %
alpar@464: % For those who want to use more than one line's worth of words in
alpar@464: % the preamble, break the line within one argument and it
alpar@464: % will parse correctly, i.e.,
alpar@464: %
alpar@464: %     @multitable {Column 1 template} {Column 2 template} {Column 3
alpar@464: %      template}
alpar@464: % Not:
alpar@464: %     @multitable {Column 1 template} {Column 2 template}
alpar@464: %      {Column 3 template}
alpar@464: 
alpar@464: % Each new table line starts with @item, each subsequent new column
alpar@464: % starts with @tab. Empty columns may be produced by supplying @tab's
alpar@464: % with nothing between them for as many times as empty columns are needed,
alpar@464: % ie, @tab@tab@tab will produce two empty columns.
alpar@464: 
alpar@464: % @item, @tab, @multitable or @end multitable do not need to be on their
alpar@464: % own lines, but it will not hurt if they are.
alpar@464: 
alpar@464: % Sample multitable:
alpar@464: 
alpar@464: %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
alpar@464: %   @item first col stuff @tab second col stuff @tab third col
alpar@464: %   @item
alpar@464: %   first col stuff
alpar@464: %   @tab
alpar@464: %   second col stuff
alpar@464: %   @tab
alpar@464: %   third col
alpar@464: %   @item first col stuff @tab second col stuff
alpar@464: %   @tab Many paragraphs of text may be used in any column.
alpar@464: %
alpar@464: %         They will wrap at the width determined by the template.
alpar@464: %   @item@tab@tab This will be in third column.
alpar@464: %   @end multitable
alpar@464: 
alpar@464: % Default dimensions may be reset by user.
alpar@464: % @multitableparskip is vertical space between paragraphs in table.
alpar@464: % @multitableparindent is paragraph indent in table.
alpar@464: % @multitablecolmargin is horizontal space to be left between columns.
alpar@464: % @multitablelinespace is space to leave between table items, baseline
alpar@464: %                                                            to baseline.
alpar@464: %   0pt means it depends on current normal line spacing.
alpar@464: %
alpar@464: \newskip\multitableparskip
alpar@464: \newskip\multitableparindent
alpar@464: \newdimen\multitablecolspace
alpar@464: \newskip\multitablelinespace
alpar@464: \multitableparskip=0pt
alpar@464: \multitableparindent=6pt
alpar@464: \multitablecolspace=12pt
alpar@464: \multitablelinespace=0pt
alpar@464: 
alpar@464: % Macros used to set up halign preamble:
alpar@464: %
alpar@464: \let\endsetuptable\relax
alpar@464: \def\xendsetuptable{\endsetuptable}
alpar@464: \let\columnfractions\relax
alpar@464: \def\xcolumnfractions{\columnfractions}
alpar@464: \newif\ifsetpercent
alpar@464: 
alpar@464: % #1 is the part of the @columnfraction before the decimal point, which
alpar@464: % is presumably either 0 or the empty string (but we don't check, we
alpar@464: % just throw it away).  #2 is the decimal part, which we use as the
alpar@464: % percent of \hsize for this column.
alpar@464: \def\pickupwholefraction#1.#2 {%
alpar@464:   \global\advance\colcount by 1
alpar@464:   \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
alpar@464:   \setuptable
alpar@464: }
alpar@464: 
alpar@464: \newcount\colcount
alpar@464: \def\setuptable#1{%
alpar@464:   \def\firstarg{#1}%
alpar@464:   \ifx\firstarg\xendsetuptable
alpar@464:     \let\go = \relax
alpar@464:   \else
alpar@464:     \ifx\firstarg\xcolumnfractions
alpar@464:       \global\setpercenttrue
alpar@464:     \else
alpar@464:       \ifsetpercent
alpar@464:          \let\go\pickupwholefraction
alpar@464:       \else
alpar@464:          \global\advance\colcount by 1
alpar@464:          \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
alpar@464:                    % separator; typically that is always in the input, anyway.
alpar@464:          \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
alpar@464:       \fi
alpar@464:     \fi
alpar@464:     \ifx\go\pickupwholefraction
alpar@464:       % Put the argument back for the \pickupwholefraction call, so
alpar@464:       % we'll always have a period there to be parsed.
alpar@464:       \def\go{\pickupwholefraction#1}%
alpar@464:     \else
alpar@464:       \let\go = \setuptable
alpar@464:     \fi%
alpar@464:   \fi
alpar@464:   \go
alpar@464: }
alpar@464: 
alpar@464: % @multitable ... @end multitable definitions:
alpar@464: %
alpar@464: \def\multitable{\parsearg\dotable}
alpar@464: \def\dotable#1{\bgroup
alpar@464:   \vskip\parskip
alpar@464:   \let\item=\crcrwithfootnotes
alpar@464:   % A \tab used to include \hskip1sp.  But then the space in a template
alpar@464:   % line is not enough.  That is bad.  So let's go back to just & until
alpar@464:   % we encounter the problem it was intended to solve again.  --karl,
alpar@464:   % nathan@acm.org, 20apr99.
alpar@464:   \let\tab=&%
alpar@464:   \let\startfootins=\startsavedfootnote
alpar@464:   \tolerance=9500
alpar@464:   \hbadness=9500
alpar@464:   \setmultitablespacing
alpar@464:   \parskip=\multitableparskip
alpar@464:   \parindent=\multitableparindent
alpar@464:   \overfullrule=0pt
alpar@464:   \global\colcount=0
alpar@464:   \def\Emultitable{%
alpar@464:     \global\setpercentfalse
alpar@464:     \crcrwithfootnotes\crcr
alpar@464:     \egroup\egroup
alpar@464:   }%
alpar@464:   %
alpar@464:   % To parse everything between @multitable and @item:
alpar@464:   \setuptable#1 \endsetuptable
alpar@464:   %
alpar@464:   % \everycr will reset column counter, \colcount, at the end of
alpar@464:   % each line. Every column entry will cause \colcount to advance by one.
alpar@464:   % The table preamble
alpar@464:   % looks at the current \colcount to find the correct column width.
alpar@464:   \everycr{\noalign{%
alpar@464:   %
alpar@464:   % \filbreak%% keeps underfull box messages off when table breaks over pages.
alpar@464:   % Maybe so, but it also creates really weird page breaks when the table
alpar@464:   % breaks over pages. Wouldn't \vfil be better?  Wait until the problem
alpar@464:   % manifests itself, so it can be fixed for real --karl.
alpar@464:     \global\colcount=0\relax}}%
alpar@464:   %
alpar@464:   % This preamble sets up a generic column definition, which will
alpar@464:   % be used as many times as user calls for columns.
alpar@464:   % \vtop will set a single line and will also let text wrap and
alpar@464:   % continue for many paragraphs if desired.
alpar@464:   \halign\bgroup&\global\advance\colcount by 1\relax
alpar@464:     \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
alpar@464:   %
alpar@464:   % In order to keep entries from bumping into each other
alpar@464:   % we will add a \leftskip of \multitablecolspace to all columns after
alpar@464:   % the first one.
alpar@464:   %
alpar@464:   % If a template has been used, we will add \multitablecolspace
alpar@464:   % to the width of each template entry.
alpar@464:   %
alpar@464:   % If the user has set preamble in terms of percent of \hsize we will
alpar@464:   % use that dimension as the width of the column, and the \leftskip
alpar@464:   % will keep entries from bumping into each other.  Table will start at
alpar@464:   % left margin and final column will justify at right margin.
alpar@464:   %
alpar@464:   % Make sure we don't inherit \rightskip from the outer environment.
alpar@464:   \rightskip=0pt
alpar@464:   \ifnum\colcount=1
alpar@464:     % The first column will be indented with the surrounding text.
alpar@464:     \advance\hsize by\leftskip
alpar@464:   \else
alpar@464:     \ifsetpercent \else
alpar@464:       % If user has not set preamble in terms of percent of \hsize
alpar@464:       % we will advance \hsize by \multitablecolspace.
alpar@464:       \advance\hsize by \multitablecolspace
alpar@464:     \fi
alpar@464:    % In either case we will make \leftskip=\multitablecolspace:
alpar@464:   \leftskip=\multitablecolspace
alpar@464:   \fi
alpar@464:   % Ignoring space at the beginning and end avoids an occasional spurious
alpar@464:   % blank line, when TeX decides to break the line at the space before the
alpar@464:   % box from the multistrut, so the strut ends up on a line by itself.
alpar@464:   % For example:
alpar@464:   % @multitable @columnfractions .11 .89
alpar@464:   % @item @code{#}
alpar@464:   % @tab Legal holiday which is valid in major parts of the whole country.
alpar@464:   % Is automatically provided with highlighting sequences respectively marking
alpar@464:   % characters.
alpar@464:   \noindent\ignorespaces##\unskip\multistrut}\cr
alpar@464: }
alpar@464: 
alpar@464: \def\setmultitablespacing{% test to see if user has set \multitablelinespace.
alpar@464: % If so, do nothing. If not, give it an appropriate dimension based on
alpar@464: % current baselineskip.
alpar@464: \ifdim\multitablelinespace=0pt
alpar@464: \setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
alpar@464: \global\advance\multitablelinespace by-\ht0
alpar@464: %% strut to put in table in case some entry doesn't have descenders,
alpar@464: %% to keep lines equally spaced
alpar@464: \let\multistrut = \strut
alpar@464: \else
alpar@464: %% FIXME: what is \box0 supposed to be?
alpar@464: \gdef\multistrut{\vrule height\multitablelinespace depth\dp0
alpar@464: width0pt\relax} \fi
alpar@464: %% Test to see if parskip is larger than space between lines of
alpar@464: %% table. If not, do nothing.
alpar@464: %%        If so, set to same dimension as multitablelinespace.
alpar@464: \ifdim\multitableparskip>\multitablelinespace
alpar@464: \global\multitableparskip=\multitablelinespace
alpar@464: \global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
alpar@464:                                       %% than skip between lines in the table.
alpar@464: \fi%
alpar@464: \ifdim\multitableparskip=0pt
alpar@464: \global\multitableparskip=\multitablelinespace
alpar@464: \global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
alpar@464:                                       %% than skip between lines in the table.
alpar@464: \fi}
alpar@464: 
alpar@464: % In case a @footnote appears inside an alignment, save the footnote
alpar@464: % text to a box and make the \insert when a row of the table is
alpar@464: % finished.  Otherwise, the insertion is lost, it never migrates to the
alpar@464: % main vertical list.  --kasal, 22jan03.
alpar@464: %
alpar@464: \newbox\savedfootnotes
alpar@464: %
alpar@464: % \dotable \let's \startfootins to this, so that \dofootnote will call
alpar@464: % it instead of starting the insertion right away.
alpar@464: \def\startsavedfootnote{%
alpar@464:   \global\setbox\savedfootnotes = \vbox\bgroup
alpar@464:     \unvbox\savedfootnotes
alpar@464: }
alpar@464: \def\crcrwithfootnotes{%
alpar@464:   \crcr
alpar@464:   \ifvoid\savedfootnotes \else
alpar@464:     \noalign{\insert\footins{\box\savedfootnotes}}%
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: \message{conditionals,}
alpar@464: % Prevent errors for section commands.
alpar@464: % Used in @ignore and in failing conditionals.
alpar@464: \def\ignoresections{%
alpar@464:   \let\appendix=\relax
alpar@464:   \let\appendixsec=\relax
alpar@464:   \let\appendixsection=\relax
alpar@464:   \let\appendixsubsec=\relax
alpar@464:   \let\appendixsubsection=\relax
alpar@464:   \let\appendixsubsubsec=\relax
alpar@464:   \let\appendixsubsubsection=\relax
alpar@464:   %\let\begin=\relax
alpar@464:   %\let\bye=\relax
alpar@464:   \let\centerchap=\relax
alpar@464:   \let\chapter=\relax
alpar@464:   \let\contents=\relax
alpar@464:   \let\section=\relax
alpar@464:   \let\smallbook=\relax
alpar@464:   \let\subsec=\relax
alpar@464:   \let\subsection=\relax
alpar@464:   \let\subsubsec=\relax
alpar@464:   \let\subsubsection=\relax
alpar@464:   \let\titlepage=\relax
alpar@464:   \let\top=\relax
alpar@464:   \let\unnumbered=\relax
alpar@464:   \let\unnumberedsec=\relax
alpar@464:   \let\unnumberedsection=\relax
alpar@464:   \let\unnumberedsubsec=\relax
alpar@464:   \let\unnumberedsubsection=\relax
alpar@464:   \let\unnumberedsubsubsec=\relax
alpar@464:   \let\unnumberedsubsubsection=\relax
alpar@464: }
alpar@464: 
alpar@464: % Ignore @ignore, @ifhtml, @ifinfo, and the like.
alpar@464: %
alpar@464: \def\direntry{\doignore{direntry}}
alpar@464: \def\documentdescriptionword{documentdescription}
alpar@464: \def\documentdescription{\doignore{documentdescription}}
alpar@464: \def\html{\doignore{html}}
alpar@464: \def\ifhtml{\doignore{ifhtml}}
alpar@464: \def\ifinfo{\doignore{ifinfo}}
alpar@464: \def\ifnottex{\doignore{ifnottex}}
alpar@464: \def\ifplaintext{\doignore{ifplaintext}}
alpar@464: \def\ifxml{\doignore{ifxml}}
alpar@464: \def\ignore{\doignore{ignore}}
alpar@464: \def\menu{\doignore{menu}}
alpar@464: \def\xml{\doignore{xml}}
alpar@464: 
alpar@464: % @dircategory CATEGORY  -- specify a category of the dir file
alpar@464: % which this file should belong to.  Ignore this in TeX.
alpar@464: \let\dircategory = \comment
alpar@464: 
alpar@464: % Ignore text until a line `@end #1', keeping track of nested conditionals.
alpar@464: %
alpar@464: % A count to remember the depth of nesting.
alpar@464: \newcount\doignorecount  \doignorecount = 0
alpar@464: 
alpar@464: \def\doignore#1{\begingroup
alpar@464:   % Don't complain about control sequences we have declared \outer.
alpar@464:   \ignoresections
alpar@464:   %
alpar@464:   % Make sure that spaces turn into tokens that match what \doignoretext wants.
alpar@464:   \catcode\spaceChar = 10
alpar@464:   %
alpar@464:   % Ignore braces, so mismatched braces don't cause trouble.
alpar@464:   \catcode`\{ = 9
alpar@464:   \catcode`\} = 9
alpar@464:   %
alpar@464:   % Count number of #1's that we've seen.
alpar@464:   \doignorecount = 0
alpar@464:   %
alpar@464:   % Swallow text until we reach the matching `@end #1'.
alpar@464:   \expandafter \dodoignore \csname#1\endcsname {#1}%
alpar@464: }
alpar@464: 
alpar@464: { \catcode`@=11 % We want to use \ST@P which cannot appear in texinfo source.
alpar@464:   \obeylines %
alpar@464:   %
alpar@464:   \gdef\dodoignore#1#2{%
alpar@464:     % #1 contains, e.g., \ifinfo, a.k.a. @ifinfo.
alpar@464:     % #2 contains the string `ifinfo'.
alpar@464:     %
alpar@464:     % Define a command to find the next `@end #2', which must be on a line
alpar@464:     % by itself.
alpar@464:     \long\def\doignoretext##1^^M\end #2{\doignoretextyyy##1^^M#1\ST@P}%
alpar@464:     % And this command to find another #1 command, at the beginning of a
alpar@464:     % line.  (Otherwise, we would consider a line `@c @ifset', for
alpar@464:     % example, to count as an @ifset for nesting.)
alpar@464:     \long\def\doignoretextyyy##1^^M#1##2\ST@P{\doignoreyyy{##2}\ST@P}%
alpar@464:     %
alpar@464:     % And now expand that command.
alpar@464:     \obeylines %
alpar@464:     \doignoretext ^^M%
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: \def\doignoreyyy#1{%
alpar@464:   \def\temp{#1}%
alpar@464:   \ifx\temp\empty			% Nothing found.
alpar@464:     \let\next\doignoretextzzz
alpar@464:   \else					% Found a nested condition, ...
alpar@464:     \advance\doignorecount by 1
alpar@464:     \let\next\doignoretextyyy		% ..., look for another.
alpar@464:     % If we're here, #1 ends with \ifinfo (for example).
alpar@464:   \fi
alpar@464:   \next #1% the token \ST@P is present just after this macro.
alpar@464: }
alpar@464: 
alpar@464: % We have to swallow the remaining "\ST@P".
alpar@464: % 
alpar@464: \def\doignoretextzzz#1{%
alpar@464:   \ifnum\doignorecount = 0	% We have just found the outermost @end.
alpar@464:     \let\next\enddoignore
alpar@464:   \else				% Still inside a nested condition.
alpar@464:     \advance\doignorecount by -1
alpar@464:     \let\next\doignoretext      % Look for the next @end.
alpar@464:   \fi
alpar@464:   \next
alpar@464: }
alpar@464: 
alpar@464: % Finish off ignored text.
alpar@464: \def\enddoignore{\endgroup\ignorespaces}
alpar@464: 
alpar@464: 
alpar@464: % @set VAR sets the variable VAR to an empty value.
alpar@464: % @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
alpar@464: %
alpar@464: % Since we want to separate VAR from REST-OF-LINE (which might be
alpar@464: % empty), we can't just use \parsearg; we have to insert a space of our
alpar@464: % own to delimit the rest of the line, and then take it out again if we
alpar@464: % didn't need it.  Make sure the catcode of space is correct to avoid
alpar@464: % losing inside @example, for instance.
alpar@464: %
alpar@464: \def\set{\begingroup\catcode` =10
alpar@464:   \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR.
alpar@464:   \parsearg\setxxx}
alpar@464: \def\setxxx#1{\setyyy#1 \endsetyyy}
alpar@464: \def\setyyy#1 #2\endsetyyy{%
alpar@464:   \def\temp{#2}%
alpar@464:   \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
alpar@464:   \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
alpar@464:   \fi
alpar@464:   \endgroup
alpar@464: }
alpar@464: % Can't use \xdef to pre-expand #2 and save some time, since \temp or
alpar@464: % \next or other control sequences that we've defined might get us into
alpar@464: % an infinite loop. Consider `@set foo @cite{bar}'.
alpar@464: \def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}}
alpar@464: 
alpar@464: % @clear VAR clears (i.e., unsets) the variable VAR.
alpar@464: %
alpar@464: \def\clear{\parsearg\clearxxx}
alpar@464: \def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax}
alpar@464: 
alpar@464: % @value{foo} gets the text saved in variable foo.
alpar@464: {
alpar@464:   \catcode`\_ = \active
alpar@464:   %
alpar@464:   % We might end up with active _ or - characters in the argument if
alpar@464:   % we're called from @code, as @code{@value{foo-bar_}}.  So \let any
alpar@464:   % such active characters to their normal equivalents.
alpar@464:   \gdef\value{\begingroup
alpar@464:     \catcode`\-=\other \catcode`\_=\other
alpar@464:     \indexbreaks \let_\normalunderscore
alpar@464:     \valuexxx}
alpar@464: }
alpar@464: \def\valuexxx#1{\expandablevalue{#1}\endgroup}
alpar@464: 
alpar@464: % We have this subroutine so that we can handle at least some @value's
alpar@464: % properly in indexes (we \let\value to this in \indexdummies).  Ones
alpar@464: % whose names contain - or _ still won't work, but we can't do anything
alpar@464: % about that.  The command has to be fully expandable (if the variable
alpar@464: % is set), since the result winds up in the index file.  This means that
alpar@464: % if the variable's value contains other Texinfo commands, it's almost
alpar@464: % certain it will fail (although perhaps we could fix that with
alpar@464: % sufficient work to do a one-level expansion on the result, instead of
alpar@464: % complete).
alpar@464: %
alpar@464: \def\expandablevalue#1{%
alpar@464:   \expandafter\ifx\csname SET#1\endcsname\relax
alpar@464:     {[No value for ``#1'']}%
alpar@464:     \message{Variable `#1', used in @value, is not set.}%
alpar@464:   \else
alpar@464:     \csname SET#1\endcsname
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
alpar@464: % with @set.
alpar@464: %
alpar@464: \def\ifset{\parsearg\doifset}
alpar@464: \def\doifset#1{%
alpar@464:   \expandafter\ifx\csname SET#1\endcsname\relax
alpar@464:     \let\next=\ifsetfail
alpar@464:   \else
alpar@464:     \let\next=\ifsetsucceed
alpar@464:   \fi
alpar@464:   \next
alpar@464: }
alpar@464: \def\ifsetsucceed{\conditionalsucceed{ifset}}
alpar@464: \def\ifsetfail{\doignore{ifset}}
alpar@464: \defineunmatchedend{ifset}
alpar@464: 
alpar@464: % @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
alpar@464: % defined with @set, or has been undefined with @clear.
alpar@464: %
alpar@464: \def\ifclear{\parsearg\doifclear}
alpar@464: \def\doifclear#1{%
alpar@464:   \expandafter\ifx\csname SET#1\endcsname\relax
alpar@464:     \let\next=\ifclearsucceed
alpar@464:   \else
alpar@464:     \let\next=\ifclearfail
alpar@464:   \fi
alpar@464:   \next
alpar@464: }
alpar@464: \def\ifclearsucceed{\conditionalsucceed{ifclear}}
alpar@464: \def\ifclearfail{\doignore{ifclear}}
alpar@464: \defineunmatchedend{ifclear}
alpar@464: 
alpar@464: % @iftex, @ifnothtml, @ifnotinfo, @ifnotplaintext always succeed; we
alpar@464: % read the text following, through the first @end iftex (etc.).  Make
alpar@464: % `@end iftex' (etc.) valid only after an @iftex.
alpar@464: %
alpar@464: \def\iftex{\conditionalsucceed{iftex}}
alpar@464: \def\ifnothtml{\conditionalsucceed{ifnothtml}}
alpar@464: \def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
alpar@464: \def\ifnotplaintext{\conditionalsucceed{ifnotplaintext}}
alpar@464: \defineunmatchedend{iftex}
alpar@464: \defineunmatchedend{ifnothtml}
alpar@464: \defineunmatchedend{ifnotinfo}
alpar@464: \defineunmatchedend{ifnotplaintext}
alpar@464: 
alpar@464: % True conditional.  Since \set globally defines its variables, we can
alpar@464: % just start and end a group (to keep the @end definition undefined at
alpar@464: % the outer level).
alpar@464: %
alpar@464: \def\conditionalsucceed#1{\begingroup
alpar@464:   \expandafter\def\csname E#1\endcsname{\endgroup}%
alpar@464: }
alpar@464: 
alpar@464: % @defininfoenclose.
alpar@464: \let\definfoenclose=\comment
alpar@464: 
alpar@464: 
alpar@464: \message{indexing,}
alpar@464: % Index generation facilities
alpar@464: 
alpar@464: % Define \newwrite to be identical to plain tex's \newwrite
alpar@464: % except not \outer, so it can be used within \newindex.
alpar@464: {\catcode`\@=11
alpar@464: \gdef\newwrite{\alloc@7\write\chardef\sixt@@n}}
alpar@464: 
alpar@464: % \newindex {foo} defines an index named foo.
alpar@464: % It automatically defines \fooindex such that
alpar@464: % \fooindex ...rest of line... puts an entry in the index foo.
alpar@464: % It also defines \fooindfile to be the number of the output channel for
alpar@464: % the file that accumulates this index.  The file's extension is foo.
alpar@464: % The name of an index should be no more than 2 characters long
alpar@464: % for the sake of vms.
alpar@464: %
alpar@464: \def\newindex#1{%
alpar@464:   \iflinks
alpar@464:     \expandafter\newwrite \csname#1indfile\endcsname
alpar@464:     \openout \csname#1indfile\endcsname \jobname.#1 % Open the file
alpar@464:   \fi
alpar@464:   \expandafter\xdef\csname#1index\endcsname{%     % Define @#1index
alpar@464:     \noexpand\doindex{#1}}
alpar@464: }
alpar@464: 
alpar@464: % @defindex foo  ==  \newindex{foo}
alpar@464: %
alpar@464: \def\defindex{\parsearg\newindex}
alpar@464: 
alpar@464: % Define @defcodeindex, like @defindex except put all entries in @code.
alpar@464: %
alpar@464: \def\defcodeindex{\parsearg\newcodeindex}
alpar@464: %
alpar@464: \def\newcodeindex#1{%
alpar@464:   \iflinks
alpar@464:     \expandafter\newwrite \csname#1indfile\endcsname
alpar@464:     \openout \csname#1indfile\endcsname \jobname.#1
alpar@464:   \fi
alpar@464:   \expandafter\xdef\csname#1index\endcsname{%
alpar@464:     \noexpand\docodeindex{#1}}%
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: % @synindex foo bar    makes index foo feed into index bar.
alpar@464: % Do this instead of @defindex foo if you don't want it as a separate index.
alpar@464: %
alpar@464: % @syncodeindex foo bar   similar, but put all entries made for index foo
alpar@464: % inside @code.
alpar@464: %
alpar@464: \def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
alpar@464: \def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
alpar@464: 
alpar@464: % #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
alpar@464: % #3 the target index (bar).
alpar@464: \def\dosynindex#1#2#3{%
alpar@464:   % Only do \closeout if we haven't already done it, else we'll end up
alpar@464:   % closing the target index.
alpar@464:   \expandafter \ifx\csname donesynindex#2\endcsname \undefined
alpar@464:     % The \closeout helps reduce unnecessary open files; the limit on the
alpar@464:     % Acorn RISC OS is a mere 16 files.
alpar@464:     \expandafter\closeout\csname#2indfile\endcsname
alpar@464:     \expandafter\let\csname\donesynindex#2\endcsname = 1
alpar@464:   \fi
alpar@464:   % redefine \fooindfile:
alpar@464:   \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
alpar@464:   \expandafter\let\csname#2indfile\endcsname=\temp
alpar@464:   % redefine \fooindex:
alpar@464:   \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
alpar@464: }
alpar@464: 
alpar@464: % Define \doindex, the driver for all \fooindex macros.
alpar@464: % Argument #1 is generated by the calling \fooindex macro,
alpar@464: %  and it is "foo", the name of the index.
alpar@464: 
alpar@464: % \doindex just uses \parsearg; it calls \doind for the actual work.
alpar@464: % This is because \doind is more useful to call from other macros.
alpar@464: 
alpar@464: % There is also \dosubind {index}{topic}{subtopic}
alpar@464: % which makes an entry in a two-level index such as the operation index.
alpar@464: 
alpar@464: \def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer}
alpar@464: \def\singleindexer #1{\doind{\indexname}{#1}}
alpar@464: 
alpar@464: % like the previous two, but they put @code around the argument.
alpar@464: \def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer}
alpar@464: \def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}}
alpar@464: 
alpar@464: % Take care of Texinfo commands that can appear in an index entry.
alpar@464: % Since there are some commands we want to expand, and others we don't,
alpar@464: % we have to laboriously prevent expansion for those that we don't.
alpar@464: %
alpar@464: \def\indexdummies{%
alpar@464:   \def\@{@}% change to @@ when we switch to @ as escape char in index files.
alpar@464:   \def\ {\realbackslash\space }%
alpar@464:   % Need these in case \tex is in effect and \{ is a \delimiter again.
alpar@464:   % But can't use \lbracecmd and \rbracecmd because texindex assumes
alpar@464:   % braces and backslashes are used only as delimiters.
alpar@464:   \let\{ = \mylbrace
alpar@464:   \let\} = \myrbrace
alpar@464:   %
alpar@464:   % \definedummyword defines \#1 as \realbackslash #1\space, thus
alpar@464:   % effectively preventing its expansion.  This is used only for control
alpar@464:   % words, not control letters, because the \space would be incorrect
alpar@464:   % for control characters, but is needed to separate the control word
alpar@464:   % from whatever follows.
alpar@464:   %
alpar@464:   % For control letters, we have \definedummyletter, which omits the
alpar@464:   % space.
alpar@464:   %
alpar@464:   % These can be used both for control words that take an argument and
alpar@464:   % those that do not.  If it is followed by {arg} in the input, then
alpar@464:   % that will dutifully get written to the index (or wherever).
alpar@464:   %
alpar@464:   \def\definedummyword##1{%
alpar@464:     \expandafter\def\csname ##1\endcsname{\realbackslash ##1\space}%
alpar@464:   }%
alpar@464:   \def\definedummyletter##1{%
alpar@464:     \expandafter\def\csname ##1\endcsname{\realbackslash ##1}%
alpar@464:   }%
alpar@464:   %
alpar@464:   % Do the redefinitions.
alpar@464:   \commondummies
alpar@464: }
alpar@464: 
alpar@464: % For the aux file, @ is the escape character.  So we want to redefine
alpar@464: % everything using @ instead of \realbackslash.  When everything uses
alpar@464: % @, this will be simpler.
alpar@464: %
alpar@464: \def\atdummies{%
alpar@464:   \def\@{@@}%
alpar@464:   \def\ {@ }%
alpar@464:   \let\{ = \lbraceatcmd
alpar@464:   \let\} = \rbraceatcmd
alpar@464:   %
alpar@464:   % (See comments in \indexdummies.)
alpar@464:   \def\definedummyword##1{%
alpar@464:     \expandafter\def\csname ##1\endcsname{@##1\space}%
alpar@464:   }%
alpar@464:   \def\definedummyletter##1{%
alpar@464:     \expandafter\def\csname ##1\endcsname{@##1}%
alpar@464:   }%
alpar@464:   %
alpar@464:   % Do the redefinitions.
alpar@464:   \commondummies
alpar@464: }
alpar@464: 
alpar@464: % Called from \indexdummies and \atdummies.  \definedummyword and
alpar@464: % \definedummyletter must be defined first.
alpar@464: %
alpar@464: \def\commondummies{%
alpar@464:   %
alpar@464:   \normalturnoffactive
alpar@464:   %
alpar@464:   % Control letters and accents.
alpar@464:   \definedummyletter{_}%
alpar@464:   \definedummyletter{,}%
alpar@464:   \definedummyletter{"}%
alpar@464:   \definedummyletter{`}%
alpar@464:   \definedummyletter{'}%
alpar@464:   \definedummyletter{^}%
alpar@464:   \definedummyletter{~}%
alpar@464:   \definedummyletter{=}%
alpar@464:   \definedummyword{u}%
alpar@464:   \definedummyword{v}%
alpar@464:   \definedummyword{H}%
alpar@464:   \definedummyword{dotaccent}%
alpar@464:   \definedummyword{ringaccent}%
alpar@464:   \definedummyword{tieaccent}%
alpar@464:   \definedummyword{ubaraccent}%
alpar@464:   \definedummyword{udotaccent}%
alpar@464:   \definedummyword{dotless}%
alpar@464:   %
alpar@464:   % Other non-English letters.
alpar@464:   \definedummyword{AA}%
alpar@464:   \definedummyword{AE}%
alpar@464:   \definedummyword{L}%
alpar@464:   \definedummyword{OE}%
alpar@464:   \definedummyword{O}%
alpar@464:   \definedummyword{aa}%
alpar@464:   \definedummyword{ae}%
alpar@464:   \definedummyword{l}%
alpar@464:   \definedummyword{oe}%
alpar@464:   \definedummyword{o}%
alpar@464:   \definedummyword{ss}%
alpar@464:   %
alpar@464:   % Although these internal commands shouldn't show up, sometimes they do.
alpar@464:   \definedummyword{bf}%
alpar@464:   \definedummyword{gtr}%
alpar@464:   \definedummyword{hat}%
alpar@464:   \definedummyword{less}%
alpar@464:   \definedummyword{sf}%
alpar@464:   \definedummyword{sl}%
alpar@464:   \definedummyword{tclose}%
alpar@464:   \definedummyword{tt}%
alpar@464:   %
alpar@464:   % Texinfo font commands.
alpar@464:   \definedummyword{b}%
alpar@464:   \definedummyword{i}%
alpar@464:   \definedummyword{r}%
alpar@464:   \definedummyword{sc}%
alpar@464:   \definedummyword{t}%
alpar@464:   %
alpar@464:   \definedummyword{TeX}%
alpar@464:   \definedummyword{acronym}%
alpar@464:   \definedummyword{cite}%
alpar@464:   \definedummyword{code}%
alpar@464:   \definedummyword{command}%
alpar@464:   \definedummyword{dfn}%
alpar@464:   \definedummyword{dots}%
alpar@464:   \definedummyword{emph}%
alpar@464:   \definedummyword{env}%
alpar@464:   \definedummyword{file}%
alpar@464:   \definedummyword{kbd}%
alpar@464:   \definedummyword{key}%
alpar@464:   \definedummyword{math}%
alpar@464:   \definedummyword{option}%
alpar@464:   \definedummyword{samp}%
alpar@464:   \definedummyword{strong}%
alpar@464:   \definedummyword{uref}%
alpar@464:   \definedummyword{url}%
alpar@464:   \definedummyword{var}%
alpar@464:   \definedummyword{w}%
alpar@464:   %
alpar@464:   % Assorted special characters.
alpar@464:   \definedummyword{bullet}%
alpar@464:   \definedummyword{copyright}%
alpar@464:   \definedummyword{dots}%
alpar@464:   \definedummyword{enddots}%
alpar@464:   \definedummyword{equiv}%
alpar@464:   \definedummyword{error}%
alpar@464:   \definedummyword{expansion}%
alpar@464:   \definedummyword{minus}%
alpar@464:   \definedummyword{pounds}%
alpar@464:   \definedummyword{point}%
alpar@464:   \definedummyword{print}%
alpar@464:   \definedummyword{result}%
alpar@464:   %
alpar@464:   % Handle some cases of @value -- where the variable name does not
alpar@464:   % contain - or _, and the value does not contain any
alpar@464:   % (non-fully-expandable) commands.
alpar@464:   \let\value = \expandablevalue
alpar@464:   %
alpar@464:   % Normal spaces, not active ones.
alpar@464:   \unsepspaces
alpar@464:   %
alpar@464:   % No macro expansion.
alpar@464:   \turnoffmacros
alpar@464: }
alpar@464: 
alpar@464: % If an index command is used in an @example environment, any spaces
alpar@464: % therein should become regular spaces in the raw index file, not the
alpar@464: % expansion of \tie (\leavevmode \penalty \@M \ ).
alpar@464: {\obeyspaces
alpar@464:  \gdef\unsepspaces{\obeyspaces\let =\space}}
alpar@464: 
alpar@464: 
alpar@464: % \indexnofonts is used when outputting the strings to sort the index
alpar@464: % by, and when constructing control sequence names.  It eliminates all
alpar@464: % control sequences and just writes whatever the best ASCII sort string
alpar@464: % would be for a given command (usually its argument).
alpar@464: %
alpar@464: \def\indexdummytex{TeX}
alpar@464: \def\indexdummydots{...}
alpar@464: %
alpar@464: \def\indexnofonts{%
alpar@464:   \def\ { }%
alpar@464:   \def\@{@}%
alpar@464:   % how to handle braces?
alpar@464:   \def\_{\normalunderscore}%
alpar@464:   %
alpar@464:   \let\,=\asis
alpar@464:   \let\"=\asis
alpar@464:   \let\`=\asis
alpar@464:   \let\'=\asis
alpar@464:   \let\^=\asis
alpar@464:   \let\~=\asis
alpar@464:   \let\==\asis
alpar@464:   \let\u=\asis
alpar@464:   \let\v=\asis
alpar@464:   \let\H=\asis
alpar@464:   \let\dotaccent=\asis
alpar@464:   \let\ringaccent=\asis
alpar@464:   \let\tieaccent=\asis
alpar@464:   \let\ubaraccent=\asis
alpar@464:   \let\udotaccent=\asis
alpar@464:   \let\dotless=\asis
alpar@464:   %
alpar@464:   % Other non-English letters.
alpar@464:   \def\AA{AA}%
alpar@464:   \def\AE{AE}%
alpar@464:   \def\L{L}%
alpar@464:   \def\OE{OE}%
alpar@464:   \def\O{O}%
alpar@464:   \def\aa{aa}%
alpar@464:   \def\ae{ae}%
alpar@464:   \def\l{l}%
alpar@464:   \def\oe{oe}%
alpar@464:   \def\o{o}%
alpar@464:   \def\ss{ss}%
alpar@464:   \def\exclamdown{!}%
alpar@464:   \def\questiondown{?}%
alpar@464:   %
alpar@464:   % Don't no-op \tt, since it isn't a user-level command
alpar@464:   % and is used in the definitions of the active chars like <, >, |, etc.
alpar@464:   % Likewise with the other plain tex font commands.
alpar@464:   %\let\tt=\asis
alpar@464:   %
alpar@464:   % Texinfo font commands.
alpar@464:   \let\b=\asis
alpar@464:   \let\i=\asis
alpar@464:   \let\r=\asis
alpar@464:   \let\sc=\asis
alpar@464:   \let\t=\asis
alpar@464:   %
alpar@464:   \let\TeX=\indexdummytex
alpar@464:   \let\acronym=\asis
alpar@464:   \let\cite=\asis
alpar@464:   \let\code=\asis
alpar@464:   \let\command=\asis
alpar@464:   \let\dfn=\asis
alpar@464:   \let\dots=\indexdummydots
alpar@464:   \let\emph=\asis
alpar@464:   \let\env=\asis
alpar@464:   \let\file=\asis
alpar@464:   \let\kbd=\asis
alpar@464:   \let\key=\asis
alpar@464:   \let\math=\asis
alpar@464:   \let\option=\asis
alpar@464:   \let\samp=\asis
alpar@464:   \let\strong=\asis
alpar@464:   \let\uref=\asis
alpar@464:   \let\url=\asis
alpar@464:   \let\var=\asis
alpar@464:   \let\w=\asis
alpar@464: }
alpar@464: 
alpar@464: \let\indexbackslash=0  %overridden during \printindex.
alpar@464: \let\SETmarginindex=\relax % put index entries in margin (undocumented)?
alpar@464: 
alpar@464: % For \ifx comparisons.
alpar@464: \def\emptymacro{\empty}
alpar@464: 
alpar@464: % Most index entries go through here, but \dosubind is the general case.
alpar@464: %
alpar@464: \def\doind#1#2{\dosubind{#1}{#2}\empty}
alpar@464: 
alpar@464: % Workhorse for all \fooindexes.
alpar@464: % #1 is name of index, #2 is stuff to put there, #3 is subentry --
alpar@464: % \empty if called from \doind, as we usually are.  The main exception
alpar@464: % is with defuns, which call us directly.
alpar@464: %
alpar@464: \def\dosubind#1#2#3{%
alpar@464:   % Put the index entry in the margin if desired.
alpar@464:   \ifx\SETmarginindex\relax\else
alpar@464:     \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}%
alpar@464:   \fi
alpar@464:   {%
alpar@464:     \count255=\lastpenalty
alpar@464:     {%
alpar@464:       \indexdummies % Must do this here, since \bf, etc expand at this stage
alpar@464:       \escapechar=`\\
alpar@464:       {%
alpar@464:         \let\folio = 0% We will expand all macros now EXCEPT \folio.
alpar@464:         \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
alpar@464:         % so it will be output as is; and it will print as backslash.
alpar@464:         %
alpar@464:         % The main index entry text.
alpar@464:         \toks0 = {#2}%
alpar@464:         %
alpar@464:         % If third arg is present, precede it with space in sort key.
alpar@464:         \def\thirdarg{#3}%
alpar@464:         \ifx\thirdarg\emptymacro \else
alpar@464:            % If the third (subentry) arg is present, add it to the index
alpar@464:            % line to write.
alpar@464:           \toks0 = \expandafter{\the\toks0 \space #3}%
alpar@464:         \fi
alpar@464:         %
alpar@464:         % Process the index entry with all font commands turned off, to
alpar@464:         % get the string to sort by.
alpar@464:         {\indexnofonts
alpar@464:          \edef\temp{\the\toks0}% need full expansion
alpar@464:          \xdef\indexsorttmp{\temp}%
alpar@464:         }%
alpar@464:         %
alpar@464:         % Set up the complete index entry, with both the sort key and
alpar@464:         % the original text, including any font commands.  We write
alpar@464:         % three arguments to \entry to the .?? file (four in the
alpar@464:         % subentry case), texindex reduces to two when writing the .??s
alpar@464:         % sorted result.
alpar@464:         \edef\temp{%
alpar@464:           \write\csname#1indfile\endcsname{%
alpar@464:             \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}%
alpar@464:         }%
alpar@464:         %
alpar@464:         % If a skip is the last thing on the list now, preserve it
alpar@464:         % by backing up by \lastskip, doing the \write, then inserting
alpar@464:         % the skip again.  Otherwise, the whatsit generated by the
alpar@464:         % \write will make \lastskip zero.  The result is that sequences
alpar@464:         % like this:
alpar@464:         % @end defun
alpar@464:         % @tindex whatever
alpar@464:         % @defun ...
alpar@464:         % will have extra space inserted, because the \medbreak in the
alpar@464:         % start of the @defun won't see the skip inserted by the @end of
alpar@464:         % the previous defun.
alpar@464:         %
alpar@464:         % But don't do any of this if we're not in vertical mode.  We
alpar@464:         % don't want to do a \vskip and prematurely end a paragraph.
alpar@464:         %
alpar@464:         % Avoid page breaks due to these extra skips, too.
alpar@464:         %
alpar@464:         \iflinks
alpar@464:           \ifvmode
alpar@464:             \skip0 = \lastskip
alpar@464:             \ifdim\lastskip = 0pt \else \nobreak\vskip-\skip0 \fi
alpar@464:           \fi
alpar@464:           %
alpar@464:           \temp % do the write
alpar@464:           %
alpar@464:           \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi
alpar@464:         \fi
alpar@464:       }%
alpar@464:     }%
alpar@464:     \penalty\count255
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % The index entry written in the file actually looks like
alpar@464: %  \entry {sortstring}{page}{topic}
alpar@464: % or
alpar@464: %  \entry {sortstring}{page}{topic}{subtopic}
alpar@464: % The texindex program reads in these files and writes files
alpar@464: % containing these kinds of lines:
alpar@464: %  \initial {c}
alpar@464: %     before the first topic whose initial is c
alpar@464: %  \entry {topic}{pagelist}
alpar@464: %     for a topic that is used without subtopics
alpar@464: %  \primary {topic}
alpar@464: %     for the beginning of a topic that is used with subtopics
alpar@464: %  \secondary {subtopic}{pagelist}
alpar@464: %     for each subtopic.
alpar@464: 
alpar@464: % Define the user-accessible indexing commands
alpar@464: % @findex, @vindex, @kindex, @cindex.
alpar@464: 
alpar@464: \def\findex {\fnindex}
alpar@464: \def\kindex {\kyindex}
alpar@464: \def\cindex {\cpindex}
alpar@464: \def\vindex {\vrindex}
alpar@464: \def\tindex {\tpindex}
alpar@464: \def\pindex {\pgindex}
alpar@464: 
alpar@464: \def\cindexsub {\begingroup\obeylines\cindexsub}
alpar@464: {\obeylines %
alpar@464: \gdef\cindexsub "#1" #2^^M{\endgroup %
alpar@464: \dosubind{cp}{#2}{#1}}}
alpar@464: 
alpar@464: % Define the macros used in formatting output of the sorted index material.
alpar@464: 
alpar@464: % @printindex causes a particular index (the ??s file) to get printed.
alpar@464: % It does not print any chapter heading (usually an @unnumbered).
alpar@464: %
alpar@464: \def\printindex{\parsearg\doprintindex}
alpar@464: \def\doprintindex#1{\begingroup
alpar@464:   \dobreak \chapheadingskip{10000}%
alpar@464:   %
alpar@464:   \smallfonts \rm
alpar@464:   \tolerance = 9500
alpar@464:   \everypar = {}% don't want the \kern\-parindent from indentation suppression.
alpar@464:   \indexbreaks
alpar@464:   %
alpar@464:   % See if the index file exists and is nonempty.
alpar@464:   % Change catcode of @ here so that if the index file contains
alpar@464:   % \initial {@}
alpar@464:   % as its first line, TeX doesn't complain about mismatched braces
alpar@464:   % (because it thinks @} is a control sequence).
alpar@464:   \catcode`\@ = 11
alpar@464:   \openin 1 \jobname.#1s
alpar@464:   \ifeof 1
alpar@464:     % \enddoublecolumns gets confused if there is no text in the index,
alpar@464:     % and it loses the chapter title and the aux file entries for the
alpar@464:     % index.  The easiest way to prevent this problem is to make sure
alpar@464:     % there is some text.
alpar@464:     \putwordIndexNonexistent
alpar@464:   \else
alpar@464:     %
alpar@464:     % If the index file exists but is empty, then \openin leaves \ifeof
alpar@464:     % false.  We have to make TeX try to read something from the file, so
alpar@464:     % it can discover if there is anything in it.
alpar@464:     \read 1 to \temp
alpar@464:     \ifeof 1
alpar@464:       \putwordIndexIsEmpty
alpar@464:     \else
alpar@464:       % Index files are almost Texinfo source, but we use \ as the escape
alpar@464:       % character.  It would be better to use @, but that's too big a change
alpar@464:       % to make right now.
alpar@464:       \def\indexbackslash{\rawbackslashxx}%
alpar@464:       \catcode`\\ = 0
alpar@464:       \escapechar = `\\
alpar@464:       \begindoublecolumns
alpar@464:       \input \jobname.#1s
alpar@464:       \enddoublecolumns
alpar@464:     \fi
alpar@464:   \fi
alpar@464:   \closein 1
alpar@464: \endgroup}
alpar@464: 
alpar@464: % These macros are used by the sorted index file itself.
alpar@464: % Change them to control the appearance of the index.
alpar@464: 
alpar@464: \def\initial#1{{%
alpar@464:   % Some minor font changes for the special characters.
alpar@464:   \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
alpar@464:   %
alpar@464:   % Remove any glue we may have, we'll be inserting our own.
alpar@464:   \removelastskip
alpar@464:   %
alpar@464:   % We like breaks before the index initials, so insert a bonus.
alpar@464:   \penalty -300
alpar@464:   %
alpar@464:   % Typeset the initial.  Making this add up to a whole number of
alpar@464:   % baselineskips increases the chance of the dots lining up from column
alpar@464:   % to column.  It still won't often be perfect, because of the stretch
alpar@464:   % we need before each entry, but it's better.
alpar@464:   %
alpar@464:   % No shrink because it confuses \balancecolumns.
alpar@464:   \vskip 1.67\baselineskip plus .5\baselineskip
alpar@464:   \leftline{\secbf #1}%
alpar@464:   \vskip .33\baselineskip plus .1\baselineskip
alpar@464:   %
alpar@464:   % Do our best not to break after the initial.
alpar@464:   \nobreak
alpar@464: }}
alpar@464: 
alpar@464: % This typesets a paragraph consisting of #1, dot leaders, and then #2
alpar@464: % flush to the right margin.  It is used for index and table of contents
alpar@464: % entries.  The paragraph is indented by \leftskip.
alpar@464: %
alpar@464: \def\entry#1#2{\begingroup
alpar@464:   %
alpar@464:   % Start a new paragraph if necessary, so our assignments below can't
alpar@464:   % affect previous text.
alpar@464:   \par
alpar@464:   %
alpar@464:   % Do not fill out the last line with white space.
alpar@464:   \parfillskip = 0in
alpar@464:   %
alpar@464:   % No extra space above this paragraph.
alpar@464:   \parskip = 0in
alpar@464:   %
alpar@464:   % Do not prefer a separate line ending with a hyphen to fewer lines.
alpar@464:   \finalhyphendemerits = 0
alpar@464:   %
alpar@464:   % \hangindent is only relevant when the entry text and page number
alpar@464:   % don't both fit on one line.  In that case, bob suggests starting the
alpar@464:   % dots pretty far over on the line.  Unfortunately, a large
alpar@464:   % indentation looks wrong when the entry text itself is broken across
alpar@464:   % lines.  So we use a small indentation and put up with long leaders.
alpar@464:   %
alpar@464:   % \hangafter is reset to 1 (which is the value we want) at the start
alpar@464:   % of each paragraph, so we need not do anything with that.
alpar@464:   \hangindent = 2em
alpar@464:   %
alpar@464:   % When the entry text needs to be broken, just fill out the first line
alpar@464:   % with blank space.
alpar@464:   \rightskip = 0pt plus1fil
alpar@464:   %
alpar@464:   % A bit of stretch before each entry for the benefit of balancing columns.
alpar@464:   \vskip 0pt plus1pt
alpar@464:   %
alpar@464:   % Start a ``paragraph'' for the index entry so the line breaking
alpar@464:   % parameters we've set above will have an effect.
alpar@464:   \noindent
alpar@464:   %
alpar@464:   % Insert the text of the index entry.  TeX will do line-breaking on it.
alpar@464:   #1%
alpar@464:   % The following is kludged to not output a line of dots in the index if
alpar@464:   % there are no page numbers.  The next person who breaks this will be
alpar@464:   % cursed by a Unix daemon.
alpar@464:   \def\tempa{{\rm }}%
alpar@464:   \def\tempb{#2}%
alpar@464:   \edef\tempc{\tempa}%
alpar@464:   \edef\tempd{\tempb}%
alpar@464:   \ifx\tempc\tempd\ \else%
alpar@464:     %
alpar@464:     % If we must, put the page number on a line of its own, and fill out
alpar@464:     % this line with blank space.  (The \hfil is overwhelmed with the
alpar@464:     % fill leaders glue in \indexdotfill if the page number does fit.)
alpar@464:     \hfil\penalty50
alpar@464:     \null\nobreak\indexdotfill % Have leaders before the page number.
alpar@464:     %
alpar@464:     % The `\ ' here is removed by the implicit \unskip that TeX does as
alpar@464:     % part of (the primitive) \par.  Without it, a spurious underfull
alpar@464:     % \hbox ensues.
alpar@464:     \ifpdf
alpar@464:       \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
alpar@464:     \else
alpar@464:       \ #2% The page number ends the paragraph.
alpar@464:     \fi
alpar@464:   \fi%
alpar@464:   \par
alpar@464: \endgroup}
alpar@464: 
alpar@464: % Like \dotfill except takes at least 1 em.
alpar@464: \def\indexdotfill{\cleaders
alpar@464:   \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
alpar@464: 
alpar@464: \def\primary #1{\line{#1\hfil}}
alpar@464: 
alpar@464: \newskip\secondaryindent \secondaryindent=0.5cm
alpar@464: \def\secondary#1#2{{%
alpar@464:   \parfillskip=0in
alpar@464:   \parskip=0in
alpar@464:   \hangindent=1in
alpar@464:   \hangafter=1
alpar@464:   \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
alpar@464:   \ifpdf
alpar@464:     \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
alpar@464:   \else
alpar@464:     #2
alpar@464:   \fi
alpar@464:   \par
alpar@464: }}
alpar@464: 
alpar@464: % Define two-column mode, which we use to typeset indexes.
alpar@464: % Adapted from the TeXbook, page 416, which is to say,
alpar@464: % the manmac.tex format used to print the TeXbook itself.
alpar@464: \catcode`\@=11
alpar@464: 
alpar@464: \newbox\partialpage
alpar@464: \newdimen\doublecolumnhsize
alpar@464: 
alpar@464: \def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
alpar@464:   % Grab any single-column material above us.
alpar@464:   \output = {%
alpar@464:     %
alpar@464:     % Here is a possibility not foreseen in manmac: if we accumulate a
alpar@464:     % whole lot of material, we might end up calling this \output
alpar@464:     % routine twice in a row (see the doublecol-lose test, which is
alpar@464:     % essentially a couple of indexes with @setchapternewpage off).  In
alpar@464:     % that case we just ship out what is in \partialpage with the normal
alpar@464:     % output routine.  Generally, \partialpage will be empty when this
alpar@464:     % runs and this will be a no-op.  See the indexspread.tex test case.
alpar@464:     \ifvoid\partialpage \else
alpar@464:       \onepageout{\pagecontents\partialpage}%
alpar@464:     \fi
alpar@464:     %
alpar@464:     \global\setbox\partialpage = \vbox{%
alpar@464:       % Unvbox the main output page.
alpar@464:       \unvbox\PAGE
alpar@464:       \kern-\topskip \kern\baselineskip
alpar@464:     }%
alpar@464:   }%
alpar@464:   \eject % run that output routine to set \partialpage
alpar@464:   %
alpar@464:   % Use the double-column output routine for subsequent pages.
alpar@464:   \output = {\doublecolumnout}%
alpar@464:   %
alpar@464:   % Change the page size parameters.  We could do this once outside this
alpar@464:   % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
alpar@464:   % format, but then we repeat the same computation.  Repeating a couple
alpar@464:   % of assignments once per index is clearly meaningless for the
alpar@464:   % execution time, so we may as well do it in one place.
alpar@464:   %
alpar@464:   % First we halve the line length, less a little for the gutter between
alpar@464:   % the columns.  We compute the gutter based on the line length, so it
alpar@464:   % changes automatically with the paper format.  The magic constant
alpar@464:   % below is chosen so that the gutter has the same value (well, +-<1pt)
alpar@464:   % as it did when we hard-coded it.
alpar@464:   %
alpar@464:   % We put the result in a separate register, \doublecolumhsize, so we
alpar@464:   % can restore it in \pagesofar, after \hsize itself has (potentially)
alpar@464:   % been clobbered.
alpar@464:   %
alpar@464:   \doublecolumnhsize = \hsize
alpar@464:     \advance\doublecolumnhsize by -.04154\hsize
alpar@464:     \divide\doublecolumnhsize by 2
alpar@464:   \hsize = \doublecolumnhsize
alpar@464:   %
alpar@464:   % Double the \vsize as well.  (We don't need a separate register here,
alpar@464:   % since nobody clobbers \vsize.)
alpar@464:   \vsize = 2\vsize
alpar@464: }
alpar@464: 
alpar@464: % The double-column output routine for all double-column pages except
alpar@464: % the last.
alpar@464: %
alpar@464: \def\doublecolumnout{%
alpar@464:   \splittopskip=\topskip \splitmaxdepth=\maxdepth
alpar@464:   % Get the available space for the double columns -- the normal
alpar@464:   % (undoubled) page height minus any material left over from the
alpar@464:   % previous page.
alpar@464:   \dimen@ = \vsize
alpar@464:   \divide\dimen@ by 2
alpar@464:   \advance\dimen@ by -\ht\partialpage
alpar@464:   %
alpar@464:   % box0 will be the left-hand column, box2 the right.
alpar@464:   \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
alpar@464:   \onepageout\pagesofar
alpar@464:   \unvbox255
alpar@464:   \penalty\outputpenalty
alpar@464: }
alpar@464: %
alpar@464: % Re-output the contents of the output page -- any previous material,
alpar@464: % followed by the two boxes we just split, in box0 and box2.
alpar@464: \def\pagesofar{%
alpar@464:   \unvbox\partialpage
alpar@464:   %
alpar@464:   \hsize = \doublecolumnhsize
alpar@464:   \wd0=\hsize \wd2=\hsize
alpar@464:   \hbox to\pagewidth{\box0\hfil\box2}%
alpar@464: }
alpar@464: %
alpar@464: % All done with double columns.
alpar@464: \def\enddoublecolumns{%
alpar@464:   \output = {%
alpar@464:     % Split the last of the double-column material.  Leave it on the
alpar@464:     % current page, no automatic page break.
alpar@464:     \balancecolumns
alpar@464:     %
alpar@464:     % If we end up splitting too much material for the current page,
alpar@464:     % though, there will be another page break right after this \output
alpar@464:     % invocation ends.  Having called \balancecolumns once, we do not
alpar@464:     % want to call it again.  Therefore, reset \output to its normal
alpar@464:     % definition right away.  (We hope \balancecolumns will never be
alpar@464:     % called on to balance too much material, but if it is, this makes
alpar@464:     % the output somewhat more palatable.)
alpar@464:     \global\output = {\onepageout{\pagecontents\PAGE}}%
alpar@464:   }%
alpar@464:   \eject
alpar@464:   \endgroup % started in \begindoublecolumns
alpar@464:   %
alpar@464:   % \pagegoal was set to the doubled \vsize above, since we restarted
alpar@464:   % the current page.  We're now back to normal single-column
alpar@464:   % typesetting, so reset \pagegoal to the normal \vsize (after the
alpar@464:   % \endgroup where \vsize got restored).
alpar@464:   \pagegoal = \vsize
alpar@464: }
alpar@464: %
alpar@464: % Called at the end of the double column material.
alpar@464: \def\balancecolumns{%
alpar@464:   \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
alpar@464:   \dimen@ = \ht0
alpar@464:   \advance\dimen@ by \topskip
alpar@464:   \advance\dimen@ by-\baselineskip
alpar@464:   \divide\dimen@ by 2 % target to split to
alpar@464:   %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}%
alpar@464:   \splittopskip = \topskip
alpar@464:   % Loop until we get a decent breakpoint.
alpar@464:   {%
alpar@464:     \vbadness = 10000
alpar@464:     \loop
alpar@464:       \global\setbox3 = \copy0
alpar@464:       \global\setbox1 = \vsplit3 to \dimen@
alpar@464:     \ifdim\ht3>\dimen@
alpar@464:       \global\advance\dimen@ by 1pt
alpar@464:     \repeat
alpar@464:   }%
alpar@464:   %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}%
alpar@464:   \setbox0=\vbox to\dimen@{\unvbox1}%
alpar@464:   \setbox2=\vbox to\dimen@{\unvbox3}%
alpar@464:   %
alpar@464:   \pagesofar
alpar@464: }
alpar@464: \catcode`\@ = \other
alpar@464: 
alpar@464: 
alpar@464: \message{sectioning,}
alpar@464: % Chapters, sections, etc.
alpar@464: 
alpar@464: \newcount\chapno
alpar@464: \newcount\secno        \secno=0
alpar@464: \newcount\subsecno     \subsecno=0
alpar@464: \newcount\subsubsecno  \subsubsecno=0
alpar@464: 
alpar@464: % This counter is funny since it counts through charcodes of letters A, B, ...
alpar@464: \newcount\appendixno  \appendixno = `\@
alpar@464: % \def\appendixletter{\char\the\appendixno}
alpar@464: % We do the following for the sake of pdftex, which needs the actual
alpar@464: % letter in the expansion, not just typeset.
alpar@464: \def\appendixletter{%
alpar@464:   \ifnum\appendixno=`A A%
alpar@464:   \else\ifnum\appendixno=`B B%
alpar@464:   \else\ifnum\appendixno=`C C%
alpar@464:   \else\ifnum\appendixno=`D D%
alpar@464:   \else\ifnum\appendixno=`E E%
alpar@464:   \else\ifnum\appendixno=`F F%
alpar@464:   \else\ifnum\appendixno=`G G%
alpar@464:   \else\ifnum\appendixno=`H H%
alpar@464:   \else\ifnum\appendixno=`I I%
alpar@464:   \else\ifnum\appendixno=`J J%
alpar@464:   \else\ifnum\appendixno=`K K%
alpar@464:   \else\ifnum\appendixno=`L L%
alpar@464:   \else\ifnum\appendixno=`M M%
alpar@464:   \else\ifnum\appendixno=`N N%
alpar@464:   \else\ifnum\appendixno=`O O%
alpar@464:   \else\ifnum\appendixno=`P P%
alpar@464:   \else\ifnum\appendixno=`Q Q%
alpar@464:   \else\ifnum\appendixno=`R R%
alpar@464:   \else\ifnum\appendixno=`S S%
alpar@464:   \else\ifnum\appendixno=`T T%
alpar@464:   \else\ifnum\appendixno=`U U%
alpar@464:   \else\ifnum\appendixno=`V V%
alpar@464:   \else\ifnum\appendixno=`W W%
alpar@464:   \else\ifnum\appendixno=`X X%
alpar@464:   \else\ifnum\appendixno=`Y Y%
alpar@464:   \else\ifnum\appendixno=`Z Z%
alpar@464:   % The \the is necessary, despite appearances, because \appendixletter is
alpar@464:   % expanded while writing the .toc file.  \char\appendixno is not
alpar@464:   % expandable, thus it is written literally, thus all appendixes come out
alpar@464:   % with the same letter (or @) in the toc without it.
alpar@464:   \else\char\the\appendixno
alpar@464:   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
alpar@464:   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
alpar@464: 
alpar@464: % Each @chapter defines this as the name of the chapter.
alpar@464: % page headings and footings can use it.  @section does likewise.
alpar@464: \def\thischapter{}
alpar@464: \def\thissection{}
alpar@464: 
alpar@464: \newcount\absseclevel % used to calculate proper heading level
alpar@464: \newcount\secbase\secbase=0 % @raise/lowersections modify this count
alpar@464: 
alpar@464: % @raisesections: treat @section as chapter, @subsection as section, etc.
alpar@464: \def\raisesections{\global\advance\secbase by -1}
alpar@464: \let\up=\raisesections % original BFox name
alpar@464: 
alpar@464: % @lowersections: treat @chapter as section, @section as subsection, etc.
alpar@464: \def\lowersections{\global\advance\secbase by 1}
alpar@464: \let\down=\lowersections % original BFox name
alpar@464: 
alpar@464: % Choose a numbered-heading macro
alpar@464: % #1 is heading level if unmodified by @raisesections or @lowersections
alpar@464: % #2 is text for heading
alpar@464: \def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
alpar@464: \ifcase\absseclevel
alpar@464:   \chapterzzz{#2}
alpar@464: \or
alpar@464:   \seczzz{#2}
alpar@464: \or
alpar@464:   \numberedsubseczzz{#2}
alpar@464: \or
alpar@464:   \numberedsubsubseczzz{#2}
alpar@464: \else
alpar@464:   \ifnum \absseclevel<0
alpar@464:     \chapterzzz{#2}
alpar@464:   \else
alpar@464:     \numberedsubsubseczzz{#2}
alpar@464:   \fi
alpar@464: \fi
alpar@464: \suppressfirstparagraphindent
alpar@464: }
alpar@464: 
alpar@464: % like \numhead, but chooses appendix heading levels
alpar@464: \def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
alpar@464: \ifcase\absseclevel
alpar@464:   \appendixzzz{#2}
alpar@464: \or
alpar@464:   \appendixsectionzzz{#2}
alpar@464: \or
alpar@464:   \appendixsubseczzz{#2}
alpar@464: \or
alpar@464:   \appendixsubsubseczzz{#2}
alpar@464: \else
alpar@464:   \ifnum \absseclevel<0
alpar@464:     \appendixzzz{#2}
alpar@464:   \else
alpar@464:     \appendixsubsubseczzz{#2}
alpar@464:   \fi
alpar@464: \fi
alpar@464: \suppressfirstparagraphindent
alpar@464: }
alpar@464: 
alpar@464: % like \numhead, but chooses numberless heading levels
alpar@464: \def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
alpar@464: \ifcase\absseclevel
alpar@464:   \unnumberedzzz{#2}
alpar@464: \or
alpar@464:   \unnumberedseczzz{#2}
alpar@464: \or
alpar@464:   \unnumberedsubseczzz{#2}
alpar@464: \or
alpar@464:   \unnumberedsubsubseczzz{#2}
alpar@464: \else
alpar@464:   \ifnum \absseclevel<0
alpar@464:     \unnumberedzzz{#2}
alpar@464:   \else
alpar@464:     \unnumberedsubsubseczzz{#2}
alpar@464:   \fi
alpar@464: \fi
alpar@464: \suppressfirstparagraphindent
alpar@464: }
alpar@464: 
alpar@464: % @chapter, @appendix, @unnumbered.
alpar@464: \def\thischaptername{No Chapter Title}
alpar@464: \outer\def\chapter{\parsearg\chapteryyy}
alpar@464: \def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz
alpar@464: \def\chapterzzz #1{%
alpar@464:   \secno=0 \subsecno=0 \subsubsecno=0
alpar@464:   \global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}%
alpar@464:   \chapmacro {#1}{\the\chapno}%
alpar@464:   \gdef\thissection{#1}%
alpar@464:   \gdef\thischaptername{#1}%
alpar@464:   % We don't substitute the actual chapter name into \thischapter
alpar@464:   % because we don't want its macros evaluated now.
alpar@464:   \xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}%
alpar@464:   \writetocentry{chap}{#1}{{\the\chapno}}
alpar@464:   \donoderef
alpar@464:   \global\let\section = \numberedsec
alpar@464:   \global\let\subsection = \numberedsubsec
alpar@464:   \global\let\subsubsection = \numberedsubsubsec
alpar@464: }
alpar@464: 
alpar@464: % we use \chapno to avoid indenting back
alpar@464: \def\appendixbox#1{%
alpar@464:   \setbox0 = \hbox{\putwordAppendix{} \the\chapno}%
alpar@464:   \hbox to \wd0{#1\hss}}
alpar@464: 
alpar@464: \outer\def\appendix{\parsearg\appendixyyy}
alpar@464: \def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz
alpar@464: \def\appendixzzz #1{%
alpar@464:   \secno=0 \subsecno=0 \subsubsecno=0
alpar@464:   \global\advance \appendixno by 1
alpar@464:   \message{\putwordAppendix\space \appendixletter}%
alpar@464:   \chapmacro {#1}{\appendixbox{\putwordAppendix{} \appendixletter}}%
alpar@464:   \gdef\thissection{#1}%
alpar@464:   \gdef\thischaptername{#1}%
alpar@464:   \xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}%
alpar@464:   \writetocentry{appendix}{#1}{{\appendixletter}}
alpar@464:   \appendixnoderef
alpar@464:   \global\let\section = \appendixsec
alpar@464:   \global\let\subsection = \appendixsubsec
alpar@464:   \global\let\subsubsection = \appendixsubsubsec
alpar@464: }
alpar@464: 
alpar@464: % @centerchap is like @unnumbered, but the heading is centered.
alpar@464: \outer\def\centerchap{\parsearg\centerchapyyy}
alpar@464: \def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}}
alpar@464: 
alpar@464: % @top is like @unnumbered.
alpar@464: \outer\def\top{\parsearg\unnumberedyyy}
alpar@464: 
alpar@464: \outer\def\unnumbered{\parsearg\unnumberedyyy}
alpar@464: \def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
alpar@464: \def\unnumberedzzz #1{%
alpar@464:   \secno=0 \subsecno=0 \subsubsecno=0
alpar@464:   %
alpar@464:   % This used to be simply \message{#1}, but TeX fully expands the
alpar@464:   % argument to \message.  Therefore, if #1 contained @-commands, TeX
alpar@464:   % expanded them.  For example, in `@unnumbered The @cite{Book}', TeX
alpar@464:   % expanded @cite (which turns out to cause errors because \cite is meant
alpar@464:   % to be executed, not expanded).
alpar@464:   %
alpar@464:   % Anyway, we don't want the fully-expanded definition of @cite to appear
alpar@464:   % as a result of the \message, we just want `@cite' itself.  We use
alpar@464:   % \the<toks register> to achieve this: TeX expands \the<toks> only once,
alpar@464:   % simply yielding the contents of <toks register>.  (We also do this for
alpar@464:   % the toc entries.)
alpar@464:   \toks0 = {#1}\message{(\the\toks0)}%
alpar@464:   %
alpar@464:   \unnumbchapmacro {#1}%
alpar@464:   \gdef\thischapter{#1}\gdef\thissection{#1}%
alpar@464:   \writetocentry{unnumbchap}{#1}{{\the\chapno}}
alpar@464:   \unnumbnoderef
alpar@464:   \global\let\section = \unnumberedsec
alpar@464:   \global\let\subsection = \unnumberedsubsec
alpar@464:   \global\let\subsubsection = \unnumberedsubsubsec
alpar@464: }
alpar@464: 
alpar@464: % Sections.
alpar@464: \outer\def\numberedsec{\parsearg\secyyy}
alpar@464: \def\secyyy #1{\numhead1{#1}} % normally calls seczzz
alpar@464: \def\seczzz #1{%
alpar@464:   \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
alpar@464:   \gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}%
alpar@464:   \writetocentry{sec}{#1}{{\the\chapno}{\the\secno}}
alpar@464:   \donoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\appendixsection{\parsearg\appendixsecyyy}
alpar@464: \outer\def\appendixsec{\parsearg\appendixsecyyy}
alpar@464: \def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz
alpar@464: \def\appendixsectionzzz #1{%
alpar@464:   \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
alpar@464:   \gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}%
alpar@464:   \writetocentry{sec}{#1}{{\appendixletter}{\the\secno}}
alpar@464:   \appendixnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\unnumberedsec{\parsearg\unnumberedsecyyy}
alpar@464: \def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz
alpar@464: \def\unnumberedseczzz #1{%
alpar@464:   \plainsecheading {#1}\gdef\thissection{#1}%
alpar@464:   \writetocentry{unnumbsec}{#1}{{\the\chapno}{\the\secno}}
alpar@464:   \unnumbnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: % Subsections.
alpar@464: \outer\def\numberedsubsec{\parsearg\numberedsubsecyyy}
alpar@464: \def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz
alpar@464: \def\numberedsubseczzz #1{%
alpar@464:   \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
alpar@464:   \subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
alpar@464:   \writetocentry{subsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
alpar@464:   \donoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\appendixsubsec{\parsearg\appendixsubsecyyy}
alpar@464: \def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz
alpar@464: \def\appendixsubseczzz #1{%
alpar@464:   \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
alpar@464:   \subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}%
alpar@464:   \writetocentry{subsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}}
alpar@464:   \appendixnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy}
alpar@464: \def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
alpar@464: \def\unnumberedsubseczzz #1{%
alpar@464:   \plainsubsecheading {#1}\gdef\thissection{#1}%
alpar@464:   \writetocentry{unnumbsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
alpar@464:   \unnumbnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: % Subsubsections.
alpar@464: \outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy}
alpar@464: \def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz
alpar@464: \def\numberedsubsubseczzz #1{%
alpar@464:   \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
alpar@464:   \subsubsecheading {#1}
alpar@464:     {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
alpar@464:   \writetocentry{subsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
alpar@464:   \donoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy}
alpar@464: \def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz
alpar@464: \def\appendixsubsubseczzz #1{%
alpar@464:   \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
alpar@464:   \subsubsecheading {#1}
alpar@464:     {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
alpar@464:   \writetocentry{subsubsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
alpar@464:   \appendixnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: \outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy}
alpar@464: \def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
alpar@464: \def\unnumberedsubsubseczzz #1{%
alpar@464:   \plainsubsubsecheading {#1}\gdef\thissection{#1}%
alpar@464:   \writetocentry{unnumbsubsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
alpar@464:   \unnumbnoderef
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: % These are variants which are not "outer", so they can appear in @ifinfo.
alpar@464: % Actually, they should now be obsolete; ordinary section commands should work.
alpar@464: \def\infotop{\parsearg\unnumberedzzz}
alpar@464: \def\infounnumbered{\parsearg\unnumberedzzz}
alpar@464: \def\infounnumberedsec{\parsearg\unnumberedseczzz}
alpar@464: \def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
alpar@464: \def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
alpar@464: 
alpar@464: \def\infoappendix{\parsearg\appendixzzz}
alpar@464: \def\infoappendixsec{\parsearg\appendixseczzz}
alpar@464: \def\infoappendixsubsec{\parsearg\appendixsubseczzz}
alpar@464: \def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
alpar@464: 
alpar@464: \def\infochapter{\parsearg\chapterzzz}
alpar@464: \def\infosection{\parsearg\sectionzzz}
alpar@464: \def\infosubsection{\parsearg\subsectionzzz}
alpar@464: \def\infosubsubsection{\parsearg\subsubsectionzzz}
alpar@464: 
alpar@464: % These macros control what the section commands do, according
alpar@464: % to what kind of chapter we are in (ordinary, appendix, or unnumbered).
alpar@464: % Define them by default for a numbered chapter.
alpar@464: \global\let\section = \numberedsec
alpar@464: \global\let\subsection = \numberedsubsec
alpar@464: \global\let\subsubsection = \numberedsubsubsec
alpar@464: 
alpar@464: % Define @majorheading, @heading and @subheading
alpar@464: 
alpar@464: % NOTE on use of \vbox for chapter headings, section headings, and such:
alpar@464: %       1) We use \vbox rather than the earlier \line to permit
alpar@464: %          overlong headings to fold.
alpar@464: %       2) \hyphenpenalty is set to 10000 because hyphenation in a
alpar@464: %          heading is obnoxious; this forbids it.
alpar@464: %       3) Likewise, headings look best if no \parindent is used, and
alpar@464: %          if justification is not attempted.  Hence \raggedright.
alpar@464: 
alpar@464: 
alpar@464: \def\majorheading{%
alpar@464:   {\advance\chapheadingskip by 10pt \chapbreak }%
alpar@464:   \parsearg\chapheadingzzz
alpar@464: }
alpar@464: 
alpar@464: \def\chapheading{\chapbreak \parsearg\chapheadingzzz}
alpar@464: \def\chapheadingzzz #1{%
alpar@464:   {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
alpar@464:                     \parindent=0pt\raggedright
alpar@464:                     \rm #1\hfill}}%
alpar@464:   \bigskip \par\penalty 200\relax
alpar@464:   \suppressfirstparagraphindent
alpar@464: }
alpar@464: 
alpar@464: % @heading, @subheading, @subsubheading.
alpar@464: \def\heading{\parsearg\doheading}
alpar@464: \def\subheading{\parsearg\dosubheading}
alpar@464: \def\subsubheading{\parsearg\dosubsubheading}
alpar@464: \def\doheading#1{\plainsecheading{#1}\suppressfirstparagraphindent}
alpar@464: \def\dosubheading#1{\plainsubsecheading{#1}\suppressfirstparagraphindent}
alpar@464: \def\dosubsubheading#1{\plainsubsubsecheading{#1}\suppressfirstparagraphindent}
alpar@464: 
alpar@464: % These macros generate a chapter, section, etc. heading only
alpar@464: % (including whitespace, linebreaking, etc. around it),
alpar@464: % given all the information in convenient, parsed form.
alpar@464: 
alpar@464: %%% Args are the skip and penalty (usually negative)
alpar@464: \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
alpar@464: 
alpar@464: \def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
alpar@464: 
alpar@464: %%% Define plain chapter starts, and page on/off switching for it
alpar@464: % Parameter controlling skip before chapter headings (if needed)
alpar@464: 
alpar@464: \newskip\chapheadingskip
alpar@464: 
alpar@464: \def\chapbreak{\dobreak \chapheadingskip {-4000}}
alpar@464: \def\chappager{\par\vfill\supereject}
alpar@464: \def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi}
alpar@464: 
alpar@464: \def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname}
alpar@464: 
alpar@464: \def\CHAPPAGoff{%
alpar@464: \global\let\contentsalignmacro = \chappager
alpar@464: \global\let\pchapsepmacro=\chapbreak
alpar@464: \global\let\pagealignmacro=\chappager}
alpar@464: 
alpar@464: \def\CHAPPAGon{%
alpar@464: \global\let\contentsalignmacro = \chappager
alpar@464: \global\let\pchapsepmacro=\chappager
alpar@464: \global\let\pagealignmacro=\chappager
alpar@464: \global\def\HEADINGSon{\HEADINGSsingle}}
alpar@464: 
alpar@464: \def\CHAPPAGodd{
alpar@464: \global\let\contentsalignmacro = \chapoddpage
alpar@464: \global\let\pchapsepmacro=\chapoddpage
alpar@464: \global\let\pagealignmacro=\chapoddpage
alpar@464: \global\def\HEADINGSon{\HEADINGSdouble}}
alpar@464: 
alpar@464: \CHAPPAGon
alpar@464: 
alpar@464: \def\CHAPFplain{
alpar@464: \global\let\chapmacro=\chfplain
alpar@464: \global\let\unnumbchapmacro=\unnchfplain
alpar@464: \global\let\centerchapmacro=\centerchfplain}
alpar@464: 
alpar@464: % Plain chapter opening.
alpar@464: % #1 is the text, #2 the chapter number or empty if unnumbered.
alpar@464: \def\chfplain#1#2{%
alpar@464:   \pchapsepmacro
alpar@464:   {%
alpar@464:     \chapfonts \rm
alpar@464:     \def\chapnum{#2}%
alpar@464:     \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}%
alpar@464:     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
alpar@464:           \hangindent = \wd0 \centerparametersmaybe
alpar@464:           \unhbox0 #1\par}%
alpar@464:   }%
alpar@464:   \nobreak\bigskip % no page break after a chapter title
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: % Plain opening for unnumbered.
alpar@464: \def\unnchfplain#1{\chfplain{#1}{}}
alpar@464: 
alpar@464: % @centerchap -- centered and unnumbered.
alpar@464: \let\centerparametersmaybe = \relax
alpar@464: \def\centerchfplain#1{{%
alpar@464:   \def\centerparametersmaybe{%
alpar@464:     \advance\rightskip by 3\rightskip
alpar@464:     \leftskip = \rightskip
alpar@464:     \parfillskip = 0pt
alpar@464:   }%
alpar@464:   \chfplain{#1}{}%
alpar@464: }}
alpar@464: 
alpar@464: \CHAPFplain % The default
alpar@464: 
alpar@464: \def\unnchfopen #1{%
alpar@464: \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
alpar@464:                        \parindent=0pt\raggedright
alpar@464:                        \rm #1\hfill}}\bigskip \par\nobreak
alpar@464: }
alpar@464: 
alpar@464: \def\chfopen #1#2{\chapoddpage {\chapfonts
alpar@464: \vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
alpar@464: \par\penalty 5000 %
alpar@464: }
alpar@464: 
alpar@464: \def\centerchfopen #1{%
alpar@464: \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
alpar@464:                        \parindent=0pt
alpar@464:                        \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
alpar@464: }
alpar@464: 
alpar@464: \def\CHAPFopen{
alpar@464: \global\let\chapmacro=\chfopen
alpar@464: \global\let\unnumbchapmacro=\unnchfopen
alpar@464: \global\let\centerchapmacro=\centerchfopen}
alpar@464: 
alpar@464: 
alpar@464: % Section titles.
alpar@464: \newskip\secheadingskip
alpar@464: \def\secheadingbreak{\dobreak \secheadingskip {-1000}}
alpar@464: \def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}}
alpar@464: \def\plainsecheading#1{\sectionheading{sec}{}{#1}}
alpar@464: 
alpar@464: % Subsection titles.
alpar@464: \newskip \subsecheadingskip
alpar@464: \def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}}
alpar@464: \def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}}
alpar@464: \def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}}
alpar@464: 
alpar@464: % Subsubsection titles.
alpar@464: \let\subsubsecheadingskip = \subsecheadingskip
alpar@464: \let\subsubsecheadingbreak = \subsecheadingbreak
alpar@464: \def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}}
alpar@464: \def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}}
alpar@464: 
alpar@464: 
alpar@464: % Print any size section title.
alpar@464: %
alpar@464: % #1 is the section type (sec/subsec/subsubsec), #2 is the section
alpar@464: % number (maybe empty), #3 the text.
alpar@464: \def\sectionheading#1#2#3{%
alpar@464:   {%
alpar@464:     \expandafter\advance\csname #1headingskip\endcsname by \parskip
alpar@464:     \csname #1headingbreak\endcsname
alpar@464:   }%
alpar@464:   {%
alpar@464:     % Switch to the right set of fonts.
alpar@464:     \csname #1fonts\endcsname \rm
alpar@464:     %
alpar@464:     % Only insert the separating space if we have a section number.
alpar@464:     \def\secnum{#2}%
alpar@464:     \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}%
alpar@464:     %
alpar@464:     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
alpar@464:           \hangindent = \wd0 % zero if no section number
alpar@464:           \unhbox0 #3}%
alpar@464:   }%
alpar@464:   % Add extra space after the heading -- either a line space or a
alpar@464:   % paragraph space, whichever is more.  (Some people like to set
alpar@464:   % \parskip to large values for some reason.)  Don't allow stretch, though.
alpar@464:   \nobreak
alpar@464:   \ifdim\parskip>\normalbaselineskip
alpar@464:     \kern\parskip
alpar@464:   \else
alpar@464:     \kern\normalbaselineskip
alpar@464:   \fi
alpar@464:   \nobreak
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: \message{toc,}
alpar@464: % Table of contents.
alpar@464: \newwrite\tocfile
alpar@464: 
alpar@464: % Write an entry to the toc file, opening it if necessary.
alpar@464: % Called from @chapter, etc.  We supply {\folio} at the end of the
alpar@464: % argument, which will end up as the last argument to the \...entry macro.
alpar@464: %
alpar@464: % Usage: \writetocentry{chap}{The Name of The Game}{{\the\chapno}}
alpar@464: % We open the .toc file for writing here instead of at @setfilename (or
alpar@464: % any other fixed time) so that @contents can be anywhere in the document.
alpar@464: %
alpar@464: \newif\iftocfileopened
alpar@464: \def\writetocentry#1#2#3{%
alpar@464:   \iftocfileopened\else
alpar@464:     \immediate\openout\tocfile = \jobname.toc
alpar@464:     \global\tocfileopenedtrue
alpar@464:   \fi
alpar@464:   %
alpar@464:   \iflinks
alpar@464:     \toks0 = {#2}%
alpar@464:     \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}#3{\folio}}}%
alpar@464:     \temp
alpar@464:   \fi
alpar@464:   %
alpar@464:   % Tell \shipout to create a page destination if we're doing pdf, which
alpar@464:   % will be the target of the links in the table of contents.  We can't
alpar@464:   % just do it on every page because the title pages are numbered 1 and
alpar@464:   % 2 (the page numbers aren't printed), and so are the first two pages
alpar@464:   % of the document.  Thus, we'd have two destinations named `1', and
alpar@464:   % two named `2'.
alpar@464:   \ifpdf \pdfmakepagedesttrue \fi
alpar@464: }
alpar@464: 
alpar@464: \newskip\contentsrightmargin \contentsrightmargin=1in
alpar@464: \newcount\savepageno
alpar@464: \newcount\lastnegativepageno \lastnegativepageno = -1
alpar@464: 
alpar@464: % Finish up the main text and prepare to read what we've written
alpar@464: % to \tocfile.
alpar@464: %
alpar@464: \def\startcontents#1{%
alpar@464:    % If @setchapternewpage on, and @headings double, the contents should
alpar@464:    % start on an odd page, unlike chapters.  Thus, we maintain
alpar@464:    % \contentsalignmacro in parallel with \pagealignmacro.
alpar@464:    % From: Torbjorn Granlund <tege@matematik.su.se>
alpar@464:    \contentsalignmacro
alpar@464:    \immediate\closeout\tocfile
alpar@464:    %
alpar@464:    % Don't need to put `Contents' or `Short Contents' in the headline.
alpar@464:    % It is abundantly clear what they are.
alpar@464:    \unnumbchapmacro{#1}\def\thischapter{}%
alpar@464:    \savepageno = \pageno
alpar@464:    \begingroup                  % Set up to handle contents files properly.
alpar@464:       \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
alpar@464:       % We can't do this, because then an actual ^ in a section
alpar@464:       % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
alpar@464:       %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
alpar@464:       \raggedbottom             % Worry more about breakpoints than the bottom.
alpar@464:       \advance\hsize by -\contentsrightmargin % Don't use the full line length.
alpar@464:       %
alpar@464:       % Roman numerals for page numbers.
alpar@464:       \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: % Normal (long) toc.
alpar@464: \def\contents{%
alpar@464:    \startcontents{\putwordTOC}%
alpar@464:      \openin 1 \jobname.toc
alpar@464:      \ifeof 1 \else
alpar@464:        \closein 1
alpar@464:        \input \jobname.toc
alpar@464:      \fi
alpar@464:      \vfill \eject
alpar@464:      \contentsalignmacro % in case @setchapternewpage odd is in effect
alpar@464:      \pdfmakeoutlines
alpar@464:    \endgroup
alpar@464:    \lastnegativepageno = \pageno
alpar@464:    \global\pageno = \savepageno
alpar@464: }
alpar@464: 
alpar@464: % And just the chapters.
alpar@464: \def\summarycontents{%
alpar@464:    \startcontents{\putwordShortTOC}%
alpar@464:       %
alpar@464:       \let\chapentry = \shortchapentry
alpar@464:       \let\appendixentry = \shortappendixentry
alpar@464:       \let\unnumbchapentry = \shortunnumberedentry
alpar@464:       % We want a true roman here for the page numbers.
alpar@464:       \secfonts
alpar@464:       \let\rm=\shortcontrm \let\bf=\shortcontbf
alpar@464:       \let\sl=\shortcontsl \let\tt=\shortconttt
alpar@464:       \rm
alpar@464:       \hyphenpenalty = 10000
alpar@464:       \advance\baselineskip by 1pt % Open it up a little.
alpar@464:       \def\secentry ##1##2##3##4{}
alpar@464:       \def\subsecentry ##1##2##3##4##5{}
alpar@464:       \def\subsubsecentry ##1##2##3##4##5##6{}
alpar@464:       \let\unnumbsecentry = \secentry
alpar@464:       \let\unnumbsubsecentry = \subsecentry
alpar@464:       \let\unnumbsubsubsecentry = \subsubsecentry
alpar@464:       \openin 1 \jobname.toc
alpar@464:       \ifeof 1 \else
alpar@464:         \closein 1
alpar@464:         \input \jobname.toc
alpar@464:       \fi
alpar@464:      \vfill \eject
alpar@464:      \contentsalignmacro % in case @setchapternewpage odd is in effect
alpar@464:    \endgroup
alpar@464:    \lastnegativepageno = \pageno
alpar@464:    \global\pageno = \savepageno
alpar@464: }
alpar@464: \let\shortcontents = \summarycontents
alpar@464: 
alpar@464: \ifpdf
alpar@464:   \pdfcatalog{/PageMode /UseOutlines}%
alpar@464: \fi
alpar@464: 
alpar@464: % These macros generate individual entries in the table of contents.
alpar@464: % The first argument is the chapter or section name.
alpar@464: % The last argument is the page number.
alpar@464: % The arguments in between are the chapter number, section number, ...
alpar@464: 
alpar@464: % Chapters, in the main contents.
alpar@464: \def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}}
alpar@464: %
alpar@464: % Chapters, in the short toc.
alpar@464: % See comments in \dochapentry re vbox and related settings.
alpar@464: \def\shortchapentry#1#2#3{%
alpar@464:   \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#3\egroup}%
alpar@464: }
alpar@464: 
alpar@464: % Appendices, in the main contents.
alpar@464: \def\appendixentry#1#2#3{%
alpar@464:   \dochapentry{\appendixbox{\putwordAppendix{} #2}\labelspace#1}{#3}}
alpar@464: %
alpar@464: % Appendices, in the short toc.
alpar@464: \let\shortappendixentry = \shortchapentry
alpar@464: 
alpar@464: % Typeset the label for a chapter or appendix for the short contents.
alpar@464: % The arg is, e.g., `Appendix A' for an appendix, or `3' for a chapter.
alpar@464: % We could simplify the code here by writing out an \appendixentry
alpar@464: % command in the toc file for appendices, instead of using \chapentry
alpar@464: % for both, but it doesn't seem worth it.
alpar@464: %
alpar@464: \newdimen\shortappendixwidth
alpar@464: %
alpar@464: \def\shortchaplabel#1{%
alpar@464:   % This space should be enough, since a single number is .5em, and the
alpar@464:   % widest letter (M) is 1em, at least in the Computer Modern fonts.
alpar@464:   % But use \hss just in case.
alpar@464:   % (This space doesn't include the extra space that gets added after
alpar@464:   % the label; that gets put in by \shortchapentry above.)
alpar@464:   \dimen0 = 1em
alpar@464:   \hbox to \dimen0{#1\hss}%
alpar@464: }
alpar@464: 
alpar@464: % Unnumbered chapters.
alpar@464: \def\unnumbchapentry#1#2#3{\dochapentry{#1}{#3}}
alpar@464: \def\shortunnumberedentry#1#2#3{\tocentry{#1}{\doshortpageno\bgroup#3\egroup}}
alpar@464: 
alpar@464: % Sections.
alpar@464: \def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}}
alpar@464: \def\unnumbsecentry#1#2#3#4{\dosecentry{#1}{#4}}
alpar@464: 
alpar@464: % Subsections.
alpar@464: \def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}}
alpar@464: \def\unnumbsubsecentry#1#2#3#4#5{\dosubsecentry{#1}{#5}}
alpar@464: 
alpar@464: % And subsubsections.
alpar@464: \def\subsubsecentry#1#2#3#4#5#6{%
alpar@464:   \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}}
alpar@464: \def\unnumbsubsubsecentry#1#2#3#4#5#6{\dosubsubsecentry{#1}{#6}}
alpar@464: 
alpar@464: % This parameter controls the indentation of the various levels.
alpar@464: \newdimen\tocindent \tocindent = 3pc
alpar@464: 
alpar@464: % Now for the actual typesetting. In all these, #1 is the text and #2 is the
alpar@464: % page number.
alpar@464: %
alpar@464: % If the toc has to be broken over pages, we want it to be at chapters
alpar@464: % if at all possible; hence the \penalty.
alpar@464: \def\dochapentry#1#2{%
alpar@464:    \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
alpar@464:    \begingroup
alpar@464:      \chapentryfonts
alpar@464:      \tocentry{#1}{\dopageno\bgroup#2\egroup}%
alpar@464:    \endgroup
alpar@464:    \nobreak\vskip .25\baselineskip plus.1\baselineskip
alpar@464: }
alpar@464: 
alpar@464: \def\dosecentry#1#2{\begingroup
alpar@464:   \secentryfonts \leftskip=\tocindent
alpar@464:   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
alpar@464: \endgroup}
alpar@464: 
alpar@464: \def\dosubsecentry#1#2{\begingroup
alpar@464:   \subsecentryfonts \leftskip=2\tocindent
alpar@464:   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
alpar@464: \endgroup}
alpar@464: 
alpar@464: \def\dosubsubsecentry#1#2{\begingroup
alpar@464:   \subsubsecentryfonts \leftskip=3\tocindent
alpar@464:   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
alpar@464: \endgroup}
alpar@464: 
alpar@464: % Final typesetting of a toc entry; we use the same \entry macro as for
alpar@464: % the index entries, but we want to suppress hyphenation here.  (We
alpar@464: % can't do that in the \entry macro, since index entries might consist
alpar@464: % of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.)
alpar@464: \def\tocentry#1#2{\begingroup
alpar@464:   \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks
alpar@464:   % Do not use \turnoffactive in these arguments.  Since the toc is
alpar@464:   % typeset in cmr, characters such as _ would come out wrong; we
alpar@464:   % have to do the usual translation tricks.
alpar@464:   \entry{#1}{#2}%
alpar@464: \endgroup}
alpar@464: 
alpar@464: % Space between chapter (or whatever) number and the title.
alpar@464: \def\labelspace{\hskip1em \relax}
alpar@464: 
alpar@464: \def\dopageno#1{{\rm #1}}
alpar@464: \def\doshortpageno#1{{\rm #1}}
alpar@464: 
alpar@464: \def\chapentryfonts{\secfonts \rm}
alpar@464: \def\secentryfonts{\textfonts}
alpar@464: \let\subsecentryfonts = \textfonts
alpar@464: \let\subsubsecentryfonts = \textfonts
alpar@464: 
alpar@464: 
alpar@464: \message{environments,}
alpar@464: % @foo ... @end foo.
alpar@464: 
alpar@464: % @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
alpar@464: %
alpar@464: % Since these characters are used in examples, it should be an even number of
alpar@464: % \tt widths. Each \tt character is 1en, so two makes it 1em.
alpar@464: %
alpar@464: \def\point{$\star$}
alpar@464: \def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
alpar@464: \def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}}
alpar@464: \def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
alpar@464: \def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}}
alpar@464: 
alpar@464: % The @error{} command.
alpar@464: % Adapted from the TeXbook's \boxit.
alpar@464: %
alpar@464: \newbox\errorbox
alpar@464: %
alpar@464: {\tentt \global\dimen0 = 3em}% Width of the box.
alpar@464: \dimen2 = .55pt % Thickness of rules
alpar@464: % The text. (`r' is open on the right, `e' somewhat less so on the left.)
alpar@464: \setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
alpar@464: %
alpar@464: \global\setbox\errorbox=\hbox to \dimen0{\hfil
alpar@464:    \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
alpar@464:    \advance\hsize by -2\dimen2 % Rules.
alpar@464:    \vbox{
alpar@464:       \hrule height\dimen2
alpar@464:       \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
alpar@464:          \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
alpar@464:          \kern3pt\vrule width\dimen2}% Space to right.
alpar@464:       \hrule height\dimen2}
alpar@464:     \hfil}
alpar@464: %
alpar@464: \def\error{\leavevmode\lower.7ex\copy\errorbox}
alpar@464: 
alpar@464: % @tex ... @end tex    escapes into raw Tex temporarily.
alpar@464: % One exception: @ is still an escape character, so that @end tex works.
alpar@464: % But \@ or @@ will get a plain tex @ character.
alpar@464: 
alpar@464: \def\tex{\begingroup
alpar@464:   \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
alpar@464:   \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
alpar@464:   \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
alpar@464:   \catcode `\%=14
alpar@464:   \catcode `\+=\other
alpar@464:   \catcode `\"=\other
alpar@464:   \catcode `\==\other
alpar@464:   \catcode `\|=\other
alpar@464:   \catcode `\<=\other
alpar@464:   \catcode `\>=\other
alpar@464:   \escapechar=`\\
alpar@464:   %
alpar@464:   \let\b=\ptexb
alpar@464:   \let\bullet=\ptexbullet
alpar@464:   \let\c=\ptexc
alpar@464:   \let\,=\ptexcomma
alpar@464:   \let\.=\ptexdot
alpar@464:   \let\dots=\ptexdots
alpar@464:   \let\equiv=\ptexequiv
alpar@464:   \let\!=\ptexexclam
alpar@464:   \let\i=\ptexi
alpar@464:   \let\indent=\ptexindent
alpar@464:   \let\{=\ptexlbrace
alpar@464:   \let\+=\tabalign
alpar@464:   \let\}=\ptexrbrace
alpar@464:   \let\/=\ptexslash
alpar@464:   \let\*=\ptexstar
alpar@464:   \let\t=\ptext
alpar@464:   %
alpar@464:   \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
alpar@464:   \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
alpar@464:   \def\@{@}%
alpar@464: \let\Etex=\endgroup}
alpar@464: 
alpar@464: % Define @lisp ... @end lisp.
alpar@464: % @lisp does a \begingroup so it can rebind things,
alpar@464: % including the definition of @end lisp (which normally is erroneous).
alpar@464: 
alpar@464: % Amount to narrow the margins by for @lisp.
alpar@464: \newskip\lispnarrowing \lispnarrowing=0.4in
alpar@464: 
alpar@464: % This is the definition that ^^M gets inside @lisp, @example, and other
alpar@464: % such environments.  \null is better than a space, since it doesn't
alpar@464: % have any width.
alpar@464: \def\lisppar{\null\endgraf}
alpar@464: 
alpar@464: % Make each space character in the input produce a normal interword
alpar@464: % space in the output.  Don't allow a line break at this space, as this
alpar@464: % is used only in environments like @example, where each line of input
alpar@464: % should produce a line of output anyway.
alpar@464: %
alpar@464: {\obeyspaces %
alpar@464: \gdef\sepspaces{\obeyspaces\let =\tie}}
alpar@464: 
alpar@464: % Define \obeyedspace to be our active space, whatever it is.  This is
alpar@464: % for use in \parsearg.
alpar@464: {\sepspaces%
alpar@464: \global\let\obeyedspace= }
alpar@464: 
alpar@464: % This space is always present above and below environments.
alpar@464: \newskip\envskipamount \envskipamount = 0pt
alpar@464: 
alpar@464: % Make spacing and below environment symmetrical.  We use \parskip here
alpar@464: % to help in doing that, since in @example-like environments \parskip
alpar@464: % is reset to zero; thus the \afterenvbreak inserts no space -- but the
alpar@464: % start of the next paragraph will insert \parskip.
alpar@464: %
alpar@464: \def\aboveenvbreak{{%
alpar@464:   % =10000 instead of <10000 because of a special case in \itemzzz, q.v.
alpar@464:   \ifnum \lastpenalty=10000 \else
alpar@464:     \advance\envskipamount by \parskip
alpar@464:     \endgraf
alpar@464:     \ifdim\lastskip<\envskipamount
alpar@464:       \removelastskip
alpar@464:       % it's not a good place to break if the last penalty was \nobreak
alpar@464:       % or better ...
alpar@464:       \ifnum\lastpenalty>10000 \else \penalty-50 \fi
alpar@464:       \vskip\envskipamount
alpar@464:     \fi
alpar@464:   \fi
alpar@464: }}
alpar@464: 
alpar@464: \let\afterenvbreak = \aboveenvbreak
alpar@464: 
alpar@464: % \nonarrowing is a flag.  If "set", @lisp etc don't narrow margins.
alpar@464: \let\nonarrowing=\relax
alpar@464: 
alpar@464: % @cartouche ... @end cartouche: draw rectangle w/rounded corners around
alpar@464: % environment contents.
alpar@464: \font\circle=lcircle10
alpar@464: \newdimen\circthick
alpar@464: \newdimen\cartouter\newdimen\cartinner
alpar@464: \newskip\normbskip\newskip\normpskip\newskip\normlskip
alpar@464: \circthick=\fontdimen8\circle
alpar@464: %
alpar@464: \def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
alpar@464: \def\ctr{{\hskip 6pt\circle\char'010}}
alpar@464: \def\cbl{{\circle\char'012\hskip -6pt}}
alpar@464: \def\cbr{{\hskip 6pt\circle\char'011}}
alpar@464: \def\carttop{\hbox to \cartouter{\hskip\lskip
alpar@464:         \ctl\leaders\hrule height\circthick\hfil\ctr
alpar@464:         \hskip\rskip}}
alpar@464: \def\cartbot{\hbox to \cartouter{\hskip\lskip
alpar@464:         \cbl\leaders\hrule height\circthick\hfil\cbr
alpar@464:         \hskip\rskip}}
alpar@464: %
alpar@464: \newskip\lskip\newskip\rskip
alpar@464: 
alpar@464: \def\cartouche{%
alpar@464: \par  % can't be in the midst of a paragraph.
alpar@464: \begingroup
alpar@464:         \lskip=\leftskip \rskip=\rightskip
alpar@464:         \leftskip=0pt\rightskip=0pt %we want these *outside*.
alpar@464:         \cartinner=\hsize \advance\cartinner by-\lskip
alpar@464:                           \advance\cartinner by-\rskip
alpar@464:         \cartouter=\hsize
alpar@464:         \advance\cartouter by 18.4pt % allow for 3pt kerns on either
alpar@464: %                                    side, and for 6pt waste from
alpar@464: %                                    each corner char, and rule thickness
alpar@464:         \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
alpar@464:         % Flag to tell @lisp, etc., not to narrow margin.
alpar@464:         \let\nonarrowing=\comment
alpar@464:         \vbox\bgroup
alpar@464:                 \baselineskip=0pt\parskip=0pt\lineskip=0pt
alpar@464:                 \carttop
alpar@464:                 \hbox\bgroup
alpar@464:                         \hskip\lskip
alpar@464:                         \vrule\kern3pt
alpar@464:                         \vbox\bgroup
alpar@464:                                 \hsize=\cartinner
alpar@464:                                 \kern3pt
alpar@464:                                 \begingroup
alpar@464:                                         \baselineskip=\normbskip
alpar@464:                                         \lineskip=\normlskip
alpar@464:                                         \parskip=\normpskip
alpar@464:                                         \vskip -\parskip
alpar@464: \def\Ecartouche{%
alpar@464:                                 \endgroup
alpar@464:                                 \kern3pt
alpar@464:                         \egroup
alpar@464:                         \kern3pt\vrule
alpar@464:                         \hskip\rskip
alpar@464:                 \egroup
alpar@464:                 \cartbot
alpar@464:         \egroup
alpar@464: \endgroup
alpar@464: }}
alpar@464: 
alpar@464: 
alpar@464: % This macro is called at the beginning of all the @example variants,
alpar@464: % inside a group.
alpar@464: \def\nonfillstart{%
alpar@464:   \aboveenvbreak
alpar@464:   \inENV % This group ends at the end of the body
alpar@464:   \hfuzz = 12pt % Don't be fussy
alpar@464:   \sepspaces % Make spaces be word-separators rather than space tokens.
alpar@464:   \let\par = \lisppar % don't ignore blank lines
alpar@464:   \obeylines % each line of input is a line of output
alpar@464:   \parskip = 0pt
alpar@464:   \parindent = 0pt
alpar@464:   \emergencystretch = 0pt % don't try to avoid overfull boxes
alpar@464:   % @cartouche defines \nonarrowing to inhibit narrowing
alpar@464:   % at next level down.
alpar@464:   \ifx\nonarrowing\relax
alpar@464:     \advance \leftskip by \lispnarrowing
alpar@464:     \exdentamount=\lispnarrowing
alpar@464:     \let\exdent=\nofillexdent
alpar@464:     \let\nonarrowing=\relax
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % Define the \E... control sequence only if we are inside the particular
alpar@464: % environment, so the error checking in \end will work.
alpar@464: %
alpar@464: % To end an @example-like environment, we first end the paragraph (via
alpar@464: % \afterenvbreak's vertical glue), and then the group.  That way we keep
alpar@464: % the zero \parskip that the environments set -- \parskip glue will be
alpar@464: % inserted at the beginning of the next paragraph in the document, after
alpar@464: % the environment.
alpar@464: %
alpar@464: \def\nonfillfinish{\afterenvbreak\endgroup}
alpar@464: 
alpar@464: % @lisp: indented, narrowed, typewriter font.
alpar@464: \def\lisp{\begingroup
alpar@464:   \nonfillstart
alpar@464:   \let\Elisp = \nonfillfinish
alpar@464:   \tt
alpar@464:   \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
alpar@464:   \gobble       % eat return
alpar@464: }
alpar@464: 
alpar@464: % @example: Same as @lisp.
alpar@464: \def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
alpar@464: 
alpar@464: % @smallexample and @smalllisp: use smaller fonts.
alpar@464: % Originally contributed by Pavel@xerox.
alpar@464: \def\smalllisp{\begingroup
alpar@464:   \def\Esmalllisp{\nonfillfinish\endgroup}%
alpar@464:   \def\Esmallexample{\nonfillfinish\endgroup}%
alpar@464:   \smallexamplefonts
alpar@464:   \lisp
alpar@464: }
alpar@464: \let\smallexample = \smalllisp
alpar@464: 
alpar@464: 
alpar@464: % @display: same as @lisp except keep current font.
alpar@464: %
alpar@464: \def\display{\begingroup
alpar@464:   \nonfillstart
alpar@464:   \let\Edisplay = \nonfillfinish
alpar@464:   \gobble
alpar@464: }
alpar@464: %
alpar@464: % @smalldisplay: @display plus smaller fonts.
alpar@464: %
alpar@464: \def\smalldisplay{\begingroup
alpar@464:   \def\Esmalldisplay{\nonfillfinish\endgroup}%
alpar@464:   \smallexamplefonts \rm
alpar@464:   \display
alpar@464: }
alpar@464: 
alpar@464: % @format: same as @display except don't narrow margins.
alpar@464: %
alpar@464: \def\format{\begingroup
alpar@464:   \let\nonarrowing = t
alpar@464:   \nonfillstart
alpar@464:   \let\Eformat = \nonfillfinish
alpar@464:   \gobble
alpar@464: }
alpar@464: %
alpar@464: % @smallformat: @format plus smaller fonts.
alpar@464: %
alpar@464: \def\smallformat{\begingroup
alpar@464:   \def\Esmallformat{\nonfillfinish\endgroup}%
alpar@464:   \smallexamplefonts \rm
alpar@464:   \format
alpar@464: }
alpar@464: 
alpar@464: % @flushleft (same as @format).
alpar@464: %
alpar@464: \def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
alpar@464: 
alpar@464: % @flushright.
alpar@464: %
alpar@464: \def\flushright{\begingroup
alpar@464:   \let\nonarrowing = t
alpar@464:   \nonfillstart
alpar@464:   \let\Eflushright = \nonfillfinish
alpar@464:   \advance\leftskip by 0pt plus 1fill
alpar@464:   \gobble
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: % @quotation does normal linebreaking (hence we can't use \nonfillstart)
alpar@464: % and narrows the margins.
alpar@464: %
alpar@464: \def\quotation{%
alpar@464:   \begingroup\inENV %This group ends at the end of the @quotation body
alpar@464:   {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
alpar@464:   \parindent=0pt
alpar@464:   % We have retained a nonzero parskip for the environment, since we're
alpar@464:   % doing normal filling. So to avoid extra space below the environment...
alpar@464:   \def\Equotation{\parskip = 0pt \nonfillfinish}%
alpar@464:   %
alpar@464:   % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
alpar@464:   \ifx\nonarrowing\relax
alpar@464:     \advance\leftskip by \lispnarrowing
alpar@464:     \advance\rightskip by \lispnarrowing
alpar@464:     \exdentamount = \lispnarrowing
alpar@464:     \let\nonarrowing = \relax
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: % LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
alpar@464: % If we want to allow any <char> as delimiter,
alpar@464: % we need the curly braces so that makeinfo sees the @verb command, eg:
alpar@464: % `@verbx...x' would look like the '@verbx' command.  --janneke@gnu.org
alpar@464: %
alpar@464: % [Knuth]: Donald Ervin Knuth, 1996.  The TeXbook.
alpar@464: %
alpar@464: % [Knuth] p.344; only we need to do the other characters Texinfo sets
alpar@464: % active too.  Otherwise, they get lost as the first character on a
alpar@464: % verbatim line.
alpar@464: \def\dospecials{%
alpar@464:   \do\ \do\\\do\{\do\}\do\$\do\&%
alpar@464:   \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
alpar@464:   \do\<\do\>\do\|\do\@\do+\do\"%
alpar@464: }
alpar@464: %
alpar@464: % [Knuth] p. 380
alpar@464: \def\uncatcodespecials{%
alpar@464:   \def\do##1{\catcode`##1=12}\dospecials}
alpar@464: %
alpar@464: % [Knuth] pp. 380,381,391
alpar@464: % Disable Spanish ligatures ?` and !` of \tt font
alpar@464: \begingroup
alpar@464:   \catcode`\`=\active\gdef`{\relax\lq}
alpar@464: \endgroup
alpar@464: %
alpar@464: % Setup for the @verb command.
alpar@464: %
alpar@464: % Eight spaces for a tab
alpar@464: \begingroup
alpar@464:   \catcode`\^^I=\active
alpar@464:   \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
alpar@464: \endgroup
alpar@464: %
alpar@464: \def\setupverb{%
alpar@464:   \tt  % easiest (and conventionally used) font for verbatim
alpar@464:   \def\par{\leavevmode\endgraf}%
alpar@464:   \catcode`\`=\active
alpar@464:   \tabeightspaces
alpar@464:   % Respect line breaks,
alpar@464:   % print special symbols as themselves, and
alpar@464:   % make each space count
alpar@464:   % must do in this order:
alpar@464:   \obeylines \uncatcodespecials \sepspaces
alpar@464: }
alpar@464: 
alpar@464: % Setup for the @verbatim environment
alpar@464: %
alpar@464: % Real tab expansion
alpar@464: \newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
alpar@464: %
alpar@464: \def\starttabbox{\setbox0=\hbox\bgroup}
alpar@464: \begingroup
alpar@464:   \catcode`\^^I=\active
alpar@464:   \gdef\tabexpand{%
alpar@464:     \catcode`\^^I=\active
alpar@464:     \def^^I{\leavevmode\egroup
alpar@464:       \dimen0=\wd0 % the width so far, or since the previous tab
alpar@464:       \divide\dimen0 by\tabw
alpar@464:       \multiply\dimen0 by\tabw % compute previous multiple of \tabw
alpar@464:       \advance\dimen0 by\tabw  % advance to next multiple of \tabw
alpar@464:       \wd0=\dimen0 \box0 \starttabbox
alpar@464:     }%
alpar@464:   }
alpar@464: \endgroup
alpar@464: \def\setupverbatim{%
alpar@464:   % Easiest (and conventionally used) font for verbatim
alpar@464:   \tt
alpar@464:   \def\par{\leavevmode\egroup\box0\endgraf}%
alpar@464:   \catcode`\`=\active
alpar@464:   \tabexpand
alpar@464:   % Respect line breaks,
alpar@464:   % print special symbols as themselves, and
alpar@464:   % make each space count
alpar@464:   % must do in this order:
alpar@464:   \obeylines \uncatcodespecials \sepspaces
alpar@464:   \everypar{\starttabbox}%
alpar@464: }
alpar@464: 
alpar@464: % Do the @verb magic: verbatim text is quoted by unique
alpar@464: % delimiter characters.  Before first delimiter expect a
alpar@464: % right brace, after last delimiter expect closing brace:
alpar@464: %
alpar@464: %    \def\doverb'{'<char>#1<char>'}'{#1}
alpar@464: %
alpar@464: % [Knuth] p. 382; only eat outer {}
alpar@464: \begingroup
alpar@464:   \catcode`[=1\catcode`]=2\catcode`\{=12\catcode`\}=12
alpar@464:   \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
alpar@464: \endgroup
alpar@464: %
alpar@464: \def\verb{\begingroup\setupverb\doverb}
alpar@464: %
alpar@464: %
alpar@464: % Do the @verbatim magic: define the macro \doverbatim so that
alpar@464: % the (first) argument ends when '@end verbatim' is reached, ie:
alpar@464: %
alpar@464: %     \def\doverbatim#1@end verbatim{#1}
alpar@464: %
alpar@464: % For Texinfo it's a lot easier than for LaTeX,
alpar@464: % because texinfo's \verbatim doesn't stop at '\end{verbatim}':
alpar@464: % we need not redefine '\', '{' and '}'.
alpar@464: %
alpar@464: % Inspired by LaTeX's verbatim command set [latex.ltx]
alpar@464: %% Include LaTeX hack for completeness -- never know
alpar@464: %% \begingroup
alpar@464: %% \catcode`|=0 \catcode`[=1
alpar@464: %% \catcode`]=2\catcode`\{=12\catcode`\}=12\catcode`\ =\active
alpar@464: %% \catcode`\\=12|gdef|doverbatim#1@end verbatim[
alpar@464: %% #1|endgroup|def|Everbatim[]|end[verbatim]]
alpar@464: %% |endgroup
alpar@464: %
alpar@464: \begingroup
alpar@464:   \catcode`\ =\active
alpar@464:   \obeylines %
alpar@464:   % ignore everything up to the first ^^M, that's the newline at the end
alpar@464:   % of the @verbatim input line itself.  Otherwise we get an extra blank
alpar@464:   % line in the output.
alpar@464:   \gdef\doverbatim#1^^M#2@end verbatim{#2\end{verbatim}}%
alpar@464: \endgroup
alpar@464: %
alpar@464: \def\verbatim{%
alpar@464:   \def\Everbatim{\nonfillfinish\endgroup}%
alpar@464:   \begingroup
alpar@464:     \nonfillstart
alpar@464:     \advance\leftskip by -\defbodyindent
alpar@464:     \begingroup\setupverbatim\doverbatim
alpar@464: }
alpar@464: 
alpar@464: % @verbatiminclude FILE - insert text of file in verbatim environment.
alpar@464: %
alpar@464: % Allow normal characters that we make active in the argument (a file name).
alpar@464: \def\verbatiminclude{%
alpar@464:   \begingroup
alpar@464:     \catcode`\\=\other
alpar@464:     \catcode`~=\other
alpar@464:     \catcode`^=\other
alpar@464:     \catcode`_=\other
alpar@464:     \catcode`|=\other
alpar@464:     \catcode`<=\other
alpar@464:     \catcode`>=\other
alpar@464:     \catcode`+=\other
alpar@464:     \parsearg\doverbatiminclude
alpar@464: }
alpar@464: \def\setupverbatiminclude{%
alpar@464:   \begingroup
alpar@464:     \nonfillstart
alpar@464:     \advance\leftskip by -\defbodyindent
alpar@464:     \begingroup\setupverbatim
alpar@464: }
alpar@464: %
alpar@464: \def\doverbatiminclude#1{%
alpar@464:      % Restore active chars for included file.
alpar@464:   \endgroup
alpar@464:   \begingroup
alpar@464:     \let\value=\expandablevalue
alpar@464:     \def\thisfile{#1}%
alpar@464:     \expandafter\expandafter\setupverbatiminclude\input\thisfile
alpar@464:   \endgroup
alpar@464:   \nonfillfinish
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @copying ... @end copying.
alpar@464: % Save the text away for @insertcopying later.  Many commands won't be
alpar@464: % allowed in this context, but that's ok.
alpar@464: %
alpar@464: % We save the uninterpreted tokens, rather than creating a box.
alpar@464: % Saving the text in a box would be much easier, but then all the
alpar@464: % typesetting commands (@smallbook, font changes, etc.) have to be done
alpar@464: % beforehand -- and a) we want @copying to be done first in the source
alpar@464: % file; b) letting users define the frontmatter in as flexible order as
alpar@464: % possible is very desirable.
alpar@464: %
alpar@464: \def\copying{\begingroup
alpar@464:   % Define a command to swallow text until we reach `@end copying'.
alpar@464:   % \ is the escape char in this texinfo.tex file, so it is the
alpar@464:   % delimiter for the command; @ will be the escape char when we read
alpar@464:   % it, but that doesn't matter.
alpar@464:   \long\def\docopying##1\end copying{\gdef\copyingtext{##1}\enddocopying}%
alpar@464:   %
alpar@464:   % We must preserve ^^M's in the input file; see \insertcopying below.
alpar@464:   \catcode`\^^M = \active
alpar@464:   \docopying
alpar@464: }
alpar@464: 
alpar@464: % What we do to finish off the copying text.
alpar@464: %
alpar@464: \def\enddocopying{\endgroup\ignorespaces}
alpar@464: 
alpar@464: % @insertcopying.  Here we must play games with ^^M's.  On the one hand,
alpar@464: % we need them to delimit commands such as `@end quotation', so they
alpar@464: % must be active.  On the other hand, we certainly don't want every
alpar@464: % end-of-line to be a \par, as would happen with the normal active
alpar@464: % definition of ^^M.  On the third hand, two ^^M's in a row should still
alpar@464: % generate a \par.
alpar@464: %
alpar@464: % Our approach is to make ^^M insert a space and a penalty1 normally;
alpar@464: % then it can also check if \lastpenalty=1.  If it does, then manually
alpar@464: % do \par.
alpar@464: %
alpar@464: % This messes up the normal definitions of @c[omment], so we redefine
alpar@464: % it.  Similarly for @ignore.  (These commands are used in the gcc
alpar@464: % manual for man page generation.)
alpar@464: %
alpar@464: % Seems pretty fragile, most line-oriented commands will presumably
alpar@464: % fail, but for the limited use of getting the copying text (which
alpar@464: % should be quite simple) inserted, we can hope it's ok.
alpar@464: %
alpar@464: {\catcode`\^^M=\active %
alpar@464: \gdef\insertcopying{\begingroup %
alpar@464:   \parindent = 0pt  % looks wrong on title page
alpar@464:   \def^^M{%
alpar@464:     \ifnum \lastpenalty=1 %
alpar@464:       \par %
alpar@464:     \else %
alpar@464:       \space \penalty 1 %
alpar@464:     \fi %
alpar@464:   }%
alpar@464:   %
alpar@464:   % Fix @c[omment] for catcode 13 ^^M's.
alpar@464:   \def\c##1^^M{\ignorespaces}%
alpar@464:   \let\comment = \c %
alpar@464:   %
alpar@464:   % Don't bother jumping through all the hoops that \doignore does, it
alpar@464:   % would be very hard since the catcodes are already set.
alpar@464:   \long\def\ignore##1\end ignore{\ignorespaces}%
alpar@464:   %
alpar@464:   \copyingtext %
alpar@464: \endgroup}%
alpar@464: }
alpar@464: 
alpar@464: \message{defuns,}
alpar@464: % @defun etc.
alpar@464: 
alpar@464: % Allow user to change definition object font (\df) internally
alpar@464: \def\setdeffont#1 {\csname DEF#1\endcsname}
alpar@464: 
alpar@464: \newskip\defbodyindent \defbodyindent=.4in
alpar@464: \newskip\defargsindent \defargsindent=50pt
alpar@464: \newskip\deflastargmargin \deflastargmargin=18pt
alpar@464: 
alpar@464: \newcount\parencount
alpar@464: 
alpar@464: % We want ()&[] to print specially on the defun line.
alpar@464: %
alpar@464: \def\activeparens{%
alpar@464:   \catcode`\(=\active \catcode`\)=\active
alpar@464:   \catcode`\&=\active
alpar@464:   \catcode`\[=\active \catcode`\]=\active
alpar@464: }
alpar@464: 
alpar@464: % Make control sequences which act like normal parenthesis chars.
alpar@464: \let\lparen = ( \let\rparen = )
alpar@464: 
alpar@464: {\activeparens % Now, smart parens don't turn on until &foo (see \amprm)
alpar@464: 
alpar@464: % Be sure that we always have a definition for `(', etc.  For example,
alpar@464: % if the fn name has parens in it, \boldbrax will not be in effect yet,
alpar@464: % so TeX would otherwise complain about undefined control sequence.
alpar@464: \global\let(=\lparen \global\let)=\rparen
alpar@464: \global\let[=\lbrack \global\let]=\rbrack
alpar@464: 
alpar@464: \gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 }
alpar@464: \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
alpar@464: % This is used to turn on special parens
alpar@464: % but make & act ordinary (given that it's active).
alpar@464: \gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr}
alpar@464: 
alpar@464: % Definitions of (, ) and & used in args for functions.
alpar@464: % This is the definition of ( outside of all parentheses.
alpar@464: \gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested
alpar@464:   \global\advance\parencount by 1
alpar@464: }
alpar@464: %
alpar@464: % This is the definition of ( when already inside a level of parens.
alpar@464: \gdef\opnested{\char`\(\global\advance\parencount by 1 }
alpar@464: %
alpar@464: \gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0.
alpar@464:   % also in that case restore the outer-level definition of (.
alpar@464:   \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi
alpar@464:   \global\advance \parencount by -1 }
alpar@464: % If we encounter &foo, then turn on ()-hacking afterwards
alpar@464: \gdef\amprm#1 {{\rm\&#1}\let(=\oprm \let)=\clrm\ }
alpar@464: %
alpar@464: \gdef\normalparens{\boldbrax\let&=\ampnr}
alpar@464: } % End of definition inside \activeparens
alpar@464: %% These parens (in \boldbrax) actually are a little bolder than the
alpar@464: %% contained text.  This is especially needed for [ and ]
alpar@464: \def\opnr{{\sf\char`\(}\global\advance\parencount by 1 }
alpar@464: \def\clnr{{\sf\char`\)}\global\advance\parencount by -1 }
alpar@464: \let\ampnr = \&
alpar@464: \def\lbrb{{\bf\char`\[}}
alpar@464: \def\rbrb{{\bf\char`\]}}
alpar@464: 
alpar@464: % Active &'s sneak into the index arguments, so make sure it's defined.
alpar@464: {
alpar@464:   \catcode`& = \active
alpar@464:   \global\let& = \ampnr
alpar@464: }
alpar@464: 
alpar@464: % \defname, which formats the name of the @def (not the args).
alpar@464: % #1 is the function name.
alpar@464: % #2 is the type of definition, such as "Function".
alpar@464: %
alpar@464: \def\defname#1#2{%
alpar@464:   % How we'll output the type name.  Putting it in brackets helps
alpar@464:   % distinguish it from the body text that may end up on the next line
alpar@464:   % just below it.
alpar@464:   \ifempty{#2}%
alpar@464:     \def\defnametype{}%
alpar@464:   \else
alpar@464:     \def\defnametype{[\rm #2]}%
alpar@464:   \fi
alpar@464:   %
alpar@464:   % Get the values of \leftskip and \rightskip as they were outside the @def...
alpar@464:   \dimen2=\leftskip
alpar@464:   \advance\dimen2 by -\defbodyindent
alpar@464:   %
alpar@464:   % Figure out values for the paragraph shape.
alpar@464:   \setbox0=\hbox{\hskip \deflastargmargin{\defnametype}}%
alpar@464:   \dimen0=\hsize \advance \dimen0 by -\wd0  % compute size for first line
alpar@464:   \dimen1=\hsize \advance \dimen1 by -\defargsindent  % size for continuations
alpar@464:   \parshape 2 0in \dimen0 \defargsindent \dimen1
alpar@464:   %
alpar@464:   % Output arg 2 ("Function" or some such) but stuck inside a box of
alpar@464:   % width 0 so it does not interfere with linebreaking.
alpar@464:   \noindent
alpar@464:   %
alpar@464:   {% Adjust \hsize to exclude the ambient margins,
alpar@464:    % so that \rightline will obey them.
alpar@464:    \advance \hsize by -\dimen2
alpar@464:    \dimen3 = 0pt  % was -1.25pc
alpar@464:    \rlap{\rightline{\defnametype\kern\dimen3}}%
alpar@464:   }%
alpar@464:   %
alpar@464:   % Allow all lines to be underfull without complaint:
alpar@464:   \tolerance=10000 \hbadness=10000
alpar@464:   \advance\leftskip by -\defbodyindent
alpar@464:   \exdentamount=\defbodyindent
alpar@464:   {\df #1}\enskip        % output function name
alpar@464:   % \defunargs will be called next to output the arguments, if any.
alpar@464: }
alpar@464: 
alpar@464: % Common pieces to start any @def...
alpar@464: % #1 is the \E... control sequence to end the definition (which we define).
alpar@464: % #2 is the \...x control sequence (which our caller defines).
alpar@464: % #3 is the control sequence to process the header, such as \defunheader.
alpar@464: %
alpar@464: \def\parsebodycommon#1#2#3{%
alpar@464:   \begingroup\inENV
alpar@464:   % If there are two @def commands in a row, we'll have a \nobreak,
alpar@464:   % which is there to keep the function description together with its
alpar@464:   % header.  But if there's nothing but headers, we want to allow a
alpar@464:   % break after all.  Check for penalty 10002 (inserted by
alpar@464:   % \defargscommonending) instead of 10000, since the sectioning
alpar@464:   % commands insert a \penalty10000, and we don't want to allow a break
alpar@464:   % between a section heading and a defun.
alpar@464:   \ifnum\lastpenalty=10002 \penalty0 \fi
alpar@464:   \medbreak
alpar@464:   %
alpar@464:   % Define the \E... end token that this defining construct specifies
alpar@464:   % so that it will exit this group.
alpar@464:   \def#1{\endgraf\endgroup\medbreak}%
alpar@464:   %
alpar@464:   \parindent=0in
alpar@464:   \advance\leftskip by \defbodyindent
alpar@464:   \exdentamount=\defbodyindent
alpar@464: }
alpar@464: 
alpar@464: % Common part of the \...x definitions.
alpar@464: %
alpar@464: \def\defxbodycommon{%
alpar@464:   % As with \parsebodycommon above, allow line break if we have multiple
alpar@464:   % x headers in a row.  It's not a great place, though.
alpar@464:   \ifnum\lastpenalty=10000 \penalty1000 \fi
alpar@464:   %
alpar@464:   \begingroup\obeylines
alpar@464: }
alpar@464: 
alpar@464: % Process body of @defun, @deffn, @defmac, etc.
alpar@464: %
alpar@464: \def\defparsebody#1#2#3{%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2{\defxbodycommon \activeparens \spacesplit#3}%
alpar@464:   \catcode\equalChar=\active
alpar@464:   \begingroup\obeylines\activeparens
alpar@464:   \spacesplit#3%
alpar@464: }
alpar@464: 
alpar@464: % #1, #2, #3 are the common arguments (see \parsebodycommon above).
alpar@464: % #4, delimited by the space, is the class name.
alpar@464: %
alpar@464: \def\defmethparsebody#1#2#3#4 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 {\defxbodycommon \activeparens \spacesplit{#3{##1}}}%
alpar@464:   \begingroup\obeylines\activeparens
alpar@464:   % The \empty here prevents misinterpretation of a construct such as
alpar@464:   %   @deffn {whatever} {Enharmonic comma}
alpar@464:   % See comments at \deftpparsebody, although in our case we don't have
alpar@464:   % to remove the \empty afterwards, since it is empty.
alpar@464:   \spacesplit{#3{#4}}\empty
alpar@464: }
alpar@464: 
alpar@464: % Used for @deftypemethod and @deftypeivar.
alpar@464: % #1, #2, #3 are the common arguments (see \defparsebody).
alpar@464: % #4, delimited by a space, is the class name.
alpar@464: % #5 is the method's return type.
alpar@464: %
alpar@464: \def\deftypemethparsebody#1#2#3#4 #5 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 ##2 {\defxbodycommon \activeparens \spacesplit{#3{##1}{##2}}}%
alpar@464:   \begingroup\obeylines\activeparens
alpar@464:   \spacesplit{#3{#4}{#5}}%
alpar@464: }
alpar@464: 
alpar@464: % Used for @deftypeop.  The change from \deftypemethparsebody is an
alpar@464: % extra argument at the beginning which is the `category', instead of it
alpar@464: % being the hardwired string `Method' or `Instance Variable'.  We have
alpar@464: % to account for this both in the \...x definition and in parsing the
alpar@464: % input at hand.  Thus also need a control sequence (passed as #5) for
alpar@464: % the \E... definition to assign the category name to.
alpar@464: %
alpar@464: \def\deftypeopparsebody#1#2#3#4#5 #6 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 ##2 ##3 {\def#4{##1}%
alpar@464:     \defxbodycommon \activeparens \spacesplit{#3{##2}{##3}}}%
alpar@464:   \begingroup\obeylines\activeparens
alpar@464:   \spacesplit{#3{#5}{#6}}%
alpar@464: }
alpar@464: 
alpar@464: % For @defop.
alpar@464: \def\defopparsebody #1#2#3#4#5 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 ##2 {\def#4{##1}%
alpar@464:     \defxbodycommon \activeparens \spacesplit{#3{##2}}}%
alpar@464:   \begingroup\obeylines\activeparens
alpar@464:   \spacesplit{#3{#5}}%
alpar@464: }
alpar@464: 
alpar@464: % These parsing functions are similar to the preceding ones
alpar@464: % except that they do not make parens into active characters.
alpar@464: % These are used for "variables" since they have no arguments.
alpar@464: %
alpar@464: \def\defvarparsebody #1#2#3{%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2{\defxbodycommon \spacesplit#3}%
alpar@464:   \catcode\equalChar=\active
alpar@464:   \begingroup\obeylines
alpar@464:   \spacesplit#3%
alpar@464: }
alpar@464: 
alpar@464: % @defopvar.
alpar@464: \def\defopvarparsebody #1#2#3#4#5 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 ##2 {\def#4{##1}%
alpar@464:     \defxbodycommon \spacesplit{#3{##2}}}%
alpar@464:   \begingroup\obeylines
alpar@464:   \spacesplit{#3{#5}}%
alpar@464: }
alpar@464: 
alpar@464: \def\defvrparsebody#1#2#3#4 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
alpar@464:   \begingroup\obeylines
alpar@464:   \spacesplit{#3{#4}}%
alpar@464: }
alpar@464: 
alpar@464: % This loses on `@deftp {Data Type} {struct termios}' -- it thinks the
alpar@464: % type is just `struct', because we lose the braces in `{struct
alpar@464: % termios}' when \spacesplit reads its undelimited argument.  Sigh.
alpar@464: % \let\deftpparsebody=\defvrparsebody
alpar@464: %
alpar@464: % So, to get around this, we put \empty in with the type name.  That
alpar@464: % way, TeX won't find exactly `{...}' as an undelimited argument, and
alpar@464: % won't strip off the braces.
alpar@464: %
alpar@464: \def\deftpparsebody #1#2#3#4 {%
alpar@464:   \parsebodycommon{#1}{#2}{#3}%
alpar@464:   \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
alpar@464:   \begingroup\obeylines
alpar@464:   \spacesplit{\parsetpheaderline{#3{#4}}}\empty
alpar@464: }
alpar@464: 
alpar@464: % Fine, but then we have to eventually remove the \empty *and* the
alpar@464: % braces (if any).  That's what this does.
alpar@464: %
alpar@464: \def\removeemptybraces\empty#1\relax{#1}
alpar@464: 
alpar@464: % After \spacesplit has done its work, this is called -- #1 is the final
alpar@464: % thing to call, #2 the type name (which starts with \empty), and #3
alpar@464: % (which might be empty) the arguments.
alpar@464: %
alpar@464: \def\parsetpheaderline#1#2#3{%
alpar@464:   #1{\removeemptybraces#2\relax}{#3}%
alpar@464: }%
alpar@464: 
alpar@464: % Split up #2 (the rest of the input line) at the first space token.
alpar@464: % call #1 with two arguments:
alpar@464: %  the first is all of #2 before the space token,
alpar@464: %  the second is all of #2 after that space token.
alpar@464: % If #2 contains no space token, all of it is passed as the first arg
alpar@464: % and the second is passed as empty.
alpar@464: %
alpar@464: {\obeylines %
alpar@464:  \gdef\spacesplit#1#2^^M{\endgroup\spacesplitx{#1}#2 \relax\spacesplitx}%
alpar@464:  \long\gdef\spacesplitx#1#2 #3#4\spacesplitx{%
alpar@464:    \ifx\relax #3%
alpar@464:      #1{#2}{}%
alpar@464:    \else %
alpar@464:      #1{#2}{#3#4}%
alpar@464:    \fi}%
alpar@464: }
alpar@464: 
alpar@464: % Define @defun.
alpar@464: 
alpar@464: % This is called to end the arguments processing for all the @def... commands.
alpar@464: %
alpar@464: \def\defargscommonending{%
alpar@464:   \interlinepenalty = 10000
alpar@464:   \advance\rightskip by 0pt plus 1fil
alpar@464:   \endgraf
alpar@464:   \nobreak\vskip -\parskip
alpar@464:   \penalty 10002  % signal to \parsebodycommon.
alpar@464: }
alpar@464: 
alpar@464: % This expands the args and terminates the paragraph they comprise.
alpar@464: %
alpar@464: \def\defunargs#1{\functionparens \sl
alpar@464: % Expand, preventing hyphenation at `-' chars.
alpar@464: % Note that groups don't affect changes in \hyphenchar.
alpar@464: % Set the font temporarily and use \font in case \setfont made \tensl a macro.
alpar@464: {\tensl\hyphenchar\font=0}%
alpar@464: #1%
alpar@464: {\tensl\hyphenchar\font=45}%
alpar@464: \ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi%
alpar@464:   \defargscommonending
alpar@464: }
alpar@464: 
alpar@464: \def\deftypefunargs #1{%
alpar@464: % Expand, preventing hyphenation at `-' chars.
alpar@464: % Note that groups don't affect changes in \hyphenchar.
alpar@464: % Use \boldbraxnoamp, not \functionparens, so that & is not special.
alpar@464: \boldbraxnoamp
alpar@464: \tclose{#1}% avoid \code because of side effects on active chars
alpar@464:   \defargscommonending
alpar@464: }
alpar@464: 
alpar@464: % Do complete processing of one @defun or @defunx line already parsed.
alpar@464: 
alpar@464: % @deffn Command forward-char nchars
alpar@464: 
alpar@464: \def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader}
alpar@464: 
alpar@464: \def\deffnheader #1#2#3{\doind {fn}{\code{#2}}%
alpar@464: \begingroup\defname {#2}{#1}\defunargs{#3}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @defun == @deffn Function
alpar@464: 
alpar@464: \def\defun{\defparsebody\Edefun\defunx\defunheader}
alpar@464: 
alpar@464: \def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
alpar@464: \begingroup\defname {#1}{\putwordDeffunc}%
alpar@464: \defunargs {#2}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @deftypefun int foobar (int @var{foo}, float @var{bar})
alpar@464: 
alpar@464: \def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader}
alpar@464: 
alpar@464: % #1 is the data type.  #2 is the name and args.
alpar@464: \def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax}
alpar@464: % #1 is the data type, #2 the name, #3 the args.
alpar@464: \def\deftypefunheaderx #1#2 #3\relax{%
alpar@464: \doind {fn}{\code{#2}}% Make entry in function index
alpar@464: \begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypefun}%
alpar@464: \deftypefunargs {#3}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar})
alpar@464: 
alpar@464: \def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader}
alpar@464: 
alpar@464: % \defheaderxcond#1\relax$.$
alpar@464: % puts #1 in @code, followed by a space, but does nothing if #1 is null.
alpar@464: \def\defheaderxcond#1#2$.${\ifx#1\relax\else\code{#1#2} \fi}
alpar@464: 
alpar@464: % #1 is the classification.  #2 is the data type.  #3 is the name and args.
alpar@464: \def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax}
alpar@464: % #1 is the classification, #2 the data type, #3 the name, #4 the args.
alpar@464: \def\deftypefnheaderx #1#2#3 #4\relax{%
alpar@464: \doind {fn}{\code{#3}}% Make entry in function index
alpar@464: \begingroup
alpar@464: \normalparens % notably, turn off `&' magic, which prevents
alpar@464: %               at least some C++ text from working
alpar@464: \defname {\defheaderxcond#2\relax$.$#3}{#1}%
alpar@464: \deftypefunargs {#4}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @defmac == @deffn Macro
alpar@464: 
alpar@464: \def\defmac{\defparsebody\Edefmac\defmacx\defmacheader}
alpar@464: 
alpar@464: \def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
alpar@464: \begingroup\defname {#1}{\putwordDefmac}%
alpar@464: \defunargs {#2}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @defspec == @deffn Special Form
alpar@464: 
alpar@464: \def\defspec{\defparsebody\Edefspec\defspecx\defspecheader}
alpar@464: 
alpar@464: \def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
alpar@464: \begingroup\defname {#1}{\putwordDefspec}%
alpar@464: \defunargs {#2}\endgroup %
alpar@464: \catcode\equalChar=\other % Turn off change made in \defparsebody
alpar@464: }
alpar@464: 
alpar@464: % @defop CATEGORY CLASS OPERATION ARG...
alpar@464: %
alpar@464: \def\defop #1 {\def\defoptype{#1}%
alpar@464: \defopparsebody\Edefop\defopx\defopheader\defoptype}
alpar@464: %
alpar@464: \def\defopheader#1#2#3{%
alpar@464:   \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% function index entry
alpar@464:   \begingroup
alpar@464:     \defname{#2}{\defoptype\ \putwordon\ #1}%
alpar@464:     \defunargs{#3}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @deftypeop CATEGORY CLASS TYPE OPERATION ARG...
alpar@464: %
alpar@464: \def\deftypeop #1 {\def\deftypeopcategory{#1}%
alpar@464:   \deftypeopparsebody\Edeftypeop\deftypeopx\deftypeopheader
alpar@464:                        \deftypeopcategory}
alpar@464: %
alpar@464: % #1 is the class name, #2 the data type, #3 the operation name, #4 the args.
alpar@464: \def\deftypeopheader#1#2#3#4{%
alpar@464:   \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
alpar@464:   \begingroup
alpar@464:     \defname{\defheaderxcond#2\relax$.$#3}
alpar@464:             {\deftypeopcategory\ \putwordon\ \code{#1}}%
alpar@464:     \deftypefunargs{#4}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @deftypemethod CLASS TYPE METHOD ARG...
alpar@464: %
alpar@464: \def\deftypemethod{%
alpar@464:   \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader}
alpar@464: %
alpar@464: % #1 is the class name, #2 the data type, #3 the method name, #4 the args.
alpar@464: \def\deftypemethodheader#1#2#3#4{%
alpar@464:   \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
alpar@464:   \begingroup
alpar@464:     \defname{\defheaderxcond#2\relax$.$#3}{\putwordMethodon\ \code{#1}}%
alpar@464:     \deftypefunargs{#4}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @deftypeivar CLASS TYPE VARNAME
alpar@464: %
alpar@464: \def\deftypeivar{%
alpar@464:   \deftypemethparsebody\Edeftypeivar\deftypeivarx\deftypeivarheader}
alpar@464: %
alpar@464: % #1 is the class name, #2 the data type, #3 the variable name.
alpar@464: \def\deftypeivarheader#1#2#3{%
alpar@464:   \dosubind{vr}{\code{#3}}{\putwordof\ \code{#1}}% entry in variable index
alpar@464:   \begingroup
alpar@464:     \defname{\defheaderxcond#2\relax$.$#3}
alpar@464:             {\putwordInstanceVariableof\ \code{#1}}%
alpar@464:     \defvarargs{#3}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @defmethod == @defop Method
alpar@464: %
alpar@464: \def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader}
alpar@464: %
alpar@464: % #1 is the class name, #2 the method name, #3 the args.
alpar@464: \def\defmethodheader#1#2#3{%
alpar@464:   \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index
alpar@464:   \begingroup
alpar@464:     \defname{#2}{\putwordMethodon\ \code{#1}}%
alpar@464:     \defunargs{#3}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @defcv {Class Option} foo-class foo-flag
alpar@464: 
alpar@464: \def\defcv #1 {\def\defcvtype{#1}%
alpar@464: \defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype}
alpar@464: 
alpar@464: \def\defcvarheader #1#2#3{%
alpar@464:   \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% variable index entry
alpar@464:   \begingroup
alpar@464:     \defname{#2}{\defcvtype\ \putwordof\ #1}%
alpar@464:     \defvarargs{#3}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @defivar CLASS VARNAME == @defcv {Instance Variable} CLASS VARNAME
alpar@464: %
alpar@464: \def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader}
alpar@464: %
alpar@464: \def\defivarheader#1#2#3{%
alpar@464:   \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% entry in var index
alpar@464:   \begingroup
alpar@464:     \defname{#2}{\putwordInstanceVariableof\ #1}%
alpar@464:     \defvarargs{#3}%
alpar@464:   \endgroup
alpar@464: }
alpar@464: 
alpar@464: % @defvar
alpar@464: % First, define the processing that is wanted for arguments of @defvar.
alpar@464: % This is actually simple: just print them in roman.
alpar@464: % This must expand the args and terminate the paragraph they make up
alpar@464: \def\defvarargs #1{\normalparens #1%
alpar@464:   \defargscommonending
alpar@464: }
alpar@464: 
alpar@464: % @defvr Counter foo-count
alpar@464: 
alpar@464: \def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader}
alpar@464: 
alpar@464: \def\defvrheader #1#2#3{\doind {vr}{\code{#2}}%
alpar@464: \begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup}
alpar@464: 
alpar@464: % @defvar == @defvr Variable
alpar@464: 
alpar@464: \def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader}
alpar@464: 
alpar@464: \def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
alpar@464: \begingroup\defname {#1}{\putwordDefvar}%
alpar@464: \defvarargs {#2}\endgroup %
alpar@464: }
alpar@464: 
alpar@464: % @defopt == @defvr {User Option}
alpar@464: 
alpar@464: \def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader}
alpar@464: 
alpar@464: \def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
alpar@464: \begingroup\defname {#1}{\putwordDefopt}%
alpar@464: \defvarargs {#2}\endgroup %
alpar@464: }
alpar@464: 
alpar@464: % @deftypevar int foobar
alpar@464: 
alpar@464: \def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader}
alpar@464: 
alpar@464: % #1 is the data type.  #2 is the name, perhaps followed by text that
alpar@464: % is actually part of the data type, which should not be put into the index.
alpar@464: \def\deftypevarheader #1#2{%
alpar@464: \dovarind#2 \relax% Make entry in variables index
alpar@464: \begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypevar}%
alpar@464:   \defargscommonending
alpar@464: \endgroup}
alpar@464: \def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}}
alpar@464: 
alpar@464: % @deftypevr {Global Flag} int enable
alpar@464: 
alpar@464: \def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader}
alpar@464: 
alpar@464: \def\deftypevrheader #1#2#3{\dovarind#3 \relax%
alpar@464: \begingroup\defname {\defheaderxcond#2\relax$.$#3}{#1}
alpar@464:   \defargscommonending
alpar@464: \endgroup}
alpar@464: 
alpar@464: % Now define @deftp
alpar@464: % Args are printed in bold, a slight difference from @defvar.
alpar@464: 
alpar@464: \def\deftpargs #1{\bf \defvarargs{#1}}
alpar@464: 
alpar@464: % @deftp Class window height width ...
alpar@464: 
alpar@464: \def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader}
alpar@464: 
alpar@464: \def\deftpheader #1#2#3{\doind {tp}{\code{#2}}%
alpar@464: \begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup}
alpar@464: 
alpar@464: % These definitions are used if you use @defunx (etc.)
alpar@464: % anywhere other than immediately after a @defun or @defunx.
alpar@464: %
alpar@464: \def\defcvx#1 {\errmessage{@defcvx in invalid context}}
alpar@464: \def\deffnx#1 {\errmessage{@deffnx in invalid context}}
alpar@464: \def\defivarx#1 {\errmessage{@defivarx in invalid context}}
alpar@464: \def\defmacx#1 {\errmessage{@defmacx in invalid context}}
alpar@464: \def\defmethodx#1 {\errmessage{@defmethodx in invalid context}}
alpar@464: \def\defoptx #1 {\errmessage{@defoptx in invalid context}}
alpar@464: \def\defopx#1 {\errmessage{@defopx in invalid context}}
alpar@464: \def\defspecx#1 {\errmessage{@defspecx in invalid context}}
alpar@464: \def\deftpx#1 {\errmessage{@deftpx in invalid context}}
alpar@464: \def\deftypefnx#1 {\errmessage{@deftypefnx in invalid context}}
alpar@464: \def\deftypefunx#1 {\errmessage{@deftypefunx in invalid context}}
alpar@464: \def\deftypeivarx#1 {\errmessage{@deftypeivarx in invalid context}}
alpar@464: \def\deftypemethodx#1 {\errmessage{@deftypemethodx in invalid context}}
alpar@464: \def\deftypeopx#1 {\errmessage{@deftypeopx in invalid context}}
alpar@464: \def\deftypevarx#1 {\errmessage{@deftypevarx in invalid context}}
alpar@464: \def\deftypevrx#1 {\errmessage{@deftypevrx in invalid context}}
alpar@464: \def\defunx#1 {\errmessage{@defunx in invalid context}}
alpar@464: \def\defvarx#1 {\errmessage{@defvarx in invalid context}}
alpar@464: \def\defvrx#1 {\errmessage{@defvrx in invalid context}}
alpar@464: 
alpar@464: 
alpar@464: \message{macros,}
alpar@464: % @macro.
alpar@464: 
alpar@464: % To do this right we need a feature of e-TeX, \scantokens,
alpar@464: % which we arrange to emulate with a temporary file in ordinary TeX.
alpar@464: \ifx\eTeXversion\undefined
alpar@464:  \newwrite\macscribble
alpar@464:  \def\scanmacro#1{%
alpar@464:    \begingroup \newlinechar`\^^M
alpar@464:    % Undo catcode changes of \startcontents and \doprintindex
alpar@464:    \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
alpar@464:    % Append \endinput to make sure that TeX does not see the ending newline.
alpar@464:    \toks0={#1\endinput}%
alpar@464:    \immediate\openout\macscribble=\jobname.tmp
alpar@464:    \immediate\write\macscribble{\the\toks0}%
alpar@464:    \immediate\closeout\macscribble
alpar@464:    \let\xeatspaces\eatspaces
alpar@464:    \input \jobname.tmp
alpar@464:    \endgroup
alpar@464: }
alpar@464: \else
alpar@464: \def\scanmacro#1{%
alpar@464: \begingroup \newlinechar`\^^M
alpar@464: % Undo catcode changes of \startcontents and \doprintindex
alpar@464: \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
alpar@464: \let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup}
alpar@464: \fi
alpar@464: 
alpar@464: \newcount\paramno   % Count of parameters
alpar@464: \newtoks\macname    % Macro name
alpar@464: \newif\ifrecursive  % Is it recursive?
alpar@464: \def\macrolist{}    % List of all defined macros in the form
alpar@464:                     % \do\macro1\do\macro2...
alpar@464: 
alpar@464: % Utility routines.
alpar@464: % Thisdoes \let #1 = #2, except with \csnames.
alpar@464: \def\cslet#1#2{%
alpar@464: \expandafter\expandafter
alpar@464: \expandafter\let
alpar@464: \expandafter\expandafter
alpar@464: \csname#1\endcsname
alpar@464: \csname#2\endcsname}
alpar@464: 
alpar@464: % Trim leading and trailing spaces off a string.
alpar@464: % Concepts from aro-bend problem 15 (see CTAN).
alpar@464: {\catcode`\@=11
alpar@464: \gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
alpar@464: \gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
alpar@464: \gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
alpar@464: \def\unbrace#1{#1}
alpar@464: \unbrace{\gdef\trim@@@ #1 } #2@{#1}
alpar@464: }
alpar@464: 
alpar@464: % Trim a single trailing ^^M off a string.
alpar@464: {\catcode`\^^M=\other \catcode`\Q=3%
alpar@464: \gdef\eatcr #1{\eatcra #1Q^^MQ}%
alpar@464: \gdef\eatcra#1^^MQ{\eatcrb#1Q}%
alpar@464: \gdef\eatcrb#1Q#2Q{#1}%
alpar@464: }
alpar@464: 
alpar@464: % Macro bodies are absorbed as an argument in a context where
alpar@464: % all characters are catcode 10, 11 or 12, except \ which is active
alpar@464: % (as in normal texinfo). It is necessary to change the definition of \.
alpar@464: 
alpar@464: % It's necessary to have hard CRs when the macro is executed. This is
alpar@464: % done by  making ^^M (\endlinechar) catcode 12 when reading the macro
alpar@464: % body, and then making it the \newlinechar in \scanmacro.
alpar@464: 
alpar@464: \def\macrobodyctxt{%
alpar@464:   \catcode`\~=\other
alpar@464:   \catcode`\^=\other
alpar@464:   \catcode`\_=\other
alpar@464:   \catcode`\|=\other
alpar@464:   \catcode`\<=\other
alpar@464:   \catcode`\>=\other
alpar@464:   \catcode`\+=\other
alpar@464:   \catcode`\{=\other
alpar@464:   \catcode`\}=\other
alpar@464:   \catcode`\@=\other
alpar@464:   \catcode`\^^M=\other
alpar@464:   \usembodybackslash}
alpar@464: 
alpar@464: \def\macroargctxt{%
alpar@464:   \catcode`\~=\other
alpar@464:   \catcode`\^=\other
alpar@464:   \catcode`\_=\other
alpar@464:   \catcode`\|=\other
alpar@464:   \catcode`\<=\other
alpar@464:   \catcode`\>=\other
alpar@464:   \catcode`\+=\other
alpar@464:   \catcode`\@=\other
alpar@464:   \catcode`\\=\other}
alpar@464: 
alpar@464: % \mbodybackslash is the definition of \ in @macro bodies.
alpar@464: % It maps \foo\ => \csname macarg.foo\endcsname => #N
alpar@464: % where N is the macro parameter number.
alpar@464: % We define \csname macarg.\endcsname to be \realbackslash, so
alpar@464: % \\ in macro replacement text gets you a backslash.
alpar@464: 
alpar@464: {\catcode`@=0 @catcode`@\=@active
alpar@464:  @gdef@usembodybackslash{@let\=@mbodybackslash}
alpar@464:  @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
alpar@464: }
alpar@464: \expandafter\def\csname macarg.\endcsname{\realbackslash}
alpar@464: 
alpar@464: \def\macro{\recursivefalse\parsearg\macroxxx}
alpar@464: \def\rmacro{\recursivetrue\parsearg\macroxxx}
alpar@464: 
alpar@464: \def\macroxxx#1{%
alpar@464:   \getargs{#1}%           now \macname is the macname and \argl the arglist
alpar@464:   \ifx\argl\empty       % no arguments
alpar@464:      \paramno=0%
alpar@464:   \else
alpar@464:      \expandafter\parsemargdef \argl;%
alpar@464:   \fi
alpar@464:   \if1\csname ismacro.\the\macname\endcsname
alpar@464:      \message{Warning: redefining \the\macname}%
alpar@464:   \else
alpar@464:      \expandafter\ifx\csname \the\macname\endcsname \relax
alpar@464:      \else \errmessage{Macro name \the\macname\space already defined}\fi
alpar@464:      \global\cslet{macsave.\the\macname}{\the\macname}%
alpar@464:      \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
alpar@464:      % Add the macroname to \macrolist
alpar@464:      \toks0 = \expandafter{\macrolist\do}%
alpar@464:      \xdef\macrolist{\the\toks0
alpar@464:        \expandafter\noexpand\csname\the\macname\endcsname}%
alpar@464:   \fi
alpar@464:   \begingroup \macrobodyctxt
alpar@464:   \ifrecursive \expandafter\parsermacbody
alpar@464:   \else \expandafter\parsemacbody
alpar@464:   \fi}
alpar@464: 
alpar@464: \def\unmacro{\parsearg\dounmacro}
alpar@464: \def\dounmacro#1{%
alpar@464:   \if1\csname ismacro.#1\endcsname
alpar@464:     \global\cslet{#1}{macsave.#1}%
alpar@464:     \global\expandafter\let \csname ismacro.#1\endcsname=0%
alpar@464:     % Remove the macro name from \macrolist:
alpar@464:     \begingroup
alpar@464:       \expandafter\let\csname#1\endcsname \relax
alpar@464:       \let\do\unmacrodo
alpar@464:       \xdef\macrolist{\macrolist}%
alpar@464:     \endgroup
alpar@464:   \else
alpar@464:     \errmessage{Macro #1 not defined}%
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % Called by \do from \dounmacro on each macro.  The idea is to omit any
alpar@464: % macro definitions that have been changed to \relax.
alpar@464: %
alpar@464: \def\unmacrodo#1{%
alpar@464:   \ifx#1\relax
alpar@464:     % remove this
alpar@464:   \else
alpar@464:     \noexpand\do \noexpand #1%
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % This makes use of the obscure feature that if the last token of a
alpar@464: % <parameter list> is #, then the preceding argument is delimited by
alpar@464: % an opening brace, and that opening brace is not consumed.
alpar@464: \def\getargs#1{\getargsxxx#1{}}
alpar@464: \def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
alpar@464: \def\getmacname #1 #2\relax{\macname={#1}}
alpar@464: \def\getmacargs#1{\def\argl{#1}}
alpar@464: 
alpar@464: % Parse the optional {params} list.  Set up \paramno and \paramlist
alpar@464: % so \defmacro knows what to do.  Define \macarg.blah for each blah
alpar@464: % in the params list, to be ##N where N is the position in that list.
alpar@464: % That gets used by \mbodybackslash (above).
alpar@464: 
alpar@464: % We need to get `macro parameter char #' into several definitions.
alpar@464: % The technique used is stolen from LaTeX:  let \hash be something
alpar@464: % unexpandable, insert that wherever you need a #, and then redefine
alpar@464: % it to # just before using the token list produced.
alpar@464: %
alpar@464: % The same technique is used to protect \eatspaces till just before
alpar@464: % the macro is used.
alpar@464: 
alpar@464: \def\parsemargdef#1;{\paramno=0\def\paramlist{}%
alpar@464:         \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,}
alpar@464: \def\parsemargdefxxx#1,{%
alpar@464:   \if#1;\let\next=\relax
alpar@464:   \else \let\next=\parsemargdefxxx
alpar@464:     \advance\paramno by 1%
alpar@464:     \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
alpar@464:         {\xeatspaces{\hash\the\paramno}}%
alpar@464:     \edef\paramlist{\paramlist\hash\the\paramno,}%
alpar@464:   \fi\next}
alpar@464: 
alpar@464: % These two commands read recursive and nonrecursive macro bodies.
alpar@464: % (They're different since rec and nonrec macros end differently.)
alpar@464: 
alpar@464: \long\def\parsemacbody#1@end macro%
alpar@464: {\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
alpar@464: \long\def\parsermacbody#1@end rmacro%
alpar@464: {\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
alpar@464: 
alpar@464: % This defines the macro itself. There are six cases: recursive and
alpar@464: % nonrecursive macros of zero, one, and many arguments.
alpar@464: % Much magic with \expandafter here.
alpar@464: % \xdef is used so that macro definitions will survive the file
alpar@464: % they're defined in; @include reads the file inside a group.
alpar@464: \def\defmacro{%
alpar@464:   \let\hash=##% convert placeholders to macro parameter chars
alpar@464:   \ifrecursive
alpar@464:     \ifcase\paramno
alpar@464:     % 0
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:         \noexpand\scanmacro{\temp}}%
alpar@464:     \or % 1
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:          \bgroup\noexpand\macroargctxt
alpar@464:          \noexpand\braceorline
alpar@464:          \expandafter\noexpand\csname\the\macname xxx\endcsname}%
alpar@464:       \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
alpar@464:          \egroup\noexpand\scanmacro{\temp}}%
alpar@464:     \else % many
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:          \bgroup\noexpand\macroargctxt
alpar@464:          \noexpand\csname\the\macname xx\endcsname}%
alpar@464:       \expandafter\xdef\csname\the\macname xx\endcsname##1{%
alpar@464:           \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
alpar@464:       \expandafter\expandafter
alpar@464:       \expandafter\xdef
alpar@464:       \expandafter\expandafter
alpar@464:         \csname\the\macname xxx\endcsname
alpar@464:           \paramlist{\egroup\noexpand\scanmacro{\temp}}%
alpar@464:     \fi
alpar@464:   \else
alpar@464:     \ifcase\paramno
alpar@464:     % 0
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:         \noexpand\norecurse{\the\macname}%
alpar@464:         \noexpand\scanmacro{\temp}\egroup}%
alpar@464:     \or % 1
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:          \bgroup\noexpand\macroargctxt
alpar@464:          \noexpand\braceorline
alpar@464:          \expandafter\noexpand\csname\the\macname xxx\endcsname}%
alpar@464:       \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
alpar@464:         \egroup
alpar@464:         \noexpand\norecurse{\the\macname}%
alpar@464:         \noexpand\scanmacro{\temp}\egroup}%
alpar@464:     \else % many
alpar@464:       \expandafter\xdef\csname\the\macname\endcsname{%
alpar@464:          \bgroup\noexpand\macroargctxt
alpar@464:          \expandafter\noexpand\csname\the\macname xx\endcsname}%
alpar@464:       \expandafter\xdef\csname\the\macname xx\endcsname##1{%
alpar@464:           \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
alpar@464:       \expandafter\expandafter
alpar@464:       \expandafter\xdef
alpar@464:       \expandafter\expandafter
alpar@464:       \csname\the\macname xxx\endcsname
alpar@464:       \paramlist{%
alpar@464:           \egroup
alpar@464:           \noexpand\norecurse{\the\macname}%
alpar@464:           \noexpand\scanmacro{\temp}\egroup}%
alpar@464:     \fi
alpar@464:   \fi}
alpar@464: 
alpar@464: \def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
alpar@464: 
alpar@464: % \braceorline decides whether the next nonwhitespace character is a
alpar@464: % {.  If so it reads up to the closing }, if not, it reads the whole
alpar@464: % line.  Whatever was read is then fed to the next control sequence
alpar@464: % as an argument (by \parsebrace or \parsearg)
alpar@464: \def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx}
alpar@464: \def\braceorlinexxx{%
alpar@464:   \ifx\nchar\bgroup\else
alpar@464:     \expandafter\parsearg
alpar@464:   \fi \next}
alpar@464: 
alpar@464: % We mant to disable all macros during \shipout so that they are not
alpar@464: % expanded by \write.
alpar@464: \def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
alpar@464:   \edef\next{\macrolist}\expandafter\endgroup\next}
alpar@464: 
alpar@464: 
alpar@464: % @alias.
alpar@464: % We need some trickery to remove the optional spaces around the equal
alpar@464: % sign.  Just make them active and then expand them all to nothing.
alpar@464: \def\alias{\begingroup\obeyspaces\parsearg\aliasxxx}
alpar@464: \def\aliasxxx #1{\aliasyyy#1\relax}
alpar@464: \def\aliasyyy #1=#2\relax{\ignoreactivespaces
alpar@464: \edef\next{\global\let\expandafter\noexpand\csname#1\endcsname=%
alpar@464:            \expandafter\noexpand\csname#2\endcsname}%
alpar@464: \expandafter\endgroup\next}
alpar@464: 
alpar@464: 
alpar@464: \message{cross references,}
alpar@464: % @xref etc.
alpar@464: 
alpar@464: \newwrite\auxfile
alpar@464: 
alpar@464: \newif\ifhavexrefs    % True if xref values are known.
alpar@464: \newif\ifwarnedxrefs  % True if we warned once that they aren't known.
alpar@464: 
alpar@464: % @inforef is relatively simple.
alpar@464: \def\inforef #1{\inforefzzz #1,,,,**}
alpar@464: \def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
alpar@464:   node \samp{\ignorespaces#1{}}}
alpar@464: 
alpar@464: % @node's job is to define \lastnode.
alpar@464: \def\node{\ENVcheck\parsearg\nodezzz}
alpar@464: \def\nodezzz#1{\nodexxx #1,\finishnodeparse}
alpar@464: \def\nodexxx#1,#2\finishnodeparse{\gdef\lastnode{#1}}
alpar@464: \let\nwnode=\node
alpar@464: \let\lastnode=\relax
alpar@464: 
alpar@464: % The sectioning commands (@chapter, etc.) call these.
alpar@464: \def\donoderef{%
alpar@464:   \ifx\lastnode\relax\else
alpar@464:     \expandafter\expandafter\expandafter\setref{\lastnode}%
alpar@464:       {Ysectionnumberandtype}%
alpar@464:     \global\let\lastnode=\relax
alpar@464:   \fi
alpar@464: }
alpar@464: \def\unnumbnoderef{%
alpar@464:   \ifx\lastnode\relax\else
alpar@464:     \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}%
alpar@464:     \global\let\lastnode=\relax
alpar@464:   \fi
alpar@464: }
alpar@464: \def\appendixnoderef{%
alpar@464:   \ifx\lastnode\relax\else
alpar@464:     \expandafter\expandafter\expandafter\setref{\lastnode}%
alpar@464:       {Yappendixletterandtype}%
alpar@464:     \global\let\lastnode=\relax
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: 
alpar@464: % @anchor{NAME} -- define xref target at arbitrary point.
alpar@464: %
alpar@464: \newcount\savesfregister
alpar@464: \gdef\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
alpar@464: \gdef\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
alpar@464: \gdef\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
alpar@464: 
alpar@464: % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
alpar@464: % anchor), namely NAME-title (the corresponding @chapter/etc. name),
alpar@464: % NAME-pg (the page number), and NAME-snt (section number and type).
alpar@464: % Called from \foonoderef.
alpar@464: %
alpar@464: % We have to set \indexdummies so commands such as @code in a section
alpar@464: % title aren't expanded.  It would be nicer not to expand the titles in
alpar@464: % the first place, but there's so many layers that that is hard to do.
alpar@464: %
alpar@464: % Likewise, use \turnoffactive so that punctuation chars such as underscore
alpar@464: % and backslash work in node names.
alpar@464: %
alpar@464: \def\setref#1#2{{%
alpar@464:   \atdummies
alpar@464:   \pdfmkdest{#1}%
alpar@464:   %
alpar@464:   \turnoffactive
alpar@464:   \dosetq{#1-title}{Ytitle}%
alpar@464:   \dosetq{#1-pg}{Ypagenumber}%
alpar@464:   \dosetq{#1-snt}{#2}%
alpar@464: }}
alpar@464: 
alpar@464: % @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
alpar@464: % the node name, #2 the name of the Info cross-reference, #3 the printed
alpar@464: % node name, #4 the name of the Info file, #5 the name of the printed
alpar@464: % manual.  All but the node name can be omitted.
alpar@464: %
alpar@464: \def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
alpar@464: \def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
alpar@464: \def\ref#1{\xrefX[#1,,,,,,,]}
alpar@464: \def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
alpar@464:   \unsepspaces
alpar@464:   \def\printedmanual{\ignorespaces #5}%
alpar@464:   \def\printednodename{\ignorespaces #3}%
alpar@464:   \setbox1=\hbox{\printedmanual}%
alpar@464:   \setbox0=\hbox{\printednodename}%
alpar@464:   \ifdim \wd0 = 0pt
alpar@464:     % No printed node name was explicitly given.
alpar@464:     \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
alpar@464:       % Use the node name inside the square brackets.
alpar@464:       \def\printednodename{\ignorespaces #1}%
alpar@464:     \else
alpar@464:       % Use the actual chapter/section title appear inside
alpar@464:       % the square brackets.  Use the real section title if we have it.
alpar@464:       \ifdim \wd1 > 0pt
alpar@464:         % It is in another manual, so we don't have it.
alpar@464:         \def\printednodename{\ignorespaces #1}%
alpar@464:       \else
alpar@464:         \ifhavexrefs
alpar@464:           % We know the real title if we have the xref values.
alpar@464:           \def\printednodename{\refx{#1-title}{}}%
alpar@464:         \else
alpar@464:           % Otherwise just copy the Info node name.
alpar@464:           \def\printednodename{\ignorespaces #1}%
alpar@464:         \fi%
alpar@464:       \fi
alpar@464:     \fi
alpar@464:   \fi
alpar@464:   %
alpar@464:   % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
alpar@464:   % insert empty discretionaries after hyphens, which means that it will
alpar@464:   % not find a line break at a hyphen in a node names.  Since some manuals
alpar@464:   % are best written with fairly long node names, containing hyphens, this
alpar@464:   % is a loss.  Therefore, we give the text of the node name again, so it
alpar@464:   % is as if TeX is seeing it for the first time.
alpar@464:   \ifpdf
alpar@464:     \leavevmode
alpar@464:     \getfilename{#4}%
alpar@464:     {\turnoffactive \otherbackslash
alpar@464:      \ifnum\filenamelength>0
alpar@464:        \startlink attr{/Border [0 0 0]}%
alpar@464:          goto file{\the\filename.pdf} name{#1}%
alpar@464:      \else
alpar@464:        \startlink attr{/Border [0 0 0]}%
alpar@464:          goto name{#1}%
alpar@464:      \fi
alpar@464:     }%
alpar@464:     \linkcolor
alpar@464:   \fi
alpar@464:   %
alpar@464:   \ifdim \wd1 > 0pt
alpar@464:     \putwordsection{} ``\printednodename'' \putwordin{} \cite{\printedmanual}%
alpar@464:   \else
alpar@464:     % _ (for example) has to be the character _ for the purposes of the
alpar@464:     % control sequence corresponding to the node, but it has to expand
alpar@464:     % into the usual \leavevmode...\vrule stuff for purposes of
alpar@464:     % printing. So we \turnoffactive for the \refx-snt, back on for the
alpar@464:     % printing, back off for the \refx-pg.
alpar@464:     {\turnoffactive \otherbackslash
alpar@464:      % Only output a following space if the -snt ref is nonempty; for
alpar@464:      % @unnumbered and @anchor, it won't be.
alpar@464:      \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
alpar@464:      \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
alpar@464:     }%
alpar@464:     % output the `[mynode]' via a macro.
alpar@464:     \xrefprintnodename\printednodename
alpar@464:     %
alpar@464:     % But we always want a comma and a space:
alpar@464:     ,\space
alpar@464:     %
alpar@464:     % output the `page 3'.
alpar@464:     \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
alpar@464:   \fi
alpar@464:   \endlink
alpar@464: \endgroup}
alpar@464: 
alpar@464: % This macro is called from \xrefX for the `[nodename]' part of xref
alpar@464: % output.  It's a separate macro only so it can be changed more easily,
alpar@464: % since not square brackets don't work in some documents.  Particularly
alpar@464: % one that Bob is working on :).
alpar@464: %
alpar@464: \def\xrefprintnodename#1{[#1]}
alpar@464: 
alpar@464: % \dosetq is called from \setref to do the actual \write (\iflinks).
alpar@464: %
alpar@464: \def\dosetq#1#2{%
alpar@464:   {\let\folio=0%
alpar@464:    \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}%
alpar@464:    \iflinks \next \fi
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % \internalsetq{foo}{page} expands into
alpar@464: %   CHARACTERS @xrdef{foo}{...expansion of \page...}
alpar@464: \def\internalsetq#1#2{@xrdef{#1}{\csname #2\endcsname}}
alpar@464: 
alpar@464: % Things to be expanded by \internalsetq.
alpar@464: %
alpar@464: \def\Ypagenumber{\folio}
alpar@464: \def\Ytitle{\thissection}
alpar@464: \def\Ynothing{}
alpar@464: \def\Ysectionnumberandtype{%
alpar@464:   \ifnum\secno=0
alpar@464:     \putwordChapter@tie \the\chapno
alpar@464:   \else \ifnum\subsecno=0
alpar@464:     \putwordSection@tie \the\chapno.\the\secno
alpar@464:   \else \ifnum\subsubsecno=0
alpar@464:     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
alpar@464:   \else
alpar@464:     \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
alpar@464:   \fi\fi\fi
alpar@464: }
alpar@464: 
alpar@464: \def\Yappendixletterandtype{%
alpar@464:   \ifnum\secno=0
alpar@464:      \putwordAppendix@tie @char\the\appendixno{}%
alpar@464:   \else \ifnum\subsecno=0
alpar@464:      \putwordSection@tie @char\the\appendixno.\the\secno
alpar@464:   \else \ifnum\subsubsecno=0
alpar@464:     \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
alpar@464:   \else
alpar@464:     \putwordSection@tie
alpar@464:       @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
alpar@464:   \fi\fi\fi
alpar@464: }
alpar@464: 
alpar@464: % Use TeX 3.0's \inputlineno to get the line number, for better error
alpar@464: % messages, but if we're using an old version of TeX, don't do anything.
alpar@464: %
alpar@464: \ifx\inputlineno\thisisundefined
alpar@464:   \let\linenumber = \empty % Pre-3.0.
alpar@464: \else
alpar@464:   \def\linenumber{\the\inputlineno:\space}
alpar@464: \fi
alpar@464: 
alpar@464: % Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
alpar@464: % If its value is nonempty, SUFFIX is output afterward.
alpar@464: %
alpar@464: \def\refx#1#2{%
alpar@464:   {%
alpar@464:     \indexnofonts
alpar@464:     \otherbackslash
alpar@464:     \expandafter\global\expandafter\let\expandafter\thisrefX
alpar@464:       \csname X#1\endcsname
alpar@464:   }%
alpar@464:   \ifx\thisrefX\relax
alpar@464:     % If not defined, say something at least.
alpar@464:     \angleleft un\-de\-fined\angleright
alpar@464:     \iflinks
alpar@464:       \ifhavexrefs
alpar@464:         \message{\linenumber Undefined cross reference `#1'.}%
alpar@464:       \else
alpar@464:         \ifwarnedxrefs\else
alpar@464:           \global\warnedxrefstrue
alpar@464:           \message{Cross reference values unknown; you must run TeX again.}%
alpar@464:         \fi
alpar@464:       \fi
alpar@464:     \fi
alpar@464:   \else
alpar@464:     % It's defined, so just use it.
alpar@464:     \thisrefX
alpar@464:   \fi
alpar@464:   #2% Output the suffix in any case.
alpar@464: }
alpar@464: 
alpar@464: % This is the macro invoked by entries in the aux file.
alpar@464: %
alpar@464: \def\xrdef#1{\expandafter\gdef\csname X#1\endcsname}
alpar@464: 
alpar@464: % Read the last existing aux file, if any.  No error if none exists.
alpar@464: \def\readauxfile{\begingroup
alpar@464:   \catcode`\^^@=\other
alpar@464:   \catcode`\^^A=\other
alpar@464:   \catcode`\^^B=\other
alpar@464:   \catcode`\^^C=\other
alpar@464:   \catcode`\^^D=\other
alpar@464:   \catcode`\^^E=\other
alpar@464:   \catcode`\^^F=\other
alpar@464:   \catcode`\^^G=\other
alpar@464:   \catcode`\^^H=\other
alpar@464:   \catcode`\^^K=\other
alpar@464:   \catcode`\^^L=\other
alpar@464:   \catcode`\^^N=\other
alpar@464:   \catcode`\^^P=\other
alpar@464:   \catcode`\^^Q=\other
alpar@464:   \catcode`\^^R=\other
alpar@464:   \catcode`\^^S=\other
alpar@464:   \catcode`\^^T=\other
alpar@464:   \catcode`\^^U=\other
alpar@464:   \catcode`\^^V=\other
alpar@464:   \catcode`\^^W=\other
alpar@464:   \catcode`\^^X=\other
alpar@464:   \catcode`\^^Z=\other
alpar@464:   \catcode`\^^[=\other
alpar@464:   \catcode`\^^\=\other
alpar@464:   \catcode`\^^]=\other
alpar@464:   \catcode`\^^^=\other
alpar@464:   \catcode`\^^_=\other
alpar@464:   % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
alpar@464:   % in xref tags, i.e., node names.  But since ^^e4 notation isn't
alpar@464:   % supported in the main text, it doesn't seem desirable.  Furthermore,
alpar@464:   % that is not enough: for node names that actually contain a ^
alpar@464:   % character, we would end up writing a line like this: 'xrdef {'hat
alpar@464:   % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
alpar@464:   % argument, and \hat is not an expandable control sequence.  It could
alpar@464:   % all be worked out, but why?  Either we support ^^ or we don't.
alpar@464:   %
alpar@464:   % The other change necessary for this was to define \auxhat:
alpar@464:   % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
alpar@464:   % and then to call \auxhat in \setq.
alpar@464:   %
alpar@464:   \catcode`\^=\other
alpar@464:   %
alpar@464:   % Special characters.  Should be turned off anyway, but...
alpar@464:   \catcode`\~=\other
alpar@464:   \catcode`\[=\other
alpar@464:   \catcode`\]=\other
alpar@464:   \catcode`\"=\other
alpar@464:   \catcode`\_=\other
alpar@464:   \catcode`\|=\other
alpar@464:   \catcode`\<=\other
alpar@464:   \catcode`\>=\other
alpar@464:   \catcode`\$=\other
alpar@464:   \catcode`\#=\other
alpar@464:   \catcode`\&=\other
alpar@464:   \catcode`\%=\other
alpar@464:   \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
alpar@464:   %
alpar@464:   % Make the characters 128-255 be printing characters
alpar@464:   {%
alpar@464:     \count 1=128
alpar@464:     \def\loop{%
alpar@464:       \catcode\count 1=\other
alpar@464:       \advance\count 1 by 1
alpar@464:       \ifnum \count 1<256 \loop \fi
alpar@464:     }%
alpar@464:   }%
alpar@464:   %
alpar@464:   % Turn off \ as an escape so we do not lose on
alpar@464:   % entries which were dumped with control sequences in their names.
alpar@464:   % For example, @xrdef{$\leq $-fun}{page ...} made by @defun ^^
alpar@464:   % Reference to such entries still does not work the way one would wish,
alpar@464:   % but at least they do not bomb out when the aux file is read in.
alpar@464:   \catcode`\\=\other
alpar@464:   %
alpar@464:   % @ is our escape character in .aux files.
alpar@464:   \catcode`\{=1
alpar@464:   \catcode`\}=2
alpar@464:   \catcode`\@=0
alpar@464:   %
alpar@464:   \openin 1 \jobname.aux
alpar@464:   \ifeof 1 \else
alpar@464:     \closein 1
alpar@464:     \input \jobname.aux
alpar@464:     \global\havexrefstrue
alpar@464:   \fi
alpar@464:   % Open the new aux file.  TeX will close it automatically at exit.
alpar@464:   \openout\auxfile=\jobname.aux
alpar@464: \endgroup}
alpar@464: 
alpar@464: 
alpar@464: % Footnotes.
alpar@464: 
alpar@464: \newcount \footnoteno
alpar@464: 
alpar@464: % The trailing space in the following definition for supereject is
alpar@464: % vital for proper filling; pages come out unaligned when you do a
alpar@464: % pagealignmacro call if that space before the closing brace is
alpar@464: % removed. (Generally, numeric constants should always be followed by a
alpar@464: % space to prevent strange expansion errors.)
alpar@464: \def\supereject{\par\penalty -20000\footnoteno =0 }
alpar@464: 
alpar@464: % @footnotestyle is meaningful for info output only.
alpar@464: \let\footnotestyle=\comment
alpar@464: 
alpar@464: \let\ptexfootnote=\footnote
alpar@464: 
alpar@464: {\catcode `\@=11
alpar@464: %
alpar@464: % Auto-number footnotes.  Otherwise like plain.
alpar@464: \gdef\footnote{%
alpar@464:   \let\indent=\ptexindent
alpar@464:   \global\advance\footnoteno by \@ne
alpar@464:   \edef\thisfootno{$^{\the\footnoteno}$}%
alpar@464:   %
alpar@464:   % In case the footnote comes at the end of a sentence, preserve the
alpar@464:   % extra spacing after we do the footnote number.
alpar@464:   \let\@sf\empty
alpar@464:   \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
alpar@464:   %
alpar@464:   % Remove inadvertent blank space before typesetting the footnote number.
alpar@464:   \unskip
alpar@464:   \thisfootno\@sf
alpar@464:   \dofootnote
alpar@464: }%
alpar@464: 
alpar@464: % Don't bother with the trickery in plain.tex to not require the
alpar@464: % footnote text as a parameter.  Our footnotes don't need to be so general.
alpar@464: %
alpar@464: % Oh yes, they do; otherwise, @ifset and anything else that uses
alpar@464: % \parseargline fail inside footnotes because the tokens are fixed when
alpar@464: % the footnote is read.  --karl, 16nov96.
alpar@464: %
alpar@464: % The start of the footnote looks usually like this:
alpar@464: \gdef\startfootins{\insert\footins\bgroup}
alpar@464: %
alpar@464: % ... but this macro is redefined inside @multitable.
alpar@464: %
alpar@464: \gdef\dofootnote{%
alpar@464:   \startfootins
alpar@464:   % We want to typeset this text as a normal paragraph, even if the
alpar@464:   % footnote reference occurs in (for example) a display environment.
alpar@464:   % So reset some parameters.
alpar@464:   \hsize=\pagewidth
alpar@464:   \interlinepenalty\interfootnotelinepenalty
alpar@464:   \splittopskip\ht\strutbox % top baseline for broken footnotes
alpar@464:   \splitmaxdepth\dp\strutbox
alpar@464:   \floatingpenalty\@MM
alpar@464:   \leftskip\z@skip
alpar@464:   \rightskip\z@skip
alpar@464:   \spaceskip\z@skip
alpar@464:   \xspaceskip\z@skip
alpar@464:   \parindent\defaultparindent
alpar@464:   %
alpar@464:   \smallfonts \rm
alpar@464:   %
alpar@464:   % Because we use hanging indentation in footnotes, a @noindent appears
alpar@464:   % to exdent this text, so make it be a no-op.  makeinfo does not use
alpar@464:   % hanging indentation so @noindent can still be needed within footnote
alpar@464:   % text after an @example or the like (not that this is good style).
alpar@464:   \let\noindent = \relax
alpar@464:   %
alpar@464:   % Hang the footnote text off the number.  Use \everypar in case the
alpar@464:   % footnote extends for more than one paragraph.
alpar@464:   \everypar = {\hang}%
alpar@464:   \textindent{\thisfootno}%
alpar@464:   %
alpar@464:   % Don't crash into the line above the footnote text.  Since this
alpar@464:   % expands into a box, it must come within the paragraph, lest it
alpar@464:   % provide a place where TeX can split the footnote.
alpar@464:   \footstrut
alpar@464:   \futurelet\next\fo@t
alpar@464: }
alpar@464: }%end \catcode `\@=11
alpar@464: 
alpar@464: % @| inserts a changebar to the left of the current line.  It should
alpar@464: % surround any changed text.  This approach does *not* work if the
alpar@464: % change spans more than two lines of output.  To handle that, we would
alpar@464: % have adopt a much more difficult approach (putting marks into the main
alpar@464: % vertical list for the beginning and end of each change).
alpar@464: %
alpar@464: \def\|{%
alpar@464:   % \vadjust can only be used in horizontal mode.
alpar@464:   \leavevmode
alpar@464:   %
alpar@464:   % Append this vertical mode material after the current line in the output.
alpar@464:   \vadjust{%
alpar@464:     % We want to insert a rule with the height and depth of the current
alpar@464:     % leading; that is exactly what \strutbox is supposed to record.
alpar@464:     \vskip-\baselineskip
alpar@464:     %
alpar@464:     % \vadjust-items are inserted at the left edge of the type.  So
alpar@464:     % the \llap here moves out into the left-hand margin.
alpar@464:     \llap{%
alpar@464:       %
alpar@464:       % For a thicker or thinner bar, change the `1pt'.
alpar@464:       \vrule height\baselineskip width1pt
alpar@464:       %
alpar@464:       % This is the space between the bar and the text.
alpar@464:       \hskip 12pt
alpar@464:     }%
alpar@464:   }%
alpar@464: }
alpar@464: 
alpar@464: % For a final copy, take out the rectangles
alpar@464: % that mark overfull boxes (in case you have decided
alpar@464: % that the text looks ok even though it passes the margin).
alpar@464: %
alpar@464: \def\finalout{\overfullrule=0pt}
alpar@464: 
alpar@464: % @image.  We use the macros from epsf.tex to support this.
alpar@464: % If epsf.tex is not installed and @image is used, we complain.
alpar@464: %
alpar@464: % Check for and read epsf.tex up front.  If we read it only at @image
alpar@464: % time, we might be inside a group, and then its definitions would get
alpar@464: % undone and the next image would fail.
alpar@464: \openin 1 = epsf.tex
alpar@464: \ifeof 1 \else
alpar@464:   \closein 1
alpar@464:   % Do not bother showing banner with epsf.tex v2.7k (available in
alpar@464:   % doc/epsf.tex and on ctan).
alpar@464:   \def\epsfannounce{\toks0 = }%
alpar@464:   \input epsf.tex
alpar@464: \fi
alpar@464: %
alpar@464: % We will only complain once about lack of epsf.tex.
alpar@464: \newif\ifwarnednoepsf
alpar@464: \newhelp\noepsfhelp{epsf.tex must be installed for images to
alpar@464:   work.  It is also included in the Texinfo distribution, or you can get
alpar@464:   it from ftp://tug.org/tex/epsf.tex.}
alpar@464: %
alpar@464: \def\image#1{%
alpar@464:   \ifx\epsfbox\undefined
alpar@464:     \ifwarnednoepsf \else
alpar@464:       \errhelp = \noepsfhelp
alpar@464:       \errmessage{epsf.tex not found, images will be ignored}%
alpar@464:       \global\warnednoepsftrue
alpar@464:     \fi
alpar@464:   \else
alpar@464:     \imagexxx #1,,,,,\finish
alpar@464:   \fi
alpar@464: }
alpar@464: %
alpar@464: % Arguments to @image:
alpar@464: % #1 is (mandatory) image filename; we tack on .eps extension.
alpar@464: % #2 is (optional) width, #3 is (optional) height.
alpar@464: % #4 is (ignored optional) html alt text.
alpar@464: % #5 is (ignored optional) extension.
alpar@464: % #6 is just the usual extra ignored arg for parsing this stuff.
alpar@464: \newif\ifimagevmode
alpar@464: \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
alpar@464:   \catcode`\^^M = 5     % in case we're inside an example
alpar@464:   \normalturnoffactive  % allow _ et al. in names
alpar@464:   % If the image is by itself, center it.
alpar@464:   \ifvmode
alpar@464:     \imagevmodetrue
alpar@464:     \nobreak\bigskip
alpar@464:     % Usually we'll have text after the image which will insert
alpar@464:     % \parskip glue, so insert it here too to equalize the space
alpar@464:     % above and below.
alpar@464:     \nobreak\vskip\parskip
alpar@464:     \nobreak
alpar@464:     \line\bgroup\hss
alpar@464:   \fi
alpar@464:   %
alpar@464:   % Output the image.
alpar@464:   \ifpdf
alpar@464:     \dopdfimage{#1}{#2}{#3}%
alpar@464:   \else
alpar@464:     % \epsfbox itself resets \epsf?size at each figure.
alpar@464:     \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
alpar@464:     \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
alpar@464:     \epsfbox{#1.eps}%
alpar@464:   \fi
alpar@464:   %
alpar@464:   \ifimagevmode \hss \egroup \bigbreak \fi  % space after the image
alpar@464: \endgroup}
alpar@464: 
alpar@464: 
alpar@464: \message{localization,}
alpar@464: % and i18n.
alpar@464: 
alpar@464: % @documentlanguage is usually given very early, just after
alpar@464: % @setfilename.  If done too late, it may not override everything
alpar@464: % properly.  Single argument is the language abbreviation.
alpar@464: % It would be nice if we could set up a hyphenation file here.
alpar@464: %
alpar@464: \def\documentlanguage{\parsearg\dodocumentlanguage}
alpar@464: \def\dodocumentlanguage#1{%
alpar@464:   \tex % read txi-??.tex file in plain TeX.
alpar@464:   % Read the file if it exists.
alpar@464:   \openin 1 txi-#1.tex
alpar@464:   \ifeof1
alpar@464:     \errhelp = \nolanghelp
alpar@464:     \errmessage{Cannot read language file txi-#1.tex}%
alpar@464:     \let\temp = \relax
alpar@464:   \else
alpar@464:     \def\temp{\input txi-#1.tex }%
alpar@464:   \fi
alpar@464:   \temp
alpar@464:   \endgroup
alpar@464: }
alpar@464: \newhelp\nolanghelp{The given language definition file cannot be found or
alpar@464: is empty.  Maybe you need to install it?  In the current directory
alpar@464: should work if nowhere else does.}
alpar@464: 
alpar@464: 
alpar@464: % @documentencoding should change something in TeX eventually, most
alpar@464: % likely, but for now just recognize it.
alpar@464: \let\documentencoding = \comment
alpar@464: 
alpar@464: 
alpar@464: % Page size parameters.
alpar@464: %
alpar@464: \newdimen\defaultparindent \defaultparindent = 15pt
alpar@464: 
alpar@464: \chapheadingskip = 15pt plus 4pt minus 2pt
alpar@464: \secheadingskip = 12pt plus 3pt minus 2pt
alpar@464: \subsecheadingskip = 9pt plus 2pt minus 2pt
alpar@464: 
alpar@464: % Prevent underfull vbox error messages.
alpar@464: \vbadness = 10000
alpar@464: 
alpar@464: % Don't be so finicky about underfull hboxes, either.
alpar@464: \hbadness = 2000
alpar@464: 
alpar@464: % Following George Bush, just get rid of widows and orphans.
alpar@464: \widowpenalty=10000
alpar@464: \clubpenalty=10000
alpar@464: 
alpar@464: % Use TeX 3.0's \emergencystretch to help line breaking, but if we're
alpar@464: % using an old version of TeX, don't do anything.  We want the amount of
alpar@464: % stretch added to depend on the line length, hence the dependence on
alpar@464: % \hsize.  We call this whenever the paper size is set.
alpar@464: %
alpar@464: \def\setemergencystretch{%
alpar@464:   \ifx\emergencystretch\thisisundefined
alpar@464:     % Allow us to assign to \emergencystretch anyway.
alpar@464:     \def\emergencystretch{\dimen0}%
alpar@464:   \else
alpar@464:     \emergencystretch = .15\hsize
alpar@464:   \fi
alpar@464: }
alpar@464: 
alpar@464: % Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
alpar@464: % 4) hoffset; 5) binding offset; 6) topskip; 7) physical page height; 8)
alpar@464: % physical page width.
alpar@464: %
alpar@464: % We also call \setleading{\textleading}, so the caller should define
alpar@464: % \textleading.  The caller should also set \parskip.
alpar@464: %
alpar@464: \def\internalpagesizes#1#2#3#4#5#6#7#8{%
alpar@464:   \voffset = #3\relax
alpar@464:   \topskip = #6\relax
alpar@464:   \splittopskip = \topskip
alpar@464:   %
alpar@464:   \vsize = #1\relax
alpar@464:   \advance\vsize by \topskip
alpar@464:   \outervsize = \vsize
alpar@464:   \advance\outervsize by 2\topandbottommargin
alpar@464:   \pageheight = \vsize
alpar@464:   %
alpar@464:   \hsize = #2\relax
alpar@464:   \outerhsize = \hsize
alpar@464:   \advance\outerhsize by 0.5in
alpar@464:   \pagewidth = \hsize
alpar@464:   %
alpar@464:   \normaloffset = #4\relax
alpar@464:   \bindingoffset = #5\relax
alpar@464:   %
alpar@464:   \ifpdf
alpar@464:     \pdfpageheight #7\relax
alpar@464:     \pdfpagewidth #8\relax
alpar@464:   \fi
alpar@464:   %
alpar@464:   \setleading{\textleading}
alpar@464:   %
alpar@464:   \parindent = \defaultparindent
alpar@464:   \setemergencystretch
alpar@464: }
alpar@464: 
alpar@464: % @letterpaper (the default).
alpar@464: \def\letterpaper{{\globaldefs = 1
alpar@464:   \parskip = 3pt plus 2pt minus 1pt
alpar@464:   \textleading = 13.2pt
alpar@464:   %
alpar@464:   % If page is nothing but text, make it come out even.
alpar@464:   \internalpagesizes{46\baselineskip}{6in}%
alpar@464:                     {\voffset}{.25in}%
alpar@464:                     {\bindingoffset}{36pt}%
alpar@464:                     {11in}{8.5in}%
alpar@464: }}
alpar@464: 
alpar@464: % Use @smallbook to reset parameters for 7x9.5 (or so) format.
alpar@464: \def\smallbook{{\globaldefs = 1
alpar@464:   \parskip = 2pt plus 1pt
alpar@464:   \textleading = 12pt
alpar@464:   %
alpar@464:   \internalpagesizes{7.5in}{5in}%
alpar@464:                     {\voffset}{.25in}%
alpar@464:                     {\bindingoffset}{16pt}%
alpar@464:                     {9.25in}{7in}%
alpar@464:   %
alpar@464:   \lispnarrowing = 0.3in
alpar@464:   \tolerance = 700
alpar@464:   \hfuzz = 1pt
alpar@464:   \contentsrightmargin = 0pt
alpar@464:   \defbodyindent = .5cm
alpar@464: }}
alpar@464: 
alpar@464: % Use @afourpaper to print on European A4 paper.
alpar@464: \def\afourpaper{{\globaldefs = 1
alpar@464:   \parskip = 3pt plus 2pt minus 1pt
alpar@464:   \textleading = 13.2pt
alpar@464:   %
alpar@464:   % Double-side printing via postscript on Laserjet 4050
alpar@464:   % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
alpar@464:   % To change the settings for a different printer or situation, adjust
alpar@464:   % \normaloffset until the front-side and back-side texts align.  Then
alpar@464:   % do the same for \bindingoffset.  You can set these for testing in
alpar@464:   % your texinfo source file like this:
alpar@464:   % @tex
alpar@464:   % \global\normaloffset = -6mm
alpar@464:   % \global\bindingoffset = 10mm
alpar@464:   % @end tex
alpar@464:   \internalpagesizes{51\baselineskip}{160mm}
alpar@464:                     {\voffset}{\hoffset}%
alpar@464:                     {\bindingoffset}{44pt}%
alpar@464:                     {297mm}{210mm}%
alpar@464:   %
alpar@464:   \tolerance = 700
alpar@464:   \hfuzz = 1pt
alpar@464:   \contentsrightmargin = 0pt
alpar@464:   \defbodyindent = 5mm
alpar@464: }}
alpar@464: 
alpar@464: % Use @afivepaper to print on European A5 paper.
alpar@464: % From romildo@urano.iceb.ufop.br, 2 July 2000.
alpar@464: % He also recommends making @example and @lisp be small.
alpar@464: \def\afivepaper{{\globaldefs = 1
alpar@464:   \parskip = 2pt plus 1pt minus 0.1pt
alpar@464:   \textleading = 12.5pt
alpar@464:   %
alpar@464:   \internalpagesizes{160mm}{120mm}%
alpar@464:                     {\voffset}{\hoffset}%
alpar@464:                     {\bindingoffset}{8pt}%
alpar@464:                     {210mm}{148mm}%
alpar@464:   %
alpar@464:   \lispnarrowing = 0.2in
alpar@464:   \tolerance = 800
alpar@464:   \hfuzz = 1.2pt
alpar@464:   \contentsrightmargin = 0pt
alpar@464:   \defbodyindent = 2mm
alpar@464:   \tableindent = 12mm
alpar@464: }}
alpar@464: 
alpar@464: % A specific text layout, 24x15cm overall, intended for A4 paper.
alpar@464: \def\afourlatex{{\globaldefs = 1
alpar@464:   \afourpaper
alpar@464:   \internalpagesizes{237mm}{150mm}%
alpar@464:                     {\voffset}{4.6mm}%
alpar@464:                     {\bindingoffset}{7mm}%
alpar@464:                     {297mm}{210mm}%
alpar@464:   %
alpar@464:   % Must explicitly reset to 0 because we call \afourpaper.
alpar@464:   \globaldefs = 0
alpar@464: }}
alpar@464: 
alpar@464: % Use @afourwide to print on A4 paper in landscape format.
alpar@464: \def\afourwide{{\globaldefs = 1
alpar@464:   \afourpaper
alpar@464:   \internalpagesizes{241mm}{165mm}%
alpar@464:                     {\voffset}{-2.95mm}%
alpar@464:                     {\bindingoffset}{7mm}%
alpar@464:                     {297mm}{210mm}%
alpar@464:   \globaldefs = 0
alpar@464: }}
alpar@464: 
alpar@464: % @pagesizes TEXTHEIGHT[,TEXTWIDTH]
alpar@464: % Perhaps we should allow setting the margins, \topskip, \parskip,
alpar@464: % and/or leading, also. Or perhaps we should compute them somehow.
alpar@464: %
alpar@464: \def\pagesizes{\parsearg\pagesizesxxx}
alpar@464: \def\pagesizesxxx#1{\pagesizesyyy #1,,\finish}
alpar@464: \def\pagesizesyyy#1,#2,#3\finish{{%
alpar@464:   \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
alpar@464:   \globaldefs = 1
alpar@464:   %
alpar@464:   \parskip = 3pt plus 2pt minus 1pt
alpar@464:   \setleading{\textleading}%
alpar@464:   %
alpar@464:   \dimen0 = #1
alpar@464:   \advance\dimen0 by \voffset
alpar@464:   %
alpar@464:   \dimen2 = \hsize
alpar@464:   \advance\dimen2 by \normaloffset
alpar@464:   %
alpar@464:   \internalpagesizes{#1}{\hsize}%
alpar@464:                     {\voffset}{\normaloffset}%
alpar@464:                     {\bindingoffset}{44pt}%
alpar@464:                     {\dimen0}{\dimen2}%
alpar@464: }}
alpar@464: 
alpar@464: % Set default to letter.
alpar@464: %
alpar@464: \letterpaper
alpar@464: 
alpar@464: 
alpar@464: \message{and turning on texinfo input format.}
alpar@464: 
alpar@464: % Define macros to output various characters with catcode for normal text.
alpar@464: \catcode`\"=\other
alpar@464: \catcode`\~=\other
alpar@464: \catcode`\^=\other
alpar@464: \catcode`\_=\other
alpar@464: \catcode`\|=\other
alpar@464: \catcode`\<=\other
alpar@464: \catcode`\>=\other
alpar@464: \catcode`\+=\other
alpar@464: \catcode`\$=\other
alpar@464: \def\normaldoublequote{"}
alpar@464: \def\normaltilde{~}
alpar@464: \def\normalcaret{^}
alpar@464: \def\normalunderscore{_}
alpar@464: \def\normalverticalbar{|}
alpar@464: \def\normalless{<}
alpar@464: \def\normalgreater{>}
alpar@464: \def\normalplus{+}
alpar@464: \def\normaldollar{$}%$ font-lock fix
alpar@464: 
alpar@464: % This macro is used to make a character print one way in ttfont
alpar@464: % where it can probably just be output, and another way in other fonts,
alpar@464: % where something hairier probably needs to be done.
alpar@464: %
alpar@464: % #1 is what to print if we are indeed using \tt; #2 is what to print
alpar@464: % otherwise.  Since all the Computer Modern typewriter fonts have zero
alpar@464: % interword stretch (and shrink), and it is reasonable to expect all
alpar@464: % typewriter fonts to have this, we can check that font parameter.
alpar@464: %
alpar@464: \def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
alpar@464: 
alpar@464: % Same as above, but check for italic font.  Actually this also catches
alpar@464: % non-italic slanted fonts since it is impossible to distinguish them from
alpar@464: % italic fonts.  But since this is only used by $ and it uses \sl anyway
alpar@464: % this is not a problem.
alpar@464: \def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
alpar@464: 
alpar@464: % Turn off all special characters except @
alpar@464: % (and those which the user can use as if they were ordinary).
alpar@464: % Most of these we simply print from the \tt font, but for some, we can
alpar@464: % use math or other variants that look better in normal text.
alpar@464: 
alpar@464: \catcode`\"=\active
alpar@464: \def\activedoublequote{{\tt\char34}}
alpar@464: \let"=\activedoublequote
alpar@464: \catcode`\~=\active
alpar@464: \def~{{\tt\char126}}
alpar@464: \chardef\hat=`\^
alpar@464: \catcode`\^=\active
alpar@464: \def^{{\tt \hat}}
alpar@464: 
alpar@464: \catcode`\_=\active
alpar@464: \def_{\ifusingtt\normalunderscore\_}
alpar@464: % Subroutine for the previous macro.
alpar@464: \def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
alpar@464: 
alpar@464: \catcode`\|=\active
alpar@464: \def|{{\tt\char124}}
alpar@464: \chardef \less=`\<
alpar@464: \catcode`\<=\active
alpar@464: \def<{{\tt \less}}
alpar@464: \chardef \gtr=`\>
alpar@464: \catcode`\>=\active
alpar@464: \def>{{\tt \gtr}}
alpar@464: \catcode`\+=\active
alpar@464: \def+{{\tt \char 43}}
alpar@464: \catcode`\$=\active
alpar@464: \def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
alpar@464: 
alpar@464: % Set up an active definition for =, but don't enable it most of the time.
alpar@464: {\catcode`\==\active
alpar@464: \global\def={{\tt \char 61}}}
alpar@464: 
alpar@464: \catcode`+=\active
alpar@464: \catcode`\_=\active
alpar@464: 
alpar@464: % If a .fmt file is being used, characters that might appear in a file
alpar@464: % name cannot be active until we have parsed the command line.
alpar@464: % So turn them off again, and have \everyjob (or @setfilename) turn them on.
alpar@464: % \otherifyactive is called near the end of this file.
alpar@464: \def\otherifyactive{\catcode`+=\other \catcode`\_=\other}
alpar@464: 
alpar@464: \catcode`\@=0
alpar@464: 
alpar@464: % \rawbackslashxx outputs one backslash character in current font,
alpar@464: % as in \char`\\.
alpar@464: \global\chardef\rawbackslashxx=`\\
alpar@464: 
alpar@464: % \rawbackslash defines an active \ to do \rawbackslashxx.
alpar@464: % \otherbackslash defines an active \ to be a literal `\' character with
alpar@464: % catcode other.
alpar@464: {\catcode`\\=\active
alpar@464:  @gdef@rawbackslash{@let\=@rawbackslashxx}
alpar@464:  @gdef@otherbackslash{@let\=@realbackslash}
alpar@464: }
alpar@464: 
alpar@464: % \realbackslash is an actual character `\' with catcode other.
alpar@464: {\catcode`\\=\other @gdef@realbackslash{\}}
alpar@464: 
alpar@464: % \normalbackslash outputs one backslash in fixed width font.
alpar@464: \def\normalbackslash{{\tt\rawbackslashxx}}
alpar@464: 
alpar@464: \catcode`\\=\active
alpar@464: 
alpar@464: % Used sometimes to turn off (effectively) the active characters
alpar@464: % even after parsing them.
alpar@464: @def@turnoffactive{%
alpar@464:   @let"=@normaldoublequote
alpar@464:   @let\=@realbackslash
alpar@464:   @let~=@normaltilde
alpar@464:   @let^=@normalcaret
alpar@464:   @let_=@normalunderscore
alpar@464:   @let|=@normalverticalbar
alpar@464:   @let<=@normalless
alpar@464:   @let>=@normalgreater
alpar@464:   @let+=@normalplus
alpar@464:   @let$=@normaldollar %$ font-lock fix
alpar@464: }
alpar@464: 
alpar@464: % Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
alpar@464: % the literal character `\'.  (Thus, \ is not expandable when this is in
alpar@464: % effect.)
alpar@464: %
alpar@464: @def@normalturnoffactive{@turnoffactive @let\=@normalbackslash}
alpar@464: 
alpar@464: % Make _ and + \other characters, temporarily.
alpar@464: % This is canceled by @fixbackslash.
alpar@464: @otherifyactive
alpar@464: 
alpar@464: % If a .fmt file is being used, we don't want the `\input texinfo' to show up.
alpar@464: % That is what \eatinput is for; after that, the `\' should revert to printing
alpar@464: % a backslash.
alpar@464: %
alpar@464: @gdef@eatinput input texinfo{@fixbackslash}
alpar@464: @global@let\ = @eatinput
alpar@464: 
alpar@464: % On the other hand, perhaps the file did not have a `\input texinfo'. Then
alpar@464: % the first `\{ in the file would cause an error. This macro tries to fix
alpar@464: % that, assuming it is called before the first `\' could plausibly occur.
alpar@464: % Also back turn on active characters that might appear in the input
alpar@464: % file name, in case not using a pre-dumped format.
alpar@464: %
alpar@464: @gdef@fixbackslash{%
alpar@464:   @ifx\@eatinput @let\ = @normalbackslash @fi
alpar@464:   @catcode`+=@active
alpar@464:   @catcode`@_=@active
alpar@464: }
alpar@464: 
alpar@464: % Say @foo, not \foo, in error messages.
alpar@464: @escapechar = `@@
alpar@464: 
alpar@464: % These look ok in all fonts, so just make them not special.
alpar@464: @catcode`@& = @other
alpar@464: @catcode`@# = @other
alpar@464: @catcode`@% = @other
alpar@464: 
alpar@464: @c Set initial fonts.
alpar@464: @textfonts
alpar@464: @rm
alpar@464: 
alpar@464: 
alpar@464: @c Local variables:
alpar@464: @c eval: (add-hook 'write-file-hooks 'time-stamp)
alpar@464: @c page-delimiter: "^\\\\message"
alpar@464: @c time-stamp-start: "def\\\\texinfoversion{"
alpar@464: @c time-stamp-format: "%:y-%02m-%02d.%02H"
alpar@464: @c time-stamp-end: "}"
alpar@464: @c End: