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 [2015/02/21 v1.4b LaTeX Kernel (definition commands)]
37 \documentclass{ltxdoc}
38 \GetFileInfo{ltdefns.dtx}
50 \MaintainedByLaTeXTeam{latex}
59 % \changes{v1.0n}{1994/05/10}{(ASAJ) Added
60 % \cs{DeclareProtectedCommand}.}
61 % \changes{v1.0p}{1994/05/12}{(ASAJ) Fixed a bug with \cs{relax}
63 % using \cs{@gobble} before defining it.}
64 % \changes{v1.0q}{1994/05/13}{(ASAJ) Renamed
65 % \cs{DeclareProtectedCommand} to
66 % \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}.}
67 % \changes{v1.0q}{1994/05/13}{(ASAJ) Replaces \cs{space} by `~' in
69 % \changes{v1.0r}{1994/05/13}{(ASAJ) Added logging message to
70 % \cs{DeclareProtectedCommand}.}
71 % \changes{v1.0s}{1994/05/13}{(ASAJ) Added \cs{@backslashchar}.}
72 % \changes{v1.0s}{1994/05/13}{(ASAJ) Coded \cs{@ifdefinable} more
74 % \changes{v1.1a}{1994/05/16}{(ASAJ) Split from ltinit.dtx.}
75 % \changes{v1.1b}{1994/05/17}{(ASAJ) Removed warnings and logging to
77 % \changes{v1.1b}{1994/05/17}{(ASAJ) Added definitions for protect.}
78 % \changes{v1.1c}{1994/05/17}{(ASAJ) Redid definitions for protect.}
79 % \changes{v1.1d}{1994/05/19}{(RmS) Added definitions for
80 % \cs{@namedef} and \cs{@nameuse} again.}
81 % \changes{v1.1e}{1994/05/20}{Changed command name from
82 % \cs{@checkcommand} to \cs{CheckCommand}.}
83 % \changes{v1.1f}{1994/05/22}{Use new warning and error cmds}
84 % \changes{v1.2a}{1994/10/18}{Add star-forms for all commands}
85 % \changes{v1.2a}{1994/10/18}{Add extra test for \cs{endgraf}}
86 % \changes{v1.2b}{1994/10/25}{Documentation improvements}
87 % \changes{v1.2c}{1994/10/30}{(CAR)\cs{@onelevel@sanitize} added}
88 % \changes{v1.2f}{1994/10/30}{(DPC)\cs{newwrite}'s moved to ltfiles}
89 % \changes{v1.0g}{1994/11/17}
90 % {\cs{@tempa} to \cs{reserved@a}}
91 % \changes{v1.0p}{1995/07/13}{Updates to documentation}
92 % \changes{v1.4b}{2015/02/21}
93 % {Removed autoload support}
95 % \section{Definitions}
97 % This section contains commands used in defining other macros.
105 % \subsection{Initex initialisations}
107 % \task{???}{This section needs extension}
109 % \begin{macro}{\two@digits}
110 % \changes{LaTeX2e}{1993/11/23}{Macro added}
111 % Prefix a number less than 10 with `0'.
113 \def\two@digits#1{\ifnum#1<10 0\fi\number#1}
117 % \changes{v1.2e}{1994/11/04}{Added \cs{set@display@protect} to
118 % \cs{typeout}. ASAJ.}
120 % \begin{macro}{\typeout}
121 % Display something on the terminal.
123 \def\typeout#1{\begingroup\set@display@protect
124 \immediate\write\@unused{#1}\endgroup}
128 % \begin{macro}{\newlinechar}
129 % A char to be used as new-line in output to files.
135 % \subsection{Saved versions of \TeX{} primitives}
137 % The TeX primitive |\foo| is saved as |\@@foo|.
138 % The following primitives are handled in this way:
139 % \begin{macro}{\@@par}
142 %\let\@@input=\input %%% moved earlier
147 % \begin{macro}{\@@hyph}
149 % \changes{1.2x}{1995/12/13}{Documentation changed.}
150 % The following comment was added when these commands were first set
152 % the |\-| command is redefined to allow it to work in the |\ttfamily|
153 % type style, where automatic hyphenation is suppressed by setting
154 % |\hyphenchar| to~$-1$. The original primitive \TeX{} definition is
155 % saved as |\@@hyph| just in case anyone needs it.
157 % There is a need for a robust command for a discretionary hyphen
158 % since its exact representation depends on the glyphs available in
159 % the current font. For example, with suitable fonts and the
160 % \texttt{T1} font encoding it is possible to use hanging hyphens.
162 % A suitable robust definition that allows for many possible types of
163 % font and encoding may be as follows:
165 % \DeclareRobustCommand {\-}{%
167 % \char \ifnum\hyphenchar\font<\z@
176 % The redefinition (via |\let|) of |\-| within tabbing also makes the
177 % use of a robust command advisable since then any redefinition
178 % of |\-| via |\DeclareRobustCommand| will not cause a conflict.
180 % Therefore, macro writers should be hereby warned that
181 % these internals will probably change! It is likely that a future
182 % release of \LaTeX{} will make |\-| effectively an encoding specific
186 \let\@@hyph=\- % Save original primitive definition
187 \def\-{\discretionary{-}{}{}}
192 % \begin{macro}{\@dischyph}
193 % \changes{v1.0g}{1994/04/12}
194 % {Define \cs{@dischyph}, was previously in ltboxes.dtx}
200 % \begin{macro}{\@@italiccorr}
201 % Save the original italic correction.
202 % \changes{v1.0a}{1994/03/07}{Macro added}
208 % \begin{macro}{\@height}
209 % \begin{macro}{\@depth}
210 % \begin{macro}{\@width}
211 % \begin{macro}{\@minus}
212 % \changes{LaTeX2e}{1993/11/22}{Macro added}
213 % \begin{macro}{\@plus}
214 % \changes{LaTeX2e}{1993/11/22}{Macro added}
216 % The following definitions save token space. E.g., using
217 % |\@height| instead of height saves 5 tokens at the cost in time
218 % of one macro expansion.
220 \def\@height{height} \def\@depth{depth} \def\@width{width}
224 % \begin{macro}{\hb@xt@}
225 % \changes{v1.2k}{1995/05/07}{Macro added}
226 % The next one is another 100 tokens worth.
228 \def\hb@xt@{\hbox to}
241 % \subsection{Command definitions}
243 % This section defines the following commands:
246 % {\@namedef}\marg{NAME}\\ Expands to |\def\|\marg{NAME},
247 % except name can contain any characters.
250 % {\@nameuse}\marg{NAME}\\
251 % Expands to |\|\marg{NAME}.
254 % {\@ifnextchar} X\marg{YES}\marg{NO}\\
255 % Expands to \meta{YES} if next character is an `X',
256 % and to \meta{NO} otherwise.
257 % (Uses |\reserved@a|--|\reserved@c|.)
258 % NOTE: GOBBLES ANY SPACE FOLLOWING IT.
261 % {\@ifstar}\marg{YES}\marg{NO}\\
262 % Gobbles following spaces and then tests if next the
263 % character is a '*'. If it is, then it gobbles the
264 % `*' and expands to \meta{YES}, otherwise it expands to \meta{NO}.
267 % {\@dblarg}\marg{CMD}\marg{ARG}\\
268 % Expands to |\|\marg{CMD}\oarg{ARG}\marg{ARG}. Use
269 % |\@dblarg\CS| when |\CS| takes arguments |[ARG1]{ARG2}|,
270 % where default is| ARG1| = |ARG2|.
273 % {\@ifundefined}\marg{NAME}\marg{YES}\marg{NO}\\
274 % : If \cs{NAME} is undefined then it executes \meta{YES},
275 % otherwise it executes \meta{NO}. More precisely,
276 % true if \cs{NAME} either undefined or = |\relax|.
279 % {\@ifdefinable}|\NAME|\marg{YES}
280 % Executes \meta{YES} if the user is allowed to define |\NAME|,
281 % otherwise it gives an error. The user can define |\NAME|
282 % if |\@ifundefined{NAME}| is true, '|NAME|' $\neq$ '|relax|'
283 % and the first three letters of '|NAME|' are not
284 % '|end|', and if |\endNAME| is not defined.
287 % \newcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
288 % User command to define |\FOO| to be a macro with
289 % i arguments (i = 0 if missing) having the definition
290 % \meta{TEXT}. Produces an error if |\FOO| already
293 % Normally the command is defined to be |\long| (ie it may
294 % take multiple paragraphs in its argument). In the
295 % star-form, the command is not defined as |\long| and a
296 % blank line in any argument to the command would generate
300 % \renewcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
301 % Same as |\newcommand|, except it checks if |\FOO| already defined.
304 % \newenvironment|*|\marg{FOO}\oarg{i}\marg{DEF1}\marg{DEF2}\\
306 % |\newcommand{\FOO}[i]{DEF1}| |\def{\endFOO}{DEF2}|\\
307 % (or the appropriate star forms).
310 % \renewenvironment\\ Obvious companion to |\newenvironment|.
313 % \@cons : See description of |\output| routine.
315 % \DescribeMacro{\@car}
316 % |\@car T1 T2 ... Tn\@nil| == |T1| (unexpanded)
318 % \DescribeMacro{\@cdr}
319 % |\@cdr T1 T2 ... Tn\@ni|l == |T2 ... Tn| (unexpanded)
322 % \typeout\marg{message}\\ Produces a warning message on the terminal.
325 % \typein\marg{message}\\
326 % Types message, asks the user to type in a command, then
330 % \typein\oarg{\cs{CS}}\marg{MSG}\\
331 % Same as above, except defines |\CS| to be the input
332 % instead of executing it.
334 % \changes{LaTeX209}{1992/03/18}
335 % {(RMS) changed input channel from 0 to \cs{@inputcheck} to avoid
336 % conflicts with other channels allocated by \cs{newread}}
338 % \begin{macro}{\typein}
340 % \changes{v1.2k}{1995/05/08}{Use \cs{@firstofone}}
341 % \changes{v1.2l}{1995/05/08}{Remove unnecessary braces}
342 % \changes{v1.2l}{1995/05/08}{Replace \cs{def} by \cs{let}}
343 % \changes{v1.2m}{1995/05/24}{(DPC) New implementation}
344 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
348 \@testopt\@xtypein\@typein}
351 % \changes{v1.2r}{1995/10/03}
352 % {Add missing \cs{@typein} for /1710 (from patch file)}
353 % \changes{v1.4a}{2015/01/03}{use modified definition in luatex}
355 \ifx\directlua\@undefined
359 \def\@xtypein[#1]#2{%
361 \advance\endlinechar\@M
362 \read\@inputcheck to#1%
363 \advance\endlinechar-\@M
372 \def\@xtypein[#1]#2{%
374 \begingroup \endlinechar\m@ne
375 \read\@inputcheck to#1%
376 \expandafter\endgroup
377 \expandafter\def\expandafter#1\expandafter{#1}%
386 % \begin{macro}{\@namedef}
388 \def\@namedef#1{\expandafter\def\csname #1\endcsname}
392 % \begin{macro}{\@nameuse}
394 \def\@nameuse#1{\csname #1\endcsname}
398 % \begin{macro}{\@cons}
400 \def\@cons#1#2{\begingroup\let\@elt\relax\xdef#1{#1\@elt #2}\endgroup}
404 % \begin{macro}{\@car}
405 % \begin{macro}{\@cdr}
407 \def\@car#1#2\@nil{#1}
408 \def\@cdr#1#2\@nil{#2}
413 % \begin{macro}{\@carcube}
414 % |\@carcube T1 ... Tn\@nil| = |T1| |T2| |T3| , $n > 3$
416 \def\@carcube#1#2#3#4\@nil{#1#2#3}
422 % \begin{macro}{\@onlypreamble}
423 % \begin{macro}{\@preamblecmds}
424 % This macro adds its argument to the list of commands stored in
425 % |\@preamblecmds| to be
426 % disabled after |\begin{document}|. These commands are redefined
427 % to generate |\@notprerr| at this point.
430 \def\@onlypreamble#1{%
431 \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
432 \@preamblecmds\do#1}}
433 \@onlypreamble\@onlypreamble
434 \@onlypreamble\@preamblecmds
440 % \begin{macro}{\@star@or@long}
441 % \changes{v1.2a}{1994/10/18}{macro added}
442 % Look ahead for a |*|. If present reset |\l@ngrel@x| so that
443 % the next definition, |#1|, will be non-long.
445 \def\@star@or@long#1{%
447 {\let\l@ngrel@x\relax#1}%
448 {\let\l@ngrel@x\long#1}}
453 % \begin{macro}{\l@ngrel@x}
454 % This is either |\relax| or |\long| depending on whether the |*|-form
455 % of a definition command is being executed.
461 % \begin{macro}{\newcommand}
462 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
463 % User level |\newcommand|.%
465 \def\newcommand{\@star@or@long\new@command}
468 % \begin{macro}{\new@command}
469 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
472 \@testopt{\@newcommand#1}0}
478 % \begin{macro}{\@newcommand}
479 % \changes{LaTeX2e}{1993/11/23}{Macro added}
480 % \begin{macro}{\@argdef}
481 % \changes{LaTeX2e}{1993/11/23}{Macro added}
482 % \begin{macro}{\@xargdef}
483 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
484 % \changes{v1.1g}{2004/01/23}{Use kernel version of
485 % \cs{@ifnextchar} (pr/3501)}
486 % Handling arguments for |\newcommand|.
488 \def\@newcommand#1[#2]{%
489 \kernel@ifnextchar [{\@xargdef#1[#2]}%
492 % Define |#1| if it is definable.
494 % Both here and in |\@xargdef| the replacement text is absorbed as
495 % an argument because if we are not allowed to make the definition
496 % we have to get rid of it completely.
498 \long\def\@argdef#1[#2]#3{%
499 \@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}}
502 % \changes{v1.2q}{1995/10/02}
503 % {New implementation, using \cs{@test@opt}}
504 % Handle the second optional argument.
506 \long\def\@xargdef#1[#2][#3]#4{%
509 % Define the actual command to be:\\
510 % |\def\foo{\@protected@testopt\foo\\foo{default}}|\\
511 % where |\\foo| is a csname generated from applying |\csname| and
512 % |\string| to |\foo|, ie the actual name contains a backslash and
513 % therefore can't clash easily with existing command names.
514 % ``Default'' is the contents of the second optional argument of
517 % \changes{v1.2z2}{1998/03/04}
518 % {Unnecessary \cs{expandafter} removed: pr/2758}
520 \expandafter\def\expandafter#1\expandafter{%
525 \csname\string#1\endcsname
528 % Now we define the internal macro ie |\\foo| which is supposed to
529 % pick up all arguments (optional and mandatory).
531 \expandafter\@yargdef
532 \csname\string#1\endcsname
541 % \begin{macro}{\@testopt}
542 % \changes{v1.2q}{1995/10/02}
544 % \changes{v1.3a}{1999/01/07}
545 % {made long and brace optional arg. latex/2896}
546 % This macro encapsulates the most common call to |\@ifnextchar|, saving
547 % several tokens each time it is used in the definition of a command
548 % with an optional argument.
549 % |#1| The code to execute in the case that there is a |[| need not be
550 % a single token but can be any sequence of commands that `expects' to
551 % be followed by |[|. If this command were only used in |\newcommand|
552 % definitions then |#1| would be a single token and the braces could
553 % be omitted from |{#1}| in the definition below, saving a bit of
555 % \changes{v1.1g}{2004/01/23}{Use kernel version of
556 % \cs{@ifnextchar} (pr/3501)}
558 \long\def\@testopt#1#2{%
559 \kernel@ifnextchar[{#1}{#1[{#2}]}}
563 % \begin{macro}{\@protected@testopt}
564 % \changes{v1.2q}{1995/10/02}
566 % Robust version of |\@testopt|. The extra argument (|#1|) must be a
567 % single token. If protection is needed the call expands to |\protect|
568 % applied to this token, and the 2nd and 3rd arguments are
569 % discarded (by |\@x@protect|). Otherwise |\@testopt| is called on
570 % the 2nd and 3rd arguments.
572 % This method of making commands robust avoids the need for using up
573 % two csnames per command, the price is the extra expansion time
574 % for the |\ifx| test.
576 \def\@protected@testopt#1{%%
577 \ifx\protect\@typeset@protect
578 \expandafter\@testopt
585 % \begin{macro}{\@yargdef}
586 % \begin{macro}{\@yargd@f}
587 % \changes{v1.3f}{1999/04/29}{New macro added}
589 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
590 % \changes{LaTeX2e}{1993/11/23}{Avoid \cs{@?@?} token}
591 % \changes{v1.0b}{1994/03/12}{Name changed from \cs{XXX@argdef}}
592 % \changes{v1.3c}{1999/01/18}{New implementation DPC /2942}
593 % \changes{v1.3d}{1999/02/09}{catch bad argument forms by re-inserting \#3}
594 % \changes{v1.3f}{1999/04/29}{Full expansion and conversion needed
595 % for digit in new version, see pr/3013}
597 % These generate a primitive argument specification, from a
598 % \LaTeX\ |[|\meta{digit}|]| form; in fact \meta{digit} can be
599 % anything such that |\number|~\meta{digit} is single digit.
601 % Reorganised slightly so that |\renewcommand{\reserved@a}[1]{foo}|
602 % works. I am not sure this is worth it, as a following
603 % |\newcommand| would over-write the definition of |\reserved@a|.
605 % Recall that \LaTeX2.09 goes into an infinite loop with\\
606 % |\renewcommand[1]{\@tempa}{foo}|\\
607 % (DPC 6 October 93).
609 % Reorganised again (DPC 1999). Rather than make a loop to
610 % construct the argument spec by counting, just extract the
611 % required argument spec by using a delimited argument (delimited
612 % by the digit). This is faster and uses less tokens. The coding
613 % is slightly odd to preserve the old interface (using |#2| =
614 % |\tw@| as the flag to surround the first argument with |[]|. But
615 % the new method did not allow for the number of arguments |#3| not
616 % being given as an explicit digit; hence (further expansion of
617 % this argument and use of) |\number| was added later in 1999.
619 % It is not clear why these are still |\long|.
622 \long \def \@yargdef #1#2#3{%
624 \def\reserved@b##11{[####1]}%
626 \let\reserved@b\@gobble
629 \@yargd@f \expandafter{\number #3}#1%
634 \long \def \@yargd@f#1#2{%
635 \def \reserved@a ##1#1##2##{%
636 \expandafter\def\expandafter#2\reserved@b ##1#1%
638 \l@ngrel@x \reserved@a 0##1##2##3##4##5##6##7##8##9###1%
645 % \begin{macro}{\@reargdef}
646 % \changes{LaTeX2e}{1993/12/20}
647 % {Kept old version of \cs{@reargdef}, for array.sty}
648 % \changes{v1.0b}{1994/03/12}{New defn, in terms of \cs{@yargdef}}
649 % \changes{v1.2y}{1996/07/26}{third arg picked up by \cs{@yargdef}}
651 \long\def\@reargdef#1[#2]{%
656 % \begin{macro}{\renewcommand}
657 % Check the command name is already used. If not give an error
658 % message. Then temporarily
659 % disable |\@ifdefinable| then call |\newcommand|. (Previous
660 % version |\let#1=\relax| but this does not work too well if |#1|
661 % is |\@temp|\emph{a--e}.)
662 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
663 % \changes{v1.1f}{1994/05/2}{Removed surplus \cs{space} in error}
665 \def\renewcommand{\@star@or@long\renew@command}
668 % \begin{macro}{\renew@command}
669 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
670 % \changes{v1.2y}{1996/07/26}{use \cs{noexpand} instead of \cs{string}}
671 % \changes{v1.2z1}{1997/10/21}{Use \cs{begingroup}/\cs{endgroup} rather
672 % than braces for grouping, to avoid generating empty math atom.}
674 \def\renew@command#1{%
675 \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
676 \expandafter\@ifundefined\@gtempa
677 {\@latex@error{\noexpand#1undefined}\@ehc}%
679 \let\@ifdefinable\@rc@ifdefinable
685 % \changes{v1.0n}{1994/05/10}{Removed braces around \cs{@ifundefined}
687 % \changes{v1.0s}{1994/05/13}{Coded more efficiently, thanks to FMi.}
689 % \begin{macro}{\@ifdefinable}
690 % \begin{macro}{\@@ifdefinable}
691 % \begin{macro}{\@rc@ifdefinable}
692 % Test is user is allowed to define a command.
694 \long\def\@ifdefinable #1#2{%
695 \edef\reserved@a{\expandafter\@gobble\string #1}%
696 \@ifundefined\reserved@a
697 {\edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
698 \ifx \reserved@b\@qend \@notdefinable\else
699 \ifx \reserved@a\@qrelax \@notdefinable\else
705 % Saved definition of |\@ifdefinable|.
707 \let\@@ifdefinable\@ifdefinable
709 % Version of |\@ifdefinable| for use with |\renewcommand|. Does
710 % not do the check this time, but restores the normal definition.
712 \long\def\@rc@ifdefinable#1#2{%
713 \let\@ifdefinable\@@ifdefinable
720 % \begin{macro}{\newenvironment}
721 % Define a new user environment.
722 % |#1| is the environment name. |#2#| Grabs all the tokens up to
723 % the first |{|. These will be any optional arguments. They are not
724 % parsed at this point, but are just passed to |\@newenv| which
725 % will eventually call |\newcommand|. Any optional arguments will
726 % then be parsed by |\newcommand| as it defines the command that
727 % executes the `begin code' of the environment.
729 % This |#2#| trick removed with version 1.2i as it fails if a |{|
730 % occurs in the optional argument. Now use |\@ifnextchar| directly.
732 \def\newenvironment{\@star@or@long\new@environment}
735 % \begin{macro}{\new@environment}
736 % \changes{v1.2i}{1995/04/25}{Parse arguments slowly but safely /1507}
737 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
739 \def\new@environment#1{%
740 \@testopt{\@newenva#1}0}
743 % \begin{macro}{\@newenva}
744 % \changes{v1.1g}{2004/01/23}{Use kernel version of
745 % \cs{@ifnextchar} (pr/3501)}
747 \def\@newenva#1[#2]{%
748 \kernel@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}}
752 % \begin{macro}{\@newenvb}
753 % \changes{v1.3a}{1999/01/07}
754 % {made long and brace optional arg. latex/2896}
756 \def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][{#3}]}}
764 % \begin{macro}{\renewenvironment}
765 % Redefine an environment.
766 % For |\renewenvironment| disable |\@ifdefinable| and then call
767 % |\newenvironment|. It is OK to |\let| the argument to |\relax|
768 % here as there should not be a |@temp|\ldots\ environment.
769 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
770 % \changes{v1.1f}{1994/05/2}{Removed surplus \cs{space} in error}
772 \def\renewenvironment{\@star@or@long\renew@environment}
775 % \begin{macro}{\renew@environment}
776 % \changes{v1.2a}{1994/10/18}{reset end command}
777 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
779 \def\renew@environment#1{%
781 {\@latex@error{Environment #1 undefined}\@ehc
783 \expandafter\let\csname#1\endcsname\relax
784 \expandafter\let\csname end#1\endcsname\relax
785 \new@environment{#1}}
791 % \begin{macro}{\@newenv}
792 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
793 % \changes{v1.2h}{1994/11/24}{Added test for \cs{endgraf}}
794 % The internal version of |\newenvironment|.
796 % Call |\newcommand| to define the \meta{begin-code} for the
797 % environment. |\def| is used for the \meta{end-code} as it does
798 % not take arguments. (but may contain |\par|s)
800 % Make sure that an attempt to define a `graf' or `group' environment
803 \long\def\@newenv#1#2#3#4{%
805 {\expandafter\let\csname#1\expandafter\endcsname
806 \csname end#1\endcsname}%
808 \expandafter\new@command
809 \csname #1\endcsname#2{#3}%
810 \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}
814 % \begin{macro}{\newif}
815 % \changes{v1.1l}{1995/05/24}{(DPC) New implementation}
816 % And here's a different sort of allocation:
818 % |\newif\iffoo| creates |\footrue|, |\foofalse| to go with |\iffoo|.
821 \count@\escapechar \escapechar\m@ne
828 % \begin{macro}{\@if}
831 \expandafter\def\csname\expandafter\@gobbletwo\string#1%
832 \expandafter\@gobbletwo\string#2\endcsname
839 % \begin{macro}{\providecommand}
840 % |\providecommand| takes the same arguments as |\newcommand|, but
841 % discards them if |#1| is already defined, Otherwise it just acts like
842 % |\newcommand|. This implementation currently leaves any discarded
843 % definition in |\reserved@a| (and possibly |\\reserved@a|) this
844 % wastes a bit of space, but it will be reclaimed as soon as these
845 % scratch macros are redefined.
847 % \changes{LaTeX2e}{1993/11/22}{Macro added}
849 \def\providecommand{\@star@or@long\provide@command}
852 % \begin{macro}{\provide@command}
853 % \changes{v1.2z}{1997/09/09}{Use \cs{begingroup} to avoid generating
854 % math ords if used in math mode. pr/2573}
856 \def\provide@command#1{%
858 \escapechar\m@ne\xdef\@gtempa{{\string#1}}%
860 \expandafter\@ifundefined\@gtempa
861 {\def\reserved@a{\new@command#1}}%
862 {\def\reserved@a{\renew@command\reserved@a}}%
868 % \begin{macro}{\CheckCommand}
869 % \changes{LaTeX2e}{1993/11/22}{Macro added}
870 % \changes{v1.1e}{1994/05/20}{Changed name from \cs{@checkcommand} to
871 % \cs{CheckCommand}.}
872 % |\CheckCommand| takes the same arguments as |\newcommand|. If
873 % the command already exists, with the same definition, then
874 % nothing happens, otherwise a warning is issued. Useful for
875 % checking the current state befor a macro package starts
876 % redefining things. Currently two macros are considered to have
877 % the same definition if they are the same except for different
878 % default arguments. That is, if the old definition was:
879 % |\newcommand\xxx[2][a]{(#1)(#2)}| then
880 % |\CheckCommand\xxx[2][b]{(#1)(#2)}| would \emph{not} generate a
881 % warning, but, for instance |\CheckCommand\xxx[2]{(#1)(#2)}|
884 \def\CheckCommand{\@star@or@long\check@command}
886 % |\CheckCommand| is only available in the preamble part of the
889 \@onlypreamble\CheckCommand
892 % \begin{macro}{\check@command}
894 \def\check@command#1#2#{\@check@c#1{#2}}
895 \@onlypreamble\check@command
900 % \begin{macro}{\@check@c}
901 % \changes{v1.2i}{1995/04/25}{Make \cs{long} for latex/1346}
902 % |\CheckCommand| itself just grabs all the arguments we need,
903 % without actually looking for |[| optional argument forms. Now
904 % define |\reserved@a|. If |\\reserved@a| is then defined, compare it
905 % with the ``|\#1|' otherwise compare |\reserved@a| with |#1|.
907 \long\def\@check@c#1#2#3{%
908 \expandafter\let\csname\string\reserved@a\endcsname\relax
909 \renew@command\reserved@a#2{#3}%
910 \@ifundefined{\string\reserved@a}%
911 {\@check@eq#1\reserved@a}%
912 {\expandafter\@check@eq
913 \csname\string#1\expandafter\endcsname
914 \csname\string\reserved@a\endcsname}}
915 \@onlypreamble\@check@c
919 % \begin{macro}{\@check@eq}
920 % Complain if |#1| and |#2| are not |\ifx| equal.
924 \@latex@warning@no@line
925 {Command \noexpand#1 has
926 changed.\MessageBreak
927 Check if current package is valid}%
929 \@onlypreamble\@check@eq
933 % \begin{macro}{\@gobble}
934 % \begin{macro}{\@gobbletwo}
935 % \begin{macro}{\@gobblefour}
936 % \changes{v1.2n}{1995/05/26}{(CAR) Added \cs{long}s}
937 % The |\@gobble| macro is used to get rid of its argument.
939 \long\def \@gobble #1{}
940 \long\def \@gobbletwo #1#2{}
941 \long\def \@gobblefour #1#2#3#4{}
947 % \begin{macro}{\@firstofone}
948 % \begin{macro}{\@firstoftwo}
949 % \begin{macro}{\@secondoftwo}
950 % Some argument-grabbers.
952 \long\def\@firstofone#1{#1}
953 \long\def\@firstoftwo#1#2{#1}
954 \long\def\@secondoftwo#1#2{#2}
956 % \begin{macro}{\@iden}
957 % |\@iden| is another name for |\@firstofone| for
958 % compatibility reasons.
960 \let\@iden\@firstofone
967 % \begin{macro}{\@thirdofthree}
968 % Another grabber now used in the encoding specific
970 % \changes{v1.2z3}{1998/03/20}{Macro added}
972 \long\def\@thirdofthree#1#2#3{#3}
977 % \begin{macro}{\@expandtwoargs}
978 % A macro to totally expand two arguments to another macro
980 \def\@expandtwoargs#1#2#3{%
981 \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a}
985 % \begin{macro}{\@backslashchar}
986 % A category code 12 backslash.
988 \edef\@backslashchar{\expandafter\@gobble\string\\}
992 % \changes{v1.0n}{1994/05/10}{Added \cs{DeclareProtectedCommand}}
993 % \changes{v1.0p}{1994/05/12}{Fixed a bug with \cs{relax } which was
994 % using \cs{@gobble} before defining it.}
995 % \changes{v1.0q}{1994/05/13}{Renamed \cs{DeclareProtectedCommand} to
996 % \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}.
997 % Moved to after the definition of \cs{@gobble}.}
998 % \changes{v1.0r}{1994/05/13}{Added logging message to
999 % \cs{DeclareProtectedCommand}.}
1001 % \subsection{Robust commands and protect}
1003 % \changes{v1.1b}{1994/05/17}{Added the discussion of protected
1004 % commands, defined the values that \cs{protect} should have.}
1005 % \changes{v1.1c}{1994/05/18}{Redid the discussion and definitions, in
1006 % line with the proposed new setting of \cs{protect} in the output
1009 % Fragile and robust commands are one of the thornier issues in
1010 % \LaTeX's commands. Whilst typesetting documents, \LaTeX{} makes use
1011 % of many of \TeX's features, such as arithmetic, defining macros, and
1012 % setting variables. However, there are (at least) three different
1013 % occasions when these commands are not safe. These are called
1014 % `moving arguments' by \LaTeX, and consist of:
1016 % \item writing information to a file, such as indexes or tables of
1018 % \item writing information to the screen.
1019 % \item inside an |\edef|, |\message|, |\mark|, or other command which
1020 % evaluates its argument fully.
1022 % The method \LaTeX{} uses for making fragile commands robust is to
1023 % precede them with |\protect|. This can have one of five possible
1026 % \item |\relax|, for normal typesetting. So |\protect\foo| will
1028 % \item |\string|, for writing to the screen. So |\protect\foo| will
1030 % \item |\noexpand|, for writing to a file. So |\protect\foo| will
1031 % write |\foo| followed by a space.
1032 % \item |\@unexpandable@protect|, for writing a moving argument to a
1033 % file. So |\protect\foo| will write |\protect\foo| followed by a
1034 % space. This value is also used inside |\edef|s, |\mark|s and
1035 % other commands which evaluate their arguments fully.
1036 % \item |\@unexpandable@noexpand|, for performing a deferred write
1037 % inside an |\edef|. So |\protect\foo| will write |\foo| followed
1038 % by a space. If you want |\protect\foo| to be written, you should
1039 % use |\@unexpandable@protect|. (Removed as never used).
1042 % \changes{1.1b}{1994/05/17}
1043 % {(ASAJ) Added the \cs{@protect@...} commands.}
1044 % \changes{1.1c}{1994/05/18}
1045 % {(ASAJ) Renamed the commands, and removed
1046 % one which is no longer needed.}
1048 % \begin{macro}{\@unexpandable@protect}
1049 % \begin{macro}{\@unexpandable@noexpand}
1050 % \changes{1.2w}{1995/12/05}{Removed as never used. internal/1733}
1051 % These commands are used for setting |\protect| inside |\edef|s.
1053 \def\@unexpandable@protect{\noexpand\protect\noexpand}
1054 %\def\@unexpandable@noexpand{\noexpand\noexpand\noexpand}
1059 % \changes{v1.2e}{1994/11/04}{Rewrote protected short commands
1060 % using \cs{x@protect}. ASAJ.}
1062 % \begin{macro}{\DeclareRobustCommand}
1063 % \begin{macro}{\declare@robustcommand}
1064 % This is a package-writers command, which has the same syntax as
1065 % |\newcommand|, but which declares a protected command. It does
1067 % |\DeclareRobustCommand\foo|\\
1068 % define |\foo| to be
1069 % |\protect\foo<space>|,\\
1070 % and then use |\newcommand\foo<space>|.\\
1071 % Since the internal command is |\foo<space>|, when it is written
1072 % to an auxiliary file, it will appear as |\foo|.
1075 % bit cleverer if we're defining a short command, such as |\_|, in
1076 % order to make sure that the auxiliary file does not include a
1077 % space after the command, since |\_ a| and |\_a| aren't the same.
1078 % In this case we define |\_| to be:
1080 % \x@protect\_\protect\_<space>
1084 % \ifx\protect\@typeset@protect\else
1089 % Then if |\protect| is |\@typeset@protect| (normally |\relax|)
1090 % then we just perform |\_<space>|, and otherwise
1091 % |\@x@protect@| gobbles everything up and expands to
1094 % \emph{Note}: setting |\protect| to any value other than |\relax|
1095 % whilst in `typesetting' mode will cause commands to go into an
1096 % infinite loop! In particular, setting |\relax| to |\@empty| will
1097 % cause |\_| to loop forever. It will also break lots of other
1098 % things, such as protected |\ifmmode|s inside |\halign|s. If you
1099 % really really have to do such a thing, then please set
1100 % |\@typeset@protect| to be |\@empty| as well. (This is what the
1101 % code for |\patterns| does, for example.)
1103 % More fun with |\expandafter| and |\csname|.
1105 \def\DeclareRobustCommand{\@star@or@long\declare@robustcommand}
1109 \def\declare@robustcommand#1{%
1110 \ifx#1\@undefined\else\ifx#1\relax\else
1111 \@latex@info{Redefining \string#1}%
1113 \edef\reserved@a{\string#1}%
1114 \def\reserved@b{#1}%
1115 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1117 \ifx\reserved@a\reserved@b
1122 \expandafter\noexpand\csname
1123 \expandafter\@gobble\string#1 \endcsname
1125 \let\@ifdefinable\@rc@ifdefinable
1126 \expandafter\new@command\csname
1127 \expandafter\@gobble\string#1 \endcsname
1134 % \begin{macro}{\@x@protect}
1135 % \begin{macro}{\x@protect}
1139 \ifx\protect\@typeset@protect\else
1143 \def\@x@protect#1\fi#2#3{%
1150 % \begin{macro}{\@typeset@protect}
1153 \let\@typeset@protect\relax
1157 % \changes{v1.2e}{1994/11/04}{Added commands for setting and restoring
1158 % \cs{protect}. ASAJ.}
1160 % \begin{macro}{\set@display@protect}
1161 % \begin{macro}{\set@typeset@protect}
1162 % These macros set |\protect| appropriately for typesetting or
1164 % \changes{v1.2o}{1995/07/03}{Use \cs{@typeset@protect} for init}
1166 \def\set@display@protect{\let\protect\string}
1167 \def\set@typeset@protect{\let\protect\@typeset@protect}
1172 % \begin{macro}{\protected@edef}
1173 % \begin{macro}{\protected@xdef}
1174 % \begin{macro}{\unrestored@protected@xdef}
1175 % \begin{macro}{\restore@protect}
1176 % The commands |\protected@edef| and |\protected@xdef| perform
1177 % `safe' |\edef|s and |\xdef|s, saving and restoring |\protect|
1178 % appropriately. For cases where restoring |\protect| doesn't
1179 % matter, there's an `unsafe' |\unrestored@protected@xdef|, useful
1180 % if you know what you're doing!
1182 \def\protected@edef{%
1183 \let\@@protect\protect
1184 \let\protect\@unexpandable@protect
1185 \afterassignment\restore@protect
1188 \def\protected@xdef{%
1189 \let\@@protect\protect
1190 \let\protect\@unexpandable@protect
1191 \afterassignment\restore@protect
1194 \def\unrestored@protected@xdef{%
1195 \let\protect\@unexpandable@protect
1198 \def\restore@protect{\let\protect\@@protect}
1206 % \begin{macro}{\protect}
1207 % The normal meaning of |\protect|
1208 % \changes{v1.2j}{1995/04/29}{Init \cs{protect} here}
1210 \set@typeset@protect
1214 % \begin{macro}{\MakeRobust}
1215 % \changes{v1.4a}{2015/01/08}{Added macro}
1217 % The macro firstly checks if the controls sequence in question exists
1221 %<latexrelease>\IncludeInRelease{2015/01/01}{\MakeRobust}{\MakeRobust}%
1222 %<*2ekernel|latexrelease>
1224 \@ifundefined{\expandafter\@gobble\string#1}{%
1225 \@latex@error{The control sequence `\string#1' is undefined!%
1226 \MessageBreak There is nothing here to make robust}%
1230 % Then we check if the macro is already robust. We do this by testing
1231 % if the internal name for a robust macro is defined, namely
1232 % \verb*=\foo =. If it is already defined do nothing, otherwise set
1233 % \verb*=\foo = equal to \verb*=\foo= and redefine \verb*=\foo= so
1234 % that it acts like a macro defined with \verb=\DeclareRobustCommand=.
1237 \@ifundefined{\expandafter\@gobble\string#1\space}%
1239 \expandafter\let\csname
1240 \expandafter\@gobble\string#1\space\endcsname=#1%
1241 \edef\reserved@a{\string#1}%
1242 \def\reserved@b{#1}%
1243 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1245 \ifx\reserved@a\reserved@b
1246 \noexpand\x@protect\noexpand#1%
1248 \noexpand\protect\expandafter\noexpand
1249 \csname\expandafter\@gobble\string#1\space\endcsname}%
1251 {\@latex@info{The control sequence `\string#1' is already robust}}%
1254 %</2ekernel|latexrelease>
1255 %<latexrelease>\EndIncludeInRelease
1256 %<latexrelease>\IncludeInRelease{0000/00/00}{\MakeRobust}{\MakeRobust}%
1257 %<latexrelease>\let\MakeRobust\@undefined
1258 %<latexrelease>\EndIncludeInRelease
1263 % \subsection{Internal defining commands}
1265 % These commands are used internally to define other \LaTeX{}
1267 % \begin{macro}{\@ifundefined}
1268 % \changes{LaTeX2e}{1993/11/23}{Redefined to remove a trailing \cs{fi}}
1269 % Check if first arg is undefined or \cs{relax} and execute second or
1270 % third arg depending,
1272 \def\@ifundefined#1{%
1273 \expandafter\ifx\csname#1\endcsname\relax
1274 \expandafter\@firstoftwo
1276 \expandafter\@secondoftwo
1282 % \begin{macro}{\@qend}
1283 % \begin{macro}{\@qrelax}
1284 % The following define |\@qend| and |\@qrelax| to be the strings
1285 % `|end|' and `|relax|' with the characters |\catcode|d 12.
1287 \edef\@qend{\expandafter\@cdr\string\end\@nil}
1288 \edef\@qrelax{\expandafter\@cdr\string\relax\@nil}
1294 % \begin{macro}{\@ifnextchar}
1295 % \changes{LaTeX209}{1992/08/24}
1296 % {(Rms) \cs{@ifnextchar} didn't work if its
1297 % first argument was an equal sign.}
1298 % \changes{v1.2q}{1995/10/02}
1299 % {Use \cs{@let@token} }
1300 % \changes{v1.3a}{1999/01/07}
1302 % \changes{v1.3b}{1999/01/07}
1303 % {extra \cs{long}. latex/2902}
1304 % \changes{v1.3e}{1999/03/01}
1305 % {remove extra \cs{long}. internal/2967}
1306 % |\@ifnextchar| peeks at the following character and compares it
1307 % with its first argument. If both are the same it executes its
1308 % second argument, otherwise its third.
1310 \long\def\@ifnextchar#1#2#3{%
1312 \def\reserved@a{#2}%
1313 \def\reserved@b{#3}%
1314 \futurelet\@let@token\@ifnch}
1318 % \begin{macro}{\kernel@ifnextchar}
1319 % \changes{v1.3g}{2004/01/23}{Added macro (pr/3501)}
1320 % This macro is the kernel version of |\@ifnextchar| which is used
1321 % in a couple of places to prevent the AMS variant from being used
1322 % since in some places this produced chaos (for example
1323 % if an \texttt{fd} file
1324 % is loaded in a random place then the optional argument to
1325 % |\ProvidesFile| could get printed there instead of being written
1326 % only in the log file. This happened
1327 % when there was a space or a newline between the mandatory and
1328 % optional arguments! It should really be fixed in the
1329 % \texttt{amsmath} package one day, but\ldots
1331 % Note that there may be other places in the kernel where this version
1332 % should be used rather than the original, but variable, version.
1335 \let\kernel@ifnextchar\@ifnextchar
1340 % \begin{macro}{\@ifnch}
1341 % |\@ifnch| is a tricky macro to skip any space tokens that may
1342 % appear before the character in question. If it encounters a space
1343 % token, it calls \@xifnch.
1344 % \changes{v1.2q}{1995/10/02}
1345 % {Use \cs{@let@token} for internal/924, save \cs{reserved@e}}
1348 \ifx\@let@token\@sptoken
1349 \let\reserved@c\@xifnch
1351 \ifx\@let@token\reserved@d
1352 \let\reserved@c\reserved@a
1354 \let\reserved@c\reserved@b
1361 % \begin{macro}{\@sptoken}
1362 % The following code makes |\@sptoken| a space token. It is
1363 % important here that the control sequence |\:| consists of
1364 % a non-letter only, so that the following whitespace is
1365 % significant. Together with the fact that the equal sign
1366 % in a |\let| may be followed by only one optional space
1367 % the desired effect is achieved.
1368 % NOTE: the following hacking must precede the definition of |\:|
1369 % as math medium space.
1371 \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token
1375 % \begin{macro}{\@xifnch}
1376 % In the following definition of |\@xifnch|, |\:| is again used
1377 % to get a space token as delimiter into the definition.
1379 \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}
1383 % \changes{v1.0n}{1994/05/10}{Added \cs{makeatletter} and
1384 % \cs{makeatother} ASAJ.}
1386 % \begin{macro}{\makeatletter}
1387 % \begin{macro}{\makeatother}
1388 % Make internal control sequences accessible or inaccessible.
1390 \def\makeatletter{\catcode`\@11\relax}
1391 \def\makeatother{\catcode`\@12\relax}
1397 % \begin{macro}{\@ifstar}
1398 % \changes{v1.2u}{1995/10/16}{(DPC) New implementation, for /1910}
1399 % The new implementation below avoids passing the \meta{true code}
1400 % Through one more |\def| than the \meta{false code}, which previously
1401 % meant that |#| had to be written as |####| in one argument, but |##|
1402 % in the other. The |*| is gobbled by |\@firstoftwo|.
1404 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
1408 % \begin{macro}{\@dblarg}
1409 % \begin{macro}{\@xdblarg}
1410 % \changes{v1.1g}{2004/01/23}{Use kernel version of
1411 % \cs{@ifnextchar} (pr/3501)}
1413 \long\def\@dblarg#1{\kernel@ifnextchar[{#1}{\@xdblarg{#1}}}
1414 \long\def\@xdblarg#1#2{#1[{#2}]{#2}}
1419 % \begin{macro}{\@sanitize}
1420 % The command |\@sanitize| changes the catcode of all special characters
1421 % except for braces to `other'. It can be used for commands like
1422 % |\index| that want to write their arguments verbatim. Needless to
1423 % say, this command should only be executed within a group, or chaos
1427 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
1428 \@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~}
1432 % \begin{macro}{\@onelevel@sanitize}
1433 % \changes{v1.2c}{1994/10/30}{Macro added}
1435 % This makes the whole ``meaning'' of |#1| (its one-level
1436 % expansion) into catcode 12 tokens: it could be used in
1437 % |\DeclareRobustCommand|.
1439 % If it is to be used on default float specifiers, this should be
1440 % done when they are defined.
1442 \def \@onelevel@sanitize #1{%
1443 \edef #1{\expandafter\strip@prefix