\part Preliminaries\endpart

\chapter Introduction\label{INTRO}\endchapter


This manual is intended for 
 \tex\ wizards  pondering the
 intricacies of various \lamstex\
constructions, as well as for 
\tex nicians designing style files for \lamstex\ who need 
more detailed information than that provided by the \lamstex~Style File
Designers Manual.
Although certain points about \tex\ receive detailed explanation,
many sections presuppose
 considerable \tex pertise, which it would be impractical
to try to provide within the scope of this already lengthy manual.


Despite  the manual's lengthiness,
the division into
 chapters and sections allows specialized constructions used for
one part of \lamstex\ to be separated from those used in other parts. 
Of course, the various chapters are not completely independent,
and
 Part~I
 should probably be perused by everyone.



\section{\amstex\ Conventions\label{K}} We will not be analyzing
the file *amstex.tex* itself, since
a detailed description
of \amstex\ is given in the file *amstex.doc*.
Nevertheless, certain \amstex\
 conventions must be mentioned here, 
because they are used throughout 
*lamstex.tex*.

First of all, \amstex\ uses the ``scratch'' tokens *\next*, *\next@*, 
*\nextii@*, *\nextiii@*, \dots. In order to keep the number down, many
definitions will, for example, define *\nextiv@* back in terms of
*\next@*, *\nextii@*, etc.

The *amstex.doc* file mentions the peculiar contortions that are used to
avoid difficulties that might arise when a definition has a clause
like
**
\def\next@{ ... \next ... }
**
since
a previous *\futurelet\next* may have let *\next* be something that is
*\outer*.  

In \lamstex@, on the other hand, it is simply quite out of the question
to allow anything to be *\outer*.  Something like *\claim* can't be
outer, for example, because then things like *\newpre\claim* wouldn't work.
But even something like *\bye* can't be *\outer* because it might easily
occur right after a  point where \lamstex\ has to subject the next
token to some sort of test (see the small print notes
on  pages~\ref{BADOUTER} and ~\ref{BADOUTER2}).
Consequently, although we will continue to reserve *\next* as the token
of choice in all *\futurelet* constructions,
 we will finesse this whole problem by
 making sure that  {\it nothing\/} in \lamstex\ is *\outer*.

The only *\outer* things in *plain* \tex\ are 
the {\ninerm ASCII} form-feed~ *^^L*, the
*\new...* constructions (*\newcount*, *\newdimen*, \dots\,),
  the 
*\+* from the *\settabs* construction, the *\beginsection* and
*\proclaim* constructions, and *\bye*.  
\lamstex\ redefines *^^L*, the *\new...* constructions, 
  *\+*, and *\bye* so that they are not 
 *\outer*,  and it makes
 *\beginsection*
be undefined (\lamstex\ has 
its own system of ``heading levels''), while \amstex\ has already made
*\proclaim* be undefined (until a style file is read in).

It should be mentioned that
although we no longer have to worry about *\next* being  *\outer*,
some precautions are still in order---see page~\ref{NEWPRECAUTION}.

\medskip
Another \amstex\ convention involves constructions like
**
\if...\def\next@{\csa}\else\def\next@{\csb}\fi\next@
**
(It is assumed that the user of this manual understands why this is
required instead of simply *\if...\csa\else\csb\fi* whenever *\csa* or
*\csb* has an argument.) 

In TUG{\ninerm BOAT},
 Volume~8, No.~2,  Kabelschacht\pagelabel{KABEL}
points out that this can be replaced by
**
\if...\expandafter\csa\else\expandafter\csb\fi
**
We will call this the ``K-method''; it is often used without explicit
mention. (As pointed out in the *amstex.doc* file,
 however, this method is not always
valid or practicable).

\medskip
Another frequently used convention of \amstex\ is ``compressed format''.
We often have to make definitions of the form
\setbox0\hbox{\<something or other\>}
**
\def\cs{\futurelet\next\cs@}
\def\cs@{\ifx\next"copy0%
  \def\next@{...\cs@@...}\else
  \def\next@{...\cs@@@...}\fi
 \next@}
\def\cs@@{...}
\def\cs@@@{...}
**
But this uses up three new control sequence names, *\cs@*, *\cs@@*, and
*\cs@@@*, just for this one construction.  The ``compressed format''
uses the same names *\next@*, *\nextii@*, etc., over and over again,
simply redefining them within each definition:
**
\def\cs{%
 \def\next@{\ifx\next"copy0%
   \def\next@{...\nextii@...}\else
   \def\next@{...\nextiii@...}\fi
  \next@}%
 \def\nextii@{...}%
 \def\nextiii@{...}%
 \futurelet\next\next@}
**
Notice that the ``first'' clause *\futurelet\next\next@* has to be made
last (and, although it looks strange at first, it's perfectly legitimate
to have *\next@* defined in terms of *\next@* in this situation).

  Compressed format makes things go a little slower, since *\next@*,
etc., have to be redefined all the time, but seems worth it, especially since
it is usually used for major formatting constructions that introduce
a lot of
space anyway.

\medskip
\amstex\ also uses the construction
**
\Invalid@\controlseq
**
to make *\controlseq* give an error message. As explained in *amstex.doc*,
this is recommended for any control sequences (often discovered via a
*\futurelet*)
that function as ``syntax''
for other control sequences, and consequently shouldn't be encountered
on their own.

\section{Constructions from \amstex\label{AC}}
Some more specific \amstex\ code should also be mentioned.
\Litbox0=**
\ifx\amstexloaded@\relax\catcode`\@=\active
 \endinput\else\let\amstexloaded@=\relax\fi
**
First of all, the code 
$$
\vcenter{\box0} \tag "\style{\bf A}"
\pagelabel{A}
$$
appears
near the beginning of the *amstex.tex* file. This prevents the file
*amstex.tex*
from being loaded twice by making
*\amstexloaded@* be undefined if *amstex.tex* hasn't been loaded, but
*\relax* if it has. This is
a necessity because of the two lines
**
\let\ic@=\/
\def\/{\unskip\ic@} "8itcorr"8
**
that occur later (compare {\it The \tex book}, pp.~382@--383).


Testing *\amstexloaded@* also allows other macro packages to tell whether
*amstex.tex* has already been loaded, which is important for \lamstex@, as
we will see in the next chapter.


\amstex\  also
introduces two new counters, and a new token list,
**
\newcount\count@@
\newcount\count@@@
\toksdef\toks@@=2
**
in addition to the counter *\count@* and token list *\toks@*
provided by *plain.tex*; these
 are also used in \lamstex\ (see section~\Sref{LANDG} for the choice of~*2*
in the *\toksdef*).

Furthermore, \amstex\ introduces the abbreviations
**
\def\FN@{\futurelet\next}
"2
\def\DN@{\def\next@}
\def\DNii@{\def\nextii@}
"2
\def\RIfM@{\relax\ifmmode}     "8RIfM"8
\def\RIfMIfI@{\relax\ifmmode\ifinner}
"2
\def\setboxz@h{\setbox\z@\hbox}
\def\wdz@{\wd\z@}
\def\boxz@{\box\z@}
**
  These are used throughout \lamstex\ also. When we
show
*lamstex.tex* code, however,
we will  usually expand out these definitions,
to make things easier to read.
Similarly, certain control sequences from *plain*, like *\z@*, *\p@*,
etc.,
will usually be expanded out for the sake of readability.
Moreover, in 
constructions like
**
\count@=...
\let\next@=\relax
**
and so forth, we will often add the optional *=* signs that are normally
omitted in the code.


We will frequently use the \amstex\ control sequence *\eat@* defined by
**
\def\eat@#1{}
**

\amstex\ introduces the token *\space@* that has been *\let* equal to a
space. It is often used after 
**
\futurelet\next\foo
**
constructions where *\foo* has to do something special if the next 
token is a space.  In many cases, *\foo* must skip over that space, and
then  execute *\goo*. The standard \amstex\ way of doing this is
with the code
**
\ifx\next\space@\def\next@. {\goo}\else
 \def\next@.{\goo}\fi\next@. "8swallow"8
**
The *.* after the *\next@* makes the space `visible' to  \tex.


As we shall see in section~\Sref{FIX},  \lamstex\ introduces a
somewhat more economical approach to this problem.

By the way,  a case like this, where something
is part of the syntax for *\next@*, is one of the situations where
the K-method would not work.

\medskip
There are a few more \amstex\ devices that are important in \lamstex@, but
their discussion has been deferred until Chapter~\ref{CA}, since these devices
are actually additions intended for later versions of \amstex.


\section{Changes to \amstex; \CS{local} and \CS{global}
assignments\label{LANDG}}
Numerous lines
of *amstex.tex* have been deleted in *amstexl.tex* because they are not
used, or are modified, by *lamstex.tex*. Major changes of this sort are
discussed at the appropriate points.

There are also numerous small changes. For example, all *\relaxnext@*'s have
been omitted, since \lamstex\ no longer needs that device for dealing
with *\outer* constructions. 

One change was necessary to avoid a conflict:
 *\roman* is now used in \lamstex\ for a numbering control sequence,
whereas it
 previously had a different
 (extremely unlikely) use in \amstex@, as a control sequence to
be used in math to produce a roman letter. The latter has now been changed
from *\roman* to *\rom*. 

One other
change should be mentioned explicitly: near the beginning of *amstexl.tex*
the definitions
**
\def\height{height}  "8HWD"8
\def\width{width}
\def\depth{depth}
**
have been inserted, so that `*height*', `*width*' and `*depth*' can
be replaced by the corresponding single tokens in the specifications for
various *\hrules* and *\vrules*; these replacements save even more memory
space in *lamstex.tex*, where rules occur much more frequently.



Finally, I have now conscientiously adhered to {\it The \tex book\/}'s
 recommendations (see pages~301 and~346)
that assignments of variables either always be  global or
always be
local. In most cases, the necessary changes have been minor (like
changing some *\xdef*'s to *\edef*'s, or vice versa), but somewhat more
extensive changes were required to ensure that *\setbox*\,{\it n} is
 always
local for {\it n\/} even
and
global
for {\it n\/} odd; these changes occur in the definitions of
*\insplit@*, *\rendsplit@*, *\lendsplit@*, *\lmultline@@@*, 
*\rmultline@@@*, *\binrel@*, *\sideset@*, *\r@@t*, *\pmb@*, and perhaps
one or two other places.

We will exercise comparable care regarding assignments of variables\linebreak
throughout \lamstex.


\chapter Getting started with \lamstex\label{GETSTART}\endchapter

The first thing in *lamstex.tex*, after the  copyright notice,
is
\C**
\catcode`\@=11
**
to make *@* a letter, in order to create ``private'' control sequences that
the casual user  cannot type, as well as to access such private control
sequences from *plain.tex* and *amstexl.tex*.

We will always adhere to the
 convention introduced here, using horizontal lines
when we print
 actual
*lamstex.tex* code, as opposed to examples, pieces of code, etc.
We will often use different line breaks from the actual *lamstex.tex*
code, so that it will fit better on these printed pages. (It should also be
noted that when we give preliminary pieces of code we will often omit 
*%*~
signs  at the ends of lines, although they are meticulously added when needed
in the code itself.)


Since \lamstex\ is not supposed to be loaded unless \amstex\ has already been
loaded, the  next code,
\C**
\ifx\amstexloaded@\relax\else
 \errmessage{AmS-TeX must be loaded before LamS-TeX}\fi
** 
produces an error message if it hasn't---see the discussion of
the code  ({\bf A}) on page~\ref{A}.


We will adopt a different scheme for preventing  *lamstex.tex* from being
read in twice,
one that doesn't create a new control sequence name, by
using the fact that *lamstex.tex* will 
eventually define the control sequence
*\laxread@* (see page~\ref{lax}), while \amstex\ makes certain that
*\undefined* is always undefined (see *amstex.doc*):
\C**
\ifx\laxread@\undefined\else\catcode`\@=\active\endinput\fi
**


[Other  
 macro packages that need to know whether or not
\lamstex\ has been loaded can use a similar test, or, if the 
status of *\undefined* isn't clear, they can use the test
**
\expandafter\ifx\csname laxread@\endcsname\relax
**
which is false when \lamstex\ has been loaded, but true when it hasn't been
loaded, since the control sequence produced by 
*\csname...\endcsname* is given the value *\relax* if it hasn't already
been defined.]



Next we redefine *\err@* from \amstex\ to produce error messages saying
`*LamS-TeX error:*'
instead of `*AmS-TeX error*:'
\C**
\def\err@#1{\errmessage{LamS-TeX error: #1}}
**
*\Err@*, which is *\err@* with \amstex's ``default help message'', will
now also produce such error messages (see
section~\Sref{STER}).


As indicated in section~\Sref{K},
we redefine *^^L*, the *\new...* constructions, *\+*, and *\bye*
 from *plain* so that they are not
*\outer*,
\C**
\def^^L{\par}
\let\+=\tabalign
"2
\def\newcount{\alloc@0\count\countdef\insc@unt}
"2
\def\newdimen{\alloc@1\dimen\dimendef\insc@unt}
"2
\def\newskip{\alloc@2\skip\skipdef\insc@unt}
"2
\def\newmuskip{\alloc@3\muskip\muskipdef\@cclvi}
"2
\def\newbox{\alloc@4\box\chardef\insc@unt}
"2
\let\newtoks=\relax
\def\newhelp#1#2{\newtoks#1#1\expandafter{\csname#2\endcsname}}
\def\newtoks{\alloc@5\toks\toksdef\@cclvi}
"2
\def\newread{\alloc@6\read\chardef\sixt@@n}
"2
\def\newwrite{\alloc@7\write\chardef\sixt@@n}
"2
\def\newfam{\alloc@8\fam\chardef\sixt@@n}
"2
\def\newlanguage{\alloc@9\language\chardef\@cclvi}
"2
\def\newinsert#1{\global\advance\insc@unt by\m@ne
  \ch@ck0\insc@unt\count
  \ch@ck1\insc@unt\dimen
  \ch@ck2\insc@unt\skip
  \ch@ck4\insc@unt\box
"2
  \allocationnumber=\insc@unt
  \global\chardef#1=\allocationnumber
  \wlog{\string#1=\string\insert\the\allocationnumber}}
"2
\def\newif#1{\count@\escapechar \escapechar\m@ne
  \expandafter\expandafter\expandafter
   \edef\@if#1{true}{\let\noexpand#1=\noexpand\iftrue}%
"2
  \expandafter\expandafter\expandafter
   \edef\@if#1{false}{\let\noexpand#1=\noexpand\iffalse}%
  \@if#1{false}\escapechar\count@} % the condition starts out false
"slip
\def\bye{\par\vfill\supereject\end}
**
and then we
\C**
\let\beginsection=\undefined
**
to make *\beginsection*  undefined (see *amstex.doc*).

\small In *plain* \tex@, the *\let\newtoks=\relax* is inserted before
the definition of *\newhelp* so that *plain.tex* can be read in twice.
Even though we are not allowing *lamstex.tex* to be read in twice, this
is still required, since we read it in after *plain.tex*!
\endsmall



\chapter Changes to \amstex\label{CA}\endchapter



The next part of \lamstex\ contains various changes to \amstex@. Some of
the changes should,
and probably eventually will, be made in \amstex@, though they didn't get
included in
 \amstex~version *2*, while other changes are relevant only for \lamstex. 
(Further changes to \amstex\ will be made later, at the relevant points.)

\section{\CS{Err\@}\label{STER}}
\amstex's definition of *\Err@*, {\litindent=0pt
**
\def\Err@#1{\errhelp\defaulthelp@\errmessage{AmS-TeX error: #1}}
**
has been deleted in *amstexl.tex*,} because it 
can obviously be shortened to
\C**
\def\Err@#1{\errhelp\defaulthelp@\err@{#1}}
**


\section{\CS{atdef\@}\label{ATDEF}}
\amstex's original mechanism for defining the active *@* character 
can be
improved considerably.

First of all, we want the active *@* to mean
**
\futurelet\next\at@
**
the problem being that we need to make this definition while *@* is active
**
{\catcode`\@=\active
 \def@{...}
** 
even though we want to allow *@* as part of the control sequence name
 *\at@*.

Now we can easily name *\at@* even when *@* is active, as
**
\csname at\string@\endcsname
**
Of course, we can't simply say
**
\def@{\futurelet\next\csname at\string@\endcsname}
**
since *@* would then simply *\let\next=a*---we need to have the
combination
*\csname...\endcsname* expanded out before the *\futurelet\next* takes
effect. 

We could do this with
**
\def@{\def\next{\futurelet\next}\expandafter\next
  \csname at\string@\endcsname}
**
but that's somewhat unsatisfactory, since 
it requires the active~ *@* to make a
subsidiary definition each time it is used.

Another possibility is to use the triple *\expandafter* trick (see
{\it The \tex book}, page~374), which we will be using later on. But for the
present problem the simplest  
strategy is to use the code
**
 \edef\next{\gdef\noexpand@{\futurelet\noexpand\next  "8ATD"8
  \csname at\string@\endcsname}
 \next
**
Here the *\edef* makes *\next* mean
**
"9\gdef"9","9@"9{"9\futurelet"9","9\next"9\at@}
**
where the boxed control sequences are not expanded out either because they
are primitives or because they are preceded by *\noexpand*; the
*\csname..."allowbreak"0\endcsname* 
{\it is\/} expanded out in the *\edef*, but the
control sequence *\at@* that it expands to is made equal to *\relax*,
since *\at@* hasn't been defined previously---so *\at@*
isn't expanded further in the *\edef*. (Here we are using the fact that
*lamstex.tex* won't be read in twice [Chapter~\ref{GETSTART}].)

Consequently, when we then call *\next* we get this *\gdef*. Thus,
 to get
the desired definition of the active *@* we just need 
\C**
{\catcode`\@=\active
 \edef\next{\gdef\noexpand@{\futurelet\noexpand\next
  \csname at\string@\endcsname}}
 \next
}
**

The definition of *\at@* itself is now easy, with *@* back as a letter.
We will call the very same routine, *\at@@*,
 when the next token is a letter,
other character, or control sequence (or active character); for any other
type of token we will call *\at@@@*, which will be an error message: 
\C**
\def\at@{%
 \ifcat\noexpand\next a\let\next@=\at@@\else
 \ifcat\noexpand\next0\let\next@=\at@@\else
 \ifcat\noexpand\next\relax\let\next@=\at@@\else
 \let\next@=\at@@@\fi\fi\fi\next@}
**

The error message *\at@@@* is simply
\C**
\def\at@@@{\errhelp\athelp@\err@{Invalid use of @}}
**
using the help message *\athelp@* from \amstex@.


On the other hand,
 *\at@@* \<token\> will simply be the control sequence
\setbox0\hbox{\<token\>}
\setbox1\hbox{`}\setbox2\hbox{'}
**
"box1"0\"box0@at"box2
**
if it has been defined, or an error message otherwise. Here we put
quotes around *\*\<token\>*@at* to emphasize that it is a single
control word, even when \<token\> isn't a letter;\pagelabel{QTS1}
 in practice, of course,
such control words have to be constructed using
*\csname"allowbreak..."allowbreak\endcsname*: 
\C**
\def\at@@#1{\expandafter
 \ifx\csname\string#1@at\endcsname\relax
  \let\next@=\at@@@
 \else
  \def\next@{\csname\string#1@at\endcsname}%
 \fi
 \next@}
** 
Note that we use *\string#1* so that the token
*#1* can be a control sequence or
active character, as well as a letter or other character.




Finally,  *\atdef@*, the mechanism for defining the value of the
active *@* on various tokens, is the same as in \amstex@, except that we
add a
  *\string*:
\C**
\def\atdef@#1{\expandafter\def\csname\string#1@at\endcsname}
**

There are two noteworthy things about this redefinition: 
\list
\item The original definition of *\atdef@* remains in *amstexl.tex*, because
it is used for
**
     \atdef@;{...}       \atdef@,{...}
     \atdef@:{...}       \atdef@!{...}
     \atdef@?{...}       \atdef@.{...}
     \atdef@-{...}
**
These *\atdef@*'s
give the same results as the new *\atdef@* would give,
 since for these characters the *\string* is simply
redundant---once *@* is active, *@;* and *@:* and so forth
 will work just
as before.  
(The *\atdef@@\vert* is irrelevant:  it is deleted in
*amstexl.tex*, and not used in \lamstex@.)

\item Later in \lamstex\ we are going to make *""* active.  Nevertheless,
\amstex's
**
     \atdef@""
**
will still make the combination
*@""* work correctly,\pagelabel{SW}
 because *\string""* for *""* active  gives
the same result as \amstex's *""* when *""* is not active.  
Actually, we are going to give a new *\atdef@""* (section~\Sref{FIX}),
but that will be done before *""* is made active, so the same principle 
still applies.
\endlist



\section{Tests\label{TESTS}}
\amstex\ has the flag *\ifin@*, which is set only by the routine *\in@*,
a test to determine whether a particular token appears in any sequence; this
test,
 in turn, is used only by the routine *\tagin@* to check for the presence
of *\tag* in a sequence.
  \lamstex\ has numerous
tests that are always performed independently, so it is economical to have a
single flag that will be used by all of them; this flag will
 also replace *\ifin@*
from \amstex@. So  *amstexl.tex* 
deletes the line
**
\newif\ifin@
**
and in \lamstex\ we
 introduce the flag
\C**
\newif\iftest@
**


Moreover, in *amstexl.tex* 
we also delete
**
\def\in@#1#2{ . . . }
\def\tagin@#1{ . . . }
**
while in \lamstex\ we
  redefine the *\tagin@* routine so that instead of using
*\ifin@* it merely reproduces (an equivalent of) the definition:
\C**
\def\tagin@#1{\tagin@false
 \def\next@##1\tag##2##3\next@{\test@true
  \ifx\tagin@##2\test@false\fi}%
 \next@#1\tag\tagin@\next@
 \tagin@false\iftest@\tagin@true\fi}
**

\section{Spaces after control sequence names in error messages\label{SACN}}
Numerous
error messages in \amstex\ use constructions of the form
**
 . . . \string\controlseq\space . . .
**
to get a space after the control sequence
 *\controlseq* in the error message.  However, it
saves one token to instead use
**
 . . . \noexpand\controlseq . . .
**
---the *\noexpand* prevents expansion of *\controlseq*
in the error message, but we still
get a space after *\controlseq*. 

This device is used throughout \lamstex@, and the requisite changes were
also made directly in *amstexl.tex*, since they were so minor. 


\small
 The first change
occurs in
the definition of
*\define@*
where
**
\err@{\string\define\space must be . . . }
**
is replaced by
**
\err@{\noexpand\define must be . . . }
**
The next occurs in the definition
**
\define@@#1
**
which takes a control sequence *#1* as its argument, where, for example
\Litbox0=**
\err@{\string#1 is already defined}
**
$$\box0\tag"\style{\bf A}"$$
is changed to
**
\err@{\noexpand#1is already defined}
**
with no space before the `*is*', since it will appear when the error
message is given. [*amstex.tex* actually has 
**
\err@{\string#1\space is already defined}
**
which is unnecessary complicated, though it has the same number of
tokens as ({\bf A}).]


Similar replacements are made in the definitions of
**
\vmodeerr@#1
\mathmodeerr@#1
"2
\dmatherr@#1
"2
\nondmatherr@#1
"2
\onlydmatherr@#1
"2
\nonmatherr@#1
"2
\nonvmodeerr@#1
\textonlyfont@#1#2
**

Finally, in the definition of *\boldkey* (which is actually redefined
in *lamstex.tex*---see page~\ref{NEWBK}) the
**
\Err@{\string\boldkey\space can't ...}
**
is replaced by
**
\Err@{\noexpand\boldkey can't ...}
**
with a similar change for
 *\boldsymbol*.

Note, by the way, that these substitutions cannot be made in 
**
\newhelp\athelp
\newhelp\defahelp
**
which end up putting things inside *\csname...\endcsname*.
\endsmall



\section{Line breaking\label{LBK}}
The original \amstex\ definition of *\nolinebreak*
 had an extra element *\refskip@*,
 which was initially *\relax*, but which
was changed for the bibliography. In version~*2*,
that aspect of the bibliography macros (sections~\Sref{BASICD} and
~\Sref{BIBMACS}),
as well as the indexing macros (section~\Sref{IPAGE}),
  has been improved.  Consequently, the
four control sequences
**
\nolinebreak
\allowlinebreak
\linebreak
\newline
**
will all have something added; it will suffice to add the same thing,
which we will call *\lkerns@*, to the first three,
and
something that we will call *\nkerns@* to the fourth;
 like the old *\refskip@*,
these are both initially *\relax*.  The definitions of these four
line-breaking macros are deleted in *amstex.tex*, and we now add
the new definitions. They differ from the original definitions (see
*amstex.doc*) in the inclusion of  *\lkerns@* and *\nkerns@*;
however, these do not occur in quite the place that *\refskip@* occurred
in the original definition of *\nolinebreak*---that was, in fact, incorrect.
We have also simplified the definition of *\newline*---as indicated 
in *amstex.doc*, 
the case of *\newline\par* 
really isn't worth worrying about.
\C**
\let\lkerns@=\relax
"slip
\def\nolinebreak{\relax
 \ifmathmode@
  \mathmodeerr@\nolinebreak\else
"2
 \ifhmode
  \saveskip@=\lastskip \unskip
  \nobreak
  \ifdim\saveskip@ > 0pt \hskip\saveskip@\fi
  \lkerns@
 \else\vmodeerr@\nolinebreak\fi\fi}
"2
\def\allowlinebreak{\relax
 \ifmathmode@
  \mathmodeerr@\allowlinebreak\else
"2
 \ifhmode
  \saveskip@=\lastskip \unskip
  \allowbreak
  \ifdim\saveskip@ > 0pt \hskip\saveskip@\fi
  \lkerns@
 \else\vmodeerr@\allowlinebreak\fi\fi}
\def\linebreak{\relax
 \ifmathmode
  \mathmodeerr@\linebreak\else
"2
 \ifhmode
  \unskip\unkern\break\lkerns@
 \else\vmodeerr@\linebreak\fi\fi}
"slip
\let\nkerns@=\relax
"slip
\def\newline{\relax
 \ifmathmode
  \mathmodeerr@\newline\else
"2
 \ifhmode
  \unskip\unkern\null\hfill\break\nkerns@
 \else\vmodeerr@\newline\fi\fi}%
**


\section{\CS{alloc\@\@}, \CS{newcount\@}, and \CS{newbox\@}\label{NEWNEW}}
Near the beginning of
\amstex@, *\alloc@* is redefined so that it doesn't write anything to the
*.log* file, while the original definition is reinstated at the end.
This means that 
the *\new...* constructions used to create new counters, \<dimen\> registers,
etc., within the file
do not write anything to the *.log* file.

After redefining *\alloc@*, \amstex\ also uses
**
\let\alloc@@=\alloc@
**
to make *\alloc@@* {\it that\/} version of *\alloc@*, even if called
after *\alloc@* has been redefined at the end. 
In the definition of *\loadmsam*, for example, the code
**
 . . . 
\alloc@@8\fam\chardef\sixt@@n\msafam
 . . .
**
functions
as a replacement for *\newfam\msafam*; this not only gets around the problem
that *\newfam* is still *\outer* in \amstex@, it also ensures that
nothing gets written to the *.log* file even if *\loadmsam* is used
after *\alloc@* is restored to its old definition.

In the definition of *\accentedsymbol*, however, a non-outer *\newbox*
is needed, because it appears in a construction like
**
\expandafter\newbox\csname ... \endcsname
**
where we can't simply use the code for *\newbox*. So 
*amstex.tex* used *\newbox@* as a non-outer version of *\newbox*.
However, the \amstex\ definition,
**
\def\newbox@{\alloc@4\box\chardef\insc@unt}
**
because it used *\alloc@* rather than *\alloc@@*, wasn't really the right
choice anyway.

In \lamstex\ we rectify this situation.  First of all, the definitions of
*\newbox@* and *\accentedsymbol* are deleted in *amstexl.tex*.  Then in
*lamstex.tex*, we
\C**
\def\newbox@{\alloc@@4\box\chardef\insc@unt}
**
and also, for later use,
\C**
\def\newcount@{\alloc@@0\count\countdef\insc@unt}
**

Then we redefine *\accentedsymbol* using *\newbox@*. In addition, the
combination 
**
\expandafter\eat@\string
**
in the definition is replaced by *\exstring@*, since we will introduce
this as an abbreviation for that combination later (section~\Sref{CNT}) (we
also take the opportunity to eliminate two unnecessary *\expandafter*'s from
the original code):
\C**
\def\accentedsymbol#1#2{\expandafter
 \newbox@\csname\exstring@#1@box\endcsname
 \setbox\csname\exstring@#1@box\endcsname
  =\hbox{$\m@th#2$}%
 \define#1{\copy\csname\exstring@#1@box\endcsname{}}}
**

\section{Lists\label{LISTS}}
\amstex\ has two lists, *\alloclist@*, and *\fontlist@*,
of the type introduced in {\it The \tex book}, page~378, and it defines
*\rightappend@*,  which is like 
*\rightappenditem* from that page.

 *\alloclist@* is maintained for
the *\showallocations* command, which is really only for the use of
\tex nicians, and \lamstex\ dispenses with this feature, in order to save
space; consequently,
in *amstexl.tex* all material related
to *\alloclist@* is deleted.

*\fontlist@* is used for the *\syntax* command, which \lamstex\ retains,
but
for this list of control sequence names it is more efficient to use
a list of the type described on page~379 of {\it The \tex book}:
\setbox0\hbox{name$_{\text1}$}%
\setbox1\hbox{name$_{\text2}$}%
**
\\\"box0\\\"box1...
**
Several other lists of this sort will be used in \lamstex@; in some cases,
we will even have a list of the form *\\_",_",_\\_",_",_ ...*, where
*_",_",_* are not control sequence names.

In \lamstex\ we will still be using 
*\rightappend@* on occasion, but
we will also define
the routine *\rightadd@#1\to#2* to add *#1* to 
one of these simpler lists *#2*:
\C**
\def\rightadd@#1\to#2{\toks@={\\#1}\toks@@=\expandafter{#2}% "8atl"8
 \xdef#2{\the\toks@@\the\toks@}%
 \toks@={}\toks@@={}}
**

In *amstexl.tex*, the definition of *\fontlist@* is deleted,
and in \lamstex\ 
we instead define *\fontlist@* to be a list of this simpler sort:
\C**
\def\fontlist@{\\\tenrm\\\sevenrm\\\fiverm\\\teni\\\seveni
 \\\fivei\\\tensy\\\sevensy\\\fivesy\\\tenex\\\tenbf
 \\\sevenbf\\\fivebf\\\tensl\\\tenit}
**

Similarly, the definition of *\font@* is deleted in *amstexl.tex*
and replaced in \lamstex\ by
\C**
\def\font@#1=#2 {\rightadd@#1\to\fontlist@\font#1=#2 } "8FL"8
**
(Although *\font@* appears in *amstexl.tex*, it occurs only within
other definitions, so the definition can be deferred to *lamstex.tex*.)


Although,
as mentioned in section~\Sref{TESTS}, the test *\ifin@* has been deleted in
\linebreak
*amstexl.tex*, 
for a list *#1* of control sequences,
\setbox0\hbox{name$_{\text1}$}%
\setbox1\hbox{name$_{\text2}$}%
**
\\\"box0\\\"box1...
**
we will need another (simpler) test to 
determine whether a control sequence *#2* 
is in the list. Basically we want to use
**
"hskip-30pt\def\ismember@#1#2{\test@false\let\next@=#2%
"hskip-30pt {\def\\##1{\let\nextii@=##1\ifx\nextii@\next@\global\test@true\fi}#1}%
**
But since we normally set the flag *\iftest@* only locally, we don't want
to use a *\global\test@true* in this one situation (compare
section~\Sref{LANDG}).
 So instead we will use a
new 
scratch token, *\Next@*, for which we will always use *\global* assignments.
In addition, there are two further details that we will explore in a moment:
\pagelabel{GNXT}
\C**
\def\ismember@#1#2{"9\global\let\Next@=F"9\let\next@"9=" "9#2%  "8ismember"8
 {\def\\##1{\let\nextii@=##1\ifx\nextii@\next@
  "9\global\let\Next@=T"9\fi}#1}%
 \test@false\ifx\Next@ T\test@true\fi"9\let\next@=\relax"9}
**

This test
may compared with the test on page~379 of {\it The \tex book}. Using
*\let\next@* instead of *\def\next@*  allows the test
**
\ismember@#1\next
**
to be used after *\next* has been *\let* equal to some control sequence
by a *\futurelet*\pagelabel{ISFL}, which will be important 
in section~\Sref{ZZZ} (on some occasions 
we will also be using *\ismember@#1#2* when
*#2* is an explicit argument).
 But two precautions are then in order:


\bullist \item\pagelabel{NEEDEQ}
Although actual *lamstex.tex* code usually omits
*=* signs after *\let*'s, in the above code we need both the boxed *=*
sign {\it and the space after it\/}!
 Reason: Our *\futurelet* may have
*\let\next* be a space token, which is thus a \<space token\> in
the notation of {\it The \tex book}, page~269. According to the syntax
rule on page~277, one such space (but only one)
will be ignored after the *=* sign; if we simply had
**
\let\next@=#2{\def\\ ...
**
then the \<space token\> *#2* would be ignored, and
*\next@* would end up being the *{*, which would then disappear, causing
infinite confusion later on.

\item
Another important precaution is the *\let\next@=\relax* at the end. That is
needed because the *\futurelet\next* may have
*\let\next*  equal something
equivalent to *\iftrue* or *\iffalse*, so that *\next@* would then also
be equal to
*\iftrue* or *\iffalse*. If that situation were allowed to continue, havoc
might ensue the next time we used a macro containing *\next@* within it.
\endlist

As an example of this latter phenomenon,\pagelabel{NEWPRECAUTION}
 note that the original *plain* \tex\ 
  definitions
**
"hskip-30pt{\catcode`\'=\active \gdef'{^\bgroup\prim@s}}
"hskip-30pt\def\prim@s{\prime\futurelet\next\prim@m@s}
"hskip-30pt\def\pr@m@s{\ifx'\next\let\next\pr@@@s \else\ifx^\next\let\next\pr@@@t
"hskip-30pt \else\let\next\egroup\fi\fi\next}
"hskip-30pt . . . 
** 
 later had to be modified by changing *\pr@m@s* to
**
"hskip-30pt\def\pr@m@s{\ifx'\next\let\nxt\pr@@@s \else\ifx^\next\let\nxt\pr@@@t
"hskip-30pt \else\let\nxt\egroup\fi\fi\nxt}
**
For example, we might have
**
$a'\iffirstset x\else y \fi$
**
where *\iffirstset* is some user-defined construction, and then
the\linebreak *\futurelet\next* in
*\prim@s* 
would *\let\next=\iffirstset*.
Note that the appearance of 
*\next*
after an *\ifx* test 
causes no problem,
but its appearance within an *\if...* clause, even following
a *\let* or *\def*, would make things go haywire. Similarly, in the
definition of *\ismember@*, the
*\next@* appears in safe places.

To avoid such problems in general, after any *\futurelet* we will use
only the token *\next*, and otherwise
*\next* will not appear in any macros except
after *\ifx* tests (or *\ifcat* tests). One definition in *amstex.tex*
requires modification to adhere to this rule: the definition
**
"hskip-30pt\gdef\comment@@@#1\comment@@@{\ifx\next\comment@@@\let\next\comment@
"hskip-30pt \else\def\next{\oldcodes@\endlinechar=`\^^M\relax}%
"hskip-30pt \fi\next}
**
has been changed in *amstexl.tex* to
**
"hskip-30pt\gdef\comment@@@#1\comment@@@{\ifx\next\comment@@@\let\next@\comment@
"hskip-30pt \else\def\next@{\oldcodes@\endlinechar=`\^^M\relax}%
"hskip-30pt \fi\next@}
**




 \section{Skipping spaces in \CS{futurelet}'s\label{FIX}}
On page~\ref{swallow} we mentioned 
 \amstex's device for skipping over space
tokens in *\futurelet* constructions. Instead of using this device
directly, which requires somewhat long definitions each time, \lamstex\ uses a
special ``futurelet-next-skipping-spaces'' construction
**
\FNSS@\foo
**
which is like *\futurelet\next\foo*, except that any space tokens after
*\foo* will be discarded, and *\foo* will be applied after
*\next* has been *\let* equal to the
first non-space token after *\foo*.  *\FNSS@#1* begins
 by storing *#1* in
*\FNSS@@*, and then 
applies a *\futurelet\next* construction, calling *\FNSS@@@*, which
 then does the checking for a space:


\C**
\def\FNSS@#1{\let\FNSS@@=#1\futurelet\next\FNSS@@@}
"slip
\def\FNSS@@@{\ifx\next\space@
 \def\FNSS@@@@. {\futurelet\next\FNSS@@@}\else
 \def\FNSS@@@@.{\FNSS@@}\fi
 \FNSS@@@@.}
**
Thus, when *\next* happens to be a space, we swallow the space and call
the routine
*\futurelet\next\FNSS@@@* again, to get the next non-space token; 
when we do get a non-space token,
 we simply apply *\FNSS@@*, the argument of *\FNSS@*.

\medskip
The \amstex\ *\atdef@""* (see *amstex.doc*) is deleted from *amstexl.tex*,
because it
can be shortened
if we use
this *\FNSS@* to get the first non-space token after *@""*:
\C**
\atdef@""{\unskip
"2
 \def\next@{\ifx\next`\def\next@`{\futurelet\next\nextii@}%
  \else\ifx\next\lq\def\next@\lq{\futurelet\next\nextii@}%
  \else\def\next@####1{\futurelet\next\nextiii@}\fi\fi
  \next@}%
"2
 \def\nextii@{\ifx\next`\def\next@`{\sldl@``}%
  \else\ifx\next\lq\def\next@\lq{\sldl@``}%
  \else\def\next@{\dlsl@`}\fi\fi\next@}%
"2
 \def\nextiii@{\ifx\next'\def\next@'{\srdr@''}%
  \else\ifx\next\rq\def\next@\rq{\srdr@''}%
  \else\def\next@{\drsr@'}\fi\fi\next@}%
 \FNSS@\next@}
**

[In our definition of *\FNSS@@@* we used a new control sequence
*\FNSS@@@@* instead of using a scratch token like *\next@* 
to allow the use of *\FNSS@* 
 in such ``compressed format'' definitions.]

There is only one other definition in \amstex\ that
is (deleted from\linebreak *amstexl.tex* and)
shortened using *\FNSS@*:
\C**
\def\root{%
  \def\next@{\ifx\next\uproot\let\next@=\nextii@\else
"2
   \ifx\next\leftroot\let\next@=\nextiii@\else
"2
   \let\next@=\plainroot@\fi\fi\next@}%
"2
  \def\nextii@\uproot##1{\uproot@##1\relax\FNSS@\nextiv@}%
"2
  \def\nextiv@{\ifx\next\leftroot\let\next@=\nextv@\else
   \let\next@=\plainroot@\fi\next@}%
"2
  \def\nextv@\leftroot##1{\leftroot@##1\relax\plainroot@}%
"2
  \def\nextiii@\leftroot##1{\leftroot@##1\relax
   \FNSS@\nextvi@}%
"2
  \def\nextvi@{\ifx\next\uproot\let\next@=\nextvii@\else
   \let\next@=\plainroot@\fi\next@}%
"2
  \def\nextvii@\uproot##1{\uproot@##1\relax\plainroot@}%
  \bgroup\uproot@\z@\leftroot@\z@
 \FNSS@\next@}
**

 However, there are numerous places in \lamstex\ where
the use of *\FNSS@* will similarly save space, definitely make the extra
tokens used for *\FNSS@* worth while.
Note, moreover, that the above definition of *\root*
not only saves space, but also 
avoids introducing the scratch tokens
*\nextviii@* and *\nextix@* that occur in the
original definition,
but which occur nowhere else in \amstex.



\section{\CS{loop}\label{LOOP}}
The same article that introduced the ``K-method'' (page~\ref{KABEL})
also introduced a new definition of *plain* \tex's *\loop...\repeat*
mechanism, which we will use in \lamstex:
\C**
\def\loop#1\repeat{%
 \def\iterate{#1\relax\expandafter\iterate\fi}%
 \iterate\let\iterate=\relax}
**
This has the property that it allows constructions like
**
\loop _",_",_ \if...  _",_",_ \else  _",_",_ \repeat
**
where we repeat when the *\if...* test is {\it false\/} rather than
true, which will turn out to be useful at several points in \lamstex@.
\footnote{The alternative is to use
*\if... \test@false \else \test@true \fi  \iftest@ _",_",_ \repeat*.}

Corresponding to this redefinition of *\loop*, we add a new definition 
of *\gloop@* (which is used by the *\cfrac* construction):
\C**
\def\gloop@#1\repeat{%
 \gdef\iterate@{#1\relax\expandafter\iterate@\fi}%
 \iterate@\global\let\iterate@=\relax}
**
The main purpose of redefining *\gloop@* is so that it will use *\iterate@*
rather than *\iterate*, so that *\iterate* will only be given a local
definition, not both a local and a global one (compare section~\Sref{LANDG}).


In *amstexl.tex* we delete the line
**
\newif\ifbadans@
**
and the definition of *\printoptions*, because we can define *\printoptions*
in terms of *\iftest@* (section~\Sref{TESTS}).  We've deferred this
redefinition until now because it is also a little bit more convenient to
use this alternative *\loop* test:
\C**
\def\printoptions{\W@{Do you want S(yntax check),
  G(alleys) or P(ages)?^^JType S, G or P, follow by 
   <return>: }%
"2
 \loop
  \read -1 to\ans@
  \edef\next@{\def\noexpand\Ans@{\ans@}}%
   \uppercase\expandafter{\next@}%
  \ifx\Ans@\S@\global\test@true\syntax\else
  \ifx\Ans@\G@\global\test@true\galleys\else
  \ifx\Ans@\P@\global\test@true\else
  \global\test@false\fi\fi\fi
 \iftest@
 \else
  \W@{Type S, G or P, follow by <return>: }%
 \repeat}
**



\section{A l\'a fran\c cais\label{ALF}}Finally, 
certain changes are made to *amstex.tex*
to accommodate French styles that make some or all of
*;* and *:* and *!* and *?* into active characters. In this case, various
\amstex\ macros that involve tests like
**
\ifx\next!
**
need to be changed. 
\footnote{In addition, in *lamstex.tex* we  have the problem that certain
control sequences, notably those for commutative diagrams and tables, use
certain punctuation as part of their {\it syntax}. For example, the *\ds*
option for arrows in a commutative diagram is typed in the form
*\ds(h;v)* (see page~155 of the \lamstex~Manual).
If we make a definition
like
*\def\ds(#1;#2){...}*, then
\tex\ incorporates a type~*12*~ *;* as part of the
syntax for *\ds*. So in a document where *;* is active, the *;* that the user
types will not be recognized as the proper syntax element. The devices for
handling this problem will be discussed at the appropriate time (in
Volume~2).}  

Our goal is to allow
all necessary changes  to be indicated in a 
reasonably short file, say *french.tex*, which can
be read in {\it after\/} *lamstex.tex* (so that it can be loaded on top of a
\lamstex\ format file). 


The most reasonable approach is to have certain control sequences
that have been *\let* equal to the active punctuation symbols, so that
we can use these in an *\ifx\next...* test.  Of course, this can only 
be done after the active punctuation symbols have been defined, not in
*amstexl.tex*. To get around this problem, 
we will  insist that the definition of the active punctuation 
symbols
in *french.tex* are not made with an ordinary *\def*, but with
 a special *\APdef*, which will manage things properly for us.


For the control sequences that  will be *\let* equal to the active
punctuation symbols
we will use the following control words (which have to be
created using *\csname...\endcsname*):~
`*\A@;*' and `*\A@:*' and `*\A@?*' and ~`*\A@!'*. 
 We begin by
assigning the non-active characters as default values:
\C**
\expandafter\let\csname A@;\endcsname=;
\expandafter\let\csname A@:\endcsname=:
\expandafter\let\csname A@?\endcsname=?
\expandafter\let\csname A@!\endcsname=!
**

When 
**
\APdef:{ ... }
**
appears in *french.tex*, we want to (1)~\hbox{*\def:{ ... }*} and
(2)~*\let*`*\A@:*'*=:* (here,\pagelabel{QTS2}
 as on page~\ref{QTS1},
 we put quotes around *\A@:* to emphasize
that it is a single control word; in actual code  something
like
**
\expandafter\let\csname A@\string:\endcsname=:
**
will be needed).

To achieve this, we use
\C**
\def\APdef#1{\def\next@{\expandafter
 \let\csname A@\string#1\endcsname=#1}%
 \afterassignment\next@\def#1}
**
Thus, for example,
*\APdef:* defines *\next@* to mean
\setbox0\hbox{`*\A@:*'}
**
\let"box0=:
**
and after the assignment *\def:*, which swallows the following
\hbox{*{ ... }*}, we perform *\next@*, so that `*\A@:*' has now been 
*\let* equal to the active~*:*\,.

So, we can
produce
 control sequences that have the value of each active punctuation symbol
that may occur in a file,
assuming that *\APdef* has always been used in *french.tex*.


Now consider the original \amstex\ definition
**
\def\tdots@{\unskip
 \def\next@{$\m@th\mathinner{\ldotp\ldotp\ldotp}\,
"2
  \ifx\next,\,$\else\ifx\next.\,$\else
"2
  \ifx\next;\,$\else
"2
  \ifx\next:\,$\else
"2
  \ifx\next?\,$\else
"2
  \ifx\next!\,$\else
  $ \fi\fi\fi\fi\fi\fi}%
 \ \futurelet\next\next@}
**

We want to supplement this with *\ifx\next* tests that check whether
*\next* is an active punctuation symbol, in case *\tdots@* gets used in a
file where that is the case. 
We can do this with tests like
**
\expandafter\ifx\csname A@\string;\endcsname\next
**
 For greater
flexibility, when we encounter an active punctuation symbol
we will not necessarily insert the extra *\,* that the non-active symbol gets;
we will instead insert *\fextra@*, which by default is 
\C**
\let\fextra@=\,
**
(but which *french.tex* can redefine, if desired).

The original definition of *\tdots@* is deleted from *amstexl.tex*, and
a new definition is given in *lamstex.tex*:
\C**
\def\tdots@{\unskip
 \def\next@{$\m@th\mathinner{\ldotp\ldotp\ldotp}\,
  \ifx\next,\,$\else\ifx\next.\,$\else
"2
  \ifx\next;\,$\else
  "9\expandafter\ifx\csname A@\string;\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next:\,$\else
  "9\expandafter\ifx\csname A@\string:\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next?\,$\else
  "9\expandafter\ifx\csname A@\string?\endcsname\next"9
   "9\fextra@$\else"9
"2
  \ifx\next!\,$\else
  "9\expandafter\ifx\csname A@\string!\endcsname\next"9
   "9\fextra@$\else"9
  $ \fi\fi\fi\fi\fi\fi"9\fi\fi\fi\fi"9}%
 \ \futurelet\next\next@}
**

Similarly, the definition of *\extrap@* 
is deleted from *amstexl.tex*, and
in *lamstex.tex* we add
\C**
\def\extrap@#1{%
 \ifx\next,\def\next@{#1\,}\else
"2
 \ifx\next;\def\next@{#1\,}\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\def\next@{#1\fextra@}\else"9
"2
 \ifx\next.\def\next@{#1\,}\else\extra@
 \ifextra@\def\next@{#1\,}\else
 \let\next@"9="9#1\fi\fi\fi\fi"9\fi"9\next@}
**
The boxed *=* sign in this code
 is another case (compare page~\ref{NEEDEQ}) where
the  *=*~ sign  cannot be omitted, though now the reason
is different: we might have *#1* being an *=* sign!
There are similar required *=*'s in
 the (original) definitions
of
 *\boldsymbol@*, *\boldkeydots@*, and *\boldsymboldots@*, and
in the new definition of *\boldkey*, to follow. These *=* signs
and the one in the definition of *\ismember@* are the only ones that
actually occur after a *\let* in *lamstex.tex*.

Similarly, the definitions of *\dotsc* and *\keybin@* are deleted from
\linebreak
*amstexl.tex*, and in *lamstex.tex* we add
\C**
\def\dotsc{\def\next@{\ifx\next;\plainldots@\,\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\plainldots@\fextra@\else"9
  \ifx\next.\plainldots@\,\else\extra@\plainldots@
  \ifextra@\,\fi\fi\fi"9\fi"9}%
 \futurelet\next\next@}
"slip
\def\keybin@{\keybin@true  
 \ifx\next+\else\ifx\next=\else\ifx\next<\else
 \ifx\next>\else\ifx\next-\else\ifx\next"1\else
 \ifx\next:\else
 "9\expandafter\ifx\csname A@\string;\endcsname\next\else"9
 \keybin@false\fi\fi\fi\fi\fi\fi\fi"9\fi"9}
**

The definition of *\boldkey#1* is also deleted from
*amstexl.tex*.\pagelabel{NEWBK}  
In this
case, where we have a control sequence with an argument, rather than one
that has picked up the next token with a *\futurelet\next*, 
and where our tests are of the form
**
\ifx#1!
**
we have to start with
**
\let\next=#1
**
so that we can then use things like 
**
\expandafter\ifx\csname A@\string!\endcsname\next
**
to check for an active~*!*.
The new code is:
\C**
\def\boldkey#1{\ifcat\noexpand#1A%  
  \ifcmmibloaded@{\fam\cmmibfam#1}\else
   \Err@{First bold symbol font not loaded}\fi
"2
 \else
 \let\next"9="9#1%  
"2
 \ifx#1!\mathchar""5\bffam@21 \else
 "9\expandafter\ifx\csname A@\string!\endcsname\next"9
  "9\mathchar""5\bffam@21 \else"9
"2
 \ifx#1(\mathchar""4\bffam@28 \else
"2
 \ifx#1)\mathchar""5\bffam@29 \else
"2
 \ifx#1+\mathchar""2\bffam@2B \else
"2
 \ifx#1:\mathchar""3\bffam@3A \else
 "9\expandafter\ifx\csname A@\string:\endcsname\next"9
  "9\mathchar""3\bffam@3A \else"9 
"2
 \ifx#1;\mathchar""6\bffam@3B \else
 "9\expandafter\ifx\csname A@\string;\endcsname\next"9
  "9\mathchar""6\bffam@3B \else"9
"2
 \ifx#1=\mathchar""3\bffam@3D \else
"2
 \ifx#1?\mathchar""5\bffam@3F \else
 "9\expandafter\ifx\csname A@\string?\endcsname\next"9
  "9\mathchar""5\bffam@3F \else"9
"2
 \ifx#1[\mathchar""4\bffam@5B \else
"2
 \ifx#1]\mathchar""5\bffam@5D \else
"2
 \ifx#1,\mathchari@63B \else
"2
 \ifx#1-\mathcharii@200 \else
"2
 \ifx#1.\mathchari@03A \else
"2
 \ifx#1/\mathchari@03D \else
"2
 \ifx#1<\mathchari@33C \else
"2
 \ifx#1>\mathchari@33E \else
"2
 \ifx#1"1\mathcharii@203 \else
"2
 \ifx#1|\mathcharii@06A \else
"2
 \ifx#10\bold0\else\ifx#11\bold1\else\ifx#12\bold2\else
"2
 \ifx#13\bold3\else\ifx#14\bold4\else\ifx#15\bold5\else
"2
 \ifx#16\bold6\else\ifx#17\bold7\else\ifx#18\bold8\else
"2
 \ifx#19\bold9\else
  \Err@{\noexpand\boldkey can't be used with #1}%
 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi"9\fi\fi\fi\fi"9}
**



\chapter Numbering styles\endchapter

 Next we define the standard \lamstex\ numbering
styles: *\arabic*, *\alph*, *\Alph*,
*\roman*,  *\Roman*, and *\fnsymbol*.  

These numbering styles are meant to be 
applied to a {\it number}, not to a counter (in the \lamstex\ macros they
are
usually  applied to
*\number*\<counter\> for some \<counter\>).
*\arabic* is consequently quite trivial:
\C**
\def\arabic#1{#1}
**

The definition of *\alph#1* uses the fact that the 
lower-case letters a--z have positions
*97*--*122*
 (if some one were to design a perverse font for which this wasn't
true, then *\alph* would have to be defined differently).

*\alph* begins by setting the scratch counter 
*\count@* to the value of *#1*:
**
\def\alph#1{\count@=#1\relax
**
We always add the *\relax* as a precaution in such situations,
 even if it may not be strictly
necessary ({\it The \tex book}, page~208, recommends a space, but *\relax*
seems best, to avoid any anomalous situations where an unwanted space might
somehow intrude itself into the token stream).


Then we add *96* to the value of *\count@* and we print the character
\linebreak
*\char\count@*,
but we give an error
message if this would give us a character past *122* (this could easily
happen if some one caused the counter to be augmented more than 25~times):
\C**
\def\alph#1{\count@=#1\relax\advance\count@ by 96 
 \ifnum\count@>122 \Err@{\noexpand\alph invalid for 
  numbers > 26}\else\char\count@\fi}
**
(See section~\Sref{SACN} for the use of *\noexpand\alph* rather than
*\string\alph*.)



We don't bother giving an error message if *\count@* ends up having a value
less than *97*, 
since  reasonable
macros will normally start the counter for a particular
construction at *1*. (So there is the possibility that some one will
perversely *\Reset* some construction to *0*, say, and then have
*\alph* produce a left quotation mark *`*! If this really seems
bothersome,
another check can easily be added to the code.)

The definition 
\C**
\def\Alph#1{\count@=#1\relax\advance\count@ by 64 
  \ifnum\count@>90 \Err@{\noexpand\Alph invalid for 
  numbers > 26}\else\char\count@\fi}
**
is exactly analogous, using the fact that the letters A--Z should have the
positions *65*--*90*.

For *\roman* we just have to
\C**
\def\roman#1{\romannumeral#1\relax}
**
since \tex\ provides the *\romannumeral* primitive. (The *\relax* is
essential here; otherwise something like
*\roman{10}3* would be expanded into
*\romannumeral103*,
giving the  result `ciii'.)

But *\Roman* is more complicated,
\C**
\def\Roman#1{\uppercase\expandafter{\romannumeral#1}}
**
Here the *\expandafter* causes expansion after the left brace *{*. 
Without the *\expandafter*, something like *\Roman3* would become
**
\uppercase{\romannumeral3}
**
which is just 
*\romannumeral3*,
and thus  `iii'.  With the
 *\expandafter*, we get
\setbox0\hbox{\<expansion of {\tt\bs romannumeral3}\>}
**
\uppercase{"box0}
**
i.e., 
*\uppercase{iii}*,
or `III'.

Note that we don't need to add *\relax* after  the *#1* in 
his definition,
because *\romannumeral#1* is expanded within the
*\uppercase{...}*.

Finally, we have
the *\fnsymbol* numbering style. As the code below shows,
 *\fnsymbol#1* successively sets
\Reset\tag1
$$\align\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}\tag\\
\hbox{\tt\bs count\@}&=\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
 \right]\tag\\
\hbox{\tt\bs count\@\@\@}&=\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
\right]+\hbox{1}\tag\\
\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}-\hbox{7}
 \cdot\left[\frac{\hbox{\tt\#1}-\hbox{1}}{\hbox{7}}
   \right].\tag\endalign$$

Hence 
$$
\hbox{\tt\bs count\@\@}=\cases
 \hbox{1}&\hbox{for \tt\#1}=\hbox{1}, \hbox{8}, \hbox{15},\dotsc{}\\
 \hbox{2}&\hbox{for \tt\#1}=\hbox{2}, \hbox{9}, \hbox{16}, \dotsc{}\\
 \hdots\\
 \hbox{7}&\hbox{for \tt\#1}=\hbox{7}, \hbox{14}, \hbox{21}, \dotsc{}\\
\endcases$$
so *\count@@* tells which of the symbols
\ast, \dag,  \ddag, \P,
\S, $\|$, \# should be printed, namely,
\ast~ for $\hbox{\tt\bs count\@\@}=
\hbox{1}$,
\dag~ for $\hbox{\tt\bs count\@\@}=\hbox{2}$, etc.

On the other hand,
$$
\hbox{\tt\bs count\@\@\@}=\cases
 \hbox{1}&\hbox{for \tt\#1}=\hbox{1},\dots,\hbox{7}\\
 \hbox{2}&\hbox{for \tt\#1}=\hbox{8},\dots,\hbox{14}\\
 \hdots\endcases$$
so *\count@@@* is the number 
 of times that this  symbol  has to be printed.
To print the symbol this many times,
 we use a loop, initially setting the counter *\count@* to
*\count@@@*:
\C**
\def\fnsymbol#1{\count@=#1\relax
 \count@@=\count@ 
"2
 \advance\count@ by -1  \divide\count@ by 7 
"2
 \count@@@=\count@ \advance\count@@@ by 1
"2
 \multiply\count@ by 7 \advance\count@@ by -\count@ 
"2
 \count@=\count@@@
 {\loop
  \ifcase\count@@\or"1\or\dag\or\ddag\or\P\or\S\or
   \text{$\|$}\or\#\fi
  \advance\count@ by -1 \ifnum\count@>0 \repeat}}
**

\amstex\ has already defined *\dag*, *\ddag*, *\P*, and *\S*, so 
that they can be used either in text or in math mode, where they will
change size properly; *\text{$\|$}* simply does the same for the
$\|$ symbol (*\#* needs no special treatment).
Modifications of *\dag*, \dots\ may be necessary for fonts with different
layouts. 


 In the above definition we
 put the *\loop* inside a group just in case *\fnsymbol*
happens to be used inside some *\loop* itself,   a somewhat
finicky precaution, since
a nested *\loop* involving
*\fnsymbol* will 
never be produced by any \lamstex\ construction. The same
precaution will be used
for any \lamstex\ *\loop* that might conceivably occur within
another *\loop*.\pagelabel{POSSLOOP}




\chapter Printing cardinal and ordinal numbers\endchapter

This chapter is in some sense a companion to the previous one.


First we define *\cardnine@#1*
for printing the final part of the name of a cardinal number; it will be
applied to a counter with a value from *1*, \dots, *9*:
\C**
\def\cardnine@#1{\ifcase#1\or one\or two\or 
 three\or four\or five\or six\or seven\or eight\or nine\fi}
**

The number *10* will be used so often in the macros of this chapter
 that
we want to use *\newcount* to
introduce a counter having that value.

As we mentioned in section~\Sref{NEWNEW},
*amstex.tex* (and *amstexl.tex*) redefine
 *\alloc@*  so that it doesn't write anything to the *.log* 
file; and
**
\let\alloc@@=\alloc@
**
is used 
so that *\alloc@@* is {\it that\/} version of *\alloc@*, even if called
after *\alloc@* has been restored to the old definition from *plain*
\tex\ at the end.\pagelabel{NEWALLOC2}
We now want to reinstate the new definition until
the end of *lamstex.tex*. Instead of redefining it directly, we just have
to 
\C**
\let\alloc@=\alloc@@    "8NEWALLOC"8
**
since *\alloc@@* was permanently given the new definition.

Since *\newcount* is defined in terms of *\alloc@*, which we have just made
equivalent to *\alloc@@*, the next code
\C**
\newcount\ten@
\ten@=10
**
does not produce anything in the *.log* file of a file that has *\input
lamstex* (nor will any of the other *\new...* constructions to follow).

Although *\cardinal{...}* will normally be applied when *...* is
a number, to be on the safe side, we first safely store the value in
a counter,
**
\def\cardinal#1{\count@=#1\relax
**
and then proceed by cases. 
\C**
\def\cardinal#1{\count@=#1\relax
 \ifnum\count@>99 \number\count@
 \else
  \ifnum\count@=0 zero%
  \else
   \ifnum\count@<\ten@ \cardnine@\count@
   \else
    \ifnum\count@<20
     \advance\count@ by -\ten@
     \ifcase\count@ ten\or eleven\or twelve\or
      thirteen\or fourteen\or fifteen\or sixteen\or
      seventeen\or eighteen\or nineteen\fi
"2
    \else
     \count@@=\count@ \count@@@=\count@@
"2
     \divide\count@ by \ten@ \multiply\count@ by \ten@
     \advance\count@@@ by -\count@ 
     \divide\count@ by \ten@
"2
     \ifcase\count@\or\or twenty\or thirty\or forty
      \or fifty\or sixty\or seventy\or eighty\or ninety\fi
"2
     \ifnum\count@@@=0 \else-\cardnine@\count@@@\fi
    \fi
   \fi
  \fi
 \fi}
**

Thus, 
if $\hbox{*#1*}>\hbox{99}$, we simply typeset this number. 
If  $\hbox{*#1*}=\hbox{0}$,
we simply typeset `zero'. If $\hbox{0}<\hbox{*#1*}<\hbox{10}$, we just use
*\cardnine@* to print the number. For $\hbox{10}<\hbox{*#1*}<\hbox{20}$,
 we
must explicitly specify `ten', \dots, `nineteen'.

\Reset\tag1
Finally, for $\hbox{20}<\hbox{*#1*}<\hbox{99}$,
 we have to do a little calculation.
The next code successively  sets
$$\spreadlines\jot\align
\hbox{\tt\bs count\@\@\@}=\hbox{\tt\bs count\@\@}&=\hbox{\tt\#1}\tag\\
\allowdisplaybreak
\hbox{\tt\bs count\@}&=\hbox{10}\cdot\left[\frac{\hbox{\tt\#1}}{\hbox{10}}
 \right]\tag\\
\allowdisplaybreak
\split\hbox{\tt\bs count\@\@\@}&=\hbox{\tt\#1}-\hbox{10}\cdot
 \left[\frac{\hbox{\tt\#1}}{\hbox{10}}\right]\\
 &=\hbox{\tt\#1}\pmod{\hbox{10}}\endsplit\tag\\
\allowdisplaybreak
\hbox{\tt\bs count\@}&=\left[\frac{\hbox{\tt\#1}}{\hbox{10}}
 \right]\tag\endalign$$
The first part of the word for *#1* is `twenty' if $\hbox{\tt\#1}=
\hbox{20},\dots,\hbox{29}$, and hence *\count@=2*; it is `thirty' if
$\hbox{\tt\#1}=\hbox{30},\dots,\hbox{39}$, and hence *\count@=3*; etc.
  If $\hbox{*\count@@@*}=0$ the name is
complete; otherwise we must add `-one', `-two', \dots, depending on the
value of *\count@@@*.

\medskip

*\ordnine@*, for ordinal numbers, is
exactly analogous to *\cardnine@*:
\C**
\def\ordnine@#1{\ifcase#1\or first\or second\or
 third\or fourth\or fifth\or sixth\or seventh\or
 eighth\or ninth\fi}
**

The ordinal numbers $<\hbox{100}$  can be treated in a manner exactly like
the cardinal numbers.  But a problem arises for ordinal numbers like
`100th', `101st', `102nd', `103rd', \dots, `109th', `110th', `111th', 
`112th', \dots---now
the proper suffix depends not only on the last digit of the number, but
also  on whether the next-to-last digit is a~*1*. 


The routine *\ordsuffix@* selects the right suffix in these cases,
assuming that the number in question has been stored in *\count@*.
The first part of the routine below divides *\count@* by~10, and then
calculates *\count@@@* to be $\hbox{*\count@*}\pmod{\hbox{10}}$ 
[compare the
previous calculations for *\cardinal*].
If this is~1, so that
the next-to-last digit of the number in *\count@* was~1,
 `th' is selected. 
Because the original value of *\count@* is needed for the second part of the
routine, we need to store it in yet another counter, *\count@@@@*,
which we have to
declare.

This second part simply computes
*\count@@@* as $\hbox{*\count@*}\pmod{\hbox{10}}$
 [for the original value of
*\count@*]; if this second part of the routine ends up being invoked,
the correct choice of the suffix depends only on this value of *\count@@@*:
\C**
\newcount\count@@@@
"slip
\def\ordsuffix@{\count@@@@=\count@
 \divide\count@ by \ten@
 \count@@@=\count@ \count@@=\count@
"2
 \divide\count@@ by \ten@ \multiply\count@@ by \ten@ 
 \advance\count@@@ by -\count@@
"2
 \ifnum\count@@@=1 th%
"2
 \else
  \count@@@=\count@@@@
  \count@@=\count@@@@ 
  \divide\count@@ by \ten@ \multiply\count@@ by \ten@
  \advance\count@@@ by -\count@@
  \ifcase\count@@@ th\or st\or nd\or rd\else th\fi
 \fi}
**

*\nordinal* and *\spordinal*  are easy, since they are
 simply a number followed by
the proper suffix, or the suffix superscripted:
\C**
\def\nordinal#1{\count@=#1\relax\number\count@\ordsuffix@}
\def\spordinal#1{\count@=#1\relax\number\count@
  $^{\text{\ordsuffix@}$}
**

And *\ordinal* itself simply mimics *\cardinal*, using
*\ordsuffix@* for numbers $\ge\hbox{100}$:
\C**
\def\ordinal#1{\count@=#1\relax
 \ifnum\count@>99 \number\count@\ordsuffix@
 \else
"2
  \ifnum\count@=0 zeroth%
  \else
"2
    \ifnum\count@<\ten@ \ordnine@\count@
    \else
"2
     \ifnum\count@<20 \advance\count@ by -\ten@
      \ifcase\count@ tenth\or eleventh\or twelfth\or 
       thirteenth\or fourteenth\or fifteenth\or sixteenth\or
       seventeenth\or eighteenth\or nineteenth\fi
     \else
"2
      \count@@=\count@ 
      \divide\count@ by \ten@ \multiply\count@ by \ten@
      \count@@@=\count@@ \advance\count@@@ by -\count@ 
      \divide\count@ by \ten@
      \ifcase\count@\or\or twent\or thirt\or fort\or fift\or 
       sixt\or sevent\or eight\or ninet\fi
      \ifnum\count@@@=0 ieth\else y-\ordnine@\count@@@\fi
     \fi
    \fi
  \fi
 \fi}
**


\chapter Inhibiting expansion\label{noexpands}\endchapter

There are numerous situations where we want to suppress expansion, during
both *\write*'s and *\edef*'s or *\xdef*'s,
 of the
numbering control sequences *\arabic*, *\alph*, \dots\ as well as the
font change control sequences *\rm*, *\it*, *\bf*, 
\dots. The latter includes
*\smc*, which may not have been defined yet, so we take care of that
first:
\C**
\font@\tensmc=cmcsc10
\textonlyfont@\smc\tensmc
**
[For the details of *\font@* and *\textonlyfont@* see *amstex.doc*
(and also page~\ref{FL});
basically, this is like saying *\font\tensmc=cmcsc10* and
*\def\smc{\tensmc}*.]



We introduce a new token list
\C**
\newtoks\noexpandtoks@
**
which will be a  list of commands, and
then
*\noexpands@* will issue these commands by inserting this token list:
\C**
\noexpandtoks@={\let\arabic=\relax\let\alph=\relax
 \let\Alph=\relax\let\roman=\relax\let\Roman=\relax
 \let\fnsymbol=\relax\let\rm=\relax\let\it=\relax
 \let\bf=\relax\let\sl=\relax\let\smc=\relax
 \let\/=\relax\let\null=\relax}
"slip
\def\noexpands@{\the\noexpandtoks@}
**

It is easy to define the
construction *\Nonexpanding#1*, which is supposed to make
*\let#1=\relax* also be executed:
\footnote{In  version~*1* of \lamstex@, this was called *\Noexpand*,
but that seems too close to  *\noexpand* for comfort.}
\C**
\def\Nonexpanding#1{\global\noexpandtoks@
 =\expandafter{\the\noexpandtoks@\let#1=\relax}}
**

*\let\/=\relax* was added to *\noexpandtoks@*
 because *\/* will often occur in ``style''
commands (pages~\ref{ic1}, \ref{ic2}, \ref{tagit}, et al\.) that appear in
*\edef*'s or
*\xdef*'s and *\write*'s\pagelabel{IC} (pages~\ref{necc},
 \ref{GGGG},
 et al\.) and *\/* is
no longer a primitive in \amstex\ or \lamstex\ (page~\ref{itcorr}).
Similarly *\let\null=\relax* was added because *\null* sometimes occurs in
``style'' commands (see page~\ref{NULLSTYLE}, for example).


\chapter Invisibility\label{invis}\endchapter

\section{Invisible constructions}
All constructions that are supposed to be ``invisible'' (the most important
examples being
 *\label* and
*\pagelabel*)
 begin with
*\prevanish@*. If we are in horizontal mode, this
 sets *\saveskip@* (a glue register declared in \amstex)\ to
be the previous glue, and then removes that glue.
Otherwise, it simply sets *\saveskip@* to *0pt*.
\C**
\def\prevanish@{\saveskip@=0pt
 \ifhmode\saveskip@=\lastskip\unskip\fi}
**

``Invisible'' constructions end with *\postvanish@*, which puts back
the *\saveskip@* glue, if greater than zero;
\footnote{We don't want to add *\hskip\saveskip@* when *\savekskip@*
is zero, because that case can occur when there is {\it no\/} previous glue: 
adding *\hskip\saveskip@* might then allow a break where none was 
allowed before.}
 it must also look ahead to see if the
next token is a space, and swallow up that space if  the *\saveskip@* glue
was greater than zero:
\C**
\def\postvanish@{\ifdim\saveskip@>0pt\hskip\saveskip@\fi
 \futurelet\next\postvanish@@}
\def\postvanish@@{\def\next@.{}%
 \ifx\next\space@\ifdim\saveskip@>0pt\def\next@. {}\fi\fi 
  \next@.}
**
Here we use the method of page~\ref{swallow}.
Note that we {\it don't\/} want to use *\FNSS@* (section~\Sref{FIX})
in this special situation, since we want to eliminate the space only when
*\saveskip@* is greater than zero.

[It is important to note that *\saveskip@* appears only in these
definitions, except for certain \amstex\ constructions that
will not ever appear within an ``invisible'' construction. So we don't
 have to worry about the value of *\saveskip@* being clobbered before
*\postvanish@* is applied.]


These constructions allow us to define the general construction to make
anything ``invisible'':
\C**
\def\invisible#1{\prevanish@\ignorespaces#1\unskip
 \postvanish@}
**
(Notice that, because of the *\ignorespaces* and *\unskip*,
the remark in the \lamstex~Manual on page~32, lines~6--8, is incorrect.)


We will need a list, *\vanishlist@*, of all invisible constructions; this
will be a list of the sort discussed in section~\Sref{LISTS}.  We initialize
it as: 
\C**
\def\vanishlist@{\\\invisible}
**

\section{Special considerations for invisible constructions\label{ZZZ}}
 If we have a
construction like
**
\par
\invisible{...}" Some text
**
then the *\prevanish@* in *\invisible* sets *\saveskip@* to *0pt*.
Consequently, the *\postvanish@* will {\it not\/} delete the following
space token that precedes `*Some text*'. But this space token is ignored
in vertical mode ({\it The \tex book}, page~282), so we don't get an extra
space before ``Some text''.  

The situation is quite different, however, if we have
**
\par
\noindent \invisible{...}" Some text
**   
because now the space token is not ignored, since it is 
encountered in horizontal mode; consequently, we will get an extra space
before ``Some text''.

In \amstex\ and \lamstex@, the combination *\par\noindent* has the special
abbreviation *\flushpar*.  We can avoid this difficulty with invisible
constructions by redefining *\flushpar* as
**
\def\flushpar{\par\noindent\futurelet\next\pretendspace@}
**
where *\pretendspace@* simply inserts *\hskip-1pt\hskip1pt* (preceded by
*\nobreak* just as a precaution) when *\next* is something in
*\vanishlist@*: 
**
\def\pretendspace@{\ismember@\vanishlist@\next
 \iftest@\nobreak\hskip-1pt\hskip1pt\fi}
**
[A precautionary *\relax* after the *\hskip1pt* is not needed here---the
*\fi* will stop the scanning of *\hskip*.]

As a result of this definition, 
**
\flushpar\invisible{...}" "0
**
becomes
**
\par\noindent\nobreak\hskip-1pt\hskip1pt\invisible{...}" "0
**
(and similarly for *\flushpar\label{...}*, and any other ``invisible''
constructions
that we will eventually define, and add to *\vanishlist@*).

Consequently,
 the *\prevanish@* removes the *\hskip1pt* and then sets\linebreak
 *\saveskip@* to
*1pt*. Then the *\postvanish@* adds back the *\hskip1pt* once again,
canceling out the *\hskip-1pt*.  Moreover, since *\saveskip@* is now
positive, the space token after the *\invisible* will be thrown away, so
that *\invisible{...}* will really be invisible.
\footnote{If some one has typed *\define\foo{\invisible{...}}* and then
used *\flushpar\foo*, this presents no problem, since in this case no space
after *\foo* will appear. (But, of course, *\define\foo/{\invisible{...}}*
would make `*\flushpar\foo/" *' behave incorrectly; this didn't seem worth
worrying about!)}

Note, by the way, that *\ismember@* was defined in such a way that
 the test *\ismember@\vanishlist@\next* sets *\iftest@* to be true when
*\next* has been *\let* equal to a
 control sequence in *\vanishlist@*
(page~\ref{ISFL}).




[In the above definitions, 
it might seem that we could simply add the\linebreak
 *\hskip-1pt\hskip1pt* in all cases.
But that wouldn't quite work, because the next construction might begin with
an *\unskip* (e.g., *\linebreak* or *\dots*). Aside from such a case, however,
the *\hskip-1pt\hskip1pt* doesn't do any harm.\pagelabel{NOHARM}]

Since some users might type *\noindent* instead of *\flushpar*, we might
as well add the *\futurelet\next\pretendspace@* to *\noindent* also.
\C**
\let\noindent@=\noindent   "8NOIN"8
\def\noindent{\par\noindent@\futurelet\next\pretendspace@}
"slip
\def\pretendspace@{\ismember@\vanishlist@\next
 \iftest@\nobreak\hskip-1pt\hskip1pt\fi}
"slip
\let\flushpar=\noindent
**




\smallskip
*\pretendspace@* will be needed at several other points in \lamstex\ 
(sections~\Sref{pretend1}, \Sref{item}, et~ al.).
\medskip

In *amstexl.tex* we delete the definition of *\flushpar*, since
it will be replaced with this new definition. 

\chapter Special considerations for \CS{everypar}\label{EVPAR}\endchapter
Numerous \lamstex\ constructions use *\noindent@* to start an unindented
paragraph. If some
**
\everypar={...}
**
has been specified in the document, these unindented paragraphs would also
start with the *\everypar* tokens, which is normally not desired.

Although this might be regarded as a
 rather paranoid concern, since *\everypar*'s should
presumably be used only within some region of the document that contains only
text, \lamstex\ contains a special construction to deal with this problem.

First we introduce a new token list
\C**
\newtoks\everypartoks@
**
and then we define
\C**
\def\noindent@@{\par
 \everypartoks@=\expandafter{\the\everypar}\everypar={}%
 \noindent@\everypar=\expandafter{\the\everypartoks@}}
**
Thus, *\noindent@@* 
\list
\item ends the previous paragraph,
\item stores the current value of *\everypar* in *\everypartoks@*,
\item sets *\everypar* to be empty, and
\item starts an unindented paragraph, which
\item resets *\everypar* to its original value for the {\it next\/}
paragraph.
\endlist
Note that the original value of *\everypar* will {\it not\/} be inserted
before the *\noindent@*'ed paragraph, because it gets the value *{}*
that was current when the *\noindent@* was encountered.

In \lamstex@, *\noindent@@* will usually be used instead of *\noindent*, 
with a 
*\futurelet\next\pretendspace@*  added when an invisible construction might
follow. 



\chapter \CS{page}\label{PG}\endchapter

In \lamstex\ the control sequence *\page* can be manipulated like *\tag*,
*\claim*, etc. Thus, we can use *\Reset\page*, *\newpre\page*, \dots .
But we want *\page* by itself to give an error message:
\C**
\def\page{\Err@{\noexpand\page has no meaning by itself}}
**
(Again, see section~\Sref{SACN} for the use of *\noexpand*.)

As we will see in Chapter~\ref{LBL1}, associated with the \lamstex\
construction *\tag* we have
\setbox0\hbox{the counter associated with *\tag*}%
\setbox1\hbox{the ``pre'' material for *\tag*}%
\setbox2\hbox{the ``post'' material for *\tag*}%
\setbox3\hbox{the style for *\tag*}%
\setbox4\hbox{the numbering style for *\tag*}%
\setbox5\hbox{the font for *\tag*}%
**
\tag@C  "box0 
\tag@P  "box1
\tag@Q  "box2
\tag@S  "box3
\tag@N  "box4
\tag@F  "box5
**
Likewise, *\claim* and all other \lamstex\ constructions that can be given
a \<label\> have similar counters and control sequences associated with them.

At present, we simply want to consider the counter and control sequences
associated to *\page*.  For *\page@C* we just use *plain* \tex's 
*\pageno*
\C**
\let\page@C=\pageno
**
and then we introduce default values (*\empty* is defined in *plain.tex*
by *\def\empty{}*, so *\let\page@P=\empty* is just a briefer way of 
saying *\def\page@P{}*):
\C**
\let\page@P=\empty
\let\page@Q=\empty
"2
\def\page@S#1{#1\/} "8ic1"8
\def\page@F{\rm}
\def\page@N{\arabic}  % cannot be \let
**


The *\/* in *\page@S* might be useful if *\page@F* is ever chosen to be
a slanted font.

We want to have
*\def\page@F{\rm}* rather than *\let\page@F=\rm*, because *\rm* may
actually change definitions.\pagelabel{pagef}
  For example, 
**
\fontstyle\page{...}
**
 expands
out (page~\ref{FS}) to
**
{\page@F...}
**
and if we are in 9-point type at the time, we would expect to get 9-point
roman type, not the 10-point roman type that is in effect at the time that
*\page@F* is specified.

And, as we will see later (page~\ref{SUB}), it is even more critical
that we have *\def\page@N{\arabic}* rather than
*\let\page@N=\arabic*. 


\chapter Indexing\label{INDX}\endchapter

The indexing macros were placed next, because they use the
fact that *""* is active in \lamstex@, and we would like to get this
declared soon, so that any *""* appearing in other macros will refer to
this active *""*. Some of the methods used here will also be crucial in
Chapters~\ref{HLS} and ~\ref{PI}.

It should be noted that in version~*1* of \lamstex@, the index entries were
written to one file, with the extension~ *.ndx*, while the corresponding page
numbers were written to another file, with the
extension~*.npg*.\pagelabel{OLDV}  That has all
changed, however, and now the entry and the page number are written together 
to the *.ndx* file.  Similarly,
as we will see in Chapter~\ref{HLS}, heading levels will be written
together with their page
numbers in the *.toc* file, and as we'll see in Chapter~\ref{PI}, Figures,
Tables, etc., will be written together with their page numbers in one file.


\section{The {\tt.ndx} file}
We will need a flag,
\C**
\newif\ifindexing@
**
to tell whether an index file is being made.

*\indexfile* will (globally) set the flag *\ifindexing@* to be true
the first time it is used; it will also test this flag when called, so
that if it is called twice it will do nothing at all the second time.
The first time *\indexfile* is called, it should create a new
 output stream,
**
\newwrite\ndx@
**
associated with the file *\jobname.ndx* (where
*\jobname* will be `*foo*' when \tex\ is processing *foo.tex*).

Instead of using *\newwrite*,
we will just write the code for it instead, substituting *\alloc@@*
(page~\ref{NEWALLOC}) 
for
*\alloc@*:
\C**
\def\indexfile{\ifindexing@\else      "8INDEXFILE"8
 \alloc@@7\write\chardef\sixt@@n\ndx@  
 \immediate\openout\ndx@=\jobname.ndx
 \global\indexing@true\fi}
**
Then (compare section~\Sref{NEWNEW}),
since we used *\alloc@@* rather then *\alloc@*,
nothing will be written to the *.log* file,  even though
*\indexfile* is used after *\alloc@* itself has been redefined at the end
of *lamstex.tex*.

\section{\CS{indexproofing}}
We will need  an insertion class,  called *\margin@*,
for index entries that are to
appear in the margin if *\indexproofing* has been specified. So we would
like to say `*\newinsert\margin@*'.  But *\newinsert* is defined
differently than all other *\new...* constructions in 
*plain*, and it will
write something to the *.log* file, despite our redefinition of *\alloc@*.
So we instead simply restate everything from *plain*
in the definition of *\newinsert*
except for the
*\wlog* part:
\C**
\global\advance\insc@unt\m@ne
\ch@ck0\insc@unt\count
\ch@ck1\insc@unt\dimen
\ch@ck2\insc@unt\skip
\ch@ck4\insc@unt\box
\allocationnumber\insc@unt
\global\chardef\margin@\allocationnumber
**
Notice that although this takes up a lot of space in the file, it 
takes up hardly any space within \tex\ itself, just like
*\newinsert\margin@*.


We put no limit on the number of marginal notes on a page, and
they take up no space (compare {\it The \tex book}, page~415):
\C**
\dimen\margin@=\maxdimen
\count\margin@=0
\skip\margin@=0pt
**

The flag *\ifindexproofing@* will tell us whether *\indexproofing*
(and\slash or *\noindexproofing*) appears:
\C**
\newif\ifindexproofing@
\def\indexproofing{\indexproofing@true}
\def\noindexproofing{\indexproofing@false}
**


\section{Converting tokens to type {\tt 12}\label{UNMACRO}}
If a control sequence *\controlseq* has been defined by
\setbox0\hbox{\<parameter text\>}
\setbox1\hbox{\<replacement text\>}
**
\def\controlseq"box0{"box1}
**
(see {\it The \tex book}, page 203, for terminology), then the \tex\
primitive 
**
\meaning\controlseq
**
expands to
\setbox0\hbox{\<parameter text\>}
\setbox1\hbox{\<replacement text\>}
**
macro:"box0->"box1
**
where all non-space tokens are of type~*12*.  

The construction *\unmacro@* is used to store the \<parameter text\>
in *\macpar@* and the \<replacement text\> in *\macdef@*:
\C**
\def\unmacro@#1:#2->#3\unmacro@{\def\macpar@{#2}% 
 \def\macdef@{#3}}
**
In particular, if we 
**
\def\foo{#1}
**
where *#1* is  any text with balanced braces, and we do
**
\expandafter\unmacro@\meaning\foo\unmacro@
**
then
\footnote{There is no problem with *:* being part of the syntax of
*\unmacro@* even in a file where *:* has been made active (compare
section~\Sref{ALF}), because
 *\unmacro@* will always be used like this, to work on
some value of
*\meaning*.}
*\macdef@* will consist of *#1* {\it with all non-space
tokens converted to type~*12*}.

Some information is lost in the process: multiple spaces in *#1* coalesce to
single spaces in *\macdef@*,  control words in *#1* are followed by spaces
in *\macdef@* even if no spaces appear after them 
in *#1*, and line breaks in *#1*
 simply become spaces in *\macdef@*.
  So this method is not particularly useful for
literal mode, especially since it cannot be applied at all unless *#1* has
balanced braces.  Nevertheless, it alleviates considerably the problems
that arise when we want to *\write* the string *#1* to a file without having
control sequences expanded.  We simply have to write *\macdef@* instead!

More precisely, for some output stream, like *\ndx@*, instead of
using an\linebreak *\immediate\write* like
**
\immediate\write\ndx@{#1}
**
we can
**
\def\next@{#1}
\expandafter\unmacro@\meaning\next@\unmacro@
\immediate\write\ndx@{\macdef@}
**
For delayed *\write*'s we have to be more careful, since *\macdef@* may have
been redefined by the time the *\write* occurs.  Instead 
of
**
\write\ndx@{\macdef@}
**
we must use
**
\edef\next@{\write\ndx@{\macdef@}} "8WRITENDX"8
\next@
**
The *\nxd@* is not expanded in this *\edef*, since it was created with
*\chardef*; such control sequences aren't expanded in *\edef*'s.
\pagelabel{CHARDEFNE} Consequently, the *\edef* simply makes *\next@* mean
\setbox0\hbox{\<expansion of *\macdef@*\>}
**
\write\ndx@{"box0}
**
so that  *\next@* then produces this *\write*.

Notice that it is  irrelevant that we are writing type~*12* tokens
to the *.ndx* file: once they are written to that file their category codes
are completely irrelevant\pagelabel{wcodes}---if 
\tex\ reads this file later, they will simply
be given the category codes that are in force at the time.


\section{The \CS{starparts\@} and \CS{windex\@} routines}
In version *1* of \lamstex@, only invisible entries could have *"1* optional
entries, but now even visible entries can have them.  

We will use a construction *\starparts@#1* that determines if *#1* contains
a *"1* and defines
\setbox0\hbox{ to be }
\setbox1\hbox{all of *#1*}
\setbox2\hbox{the part of *#1* before the first *"1* (or all of *#1* if there
 is none)}
\setbox3\hbox{the part of *#1* after the first
 *"1* (or empty if there is none)}
**
"hskip-20pt\stari@    "copy0"0 "box1
"hskip-20pt\starii@   "copy0"0 "box2
"hskip-20pt\stariii@  "copy0"0 "box3
**
We begin by choosing the values that will hold when no *"1* appears:
**
"hskip-20pt\def\starparts@#1{\def\stari@{#1}\def\starii@{#1}\let\stariii@=\empty
 . . .
**
Then we perform a test that sets *\iftest@* to be true if *"1* appears in *#1*
and false if it doesn't (compare the definition of *\tagin@* in
section~\Sref{TESTS}):
**
\test@false
\def\next@##1"1##2##3\next@{\ifx\starparts@##2\test@false
 \else\test@true\fi}
\next@#1"1\starparts@\next@
**
If no *"1* appears we are done; otherwise we will have to call another
routine that separates the two parts:
\C**
\def\starparts@#1{\def\stari@{#1}\def\starii@{#1}%
 \let\stariii@=\empty
 \test@false
 \def\next@##1"1##2##3\next@{\ifx\starparts@##2\test@false
  \else\test@true\fi}%
 \next@#1"1\starparts@\next@
 \iftest@\def\next@{\starparts@@#1\starparts@@}%
 \else\let\next@=\relax\fi\next@}
"slip
\def\starparts@@#1"1#2\starparts@@{\def\starii@{#1}%
 \def\stariii@{"1#2}}
**

\medskip
Once our *""...""* and *""""...""* constructions, to be defined
in section~\Sref{MKI},
 have used *\starparts@*
to determine *\stari@*, *\starii@*, and *\stariii@*, we will use 
*\starii@* to typeset `*...*' in the case of a visible index entry, 
and then we will use
the
``write@-index'' routine *\windex@*.

When we are making an *.ndx* file, this routine will first
**
\expandafter\unmacro@\meaning\stari@\unmacro@
**
to convert `*...*' to type~*12* tokens. Then 
**
\edef\macdef@{\string""\macdef@\string""}
**
will add *""* at each end, for the sake of the *index* program; *\string""*
is needed since *""* will be active.

Then we will use the *\edef* of page~\ref{WRITENDX} to write these tokens
to the *.ndx* file.  This will be followed by the page number. Actually,
instead of writing just the page number, 
we  write 
four groups,
the first containing the page number, and the next
three containing the page numbering style, the ``pre-page'' material, and the
``post-page'' material (Chapter~\ref{PG}), 
**
\write\ndx@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}
**
This allows the  *index* program to
 deal with all sorts of special page numbering possibilities.

In addition, when *\ifindexproofing@* has been set true, we want to
**
\insert\margin@{\hbox{\rm\vrule \height9pt \depth2pt
 \width0pt ...
**
where the *\hbox* begins with a ``strut'', designed to keep baselines of
successive entries 11~points apart (see page~\ref{HWD} for the use of
*\height*, \dots).
\footnote{Perhaps \pagelabel{STRUTINSERT}
 this is a good place to mention something that
tends to be obscured in discussions about struts. Most \tex nicians are
familiar with struts as the device that allows one to place 
one *\vbox*
 above another and still have the proper space between the
bottom baseline of the top *\vbox* and top baseline of the bottom
*\vbox*.
 The problem here is that \tex\ will normally
insert only
*\lineskip* space between the two boxes, since the baseline of
the second box is so far from the baseline of the first.
  But the situation with regard
to *\footnote*'s, or members of other insertion classes,
 is really quite different:
\tex\ inserts {\it no interline glue whatsoever\/} between two different
members of an insertion class ({\it The \tex book}, page~125). Thus,
even single line footnotes will be spaced incorrectly without struts!
(Struts are discussed further in section~\Sref{VF}.)}


This *\hbox* should contain all material before any *"1* in `*...*'
typeset
in *\rm*, but all material after the first *"1* should be converted to 
type~*12* tokens, and typeset in the *\tt* font,
\footnote{Other styles (compare Part~\ref{SFPART}) may use smaller print for
these side notes.}
 since it contains things
like *"1e\it*, which are not supposed to be acted upon, but merely convey
information to the *index* program.



This is all accomplished with the following code:
\C**
\def\windex@{\ifindexing@
 \expandafter\unmacro@\meaning\stari@\unmacro@
 \edef\macdef@{\string""\macdef@\string""}%
 \edef\next@{\write\ndx@{\macdef@}}\next@
 \write\ndx@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}%   
 \fi
 \ifindexproofing@
  \ifx\stariii@\empty\else
   \expandafter\unmacro@\meaning\stariii@\unmacro@\fi
  \insert\margin@{\hbox{\rm\vrule \height9pt \depth2pt
   \width0pt \starii@
  \ifx\stariii@\empty\else\tt\macdef@\fi}}%
 \fi}
**

At the time that our *\write* is performed, we will want 
*\noexpands@* to be in effect, partly
 to prevent expansion of any font control sequences that might appear in
*\page@P* and *\page@Q*, but mainly because we want to be sure that
*\page@N* isn't expanded during the *\write*, since  the *index* program
expects to see a numbering control sequence in this second group.

 But there's no point putting
**
{\noexpands@
 \write\npg@{{\number\pageno}{\page@N}{\page@P}{\page@Q}}}
**
in our definition, because this delayed *\write* is simply added to the
main vertical list and does not take place until a *\shipout*.   Instead,
we will have to be careful to specify *\noexpands@* during any
*\shipout* (section~\Sref{SO}).\pagelabel{SUB1}

Nevertheless, this is an appropriate time to discuss the problems that
would be encountered if expansion were not prohibited.
Expansion  would clearly cause problems if *\page@N* is defined as *\alph*
or *\Alph*, but, in fact, for this particular *\write*,
 expansion would be a problem
even if *\page@N* is defined as *\arabic*, because 
  *\page@N* appears in a group by
itself---\tex\ would complain during the *\write* that
**
! Argument of \page@N has an extra }.
**

And here comes the most subtle point of all: If we 
 *\let\page@N=\arabic*, then our *\write* would not
put *\arabic* in place of *\page@N*, even if *\noexpands@* is in effect
when it takes place,
 and we would get the very same error
message.\pagelabel{SUB} That is
because *\page@N* would have the
{\it original\/} meaning of *\arabic*---although *\noexpands@* says
`*\let\arabic=\relax*', our *\page@N* would not be this *\arabic*!
On the other hand,
when we *\def\page@N{\arabic}*, the *\write* first expands *\page@N* to
(the current) *\arabic*, and then doesn't expand {\it this\/} *\arabic*
further.


\section{Indexing\label{MKI}}
 Now we are finally ready to make *""* active,
\C**
\catcode`\""=\active
**
and define the action of *""*.
As we have already noted (page~\ref{SW}),
the combination *@""* will still work when~ *""*~ is active.


First of all,
*""* will have to look ahead to see if it is followed by another
*""*, because this indicates an invisible entry:
\C**
\def""{\futurelet\next\quote@}
\def\quote@{\ifx\next""\expandafter\quote@@\else
 \expandafter\quote@@@\fi}
**
Note that we are using the ``K-method'' here (see section~\Sref{K}).


*\quote@@@*, the result when *""* isn't followed by
another *""*, so that we have a visible index entry, is simply defined as
\C**
\def\quote@@@#1""{\starparts@{#1}\starii@\windex@}
**
Thus, after *\starparts@* defines *\stari@*, *\starii@*, and *\stariii@*,
we typeset *\starii@*---the part before any *"1*---%
 and then  apply the ``write-index'' routine *\windex@*.

We should note that
as a consequence of the definition of *\quote@@@#1*, the indexed word
 *#1* may be followed by an *\insert* and/or a
 ``whatsit'', namely, the 
*\write* produced by *\windex@*.
But either an *\insert* or
a  ``whatsit'' can  appear {\it after\/}
a  word without suppressing hyphenation---%
 see {\it The \tex book}, third paragraph
from the bottom on page~454.   (This should be compared to the *\makexref*
macro on page~424 of {\it The \tex book}, where the *\insert*
appears {\it before\/} the word, and therefore suppresses hyphenation of
the word.)  Similarly, as we will see in a moment,
 an invisible index entry simply supplies an *\insert* and/or 
a *\write*. The warning on page~100 of the 
\lamstex~Manual
is therefore inaccurate: an invisible entry will suppress hyphenation of a
word only if it immediately precedes it, not if it follows it. Similarly, 
the warnings on pages~31 and~33 are inaccurate; only a *\label* or
*\pagelabel* immediately preceding a word will interfere with its
hyphenation---in particular, the example given on page~33 won't interfere
with hyphenation.

\medskip


*\quote@@* is not that much different from *\quote@*, except that we want it
to swallow the next *""*, and begin with *\prevanish@*, so that it will be
invisible:
\C**
\def\quote@@""#1""{\prevanish@\starparts@{#1}\windex@
 \futurelet\next\quote@@@@}
**
The *\futurelet\next\quote@@@@* is needed to see whether yet
another *""* occurs after the third *""* that caused all this to happen.
If a fourth *""* didn't occur, we insert the  *\postvanish@*,
and if a fourth *""* did occur, we simply swallow it up, and then
insert the
*\postvanish@*:
\C**
\def\quote@@@@{\ifx\next""\def\next@""{\postvanish@}\else
 \let\next@=\postvanish@\fi\next@}
**

\section{Changes to the \lamstex\ Manual}Because of changes in the indexing
macros, almost every caveat on page~101 of the \lamstex~Manual is wrong.


The first paragraph is wrong:
index entries within heading levels {\it will\/} show up in the margins when
*\indexproofing* has been specified. (Of course, one had better not
type something like
**
\HL1 ""Disappearing"" words\endHL
**
since *""Disappearing""* would then be interpreted as a ``quoted'' number for
*\HL1*\,! Something like *\HL1{}""Disappearing""* is needed.)

The third paragraph is wrong, because only the parts after the first *"1*
will be typeset in the typewrite font, with
 characters of type~*12*.

The fourth paragraph is wrong: *\""* can be used within an invisible entry.

The fifth paragraph is wrong: invisible entries can now appear anywhere.

It is true, as the final paragraph claims, that index entries in
*\footnote*'s 
won't appear in
the margin (they are *\insert*'s within an *\insert*, and won't migrate out).
However, no special efforts are required in the *\footnote* macros to get 
indexing to work within *\footnote*.

\section{Invisibility}
After all this, we  want to add *""* to *\vanishlist@*:
\C**
\rightadd@""\to\vanishlist@
**
This probably looks wrong, since it is only the double mark *""""* that
indicates an invisible entry, but 
**
\nobreak\hskip-1pt\hskip1pt""...""
**
and 
**
\nobreak\hskip-1pt\hskip1pt""""...""
**
will both work out just right: before the visible index entry *""...""*
the *\hskip-1pt\hskip1pt* will simply be irrelevant, while before an
invisible index entry *""""...""* it provides the right clues for the
*\prevanish@* called by *\quote@@* (compare 
page~\ref{NOHARM}).



\section{Other delimiters for index entries\label{OTHERD}}The 
use of *""* as a delimiter
for index entries conflicts with its use in German styles (this will
probably remain true even when the
international font layouts are in use, although then the *""* will
presumably no longer be active for German). However, it is not very hard to
set up other delimiters for this purpose.  

For example, suppose we want to use *<...>* delimiters, so that
**
Beauty<<beauty>> is <truth>.
**
will produce a index entry for *truth*, and an
 invisible index entry for *beauty*. 

For this, we could
**
\catcode`\<=\active
\let<=""  % we might as well continue using \quote@, ...
"slip
% \def""{...} if we have new definitions for German, or
% \catcode`\""=12 if "" should no longer be active
"slip
\def\windex@{\ifindexing@
 \expandafter\unmacro@\meaning\nextii@\unmacro@
 \xdef\nextii@{\string<\macdef@>}%
  . . .
 \fi}
"slip
\def\quote@{\ifx\next<\expandafter\quote@@\else
 \expandafter\quote@@@\fi}
\def\quote@@@#1>{\starparts@{#1}\starii@\windex@}
\def\quote@@<#1>{\prevanish\starparts@{#1}\windex@
 \futurelet\next\quote@@@@}
\def\quote@@@@{\ifx\next>\def\next@>{\postvanish@}\else
 \let\next@=\postvanish@\fi\next@}
**

The new version of the *index* program (see Chapter~\ref{IPROG}) now accepts
any delimiters in the *.ndx* file.  However, as Chapter~\ref{IPROG}
 points out,
for German alphabetization we
would probably want some modifications to deal with words with umlauts.

We should probably also remove *""* from *\vanishlist@*. There is no general
mechanism for removing something from *\vanishlist@*.  However, since
we know that *\vanishlist@* will be of the form
**
\\\invisible\\"" ...
**
we can
**
\def\next@\\\invisible\\""#1\next@{\def\vanishlist@{#1}}
\expandafter\next@\vanishlist@\next@
**
	
\small 
For consistency, it would probably be better to choose, once and for all,
index entry delimiters that could be used in all cases; *<...>* don't satisfy
that requirement, since Scandinavian keyboards have letters instead of *<*
and *>*. There aren't too many possibilities left, however! 
The only reasonable candidates are *_* and *|* (although *+* and *=* would
also be possible, if we insisted that people never used them outside of math
mode), and
**
Beauty||beauty|| is |truth|, truth beauty
**
doesn't look too bad.
  If only *|* weren't used for something else in German styles!)
\endsmall

\section{{\tt\bs idefine} and {\tt\bs iabbrev}\label{IDAA}}
A construction like
\setbox0\hbox{\<parameter text\>}\setbox1\hbox{\<replacement text\>}
**
\idefine\cs"copy0{"copy1}
**
has to 
**
\define\cs"copy0{"copy1}
**
and also send this definition
off to the *.ndx* file.

*\idefine* first 
 stores its argument, *\cs* say, in *\next@*, and also stores
*\noexpand\cs* in *\nextii@*, for later use:   %%%%%%%
**
 \def\next@{#1}\def\nextii@{\noexpand#1}%
**
Then we will apply the construction *\idefine@* once we
have suitably swallowed up the \<parameter text\> and \<replacement text\>:
\C**
\def\idefine#1{\def\next@{#1}\def\nextii@{\noexpand#1}%
 \afterassignment\idefine@\def\nextiii@}
**
Here the *\def\nextiii@* will cause the following \<parameter text\> and
\<replacement text\> to be digested into a definition of *\nextiii@*, after
which assignment we will apply *\idefine@*.

Since *\nextiii@* now has the definition that we want for *\cs*, 
the first thing *\idefine@* must do is to
**
\let\cs=\nextiii@
**
Since *\next@* was *\def*'ed to be *\cs*, we can do this with
**
\expandafter\let\next@=\nextiii@
**

Then, if we are indexing,
 we need to recover the \<parameter text\> and \<replacement text\>
for *\cs*, which is now that for *\nextiii@*.
So we use
**
\expandafter\unmacro@\meaning\nextiii@\unmacro@
**
[This  construction
 doesn't work if `*->*'  appears in the \<parameter text\> of a
definition, so let's hope no one ever makes such a definition.]

Now we want to write
\setbox0\hbox{\<parameter text\>}\setbox1\hbox{\<replacement text\>}
**
\define\cs"box0{"box1}
**
to the *.ndx* file. Since *\nextii@* was defined as *\noexpand\cs*,
we can do this with
**
\immediate\write\ndx@{\noexpand\define
 \nextii@\macpar@{\macdef@}}
**
---note that the *\write* will first expand *\nextii@* to
*\noexpand\cs*, and then replace this with *\cs*, unexpanded.
Since all tokens in *\macpar@* and *\macdef@* are type~12, we don't have
to worry about their
 expansion (and note the remark on page~\ref{wcodes}).



Thus, the definition of *\idefine@* reads:
\C**
\def\idefine@{\ifindexing@
 \expandafter\let\next@=\nextiii@
 \expandafter\unmacro@\meaning\nextiii@\unmacro@
  \immediate\write\ndx@{\noexpand\define\nextii@
   \macpar@{\macdef@}}\fi}
**

*\iabbrev* is  simpler.  Recall that *\iabbrev* must be used
in the form
**
\iabbrev"1\cs{...}
**
so we define
\C**
\def\iabbrev"1#1#2{\ifindexing@
 \toks@={#2}%
 \immediate\write\ndx@
  {\noexpand\abbrev"1\noexpand#1{\the\toks@}}\fi}
**
