10

I would like to know a list of all control sequences which are let equal to primitives in common formats. For plain TeX for instance, we would get the list

\endgraf % = \par
\endline % = \cr
\repeat  % = \fi
\bgroup  % = { so not quite a primitive
\egroup  % = }
\sp      % = ^
\sb      % = _
^^M      % (active character) = \par in \obeylines
         % (active space) = space in \obeyspaces
% (the \if... defined by \newif) = \iftrue or \iffalse
% (various control sequences) = \relax

while for other formats we would get longer lists (such as \@@par being \par in LaTeX2e, or \normalunexpanded being \unexpanded in ConTeXt).

I am more particularly interested in control sequences (and active characters) let equal to primitives which perform assignments (\def, \edef, \gdef, \xdef, \let, \futurelet, \chardef, \mathchardef, \countdef, \dimendef, \skipdef, \muskipdef, \toksdef, \read, \readline, \font), prefixes (\protected, \long, \outer, \global), and \afterassignment. I can further restrict myself to control sequences (and active characters) which are equal to one of the primitives in this list when TeX starts up with these formats preloaded.

Here is why I care: I just wrote some code which redefines the primitives listed above in order to track down assignments. This lets me list all commands defined in a document, and I have ideas on how to extract from that a list of all commands actually used in the document. However, a requirement is that I should hook into all commands which assign a new meaning to a token, that is, all control sequences and active characters let to one of the primitives in the list above. If I miss an alias for one of those primitives, all tokens defined using it will be missed.

  • What if a package redefines primitives? Some do. – egreg Jul 24 '14 at 9:40
  • @egreg No problem if my code is loaded before: tokens can still only be defined through \def and friends. Such a package necessarily copies \def et al to some control sequence. As long as it does not explicitly make sure that it has the primitive (as some of Heiko Oberdiek's packages do), it won't realize that what it copied contained my hooks. Say some package author does \def\xdef#1{\message{\string#1 defined}\global\edef#1} (a very bad idea, on its own, since prefixes won't work). Then \xdef\foo{} will use my \global and my \edef hence be logged correctly. – Bruno Le Floch Jul 24 '14 at 12:03
7

LaTeX2e answer.

In LaTeX2e, there are only two control sequences let to one of the "prefix and definition primitives" listed in the question.

\install@mathalphabet % = \gdef
\l@ngrel@x            % = \long or \relax in \@star@or@long

Next, let us list every control sequence or active character which is set equal to a primitive in the course of running LaTeX2e with no error, excepting primitives set equal to themselves in a roundabout way (such as \par being redefined then eventually going back to being the primitive \par thanks to \@@par).

% Expandable primitives
\@@input    % = \input
\if@tempswa % = \iftrue or \iffalse (and all other \newif switches)
\repeat     % = \fi
\do         % = \noexpand in \begin{document}
\protect    % = \string or \noexpand (or a macro)
\@@protect  % see \protect
\firstmark  % = \botmark in \@outputpage

% Non-expandable primitives
\frozen@everymath     % = \everymath
\frozen@everydisplay  % = \everydisplay
\mathgroup            % = \fam
\mathalpha            % = \mathord in \DeclareMathDelimiter
\@@underline          % = \underline
\@@hyph               % = \-
\@@italiccorr         % = \/
\mb@b                 % = \vss in \@imakepicbox
\mb@l                 % = \hss in \@imakepicbox and \@shortstack
\mb@r                 % = \hss in \@imakepicbox and \@shortstack
\mb@t                 % = \vss in \@imakepicbox
\hss                  % = \vss in \@iiiparbox
\unhbox               % = \unvbox in \@iiiparbox
\@upordown            % = \raise or \lower in \@sline
\@cite@ofmt           % = \hbox
\endline              % = \cr
\@@par                % = \par
\endgraf              % = \par
(active) ^^M          % = \par
\@@end                % = \end
\install@mathalphabet % = \gdef
\l@ngrel@x            % = \long (or \relax) in \@star@or@long
\@end@tempboxa        % = \endgroup
\@err@<74 spaces>     % = \errmessage in for old TeXs.
\c@errorcontextlines  % = \errorcontextlines
\@let@token           % \futurelet (various uses) to what follows
\reserved@a           % \futurelet in \hline to what follows
\reserved@b           % = items in \nocorrlist (could be primitives)
\reserved@d           % = #1 of \@ifnextchar
\reserved@e           % = \vadjust in \\ or \newline

The last five lines are included for completeness, but are all temporary definitions hence should not be a problem for anyone looking to hook into primitives. Finally, implicit character tokens, which are of no interest for primitive-hooking, but maybe for someone else.

\bgroup        % = {
\math@bgroup   % = \bgroup
\@@math@bgroup % = \bgroup
\egroup        % = }
\@sptoken      % = space
\sp            % = ^
\sb            % = _
\@sharp        % = # in \@array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.