1 % \iffalse meta-comment
4 % The LaTeX3 Project and any individual authors listed elsewhere
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This file has the LPPL maintenance status "maintained".
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
31 %%% From File: ltdefns.dtx
34 \ProvidesFile{ltdefns.dtx}
35 [2017/03/73 v1.5b LaTeX Kernel (definition commands)]
37 \documentclass{ltxdoc}
38 \GetFileInfo{ltdefns.dtx}
50 \MaintainedByLaTeXTeam{latex}
58 % \changes{v1.0n}{1994/05/10}{(ASAJ) Added
59 % \cs{DeclareProtectedCommand}.}
60 % \changes{v1.0p}{1994/05/12}{(ASAJ) Fixed a bug with \cs{relax}
62 % using \cs{@gobble} before defining it.}
63 % \changes{v1.0q}{1994/05/13}{(ASAJ) Renamed
64 % \cs{DeclareProtectedCommand} to
65 % \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}.}
66 % \changes{v1.0q}{1994/05/13}{(ASAJ) Replaces \cs{space} by `~' in
68 % \changes{v1.0r}{1994/05/13}{(ASAJ) Added logging message to
69 % \cs{DeclareProtectedCommand}.}
70 % \changes{v1.0s}{1994/05/13}{(ASAJ) Added \cs{@backslashchar}.}
71 % \changes{v1.0s}{1994/05/13}{(ASAJ) Coded \cs{@ifdefinable} more
73 % \changes{v1.1a}{1994/05/16}{(ASAJ) Split from ltinit.dtx.}
74 % \changes{v1.1b}{1994/05/17}{(ASAJ) Removed warnings and logging to
76 % \changes{v1.1b}{1994/05/17}{(ASAJ) Added definitions for protect.}
77 % \changes{v1.1c}{1994/05/17}{(ASAJ) Redid definitions for protect.}
78 % \changes{v1.1d}{1994/05/19}{(RmS) Added definitions for
79 % \cs{@namedef} and \cs{@nameuse} again.}
80 % \changes{v1.1e}{1994/05/20}{Changed command name from
81 % \cs{@checkcommand} to \cs{CheckCommand}.}
82 % \changes{v1.1f}{1994/05/22}{Use new warning and error cmds}
83 % \changes{v1.2a}{1994/10/18}{Add star-forms for all commands}
84 % \changes{v1.2a}{1994/10/18}{Add extra test for \cs{endgraf}}
85 % \changes{v1.2b}{1994/10/25}{Documentation improvements}
86 % \changes{v1.2c}{1994/10/30}{(CAR)\cs{@onelevel@sanitize} added}
87 % \changes{v1.2f}{1994/10/30}{(DPC)\cs{newwrite}'s moved to ltfiles}
88 % \changes{v1.0g}{1994/11/17}
89 % {\cs{@tempa} to \cs{reserved@a}}
90 % \changes{v1.0p}{1995/07/13}{Updates to documentation}
91 % \changes{v1.4b}{2015/02/21}
92 % {Removed autoload support}
94 % \section{Definitions}
96 % This section contains commands used in defining other macros.
104 % \subsection{Initex initialisations}
106 % \task{???}{This section needs extension}
108 % \begin{macro}{\two@digits}
109 % \changes{LaTeX2e}{1993/11/23}{Macro added}
110 % Prefix a number less than 10 with `0'.
112 \def\two@digits#1{\ifnum#1<10 0\fi\number#1}
116 % \changes{v1.2e}{1994/11/04}{Added \cs{set@display@protect} to
117 % \cs{typeout}. ASAJ.}
119 % \begin{macro}{\typeout}
120 % Display something on the terminal.
122 \def\typeout#1{\begingroup\set@display@protect
123 \immediate\write\@unused{#1}\endgroup}
127 % \begin{macro}{\newlinechar}
128 % A char to be used as new-line in output to files.
134 % \subsection{Saved versions of \TeX{} primitives}
136 % The TeX primitive |\foo| is saved as |\@@foo|.
137 % The following primitives are handled in this way:
138 % \begin{macro}{\@@par}
141 %\let\@@input=\input %%% moved earlier
146 % \begin{macro}{\@@hyph}
147 % Save original primitive definition.
154 % \begin{macro}{\@@italiccorr}
155 % Save the original italic correction.
156 % \changes{v1.0a}{1994/03/07}{Macro added}
162 % \begin{macro}{\@height}
163 % \begin{macro}{\@depth}
164 % \begin{macro}{\@width}
165 % \begin{macro}{\@minus}
166 % \changes{LaTeX2e}{1993/11/22}{Macro added}
167 % \begin{macro}{\@plus}
168 % \changes{LaTeX2e}{1993/11/22}{Macro added}
170 % The following definitions save token space. E.g., using
171 % |\@height| instead of height saves 5 tokens at the cost in time
172 % of one macro expansion.
174 \def\@height{height} \def\@depth{depth} \def\@width{width}
178 % \begin{macro}{\hb@xt@}
179 % \changes{v1.2k}{1995/05/07}{Macro added}
180 % The next one is another 100 tokens worth.
182 \def\hb@xt@{\hbox to}
195 % \subsection{Command definitions}
197 % This section defines the following commands:
200 % {\@namedef}\marg{NAME}\\ Expands to |\def\|\marg{NAME},
201 % except name can contain any characters.
204 % {\@nameuse}\marg{NAME}\\
205 % Expands to |\|\marg{NAME}.
208 % {\@ifnextchar} X\marg{YES}\marg{NO}\\
209 % Expands to \meta{YES} if next character is an `X',
210 % and to \meta{NO} otherwise.
211 % (Uses |\reserved@a|--|\reserved@c|.)
212 % NOTE: GOBBLES ANY SPACE FOLLOWING IT.
215 % {\@ifstar}\marg{YES}\marg{NO}\\
216 % Gobbles following spaces and then tests if next the
217 % character is a '*'. If it is, then it gobbles the
218 % `*' and expands to \meta{YES}, otherwise it expands to \meta{NO}.
221 % {\@dblarg}\marg{CMD}\marg{ARG}\\
222 % Expands to |\|\marg{CMD}\oarg{ARG}\marg{ARG}. Use
223 % |\@dblarg\CS| when |\CS| takes arguments |[ARG1]{ARG2}|,
224 % where default is| ARG1| = |ARG2|.
227 % {\@ifundefined}\marg{NAME}\marg{YES}\marg{NO}\\
228 % : If \cs{NAME} is undefined then it executes \meta{YES},
229 % otherwise it executes \meta{NO}. More precisely,
230 % true if \cs{NAME} either undefined or = |\relax|.
233 % {\@ifdefinable}|\NAME|\marg{YES}
234 % Executes \meta{YES} if the user is allowed to define |\NAME|,
235 % otherwise it gives an error. The user can define |\NAME|
236 % if |\@ifundefined{NAME}| is true, '|NAME|' $\neq$ '|relax|'
237 % and the first three letters of '|NAME|' are not
238 % '|end|', and if |\endNAME| is not defined.
241 % \newcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
242 % User command to define |\FOO| to be a macro with
243 % i arguments (i = 0 if missing) having the definition
244 % \meta{TEXT}. Produces an error if |\FOO| already
247 % Normally the command is defined to be |\long| (ie it may
248 % take multiple paragraphs in its argument). In the
249 % star-form, the command is not defined as |\long| and a
250 % blank line in any argument to the command would generate
254 % \renewcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
255 % Same as |\newcommand|, except it checks if |\FOO| already defined.
258 % \newenvironment|*|\marg{FOO}\oarg{i}\marg{DEF1}\marg{DEF2}\\
260 % |\newcommand{\FOO}[i]{DEF1}| |\def{\endFOO}{DEF2}|\\
261 % (or the appropriate star forms).
264 % \renewenvironment\\ Obvious companion to |\newenvironment|.
267 % \@cons : See description of |\output| routine.
269 % \DescribeMacro{\@car}
270 % |\@car T1 T2 ... Tn\@nil| == |T1| (unexpanded)
272 % \DescribeMacro{\@cdr}
273 % |\@cdr T1 T2 ... Tn\@ni|l == |T2 ... Tn| (unexpanded)
276 % \typeout\marg{message}\\ Produces a warning message on the terminal.
279 % \typein\marg{message}\\
280 % Types message, asks the user to type in a command, then
284 % \typein\oarg{\cs{CS}}\marg{MSG}\\
285 % Same as above, except defines |\CS| to be the input
286 % instead of executing it.
288 % \changes{LaTeX209}{1992/03/18}
289 % {(RMS) changed input channel from 0 to \cs{@inputcheck} to avoid
290 % conflicts with other channels allocated by \cs{newread}}
292 % \begin{macro}{\typein}
294 % \changes{v1.2k}{1995/05/08}{Use \cs{@firstofone}}
295 % \changes{v1.2l}{1995/05/08}{Remove unnecessary braces}
296 % \changes{v1.2l}{1995/05/08}{Replace \cs{def} by \cs{let}}
297 % \changes{v1.2m}{1995/05/24}{(DPC) New implementation}
298 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
302 \@testopt\@xtypein\@typein}
305 % \changes{v1.2r}{1995/10/03}
306 % {Add missing \cs{@typein} for /1710 (from patch file)}
307 % \changes{v1.4a}{2015/01/03}{use modified definition in luatex}
309 \ifx\directlua\@undefined
313 \def\@xtypein[#1]#2{%
315 \advance\endlinechar\@M
316 \read\@inputcheck to#1%
317 \advance\endlinechar-\@M
326 \def\@xtypein[#1]#2{%
328 \begingroup \endlinechar\m@ne
329 \read\@inputcheck to#1%
330 \expandafter\endgroup
331 \expandafter\def\expandafter#1\expandafter{#1}%
340 % \begin{macro}{\@namedef}
342 \def\@namedef#1{\expandafter\def\csname #1\endcsname}
346 % \begin{macro}{\@nameuse}
348 \def\@nameuse#1{\csname #1\endcsname}
352 % \begin{macro}{\@cons}
354 \def\@cons#1#2{\begingroup\let\@elt\relax\xdef#1{#1\@elt #2}\endgroup}
358 % \begin{macro}{\@car}
359 % \begin{macro}{\@cdr}
361 \def\@car#1#2\@nil{#1}
362 \def\@cdr#1#2\@nil{#2}
367 % \begin{macro}{\@carcube}
368 % |\@carcube T1 ... Tn\@nil| = |T1| |T2| |T3| , $n > 3$
370 \def\@carcube#1#2#3#4\@nil{#1#2#3}
376 % \begin{macro}{\@onlypreamble}
377 % \begin{macro}{\@preamblecmds}
378 % This macro adds its argument to the list of commands stored in
379 % |\@preamblecmds| to be
380 % disabled after |\begin{document}|. These commands are redefined
381 % to generate |\@notprerr| at this point.
384 \def\@onlypreamble#1{%
385 \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
386 \@preamblecmds\do#1}}
387 \@onlypreamble\@onlypreamble
388 \@onlypreamble\@preamblecmds
394 % \begin{macro}{\@star@or@long}
395 % \changes{v1.2a}{1994/10/18}{macro added}
396 % Look ahead for a |*|. If present reset |\l@ngrel@x| so that
397 % the next definition, |#1|, will be non-long.
399 \def\@star@or@long#1{%
401 {\let\l@ngrel@x\relax#1}%
402 {\let\l@ngrel@x\long#1}}
407 % \begin{macro}{\l@ngrel@x}
408 % This is either |\relax| or |\long| depending on whether the |*|-form
409 % of a definition command is being executed.
415 % \begin{macro}{\newcommand}
416 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
417 % User level |\newcommand|.%
419 \def\newcommand{\@star@or@long\new@command}
422 % \begin{macro}{\new@command}
423 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
426 \@testopt{\@newcommand#1}0}
432 % \begin{macro}{\@newcommand}
433 % \changes{LaTeX2e}{1993/11/23}{Macro added}
434 % \begin{macro}{\@argdef}
435 % \changes{LaTeX2e}{1993/11/23}{Macro added}
436 % \begin{macro}{\@xargdef}
437 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
438 % \changes{v1.1g}{2004/01/23}{Use kernel version of
439 % \cs{@ifnextchar} (pr/3501)}
440 % Handling arguments for |\newcommand|.
442 \def\@newcommand#1[#2]{%
443 \kernel@ifnextchar [{\@xargdef#1[#2]}%
446 % Define |#1| if it is definable.
448 % Both here and in |\@xargdef| the replacement text is absorbed as
449 % an argument because if we are not allowed to make the definition
450 % we have to get rid of it completely.
452 \long\def\@argdef#1[#2]#3{%
453 \@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}}
456 % \changes{v1.2q}{1995/10/02}
457 % {New implementation, using \cs{@test@opt}}
458 % Handle the second optional argument.
460 \long\def\@xargdef#1[#2][#3]#4{%
463 % Define the actual command to be:\\
464 % |\def\foo{\@protected@testopt\foo\\foo{default}}|\\
465 % where |\\foo| is a csname generated from applying |\csname| and
466 % |\string| to |\foo|, ie the actual name contains a backslash and
467 % therefore can't clash easily with existing command names.
468 % ``Default'' is the contents of the second optional argument of
471 % \changes{v1.2z2}{1998/03/04}
472 % {Unnecessary \cs{expandafter} removed: pr/2758}
474 \expandafter\def\expandafter#1\expandafter{%
479 \csname\string#1\endcsname
482 % Now we define the internal macro ie |\\foo| which is supposed to
483 % pick up all arguments (optional and mandatory).
485 \expandafter\@yargdef
486 \csname\string#1\endcsname
495 % \begin{macro}{\@testopt}
496 % \changes{v1.2q}{1995/10/02}
498 % \changes{v1.3a}{1999/01/07}
499 % {made long and brace optional arg. latex/2896}
500 % This macro encapsulates the most common call to |\@ifnextchar|, saving
501 % several tokens each time it is used in the definition of a command
502 % with an optional argument.
503 % |#1| The code to execute in the case that there is a |[| need not be
504 % a single token but can be any sequence of commands that `expects' to
505 % be followed by |[|. If this command were only used in |\newcommand|
506 % definitions then |#1| would be a single token and the braces could
507 % be omitted from |{#1}| in the definition below, saving a bit of
509 % \changes{v1.1g}{2004/01/23}{Use kernel version of
510 % \cs{@ifnextchar} (pr/3501)}
512 \long\def\@testopt#1#2{%
513 \kernel@ifnextchar[{#1}{#1[{#2}]}}
517 % \begin{macro}{\@protected@testopt}
518 % \changes{v1.2q}{1995/10/02}
520 % Robust version of |\@testopt|. The extra argument (|#1|) must be a
521 % single token. If protection is needed the call expands to |\protect|
522 % applied to this token, and the 2nd and 3rd arguments are
523 % discarded (by |\@x@protect|). Otherwise |\@testopt| is called on
524 % the 2nd and 3rd arguments.
526 % This method of making commands robust avoids the need for using up
527 % two csnames per command, the price is the extra expansion time
528 % for the |\ifx| test.
530 \def\@protected@testopt#1{%%
531 \ifx\protect\@typeset@protect
532 \expandafter\@testopt
539 % \begin{macro}{\@yargdef}
540 % \begin{macro}{\@yargd@f}
541 % \changes{v1.3f}{1999/04/29}{New macro added}
543 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
544 % \changes{LaTeX2e}{1993/11/23}{Avoid \cs{@?@?} token}
545 % \changes{v1.0b}{1994/03/12}{Name changed from \cs{XXX@argdef}}
546 % \changes{v1.3c}{1999/01/18}{New implementation DPC /2942}
547 % \changes{v1.3d}{1999/02/09}{catch bad argument forms by re-inserting \#3}
548 % \changes{v1.3f}{1999/04/29}{Full expansion and conversion needed
549 % for digit in new version, see pr/3013}
551 % These generate a primitive argument specification, from a
552 % \LaTeX\ |[|\meta{digit}|]| form; in fact \meta{digit} can be
553 % anything such that |\number|~\meta{digit} is single digit.
555 % Reorganised slightly so that |\renewcommand{\reserved@a}[1]{foo}|
556 % works. I am not sure this is worth it, as a following
557 % |\newcommand| would over-write the definition of |\reserved@a|.
559 % Recall that \LaTeX2.09 goes into an infinite loop with\\
560 % |\renewcommand[1]{\@tempa}{foo}|\\
561 % (DPC 6 October 93).
563 % Reorganised again (DPC 1999). Rather than make a loop to
564 % construct the argument spec by counting, just extract the
565 % required argument spec by using a delimited argument (delimited
566 % by the digit). This is faster and uses less tokens. The coding
567 % is slightly odd to preserve the old interface (using |#2| =
568 % |\tw@| as the flag to surround the first argument with |[]|. But
569 % the new method did not allow for the number of arguments |#3| not
570 % being given as an explicit digit; hence (further expansion of
571 % this argument and use of) |\number| was added later in 1999.
573 % It is not clear why these are still |\long|.
576 \long \def \@yargdef #1#2#3{%
578 \def\reserved@b##11{[####1]}%
580 \let\reserved@b\@gobble
583 \@yargd@f \expandafter{\number #3}#1%
588 \long \def \@yargd@f#1#2{%
589 \def \reserved@a ##1#1##2##{%
590 \expandafter\def\expandafter#2\reserved@b ##1#1%
592 \l@ngrel@x \reserved@a 0##1##2##3##4##5##6##7##8##9###1%
599 % \begin{macro}{\@reargdef}
600 % \changes{LaTeX2e}{1993/12/20}
601 % {Kept old version of \cs{@reargdef}, for array.sty}
602 % \changes{v1.0b}{1994/03/12}{New defn, in terms of \cs{@yargdef}}
603 % \changes{v1.2y}{1996/07/26}{third arg picked up by \cs{@yargdef}}
605 \long\def\@reargdef#1[#2]{%
610 % \begin{macro}{\renewcommand}
611 % Check the command name is already used. If not give an error
612 % message. Then temporarily
613 % disable |\@ifdefinable| then call |\newcommand|. (Previous
614 % version |\let#1=\relax| but this does not work too well if |#1|
615 % is |\@temp|\emph{a--e}.)
616 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
617 % \changes{v1.1f}{1994/05/02}{Removed surplus \cs{space} in error}
619 \def\renewcommand{\@star@or@long\renew@command}
622 % \begin{macro}{\renew@command}
623 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
624 % \changes{v1.2y}{1996/07/26}{use \cs{noexpand} instead of \cs{string}}
625 % \changes{v1.2z1}{1997/10/21}{Use \cs{begingroup}/\cs{endgroup} rather
626 % than braces for grouping, to avoid generating empty math atom.}
628 \def\renew@command#1{%
629 \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
630 \expandafter\@ifundefined\@gtempa
631 {\@latex@error{\noexpand#1undefined}\@ehc}%
633 \let\@ifdefinable\@rc@ifdefinable
639 % \changes{v1.0n}{1994/05/10}{Removed braces around \cs{@ifundefined}
641 % \changes{v1.0s}{1994/05/13}{Coded more efficiently, thanks to FMi.}
643 % \begin{macro}{\@ifdefinable}
644 % \begin{macro}{\@@ifdefinable}
645 % \begin{macro}{\@rc@ifdefinable}
646 % Test is user is allowed to define a command.
648 \long\def\@ifdefinable #1#2{%
649 \edef\reserved@a{\expandafter\@gobble\string #1}%
650 \@ifundefined\reserved@a
651 {\edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
652 \ifx \reserved@b\@qend \@notdefinable\else
653 \ifx \reserved@a\@qrelax \@notdefinable\else
659 % Saved definition of |\@ifdefinable|.
661 \let\@@ifdefinable\@ifdefinable
663 % Version of |\@ifdefinable| for use with |\renewcommand|. Does
664 % not do the check this time, but restores the normal definition.
666 \long\def\@rc@ifdefinable#1#2{%
667 \let\@ifdefinable\@@ifdefinable
674 % \begin{macro}{\newenvironment}
675 % Define a new user environment.
676 % |#1| is the environment name. |#2#| Grabs all the tokens up to
677 % the first |{|. These will be any optional arguments. They are not
678 % parsed at this point, but are just passed to |\@newenv| which
679 % will eventually call |\newcommand|. Any optional arguments will
680 % then be parsed by |\newcommand| as it defines the command that
681 % executes the `begin code' of the environment.
683 % This |#2#| trick removed with version 1.2i as it fails if a |{|
684 % occurs in the optional argument. Now use |\@ifnextchar| directly.
686 \def\newenvironment{\@star@or@long\new@environment}
689 % \begin{macro}{\new@environment}
690 % \changes{v1.2i}{1995/04/25}{Parse arguments slowly but safely /1507}
691 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
693 \def\new@environment#1{%
694 \@testopt{\@newenva#1}0}
697 % \begin{macro}{\@newenva}
698 % \changes{v1.1g}{2004/01/23}{Use kernel version of
699 % \cs{@ifnextchar} (pr/3501)}
701 \def\@newenva#1[#2]{%
702 \kernel@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}}
706 % \begin{macro}{\@newenvb}
707 % \changes{v1.3a}{1999/01/07}
708 % {made long and brace optional arg. latex/2896}
710 \def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][{#3}]}}
718 % \begin{macro}{\renewenvironment}
719 % Redefine an environment.
720 % For |\renewenvironment| disable |\@ifdefinable| and then call
721 % |\newenvironment|. It is OK to |\let| the argument to |\relax|
722 % here as there should not be a |@temp|\ldots\ environment.
723 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
724 % \changes{v1.1f}{1994/05/02}{Removed surplus \cs{space} in error}
726 \def\renewenvironment{\@star@or@long\renew@environment}
729 % \begin{macro}{\renew@environment}
730 % \changes{v1.2a}{1994/10/18}{reset end command}
731 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
733 \def\renew@environment#1{%
735 {\@latex@error{Environment #1 undefined}\@ehc
737 \expandafter\let\csname#1\endcsname\relax
738 \expandafter\let\csname end#1\endcsname\relax
739 \new@environment{#1}}
745 % \begin{macro}{\@newenv}
746 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
747 % \changes{v1.2h}{1994/11/24}{Added test for \cs{endgraf}}
748 % The internal version of |\newenvironment|.
750 % Call |\newcommand| to define the \meta{begin-code} for the
751 % environment. |\def| is used for the \meta{end-code} as it does
752 % not take arguments. (but may contain |\par|s)
754 % Make sure that an attempt to define a `graf' or `group' environment
757 \long\def\@newenv#1#2#3#4{%
759 {\expandafter\let\csname#1\expandafter\endcsname
760 \csname end#1\endcsname}%
762 \expandafter\new@command
763 \csname #1\endcsname#2{#3}%
764 \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}
768 % \begin{macro}{\newif}
769 % \changes{v1.1l}{1995/05/24}{(DPC) New implementation}
770 % And here's a different sort of allocation:
772 % |\newif\iffoo| creates |\footrue|, |\foofalse| to go with |\iffoo|.
775 \count@\escapechar \escapechar\m@ne
782 % \begin{macro}{\@if}
785 \expandafter\def\csname\expandafter\@gobbletwo\string#1%
786 \expandafter\@gobbletwo\string#2\endcsname
793 % \begin{macro}{\providecommand}
794 % |\providecommand| takes the same arguments as |\newcommand|, but
795 % discards them if |#1| is already defined, Otherwise it just acts like
796 % |\newcommand|. This implementation currently leaves any discarded
797 % definition in |\reserved@a| (and possibly |\\reserved@a|) this
798 % wastes a bit of space, but it will be reclaimed as soon as these
799 % scratch macros are redefined.
801 % \changes{LaTeX2e}{1993/11/22}{Macro added}
803 \def\providecommand{\@star@or@long\provide@command}
806 % \begin{macro}{\provide@command}
807 % \changes{v1.2z}{1997/09/09}{Use \cs{begingroup} to avoid generating
808 % math ords if used in math mode. pr/2573}
810 \def\provide@command#1{%
812 \escapechar\m@ne\xdef\@gtempa{{\string#1}}%
814 \expandafter\@ifundefined\@gtempa
815 {\def\reserved@a{\new@command#1}}%
816 {\def\reserved@a{\renew@command\reserved@a}}%
822 % \begin{macro}{\CheckCommand}
823 % \changes{LaTeX2e}{1993/11/22}{Macro added}
824 % \changes{v1.1e}{1994/05/20}{Changed name from \cs{@checkcommand} to
825 % \cs{CheckCommand}.}
826 % |\CheckCommand| takes the same arguments as |\newcommand|. If
827 % the command already exists, with the same definition, then
828 % nothing happens, otherwise a warning is issued. Useful for
829 % checking the current state befor a macro package starts
830 % redefining things. Currently two macros are considered to have
831 % the same definition if they are the same except for different
832 % default arguments. That is, if the old definition was:
833 % |\newcommand\xxx[2][a]{(#1)(#2)}| then
834 % |\CheckCommand\xxx[2][b]{(#1)(#2)}| would \emph{not} generate a
835 % warning, but, for instance |\CheckCommand\xxx[2]{(#1)(#2)}|
838 \def\CheckCommand{\@star@or@long\check@command}
840 % |\CheckCommand| is only available in the preamble part of the
843 \@onlypreamble\CheckCommand
846 % \begin{macro}{\check@command}
848 \def\check@command#1#2#{\@check@c#1{#2}}
849 \@onlypreamble\check@command
854 % \begin{macro}{\@check@c}
855 % \changes{v1.2i}{1995/04/25}{Make \cs{long} for latex/1346}
856 % |\CheckCommand| itself just grabs all the arguments we need,
857 % without actually looking for |[| optional argument forms. Now
858 % define |\reserved@a|. If |\\reserved@a| is then defined, compare it
859 % with the ``|\#1|' otherwise compare |\reserved@a| with |#1|.
861 \long\def\@check@c#1#2#3{%
862 \expandafter\let\csname\string\reserved@a\endcsname\relax
863 \renew@command\reserved@a#2{#3}%
864 \@ifundefined{\string\reserved@a}%
865 {\@check@eq#1\reserved@a}%
866 {\expandafter\@check@eq
867 \csname\string#1\expandafter\endcsname
868 \csname\string\reserved@a\endcsname}}
869 \@onlypreamble\@check@c
873 % \begin{macro}{\@check@eq}
874 % Complain if |#1| and |#2| are not |\ifx| equal.
878 \@latex@warning@no@line
879 {Command \noexpand#1 has
880 changed.\MessageBreak
881 Check if current package is valid}%
883 \@onlypreamble\@check@eq
887 % \begin{macro}{\@gobble}
888 % \begin{macro}{\@gobbletwo}
889 % \begin{macro}{\@gobblefour}
890 % \changes{v1.2n}{1995/05/26}{(CAR) Added \cs{long}s}
891 % The |\@gobble| macro is used to get rid of its argument.
893 \long\def \@gobble #1{}
894 \long\def \@gobbletwo #1#2{}
895 \long\def \@gobblefour #1#2#3#4{}
901 % \begin{macro}{\@firstofone}
902 % \begin{macro}{\@firstoftwo}
903 % \begin{macro}{\@secondoftwo}
904 % Some argument-grabbers.
906 \long\def\@firstofone#1{#1}
907 \long\def\@firstoftwo#1#2{#1}
908 \long\def\@secondoftwo#1#2{#2}
910 % \begin{macro}{\@iden}
911 % |\@iden| is another name for |\@firstofone| for
912 % compatibility reasons.
914 \let\@iden\@firstofone
921 % \begin{macro}{\@thirdofthree}
922 % Another grabber now used in the encoding specific
924 % \changes{v1.2z3}{1998/03/20}{Macro added}
926 \long\def\@thirdofthree#1#2#3{#3}
931 % \begin{macro}{\@expandtwoargs}
932 % A macro to totally expand two arguments to another macro
934 \def\@expandtwoargs#1#2#3{%
935 \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a}
939 % \begin{macro}{\@backslashchar}
940 % A category code 12 backslash.
942 \edef\@backslashchar{\expandafter\@gobble\string\\}
946 % \changes{v1.0n}{1994/05/10}{Added \cs{DeclareProtectedCommand}}
947 % \changes{v1.0p}{1994/05/12}{Fixed a bug with \cs{relax } which was
948 % using \cs{@gobble} before defining it.}
949 % \changes{v1.0q}{1994/05/13}{Renamed \cs{DeclareProtectedCommand} to
950 % \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}.
951 % Moved to after the definition of \cs{@gobble}.}
952 % \changes{v1.0r}{1994/05/13}{Added logging message to
953 % \cs{DeclareProtectedCommand}.}
955 % \subsection{Robust commands and protect}
957 % \changes{v1.1b}{1994/05/17}{Added the discussion of protected
958 % commands, defined the values that \cs{protect} should have.}
959 % \changes{v1.1c}{1994/05/18}{Redid the discussion and definitions, in
960 % line with the proposed new setting of \cs{protect} in the output
963 % Fragile and robust commands are one of the thornier issues in
964 % \LaTeX's commands. Whilst typesetting documents, \LaTeX{} makes use
965 % of many of \TeX's features, such as arithmetic, defining macros, and
966 % setting variables. However, there are (at least) three different
967 % occasions when these commands are not safe. These are called
968 % `moving arguments' by \LaTeX, and consist of:
970 % \item writing information to a file, such as indexes or tables of
972 % \item writing information to the screen.
973 % \item inside an |\edef|, |\message|, |\mark|, or other command which
974 % evaluates its argument fully.
976 % The method \LaTeX{} uses for making fragile commands robust is to
977 % precede them with |\protect|. This can have one of five possible
980 % \item |\relax|, for normal typesetting. So |\protect\foo| will
982 % \item |\string|, for writing to the screen. So |\protect\foo| will
984 % \item |\noexpand|, for writing to a file. So |\protect\foo| will
985 % write |\foo| followed by a space.
986 % \item |\@unexpandable@protect|, for writing a moving argument to a
987 % file. So |\protect\foo| will write |\protect\foo| followed by a
988 % space. This value is also used inside |\edef|s, |\mark|s and
989 % other commands which evaluate their arguments fully.
990 % \item |\@unexpandable@noexpand|, for performing a deferred write
991 % inside an |\edef|. So |\protect\foo| will write |\foo| followed
992 % by a space. If you want |\protect\foo| to be written, you should
993 % use |\@unexpandable@protect|. (Removed as never used).
996 % \changes{1.1b}{1994/05/17}
997 % {(ASAJ) Added the \cs{@protect@...} commands.}
998 % \changes{1.1c}{1994/05/18}
999 % {(ASAJ) Renamed the commands, and removed
1000 % one which is no longer needed.}
1002 % \begin{macro}{\@unexpandable@protect}
1003 % \begin{macro}{\@unexpandable@noexpand}
1004 % \changes{1.2w}{1995/12/05}{Removed as never used. internal/1733}
1005 % These commands are used for setting |\protect| inside |\edef|s.
1007 \def\@unexpandable@protect{\noexpand\protect\noexpand}
1008 %\def\@unexpandable@noexpand{\noexpand\noexpand\noexpand}
1013 % \changes{v1.2e}{1994/11/04}{Rewrote protected short commands
1014 % using \cs{x@protect}. ASAJ.}
1016 % \begin{macro}{\DeclareRobustCommand}
1017 % \begin{macro}{\declare@robustcommand}
1018 % This is a package-writers command, which has the same syntax as
1019 % |\newcommand|, but which declares a protected command. It does
1021 % |\DeclareRobustCommand\foo|\\
1022 % define |\foo| to be
1023 % |\protect\foo<space>|,\\
1024 % and then use |\newcommand\foo<space>|.\\
1025 % Since the internal command is |\foo<space>|, when it is written
1026 % to an auxiliary file, it will appear as |\foo|.
1029 % bit cleverer if we're defining a short command, such as |\_|, in
1030 % order to make sure that the auxiliary file does not include a
1031 % space after the command, since |\_ a| and |\_a| aren't the same.
1032 % In this case we define |\_| to be:
1034 % \x@protect\_\protect\_<space>
1038 % \ifx\protect\@typeset@protect\else
1043 % Then if |\protect| is |\@typeset@protect| (normally |\relax|)
1044 % then we just perform |\_<space>|, and otherwise
1045 % |\@x@protect@| gobbles everything up and expands to
1048 % \emph{Note}: setting |\protect| to any value other than |\relax|
1049 % whilst in `typesetting' mode will cause commands to go into an
1050 % infinite loop! In particular, setting |\relax| to |\@empty| will
1051 % cause |\_| to loop forever. It will also break lots of other
1052 % things, such as protected |\ifmmode|s inside |\halign|s. If you
1053 % really really have to do such a thing, then please set
1054 % |\@typeset@protect| to be |\@empty| as well. (This is what the
1055 % code for |\patterns| does, for example.)
1057 % More fun with |\expandafter| and |\csname|.
1059 \def\DeclareRobustCommand{\@star@or@long\declare@robustcommand}
1063 \def\declare@robustcommand#1{%
1064 \ifx#1\@undefined\else\ifx#1\relax\else
1065 \@latex@info{Redefining \string#1}%
1067 \edef\reserved@a{\string#1}%
1068 \def\reserved@b{#1}%
1069 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1071 \ifx\reserved@a\reserved@b
1076 \expandafter\noexpand\csname
1077 \expandafter\@gobble\string#1 \endcsname
1079 \let\@ifdefinable\@rc@ifdefinable
1080 \expandafter\new@command\csname
1081 \expandafter\@gobble\string#1 \endcsname
1088 % \begin{macro}{\@x@protect}
1089 % \begin{macro}{\x@protect}
1093 \ifx\protect\@typeset@protect\else
1097 \def\@x@protect#1\fi#2#3{%
1104 % \begin{macro}{\@typeset@protect}
1107 \let\@typeset@protect\relax
1111 % \changes{v1.2e}{1994/11/04}{Added commands for setting and restoring
1112 % \cs{protect}. ASAJ.}
1114 % \begin{macro}{\set@display@protect}
1115 % \begin{macro}{\set@typeset@protect}
1116 % These macros set |\protect| appropriately for typesetting or
1118 % \changes{v1.2o}{1995/07/03}{Use \cs{@typeset@protect} for init}
1120 \def\set@display@protect{\let\protect\string}
1121 \def\set@typeset@protect{\let\protect\@typeset@protect}
1126 % \begin{macro}{\protected@edef}
1127 % \begin{macro}{\protected@xdef}
1128 % \begin{macro}{\unrestored@protected@xdef}
1129 % \begin{macro}{\restore@protect}
1130 % The commands |\protected@edef| and |\protected@xdef| perform
1131 % `safe' |\edef|s and |\xdef|s, saving and restoring |\protect|
1132 % appropriately. For cases where restoring |\protect| doesn't
1133 % matter, there's an `unsafe' |\unrestored@protected@xdef|, useful
1134 % if you know what you're doing!
1136 \def\protected@edef{%
1137 \let\@@protect\protect
1138 \let\protect\@unexpandable@protect
1139 \afterassignment\restore@protect
1142 \def\protected@xdef{%
1143 \let\@@protect\protect
1144 \let\protect\@unexpandable@protect
1145 \afterassignment\restore@protect
1148 \def\unrestored@protected@xdef{%
1149 \let\protect\@unexpandable@protect
1152 \def\restore@protect{\let\protect\@@protect}
1160 % \begin{macro}{\protect}
1161 % The normal meaning of |\protect|
1162 % \changes{v1.2j}{1995/04/29}{Init \cs{protect} here}
1164 \set@typeset@protect
1168 % \begin{macro}{\MakeRobust}
1169 % \changes{v1.4a}{2015/01/08}{Added macro}
1171 % The macro firstly checks if the controls sequence in question exists
1175 %<latexrelease>\IncludeInRelease{2015/01/01}{\MakeRobust}{\MakeRobust}%
1176 %<*2ekernel|latexrelease>
1178 \@ifundefined{\expandafter\@gobble\string#1}{%
1179 \@latex@error{The control sequence `\string#1' is undefined!%
1180 \MessageBreak There is nothing here to make robust}%
1184 % Then we check if the macro is already robust. We do this by testing
1185 % if the internal name for a robust macro is defined, namely
1186 % \verb*=\foo =. If it is already defined do nothing, otherwise set
1187 % \verb*=\foo = equal to \verb*=\foo= and redefine \verb*=\foo= so
1188 % that it acts like a macro defined with \verb=\DeclareRobustCommand=.
1191 \@ifundefined{\expandafter\@gobble\string#1\space}%
1193 \expandafter\let\csname
1194 \expandafter\@gobble\string#1\space\endcsname=#1%
1195 \edef\reserved@a{\string#1}%
1196 \def\reserved@b{#1}%
1197 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1199 \ifx\reserved@a\reserved@b
1200 \noexpand\x@protect\noexpand#1%
1202 \noexpand\protect\expandafter\noexpand
1203 \csname\expandafter\@gobble\string#1\space\endcsname}%
1205 {\@latex@info{The control sequence `\string#1' is already robust}}%
1208 %</2ekernel|latexrelease>
1209 %<latexrelease>\EndIncludeInRelease
1210 %<latexrelease>\IncludeInRelease{0000/00/00}{\MakeRobust}{\MakeRobust}%
1211 %<latexrelease>\let\MakeRobust\@undefined
1212 %<latexrelease>\EndIncludeInRelease
1217 % \subsection{Internal defining commands}
1219 % These commands are used internally to define other \LaTeX{}
1221 % \begin{macro}{\@ifundefined}
1222 % \changes{LaTeX2e}{1993/11/23}{Redefined to remove a trailing \cs{fi}}
1223 % Check if first arg is undefined or \cs{relax} and execute second or
1224 % third arg depending,
1226 \def\@ifundefined#1{%
1227 \expandafter\ifx\csname#1\endcsname\relax
1228 \expandafter\@firstoftwo
1230 \expandafter\@secondoftwo
1236 % \begin{macro}{\@qend}
1237 % \begin{macro}{\@qrelax}
1238 % The following define |\@qend| and |\@qrelax| to be the strings
1239 % `|end|' and `|relax|' with the characters |\catcode|d 12.
1241 \edef\@qend{\expandafter\@cdr\string\end\@nil}
1242 \edef\@qrelax{\expandafter\@cdr\string\relax\@nil}
1248 % \begin{macro}{\@ifnextchar}
1249 % \changes{LaTeX209}{1992/08/24}
1250 % {(Rms) \cs{@ifnextchar} didn't work if its
1251 % first argument was an equal sign.}
1252 % \changes{v1.2q}{1995/10/02}
1253 % {Use \cs{@let@token} }
1254 % \changes{v1.3a}{1999/01/07}
1256 % \changes{v1.3b}{1999/01/07}
1257 % {extra \cs{long}. latex/2902}
1258 % \changes{v1.3e}{1999/03/01}
1259 % {remove extra \cs{long}. internal/2967}
1260 % |\@ifnextchar| peeks at the following character and compares it
1261 % with its first argument. If both are the same it executes its
1262 % second argument, otherwise its third.
1264 \long\def\@ifnextchar#1#2#3{%
1266 \def\reserved@a{#2}%
1267 \def\reserved@b{#3}%
1268 \futurelet\@let@token\@ifnch}
1272 % \begin{macro}{\kernel@ifnextchar}
1273 % \changes{v1.3g}{2004/01/23}{Added macro (pr/3501)}
1274 % This macro is the kernel version of |\@ifnextchar| which is used
1275 % in a couple of places to prevent the AMS variant from being used
1276 % since in some places this produced chaos (for example
1277 % if an \texttt{fd} file
1278 % is loaded in a random place then the optional argument to
1279 % |\ProvidesFile| could get printed there instead of being written
1280 % only in the log file. This happened
1281 % when there was a space or a newline between the mandatory and
1282 % optional arguments! It should really be fixed in the
1283 % \texttt{amsmath} package one day, but\ldots
1285 % Note that there may be other places in the kernel where this version
1286 % should be used rather than the original, but variable, version.
1289 \let\kernel@ifnextchar\@ifnextchar
1294 % \begin{macro}{\@ifnch}
1295 % |\@ifnch| is a tricky macro to skip any space tokens that may
1296 % appear before the character in question. If it encounters a space
1297 % token, it calls \@xifnch.
1298 % \changes{v1.2q}{1995/10/02}
1299 % {Use \cs{@let@token} for internal/924, save \cs{reserved@e}}
1302 \ifx\@let@token\@sptoken
1303 \let\reserved@c\@xifnch
1305 \ifx\@let@token\reserved@d
1306 \let\reserved@c\reserved@a
1308 \let\reserved@c\reserved@b
1315 % \begin{macro}{\@sptoken}
1316 % The following code makes |\@sptoken| a space token. It is
1317 % important here that the control sequence |\:| consists of
1318 % a non-letter only, so that the following whitespace is
1319 % significant. Together with the fact that the equal sign
1320 % in a |\let| may be followed by only one optional space
1321 % the desired effect is achieved.
1322 % NOTE: the following hacking must precede the definition of |\:|
1323 % as math medium space.
1325 \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token
1329 % \begin{macro}{\@xifnch}
1330 % In the following definition of |\@xifnch|, |\:| is again used
1331 % to get a space token as delimiter into the definition.
1333 \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}
1337 % \changes{v1.0n}{1994/05/10}{Added \cs{makeatletter} and
1338 % \cs{makeatother} ASAJ.}
1340 % \begin{macro}{\makeatletter}
1341 % \begin{macro}{\makeatother}
1342 % Make internal control sequences accessible or inaccessible.
1344 \def\makeatletter{\catcode`\@11\relax}
1345 \def\makeatother{\catcode`\@12\relax}
1351 % \begin{macro}{\@ifstar}
1352 % \changes{v1.2u}{1995/10/16}{(DPC) New implementation, for /1910}
1353 % The new implementation below avoids passing the \meta{true code}
1354 % Through one more |\def| than the \meta{false code}, which previously
1355 % meant that |#| had to be written as |####| in one argument, but |##|
1356 % in the other. The |*| is gobbled by |\@firstoftwo|.
1358 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
1362 % \begin{macro}{\@dblarg}
1363 % \begin{macro}{\@xdblarg}
1364 % \changes{v1.1g}{2004/01/23}{Use kernel version of
1365 % \cs{@ifnextchar} (pr/3501)}
1367 \long\def\@dblarg#1{\kernel@ifnextchar[{#1}{\@xdblarg{#1}}}
1368 \long\def\@xdblarg#1#2{#1[{#2}]{#2}}
1373 % \begin{macro}{\@sanitize}
1374 % The command |\@sanitize| changes the catcode of all special characters
1375 % except for braces to `other'. It can be used for commands like
1376 % |\index| that want to write their arguments verbatim. Needless to
1377 % say, this command should only be executed within a group, or chaos
1381 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
1382 \@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~}
1386 % \begin{macro}{\@onelevel@sanitize}
1387 % \changes{v1.2c}{1994/10/30}{Macro added}
1389 % This makes the whole ``meaning'' of |#1| (its one-level
1390 % expansion) into catcode 12 tokens: it could be used in
1391 % |\DeclareRobustCommand|.
1393 % If it is to be used on default float specifiers, this should be
1394 % done when they are defined.
1396 \def \@onelevel@sanitize #1{%
1397 \edef #1{\expandafter\strip@prefix
1403 % \section{Discretionary Hyphenation}
1405 % \changes{1.2x}{1995/12/13}{Documentation changed.}
1406 % \changes{v1.5a}{2017/03/13}{Define \cs{-} in terms of \cs{hyphenchar}}
1407 % \begin{macro}{\@dischyph}
1408 % \changes{v1.0g}{1994/04/12}
1409 % {Define \cs{@dischyph}, was previously in ltboxes.dtx}
1410 % \changes{v1.5b}{2017/03/27}{Define \cs{@dischyph} after \cs{-}}
1412 % Moved here to be after the definition of |\DeclareRobustCommand|.
1414 % The primitive |\-| command adds a discretionary hyphen using the
1415 % current font's |\hyphenchar|. Monospace fonts are usually declared
1416 % with |\hyphenchar| set to $-1$ to suppress hyhenation.
1418 % \LaTeX, from \LaTeX2.09 in 1986 defined |\-| by
1420 % \def\-{\discretionary{-}{}{}}
1422 % The following comment was added when these commands were first set
1423 % up, 19 April 1986:
1425 % the |\-| command is redefined to allow it to work in the |\ttfamily|
1426 % type style, where automatic hyphenation is suppressed by setting
1427 % |\hyphenchar| to~$-1$. The original primitive \TeX{} definition is
1428 % saved as |\@@hyph| just in case anyone needs it.
1431 % \LaTeXe, between 1993 and 2017, had a comment at this point
1432 % saying that the definition ``would probably change'' because
1433 % the definition always uses |-|. The definition used below
1434 % was given in comments at this point during time.
1436 % In 2017 we finally enabled this definition by default, with the
1437 % older \LaTeX\ definition accessible via \textsf{latexrelease}
1442 %<latexrelease>\IncludeInRelease{2017/05/01}{\-}{Use \hyphenchar in \-}%
1444 % Temporary definition of |\@latex@info|, final definition is later.
1447 \def\@latex@info#1{}
1452 %<*2ekernel|latexrelease>
1453 \DeclareRobustCommand{\-}{%
1455 \char \ifnum\hyphenchar\font<\z@
1463 %</2ekernel|latexrelease>
1464 %<latexrelease>\EndIncludeInRelease
1465 %<latexrelease>\IncludeInRelease{0000/00/00}{\-}{Use \hyphenchar in \-}%
1466 %<latexrelease>\def\-{\discretionary{-}{}{}}
1467 %<latexrelease>\let\@dischyph=\-
1468 %<latexrelease>\EndIncludeInRelease