ltdefns.dtx

Johannes Braams  David Carlisle  Alan Jeffrey
Leslie Lamport  Frank Mittelbach  Chris Rowley

Rainer Schöpf

1995/12/13

1 Definitions

This section contains commands used in defining other macros.

1 ⟨∗2ekernel⟩

1.1 Initex initialisations

\two@digits Prefix a number less than 10 with ‘0’.

 2 \def\two@digits#1{\ifnum#1<10 0\fi\number#1}

\typeout Display something on the terminal.

 3 \def\typeout#1{\begingroup\set@display@protect
 4  \immediate\write\@unused{#1}\endgroup}

\newlinechar A char to be used as new-line in output to files.

 5 \newlinechar`\^^J

1.2 Saved versions of TEX primitives

The TeX primitive \foo is saved as \@@foo. The following primitives are handled in this way:

\@@par
 6 \let\@@par=\par
 7 %\let\@@input=\input    %%% moved earlier
 8 %\let\@@end=\end        %%%

{\@@hyph \atop \-} The following comment was added when these commands were first set up, 19 April 1986: the \- command is redefined to allow it to work in the \ttfamily type style, where automatic hyphenation is suppressed by setting \hyphenchar to -1. The original primitive TEX definition is saved as \@@hyph just in case anyone needs it.

There is a need for a robust command for a discretionary hyphen since its exact representation depends on the glyphs available in the current font. For example, with suitable fonts and the T1 font encoding it is possible to use hanging hyphens.

A suitable robust definition that allows for many possible types of font and encoding may be as follows:

  \DeclareRobustCommand {\-}{%
    \discretionary {%
      \char \ifnum\hyphenchar\font<\z@
              \defaulthyphenchar
            \else
              \hyphenchar\font
            \fi
                    }{}{}%
  }

The redefinition (via \let) of \- within tabbing also makes the use of a robust command advisable since then any redefinition of \- via \DeclareRobustCommand will not cause a conflict.

Therefore, macro writers should be hereby warned that these internals will probably change! It is likely that a future release of L^{A}TEX will make \- effectively an encoding specific text command.

 9 \let\@@hyph=\-        % Save original primitive definition
10 \def\-{\discretionary{-}{}{}}
\@dischyph
11 \let\@dischyph=\-

\@@italiccorr Save the original italic correction.

12 \let\@@italiccorr=\/

\@height \@depth \@width \@minus \@plus The following definitions save token space. E.g., using \@height instead of height saves 5 tokens at the cost in time of one macro expansion.

13 \def\@height{height} \def\@depth{depth} \def\@width{width}
14 \def\@minus{minus}
15 \def\@plus{plus}

\hb@xt@ The next one is another 100 tokens worth.

16 \def\hb@xt@{\hbox to}
17 \message{hacks,}

1.3 Command definitions

This section defines the following commands:

\@namedef      {⟨NAME⟩}

Expands to \def\{⟨NAME⟩}, except name can contain any characters.

\@nameuse      {⟨NAME⟩}

Expands to \{⟨NAME⟩}.

\@ifnextchar  X{⟨YES⟩}{⟨NO⟩}

Expands to ⟨YES⟩ if next character is an ‘X’, and to ⟨NO⟩ otherwise. (Uses \reserved@a–\reserved@c.) NOTE: GOBBLES ANY SPACE FOLLOWING IT.

\@ifstar      {⟨YES⟩}{⟨NO⟩}

Gobbles following spaces and then tests if next the character is a ’*’. If it is, then it gobbles the ‘*’ and expands to ⟨YES⟩, otherwise it expands to ⟨NO⟩.

\@dblarg      {⟨CMD⟩}{⟨ARG⟩}

Expands to \{⟨CMD⟩}[⟨ARG⟩]{⟨ARG⟩}. Use \@dblarg\CS when \CS takes arguments [ARG1]{ARG2}, where default is ARG1 = ARG2.

\@ifundefined      {⟨NAME⟩}{⟨YES⟩}{⟨NO⟩}

: If \NAME is undefined then it executes ⟨YES⟩, otherwise it executes ⟨NO⟩. More precisely, true if \NAME either undefined or = \relax.

\@ifdefinable \NAME{⟨YES⟩} Executes ⟨YES⟩ if the user is allowed to define \NAME, otherwise it gives an error. The user can define \NAME if \@ifundefined{NAME} is true, ’NAME’ ≠ ’relax’ and the first three letters of ’NAME’ are not ’end’, and if \endNAME is not defined.

\newcommand      *{⟨\FOO ⟩}[⟨i⟩]{⟨TEXT ⟩}

User command to define \FOO to be a macro with i arguments (i = 0 if missing) having the definition ⟨TEXT ⟩. Produces an error if \FOO already defined.

Normally the command is defined to be \long (ie it may take multiple paragraphs in its argument). In the star-form, the command is not defined as \long and a blank line in any argument to the command would generate an error.

\renewcommand      *{⟨\FOO ⟩}[⟨i⟩]{⟨TEXT ⟩}

Same as \newcommand, except it checks if \FOO already defined.

\newenvironment      *{⟨FOO⟩}[⟨i⟩]{⟨DEF1 ⟩}{⟨DEF2 ⟩}

equivalent to:

\newcommand{\FOO}[i]{DEF1} \def{\endFOO}{DEF2}

(or the appropriate star forms).

\renewenvironment

Obvious companion to \newenvironment. \@cons : See description of \output routine.

\@car      \@car T1 T2 ... Tn\@nil == T1 (unexpanded)
\@cdr      \@cdr T1 T2 ... Tn\@nil == T2 ... Tn (unexpanded)
\typeout      {⟨message⟩}

Produces a warning message on the terminal.

\typein      {⟨message⟩}

Types message, asks the user to type in a command, then executes it

\typein      [⟨\CS ⟩]{⟨MSG⟩}

Same as above, except defines \CS to be the input instead of executing it.

\typein
18 \def\typein{%
19 \let\@typein\relax

20 \@testopt\@xtypein\@typein}
21 \def\@xtypein[#1]#2{%
22 \typeout{#2}%
23 \advance\endlinechar\@M
24 \read\@inputcheck to#1%
25 \advance\endlinechar-\@M
26 \@typein}
\@namedef
27 \def\@namedef#1{\expandafter\def\csname #1\endcsname}
\@nameuse
28 \def\@nameuse#1{\csname #1\endcsname}
\@cons
29 \def\@cons#1#2{\begingroup\let\@elt\relax\xdef#1{#1\@elt #2}\endgroup}

{\@car \atop \@cdr}

30 \def\@car#1#2\@nil{#1}
31 \def\@cdr#1#2\@nil{#2}
\@carcube  \@carcube T1 ... Tn\@nil = T1 T2 T3 , n > 3
32 \def\@carcube#1#2#3#4\@nil{#1#2#3}

\@onlypreamble \@preamblecmds This macro adds its argument to the list of commands stored in \@preamblecmds to be disabled after \begin{document}. These commands are redefined to generate \@notprerr at this point.

33 \def\@preamblecmds{}
34 \def\@onlypreamble#1{%
35 \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
36  \@preamblecmds\do#1}}
37 \@onlypreamble\@onlypreamble
38 \@onlypreamble\@preamblecmds

\@star@or@long Look ahead for a *. If present reset \l@ngrel@x so that the next definition, #1, will be non-long.

39 \def\@star@or@long#1{%
40 \@ifstar
41 {\let\l@ngrel@x\relax#1}%
42 {\let\l@ngrel@x\long#1}}

\l@ngrel@x This is either \relax or \long depending on whether the *-form of a definition command is being executed.

43 \let\l@ngrel@x\relax
\newcommand User level \newcommand.
44 \def\newcommand{\@star@or@long\new@command}

\new@command
45 \def\new@command#1{%
46 \@testopt{\@newcommand#1}0}
\@newcommand \@argdef \@xargdef Handling arguments for \newcommand.
47 \def\@newcommand#1[#2]{%
48 \@ifnextchar [{\@xargdef#1[#2]}%
49  {\@argdef#1[#2]}}

Define #1 if it is definable.

50 \long\def\@argdef#1[#2]#3{%
51 \@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}}

Handle the second optional argument.

52 \long\def\@xargdef#1[#2][#3]#4{%
53 \@ifdefinable#1{%

Define the actual command to be:

\def\foo{\@protected@testopt\foo\\foo{default}}

where \\foo is a csname generated from applying \csname and \string to \foo, ie the actual name contains a backslash and therefore can’t clash easily with exisiting command names. “Default” is the contents of the second optional argument of

\(re)newcommand.

The \aut@global command below is only used in the autoload format. If it is \global then a global definition will be made.

54 ⟨autoload⟩\aut@global

55  \expandafter\def\expandafter#1\expandafter{%
56  \expandafter
57  \@protected@testopt
58  \expandafter
59  #1%
60  \csname\string#1\expandafter\endcsname
61  {#3}}%

Now we define the internal macro (ie \\foo which is supposed to pick up all arguments (optional and mandatory).

62  \expandafter\@yargdef
63  \csname\string#1\endcsname
64  \tw@
65  {#2}%
66  {#4}}}

\@testopt This macro encapsulates the most common call to \@ifnextchar, saving several tokens each time it is used in the definition of a command with an optional argument. #1 The code to execute in the case that there is a [ need not be a single token but can be any sequence of commands that ‘expects’ to be followed by [. If this command were only used in \newcommand definitions then #1 would be a single token and the braces could be omitted from {#1} in the definition below, saving a bit of memory.

67 \def\@testopt#1#2{%
68 \@ifnextchar[{#1}{#1[#2]}}

\@protected@testopt Robust version of \@testopt. The extra argument (#1) must be a single token. If protection is needed the call expands to \protect applied to this token, and the 2nd and 3rd arguments are discarded. Otherwise \@testopt is called on 2nd and 3rd arguments.

This method of making commands robust avoids the need for using up two csnames per command, the price is the extra expansion time for the \ifx test.

69 \def\@protected@testopt#1{%%
70 \ifx\protect\@typeset@protect
71  \expandafter\@testopt
72 \else
73  \@x@protect#1%
74 \fi}

\@yargdef Generate a primitive argument specification, from a L^{A}TEX [⟨num⟩] form.

   Reorganised slightly so that \renewcommand[1]{\reserved@a}{foo} works.

I am not sure this is worth it, as a following \newcommand would over-write the definition of \reserved@a. L^{A}TEX2.09 goes into an infinite loop with

\renewcommand[1]{\@tempa}{foo}.

(DPC 6 October 93)

75 \long\def\@yargdef#1#2#3{%
76 \@tempcnta#3\relax
77 \advance \@tempcnta \@ne
78 \let\@hash@\relax
79 \edef\reserved@a{\ifx#2\tw@ [\@hash@1]\fi}%
80 \@tempcntb #2%
81 \@whilenum\@tempcntb <\@tempcnta
82  \do{%
83  \edef\reserved@a{\reserved@a\@hash@\the\@tempcntb}%
84  \advance\@tempcntb \@ne}%
85 \let\@hash@##%

86 ⟨autoload⟩\aut@global

87 \l@ngrel@x\expandafter\def\expandafter#1\reserved@a}
\@reargdef
88 \long\def\@reargdef#1[#2]#3{%
89 \@yargdef#1\@ne{#2}{#3}}

\renewcommand Check the command name is already used. If not give an error message. Then temporarily disable \@ifdefinable then call \newcommand. (Previous version \let#1=\relax but this does not work too well if #1 is \@tempa–e.)

90 \def\renewcommand{\@star@or@long\renew@command}
\renew@command
91 \def\renew@command#1{%
92 {\escapechar\m@ne\xdef\@gtempa{{\string#1}}}%

 93 \expandafter\@ifundefined\@gtempa
 94  {\@latex@error{\string#1 undefined}\@ehc}%
 95  {}%
 96 \let\@ifdefinable\@rc@ifdefinable
 97 \new@command#1}
\@ifdefinable \@@ifdefinable \@rc@ifdefinable Test is user is allowed to define a command.
 98 \long\def\@ifdefinable #1#2{%
 99  \edef\reserved@a{\expandafter\@gobble\string #1}%
100  \@ifundefined\reserved@a
101  {\edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
102  \ifx \reserved@b\@qend \@notdefinable\else
103  \ifx \reserved@a\@qrelax \@notdefinable\else
104  #2%
105  \fi
106  \fi}%
107  \@notdefinable}

Saved definition of \@ifdefinable.

108 \let\@@ifdefinable\@ifdefinable

Version of \@ifdefinable for use with \renewcommand. Does not do the check this time, but restores the normal definition.

109 \long\def\@rc@ifdefinable#1#2{%
110 \let\@ifdefinable\@@ifdefinable
111 #2}

\newenvironment Define a new user environment. #1 is the environment name. #2# Grabs all the tokens up to the first {. These will be any optional arguments. They are not parsed at this point, but are just passed to \@newenv which will eventually call \newcommand. Any optional arguments will then be parsed by \newcommand as it defines the command that executes the ‘begin code’ of the environment.

This #2# trick removed with version 1.2i as it fails if a { occurs in the optional argument. Now use \@ifnextchar directly.

112 \def\newenvironment{\@star@or@long\new@environment}
\new@environment
113 \def\new@environment#1{%
114 \@testopt{\@newenva#1}0}
115 \def\@newenva#1[#2]{%
116 \@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}}
117 \def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][#3]}}
\renewenvironment Redefine an environment. For \renewenvironment disable \@ifdefinable and

then call \newenvironment. It is OK to \let the argument to \relax here as there should not be a @temp… environment.

118 \def\renewenvironment{\@star@or@long\renew@environment}

\renew@environment
119 \def\renew@environment#1{%
120 \@ifundefined{#1}%
121  {\@latex@error{Environment #1 undefined}\@ehc
122  }{}%
123 \expandafter\let\csname#1\endcsname\relax

124 ⟨autoload⟩\aut@global

125 \expandafter\let\csname end#1\endcsname\relax
126 \new@environment{#1}}
\@newenv The internal version of \newenvironment.

Call \newcommand to define the ⟨begin-code⟩ for the environment. \def is used for the ⟨end-code⟩ as it does not take arguments. (but may contain \pars)

Make sure that an attempt to define a ‘graf’ or ‘group’ environment fails.

127 \long\def\@newenv#1#2#3#4{%
128 \@ifundefined{#1}%
129  {\expandafter\let\csname#1\expandafter\endcsname
130  \csname end#1\endcsname}%
131  \relax
132 \expandafter\new@command
133  \csname #1\endcsname#2{#3}%

134 ⟨autoload⟩\aut@global

135  \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}

\newif And here’s a different sort of allocation: For example, \newif\iffoo creates

 \footrue, \foofalse to go with \iffoo.
136 \def\newif#1{%
137 \count@\escapechar \escapechar\m@ne

138 ⟨autoload⟩\aut@global

139  \let#1\iffalse
140  \@if#1\iftrue
141  \@if#1\iffalse
142 \escapechar\count@}
\@if
143 \def\@if#1#2{%

144 ⟨autoload⟩\aut@global

145 \expandafter\def\csname\expandafter\@gobbletwo\string#1%
146  \expandafter\@gobbletwo\string#2\endcsname
147  {\let#1#2}}
\providecommand  \providecommand takes the same arguments as \newcommand, but discards them

if #1 is already defined, Otherwise it just acts like \newcommand. This implementation currently leaves any discarded definition in \reserved@a (and possibly \\reserved@a) this wastes a bit of space, but it will be reclaimed as soon as these scratch macros are redefined.

148 \def\providecommand{\@star@or@long\provide@command}

\provide@command
149 \def\provide@command#1{%
150 {\escapechar\m@ne\xdef\@gtempa{{\string#1}}}%
151 \expandafter\@ifundefined\@gtempa
152  {\def\reserved@a{\new@command#1}}%
153  {\def\reserved@a{\renew@command\reserved@a}}%
154 \reserved@a}%
\CheckCommand  \CheckCommand takes the same arguments as \newcommand. If the command

already exists, with the same definition, then nothing happens, otherwise a warning is issued. Useful for checking the current state befor a macro package starts redefining things. Currently two macros are considered to have the same definition if they are the same except for different default arguments. That is, if the old definition was: \newcommand\xxx[2][a]{(#1)(#2)} then

 \CheckCommand\xxx[2][b]{(#1)(#2)} would not generate a warning, but, for
 instance \CheckCommand\xxx[2]{(#1)(#2)} would.
155 \def\CheckCommand{\@star@or@long\check@command}

\CheckCommand is only available in the preamble part of the document.

156 \@onlypreamble\CheckCommand
\check@command
157 \def\check@command#1#2#{\@check@c#1{#2}}
158 \@onlypreamble\check@command

\@check@c \CheckCommand itself just grabs all the arguments we need, without actually looking for [ optional argument forms. Now define \reserved@a. If \\reserved@a is then defined, compare it with the “\#1’ otherwise compare \reserved@a with #1.

159 \long\def\@check@c#1#2#3{%
160 \expandafter\let\csname\string\reserved@a\endcsname\relax
161 \renew@command\reserved@a#2{#3}%
162 \@ifundefined{\string\reserved@a}%
163 {\@check@eq#1\reserved@a}%
164 {\expandafter\@check@eq
165  \csname\string#1\expandafter\endcsname
166  \csname\string\reserved@a\endcsname}}
167 \@onlypreamble\@check@c

\@check@eq Complain if #1 and #2 are not \ifx equal.

168 \def\@check@eq#1#2{%
169 \ifx#1#2\else
170  \@latex@warning@no@line
171  {Command \noexpand#1 has
172  changed.\MessageBreak
173  Check if current package is valid}%
174 \fi}
175 \@onlypreamble\@check@eq

\@gobble \@gobbletwo \@gobblefour The \@gobble macro is used to get rid of its argument.
176 \long\def \@gobble #1{}
177 \long\def \@gobbletwo #1#2{}
178 \long\def \@gobblefour #1#2#3#4{}
\@firstofone \@firstoftwo \@secondoftwo Some argument-grabbers.
179 \long\def\@firstofone#1{#1}
180 \long\def\@firstoftwo#1#2{#1}
181 \long\def\@secondoftwo#1#2{#2}

\@iden \@iden is another name for \@firstofone for compatibility reasons.

182 \let\@iden\@firstofone

\@expandtwoargs A macro to totally expand two arguments to another macro

183 \def\@expandtwoargs#1#2#3{%
184 \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a}

\@backslashchar A category code 12 backslash.

185 \edef\@backslashchar{\expandafter\@gobble\string\\}

1.4 Robust commands and protect

Fragile and robust commands are one of the thornier issues in L^{A}TEX’s commands. Whilst typesetting documents, L^{A}TEX makes use of many of TEX’s features, such as arithmetic, defining macros, and setting variables. However, there are (at least) three different ocassions when these commands are not safe. These are called ‘moving arguments’ by L^{A}TEX, and consist of:

• writing information to a file, such as indexes or tables of contents.

• writing information to the screen.

• inside an \edef, \message, \mark, or other command which evaluates its argument fully.

The method L^{A}TEX uses for making fragile commands robust is to precede them with \protect. This can have one of five possible values:

• \relax, for normal typesetting. So \protect\foo will execute \foo.

• \string, for writing to the screen. So \protect\foo will write \foo.

• \noexpand, for writing to a file. So \protect\foo will write \foo followed by a space.

• \@unexpandable@protect, for writing a moving argument to a file. So \protect\foo will write \protect\foo followed by a space. This value is also used inside \edefs, \marks and other commands which evaluate their arguments fully.

• \@unexpandable@noexpand, for performing a deferred write inside an \edef. So \protect\foo will write \foo followed by a space. If you want

     \protect\foo to be written, you should use \@unexpandable@protect.

(Removed as never used).

\@unexpandable@protect \@unexpandable@noexpand These commands are used for setting \protect inside \edefs.
186 \def\@unexpandable@protect{\noexpand\protect\noexpand}
187 %\def\@unexpandable@noexpand{\noexpand\noexpand\noexpand}
\DeclareRobustCommand \declare@robustcommand This is a package-writers command, which has the same syntax as \newcommand,

but which declares a protected command. It does this by having

\DeclareRobustCommand\foo
define \foo to be \protect\foo<space>,
and then use \newcommand\foo<space>.

Since the internal command is \foo<space>, when it is written to an auxiliary file, it will appear as \foo.

We have to be a bit cleverer if we’re defining a short command, such as \_, in order to make sure that the auxiliary file does not include a space after the command, since \_a and \_a aren’t the same. In this case we define \_to be:

    \x@protect\_\protect\_<space>

which expands to:

    \ifx\protect\@typeset@protect\else
       \@x@protect@\_
    \fi
    \protect\_<space>

Then if \protect is \@typeset@protect (normally \relax) then we just perform \_<space>, and otherwise \@x@protect@ gobbles everything up and expands to

\protect\_.

Note: setting \protect to any value other than \relax whilst in ‘typesetting’ mode will cause commands to go into an infinite loop! In particular, setting \relax to \@empty will cause \_to loop forever. It will also break lots of other things, such as protected \ifmmodes inside \haligns. If you really really have to do such a thing, then please set \@typeset@protect to be \@empty as well. (This is what the code for \patterns does, for example.)

   More fun with \expandafter and \csname.
188 \def\DeclareRobustCommand{\@star@or@long\declare@robustcommand}
189 \def\declare@robustcommand#1{%
190 \ifx#1\@undefined\else\ifx#1\relax\else
191  \@latex@info{Redefining \string#1}%
192 \fi\fi
193 \edef\reserved@a{\string#1}%
194 \def\reserved@b{#1}%
195 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%

196 ⟨autoload⟩\aut@global

197 \edef#1{%
198  \ifx\reserved@a\reserved@b
199  \noexpand\x@protect
200  \noexpand#1%
201  \fi
202  \noexpand\protect
203  \expandafter\noexpand\csname
204  \expandafter\@gobble\string#1 \endcsname

205 }%

206 \let\@ifdefinable\@rc@ifdefinable
207 \expandafter\new@command\csname
208  \expandafter\@gobble\string#1 \endcsname

209 }

\@x@protect \x@protect
210 \def\x@protect#1{%
211 \ifx\protect\@typeset@protect\else
212  \@x@protect#1%
213 \fi

214 }

215 \def\@x@protect#1\fi#2#3{%
216 \fi\protect#1%

217 }

\@typeset@protect
218 \let\@typeset@protect\relax

\set@display@protect \set@typeset@protect These macros set \protect appropriately for typesetting or displaying.

219 \def\set@display@protect{\let\protect\string}
220 \def\set@typeset@protect{\let\protect\@typeset@protect}
\protected@edef \protected@xdef \unrestored@protected@xdef \restore@protect The commands \protected@edef and \protected@xdef perform ‘safe’ \edefs

and \xdefs, saving and restoring \protect appropriately. For cases where restoring \protect doesn’t matter, there’s an ‘unsafe’ \unrestored@protected@xdef, useful if you know what you’re doing!

221 \def\protected@edef{%
222 \let\@@protect\protect
223 \let\protect\@unexpandable@protect
224 \afterassignment\restore@protect
225 \edef

226 }

227 \def\protected@xdef{%
228 \let\@@protect\protect
229 \let\protect\@unexpandable@protect
230 \afterassignment\restore@protect
231 \xdef

232 }

233 \def\unrestored@protected@xdef{%

234 \let\protect\@unexpandable@protect
235 \xdef

236 }

237 \def\restore@protect{\let\protect\@@protect}

\protect The normal meaning of \protect

238 \set@typeset@protect

1.5 Internal defining commands

These commands are used internally to define other L^{A}TEX commands.

\@ifundefined Check if first arg is undefined or \relax and execute second or third arg depending,

239 \def\@ifundefined#1{%
240 \expandafter\ifx\csname#1\endcsname\relax
241  \expandafter\@firstoftwo
242 \else
243  \expandafter\@secondoftwo
244 \fi}

\@qend \@qrelax The following define \@qend and \@qrelax to be the strings ‘end’ and ‘relax’ with the characters \catcoded 12.

245 \edef\@qend{\expandafter\@cdr\string\end\@nil}
246 \edef\@qrelax{\expandafter\@cdr\string\relax\@nil}

\@ifnextchar \@ifnextchar peeks at the following character and compares it with its first argument. If both are the same it executes its second argument, otherwise its third.

247 \def\@ifnextchar#1#2#3{%
248 \let\reserved@d=#1%
249 \def\reserved@a{#2}\def\reserved@b{#3}%
250 \futurelet\@let@token\@ifnch}

\@ifnch \@ifnch is a tricky macro to skip any space tokens that may appear before the character in question. If it encounters a space token, it calls xifnch.

251 \def\@ifnch{%
252 \ifx\@let@token\@sptoken
253  \let\reserved@c\@xifnch
254 \else
255  \ifx\@let@token\reserved@d
256  \let\reserved@c\reserved@a
257  \else
258  \let\reserved@c\reserved@b
259  \fi
260 \fi
261 \reserved@c}

\@sptoken The following code makes \@sptoken a space token. It is important here that the control sequence \: consists of a non-letter only, so that the following whitespace is significant. Together with the fact that the equal sign in a \let may be followed by only one optional space the desired effect is achieved. NOTE: the following hacking must precede the definition of \: as math medium space.

262 \def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token

\@xifnch In the following definition of \@xifnch, \: is again used to get a space token as delimiter into the definition.

263 \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}

\makeatletter \makeatother Make internal control sequences accessible or inaccessible.

264 \def\makeatletter{\catcode`\@11\relax}
265 \def\makeatother{\catcode`\@12\relax}

\@ifstar The new implementation below avoids passing the ⟨true code⟩ Through one more \def than the ⟨false code⟩, which previously meant that # had to be written as #### in one argument, but ## in the other. The * is gobbled by \@firstoftwo.

266 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
\@dblarg \@xdblarg
267 \long\def\@dblarg#1{\@ifnextchar[{#1}{\@xdblarg{#1}}}
268 \long\def\@xdblarg#1#2{#1[{#2}]{#2}}

\@sanitize The command \@sanitize changes the catcode of all special characters except for braces to ‘other’. It can be used for commands like \index that want to write their arguments verbatim. Needless to say, this command should only be executed within a group, or chaos will ensue.

269 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
270 \@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~}

\@onelevel@sanitize This makes the whole “meaning” of #1 (its one-level expansion) into catcode 12

tokens: it could be used in \DeclareRobustCommand.

If it is to be used on default float specifiers, this should be done when they are defined.

271 \def \@onelevel@sanitize #1{%
272 \edef #1{\expandafter\strip@prefix
273  \meaning #1}%

274 }

275 ⟨/2ekernel⟩

1.6 Commands for Autoloading

276 ⟨∗autoload⟩

\aut@global This command is only defined in the ‘autoload’ format. It is normally \relax but may be set to \global, in which case \newif and the commands based on \newcommand will all make global definitions.

277 \let\aut@global\relax

\@autoload This macro is only defined in the ‘autoload’ format. It inputs a package ‘auto#1.sty’ within a local group, and with normalised catcodes. \aut@global is set to \global so that \newif \newcommand and related commands make global definitions.

278 \def\@autoload#1{%
279 \begingroup
280 \makeatletter
281 \let\aut@global\global
282 \nfss@catcodes
283 \catcode`\ =10
284 \let\@latex@e@error\@gobble
285 \@@input auto#1.sty\relax
286 \endgroup}

287 ⟨/autoload⟩