You can't understand the definition of \@next
without looking also at the definition of \@xnext
and at an example of usage; the complete code is
\def\@next#1#2#3#4{\ifx#2\@empty #4\else
\expandafter\@xnext #2\@@#1#2#3\fi}
\def\@xnext \@elt #1#2\@@#3#4{\def#3{#1}\gdef#4{#2}}
and an example of usage is at line 5963
\@next\@marbox\@freelist{\global\count\@marbox\m@ne}%
{\@floatpenalty\z@
\@fltovf\def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}%
The second argument to \@next
should be a parameterless control sequence (due to the \ifx
test and the following \expandafter
). The macro \@freelist
is such a macro, used in connection with the float queues, and it is updated when a float is started or floats are flushed with \clearpage
. Its definition at startup is
\@elt\bx@A\@elt\bx@B\@elt\bx@C...\@elt \bx@R
that is, it lists the insertion classes pertaining to floats (here ...
denote similar tokens).
If \@freelist
contains nothing, the fourth argument is delivered; otherwise
\expandafter\@xnext\@freelist\@@\@marbox\@freelist{\global\count\@marbox\m@ne}\fi
remains on the input stream. So, assume \@freelist
is not empty and, for the sake of simplicity, it is the same as at startup. The \expandafter
makes TeX see
\@xnext\@elt\bx@A\@elt\bx@B\@elt\bx@C...\@elt \bx@R\@@\@marbox\@freelist{\global\count\@marbox\m@ne}\fi
Note that, in order for this to work, the first level expansion of the second argument to \@next
must begin with \@elt
. What's \@elt
? It's just a token usually defined to be \relax
, which is used to store ordered lists of tokens in the form \@elt<token1>\@elt<token2>...
that allows for list manipulations.
Now the definition of \@xnext
comes into play. It has a complex parameter text that can be described as follows:
\@elt
is expected just after the command
#1
means an undelimited argument, so just one token or a braced group, because it's immediately followed by #2
#2\@@
means a delimited argument, that is, TeX will substitute #2
with everything up to (and excluding) the first \@@
token it finds;
#3
and #4
are undelimited arguments (the same as for #1
applies).
In the context of delimited arguments, the delimiter tokens need not be defined; TeX looks for the exact sequence of tokens and control sequences are considered equal only if their names are the same.
The delimiters are removed from the input stream as part of macro expansion. So in this particular case, \@elt
is found and the search for the following arguments can start (\@elt
will be removed); argument #1
is \bx@A
; argument #2
is
\@elt\bx@B\@elt\bx@C...\@elt \bx@R
and arguments #3
and #4
are \@marbox
and \@freelist
respectively.
Expansion of \@xnext
makes all that code be replaced by
\gdef\@marbox{\bx@A}\gdef{\@freelist}{\@elt\bx@B\@elt\bx@C...\@elt \bx@R}
The two definitions are performed, which in particular shows how \@marbox
becomes equivalent to \bx@A
(the first insertion class) and \@freelist
is updated, essentially removing the first item. The dangling \fi
remaining disappears by general TeX rule (the expansion of \fi
is empty, provided it resulted from expansion of a previous conditional, which in this case was the \ifx
we started with).
The token \@@
is used in a very similar way, that is, as a pure delimiter, in the auxiliary macros for the loop functions \@for
and \@tfor
.
\@next
there as a token, then\@@
is a single token, it's no concatenation. It seems to be used as some sort of delimiter in arguments like\def\foo#1#2#3\@@#4{..}
.