]> git.donarmstrong.com Git - lilypond.git/commitdiff
update
authorJan Nieuwenhuizen <janneke@gnu.org>
Sun, 29 Feb 2004 20:12:59 +0000 (20:12 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sun, 29 Feb 2004 20:12:59 +0000 (20:12 +0000)
tex/texinfo.tex

index a5946dfd5a3d3ac5ad93d98a07262443d0ee1fee..cf260906e1b6fc541ee44e9d8f83ab89755b5ac1 100644 (file)
@@ -3,10 +3,11 @@
 % Load plain if necessary, i.e., if running under initex.
 \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
 %
-\def\texinfoversion{2003-12-07.11}
+\def\texinfoversion{2004-02-25.17}
 %
 % Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
-% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
+% Foundation, Inc.
 %
 % This texinfo.tex file is free software; you can redistribute it and/or
 % modify it under the terms of the GNU General Public License as
 \chardef\exclamChar= `\!
 \chardef\questChar = `\?
 \chardef\semiChar  = `\;
-\chardef\spaceChar = `\ %
 \chardef\underChar = `\_
 
+\chardef\spaceChar = `\ %
+\chardef\spacecat = 10
+\def\spaceisspace{\catcode\spaceChar=\spacecat}
+
 % Ignore a token.
 %
 \def\gobble#1{}
 % The following is used inside several \edef's.
 \def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
 
-% Make an outer definition into an inner one (due to Chris Thompson).
-% The arguments should be the control sequence to be defined, and the
-% new of the \outer control sequence, as characters; the control
-% sequence #1 is defined to be just the same as \csname#2\endcsname, but
-% not \outer.
-% 
-% For example, \innerdef\innernewcount{newcount} defines \innernewcount
-% to be a non-outer version of \newcount.
-%
-\def\innerdef#1#2{\edef#1{\expandafter\noexpand\csname #2\endcsname}}%
-%
-\innerdef\innernewcount{newcount}%
-
 % Hyphenation fixes.
-\hyphenation{ap-pen-dix}
-\hyphenation{eshell}
-\hyphenation{mini-buf-fer mini-buf-fers}
-\hyphenation{time-stamp}
-\hyphenation{white-space}
+\hyphenation{
+  Flor-i-da Ghost-script Ghost-view Mac-OS ap-pen-dix bit-map bit-maps
+  data-base data-bases eshell fall-ing half-way long-est man-u-script
+  man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
+  par-a-digms rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
+  stand-alone strong-est time-stamp time-stamps which-ever white-space
+  wide-spread wrap-around
+}
 
 % Margin to add to right of even pages, to left of odd pages.
 \newdimen\bindingoffset
     \tracingassigns1
   \fi
   \tracingcommands3  % 3 gives us more in etex
-  \errorcontextlines\maxdimen
+  \errorcontextlines16
 }%
 
 % add check for \lastpenalty to plain's definitions.  If the last thing
   \def\next{#2}%
   \begingroup
     \obeylines
-    \catcode`\ =10
+    \spaceisspace
     #1%
     \parseargline\empty% Insert the \empty token, see \finishparsearg below.
 }
 
 % First remove any @comment, then any @c comment.
 \def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
-\def\argremovec#1\c#2\ArgTerm{\argremovespace#1$ $\ArgTerm}
-% \argremovec might leave us with trailing space, though; e.g.,
+\def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
+
+% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
+%
+% \argremovec might leave us with trailing space, e.g.,
 %    @end itemize  @c foo
-% Note that the argument cannot contain the TeX $, as its catcode is
-% changed to \other when Texinfo source is read.
-\def\argremovespace#1 $#2\ArgTerm{\finishparsearg#1$\ArgTerm}
+% This space token undergoes the same procedure and is eventually removed
+% by \finishparsearg.
+%
+\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
+\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
+\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
+  \def\temp{#3}%
+  \ifx\temp\empty
+    % We cannot use \next here, as it holds the macro to run;
+    % thus we reuse \temp.
+    \let\temp\finishparsearg
+  \else
+    \let\temp\argcheckspaces
+  \fi
+  % Put the space token in:
+  \temp#1 #3\ArgTerm
+}
 
 % If a _delimited_ argument is enclosed in braces, they get stripped; so
 % to get _exactly_ the rest of the line, we had to prevent such situation.
-% We prepended an \empty token at the very beginning and we expand it
+% We prepended an \empty token at the very beginning and we expand it now,
 % just before passing the control to \next.
-% (But first, we have to spend the remaining $ or two.)
-\def\finishparsearg#1$#2\ArgTerm{\expandafter\next\expandafter{#1}}
+% (Similarily, we have to think about #3 of \argcheckspacesY above: it is
+% either the null string, or it ends with \^^M---thus there is no danger
+% that a pair of braces would be stripped.
+%
+% But first, we have to remove the trailing space token.
+%
+\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}}
 
-% \defparsearg\foo{...}
-%      is roughly equivalent to
+% \parseargdef\foo{...}
+%       is roughly equivalent to
 % \def\foo{\parsearg\Xfoo}
 % \def\Xfoo#1{...}
 %
 % Actually, I use \csname\string\foo\endcsname, ie. \\foo, as it is my
 % favourite TeX trick.  --kasal, 16nov03
 
-\def\defparsearg#1{%
-  \expandafter \dodefparsearg \csname\string#1\endcsname #1%
+\def\parseargdef#1{%
+  \expandafter \doparseargdef \csname\string#1\endcsname #1%
 }
-\def\dodefparsearg#1#2{%
+\def\doparseargdef#1#2{%
   \def#2{\parsearg#1}%
   \def#1##1%
 }
 
 \def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
 
+% Define the framework for environments in texinfo.tex.  It's used like this:
+% 
+%   \envdef\foo{...}
+%   \def\Efoo{...}
+%   
+% It's the responsibility of \envdef to insert \begingroup before the
+% actual body; @end closes the group after calling \Efoo.  \envdef also
+% defines \thisenv, so the current environment is known; @end checks
+% whether the environment name matches.  The \checkenv macro can also be
+% used to check whether the current environment is the one expected.
+% 
+% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
+% are not treated as enviroments; they don't open a group.  (The
+% implementation of @end takes care not to call \endgroup in this
+% special case.)
 
-%% These are used to keep @begin/@end levels from running away
-%% Call \inENV within environments (after a \begingroup)
-\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
-\def\ENVcheck{%
-\ifENV\errmessage{Still within an environment; press RETURN to continue}
-\endgroup\fi} % This is not perfect, but it should reduce lossage
 
-% @end foo executes the definition of \Efoo.
-%
-\defparsearg\end{%
-  \expandafter\ifx\csname E#1\endcsname\relax
-    \badenderror{#1}%
-  \else
-    % Everything's ok; the right environment has been started.
-    \csname E#1\endcsname
-  \fi
-}
+% At runtime, environments start with this:
+\def\startenvironment#1{\begingroup\def\thisenv{#1}}
+% initialize
+\let\thisenv\empty
 
-\def\badenderror#1{%
-  \expandafter\ifx\csname#1\endcsname\relax
-    % There's no \foo, i.e., no ``environment'' foo.
-    \errhelp = \EMsimple
-    \errmessage{Undefined command `@end #1'}%
+% ... but they get defined via ``\envdef\foo{...}'':
+\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
+\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
+
+% Check whether we're in the right environment:
+\def\checkenv#1{%
+  \def\temp{#1}%
+  \ifx\thisenv\temp
   \else
-    \unmatchedenderror{#1}%
+    \badenverr
   \fi
 }
 
-% There is an environment #1, but it hasn't been started.  Give an error.
-%
-\def\unmatchedenderror#1{%
+% Evironment mismatch, #1 expected:
+\def\badenverr{%
   \errhelp = \EMsimple
-  \errmessage{This `@end #1' doesn't have a matching `@#1'}%
+  \errmessage{This command can appear only \inenvironment\temp,
+    not \inenvironment\thisenv}%
+}
+\def\inenvironment#1{%
+  \ifx#1\empty
+    out of any environment%
+  \else
+    in environment \expandafter\string#1%
+  \fi
 }
 
-% Define the control sequence \E#1 to give an unmatched @end error.
+% @end foo executes the definition of \Efoo.
+% But first, it executes a specialized version of \checkenv
 %
-\def\defineunmatchedend#1{%
-  \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
+\parseargdef\end{%
+  \if 1\csname iscond.#1\endcsname
+  \else
+    % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03
+    \expandafter\checkenv\csname#1\endcsname
+    \csname E#1\endcsname
+    \endgroup
+  \fi
 }
 
 \newhelp\EMsimple{Press RETURN to continue.}
   !gdef!rbraceatcmd[@}]%
 !endgroup
 
+% @comma{} to avoid , parsing problems.
+\let\comma = ,
+
 % Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
 % Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
 \let\, = \c
 \let\ubaraccent = \b
 \let\udotaccent = \d
 
-% Other special characters: @questiondown @exclamdown
+% Other special characters: @questiondown @exclamdown @ordf @ordm
 % Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
 \def\questiondown{?`}
 \def\exclamdown{!`}
+\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
+\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
 
 % Dotless i and dotless j, used for accents.
 \def\imacro{i}
   \fi\fi
 }
 
+% The \TeX{} logo, as in plain, but resetting the spacing so that a
+% period following counts as ending a sentence.  (Idea found in latex.)
+% 
+\edef\TeX{\TeX \spacefactor=3000 }
+
+% @LaTeX{} logo.  Not quite the same results as the definition in
+% latex.ltx, since we use a different font for the raised A; it's most
+% convenient for us to use an explicitly smaller font, rather than using
+% the \scriptstyle font (since we don't reset \scriptstyle and
+% \scriptscriptstyle).
+% 
+\def\LaTeX{%
+  L\kern-.36em
+  {\setbox0=\hbox{T}%
+   \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}%
+  \kern-.15em
+  \TeX
+}
+
 % Be sure we're in horizontal mode when doing a tie, since we make space
 % equivalent to this in @example-like environments. Otherwise, a space
 % at the beginning of a line will start with \penalty -- and
 \newbox\groupbox
 \def\vfilllimit{0.7}
 %
-\def\group{\begingroup
+\envdef\group{%
   \ifnum\catcode`\^^M=\active \else
     \errhelp = \groupinvalidhelp
     \errmessage{@group invalid in context where filling is enabled}%
   \fi
   \startsavinginserts
   %
-  % The \vtop we start below produces a box with normal height and large
-  % depth; thus, TeX puts \baselineskip glue before it, and (when the
-  % next line of text is done) \lineskip glue after it.  (See p.82 of
-  % the TeXbook.)  Thus, space below is not quite equal to space
-  % above.  But it's pretty close.
-  \def\Egroup{%
-    \egroup           % End the \vtop.
-    % \dimen0 is the vertical size of the group's box.
-    \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
-    % \dimen2 is how much space is left on the page (more or less).
-    \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
-    % if the group doesn't fit on the current page, and it's a big big
-    % group, force a page break.
-    \ifdim \dimen0 > \dimen2
-      \ifdim \pagetotal < \vfilllimit\pageheight
-        \page
-      \fi
-    \fi
-    \box\groupbox
-    \checkinserts
-    \endgroup         % End the \group.
-  }%
-  %
   \setbox\groupbox = \vtop\bgroup
-    % We have to put a strut on the last line in case the @group is in
-    % the midst of an example, rather than completely enclosing it.
-    % Otherwise, the interline space between the last line of the group
-    % and the first line afterwards is too small.  But we can't put the
-    % strut in \Egroup, since there it would be on a line by itself.
-    % Hence this just inserts a strut at the beginning of each line.
-    \everypar = {\strut}%
-    %
-    % Since we have a strut on every line, we don't need any of TeX's
-    % normal interline spacing.
-    \offinterlineskip
-    %
-    % OK, but now we have to do something about blank
-    % lines in the input in @example-like environments, which normally
-    % just turn into \lisppar, which will insert no space now that we've
-    % turned off the interline space.  Simplest is to make them be an
-    % empty paragraph.
-    \ifx\par\lisppar
-      \edef\par{\leavevmode \par}%
-      %
-      % Reset ^^M's definition to new definition of \par.
-      \obeylines
-    \fi
-    %
     % Do @comment since we are called inside an environment such as
     % @example, where each end-of-line in the input causes an
     % end-of-line in the output.  We don't want the end-of-line after
     \comment
 }
 %
+% The \vtop produces a box with normal height and large depth; thus, TeX puts
+% \baselineskip glue before it, and (when the next line of text is done)
+% \lineskip glue after it.  Thus, space below is not quite equal to space
+% above.  But it's pretty close.
+\def\Egroup{%
+    % To get correct interline space between the last line of the group
+    % and the first line afterwards, we have to propagate \prevdepth.
+    \endgraf % Not \par, as it may have been set to \lisppar.
+    \global\dimen1 = \prevdepth
+  \egroup           % End the \vtop.
+  % \dimen0 is the vertical size of the group's box.
+  \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
+  % \dimen2 is how much space is left on the page (more or less).
+  \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
+  % if the group doesn't fit on the current page, and it's a big big
+  % group, force a page break.
+  \ifdim \dimen0 > \dimen2
+    \ifdim \pagetotal < \vfilllimit\pageheight
+      \page
+    \fi
+  \fi
+  \box\groupbox
+  \prevdepth = \dimen1
+  \checkinserts
+}
+%
 % TeX puts in an \escapechar (i.e., `@') at the beginning of the help
 % message, so this ends up printing `@group can only ...'.
 %
@@ -692,7 +731,7 @@ where each line of input produces a line of output.}
 \newdimen\mil  \mil=0.001in
 
 % Old definition--didn't work.
-%\defparsearg\need{\par %
+%\parseargdef\need{\par %
 %% This method tries to make TeX break the page naturally
 %% if the depth of the box does not fit.
 %{\baselineskip=0pt%
@@ -700,7 +739,7 @@ where each line of input produces a line of output.}
 %\prevdepth=-1000pt
 %}}
 
-\defparsearg\need{%
+\parseargdef\need{%
   % Ensure vertical mode, so we don't make a big box in the middle of a
   % paragraph.
   \par
@@ -739,35 +778,10 @@ where each line of input produces a line of output.}
   \fi
 }
 
-% @br   forces paragraph break
+% @br   forces paragraph break (and is undocumented).
 
 \let\br = \par
 
-% @dots{} output an ellipsis using the current font.
-% We do .5em per period so that it has the same spacing in a typewriter
-% font as three actual period characters.
-%
-\def\dots{%
-  \leavevmode
-  \hbox to 1.5em{%
-    \hskip 0pt plus 0.25fil minus 0.25fil
-    .\hss.\hss.%
-    \hskip 0pt plus 0.5fil minus 0.5fil
-  }%
-}
-
-% @enddots{} is an end-of-sentence ellipsis.
-%
-\def\enddots{%
-  \leavevmode
-  \hbox to 2em{%
-    \hskip 0pt plus 0.25fil minus 0.25fil
-    .\hss.\hss.\hss.%
-    \hskip 0pt plus 0.5fil minus 0.5fil
-  }%
-  \spacefactor=3000
-}
-
 % @page forces the start of a new page.
 %
 \def\page{\par\vfill\supereject}
@@ -780,10 +794,10 @@ where each line of input produces a line of output.}
 \newskip\exdentamount
 
 % This defn is used inside fill environments such as @defun.
-\defparsearg\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
+\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
 
 % This defn is used inside nofill environments such as @example.
-\defparsearg\nofillexdent{{\advance \leftskip by -\exdentamount
+\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
   \leftline{\hskip\leftskip{\rm#1}}}}
 
 % @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
@@ -879,19 +893,28 @@ where each line of input produces a line of output.}
 % @center line
 % outputs that line, centered.
 %
-\defparsearg\center{%
-  \ifhmode \hfil\break \fi
+\parseargdef\center{%
+  \ifhmode
+    \let\next\centerH
+  \else
+    \let\next\centerV
+  \fi
+  \next{\hfil \ignorespaces#1\unskip \hfil}%
+}
+\def\centerH#1{%
   {%
+    \hfil\break
     \advance\hsize by -\leftskip
     \advance\hsize by -\rightskip
-    \line{\hfil \ignorespaces#1\unskip \hfil}%
+    \line{#1}%
+    \break
   }%
-  \ifhmode \break \fi
 }
+\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}}
 
 % @sp n   outputs n lines of vertical space
 
-\defparsearg\sp{\vskip #1\baselineskip}
+\parseargdef\sp{\vskip #1\baselineskip}
 
 % @comment ...line which is ignored...
 % @c is the same as @comment
@@ -912,7 +935,7 @@ where each line of input produces a line of output.}
 \def\asisword{asis} % no translation, these are keywords
 \def\noneword{none}
 %
-\defparsearg\paragraphindent{%
+\parseargdef\paragraphindent{%
   \def\temp{#1}%
   \ifx\temp\asisword
   \else
@@ -929,7 +952,7 @@ where each line of input produces a line of output.}
 % We'll use ems for NCHARS like @paragraphindent.
 % It seems @exampleindent asis isn't necessary, but
 % I preserve it to make it similar to @paragraphindent.
-\defparsearg\exampleindent{%
+\parseargdef\exampleindent{%
   \def\temp{#1}%
   \ifx\temp\asisword
   \else
@@ -952,11 +975,9 @@ where each line of input produces a line of output.}
 % By default, we suppress indentation.
 %
 \def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
-\newdimen\currentparindent
-%
 \def\insertword{insert}
 %
-\defparsearg\firstparagraphindent{%
+\parseargdef\firstparagraphindent{%
   \def\temp{#1}%
   \ifx\temp\noneword
     \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
@@ -1028,7 +1049,7 @@ where each line of input produces a line of output.}
   \mathactive
   $\finishmath
 }
-\def\finishmath#1{#1$\Etex}
+\def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
 
 % Some active characters (such as <) are spaced differently in math.
 % We have to reset their definitions in case the @math was an argument
@@ -1051,6 +1072,31 @@ where each line of input produces a line of output.}
 \def\bullet{$\ptexbullet$}
 \def\minus{$-$}
 
+% @dots{} outputs an ellipsis using the current font.
+% We do .5em per period so that it has the same spacing in a typewriter
+% font as three actual period characters.
+%
+\def\dots{%
+  \leavevmode
+  \hbox to 1.5em{%
+    \hskip 0pt plus 0.25fil
+    .\hfil.\hfil.%
+    \hskip 0pt plus 0.5fil
+  }%
+}
+
+% @enddots{} is an end-of-sentence ellipsis.
+%
+\def\enddots{%
+  \dots
+  \spacefactor=3000
+}
+
+% @comma{} is so commas can be inserted into text without messing up
+% Texinfo's parsing.
+% 
+\let\comma = ,
+
 % @refill is a no-op.
 \let\refill=\relax
 
@@ -1065,20 +1111,20 @@ where each line of input produces a line of output.}
 % So open here the files we need to have open while reading the input.
 % This makes it possible to make a .fmt file for texinfo.
 \def\setfilename{%
+   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
    \iflinks
-     \readauxfile
+     \tryauxfile
+     % Open the new aux file.  TeX will close it automatically at exit.
+     \immediate\openout\auxfile=\jobname.aux
    \fi % \openindices needs to do some work in any case.
    \openindices
-   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
-   \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
+   \let\setfilename=\comment % Ignore extra @setfilename cmds.
    %
    % If texinfo.cnf is present on the system, read it.
    % Useful for site-wide @afourpaper, etc.
-   % Just to be on the safe side, close the input stream before the \input.
    \openin 1 texinfo.cnf
-   \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
-   \closein1
-   \temp
+   \ifeof 1 \else \input texinfo.cnf \fi
+   \closein 1
    %
    \comment % Ignore the actual filename.
 }
@@ -1181,22 +1227,32 @@ where each line of input produces a line of output.}
   }
   %
   \def\pdfmakeoutlines{%
-    \openin 1 \jobname.toc
-    \ifeof 1\else\begingroup
-      \closein 1
+    \begingroup
       % Thanh's hack / proper braces in bookmarks
       \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
       \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
       %
       % Read toc silently, to get counts of subentries for \pdfoutline.
-      \def\numchapentry##1##2##3##4{\def\thischapnum{##2}}%
+      \def\numchapentry##1##2##3##4{%
+        \def\thischapnum{##2}%
+        \let\thissecnum\empty
+        \let\thissubsecnum\empty
+      }%
       \def\numsecentry##1##2##3##4{%
+        \advancenumber{chap\thischapnum}%
         \def\thissecnum{##2}%
-        \advancenumber{chap\thischapnum}}%
+        \let\thissubsecnum\empty
+      }%
       \def\numsubsecentry##1##2##3##4{%
+        \advancenumber{sec\thissecnum}%
         \def\thissubsecnum{##2}%
-        \advancenumber{sec\thissecnum}}%
-      \def\numsubsubsecentry##1##2##3##4{\advancenumber{subsec\thissubsecnum}}%
+      }%
+      \def\numsubsubsecentry##1##2##3##4{%
+        \advancenumber{subsec\thissubsecnum}%
+      }%
+      \let\thischapnum\empty
+      \let\thissecnum\empty
+      \let\thissubsecnum\empty
       %
       % use \def rather than \let here because we redefine \chapentry et
       % al. a second time, below.
@@ -1224,11 +1280,19 @@ where each line of input produces a line of output.}
       \def\numsubsubsecentry##1##2##3##4{% count is always zero
         \dopdfoutline{##1}{}{##3}{##4}}%
       %
-      % Make special characters normal for writing to the pdf file.
+      % PDF outlines are displayed using system fonts, instead of
+      % document fonts.  Therefore we cannot use special characters,
+      % since the encoding is unknown.  For example, the eogonek from
+      % Latin 2 (0xea) gets translated to a | character.  Info from
+      % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
+      % 
+      % xx to do this right, we have to translate 8-bit characters to
+      % their "best" equivalent, based on the @documentencoding.  Right
+      % now, I guess we'll just let the pdf reader have its way.
       \indexnofonts
       \turnoffactive
       \input \jobname.toc
-    \endgroup\fi
+    \endgroup
   }
   %
   \def\makelinks #1,{%
@@ -1261,7 +1325,6 @@ where each line of input produces a line of output.}
   \def\ppn#1{\pgn=#1\gobble}
   \def\ppnn{\pgn=\first}
   \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
-  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
     \ifx\PP\D\let\nextsp\relax
     \else\let\nextsp\skipspaces
@@ -1283,14 +1346,13 @@ where each line of input produces a line of output.}
       \leavevmode\Red
       \startlink attr{/Border [0 0 0]}%
         user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
-        % #1
     \endgroup}
   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
   \def\maketoks{%
-    \expandafter\poptoks\the\toksA|ENDTOKS|
+    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
     \ifx\first0\adn0
     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
@@ -1314,16 +1376,34 @@ where each line of input produces a line of output.}
 
 
 \message{fonts,}
-% Font-change commands.
+
+% Change the current font style to #1, remembering it in \curfontstyle.
+% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
+% italics, not bold italics.
+% 
+\def\setfontstyle#1{%
+  \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
+  \csname ten#1\endcsname  % change the current font
+}
+
+% Select #1 fonts with the current style.
+% 
+\def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
+
+\def\rm{\fam=0 \setfontstyle{rm}}
+\def\it{\fam=\itfam \setfontstyle{it}}
+\def\sl{\fam=\slfam \setfontstyle{sl}}
+\def\bf{\fam=\bffam \setfontstyle{bf}}
+\def\tt{\fam=\ttfam \setfontstyle{tt}}
 
 % Texinfo sort of supports the sans serif font style, which plain TeX does not.
-% So we set up a \sf analogous to plain's \rm, etc.
+% So we set up a \sf.
 \newfam\sffam
-\def\sf{\fam=\sffam \tensf}
+\def\sf{\fam=\sffam \setfontstyle{sf}}
 \let\li = \sf % Sometimes we call it \li, not \sf.
 
-% We don't need math for this one.
-\def\ttsl{\tenttsl}
+% We don't need math for this font style.
+\def\ttsl{\setfontstyle{ttsl}}
 
 % Default leading.
 \newdimen\textleading  \textleading = 13.2pt
@@ -1374,6 +1454,7 @@ where each line of input produces a line of output.}
 \def\scshape{csc}
 \def\scbshape{csc}
 
+% Text fonts (11.2pt, magstep1).
 \newcount\mainmagstep
 \ifx\bigger\relax
   % not really supported.
@@ -1424,7 +1505,7 @@ where each line of input produces a line of output.}
 \font\smalleri=cmmi8
 \font\smallersy=cmsy8
 
-% Fonts for title page:
+% Fonts for title page (20.4pt):
 \setfont\titlerm\rmbshape{12}{\magstep3}
 \setfont\titleit\itbshape{10}{\magstep4}
 \setfont\titlesl\slbshape{10}{\magstep4}
@@ -1470,11 +1551,21 @@ where each line of input produces a line of output.}
 \setfont\ssecttsl\ttslshape{10}{1315}
 \setfont\ssecsf\sfbshape{12}{\magstephalf}
 \let\ssecbf\ssecrm
-\setfont\ssecsc\scbshape{10}{\magstep1}
+\setfont\ssecsc\scbshape{10}{1315}
 \font\sseci=cmmi12 scaled \magstephalf
 \font\ssecsy=cmsy10 scaled 1315
-% The smallcaps and symbol fonts should actually be scaled \magstep1.5,
-% but that is not a standard magnification.
+
+% Reduced fonts for @acro in text (10pt).
+\setfont\reducedrm\rmshape{10}{1000}
+\setfont\reducedtt\ttshape{10}{1000}
+\setfont\reducedbf\bfshape{10}{1000}
+\setfont\reducedit\itshape{10}{1000}
+\setfont\reducedsl\slshape{10}{1000}
+\setfont\reducedsf\sfshape{10}{1000}
+\setfont\reducedsc\scshape{10}{1000}
+\setfont\reducedttsl\ttslshape{10}{1000}
+\font\reducedi=cmmi10
+\font\reducedsy=cmsy10
 
 % In order for the font changes to affect most math symbols and letters,
 % we have to define the \textfont of the standard families.  Since
@@ -1489,50 +1580,72 @@ where each line of input produces a line of output.}
 }
 
 % The font-changing commands redefine the meanings of \tenSTYLE, instead
-% of just \STYLE.  We do this so that font changes will continue to work
-% in math mode, where it is the current \fam that is relevant in most
-% cases, not the current font.  Plain TeX does \def\bf{\fam=\bffam
-% \tenbf}, for example.  By redefining \tenbf, we obviate the need to
-% redefine \bf itself.
+% of just \STYLE.  We do this because \STYLE needs to also set the
+% current \fam for math mode.  Our \STYLE (e.g., \rm) commands hardwire
+% \tenSTYLE to set the current font.
+% 
+% Each font-changing command also sets the names \lsize (one size lower)
+% and \lllsize (three sizes lower).  These relative commands are used in
+% the LaTeX logo and acronyms.
+% 
+% This all needs generalizing, badly.
+% 
 \def\textfonts{%
   \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
   \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
-  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
+  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
+  \let\tenttsl=\textttsl
+  \def\lsize{reduced}\def\lllsize{smaller}%
   \resetmathfonts \setleading{\textleading}}
 \def\titlefonts{%
   \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
   \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
   \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
   \let\tenttsl=\titlettsl
+  \def\lsize{chap}\def\lllsize{subsec}%
   \resetmathfonts \setleading{25pt}}
 \def\titlefont#1{{\titlefonts\rm #1}}
 \def\chapfonts{%
   \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
   \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
   \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
+  \def\lsize{sec}\def\lllsize{text}%
   \resetmathfonts \setleading{19pt}}
 \def\secfonts{%
   \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
   \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
-  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
+  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
+  \let\tenttsl=\secttsl
+  \def\lsize{subsec}\def\lllsize{reduced}%
   \resetmathfonts \setleading{16pt}}
 \def\subsecfonts{%
   \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
   \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
-  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
+  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
+  \let\tenttsl=\ssecttsl
+  \def\lsize{text}\def\lllsize{small}%
   \resetmathfonts \setleading{15pt}}
-\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
+\let\subsubsecfonts = \subsecfonts
+\def\reducedfonts{%
+  \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
+  \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
+  \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
+  \let\tenttsl=\reducedttsl
+  \def\lsize{small}\def\lllsize{smaller}%
+  \resetmathfonts \setleading{10.5pt}}
 \def\smallfonts{%
   \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
   \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
   \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
   \let\tenttsl=\smallttsl
+  \def\lsize{smaller}\def\lllsize{smaller}%
   \resetmathfonts \setleading{10.5pt}}
 \def\smallerfonts{%
   \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
   \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
   \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
   \let\tenttsl=\smallerttsl
+  \def\lsize{smaller}\def\lllsize{smaller}%
   \resetmathfonts \setleading{9.5pt}}
 
 % Set the fonts to use with the @small... environments.
@@ -1541,7 +1654,7 @@ where each line of input produces a line of output.}
 % About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
 % can fit this many characters:
 %   8.5x11=86   smallbook=72  a4=90  a5=69
-% If we use \smallerfonts (8pt), then we can fit this many characters:
+% If we use \scriptfonts (8pt), then we can fit this many characters:
 %   8.5x11=90+  smallbook=80  a4=90+  a5=77
 % For me, subjectively, the few extra characters that fit aren't worth
 % the additional smallness of 8pt.  So I'm making the default 9pt.
@@ -1549,14 +1662,13 @@ where each line of input produces a line of output.}
 % By the way, for comparison, here's what fits with @example (10pt):
 %   8.5x11=71  smallbook=60  a4=75  a5=58
 %
-% I wish we used A4 paper on this side of the Atlantic.
-%
+% I wish the USA used A4 paper.
 % --karl, 24jan03.
 
 
 % Set up the default fonts, so we can use them for creating boxes.
 %
-\textfonts
+\textfonts \rm
 
 % Define these so they can be easily changed for other fonts.
 \def\angleleft{$\langle$}
@@ -1619,7 +1731,6 @@ where each line of input produces a line of output.}
   {\tt \rawbackslash \frenchspacing #1}%
   \null
 }
-\let\ttfont=\t
 \def\samp#1{`\tclose{#1}'\null}
 \setfont\keyrm\rmshape{8}{1000}
 \font\keysy=cmsy9
@@ -1660,7 +1771,7 @@ where each line of input produces a line of output.}
   \null
 }
 
-% We *must* turn on hyphenation at `-' and `_' in \code.
+% We *must* turn on hyphenation at `-' and `_' in @code.
 % Otherwise, it is too hard to avoid overfull hboxes
 % in the Emacs manual, the Library manual, etc.
 
@@ -1701,7 +1812,7 @@ where each line of input produces a line of output.}
 % @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
 %   `example' (@kbd uses ttsl only inside of @example and friends),
 %   or `code' (@kbd uses normal tty font always).
-\defparsearg\kbdinputstyle{%
+\parseargdef\kbdinputstyle{%
   \def\arg{#1}%
   \ifx\arg\worddistinct
     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
@@ -1801,20 +1912,26 @@ where each line of input produces a line of output.}
 \def\sc#1{{\smallcaps#1}}       % smallcaps font
 \def\ii#1{{\it #1}}             % italic font
 
-% @acronym downcases the argument and prints in smallcaps.
-% It would be nicer to go one point size down.
-\def\acronym#1{{\smallcaps \lowercase{#1}}}
+\def\acronym#1{\doacronym #1,,\finish}
+\def\doacronym#1,#2,#3\finish{%
+  {\selectfonts\lsize #1}%
+  \def\temp{#2}%
+  \ifx\temp\empty \else
+    \space ({\unsepspaces \ignorespaces \temp \unskip})%
+  \fi
+}
 
-% @pounds{} is a sterling sign.
+% @pounds{} is a sterling sign, which is in the CM italic font.
+% 
 \def\pounds{{\it\$}}
 
-% @registeredsymbol - R in a circle.  For now, only works in text size;
-% we'd have to redo the font mechanism to change the \scriptstyle and
-% \scriptscriptstyle font sizes to make it look right in headings.
+% @registeredsymbol - R in a circle.  The font for the R should really
+% be smaller yet, but lllsize is the best we can do for now.
 % Adapted from the plain.tex definition of \copyright.
 %
 \def\registeredsymbol{%
-  $^{{\ooalign{\hfil\raise.07ex\hbox{$\scriptstyle\rm R$}\hfil\crcr\Orb}}%
+  $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
+               \hfil\crcr\Orb}}%
     }$%
 }
 
@@ -1836,63 +1953,65 @@ where each line of input produces a line of output.}
 \newif\ifsetshortcontentsaftertitlepage
  \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
 
-\defparsearg\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
+\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
         \endgroup\page\hbox{}\page}
 
-\def\titlepage{%
-  \begingroup \parindent=0pt \textfonts
-  % Leave some space at the very top of the page.
-  \vglue\titlepagetopglue
-  % No rule at page bottom unless we print one at the top with @title.
-  \finishedtitlepagetrue
-  %
-  % Most title ``pages'' are actually two pages long, with space
-  % at the top of the second.  We don't want the ragged left on the second.
-  \let\oldpage = \page
-  \def\page{%
-    \iffinishedtitlepage\else
-       \finishtitlepage
-    \fi
-    \let\page = \oldpage
-    \page
-    \null
-  }%
+\envdef\titlepage{%
+  % Open one extra group, as we want to close it in the middle of \Etitlepage.
+  \begingroup
+    \parindent=0pt \textfonts
+    % Leave some space at the very top of the page.
+    \vglue\titlepagetopglue
+    % No rule at page bottom unless we print one at the top with @title.
+    \finishedtitlepagetrue
+    %
+    % Most title ``pages'' are actually two pages long, with space
+    % at the top of the second.  We don't want the ragged left on the second.
+    \let\oldpage = \page
+    \def\page{%
+      \iffinishedtitlepage\else
+         \finishtitlepage
+      \fi
+      \let\page = \oldpage
+      \page
+      \null
+    }%
 }
 
 \def\Etitlepage{%
-   \iffinishedtitlepage\else
-      \finishtitlepage
-   \fi
-   % It is important to do the page break before ending the group,
-   % because the headline and footline are only empty inside the group.
-   % If we use the new definition of \page, we always get a blank page
-   % after the title page, which we certainly don't want.
-   \oldpage
-   \endgroup
-   %
-   % Need this before the \...aftertitlepage checks so that if they are
-   % in effect the toc pages will come out with page numbers.
-   \HEADINGSon
-   %
-   % If they want short, they certainly want long too.
-   \ifsetshortcontentsaftertitlepage
-     \shortcontents
-     \contents
-     \global\let\shortcontents = \relax
-     \global\let\contents = \relax
-   \fi
-   %
-   \ifsetcontentsaftertitlepage
-     \contents
-     \global\let\contents = \relax
-     \global\let\shortcontents = \relax
-   \fi
+    \iffinishedtitlepage\else
+        \finishtitlepage
+    \fi
+    % It is important to do the page break before ending the group,
+    % because the headline and footline are only empty inside the group.
+    % If we use the new definition of \page, we always get a blank page
+    % after the title page, which we certainly don't want.
+    \oldpage
+  \endgroup
+  %
+  % Need this before the \...aftertitlepage checks so that if they are
+  % in effect the toc pages will come out with page numbers.
+  \HEADINGSon
+  %
+  % If they want short, they certainly want long too.
+  \ifsetshortcontentsaftertitlepage
+    \shortcontents
+    \contents
+    \global\let\shortcontents = \relax
+    \global\let\contents = \relax
+  \fi
+  %
+  \ifsetcontentsaftertitlepage
+    \contents
+    \global\let\contents = \relax
+    \global\let\shortcontents = \relax
+  \fi
 }
 
 \def\finishtitlepage{%
-   \vskip4pt \hrule height 2pt width \hsize
-   \vskip\titlepagebottomglue
-   \finishedtitlepagetrue
+  \vskip4pt \hrule height 2pt width \hsize
+  \vskip\titlepagebottomglue
+  \finishedtitlepagetrue
 }
 
 %%% Macros to be used within @titlepage:
@@ -1901,18 +2020,34 @@ where each line of input produces a line of output.}
 \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
 
 \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
-               \let\tt=\authortt}
+                \let\tt=\authortt}
 
-\defparsearg\title{\leftline{\titlefonts\rm #1}
-               % print a rule at the page bottom also.
-               \finishedtitlepagefalse
-               \vskip4pt \hrule height 4pt width \hsize \vskip4pt}
+\parseargdef\title{%
+  \checkenv\titlepage
+  \leftline{\titlefonts\rm #1}
+  % print a rule at the page bottom also.
+  \finishedtitlepagefalse
+  \vskip4pt \hrule height 4pt width \hsize \vskip4pt
+}
 
-\defparsearg\subtitle{{\subtitlefont \rightline{#1}}}
+\parseargdef\subtitle{%
+  \checkenv\titlepage
+  {\subtitlefont \rightline{#1}}%
+}
 
 % @author should come last, but may come many times.
-\defparsearg\author{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
-  {\authorfont \leftline{#1}}}
+% It can also be used inside @quotation.
+% 
+\parseargdef\author{%
+  \def\temp{\quotation}%
+  \ifx\thisenv\temp
+    \def\quotationauthor{#1}% printed in \Equotation.
+  \else
+    \checkenv\titlepage
+    \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
+    {\authorfont \leftline{#1}}%
+  \fi
+}
 
 
 %%% Set up page headings and footings.
@@ -1949,7 +2084,7 @@ where each line of input produces a line of output.}
 \def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
 \global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
 
-\defparsearg\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
+\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
 
 \def\evenfooting{\parsearg\evenfootingxxx}
 \def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
@@ -1967,7 +2102,7 @@ where each line of input produces a line of output.}
   \global\advance\vsize by -\baselineskip
 }
 
-\defparsearg\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
+\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
 
 
 % @headings double      turns headings on for double-sided printing.
@@ -2139,18 +2274,15 @@ where each line of input produces a line of output.}
 \def\itemx{\errmessage{@itemx while not in a list environment}}
 
 % @table, @ftable, @vtable.
-\def\table{%
-  \begingroup\inENV
+\envdef\table{%
   \let\itemindex\gobble
   \tablex
 }
-\def\ftable{%
-  \begingroup\inENV
+\envdef\ftable{%
   \def\itemindex ##1{\doind {fn}{\code{##1}}}%
   \tablex
 }
-\def\vtable{%
-  \begingroup\inENV
+\envdef\vtable{%
   \def\itemindex ##1{\doind {vr}{\code{##1}}}%
   \tablex
 }
@@ -2180,20 +2312,19 @@ where each line of input produces a line of output.}
   \let\item = \internalBitem
   \let\itemx = \internalBitemx
 }
-\def\Etable{\endgraf\afterenvbreak\endgroup}
+\def\Etable{\endgraf\afterenvbreak}
 \let\Eftable\Etable
 \let\Evtable\Etable
+\let\Eitemize\Etable
+\let\Eenumerate\Etable
 
 % This is the counter used by @enumerate, which is really @itemize
 
 \newcount \itemno
 
-\defparsearg\itemize{%
-  \begingroup % ended by the @end itemize
-  \itemizey {#1}{\Eitemize}
-}
+\envdef\itemize{\parsearg\doitemize}
 
-\def\itemizey#1#2{%
+\def\doitemize#1{%
   \aboveenvbreak
   \itemmax=\itemindent
   \advance\itemmax by -\itemmargin
@@ -2202,13 +2333,33 @@ where each line of input produces a line of output.}
   \parindent=0pt
   \parskip=\smallskipamount
   \ifdim\parskip=0pt \parskip=2pt \fi
-  \def#2{\endgraf\afterenvbreak\endgroup}%
   \def\itemcontents{#1}%
   % @itemize with no arg is equivalent to @itemize @bullet.
   \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
   \let\item=\itemizeitem
 }
 
+% Definition of @item while inside @itemize and @enumerate.
+%
+\def\itemizeitem{%
+  \advance\itemno by 1  % for enumerations
+  {\let\par=\endgraf \smallbreak}% reasonable place to break
+  {%
+   % If the document has an @itemize directly after a section title, a
+   % \nobreak will be last on the list, and \sectionheading will have
+   % done a \vskip-\parskip.  In that case, we don't want to zero
+   % parskip, or the item text will crash with the heading.  On the
+   % other hand, when there is normal text preceding the item (as there
+   % usually is), we do want to zero parskip, or there would be too much
+   % space.  In that case, we won't have a \nobreak before.  At least
+   % that's the theory.
+   \ifnum\lastpenalty<10000 \parskip=0in \fi
+   \noindent
+   \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
+   \vadjust{\penalty 1200}}% not good to break after first line of item.
+  \flushcr
+}
+
 % \splitoff TOKENS\endmark defines \first to be the first token in
 % TOKENS, and \rest to be the remainder.
 %
@@ -2218,10 +2369,8 @@ where each line of input produces a line of output.}
 % or number, to specify the first label in the enumerated list.  No
 % argument is the same as `1'.
 %
-\defparsearg\enumerate{\enumeratey #1  \endenumeratey}
+\envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
 \def\enumeratey #1 #2\endenumeratey{%
-  \begingroup % ended by the @end enumerate
-  %
   % If we were given no argument, pretend we were given `1'.
   \def\thearg{#1}%
   \ifx\thearg\empty \def\thearg{1}\fi
@@ -2292,13 +2441,13 @@ where each line of input produces a line of output.}
   }%
 }
 
-% Call itemizey, adding a period to the first argument and supplying the
+% Call \doitemize, adding a period to the first argument and supplying the
 % common last two arguments.  Also subtract one from the initial value in
 % \itemno, since @item increments \itemno.
 %
 \def\startenumeration#1{%
   \advance\itemno by -1
-  \itemizey{#1.}\Eenumerate\flushcr
+  \doitemize{#1.}\flushcr
 }
 
 % @alphaenumerate and @capsenumerate are abbreviations for giving an arg
@@ -2309,16 +2458,6 @@ where each line of input produces a line of output.}
 \def\Ealphaenumerate{\Eenumerate}
 \def\Ecapsenumerate{\Eenumerate}
 
-% Definition of @item while inside @itemize.
-
-\def\itemizeitem{%
-\advance\itemno by 1
-{\let\par=\endgraf \smallbreak}%
-\ifhmode \errmessage{In hmode at itemizeitem}\fi
-{\parskip=0in \hskip 0pt
-\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
-\vadjust{\penalty 1200}}%
-\flushcr}
 
 % @multitable macros
 % Amy Hendrickson, 8/18/94, 3/6/96
@@ -2396,13 +2535,12 @@ where each line of input produces a line of output.}
 \def\xcolumnfractions{\columnfractions}
 \newif\ifsetpercent
 
-% #1 is the part of the @columnfraction before the decimal point, which
-% is presumably either 0 or the empty string (but we don't check, we
-% just throw it away).  #2 is the decimal part, which we use as the
-% percent of \hsize for this column.
-\def\pickupwholefraction#1.#2 {%
+% #1 is the @columnfraction, usually a decimal number like .5, but might
+% be just 1.  We just use it, whatever it is.
+% 
+\def\pickupwholefraction#1 {%
   \global\advance\colcount by 1
-  \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
+  \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
   \setuptable
 }
 
@@ -2436,30 +2574,28 @@ where each line of input produces a line of output.}
 }
 
 % multitable-only commands.
-\def\headitem{\errmessage{@headitem outside of @multitable}}
-\def\tab{\errmessage{@tab outside of @multitable}}
+%
+% @headitem starts a heading row, which we typeset in bold.
+% Assignments have to be global since we are inside the implicit group
+% of an alignment entry.  Note that \everycr resets \everytab.
+\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}%
+%
+% A \tab used to include \hskip1sp.  But then the space in a template
+% line is not enough.  That is bad.  So let's go back to just `&' until
+% we encounter the problem it was intended to solve again.
+%                                       --karl, nathan@acm.org, 20apr99.
+\def\tab{\checkenv\multitable &\the\everytab}%
 
 % @multitable ... @end multitable definitions:
 %
 \newtoks\everytab  % insert after every tab.
 %
-\defparsearg\multitable{\bgroup
+\envdef\multitable{%
   \vskip\parskip
   \startsavinginserts
   %
-  % @headitem starts a heading row, which we typeset in bold.
-  % Assignments have to be global since we are inside the implicit group
-  % of an alignment entry.
-  \def\headitem{\crcrwithinserts \global\everytab={\bf}\the\everytab}%
-  %
-  % @item within a multitable starts a normal row, get rid of any bold.
-  \def\item{\crcrwithinserts \global\everytab={}}%
-  %
-  % A \tab used to include \hskip1sp.  But then the space in a template
-  % line is not enough.  That is bad.  So let's go back to just & until
-  % we encounter the problem it was intended to solve again.  --karl,
-  % nathan@acm.org, 20apr99.
-  \def\tab{&\the\everytab}%
+  % @item within a multitable starts a normal row.
+  \let\item\crcr
   %
   \tolerance=9500
   \hbadness=9500
@@ -2469,72 +2605,80 @@ where each line of input produces a line of output.}
   \overfullrule=0pt
   \global\colcount=0
   %
-  \def\Emultitable{%
-    \global\setpercentfalse
-    \crcrwithinserts
-    \egroup\egroup
+  \everycr = {%
+    \noalign{%
+      \global\everytab={}%
+      \global\colcount=0 % Reset the column counter.
+      % Check for saved footnotes, etc.
+      \checkinserts
+      % Keeps underfull box messages off when table breaks over pages.
+      %\filbreak
+        % Maybe so, but it also creates really weird page breaks when the
+        % table breaks over pages. Wouldn't \vfil be better?  Wait until the
+        % problem manifests itself, so it can be fixed for real --karl.
+    }%
   }%
   %
+  \parsearg\domultitable
+}
+\def\domultitable#1{%
   % To parse everything between @multitable and @item:
   \setuptable#1 \endsetuptable
   %
-  % \everycr will reset column counter, \colcount, at the end of
-  % each line. Every column entry will cause \colcount to advance by one.
-  % The table preamble
-  % looks at the current \colcount to find the correct column width.
-  \everycr{\noalign{%
-  %
-  % \filbreak%% keeps underfull box messages off when table breaks over pages.
-  % Maybe so, but it also creates really weird page breaks when the table
-  % breaks over pages. Wouldn't \vfil be better?  Wait until the problem
-  % manifests itself, so it can be fixed for real --karl.
-    \global\colcount=0\relax}}%
-  %
   % This preamble sets up a generic column definition, which will
   % be used as many times as user calls for columns.
   % \vtop will set a single line and will also let text wrap and
   % continue for many paragraphs if desired.
-  \halign\bgroup&\global\advance\colcount by 1\relax
-    \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
-  %
-  % In order to keep entries from bumping into each other
-  % we will add a \leftskip of \multitablecolspace to all columns after
-  % the first one.
-  %
-  % If a template has been used, we will add \multitablecolspace
-  % to the width of each template entry.
-  %
-  % If the user has set preamble in terms of percent of \hsize we will
-  % use that dimension as the width of the column, and the \leftskip
-  % will keep entries from bumping into each other.  Table will start at
-  % left margin and final column will justify at right margin.
-  %
-  % Make sure we don't inherit \rightskip from the outer environment.
-  \rightskip=0pt
-  \ifnum\colcount=1
-    % The first column will be indented with the surrounding text.
-    \advance\hsize by\leftskip
-  \else
-    \ifsetpercent \else
-      % If user has not set preamble in terms of percent of \hsize
-      % we will advance \hsize by \multitablecolspace.
-      \advance\hsize by \multitablecolspace
-    \fi
-   % In either case we will make \leftskip=\multitablecolspace:
-  \leftskip=\multitablecolspace
-  \fi
-  % Ignoring space at the beginning and end avoids an occasional spurious
-  % blank line, when TeX decides to break the line at the space before the
-  % box from the multistrut, so the strut ends up on a line by itself.
-  % For example:
-  % @multitable @columnfractions .11 .89
-  % @item @code{#}
-  % @tab Legal holiday which is valid in major parts of the whole country.
-  % Is automatically provided with highlighting sequences respectively marking
-  % characters.
-  \noindent\ignorespaces##\unskip\multistrut}\cr
-}
-\def\crcrwithinserts{\crcr\noalign{\checkinserts}}
+  \halign\bgroup &%
+    \global\advance\colcount by 1
+    \multistrut
+    \vtop{%
+      % Use the current \colcount to find the correct column width:
+      \hsize=\expandafter\csname col\the\colcount\endcsname
+      %
+      % In order to keep entries from bumping into each other
+      % we will add a \leftskip of \multitablecolspace to all columns after
+      % the first one.
+      %
+      % If a template has been used, we will add \multitablecolspace
+      % to the width of each template entry.
+      %
+      % If the user has set preamble in terms of percent of \hsize we will
+      % use that dimension as the width of the column, and the \leftskip
+      % will keep entries from bumping into each other.  Table will start at
+      % left margin and final column will justify at right margin.
+      %
+      % Make sure we don't inherit \rightskip from the outer environment.
+      \rightskip=0pt
+      \ifnum\colcount=1
+        % The first column will be indented with the surrounding text.
+        \advance\hsize by\leftskip
+      \else
+        \ifsetpercent \else
+          % If user has not set preamble in terms of percent of \hsize
+          % we will advance \hsize by \multitablecolspace.
+          \advance\hsize by \multitablecolspace
+        \fi
+       % In either case we will make \leftskip=\multitablecolspace:
+      \leftskip=\multitablecolspace
+      \fi
+      % Ignoring space at the beginning and end avoids an occasional spurious
+      % blank line, when TeX decides to break the line at the space before the
+      % box from the multistrut, so the strut ends up on a line by itself.
+      % For example:
+      % @multitable @columnfractions .11 .89
+      % @item @code{#}
+      % @tab Legal holiday which is valid in major parts of the whole country.
+      % Is automatically provided with highlighting sequences respectively
+      % marking characters.
+      \noindent\ignorespaces##\unskip\multistrut
+    }\cr
+}
+\def\Emultitable{%
+  \crcr
+  \egroup % end the \halign
+  \global\setpercentfalse
+}
 
 \def\setmultitablespacing{% test to see if user has set \multitablelinespace.
 % If so, do nothing. If not, give it an appropriate dimension based on
@@ -2565,42 +2709,27 @@ width0pt\relax} \fi
 
 
 \message{conditionals,}
-% Prevent errors for section commands.
-% Used in @ignore and in failing conditionals.
-\def\ignoresections{%
-  \let\appendix=\relax
-  \let\appendixsec=\relax
-  \let\appendixsection=\relax
-  \let\appendixsubsec=\relax
-  \let\appendixsubsection=\relax
-  \let\appendixsubsubsec=\relax
-  \let\appendixsubsubsection=\relax
-  %\let\begin=\relax
-  %\let\bye=\relax
-  \let\centerchap=\relax
-  \let\chapter=\relax
-  \let\contents=\relax
-  \let\section=\relax
-  \let\smallbook=\relax
-  \let\subsec=\relax
-  \let\subsection=\relax
-  \let\subsubsec=\relax
-  \let\subsubsection=\relax
-  \let\titlepage=\relax
-  \let\top=\relax
-  \let\unnumbered=\relax
-  \let\unnumberedsec=\relax
-  \let\unnumberedsection=\relax
-  \let\unnumberedsubsec=\relax
-  \let\unnumberedsubsection=\relax
-  \let\unnumberedsubsubsec=\relax
-  \let\unnumberedsubsubsection=\relax
+
+% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
+% @ifnotxml always succeed.  They currently do nothing; we don't
+% attempt to check whether the conditionals are properly nested.  But we
+% have to remember that they are conditionals, so that @end doesn't
+% attempt to close an environment group.
+%
+\def\makecond#1{%
+  \expandafter\let\csname #1\endcsname = \relax
+  \expandafter\let\csname iscond.#1\endcsname = 1
 }
+\makecond{iftex}
+\makecond{ifnotdocbook}
+\makecond{ifnothtml}
+\makecond{ifnotinfo}
+\makecond{ifnotplaintext}
+\makecond{ifnotxml}
 
 % Ignore @ignore, @ifhtml, @ifinfo, and the like.
 %
 \def\direntry{\doignore{direntry}}
-\def\documentdescriptionword{documentdescription}
 \def\documentdescription{\doignore{documentdescription}}
 \def\docbook{\doignore{docbook}}
 \def\html{\doignore{html}}
@@ -2614,10 +2743,6 @@ width0pt\relax} \fi
 \def\menu{\doignore{menu}}
 \def\xml{\doignore{xml}}
 
-% @dircategory CATEGORY  -- specify a category of the dir file
-% which this file should belong to.  Ignore this in TeX.
-\let\dircategory = \comment
-
 % Ignore text until a line `@end #1', keeping track of nested conditionals.
 %
 % A count to remember the depth of nesting.
@@ -2630,7 +2755,7 @@ width0pt\relax} \fi
   \catcode`\} = \other
   %
   % Make sure that spaces turn into tokens that match what \doignoretext wants.
-  \catcode\spaceChar = 10
+  \spaceisspace
   %
   % Count number of #1's that we've seen.
   \doignorecount = 0
@@ -2661,11 +2786,11 @@ width0pt\relax} \fi
 
 \def\doignoreyyy#1{%
   \def\temp{#1}%
-  \ifx\temp\empty                      % Nothing found.
+  \ifx\temp\empty                       % Nothing found.
     \let\next\doignoretextzzz
-  \else                                        % Found a nested condition, ...
+  \else                                 % Found a nested condition, ...
     \advance\doignorecount by 1
-    \let\next\doignoretextyyy          % ..., look for another.
+    \let\next\doignoretextyyy           % ..., look for another.
     % If we're here, #1 ends with ^^M\ifinfo (for example).
   \fi
   \next #1% the token \_STOP_ is present just after this macro.
@@ -2674,9 +2799,9 @@ width0pt\relax} \fi
 % We have to swallow the remaining "\_STOP_".
 % 
 \def\doignoretextzzz#1{%
-  \ifnum\doignorecount = 0     % We have just found the outermost @end.
+  \ifnum\doignorecount = 0      % We have just found the outermost @end.
     \let\next\enddoignore
-  \else                                % Still inside a nested condition.
+  \else                         % Still inside a nested condition.
     \advance\doignorecount by -1
     \let\next\doignoretext      % Look for the next @end.
   \fi
@@ -2696,23 +2821,30 @@ width0pt\relax} \fi
 % didn't need it.
 % We rely on the fact that \parsearg sets \catcode`\ =10.
 %
-\def\set{\parseargusing{\catcode`\-=\other \catcode`\_=\other}\setxxx}
-\def\setxxx#1{\setyyy#1 \endsetyyy}
+\parseargdef\set{\setyyy#1 \endsetyyy}
 \def\setyyy#1 #2\endsetyyy{%
-  \def\temp{#2}%
-  \edef\next{\gdef\makecsname{SET#1}}%
-  \ifx\temp\empty
-    \next{}%
-  \else
-    \setzzz#2\endsetzzz
-  \fi
+  {%
+    \makevalueexpandable
+    \def\temp{#2}%
+    \edef\next{\gdef\makecsname{SET#1}}%
+    \ifx\temp\empty
+      \next{}%
+    \else
+      \setzzz#2\endsetzzz
+    \fi
+  }%
 }
 % Remove the trailing space \setxxx inserted.
 \def\setzzz#1 \endsetzzz{\next{#1}}
 
 % @clear VAR clears (i.e., unsets) the variable VAR.
 %
-\defparsearg\clear{\global\expandafter\let\csname SET#1\endcsname=\relax}
+\parseargdef\clear{%
+  {%
+    \makevalueexpandable
+    \global\expandafter\let\csname SET#1\endcsname=\relax
+  }%
+}
 
 % @value{foo} gets the text saved in variable foo.
 \def\value{\begingroup\makevalueexpandable\valuexxx}
@@ -2751,53 +2883,36 @@ width0pt\relax} \fi
 % @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
 % with @set.
 %
-\defparsearg\ifset{%
-  \expandafter\ifx\csname SET#1\endcsname\relax
-    \let\next=\ifsetfail
-  \else
-    \let\next=\ifsetsucceed
-  \fi
-  \next
+% To get special treatment of `@end ifset,' call \makeond and the redefine.
+%
+\makecond{ifset}
+\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
+\def\doifset#1#2{%
+  {%
+    \makevalueexpandable
+    \let\next=\empty
+    \expandafter\ifx\csname SET#2\endcsname\relax
+      #1% If not set, redefine \next.
+    \fi
+    \expandafter
+  }\next
 }
-\def\ifsetsucceed{\conditionalsucceed{ifset}}
 \def\ifsetfail{\doignore{ifset}}
-\defineunmatchedend{ifset}
 
 % @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
 % defined with @set, or has been undefined with @clear.
 %
-\defparsearg\ifclear{%
-  \expandafter\ifx\csname SET#1\endcsname\relax
-    \let\next=\ifclearsucceed
-  \else
-    \let\next=\ifclearfail
-  \fi
-  \next
-}
-\def\ifclearsucceed{\conditionalsucceed{ifclear}}
-\def\ifclearfail{\doignore{ifclear}}
-\defineunmatchedend{ifclear}
-
-% @iftex, @ifnothtml, @ifnotinfo, @ifnotplaintext always succeed; we
-% read the text following, through the first @end iftex (etc.).  Make
-% `@end iftex' (etc.) valid only after an @iftex.
+% The `\else' inside the `\doifset' parameter is a trick to reuse the
+% above code: if the variable is not set, do nothing, if it is set,
+% then redefine \next to \ifclearfail.
 %
-\def\iftex{\conditionalsucceed{iftex}}
-\def\ifnothtml{\conditionalsucceed{ifnothtml}}
-\def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
-\def\ifnotplaintext{\conditionalsucceed{ifnotplaintext}}
-\defineunmatchedend{iftex}
-\defineunmatchedend{ifnothtml}
-\defineunmatchedend{ifnotinfo}
-\defineunmatchedend{ifnotplaintext}
+\makecond{ifclear}
+\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
+\def\ifclearfail{\doignore{ifclear}}
 
-% True conditional.  Since \set globally defines its variables, we can
-% just start and end a group (to keep the @end definition undefined at
-% the outer level).
-%
-\def\conditionalsucceed#1{\begingroup
-  \expandafter\def\csname E#1\endcsname{\endgroup}%
-}
+% @dircategory CATEGORY  -- specify a category of the dir file
+% which this file should belong to.  Ignore this in TeX.
+\let\dircategory=\comment
 
 % @defininfoenclose.
 \let\definfoenclose=\comment
@@ -2956,26 +3071,11 @@ width0pt\relax} \fi
   %
   \normalturnoffactive
   %
-  % Control letters and accents.
+  \commondummiesnofonts
+  %
   \definedummyletter{_}%
-  \definedummyletter{,}%
-  \definedummyletter{"}%
-  \definedummyletter{`}%
-  \definedummyletter{'}%
-  \definedummyletter{^}%
-  \definedummyletter{~}%
-  \definedummyletter{=}%
-  \definedummyword{u}%
-  \definedummyword{v}%
-  \definedummyword{H}%
-  \definedummyword{dotaccent}%
-  \definedummyword{ringaccent}%
-  \definedummyword{tieaccent}%
-  \definedummyword{ubaraccent}%
-  \definedummyword{udotaccent}%
-  \definedummyword{dotless}%
-  %
-  % Other non-English letters.
+  %
+  % Non-English letters.
   \definedummyword{AA}%
   \definedummyword{AE}%
   \definedummyword{L}%
@@ -2985,7 +3085,565 @@ width0pt\relax} \fi
   \definedummyword{ae}%
   \definedummyword{l}%
   \definedummyword{oe}%
+  \definedummyword{o}%
+  \definedummyword{ss}%
+  \definedummyword{exclamdown}%
+  \definedummyword{questiondown}%
+  \definedummyword{ordf}%
+  \definedummyword{ordm}%
+  %
+  % Although these internal commands shouldn't show up, sometimes they do.
+  \definedummyword{bf}%
+  \definedummyword{gtr}%
+  \definedummyword{hat}%
+  \definedummyword{less}%
+  \definedummyword{sf}%
+  \definedummyword{sl}%
+  \definedummyword{tclose}%
+  \definedummyword{tt}%
+  %
+  \definedummyword{LaTeX}%
+  \definedummyword{TeX}%
+  %
+  % Assorted special characters.
+  \definedummyword{bullet}%
+  \definedummyword{copyright}%
+  \definedummyword{registeredsymbol}%
+  \definedummyword{dots}%
+  \definedummyword{enddots}%
+  \definedummyword{equiv}%
+  \definedummyword{error}%
+  \definedummyword{expansion}%
+  \definedummyword{minus}%
+  \definedummyword{pounds}%
+  \definedummyword{point}%
+  \definedummyword{print}%
+  \definedummyword{result}%
+  %
+  % Handle some cases of @value -- where it does not contain any
+  % (non-fully-expandable) commands.
+  \makevalueexpandable
+  %
+  % Normal spaces, not active ones.
+  \unsepspaces
+  %
+  % No macro expansion.
+  \turnoffmacros
+}
+
+% \commondummiesnofonts: common to \commondummies and \indexnofonts.
+%
+% Better have this without active chars.
+{
+  \catcode`\~=\other
+  \gdef\commondummiesnofonts{%
+    % Control letters and accents.
+    \definedummyletter{!}%
+    \definedummyletter{"}%
+    \definedummyletter{'}%
+    \definedummyletter{*}%
+    \definedummyletter{,}%
+    \definedummyletter{.}%
+    \definedummyletter{/}%
+    \definedummyletter{:}%
+    \definedummyletter{=}%
+    \definedummyletter{?}%
+    \definedummyletter{^}%
+    \definedummyletter{`}%
+    \definedummyletter{~}%
+    \definedummyword{u}%
+    \definedummyword{v}%
+    \definedummyword{H}%
+    \definedummyword{dotaccent}%
+    \definedummyword{ringaccent}%
+    \definedummyword{tieaccent}%
+    \definedummyword{ubaraccent}%
+    \definedummyword{udotaccent}%
+    \definedummyword{dotless}%
+    %
+    % Texinfo font commands.
+    \definedummyword{b}%
+    \definedummyword{i}%
+    \definedummyword{r}%
+    \definedummyword{sc}%
+    \definedummyword{t}%
+    %
+    % Commands that take arguments.
+    \definedummyword{acronym}%
+    \definedummyword{cite}%
+    \definedummyword{code}%
+    \definedummyword{command}%
+    \definedummyword{dfn}%
+    \definedummyword{emph}%
+    \definedummyword{env}%
+    \definedummyword{file}%
+    \definedummyword{kbd}%
+    \definedummyword{key}%
+    \definedummyword{math}%
+    \definedummyword{option}%
+    \definedummyword{samp}%
+    \definedummyword{strong}%
+    \definedummyword{tie}%
+    \definedummyword{uref}%
+    \definedummyword{url}%
+    \definedummyword{var}%
+    \definedummyword{verb}%
+    \definedummyword{w}%
+  }
+}
+
+% \indexnofonts is used when outputting the strings to sort the index
+% by, and when constructing control sequence names.  It eliminates all
+% control sequences and just writes whatever the best ASCII sort string
+% would be for a given command (usually its argument).
+%
+\def\indexnofonts{%
+  \def\definedummyword##1{%
+    \expandafter\let\csname ##1\endcsname\asis
+  }%
+  \let\definedummyletter=\definedummyword
+  %
+  \commondummiesnofonts
+  %
+  % Don't no-op \tt, since it isn't a user-level command
+  % and is used in the definitions of the active chars like <, >, |, etc.
+  % Likewise with the other plain tex font commands.
+  %\let\tt=\asis
+  %
+  \def\ { }%
+  \def\@{@}%
+  % how to handle braces?
+  \def\_{\normalunderscore}%
+  %
+  % Non-English letters.
+  \def\AA{AA}%
+  \def\AE{AE}%
+  \def\L{L}%
+  \def\OE{OE}%
+  \def\O{O}%
+  \def\aa{aa}%
+  \def\ae{ae}%
+  \def\l{l}%
+  \def\oe{oe}%
+  \def\o{o}%
+  \def\ss{ss}%
+  \def\exclamdown{!}%
+  \def\questiondown{?}%
+  \def\ordf{a}%
+  \def\ordm{o}%
+  %
+  \def\LaTeX{LaTeX}%
+  \def\TeX{TeX}%
+  %
+  % Assorted special characters.
+  % (The following {} will end up in the sort string, but that's ok.)
+  \def\bullet{bullet}%
+  \def\copyright{copyright}%
+  \def\registeredsymbol{R}%
+  \def\dots{...}%
+  \def\enddots{...}%
+  \def\equiv{==}%
+  \def\error{error}%
+  \def\expansion{==>}%
+  \def\minus{-}%
+  \def\pounds{pounds}%
+  \def\point{.}%
+  \def\print{-|}%
+  \def\result{=>}%
+}
+
+\let\indexbackslash=0  %overridden during \printindex.
+\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
+
+% Most index entries go through here, but \dosubind is the general case.
+% #1 is the index name, #2 is the entry text.
+\def\doind#1#2{\dosubind{#1}{#2}{}}
+
+% Workhorse for all \fooindexes.
+% #1 is name of index, #2 is stuff to put there, #3 is subentry --
+% empty if called from \doind, as we usually are (the main exception
+% is with most defuns, which call us directly).
+%
+\def\dosubind#1#2#3{%
+  \iflinks
+  {%
+    % Store the main index entry text (including the third arg).
+    \toks0 = {#2}%
+    % If third arg is present, precede it with a space.
+    \def\thirdarg{#3}%
+    \ifx\thirdarg\empty \else
+      \toks0 = \expandafter{\the\toks0 \space #3}%
+    \fi
+    %
+    \edef\writeto{\csname#1indfile\endcsname}%
+    %
+    \ifvmode
+      \dosubindsanitize
+    \else
+      \dosubindwrite
+    \fi
+  }%
+  \fi
+}
+
+% Write the entry in \toks0 to the index file:
+%
+\def\dosubindwrite{%
+  % Put the index entry in the margin if desired.
+  \ifx\SETmarginindex\relax\else
+    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
+  \fi
+  %
+  % Remember, we are within a group.
+  \indexdummies % Must do this here, since \bf, etc expand at this stage
+  \escapechar=`\\
+  \def\backslashcurfont{\indexbackslash}% \indexbackslash isn't defined now
+      % so it will be output as is; and it will print as backslash.
+  %
+  % Process the index entry with all font commands turned off, to
+  % get the string to sort by.
+  {\indexnofonts
+   \edef\temp{\the\toks0}% need full expansion
+   \xdef\indexsorttmp{\temp}%
+  }%
+  %
+  % Set up the complete index entry, with both the sort key and
+  % the original text, including any font commands.  We write
+  % three arguments to \entry to the .?? file (four in the
+  % subentry case), texindex reduces to two when writing the .??s
+  % sorted result.
+  \edef\temp{%
+    \write\writeto{%
+      \string\entry{\indexsorttmp}{\noexpand\folio}{\the\toks0}}%
+  }%
+  \temp
+}
+
+% Take care of unwanted page breaks:
+%
+% If a skip is the last thing on the list now, preserve it
+% by backing up by \lastskip, doing the \write, then inserting
+% the skip again.  Otherwise, the whatsit generated by the
+% \write will make \lastskip zero.  The result is that sequences
+% like this:
+% @end defun
+% @tindex whatever
+% @defun ...
+% will have extra space inserted, because the \medbreak in the
+% start of the @defun won't see the skip inserted by the @end of
+% the previous defun.
+%
+% But don't do any of this if we're not in vertical mode.  We
+% don't want to do a \vskip and prematurely end a paragraph.
+%
+% Avoid page breaks due to these extra skips, too.
+%
+% But wait, there is a catch there:
+% We'll have to check whether \lastskip is zero skip.  \ifdim is not
+% sufficient for this purpose, as it ignores stretch and shrink parts
+% of the skip.  The only way seems to be to check the textual
+% representation of the skip.
+%
+% The following is almost like \def\zeroskipmacro{0.0pt} except that
+% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
+%
+\edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
+%
+% ..., ready, GO:
+%
+\def\dosubindsanitize{%
+  % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
+  \skip0 = \lastskip
+  \edef\lastskipmacro{\the\lastskip}%
+  \count255 = \lastpenalty
+  %
+  % If \lastskip is nonzero, that means the last item was a
+  % skip.  And since a skip is discardable, that means this
+  % -\skip0 glue we're inserting is preceded by a
+  % non-discardable item, therefore it is not a potential
+  % breakpoint, therefore no \nobreak needed.
+  \ifx\lastskipmacro\zeroskipmacro
+  \else
+    \vskip-\skip0
+  \fi
+  %
+  \dosubindwrite
+  %
+  \ifx\lastskipmacro\zeroskipmacro
+    % if \lastskip was zero, perhaps the last item was a
+    % penalty, and perhaps it was >=10000, e.g., a \nobreak.
+    % In that case, we want to re-insert the penalty; since we
+    % just inserted a non-discardable item, any following glue
+    % (such as a \parskip) would be a breakpoint.  For example:
+    %   @deffn deffn-whatever
+    %   @vindex index-whatever
+    %   Description.
+    % would allow a break between the index-whatever whatsit
+    % and the "Description." paragraph.
+    \ifnum\count255>9999 \nobreak \fi
+  \else
+    % On the other hand, if we had a nonzero \lastskip,
+    % this make-up glue would be preceded by a non-discardable item
+    % (the whatsit from the \write), so we must insert a \nobreak.
+    \nobreak\vskip\skip0
+  \fi
+}
+
+% The index entry written in the file actually looks like
+%  \entry {sortstring}{page}{topic}
+% or
+%  \entry {sortstring}{page}{topic}{subtopic}
+% The texindex program reads in these files and writes files
+% containing these kinds of lines:
+%  \initial {c}
+%     before the first topic whose initial is c
+%  \entry {topic}{pagelist}
+%     for a topic that is used without subtopics
+%  \primary {topic}
+%     for the beginning of a topic that is used with subtopics
+%  \secondary {subtopic}{pagelist}
+%     for each subtopic.
+
+% Define the user-accessible indexing commands
+% @findex, @vindex, @kindex, @cindex.
+
+\def\findex {\fnindex}
+\def\kindex {\kyindex}
+\def\cindex {\cpindex}
+\def\vindex {\vrindex}
+\def\tindex {\tpindex}
+\def\pindex {\pgindex}
+
+\def\cindexsub {\begingroup\obeylines\cindexsub}
+{\obeylines %
+\gdef\cindexsub "#1" #2^^M{\endgroup %
+\dosubind{cp}{#2}{#1}}}
+
+% Define the macros used in formatting output of the sorted index material.
+
+% @printindex causes a particular index (the ??s file) to get printed.
+% It does not print any chapter heading (usually an @unnumbered).
+%
+\parseargdef\printindex{\begingroup
+  \dobreak \chapheadingskip{10000}%
+  %
+  \smallfonts \rm
+  \tolerance = 9500
+  \everypar = {}% don't want the \kern\-parindent from indentation suppression.
+  %
+  % See if the index file exists and is nonempty.
+  % Change catcode of @ here so that if the index file contains
+  % \initial {@}
+  % as its first line, TeX doesn't complain about mismatched braces
+  % (because it thinks @} is a control sequence).
+  \catcode`\@ = 11
+  \openin 1 \jobname.#1s
+  \ifeof 1
+    % \enddoublecolumns gets confused if there is no text in the index,
+    % and it loses the chapter title and the aux file entries for the
+    % index.  The easiest way to prevent this problem is to make sure
+    % there is some text.
+    \putwordIndexNonexistent
+  \else
+    %
+    % If the index file exists but is empty, then \openin leaves \ifeof
+    % false.  We have to make TeX try to read something from the file, so
+    % it can discover if there is anything in it.
+    \read 1 to \temp
+    \ifeof 1
+      \putwordIndexIsEmpty
+    \else
+      % Index files are almost Texinfo source, but we use \ as the escape
+      % character.  It would be better to use @, but that's too big a change
+      % to make right now.
+      \def\indexbackslash{\backslashcurfont}%
+      \catcode`\\ = 0
+      \escapechar = `\\
+      \begindoublecolumns
+      \input \jobname.#1s
+      \enddoublecolumns
+    \fi
+  \fi
+  \closein 1
+\endgroup}
+
+% These macros are used by the sorted index file itself.
+% Change them to control the appearance of the index.
+
+\def\initial#1{{%
+  % Some minor font changes for the special characters.
+  \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
+  %
+  % Remove any glue we may have, we'll be inserting our own.
+  \removelastskip
+  %
+  % We like breaks before the index initials, so insert a bonus.
+  \penalty -300
+  %
+  % Typeset the initial.  Making this add up to a whole number of
+  % baselineskips increases the chance of the dots lining up from column
+  % to column.  It still won't often be perfect, because of the stretch
+  % we need before each entry, but it's better.
+  %
+  % No shrink because it confuses \balancecolumns.
+  \vskip 1.67\baselineskip plus .5\baselineskip
+  \leftline{\secbf #1}%
+  \vskip .33\baselineskip plus .1\baselineskip
+  %
+  % Do our best not to break after the initial.
+  \nobreak
+}}
+
+% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
+% then page number (#2) flushed to the right margin.  It is used for index
+% and table of contents entries.  The paragraph is indented by \leftskip.
+%
+% A straightforward implementation would start like this:
+%       \def\entry#1#2{...
+% But this frozes the catcodes in the argument, and can cause problems to
+% @code, which sets - active.  This problem was fixed by a kludge---
+% ``-'' was active throughout whole index, but this isn't really right.
+% 
+% The right solution is to prevent \entry from swallowing the whole text.
+%                                 --kasal, 21nov03
+\def\entry{%
+  \begingroup
+    %
+    % Start a new paragraph if necessary, so our assignments below can't
+    % affect previous text.
+    \par
+    %
+    % Do not fill out the last line with white space.
+    \parfillskip = 0in
+    %
+    % No extra space above this paragraph.
+    \parskip = 0in
+    %
+    % Do not prefer a separate line ending with a hyphen to fewer lines.
+    \finalhyphendemerits = 0
+    %
+    % \hangindent is only relevant when the entry text and page number
+    % don't both fit on one line.  In that case, bob suggests starting the
+    % dots pretty far over on the line.  Unfortunately, a large
+    % indentation looks wrong when the entry text itself is broken across
+    % lines.  So we use a small indentation and put up with long leaders.
+    %
+    % \hangafter is reset to 1 (which is the value we want) at the start
+    % of each paragraph, so we need not do anything with that.
+    \hangindent = 2em
+    %
+    % When the entry text needs to be broken, just fill out the first line
+    % with blank space.
+    \rightskip = 0pt plus1fil
+    %
+    % A bit of stretch before each entry for the benefit of balancing
+    % columns.
+    \vskip 0pt plus1pt
+    %
+    % Swallow the left brace of the text (first parameter):
+    \afterassignment\doentry
+    \let\temp =
+}
+\def\doentry{%
+    \bgroup % Instead of the swallowed brace.
+      \noindent
+      \aftergroup\finishentry
+      % And now comes the text of the entry.
+}
+\def\finishentry#1{%
+    % #1 is the page number.
+    %
+    % The following is kludged to not output a line of dots in the index if
+    % there are no page numbers.  The next person who breaks this will be
+    % cursed by a Unix daemon.
+    \def\tempa{{\rm }}%
+    \def\tempb{#1}%
+    \edef\tempc{\tempa}%
+    \edef\tempd{\tempb}%
+    \ifx\tempc\tempd
+      \ %
+    \else
+      %
+      % If we must, put the page number on a line of its own, and fill out
+      % this line with blank space.  (The \hfil is overwhelmed with the
+      % fill leaders glue in \indexdotfill if the page number does fit.)
+      \hfil\penalty50
+      \null\nobreak\indexdotfill % Have leaders before the page number.
+      %
+      % The `\ ' here is removed by the implicit \unskip that TeX does as
+      % part of (the primitive) \par.  Without it, a spurious underfull
+      % \hbox ensues.
+      \ifpdf
+        \pdfgettoks#1.%
+        \ \the\toksA
+      \else
+        \ #1%
+      \fi
+    \fi
+    \par
+  \endgroup
+}
+
+% Like \dotfill except takes at least 1 em.
+\def\indexdotfill{\cleaders
+  \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
+
+\def\primary #1{\line{#1\hfil}}
+
+\newskip\secondaryindent \secondaryindent=0.5cm
+\def\secondary#1#2{{%
+  \parfillskip=0in
+  \parskip=0in
+  \hangindent=1in
+  \hangafter=1
+  \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
+  \ifpdf
+    \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
+  \else
+    #2
+  \fi
+  \par
+}}
 
+% Define two-column mode, which we use to typeset indexes.
+% Adapted from the TeXbook, page 416, which is to say,
+% the manmac.tex format used to print the TeXbook itself.
+\catcode`\@=11
+
+\newbox\partialpage
+\newdimen\doublecolumnhsize
+
+\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
+  % Grab any single-column material above us.
+  \output = {%
+    %
+    % Here is a possibility not foreseen in manmac: if we accumulate a
+    % whole lot of material, we might end up calling this \output
+    % routine twice in a row (see the doublecol-lose test, which is
+    % essentially a couple of indexes with @setchapternewpage off).  In
+    % that case we just ship out what is in \partialpage with the normal
+    % output routine.  Generally, \partialpage will be empty when this
+    % runs and this will be a no-op.  See the indexspread.tex test case.
+    \ifvoid\partialpage \else
+      \onepageout{\pagecontents\partialpage}%
+    \fi
+    %
+    \global\setbox\partialpage = \vbox{%
+      % Unvbox the main output page.
+      \unvbox\PAGE
+      \kern-\topskip \kern\baselineskip
+    }%
+  }%
+  \eject % run that output routine to set \partialpage
+  %
+  % Use the double-column output routine for subsequent pages.
+  \output = {\doublecolumnout}%
+  %
+  % Change the page size parameters.  We could do this once outside this
+  % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
+  % format, but then we repeat the same computation.  Repeating a couple
+  % of assignments once per index is clearly meaningless for the
+  % execution time, so we may as well do it in one place.
   %
   % First we halve the line length, less a little for the gutter between
   % the columns.  We compute the gutter based on the line length, so it
@@ -3164,53 +3822,88 @@ width0pt\relax} \fi
 \def\lowersections{\global\advance\secbase by 1}
 \let\down=\lowersections % original BFox name
 
-% Choose a numbered-heading macro
-% #1 is heading level if unmodified by @raisesections or @lowersections
-% #2 is text for heading
-\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
-      \chapterzzz{#2}%
-  \or \seczzz{#2}%
-  \or \numberedsubseczzz{#2}%
-  \or \numberedsubsubseczzz{#2}%
+% we only have subsub.
+\chardef\maxseclevel = 3
+%
+% A numbered section within an unnumbered changes to unnumbered too.
+% To achive this, remember the "biggest" unnum. sec. we are currently in:
+\chardef\unmlevel = \maxseclevel
+%
+% Trace whether the current chapter is an appendix or not:
+% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
+\def\chapheadtype{N}
+
+% Choose a heading macro
+% #1 is heading type
+% #2 is heading level
+% #3 is text for heading
+\def\genhead#1#2#3{%
+  % Compute the abs. sec. level:
+  \absseclevel=#2
+  \advance\absseclevel by \secbase
+  % Make sure \absseclevel doesn't fall outside the range:
+  \ifnum \absseclevel < 0
+    \absseclevel = 0
   \else
-    \ifnum \absseclevel<0 \chapterzzz{#2}%
-    \else \numberedsubsubseczzz{#2}%
+    \ifnum \absseclevel > 3
+      \absseclevel = 3
     \fi
   \fi
-  \suppressfirstparagraphindent
-}
-
-% like \numhead, but chooses appendix heading levels
-\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
-      \appendixzzz{#2}%
-  \or \appendixsectionzzz{#2}%
-  \or \appendixsubseczzz{#2}%
-  \or \appendixsubsubseczzz{#2}%
+  % The heading type:
+  \def\headtype{#1}%
+  \if \headtype U%
+    \ifnum \absseclevel < \unmlevel
+      \chardef\unmlevel = \absseclevel
+    \fi
   \else
-    \ifnum \absseclevel<0 \appendixzzz{#2}%
-    \else \appendixsubsubseczzz{#2}%
+    % Check for appendix sections:
+    \ifnum \absseclevel = 0
+      \edef\chapheadtype{\headtype}%
+    \else
+      \if \headtype A\if \chapheadtype N%
+        \errmessage{@appendix... within a non-appendix chapter}%
+      \fi\fi
+    \fi
+    % Check for numbered within unnumbered:
+    \ifnum \absseclevel > \unmlevel
+      \def\headtype{U}%
+    \else
+      \chardef\unmlevel = 3
     \fi
   \fi
-  \suppressfirstparagraphindent
-}
-
-% like \numhead, but chooses numberless heading levels
-\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-  \ifcase\absseclevel
-      \unnumberedzzz{#2}%
-  \or \unnumberedseczzz{#2}%
-  \or \unnumberedsubseczzz{#2}%
-  \or \unnumberedsubsubseczzz{#2}%
+  % Now print the heading:
+  \if \headtype U%
+    \ifcase\absseclevel
+        \unnumberedzzz{#3}%
+    \or \unnumberedseczzz{#3}%
+    \or \unnumberedsubseczzz{#3}%
+    \or \unnumberedsubsubseczzz{#3}%
+    \fi
   \else
-    \ifnum \absseclevel<0 \unnumberedzzz{#2}%
-    \else \unnumberedsubsubseczzz{#2}%
+    \if \headtype A%
+      \ifcase\absseclevel
+          \appendixzzz{#3}%
+      \or \appendixsectionzzz{#3}%
+      \or \appendixsubseczzz{#3}%
+      \or \appendixsubsubseczzz{#3}%
+      \fi
+    \else
+      \ifcase\absseclevel
+          \chapterzzz{#3}%
+      \or \seczzz{#3}%
+      \or \numberedsubseczzz{#3}%
+      \or \numberedsubsubseczzz{#3}%
+      \fi
     \fi
   \fi
   \suppressfirstparagraphindent
 }
 
+% an interface:
+\def\numhead{\genhead N}
+\def\apphead{\genhead A}
+\def\unnmhead{\genhead U}
+
 % @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
 % all lower-level sectioning counters to zero.
 % 
@@ -3218,7 +3911,7 @@ width0pt\relax} \fi
 % (e.g., figures), q.v.  By default (before any chapter), that is empty.
 \let\chaplevelprefix = \empty
 % 
-\outer\defparsearg\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
+\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
 \def\chapterzzz#1{%
   % section resetting is \global in case the chapter is in a group, such
   % as an @include file.
@@ -3240,7 +3933,7 @@ width0pt\relax} \fi
   \global\let\subsubsection = \numberedsubsubsec
 }
 
-\outer\defparsearg\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
+\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
 \def\appendixzzz#1{%
   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
     \global\advance\appendixno by 1
@@ -3257,15 +3950,12 @@ width0pt\relax} \fi
   \global\let\subsubsection = \appendixsubsubsec
 }
 
-% @centerchap is like @unnumbered, but the heading is centered.
-\outer\defparsearg\centerchap{{\unnumberedyyy{#1}}}
-
-\outer\defparsearg\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
+\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
 \def\unnumberedzzz#1{%
   \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
     \global\advance\unnumberedno by 1
   %
-  % Since an unnumbered as no number, no prefix for figures.
+  % Since an unnumbered has no number, no prefix for figures.
   \global\let\chaplevelprefix = \empty
   \resetallfloatnos
   %
@@ -3290,44 +3980,54 @@ width0pt\relax} \fi
   \global\let\subsubsection = \unnumberedsubsubsec
 }
 
+% @centerchap is like @unnumbered, but the heading is centered.
+\outer\parseargdef\centerchap{%
+  % Well, we could do the following in a group, but that would break
+  % an assumption that \chapmacro is called at the outermost level.
+  % Thus we are safer this way:         --kasal, 24feb04
+  \let\centerparametersmaybe = \centerparameters
+  \unnmhead0{#1}%
+  \let\centerparametersmaybe = \relax
+}
+
 % @top is like @unnumbered.
 \let\top\unnumbered
 
 % Sections.
-\outer\defparsearg\numberedsec{\numhead1{#1}} % normally calls seczzz
+\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
 \def\seczzz#1{%
   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
   \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
 }
 
-\outer\defparsearg\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
+\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
 \def\appendixsectionzzz#1{%
   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
   \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
 }
 \let\appendixsec\appendixsection
 
-\outer\defparsearg\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
+\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
 \def\unnumberedseczzz#1{%
   \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
   \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
 }
 
 % Subsections.
-\outer\defparsearg\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
+\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
 \def\numberedsubseczzz#1{%
   \global\subsubsecno=0  \global\advance\subsecno by 1
   \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
 }
 
-\outer\defparsearg\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
+\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
 \def\appendixsubseczzz#1{%
   \global\subsubsecno=0  \global\advance\subsecno by 1
   \sectionheading{#1}{subsec}{Yappendix}%
                  {\appendixletter.\the\secno.\the\subsecno}%
 }
 
-\outer\defparsearg\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
+\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
 \def\unnumberedsubseczzz#1{%
   \global\subsubsecno=0  \global\advance\subsecno by 1
   \sectionheading{#1}{subsec}{Ynothing}%
@@ -3335,45 +4035,27 @@ width0pt\relax} \fi
 }
 
 % Subsubsections.
-\outer\defparsearg\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
+\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
 \def\numberedsubsubseczzz#1{%
   \global\advance\subsubsecno by 1
   \sectionheading{#1}{subsubsec}{Ynumbered}%
                  {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
 }
 
-\outer\defparsearg\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
+\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
 \def\appendixsubsubseczzz#1{%
   \global\advance\subsubsecno by 1
   \sectionheading{#1}{subsubsec}{Yappendix}%
                  {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
 }
 
-\outer\defparsearg\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
+\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
 \def\unnumberedsubsubseczzz#1{%
   \global\advance\subsubsecno by 1
   \sectionheading{#1}{subsubsec}{Ynothing}%
                  {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
 }
 
-% These are variants which are not "outer", so they can appear in @ifinfo.
-% Actually, they are now be obsolete; ordinary section commands should work.
-\def\infotop{\parsearg\unnumberedzzz}
-\def\infounnumbered{\parsearg\unnumberedzzz}
-\def\infounnumberedsec{\parsearg\unnumberedseczzz}
-\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
-\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
-
-\def\infoappendix{\parsearg\appendixzzz}
-\def\infoappendixsec{\parsearg\appendixseczzz}
-\def\infoappendixsubsec{\parsearg\appendixsubseczzz}
-\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
-
-\def\infochapter{\parsearg\chapterzzz}
-\def\infosection{\parsearg\sectionzzz}
-\def\infosubsection{\parsearg\subsectionzzz}
-\def\infosubsubsection{\parsearg\subsubsectionzzz}
-
 % These macros control what the section commands do, according
 % to what kind of chapter we are in (ordinary, appendix, or unnumbered).
 % Define them by default for a numbered chapter.
@@ -3407,11 +4089,11 @@ width0pt\relax} \fi
 }
 
 % @heading, @subheading, @subsubheading.
-\defparsearg\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
+\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
   \suppressfirstparagraphindent}
-\defparsearg\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
+\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
   \suppressfirstparagraphindent}
-\defparsearg\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
+\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
   \suppressfirstparagraphindent}
 
 % These macros generate a chapter, section, etc. heading only
@@ -3421,8 +4103,6 @@ width0pt\relax} \fi
 %%% Args are the skip and penalty (usually negative)
 \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
 
-\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
-
 %%% Define plain chapter starts, and page on/off switching for it
 % Parameter controlling skip before chapter headings (if needed)
 
@@ -3453,11 +4133,7 @@ width0pt\relax} \fi
 
 \CHAPPAGon
 
-\def\CHAPFplain{%
-\global\let\chapmacro=\chfplain
-\global\let\centerchapmacro=\centerchfplain}
-
-% Normal chapter opening.
+% Chapter opening.
 % 
 % #1 is the text, #2 is the section type (Ynumbered, Ynothing,
 % Yappendix, Yomitfromtoc), #3 the chapter number.
@@ -3467,7 +4143,7 @@ width0pt\relax} \fi
 \def\Yomitfromtockeyword{Yomitfromtoc}
 \def\Yappendixkeyword{Yappendix}
 %
-\def\chfplain#1#2#3{%
+\def\chapmacro#1#2#3{%
   \pchapsepmacro
   {%
     \chapfonts \rm
@@ -3528,40 +4204,35 @@ width0pt\relax} \fi
 
 % @centerchap -- centered and unnumbered.
 \let\centerparametersmaybe = \relax
-\def\centerchfplain#1{{%
-  \def\centerparametersmaybe{%
-    \advance\rightskip by 3\rightskip
-    \leftskip = \rightskip
-    \parfillskip = 0pt
-  }%
-  \chfplain{#1}{Ynothing}{}%
-}}
+\def\centerparameters{%
+  \advance\rightskip by 3\rightskip
+  \leftskip = \rightskip
+  \parfillskip = 0pt
+}
 
-\CHAPFplain % The default
 
 % I don't think this chapter style is supported any more, so I'm not
 % updating it with the new noderef stuff.  We'll see.  --karl, 11aug03.
 % 
+\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
+%
 \def\unnchfopen #1{%
 \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
                        \parindent=0pt\raggedright
                        \rm #1\hfill}}\bigskip \par\nobreak
 }
-
 \def\chfopen #1#2{\chapoddpage {\chapfonts
 \vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
 \par\penalty 5000 %
 }
-
 \def\centerchfopen #1{%
 \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
                        \parindent=0pt
                        \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
 }
-
 \def\CHAPFopen{%
-\global\let\chapmacro=\chfopen
-\global\let\centerchapmacro=\centerchfopen}
+  \global\let\chapmacro=\chfopen
+  \global\let\centerchapmacro=\centerchfopen}
 
 
 % Section titles.  These macros combine the section number parts and
@@ -3706,81 +4377,83 @@ width0pt\relax} \fi
 % Prepare to read what we've written to \tocfile.
 %
 \def\startcontents#1{%
-   % If @setchapternewpage on, and @headings double, the contents should
-   % start on an odd page, unlike chapters.  Thus, we maintain
-   % \contentsalignmacro in parallel with \pagealignmacro.
-   % From: Torbjorn Granlund <tege@matematik.su.se>
-   \contentsalignmacro
-   \immediate\closeout\tocfile
-   %
-   % Don't need to put `Contents' or `Short Contents' in the headline.
-   % It is abundantly clear what they are.
-   \def\thischapter{}%
-   \chapmacro{#1}{Yomitfromtoc}{}%
-   %
-   \savepageno = \pageno
-   \begingroup                  % Set up to handle contents files properly.
-      \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
-      % We can't do this, because then an actual ^ in a section
-      % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
-      %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
-      \raggedbottom             % Worry more about breakpoints than the bottom.
-      \advance\hsize by -\contentsrightmargin % Don't use the full line length.
-      %
-      % Roman numerals for page numbers.
-      \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
+  % If @setchapternewpage on, and @headings double, the contents should
+  % start on an odd page, unlike chapters.  Thus, we maintain
+  % \contentsalignmacro in parallel with \pagealignmacro.
+  % From: Torbjorn Granlund <tege@matematik.su.se>
+  \contentsalignmacro
+  \immediate\closeout\tocfile
+  %
+  % Don't need to put `Contents' or `Short Contents' in the headline.
+  % It is abundantly clear what they are.
+  \def\thischapter{}%
+  \chapmacro{#1}{Yomitfromtoc}{}%
+  %
+  \savepageno = \pageno
+  \begingroup                  % Set up to handle contents files properly.
+    \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
+    % We can't do this, because then an actual ^ in a section
+    % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
+    %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
+    \raggedbottom             % Worry more about breakpoints than the bottom.
+    \advance\hsize by -\contentsrightmargin % Don't use the full line length.
+    %
+    % Roman numerals for page numbers.
+    \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
 }
 
 
 % Normal (long) toc.
 \def\contents{%
-   \startcontents{\putwordTOC}%
-     \openin 1 \jobname.toc
-     \ifeof 1 \else
-       \closein 1
-       \input \jobname.toc
-     \fi
-     \vfill \eject
-     \contentsalignmacro % in case @setchapternewpage odd is in effect
-     \pdfmakeoutlines
-   \endgroup
-   \lastnegativepageno = \pageno
-   \global\pageno = \savepageno
+  \startcontents{\putwordTOC}%
+    \openin 1 \jobname.toc
+    \ifeof 1 \else
+      \input \jobname.toc
+    \fi
+    \vfill \eject
+    \contentsalignmacro % in case @setchapternewpage odd is in effect
+    \ifeof 1 \else
+      \pdfmakeoutlines
+    \fi
+    \closein 1
+  \endgroup
+  \lastnegativepageno = \pageno
+  \global\pageno = \savepageno
 }
 
 % And just the chapters.
 \def\summarycontents{%
-   \startcontents{\putwordShortTOC}%
-      %
-      \let\numchapentry = \shortchapentry
-      \let\appentry = \shortchapentry
-      \let\unnchapentry = \shortunnchapentry
-      % We want a true roman here for the page numbers.
-      \secfonts
-      \let\rm=\shortcontrm \let\bf=\shortcontbf
-      \let\sl=\shortcontsl \let\tt=\shortconttt
-      \rm
-      \hyphenpenalty = 10000
-      \advance\baselineskip by 1pt % Open it up a little.
-      \def\numsecentry##1##2##3##4{}
-      \let\appsecentry = \numsecentry
-      \let\unnsecentry = \numsecentry
-      \let\numsubsecentry = \numsecentry
-      \let\appsubsecentry = \numsecentry
-      \let\unnsubsecentry = \numsecentry
-      \let\numsubsubsecentry = \numsecentry
-      \let\appsubsubsecentry = \numsecentry
-      \let\unnsubsubsecentry = \numsecentry
-      \openin 1 \jobname.toc
-      \ifeof 1 \else
-        \closein 1
-        \input \jobname.toc
-      \fi
-     \vfill \eject
-     \contentsalignmacro % in case @setchapternewpage odd is in effect
-   \endgroup
-   \lastnegativepageno = \pageno
-   \global\pageno = \savepageno
+  \startcontents{\putwordShortTOC}%
+    %
+    \let\numchapentry = \shortchapentry
+    \let\appentry = \shortchapentry
+    \let\unnchapentry = \shortunnchapentry
+    % We want a true roman here for the page numbers.
+    \secfonts
+    \let\rm=\shortcontrm \let\bf=\shortcontbf
+    \let\sl=\shortcontsl \let\tt=\shortconttt
+    \rm
+    \hyphenpenalty = 10000
+    \advance\baselineskip by 1pt % Open it up a little.
+    \def\numsecentry##1##2##3##4{}
+    \let\appsecentry = \numsecentry
+    \let\unnsecentry = \numsecentry
+    \let\numsubsecentry = \numsecentry
+    \let\appsubsecentry = \numsecentry
+    \let\unnsubsecentry = \numsecentry
+    \let\numsubsubsecentry = \numsecentry
+    \let\appsubsubsecentry = \numsecentry
+    \let\unnsubsubsecentry = \numsecentry
+    \openin 1 \jobname.toc
+    \ifeof 1 \else
+      \input \jobname.toc
+    \fi
+    \closein 1
+    \vfill \eject
+    \contentsalignmacro % in case @setchapternewpage odd is in effect
+  \endgroup
+  \lastnegativepageno = \pageno
+  \global\pageno = \savepageno
 }
 \let\shortcontents = \summarycontents
 
@@ -3846,7 +4519,8 @@ width0pt\relax} \fi
 \def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
 
 % This parameter controls the indentation of the various levels.
-\newdimen\tocindent \tocindent = 2pc
+% Same as \defaultparindent.
+\newdimen\tocindent \tocindent = 15pt
 
 % Now for the actual typesetting. In all these, #1 is the text and #2 is the
 % page number.
@@ -3933,7 +4607,7 @@ width0pt\relax} \fi
 % One exception: @ is still an escape character, so that @end tex works.
 % But \@ or @@ will get a plain tex @ character.
 
-\def\tex{\begingroup
+\envdef\tex{%
   \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
   \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
   \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
@@ -3966,10 +4640,11 @@ width0pt\relax} \fi
   \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
   \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
   \def\@{@}%
-\let\Etex=\endgroup}
+}
+% There is no need to define \Etex.
 
 % Define @lisp ... @end lisp.
-% @lisp does a \begingroup so it can rebind things,
+% @lisp environment forms a group so it can rebind things,
 % including the definition of @end lisp (which normally is erroneous).
 
 % Amount to narrow the margins by for @lisp.
@@ -3997,7 +4672,7 @@ width0pt\relax} \fi
       \removelastskip
       % it's not a good place to break if the last penalty was \nobreak
       % or better ...
-      \ifnum\lastpenalty>10000 \else \penalty-50 \fi
+      \ifnum\lastpenalty<10000 \penalty-50 \fi
       \vskip\envskipamount
     \fi
   \fi
@@ -4029,8 +4704,7 @@ width0pt\relax} \fi
 %
 \newskip\lskip\newskip\rskip
 
-\def\cartouche{%
-\begingroup\inENV
+\envdef\cartouche{%
   \ifhmode\par\fi  % can't be in the midst of a paragraph.
   \startsavinginserts
   \lskip=\leftskip \rskip=\rightskip
@@ -4038,9 +4712,9 @@ width0pt\relax} \fi
   \cartinner=\hsize \advance\cartinner by-\lskip
   \advance\cartinner by-\rskip
   \cartouter=\hsize
-  \advance\cartouter by 18.4pt % allow for 3pt kerns on either
-                               % side, and for 6pt waste from
-                               % each corner char, and rule thickness
+  \advance\cartouter by 18.4pt  % allow for 3pt kerns on either
+                                % side, and for 6pt waste from
+                                % each corner char, and rule thickness
   \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
   % Flag to tell @lisp, etc., not to narrow margin.
   \let\nonarrowing=\comment
@@ -4048,28 +4722,27 @@ width0pt\relax} \fi
       \baselineskip=0pt\parskip=0pt\lineskip=0pt
       \carttop
       \hbox\bgroup
-         \hskip\lskip
-         \vrule\kern3pt
-         \vbox\bgroup
-             \kern3pt
-             \hsize=\cartinner
-             \baselineskip=\normbskip
-             \lineskip=\normlskip
-             \parskip=\normpskip
-             \vskip -\parskip
-             \comment % For explanation, see the end of \def\group.
+          \hskip\lskip
+          \vrule\kern3pt
+          \vbox\bgroup
+              \kern3pt
+              \hsize=\cartinner
+              \baselineskip=\normbskip
+              \lineskip=\normlskip
+              \parskip=\normpskip
+              \vskip -\parskip
+              \comment % For explanation, see the end of \def\group.
 }
 \def\Ecartouche{%
               \ifhmode\par\fi
-             \kern3pt
-         \egroup
-         \kern3pt\vrule
-         \hskip\rskip
+              \kern3pt
+          \egroup
+          \kern3pt\vrule
+          \hskip\rskip
       \egroup
       \cartbot
   \egroup
   \checkinserts
-\endgroup
 }
 
 
@@ -4077,7 +4750,6 @@ width0pt\relax} \fi
 % inside a group.
 \def\nonfillstart{%
   \aboveenvbreak
-  \inENV % This group ends at the end of the body
   \hfuzz = 12pt % Don't be fussy
   \sepspaces % Make spaces be word-separators rather than space tokens.
   \let\par = \lisppar % don't ignore blank lines
@@ -4090,103 +4762,99 @@ width0pt\relax} \fi
   \ifx\nonarrowing\relax
     \advance \leftskip by \lispnarrowing
     \exdentamount=\lispnarrowing
-    \let\exdent=\nofillexdent
-    \let\nonarrowing=\relax
   \fi
+  \let\exdent=\nofillexdent
 }
 
-% Define the \E... control sequence only if we are inside the particular
-% environment, so the error checking in \end will work.
+% If you want all examples etc. small: @set dispenvsize small.
+% If you want even small examples the full size: @set dispenvsize nosmall.
+% This affects the following displayed environments:
+%    @example, @display, @format, @lisp
 %
-% To end an @example-like environment, we first end the paragraph (via
-% \afterenvbreak's vertical glue), and then the group.  That way we keep
-% the zero \parskip that the environments set -- \parskip glue will be
-% inserted at the beginning of the next paragraph in the document, after
-% the environment.
-%
-\def\nonfillfinish{\afterenvbreak\endgroup}
+\def\smallword{small}
+\def\nosmallword{nosmall}
+\let\SETdispenvsize\relax
+\def\setnormaldispenv{%
+  \ifx\SETdispenvsize\smallword
+    \smallexamplefonts \rm
+  \fi
+}
+\def\setsmalldispenv{%
+  \ifx\SETdispenvsize\nosmallword
+  \else
+    \smallexamplefonts \rm
+  \fi
+}
 
-% @lisp: indented, narrowed, typewriter font.
-\def\lisp{\begingroup
-  \nonfillstart
-  \let\Elisp = \nonfillfinish
-  \tt
-  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
-  \gobble       % eat return
+% We often define two environments, @foo and @smallfoo.
+% Let's do it by one command:
+\def\makedispenv #1#2{
+  \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}
+  \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}
+  \expandafter\let\csname E#1\endcsname \afterenvbreak
+  \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
 }
 
-% @example: Same as @lisp.
-\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
+% Define two synonyms:
+\def\maketwodispenvs #1#2#3{
+  \makedispenv{#1}{#3}
+  \makedispenv{#2}{#3}
+}
 
+% @lisp: indented, narrowed, typewriter font; @example: same as @lisp.
+%
 % @smallexample and @smalllisp: use smaller fonts.
 % Originally contributed by Pavel@xerox.
-\def\smalllisp{\begingroup
-  \def\Esmalllisp{\nonfillfinish\endgroup}%
-  \def\Esmallexample{\nonfillfinish\endgroup}%
-  \smallexamplefonts
-  \lisp
+%
+\maketwodispenvs {lisp}{example}{%
+  \nonfillstart
+  \tt
+  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
+  \gobble       % eat return
 }
-\let\smallexample = \smalllisp
-
 
-% @display: same as @lisp except keep current font.
+% @display/@smalldisplay: same as @lisp except keep current font.
 %
-\def\display{\begingroup
+\makedispenv {display}{%
   \nonfillstart
-  \let\Edisplay = \nonfillfinish
   \gobble
 }
-%
-% @smalldisplay: @display plus smaller fonts.
-%
-\def\smalldisplay{\begingroup
-  \def\Esmalldisplay{\nonfillfinish\endgroup}%
-  \smallexamplefonts \rm
-  \display
-}
 
-% @format: same as @display except don't narrow margins.
+% @format/@smallformat: same as @display except don't narrow margins.
 %
-\def\format{\begingroup
+\makedispenv{format}{%
   \let\nonarrowing = t%
   \nonfillstart
-  \let\Eformat = \nonfillfinish
   \gobble
 }
-%
-% @smallformat: @format plus smaller fonts.
-%
-\def\smallformat{\begingroup
-  \def\Esmallformat{\nonfillfinish\endgroup}%
-  \smallexamplefonts \rm
-  \format
-}
 
-% @flushleft (same as @format).
-%
-\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
+% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
+\envdef\flushleft{%
+  \let\nonarrowing = t%
+  \nonfillstart
+  \gobble
+}
+\let\Eflushleft = \afterenvbreak
 
 % @flushright.
 %
-\def\flushright{\begingroup
+\envdef\flushright{%
   \let\nonarrowing = t%
   \nonfillstart
-  \let\Eflushright = \nonfillfinish
   \advance\leftskip by 0pt plus 1fill
   \gobble
 }
+\let\Eflushright = \afterenvbreak
 
 
 % @quotation does normal linebreaking (hence we can't use \nonfillstart)
-% and narrows the margins.
+% and narrows the margins.  We keep \parskip nonzero in general, since
+% we're doing normal filling.  So, when using \aboveenvbreak and
+% \afterenvbreak, temporarily make \parskip 0.
 %
-\def\quotation{%
-  \begingroup\inENV %This group ends at the end of the @quotation body
+\envdef\quotation{%
   {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
   \parindent=0pt
-  % We have retained a nonzero parskip for the environment, since we're
-  % doing normal filling. So to avoid extra space below the environment...
-  \def\Equotation{\parskip = 0pt \nonfillfinish}%
   %
   % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
   \ifx\nonarrowing\relax
@@ -4198,6 +4866,18 @@ width0pt\relax} \fi
   \parsearg\quotationlabel
 }
 
+% We have retained a nonzero parskip for the environment, since we're
+% doing normal filling.
+% 
+\def\Equotation{%
+  \par
+  \ifx\quotationauthor\undefined\else
+    % indent a bit.
+    \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
+  \fi
+  {\parskip=0pt \afterenvbreak}%
+}
+
 % If we're given an argument, typeset it in bold with a colon after.
 \def\quotationlabel#1{%
   \def\temp{#1}%
@@ -4325,22 +5005,23 @@ width0pt\relax} \fi
   % without the active space; thus we have to use \xdef and \gobble.
 \endgroup
 %
-\def\verbatim{%
-  \let\Everbatim\nonfillfinish
-  \begingroup
+\envdef\verbatim{%
     \setupverbatim\doverbatim
 }
+\let\Everbatim = \afterenvbreak
+
 
 % @verbatiminclude FILE - insert text of file in verbatim environment.
 %
 \def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
 %
 \def\doverbatiminclude#1{%
-  \begingroup
+  {%
     \makevalueexpandable
     \setupverbatim
     \input #1
-  \nonfillfinish % contains \endgroup
+    \afterenvbreak
+  }%
 }
 
 % @copying ... @end copying.
@@ -4419,11 +5100,8 @@ width0pt\relax} \fi
 \newskip\defargsindent \defargsindent=50pt
 \newskip\deflastargmargin \deflastargmargin=18pt
 
-% \startdefun \deffn
-% -- starts the processing of @deffn
-\def\startdefun#1{%
-  \begingroup\inENV
-  \def\thisenv{#1}%
+% Start the processing of @deffn:
+\def\startdefun{%
   \ifnum\lastpenalty<10000
     \medbreak
   \else
@@ -4446,99 +5124,25 @@ width0pt\relax} \fi
   \exdentamount=\defbodyindent
 }
 
-% \dodefunx \startdefun \deffn
-% -- converts \deffn expansion to \deffnx, omitting \startdefun.
-\def\dodefunx \startdefun #1{%
+\def\dodefunx#1{%
+  % First, check whether we are in the right environment:
+  \checkenv#1%
+  %
   % As above, allow line break if we have multiple x headers in a row.
   % It's not a great place, though.
   \ifnum\lastpenalty=10002 \penalty3000 \fi
   %
-  % Check whether we are inside the corresponding @defun.
-  \def\temp{#1}%
-  \ifx\thisenv\temp
-  \else
-    \errmessage{\expandafter\string\temp x inside
-      \expandafter\noexpand\thisenv environment}%
-  \fi
-}
-
-% Without continued lines we'd just have:
-%   \def\parsedefunline#1{\parseargusing\activeparens{\parsedefunlineX#1}}
-%   \def\parsedefunlineX#1#2{\printdefunline #1#2\DefunTerm}
-% but with continuations, things are much more complicated.
-%
-\def\parsedefunline#1{%
-  \def\defunlinemacro{#1}% store \deffnheader (initially)
-  \parsedefunlineX
-}
-\def\parsedefunlineX{%
-  \parseargusing\activeparens\parsedefunlineY
+  % And now, it's time to reuse the body of the original defun:
+  \expandafter\gobbledefun#1%
 }
-\def\parsedefunlineY#1{%
-  % We have to prepend a token to prevent brace stripping;
-  % \defunlinemacro just comes handy.
-  \defunchkspace\defunlinemacro#1\DefunMid\ \DefunMid\DefunTerm
-}
-\def\defunchkspace#1\ \DefunMid#2\DefunTerm{%
-  \def\temp{#2}%
-  \ifx\temp\empty
-    % The line doesn't end with `@ '; in this case, #1 ends with \DefunMid.
-    \let\next\defunchktab
-  \else
-    % `@ ' was found and stripped.
-    \let\next\defunloop
-  \fi
-  \next#1\^^I\DefunMid\DefunTerm
-}
-\def\defunchktab#1\^^I\DefunMid#2\DefunTerm{%
-  \def\temp{#2}%
-  \ifx\temp\empty
-    % The line doesn't end with `@TAB', either.
-    \let\next\defunchkfinish
-  \else
-    % `@TAB' was found and stripped.
-    \let\next\defunloop
-  \fi
-  \next#1\^^I\DefunMid\DefunTerm
-}
-\def\defunloop#1\^^I\DefunMid\DefunTerm{%
-  % Expand the \defunlinemacro token at the beginning of #1.
-  \expandafter\def\expandafter\defunlinemacro
-    \expandafter{#1 }%
-  \parsedefunlineX
-}
-\def\defunchkfinish#1\DefunMid\^^I%\DefunMid\DefunTerm -- stays here
-{%
-  % #1 starts with \defunlinemacro, which is expanded and its expansion
-  % starts with eg. \deffnheader.
-  \expandafter\replaceeols #1\^^M%\DefunMid\DefunTerm -- stays here
-}
-
-% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
-%
-% The parameters start with \deffnheader token, so trere is no risk braces
-% could be stripped at #1.  And we have a \DefunMid token just before
-% \DefunTerm, so we cannot loose braces at #2 either.  Uff!
-%
-\def\replaceeols#1\^^M#2\DefunTerm{%
-  \stripDefunMid #2%
-  \ifx\temp\empty
-    % This \^^M is the terminating one.
-    \printdefunline #1\DefunTerm
-  \else
-    \replaceeolsX#1\^^M \^^M#2\DefunTerm
-  \fi
-}
-\def\replaceeolsX#1 \^^M{\replaceeolsY#1\^^M}
-\def\replaceeolsY#1\^^M#2\^^M{\replaceeols#1 }
-\def\stripDefunMid#1\DefunMid{\def\temp{#1}}
+\def\gobbledefun#1\startdefun{}
 
-% \printdefunline \deffnheader text\DefunTerm
+% \printdefunline \deffnheader{text}
 %
-\def\printdefunline#1\DefunTerm{%
+\def\printdefunline#1#2{%
   \begingroup
     % call \deffnheader:
-    #1 \endheader
+    #1#2 \endheader
     % common ending:
     \interlinepenalty = 10000
     \advance\rightskip by 0pt plus 1fil
@@ -4551,7 +5155,7 @@ width0pt\relax} \fi
   \endgroup
 }
 
-\def\Edefun{\endgraf\endgroup\medbreak}
+\def\Edefun{\endgraf\medbreak}
 
 % \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
 % the only thing remainnig is to define \deffnheader.
@@ -4569,21 +5173,21 @@ width0pt\relax} \fi
 % \deffnheader has to be defined explicitly.
 %
 \def\domakedefun#1#2#3{%
-  \def#1{%
-    \startdefun#1%
-    \parsedefunline#3%
+  \envdef#1{%
+    \startdefun
+    \parseargusing\activeparens{\printdefunline#3}%
   }%
-  % A tricky way to recycle the code defined above:
-  \def#2{\expandafter\dodefunx#1}%
+  \def#2{\dodefunx#1}%
+  \def#3%
 }
 
-% Untyped functions (@deffn, @defop):
+%%% Untyped functions:
 
-\makedefun{deffn} % category name args
-\def\deffnheader{\deffngeneral{}}
+% @deffn category name args
+\makedefun{deffn}{\deffngeneral{}}
 
-\makedefun{defop} % category class name args
-\def\defopheader#1 {\defopon{#1\ \putwordon}}
+% @deffn category class name args
+\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
 
 % \defopon {category on}class name args
 \def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
@@ -4591,18 +5195,18 @@ width0pt\relax} \fi
 % \deffngeneral {subind}category name args
 %
 \def\deffngeneral#1#2 #3 #4\endheader{%
-  % Remember that \dosubin{fn}{xxx}{} is equivalent to \doind{fn}{xxx}.
+  % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
   \dosubind{fn}{\code{#3}}{#1}%
-  \defname{#2}{}{#3}\ampdefunargs{#4\unskip}%
+  \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
 }
 
-% Typed functions (@deftypefn, @deftypeop):
+%%% Typed functions:
 
-\makedefun{deftypefn} % category type name args
-\def\deftypefnheader{\deftypefngeneral{}}
+% @deftypefn category type name args
+\makedefun{deftypefn}{\deftypefngeneral{}}
 
-\makedefun{deftypeop} % category class type name args
-\def\deftypeopheader#1 {\deftypeopon{#1\ \putwordon}}
+% @deftypeop category class type name args
+\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
 
 % \deftypeopon {category on}class type name args
 \def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
@@ -4611,16 +5215,16 @@ width0pt\relax} \fi
 %
 \def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
   \dosubind{fn}{\code{#4}}{#1}%
-  \defname{#2}{#3}{#4}\normaldefunargs{#5\unskip}%
+  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
 }
 
-% Typed variables (@deftypevr, @deftypecv):
+%%% Typed variables:
 
-\makedefun{deftypevr}% category type var args
-\def\deftypevrheader{\deftypecvgeneral{}}
+% @deftypevr category type var args
+\makedefun{deftypevr}{\deftypecvgeneral{}}
 
-\makedefun{deftypecv}% category class type var args
-\def\deftypecvheader#1 {\deftypecvof{#1\ \putwordof}}
+% @deftypecv category class type var args
+\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
 
 % \deftypecvof {category of}class type var args
 \def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
@@ -4629,38 +5233,39 @@ width0pt\relax} \fi
 %
 \def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
   \dosubind{vr}{\code{#4}}{#1}%
-  \defname{#2}{#3}{#4}\normaldefunargs{#5\unskip}%
+  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
 }
 
-% Untyped variables (@defvr, @defcv):
-\makedefun{defvr}% category var args
-\def\defvrheader#1 {\deftypevrheader{#1} {} }
+%%% Untyped variables:
+
+% @defvr category var args
+\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
 
-\makedefun{defcv}% category class var args
-\def\defcvheader#1 {\defcvof{#1\ \putwordof}}
+% @defcv category class var args
+\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
 
 % \defcvof {category of}class var args
 \def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
 
-% Type (@deftp):
-\makedefun{deftp}% category name args
-\def\deftpheader#1 #2 #3\endheader{%
+%%% Type:
+% @deftp category name args
+\makedefun{deftp}#1 #2 #3\endheader{%
   \doind{tp}{\code{#2}}%
-  \defname{#1}{}{#2}\normaldefunargs{#3\unskip}%
+  \defname{#1}{}{#2}\defunargs{#3\unskip}%
 }
 
 % Remaining @defun-like shortcuts:
-\makedefun{defun}     \def\defunheader{\deffnheader{\putwordDeffunc} }
-\makedefun{defmac}    \def\defmacheader{\deffnheader{\putwordDefmac} }
-\makedefun{defspec}   \def\defspecheader{\deffnheader{\putwordDefspec} }
-\makedefun{deftypefun}\def\deftypefunheader{\deftypefnheader{\putwordDeffunc} }
-\makedefun{defvar}    \def\defvarheader{\defvrheader{\putwordDefvar} }
-\makedefun{defopt}    \def\defoptheader{\defvrheader{\putwordDefopt} }
-\makedefun{deftypevar}\def\deftypevarheader{\deftypevrheader{\putwordDefvar} }
-\makedefun{defmethod} \def\defmethodheader{\defopon\putwordMethodon}
-\makedefun{deftypemethod}\def\deftypemethodheader{\deftypeopon\putwordMethodon}
-\makedefun{defivar}    \def\defivarheader{\defcvof\putwordInstanceVariableof}
-\makedefun{deftypeivar}\def\deftypeivarheader{\deftypecvof\putwordInstanceVariableof}
+\makedefun{defun}{\deffnheader{\putwordDeffunc} }
+\makedefun{defmac}{\deffnheader{\putwordDefmac} }
+\makedefun{defspec}{\deffnheader{\putwordDefspec} }
+\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
+\makedefun{defvar}{\defvrheader{\putwordDefvar} }
+\makedefun{defopt}{\defvrheader{\putwordDefopt} }
+\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
+\makedefun{defmethod}{\defopon\putwordMethodon}
+\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
+\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
+\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
 
 % \defname, which formats the name of the @def (not the args).
 % #1 is the category, such as "Function".
@@ -4720,22 +5325,16 @@ width0pt\relax} \fi
   % arguments will be output next, if any.
 }
 
-% This expands the args, with & being treated magically.
-%
-\def\ampdefunargs{%
-  \magicamp
-  \normaldefunargs
-}
-
-% Print arguments in slanted typewriter, prevent hyphenation at `-' chars.
+% Print arguments in slanted roman (not ttsl), inconsistently with using
+% tt for the name.  This is because literal text is sometimes needed in
+% the argument list (groff manual), and ttsl and tt are not very
+% distinguishable.  Prevent hyphenation at `-' chars.
 % 
-\def\normaldefunargs#1{%
-  % use sl by default (not ttsl), inconsistently with using tt for the
-  % name.  This is because literal text is sometimes needed in the
-  % argument list (groff manual), and ttsl and tt are not very
-  % distinguishable.
+\def\defunargs#1{%
+  % use sl by default (not ttsl), 
   % tt for the names.
   \df \sl \hyphenchar\font=0
+  %
   % On the other hand, if an argument has two dashes (for instance), we
   % want a way to get ttsl.  Let's try @var for that.
   \let\var=\ttslanted
@@ -4834,28 +5433,33 @@ width0pt\relax} \fi
 % To do this right we need a feature of e-TeX, \scantokens,
 % which we arrange to emulate with a temporary file in ordinary TeX.
 \ifx\eTeXversion\undefined
- \newwrite\macscribble
- \def\scanmacro#1{%
-   \begingroup \newlinechar`\^^M
-   % Undo catcode changes of \startcontents and \doprintindex
-   \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
-   % Append \endinput to make sure that TeX does not see the ending newline.
-   \toks0={#1\endinput}%
-   \immediate\openout\macscribble=\jobname.tmp
-   \immediate\write\macscribble{\the\toks0}%
-   \immediate\closeout\macscribble
-   \let\xeatspaces\eatspaces
-   \input \jobname.tmp
-   \endgroup
-}
-\else
-\def\scanmacro#1{%
-\begingroup \newlinechar`\^^M
-% Undo catcode changes of \startcontents and \doprintindex
-\catcode`\@=0 \catcode`\\=\other \escapechar=`\@
-\let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup}
+  \newwrite\macscribble
+  \def\scantokens#1{%
+    \toks0={#1\endinput}%
+    \immediate\openout\macscribble=\jobname.tmp
+    \immediate\write\macscribble{\the\toks0}%
+    \immediate\closeout\macscribble
+    \input \jobname.tmp
+  }
 \fi
 
+\def\scanmacro#1{%
+  \begingroup
+    \newlinechar`\^^M
+    \let\xeatspaces\eatspaces
+    % Undo catcode changes of \startcontents and \doprintindex
+    \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
+    % ... and \example
+    \spaceisspace
+    %
+    % Append \endinput to make sure that TeX does not see the ending newline.
+    %
+    % I've verified that it is necessary both for e-TeX and for ordinary TeX
+    %                                                   --kasal, 29nov03
+    \scantokens{#1\endinput}%
+  \endgroup
+}
+
 \newcount\paramno   % Count of parameters
 \newtoks\macname    % Macro name
 \newif\ifrecursive  % Is it recursive?
@@ -4863,7 +5467,7 @@ width0pt\relax} \fi
                     % \do\macro1\do\macro2...
 
 % Utility routines.
-% Thisdoes \let #1 = #2, except with \csnames.
+% This does \let #1 = #2, except with \csnames.
 \def\cslet#1#2{%
 \expandafter\expandafter
 \expandafter\let
@@ -4960,7 +5564,7 @@ width0pt\relax} \fi
   \else \expandafter\parsemacbody
   \fi}
 
-\defparsearg\unmacro{%
+\parseargdef\unmacro{%
   \if1\csname ismacro.#1\endcsname
     \global\cslet{#1}{macsave.#1}%
     \global\expandafter\let \csname ismacro.#1\endcsname=0%
@@ -5135,7 +5739,7 @@ width0pt\relax} \fi
 
 % @node's only job in TeX is to define \lastnode, which is used in
 % cross-references.
-\defparsearg\node{\ENVcheck\nodexxx #1,\finishnodeparse}
+\parseargdef\node{\checkenv{}\nodexxx #1,\finishnodeparse}
 \def\nodexxx#1,#2\finishnodeparse{\gdef\lastnode{#1}}
 \let\nwnode=\node
 \let\lastnode=\empty
@@ -5154,36 +5758,32 @@ width0pt\relax} \fi
 %
 \newcount\savesfregister
 %
-\gdef\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
-\gdef\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
-\gdef\anchor#1{%
-  \savesf
-  \setref{#1}{Ynothing}%
-  \restoresf
-  \ignorespaces
-}
+\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
+\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
+\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
 
 % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
 % anchor), which consists of three parts:
-% 1) NAME-title - the current sectioning name, taken from \thissection;
-% 2) NAME-snt   - section number and type, defined as the SNT arg;
+% 1) NAME-title - the current sectioning name taken from \thissection,
+%                 or the anchor name.
+% 2) NAME-snt   - section number and type, passed as the SNT arg, or
+%                 empty for anchors.
 % 3) NAME-pg    - the page number.
-% This is called from \donoderef, \anchor, and \dofloat.
 % 
-% We take care not to fully expand the title, since it may contain
-% arbitrary macros.
-%
-% Use \turnoffactive so that punctuation chars such as underscore
-% and backslash work in node names.
-%
+% This is called from \donoderef, \anchor, and \dofloat.  In the case of
+% floats, there is an additional part, which is not written here:
+% 4) NAME-lof   - the text as it should appear in a @listoffloats.
+% 
 \def\setref#1#2{%
   \pdfmkdest{#1}%
   \iflinks
     {%
+      \atdummies  % preserve commands, but don't expand them
       \turnoffactive
+      \otherbackslash
       \edef\writexrdef##1##2{%
-       \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
-         ##1}{##2}}% these are parameters of \writexrdef
+        \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
+          ##1}{##2}}% these are parameters of \writexrdef
       }%
       \toks0 = \expandafter{\thissection}%
       \immediate \writexrdef{title}{\the\toks0 }%
@@ -5231,7 +5831,6 @@ width0pt\relax} \fi
   \fi
   %
   % Make link in pdf output.
-  % 
   \ifpdf
     \leavevmode
     \getfilename{#4}%
@@ -5250,7 +5849,16 @@ width0pt\relax} \fi
   % Float references are printed completely differently: "Figure 1.2"
   % instead of "[somenode], p.3".  We distinguish them by the
   % LABEL-title being set to a magic string.
-  \expandafter\ifx \csname X#1-title\endcsname \floatmagic
+  {%
+    % Have to otherify everything special to allow the \csname to
+    % include an _ in the xref name, etc.
+    \indexnofonts
+    \turnoffactive
+    \otherbackslash
+    \expandafter\global\expandafter\let\expandafter\Xthisreftitle
+      \csname XR#1-title\endcsname
+  }%
+  \iffloat\Xthisreftitle
     % If the user specified the print name (third arg) to the ref,
     % print it instead of our usual "Figure 1.2".
     \ifdim\wd0 = 0pt
@@ -5265,38 +5873,39 @@ width0pt\relax} \fi
       \space \putwordin{} \cite{\printedmanual}%
     \fi
   \else
-  %
-  % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
-  % insert empty discretionaries after hyphens, which means that it will
-  % not find a line break at a hyphen in a node names.  Since some manuals
-  % are best written with fairly long node names, containing hyphens, this
-  % is a loss.  Therefore, we give the text of the node name again, so it
-  % is as if TeX is seeing it for the first time.
-  \ifdim \wd1 > 0pt
-    \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
-  \else
-    % _ (for example) has to be the character _ for the purposes of the
-    % control sequence corresponding to the node, but it has to expand
-    % into the usual \leavevmode...\vrule stuff for purposes of
-    % printing. So we \turnoffactive for the \refx-snt, back on for the
-    % printing, back off for the \refx-pg.
-    {\turnoffactive \otherbackslash
-     % Only output a following space if the -snt ref is nonempty; for
-     % @unnumbered and @anchor, it won't be.
-     \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
-     \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
-    }%
-    % output the `[mynode]' via a macro.
-    \xrefprintnodename\printedrefname
-    %
-    % But we always want a comma and a space:
-    ,\space
-    %
-    % output the `page 3'.
-    \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
+    % node/anchor (non-float) references.
+    % 
+    % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
+    % insert empty discretionaries after hyphens, which means that it will
+    % not find a line break at a hyphen in a node names.  Since some manuals
+    % are best written with fairly long node names, containing hyphens, this
+    % is a loss.  Therefore, we give the text of the node name again, so it
+    % is as if TeX is seeing it for the first time.
+    \ifdim \wd1 > 0pt
+      \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
+    \else
+      % _ (for example) has to be the character _ for the purposes of the
+      % control sequence corresponding to the node, but it has to expand
+      % into the usual \leavevmode...\vrule stuff for purposes of
+      % printing. So we \turnoffactive for the \refx-snt, back on for the
+      % printing, back off for the \refx-pg.
+      {\turnoffactive \otherbackslash
+       % Only output a following space if the -snt ref is nonempty; for
+       % @unnumbered and @anchor, it won't be.
+       \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
+       \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
+      }%
+      % output the `[mynode]' via a macro so it can be overridden.
+      \xrefprintnodename\printedrefname
+      %
+      % But we always want a comma and a space:
+      ,\space
+      %
+      % output the `page 3'.
+      \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
+    \fi
   \fi
   \endlink
-  \fi
 \endgroup}
 
 % This macro is called from \xrefX for the `[nodename]' part of xref
@@ -5342,7 +5951,7 @@ width0pt\relax} \fi
     \indexnofonts
     \otherbackslash
     \expandafter\global\expandafter\let\expandafter\thisrefX
-      \csname X#1\endcsname
+      \csname XR#1\endcsname
   }%
   \ifx\thisrefX\relax
     % If not defined, say something at least.
@@ -5364,13 +5973,44 @@ width0pt\relax} \fi
   #2% Output the suffix in any case.
 }
 
-% This is the macro invoked by entries in the aux file.
+% This is the macro invoked by entries in the aux file.  Usually it's
+% just a \def (we prepend XR to the control sequence name to avoid
+% collisions).  But if this is a float type, we have more work to do.
 %
-\def\xrdef#1{\expandafter\gdef\csname X#1\endcsname}
+\def\xrdef#1#2{%
+  \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value.
+  %
+  % Was that xref control sequence that we just defined for a float?
+  \expandafter\iffloat\csname XR#1\endcsname
+    % it was a float, and we have the (safe) float type in \iffloattype.
+    \expandafter\let\expandafter\floatlist
+      \csname floatlist\iffloattype\endcsname
+    % 
+    % Is this the first time we've seen this float type?
+    \expandafter\ifx\floatlist\relax
+      \toks0 = {\do}% yes, so just \do
+    \else
+      % had it before, so preserve previous elements in list.
+      \toks0 = \expandafter{\floatlist\do}%
+    \fi
+    %
+    % Remember this xref in the control sequence \floatlistFLOATTYPE,
+    % for later use in \listoffloats.
+    \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}%
+  \fi
+}
 
 % Read the last existing aux file, if any.  No error if none exists.
-% Open the new one.
 % 
+\def\tryauxfile{%
+  \openin 1 \jobname.aux
+  \ifeof 1 \else
+    \readauxfile
+    \global\havexrefstrue
+  \fi
+  \closein 1
+}
+
 \def\readauxfile{\begingroup
   \catcode`\^^@=\other
   \catcode`\^^A=\other
@@ -5429,7 +6069,16 @@ width0pt\relax} \fi
   \catcode`\%=\other
   \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
   %
-  % Make the characters 128-255 be printing characters
+  % This is to support \ in node names and titles, since the \
+  % characters end up in a \csname.  It's easier than
+  % leaving it active and making its active definition an actual \
+  % character.  What I don't understand is why it works in the *value*
+  % of the xrdef.  Seems like it should be a catcode12 \, and that
+  % should not typeset properly.  But it works, so I'm moving on for
+  % now.  --karl, 15jan04.
+  \catcode`\\=\other
+  %
+  % Make the characters 128-255 be printing characters.
   {%
     \count 1=128
     \def\loop{%
@@ -5439,28 +6088,12 @@ width0pt\relax} \fi
     }%
   }%
   %
-  % Turn off \ as an escape so we do not lose on
-  % entries which were dumped with control sequences in their names.
-  % For example, @xrdef{$\leq $-fun}{page ...} made by @defun ^^
-  % Reference to such entries still does not work the way one would wish,
-  % but at least they do not bomb out when the aux file is read in.
-  \catcode`\\=\other
-  %
-  % @ is our escape character in .aux files.
+  % @ is our escape character in .aux files, and we need braces.
   \catcode`\{=1
   \catcode`\}=2
   \catcode`\@=0
   %
-  \openin 1 \jobname.aux
-  \ifeof 1 \else
-    \closein 1
-    \input \jobname.aux
-    \global\havexrefstrue
-  \fi
-  % Open the new aux file right away (otherwise the \immediate's in
-  % \setref cause spurious terminal output).  TeX will close it
-  % automatically at exit.
-  \immediate\openout\auxfile=\jobname.aux
+  \input \jobname.aux
 \endgroup}
 
 
@@ -5562,8 +6195,8 @@ width0pt\relax} \fi
   \fi
 }
 
-% This \insert replacements works for both \insert\footins{xx} and
-% \insert\footins\bgroup xx\egroup, but it doesn't work for \insert27{xx}.
+% This \insert replacement works for both \insert\footins{foo} and
+% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
 %
 \def\saveinsert#1{%
   \edef\next{\noexpand\savetobox \makeSAVEname#1}%
@@ -5593,9 +6226,9 @@ width0pt\relax} \fi
   \next
 }
 \def\newsaveinsX #1{%
-  \csname newbox\endcsname #1% \newbox cannot be pronounced, as it is outer
+  \csname newbox\endcsname #1%
   \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
-    \checksaveins#1}%
+    \checksaveins #1}%
 }
 
 % initialize:
@@ -5612,12 +6245,12 @@ width0pt\relax} \fi
 % undone and the next image would fail.
 \openin 1 = epsf.tex
 \ifeof 1 \else
-  \closein 1
   % Do not bother showing banner with epsf.tex v2.7k (available in
   % doc/epsf.tex and on ctan).
   \def\epsfannounce{\toks0 = }%
   \input epsf.tex
 \fi
+\closein 1
 %
 % We will only complain once about lack of epsf.tex.
 \newif\ifwarnednoepsf
@@ -5677,8 +6310,7 @@ width0pt\relax} \fi
 % We don't actually implement floating yet, we just plop the float "here".
 % But it seemed the best name for the future.
 % 
-\def\float{\parsearg\parsefloat}
-\def\parsefloat#1{\dofloat #1,,,\finish}
+\envparseargdef\float{\dofloat #1,,,\finish}
 
 % #1 is the optional FLOATTYPE, the text label for this float, typically
 % "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
@@ -5694,104 +6326,231 @@ width0pt\relax} \fi
 % chapter-level command.
 \let\resetallfloatnos=\empty
 %
-\def\dofloat#1,#2,#3,#4\finish{\vtop\bgroup
-  \def\floattype{#1}%
-  \def\floatlabel{#2}%
-  \def\floatloc{#3}% we do nothing with this yet.
-  % xx should we indent the whole thing? center it?
-  % 
-  % allow @[short]caption now.
+\def\dofloat#1,#2,#3,#4\finish{%
   \let\thiscaption=\empty
-  \def\caption##1{\def\thiscaption{##1}}%
-  %
   \let\thisshortcaption=\empty
-  \def\shortcaption##1{\def\thisshortcaption{##1}}%
-  %
-  \ifx\floattype\empty \else
-    % For now, assume the FLOATTYPE is entirely letters, so we just use it
-    % in a control sequence name literally.  We want each FLOATTYPE to be
-    % numbered separately (Figure 1, Table 1, Figure 2, ...).
-    \expandafter\let\expandafter\floatno\csname\floattype floatno\endcsname
-    \ifx\floatno\relax
-      % Haven't seen this figure type before, so need to define
-      % the counter for it, and then redefine \floatno.
-      \expandafter\innernewcount\csname\floattype floatno\endcsname
-      \expandafter\let\expandafter\floatno\csname\floattype floatno\endcsname
-      %
-      % Remember to reset this floatno at the next chap.
-      \toks0 = \expandafter{\resetallfloatnos}%
-      \xdef\resetallfloatnos{\the\toks0 \makecsname{\floattype floatno}=0 }%
+  %
+  % don't lose footnotes inside @float.
+  \startsavinginserts
+  %
+  % We can't be used inside a paragraph.
+  \par
+  %
+  \vtop\bgroup
+    \def\floattype{#1}%
+    \def\floatlabel{#2}%
+    \def\floatloc{#3}% we do nothing with this yet.
+    %
+    \ifx\floattype\empty
+      \let\safefloattype=\empty
+    \else
+      {%
+        % the floattype might have accents or other special characters,
+        % but we need to use it in a control sequence name.
+        \indexnofonts
+        \turnoffactive
+        \xdef\safefloattype{\floattype}%
+      }%
     \fi
-    \global\advance\floatno by 1
     %
+    % If label is given but no type, we handle that as the empty type.
     \ifx\floatlabel\empty \else
+      % We want each FLOATTYPE to be numbered separately (Figure 1,
+      % Table 1, Figure 2, ...).  (And if no label, no number.)
+      % 
+      \expandafter\getfloatno\csname\safefloattype floatno\endcsname
+      \global\advance\floatno by 1
+      %
       {%
         % This magic value for \thissection is output by \setref as the
         % XREFLABEL-title value.  \xrefX uses it to distinguish float
         % labels (which have a completely different output format) from
-        % nodes and xref labels.
+        % node and anchor labels.  And \xrdef uses it to construct the
+        % lists of floats.
         % 
-        \let\thissection=\floatmagic
+        \edef\thissection{\floatmagic=\safefloattype}%
         \setref{\floatlabel}{Yfloat}%
       }%
     \fi
-  \fi
-  %
-  \def\Efloat{%
-    % we have four possibilities:
-    % @float Foo & @caption{Cap}: Foo 1.1: Cap
-    % @float Foo & no caption:    Foo 1.1
-    % @float & @caption{cap}:     Cap
-    % @float & no caption:
     %
-    \let\printedsomething = \empty
+    % start with \parskip glue, I guess.
+    \vskip\parskip
     %
-    \ifx\floattype\empty \else
-      \vskip.5\parskip  % space above caption
-      %
-      % Print the float number preceded by the chapter-level number
-      % (empty in the case of unnumbered).  Although there are other
-      % styles of float numbering, we hardwire this one.
-      \floattype\space\chaplevelprefix\the\floatno
-      \let\printedsomething = t%
+    % Don't suppress indentation if a float happens to start a section.
+    \restorefirstparagraphindent
+}
+
+% we have these possibilities:
+% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
+% @float Foo,lbl & no caption:    Foo 1.1
+% @float Foo & @caption{Cap}:     Foo: Cap
+% @float Foo & no caption:        Foo
+% @float ,lbl & Caption{Cap}:     1.1: Cap
+% @float ,lbl & no caption:       1.1
+% @float & @caption{Cap}:         Cap
+% @float & no caption:
+%
+\def\Efloat{%
+    \let\floatident = \empty
+    %
+    % In all cases, if we have a float type, it comes first.
+    \ifx\floattype\empty \else \def\floatident{\floattype}\fi
+    %
+    % If we have an xref label, the number comes next.
+    \ifx\floatlabel\empty \else
+      \ifx\floattype\empty \else % if also had float type, need tie first.
+        \appendtomacro\floatident{\tie}%
+      \fi
+      % the number.
+      \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
     \fi
     %
+    % Start the printed caption with what we've constructed in
+    % \floatident, but keep it separate; we need \floatident again.
+    \let\captionline = \floatident
+    %
     \ifx\thiscaption\empty \else
-      \ifx\printedsomething\empty
-        \vskip.5\parskip  % space above caption
-      \else
-        :\space  % had a number, so print a colon.
+      \ifx\floatident\empty \else
+        \appendtomacro\captionline{: }% had ident, so need a colon between
       \fi
       %
-      % Print caption text.
-      \thiscaption
-      \let\printedsomething = t%
+      % caption text.
+      \appendtomacro\captionline\thiscaption
+    \fi
+    %
+    % If we have anything to print, print it, with space before.
+    % Eventually this needs to become an \insert.
+    \ifx\captionline\empty \else
+      \vskip.5\parskip
+      \captionline
+    \fi
+    %
+    % If have an xref label, write the list of floats info.  Do this
+    % after the caption, to avoid chance of it being a breakpoint.
+    \ifx\floatlabel\empty \else
+      % Write the text that goes in the lof to the aux file as
+      % \floatlabel-lof.  Besides \floatident, we include the short
+      % caption if specified, else the full caption if specified, else nothing.
+      {%
+        \atdummies \turnoffactive \otherbackslash
+        \immediate\write\auxfile{@xrdef{\floatlabel-lof}{%
+          \floatident
+          \ifx\thisshortcaption\empty
+            \ifx\thiscaption\empty \else : \thiscaption \fi
+          \else
+            : \thisshortcaption
+          \fi
+        }}%
+      }%
     \fi
     %
     % Space below caption, if we printed anything.
     \ifx\printedsomething\empty \else \vskip\parskip \fi
-    %
-    \egroup  % end of \vtop
-  }%
+  \egroup  % end of \vtop
+  \checkinserts
+}
+
+% Append the tokens #2 to the definition of macro #1, not expanding either.
+% 
+\newtoks\appendtomacroAtoks
+\newtoks\appendtomacroBtoks
+\def\appendtomacro#1#2{%
+  \appendtomacroAtoks = \expandafter{#1}%
+  \appendtomacroBtoks = {#2}%
+  \edef#1{\the\appendtomacroAtoks \the\appendtomacroBtoks}%
+}
+
+% @caption, @shortcaption are easy.
+% 
+\long\def\caption#1{\checkenv\float \def\thiscaption{#1}}
+\def\shortcaption#1{\checkenv\float \def\thisshortcaption{#1}}
+
+% The parameter is the control sequence identifying the counter we are
+% going to use.  Create it if it doesn't exist and assign it to \floatno.
+\def\getfloatno#1{%
+  \ifx#1\relax
+      % Haven't seen this figure type before.
+      \csname newcount\endcsname #1%
+      %
+      % Remember to reset this floatno at the next chap.
+      \expandafter\gdef\expandafter\resetallfloatnos
+        \expandafter{\resetallfloatnos #1=0 }%
+  \fi
+  \let\floatno#1%
 }
 
 % \setref calls this to get the XREFLABEL-snt value.  We want an @xref
 % to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
 % first read the @float command.
 % 
-\def\Yfloat{\floattype @tie{}\chaplevelprefix\the\floatno}%
+\def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
 
+% Magic string used for the XREFLABEL-title value, so \xrefX can
+% distinguish floats from other xref types.
 \def\floatmagic{!!float!!}
 
-% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
-\def\listoffloats{\parsearg\dolistoffloats}
-\def\dolistoffloats#1{%xx
+% #1 is the control sequence we are passed; we expand into a conditional
+% which is true if #1 represents a float ref.  That is, the magic
+% \thissection value which we \setref above.
+% 
+\def\iffloat#1{\expandafter\doiffloat#1==\finish}
+%
+% #1 is (maybe) the \floatmagic string.  If so, #2 will be the
+% (safe) float type for this float.  We set \iffloattype to #2.
+% 
+\def\doiffloat#1=#2=#3\finish{%
+  \def\temp{#1}%
+  \def\iffloattype{#2}%
+  \ifx\temp\floatmagic
 }
 
-% Default definitions.
-\def\caption{\errmessage{@caption while not in @float environment}}
-\def\shortcaption{\errmessage{@shortcaption while not in @float environment}}
+% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
+% 
+\parseargdef\listoffloats{%
+  \def\floattype{#1}% floattype
+  {%
+    % the floattype might have accents or other special characters,
+    % but we need to use it in a control sequence name.
+    \indexnofonts
+    \turnoffactive
+    \xdef\safefloattype{\floattype}%
+  }%
+  %
+  % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
+  \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
+    \ifhavexrefs
+      % if the user said @listoffloats foo but never @float foo.
+      \message{\linenumber No `\safefloattype' floats to list.}%
+    \fi
+  \else
+    \begingroup
+      \leftskip=\tocindent  % indent these entries like a toc
+      \let\do=\listoffloatsdo
+      \csname floatlist\safefloattype\endcsname
+    \endgroup
+  \fi
+}
 
+% This is called on each entry in a list of floats.  We're passed the
+% xref label, in the form LABEL-title, which is how we save it in the
+% aux file.  We strip off the -title and look up \XRLABEL-lof, which
+% has the text we're supposed to typeset here.
+% 
+% Figures without xref labels will not be included in the list (since
+% they won't appear in the aux file).
+% 
+\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
+\def\listoffloatsdoentry#1-title\finish{{%
+  % Can't fully expand XR#1-lof because it can contain anything.  Just
+  % pass the control sequence.  On the other hand, XR#1-pg is just the
+  % page number, and we want to fully expand that so we can get a link
+  % in pdf output.
+  \toksA = \expandafter{\csname XR#1-lof\endcsname}%
+  %
+  % use the same \entry macro we use to generate the TOC and index.
+  \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
+  \writeentry
+}}
 
 \message{localization,}
 % and i18n.
@@ -5801,18 +6560,17 @@ width0pt\relax} \fi
 % properly.  Single argument is the language abbreviation.
 % It would be nice if we could set up a hyphenation file here.
 %
-\defparsearg\documentlanguage{%
+\parseargdef\documentlanguage{%
   \tex % read txi-??.tex file in plain TeX.
-  % Read the file if it exists.
-  \openin 1 txi-#1.tex
-  \ifeof1
-    \errhelp = \nolanghelp
-    \errmessage{Cannot read language file txi-#1.tex}%
-    \let\temp = \relax
-  \else
-    \def\temp{\input txi-#1.tex }%
-  \fi
-  \temp
+    % Read the file if it exists.
+    \openin 1 txi-#1.tex
+    \ifeof 1
+      \errhelp = \nolanghelp
+      \errmessage{Cannot read language file txi-#1.tex}%
+    \else
+      \input txi-#1.tex
+    \fi
+    \closein 1
   \endgroup
 }
 \newhelp\nolanghelp{The given language definition file cannot be found or
@@ -5995,7 +6753,7 @@ should work if nowhere else does.}
 % Perhaps we should allow setting the margins, \topskip, \parskip,
 % and/or leading, also. Or perhaps we should compute them somehow.
 %
-\defparsearg\pagesizes{\pagesizesyyy #1,,\finish}
+\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
 \def\pagesizesyyy#1,#2,#3\finish{{%
   \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
   \globaldefs = 1
@@ -6042,8 +6800,8 @@ should work if nowhere else does.}
 \def\normalplus{+}
 \def\normaldollar{$}%$ font-lock fix
 
-% This macro is used to make a character print one way in ttfont
-% where it can probably just be output, and another way in other fonts,
+% This macro is used to make a character print one way in \tt
+% (where it can probably be output as-is), and another way in other fonts,
 % where something hairier probably needs to be done.
 %
 % #1 is what to print if we are indeed using \tt; #2 is what to print
@@ -6099,15 +6857,16 @@ should work if nowhere else does.}
 
 \catcode`\@=0
 
-% \rawbackslashxx outputs one backslash character in current font,
+% \backslashcurfont outputs one backslash character in current font,
 % as in \char`\\.
-\global\chardef\rawbackslashxx=`\\
+\global\chardef\backslashcurfont=`\\
+\global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
 
-% \rawbackslash defines an active \ to do \rawbackslashxx.
+% \rawbackslash defines an active \ to do \backslashcurfont.
 % \otherbackslash defines an active \ to be a literal `\' character with
 % catcode other.
 {\catcode`\\=\active
- @gdef@rawbackslash{@let\=@rawbackslashxx}
+ @gdef@rawbackslash{@let\=@backslashcurfont}
  @gdef@otherbackslash{@let\=@realbackslash}
 }
 
@@ -6115,7 +6874,7 @@ should work if nowhere else does.}
 {\catcode`\\=\other @gdef@realbackslash{\}}
 
 % \normalbackslash outputs one backslash in fixed width font.
-\def\normalbackslash{{\tt\rawbackslashxx}}
+\def\normalbackslash{{\tt\backslashcurfont}}
 
 \catcode`\\=\active
 
@@ -6172,10 +6931,6 @@ should work if nowhere else does.}
 @catcode`@# = @other
 @catcode`@% = @other
 
-@c Set initial fonts.
-@textfonts
-@rm
-
 
 @c Local variables:
 @c eval: (add-hook 'write-file-hooks 'time-stamp)