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}
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}
148 % \changes{1.2x}{1995/12/13}{Documentation changed.}
149 % The following comment was added when these commands were first set
151 % the |\-| command is redefined to allow it to work in the |\ttfamily|
152 % type style, where automatic hyphenation is suppressed by setting
153 % |\hyphenchar| to~$-1$. The original primitive \TeX{} definition is
154 % saved as |\@@hyph| just in case anyone needs it.
156 % There is a need for a robust command for a discretionary hyphen
157 % since its exact representation depends on the glyphs available in
158 % the current font. For example, with suitable fonts and the
159 % \texttt{T1} font encoding it is possible to use hanging hyphens.
161 % A suitable robust definition that allows for many possible types of
162 % font and encoding may be as follows:
164 % \DeclareRobustCommand {\-}{%
166 % \char \ifnum\hyphenchar\font<\z@
175 % The redefinition (via |\let|) of |\-| within tabbing also makes the
176 % use of a robust command advisable since then any redefinition
177 % of |\-| via |\DeclareRobustCommand| will not cause a conflict.
179 % Therefore, macro writers should be hereby warned that
180 % these internals will probably change! It is likely that a future
181 % release of \LaTeX{} will make |\-| effectively an encoding specific
185 \let\@@hyph=\- % Save original primitive definition
186 \def\-{\discretionary{-}{}{}}
191 % \begin{macro}{\@dischyph}
192 % \changes{v1.0g}{1994/04/12}
193 % {Define \cs{@dischyph}, was previously in ltboxes.dtx}
199 % \begin{macro}{\@@italiccorr}
200 % Save the original italic correction.
201 % \changes{v1.0a}{1994/03/07}{Macro added}
207 % \begin{macro}{\@height}
208 % \begin{macro}{\@depth}
209 % \begin{macro}{\@width}
210 % \begin{macro}{\@minus}
211 % \changes{LaTeX2e}{1993/11/22}{Macro added}
212 % \begin{macro}{\@plus}
213 % \changes{LaTeX2e}{1993/11/22}{Macro added}
215 % The following definitions save token space. E.g., using
216 % |\@height| instead of height saves 5 tokens at the cost in time
217 % of one macro expansion.
219 \def\@height{height} \def\@depth{depth} \def\@width{width}
223 % \begin{macro}{\hb@xt@}
224 % \changes{v1.2k}{1995/05/07}{Macro added}
225 % The next one is another 100 tokens worth.
227 \def\hb@xt@{\hbox to}
240 % \subsection{Command definitions}
242 % This section defines the following commands:
245 % {\@namedef}\marg{NAME}\\ Expands to |\def\|\marg{NAME},
246 % except name can contain any characters.
249 % {\@nameuse}\marg{NAME}\\
250 % Expands to |\|\marg{NAME}.
253 % {\@ifnextchar} X\marg{YES}\marg{NO}\\
254 % Expands to \meta{YES} if next character is an `X',
255 % and to \meta{NO} otherwise.
256 % (Uses |\reserved@a|--|\reserved@c|.)
257 % NOTE: GOBBLES ANY SPACE FOLLOWING IT.
260 % {\@ifstar}\marg{YES}\marg{NO}\\
261 % Gobbles following spaces and then tests if next the
262 % character is a '*'. If it is, then it gobbles the
263 % `*' and expands to \meta{YES}, otherwise it expands to \meta{NO}.
266 % {\@dblarg}\marg{CMD}\marg{ARG}\\
267 % Expands to |\|\marg{CMD}\oarg{ARG}\marg{ARG}. Use
268 % |\@dblarg\CS| when |\CS| takes arguments |[ARG1]{ARG2}|,
269 % where default is| ARG1| = |ARG2|.
272 % {\@ifundefined}\marg{NAME}\marg{YES}\marg{NO}\\
273 % : If \cs{NAME} is undefined then it executes \meta{YES},
274 % otherwise it executes \meta{NO}. More precisely,
275 % true if \cs{NAME} either undefined or = |\relax|.
278 % {\@ifdefinable}|\NAME|\marg{YES}
279 % Executes \meta{YES} if the user is allowed to define |\NAME|,
280 % otherwise it gives an error. The user can define |\NAME|
281 % if |\@ifundefined{NAME}| is true, '|NAME|' $\neq$ '|relax|'
282 % and the first three letters of '|NAME|' are not
283 % '|end|', and if |\endNAME| is not defined.
286 % \newcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
287 % User command to define |\FOO| to be a macro with
288 % i arguments (i = 0 if missing) having the definition
289 % \meta{TEXT}. Produces an error if |\FOO| already
292 % Normally the command is defined to be |\long| (ie it may
293 % take multiple paragraphs in its argument). In the
294 % star-form, the command is not defined as |\long| and a
295 % blank line in any argument to the command would generate
299 % \renewcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\
300 % Same as |\newcommand|, except it checks if |\FOO| already defined.
303 % \newenvironment|*|\marg{FOO}\oarg{i}\marg{DEF1}\marg{DEF2}\\
305 % |\newcommand{\FOO}[i]{DEF1}| |\def{\endFOO}{DEF2}|\\
306 % (or the appropriate star forms).
309 % \renewenvironment\\ Obvious companion to |\newenvironment|.
312 % \@cons : See description of |\output| routine.
314 % \DescribeMacro{\@car}
315 % |\@car T1 T2 ... Tn\@nil| == |T1| (unexpanded)
317 % \DescribeMacro{\@cdr}
318 % |\@cdr T1 T2 ... Tn\@ni|l == |T2 ... Tn| (unexpanded)
321 % \typeout\marg{message}\\ Produces a warning message on the terminal.
324 % \typein\marg{message}\\
325 % Types message, asks the user to type in a command, then
329 % \typein\oarg{\cs{CS}}\marg{MSG}\\
330 % Same as above, except defines |\CS| to be the input
331 % instead of executing it.
333 % \changes{LaTeX209}{1992/03/18}
334 % {(RMS) changed input channel from 0 to \cs{@inputcheck} to avoid
335 % conflicts with other channels allocated by \cs{newread}}
337 % \begin{macro}{\typein}
339 % \changes{v1.2k}{1995/05/08}{Use \cs{@firstofone}}
340 % \changes{v1.2l}{1995/05/08}{Remove unnecessary braces}
341 % \changes{v1.2l}{1995/05/08}{Replace \cs{def} by \cs{let}}
342 % \changes{v1.2m}{1995/05/24}{(DPC) New implementation}
343 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
347 \@testopt\@xtypein\@typein}
350 % \changes{v1.2r}{1995/10/03}
351 % {Add missing \cs{@typein} for /1710 (from patch file)}
352 % \changes{v1.4a}{2015/01/03}{use modified definition in luatex}
354 \ifx\directlua\@undefined
358 \def\@xtypein[#1]#2{%
360 \advance\endlinechar\@M
361 \read\@inputcheck to#1%
362 \advance\endlinechar-\@M
371 \def\@xtypein[#1]#2{%
373 \begingroup \endlinechar\m@ne
374 \read\@inputcheck to#1%
375 \expandafter\endgroup
376 \expandafter\def\expandafter#1\expandafter{#1}%
385 % \begin{macro}{\@namedef}
387 \def\@namedef#1{\expandafter\def\csname #1\endcsname}
391 % \begin{macro}{\@nameuse}
393 \def\@nameuse#1{\csname #1\endcsname}
397 % \begin{macro}{\@cons}
399 \def\@cons#1#2{\begingroup\let\@elt\relax\xdef#1{#1\@elt #2}\endgroup}
403 % \begin{macro}{\@car}
404 % \begin{macro}{\@cdr}
406 \def\@car#1#2\@nil{#1}
407 \def\@cdr#1#2\@nil{#2}
412 % \begin{macro}{\@carcube}
413 % |\@carcube T1 ... Tn\@nil| = |T1| |T2| |T3| , $n > 3$
415 \def\@carcube#1#2#3#4\@nil{#1#2#3}
421 % \begin{macro}{\@onlypreamble}
422 % \begin{macro}{\@preamblecmds}
423 % This macro adds its argument to the list of commands stored in
424 % |\@preamblecmds| to be
425 % disabled after |\begin{document}|. These commands are redefined
426 % to generate |\@notprerr| at this point.
429 \def\@onlypreamble#1{%
430 \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
431 \@preamblecmds\do#1}}
432 \@onlypreamble\@onlypreamble
433 \@onlypreamble\@preamblecmds
439 % \begin{macro}{\@star@or@long}
440 % \changes{v1.2a}{1994/10/18}{macro added}
441 % Look ahead for a |*|. If present reset |\l@ngrel@x| so that
442 % the next definition, |#1|, will be non-long.
444 \def\@star@or@long#1{%
446 {\let\l@ngrel@x\relax#1}%
447 {\let\l@ngrel@x\long#1}}
452 % \begin{macro}{\l@ngrel@x}
453 % This is either |\relax| or |\long| depending on whether the |*|-form
454 % of a definition command is being executed.
460 % \begin{macro}{\newcommand}
461 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
462 % User level |\newcommand|.%
464 \def\newcommand{\@star@or@long\new@command}
467 % \begin{macro}{\new@command}
468 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
471 \@testopt{\@newcommand#1}0}
477 % \begin{macro}{\@newcommand}
478 % \changes{LaTeX2e}{1993/11/23}{Macro added}
479 % \begin{macro}{\@argdef}
480 % \changes{LaTeX2e}{1993/11/23}{Macro added}
481 % \begin{macro}{\@xargdef}
482 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
483 % \changes{v1.1g}{2004/01/23}{Use kernel version of
484 % \cs{@ifnextchar} (pr/3501)}
485 % Handling arguments for |\newcommand|.
487 \def\@newcommand#1[#2]{%
488 \kernel@ifnextchar [{\@xargdef#1[#2]}%
491 % Define |#1| if it is definable.
493 % Both here and in |\@xargdef| the replacement text is absorbed as
494 % an argument because if we are not allowed to make the definition
495 % we have to get rid of it completely.
497 \long\def\@argdef#1[#2]#3{%
498 \@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}}
501 % \changes{v1.2q}{1995/10/02}
502 % {New implementation, using \cs{@test@opt}}
503 % Handle the second optional argument.
505 \long\def\@xargdef#1[#2][#3]#4{%
508 % Define the actual command to be:\\
509 % |\def\foo{\@protected@testopt\foo\\foo{default}}|\\
510 % where |\\foo| is a csname generated from applying |\csname| and
511 % |\string| to |\foo|, ie the actual name contains a backslash and
512 % therefore can't clash easily with existing command names.
513 % ``Default'' is the contents of the second optional argument of
516 % \changes{v1.2z2}{1998/03/04}
517 % {Unnecessary \cs{expandafter} removed: pr/2758}
519 \expandafter\def\expandafter#1\expandafter{%
524 \csname\string#1\endcsname
527 % Now we define the internal macro ie |\\foo| which is supposed to
528 % pick up all arguments (optional and mandatory).
530 \expandafter\@yargdef
531 \csname\string#1\endcsname
540 % \begin{macro}{\@testopt}
541 % \changes{v1.2q}{1995/10/02}
543 % \changes{v1.3a}{1999/01/07}
544 % {made long and brace optional arg. latex/2896}
545 % This macro encapsulates the most common call to |\@ifnextchar|, saving
546 % several tokens each time it is used in the definition of a command
547 % with an optional argument.
548 % |#1| The code to execute in the case that there is a |[| need not be
549 % a single token but can be any sequence of commands that `expects' to
550 % be followed by |[|. If this command were only used in |\newcommand|
551 % definitions then |#1| would be a single token and the braces could
552 % be omitted from |{#1}| in the definition below, saving a bit of
554 % \changes{v1.1g}{2004/01/23}{Use kernel version of
555 % \cs{@ifnextchar} (pr/3501)}
557 \long\def\@testopt#1#2{%
558 \kernel@ifnextchar[{#1}{#1[{#2}]}}
562 % \begin{macro}{\@protected@testopt}
563 % \changes{v1.2q}{1995/10/02}
565 % Robust version of |\@testopt|. The extra argument (|#1|) must be a
566 % single token. If protection is needed the call expands to |\protect|
567 % applied to this token, and the 2nd and 3rd arguments are
568 % discarded (by |\@x@protect|). Otherwise |\@testopt| is called on
569 % the 2nd and 3rd arguments.
571 % This method of making commands robust avoids the need for using up
572 % two csnames per command, the price is the extra expansion time
573 % for the |\ifx| test.
575 \def\@protected@testopt#1{%%
576 \ifx\protect\@typeset@protect
577 \expandafter\@testopt
584 % \begin{macro}{\@yargdef}
585 % \begin{macro}{\@yargd@f}
586 % \changes{v1.3f}{1999/04/29}{New macro added}
588 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
589 % \changes{LaTeX2e}{1993/11/23}{Avoid \cs{@?@?} token}
590 % \changes{v1.0b}{1994/03/12}{Name changed from \cs{XXX@argdef}}
591 % \changes{v1.3c}{1999/01/18}{New implementation DPC /2942}
592 % \changes{v1.3d}{1999/02/09}{catch bad argument forms by re-inserting \#3}
593 % \changes{v1.3f}{1999/04/29}{Full expansion and conversion needed
594 % for digit in new version, see pr/3013}
596 % These generate a primitive argument specification, from a
597 % \LaTeX\ |[|\meta{digit}|]| form; in fact \meta{digit} can be
598 % anything such that |\number|~\meta{digit} is single digit.
600 % Reorganised slightly so that |\renewcommand{\reserved@a}[1]{foo}|
601 % works. I am not sure this is worth it, as a following
602 % |\newcommand| would over-write the definition of |\reserved@a|.
604 % Recall that \LaTeX2.09 goes into an infinite loop with\\
605 % |\renewcommand[1]{\@tempa}{foo}|\\
606 % (DPC 6 October 93).
608 % Reorganised again (DPC 1999). Rather than make a loop to
609 % construct the argument spec by counting, just extract the
610 % required argument spec by using a delimited argument (delimited
611 % by the digit). This is faster and uses less tokens. The coding
612 % is slightly odd to preserve the old interface (using |#2| =
613 % |\tw@| as the flag to surround the first argument with |[]|. But
614 % the new method did not allow for the number of arguments |#3| not
615 % being given as an explicit digit; hence (further expansion of
616 % this argument and use of) |\number| was added later in 1999.
618 % It is not clear why these are still |\long|.
621 \long \def \@yargdef #1#2#3{%
623 \def\reserved@b##11{[####1]}%
625 \let\reserved@b\@gobble
628 \@yargd@f \expandafter{\number #3}#1%
633 \long \def \@yargd@f#1#2{%
634 \def \reserved@a ##1#1##2##{%
635 \expandafter\def\expandafter#2\reserved@b ##1#1%
637 \l@ngrel@x \reserved@a 0##1##2##3##4##5##6##7##8##9###1%
644 % \begin{macro}{\@reargdef}
645 % \changes{LaTeX2e}{1993/12/20}
646 % {Kept old version of \cs{@reargdef}, for array.sty}
647 % \changes{v1.0b}{1994/03/12}{New defn, in terms of \cs{@yargdef}}
648 % \changes{v1.2y}{1996/07/26}{third arg picked up by \cs{@yargdef}}
650 \long\def\@reargdef#1[#2]{%
655 % \begin{macro}{\renewcommand}
656 % Check the command name is already used. If not give an error
657 % message. Then temporarily
658 % disable |\@ifdefinable| then call |\newcommand|. (Previous
659 % version |\let#1=\relax| but this does not work too well if |#1|
660 % is |\@temp|\emph{a--e}.)
661 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
662 % \changes{v1.1f}{1994/05/2}{Removed surplus \cs{space} in error}
664 \def\renewcommand{\@star@or@long\renew@command}
667 % \begin{macro}{\renew@command}
668 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
669 % \changes{v1.2y}{1996/07/26}{use \cs{noexpand} instead of \cs{string}}
670 % \changes{v1.2z1}{1997/10/21}{Use \cs{begingroup}/\cs{endgroup} rather
671 % than braces for grouping, to avoid generating empty math atom.}
673 \def\renew@command#1{%
674 \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
675 \expandafter\@ifundefined\@gtempa
676 {\@latex@error{\noexpand#1undefined}\@ehc}%
678 \let\@ifdefinable\@rc@ifdefinable
684 % \changes{v1.0n}{1994/05/10}{Removed braces around \cs{@ifundefined}
686 % \changes{v1.0s}{1994/05/13}{Coded more efficiently, thanks to FMi.}
688 % \begin{macro}{\@ifdefinable}
689 % \begin{macro}{\@@ifdefinable}
690 % \begin{macro}{\@rc@ifdefinable}
691 % Test is user is allowed to define a command.
693 \long\def\@ifdefinable #1#2{%
694 \edef\reserved@a{\expandafter\@gobble\string #1}%
695 \@ifundefined\reserved@a
696 {\edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
697 \ifx \reserved@b\@qend \@notdefinable\else
698 \ifx \reserved@a\@qrelax \@notdefinable\else
704 % Saved definition of |\@ifdefinable|.
706 \let\@@ifdefinable\@ifdefinable
708 % Version of |\@ifdefinable| for use with |\renewcommand|. Does
709 % not do the check this time, but restores the normal definition.
711 \long\def\@rc@ifdefinable#1#2{%
712 \let\@ifdefinable\@@ifdefinable
719 % \begin{macro}{\newenvironment}
720 % Define a new user environment.
721 % |#1| is the environment name. |#2#| Grabs all the tokens up to
722 % the first |{|. These will be any optional arguments. They are not
723 % parsed at this point, but are just passed to |\@newenv| which
724 % will eventually call |\newcommand|. Any optional arguments will
725 % then be parsed by |\newcommand| as it defines the command that
726 % executes the `begin code' of the environment.
728 % This |#2#| trick removed with version 1.2i as it fails if a |{|
729 % occurs in the optional argument. Now use |\@ifnextchar| directly.
731 \def\newenvironment{\@star@or@long\new@environment}
734 % \begin{macro}{\new@environment}
735 % \changes{v1.2i}{1995/04/25}{Parse arguments slowly but safely /1507}
736 % \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911}
738 \def\new@environment#1{%
739 \@testopt{\@newenva#1}0}
742 % \begin{macro}{\@newenva}
743 % \changes{v1.1g}{2004/01/23}{Use kernel version of
744 % \cs{@ifnextchar} (pr/3501)}
746 \def\@newenva#1[#2]{%
747 \kernel@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}}
751 % \begin{macro}{\@newenvb}
752 % \changes{v1.3a}{1999/01/07}
753 % {made long and brace optional arg. latex/2896}
755 \def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][{#3}]}}
763 % \begin{macro}{\renewenvironment}
764 % Redefine an environment.
765 % For |\renewenvironment| disable |\@ifdefinable| and then call
766 % |\newenvironment|. It is OK to |\let| the argument to |\relax|
767 % here as there should not be a |@temp|\ldots\ environment.
768 % \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended}
769 % \changes{v1.1f}{1994/05/2}{Removed surplus \cs{space} in error}
771 \def\renewenvironment{\@star@or@long\renew@environment}
774 % \begin{macro}{\renew@environment}
775 % \changes{v1.2a}{1994/10/18}{reset end command}
776 % \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg}
778 \def\renew@environment#1{%
780 {\@latex@error{Environment #1 undefined}\@ehc
782 \expandafter\let\csname#1\endcsname\relax
783 \expandafter\let\csname end#1\endcsname\relax
784 \new@environment{#1}}
790 % \begin{macro}{\@newenv}
791 % \changes{LaTeX2e}{1993/11/23}{Macro interface changed}
792 % \changes{v1.2h}{1994/11/24}{Added test for \cs{endgraf}}
793 % The internal version of |\newenvironment|.
795 % Call |\newcommand| to define the \meta{begin-code} for the
796 % environment. |\def| is used for the \meta{end-code} as it does
797 % not take arguments. (but may contain |\par|s)
799 % Make sure that an attempt to define a `graf' or `group' environment
802 \long\def\@newenv#1#2#3#4{%
804 {\expandafter\let\csname#1\expandafter\endcsname
805 \csname end#1\endcsname}%
807 \expandafter\new@command
808 \csname #1\endcsname#2{#3}%
809 \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}
813 % \begin{macro}{\newif}
814 % \changes{v1.1l}{1995/05/24}{(DPC) New implementation}
815 % And here's a different sort of allocation:
817 % |\newif\iffoo| creates |\footrue|, |\foofalse| to go with |\iffoo|.
820 \count@\escapechar \escapechar\m@ne
827 % \begin{macro}{\@if}
830 \expandafter\def\csname\expandafter\@gobbletwo\string#1%
831 \expandafter\@gobbletwo\string#2\endcsname
838 % \begin{macro}{\providecommand}
839 % |\providecommand| takes the same arguments as |\newcommand|, but
840 % discards them if |#1| is already defined, Otherwise it just acts like
841 % |\newcommand|. This implementation currently leaves any discarded
842 % definition in |\reserved@a| (and possibly |\\reserved@a|) this
843 % wastes a bit of space, but it will be reclaimed as soon as these
844 % scratch macros are redefined.
846 % \changes{LaTeX2e}{1993/11/22}{Macro added}
848 \def\providecommand{\@star@or@long\provide@command}
851 % \begin{macro}{\provide@command}
852 % \changes{v1.2z}{1997/09/09}{Use \cs{begingroup} to avoid generating
853 % math ords if used in math mode. pr/2573}
855 \def\provide@command#1{%
857 \escapechar\m@ne\xdef\@gtempa{{\string#1}}%
859 \expandafter\@ifundefined\@gtempa
860 {\def\reserved@a{\new@command#1}}%
861 {\def\reserved@a{\renew@command\reserved@a}}%
867 % \begin{macro}{\CheckCommand}
868 % \changes{LaTeX2e}{1993/11/22}{Macro added}
869 % \changes{v1.1e}{1994/05/20}{Changed name from \cs{@checkcommand} to
870 % \cs{CheckCommand}.}
871 % |\CheckCommand| takes the same arguments as |\newcommand|. If
872 % the command already exists, with the same definition, then
873 % nothing happens, otherwise a warning is issued. Useful for
874 % checking the current state befor a macro package starts
875 % redefining things. Currently two macros are considered to have
876 % the same definition if they are the same except for different
877 % default arguments. That is, if the old definition was:
878 % |\newcommand\xxx[2][a]{(#1)(#2)}| then
879 % |\CheckCommand\xxx[2][b]{(#1)(#2)}| would \emph{not} generate a
880 % warning, but, for instance |\CheckCommand\xxx[2]{(#1)(#2)}|
883 \def\CheckCommand{\@star@or@long\check@command}
885 % |\CheckCommand| is only available in the preamble part of the
888 \@onlypreamble\CheckCommand
891 % \begin{macro}{\check@command}
893 \def\check@command#1#2#{\@check@c#1{#2}}
894 \@onlypreamble\check@command
899 % \begin{macro}{\@check@c}
900 % \changes{v1.2i}{1995/04/25}{Make \cs{long} for latex/1346}
901 % |\CheckCommand| itself just grabs all the arguments we need,
902 % without actually looking for |[| optional argument forms. Now
903 % define |\reserved@a|. If |\\reserved@a| is then defined, compare it
904 % with the ``|\#1|' otherwise compare |\reserved@a| with |#1|.
906 \long\def\@check@c#1#2#3{%
907 \expandafter\let\csname\string\reserved@a\endcsname\relax
908 \renew@command\reserved@a#2{#3}%
909 \@ifundefined{\string\reserved@a}%
910 {\@check@eq#1\reserved@a}%
911 {\expandafter\@check@eq
912 \csname\string#1\expandafter\endcsname
913 \csname\string\reserved@a\endcsname}}
914 \@onlypreamble\@check@c
918 % \begin{macro}{\@check@eq}
919 % Complain if |#1| and |#2| are not |\ifx| equal.
923 \@latex@warning@no@line
924 {Command \noexpand#1 has
925 changed.\MessageBreak
926 Check if current package is valid}%
928 \@onlypreamble\@check@eq
932 % \begin{macro}{\@gobble}
933 % \begin{macro}{\@gobbletwo}
934 % \begin{macro}{\@gobblefour}
935 % \changes{v1.2n}{1995/05/26}{(CAR) Added \cs{long}s}
936 % The |\@gobble| macro is used to get rid of its argument.
938 \long\def \@gobble #1{}
939 \long\def \@gobbletwo #1#2{}
940 \long\def \@gobblefour #1#2#3#4{}
946 % \begin{macro}{\@firstofone}
947 % \begin{macro}{\@firstoftwo}
948 % \begin{macro}{\@secondoftwo}
949 % Some argument-grabbers.
951 \long\def\@firstofone#1{#1}
952 \long\def\@firstoftwo#1#2{#1}
953 \long\def\@secondoftwo#1#2{#2}
955 % \begin{macro}{\@iden}
956 % |\@iden| is another name for |\@firstofone| for
957 % compatibility reasons.
959 \let\@iden\@firstofone
966 % \begin{macro}{\@thirdofthree}
967 % Another grabber now used in the encoding specific
969 % \changes{v1.2z3}{1998/03/20}{Macro added}
971 \long\def\@thirdofthree#1#2#3{#3}
976 % \begin{macro}{\@expandtwoargs}
977 % A macro to totally expand two arguments to another macro
979 \def\@expandtwoargs#1#2#3{%
980 \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a}
984 % \begin{macro}{\@backslashchar}
985 % A category code 12 backslash.
987 \edef\@backslashchar{\expandafter\@gobble\string\\}
991 % \changes{v1.0n}{1994/05/10}{Added \cs{DeclareProtectedCommand}}
992 % \changes{v1.0p}{1994/05/12}{Fixed a bug with \cs{relax } which was
993 % using \cs{@gobble} before defining it.}
994 % \changes{v1.0q}{1994/05/13}{Renamed \cs{DeclareProtectedCommand} to
995 % \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}.
996 % Moved to after the definition of \cs{@gobble}.}
997 % \changes{v1.0r}{1994/05/13}{Added logging message to
998 % \cs{DeclareProtectedCommand}.}
1000 % \subsection{Robust commands and protect}
1002 % \changes{v1.1b}{1994/05/17}{Added the discussion of protected
1003 % commands, defined the values that \cs{protect} should have.}
1004 % \changes{v1.1c}{1994/05/18}{Redid the discussion and definitions, in
1005 % line with the proposed new setting of \cs{protect} in the output
1008 % Fragile and robust commands are one of the thornier issues in
1009 % \LaTeX's commands. Whilst typesetting documents, \LaTeX{} makes use
1010 % of many of \TeX's features, such as arithmetic, defining macros, and
1011 % setting variables. However, there are (at least) three different
1012 % occasions when these commands are not safe. These are called
1013 % `moving arguments' by \LaTeX, and consist of:
1015 % \item writing information to a file, such as indexes or tables of
1017 % \item writing information to the screen.
1018 % \item inside an |\edef|, |\message|, |\mark|, or other command which
1019 % evaluates its argument fully.
1021 % The method \LaTeX{} uses for making fragile commands robust is to
1022 % precede them with |\protect|. This can have one of five possible
1025 % \item |\relax|, for normal typesetting. So |\protect\foo| will
1027 % \item |\string|, for writing to the screen. So |\protect\foo| will
1029 % \item |\noexpand|, for writing to a file. So |\protect\foo| will
1030 % write |\foo| followed by a space.
1031 % \item |\@unexpandable@protect|, for writing a moving argument to a
1032 % file. So |\protect\foo| will write |\protect\foo| followed by a
1033 % space. This value is also used inside |\edef|s, |\mark|s and
1034 % other commands which evaluate their arguments fully.
1035 % \item |\@unexpandable@noexpand|, for performing a deferred write
1036 % inside an |\edef|. So |\protect\foo| will write |\foo| followed
1037 % by a space. If you want |\protect\foo| to be written, you should
1038 % use |\@unexpandable@protect|. (Removed as never used).
1041 % \changes{1.1b}{1994/05/17}
1042 % {(ASAJ) Added the \cs{@protect@...} commands.}
1043 % \changes{1.1c}{1994/05/18}
1044 % {(ASAJ) Renamed the commands, and removed
1045 % one which is no longer needed.}
1047 % \begin{macro}{\@unexpandable@protect}
1048 % \begin{macro}{\@unexpandable@noexpand}
1049 % \changes{1.2w}{1995/12/05}{Removed as never used. internal/1733}
1050 % These commands are used for setting |\protect| inside |\edef|s.
1052 \def\@unexpandable@protect{\noexpand\protect\noexpand}
1053 %\def\@unexpandable@noexpand{\noexpand\noexpand\noexpand}
1058 % \changes{v1.2e}{1994/11/04}{Rewrote protected short commands
1059 % using \cs{x@protect}. ASAJ.}
1061 % \begin{macro}{\DeclareRobustCommand}
1062 % \begin{macro}{\declare@robustcommand}
1063 % This is a package-writers command, which has the same syntax as
1064 % |\newcommand|, but which declares a protected command. It does
1066 % |\DeclareRobustCommand\foo|\\
1067 % define |\foo| to be
1068 % |\protect\foo<space>|,\\
1069 % and then use |\newcommand\foo<space>|.\\
1070 % Since the internal command is |\foo<space>|, when it is written
1071 % to an auxiliary file, it will appear as |\foo|.
1074 % bit cleverer if we're defining a short command, such as |\_|, in
1075 % order to make sure that the auxiliary file does not include a
1076 % space after the command, since |\_ a| and |\_a| aren't the same.
1077 % In this case we define |\_| to be:
1079 % \x@protect\_\protect\_<space>
1083 % \ifx\protect\@typeset@protect\else
1088 % Then if |\protect| is |\@typeset@protect| (normally |\relax|)
1089 % then we just perform |\_<space>|, and otherwise
1090 % |\@x@protect@| gobbles everything up and expands to
1093 % \emph{Note}: setting |\protect| to any value other than |\relax|
1094 % whilst in `typesetting' mode will cause commands to go into an
1095 % infinite loop! In particular, setting |\relax| to |\@empty| will
1096 % cause |\_| to loop forever. It will also break lots of other
1097 % things, such as protected |\ifmmode|s inside |\halign|s. If you
1098 % really really have to do such a thing, then please set
1099 % |\@typeset@protect| to be |\@empty| as well. (This is what the
1100 % code for |\patterns| does, for example.)
1102 % More fun with |\expandafter| and |\csname|.
1104 \def\DeclareRobustCommand{\@star@or@long\declare@robustcommand}
1108 \def\declare@robustcommand#1{%
1109 \ifx#1\@undefined\else\ifx#1\relax\else
1110 \@latex@info{Redefining \string#1}%
1112 \edef\reserved@a{\string#1}%
1113 \def\reserved@b{#1}%
1114 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1116 \ifx\reserved@a\reserved@b
1121 \expandafter\noexpand\csname
1122 \expandafter\@gobble\string#1 \endcsname
1124 \let\@ifdefinable\@rc@ifdefinable
1125 \expandafter\new@command\csname
1126 \expandafter\@gobble\string#1 \endcsname
1133 % \begin{macro}{\@x@protect}
1134 % \begin{macro}{\x@protect}
1138 \ifx\protect\@typeset@protect\else
1142 \def\@x@protect#1\fi#2#3{%
1149 % \begin{macro}{\@typeset@protect}
1152 \let\@typeset@protect\relax
1156 % \changes{v1.2e}{1994/11/04}{Added commands for setting and restoring
1157 % \cs{protect}. ASAJ.}
1159 % \begin{macro}{\set@display@protect}
1160 % \begin{macro}{\set@typeset@protect}
1161 % These macros set |\protect| appropriately for typesetting or
1163 % \changes{v1.2o}{1995/07/03}{Use \cs{@typeset@protect} for init}
1165 \def\set@display@protect{\let\protect\string}
1166 \def\set@typeset@protect{\let\protect\@typeset@protect}
1171 % \begin{macro}{\protected@edef}
1172 % \begin{macro}{\protected@xdef}
1173 % \begin{macro}{\unrestored@protected@xdef}
1174 % \begin{macro}{\restore@protect}
1175 % The commands |\protected@edef| and |\protected@xdef| perform
1176 % `safe' |\edef|s and |\xdef|s, saving and restoring |\protect|
1177 % appropriately. For cases where restoring |\protect| doesn't
1178 % matter, there's an `unsafe' |\unrestored@protected@xdef|, useful
1179 % if you know what you're doing!
1181 \def\protected@edef{%
1182 \let\@@protect\protect
1183 \let\protect\@unexpandable@protect
1184 \afterassignment\restore@protect
1187 \def\protected@xdef{%
1188 \let\@@protect\protect
1189 \let\protect\@unexpandable@protect
1190 \afterassignment\restore@protect
1193 \def\unrestored@protected@xdef{%
1194 \let\protect\@unexpandable@protect
1197 \def\restore@protect{\let\protect\@@protect}
1205 % \begin{macro}{\protect}
1206 % The normal meaning of |\protect|
1207 % \changes{v1.2j}{1995/04/29}{Init \cs{protect} here}
1209 \set@typeset@protect
1213 % \begin{macro}{\MakeRobust}
1214 % \changes{v1.4a}{2015/01/08}{Added macro}
1216 % The macro firstly checks if the controls sequence in question exists
1220 %<latexrelease>\IncludeInRelease{2015/01/01}{\MakeRobust}{\MakeRobust}%
1221 %<*2ekernel|latexrelease>
1223 \@ifundefined{\expandafter\@gobble\string#1}{%
1224 \@latex@error{The control sequence `\string#1' is undefined!%
1225 \MessageBreak There is nothing here to make robust}%
1229 % Then we check if the macro is already robust. We do this by testing
1230 % if the internal name for a robust macro is defined, namely
1231 % \verb*=\foo =. If it is already defined do nothing, otherwise set
1232 % \verb*=\foo = equal to \verb*=\foo= and redefine \verb*=\foo= so
1233 % that it acts like a macro defined with \verb=\DeclareRobustCommand=.
1236 \@ifundefined{\expandafter\@gobble\string#1\space}%
1238 \expandafter\let\csname
1239 \expandafter\@gobble\string#1\space\endcsname=#1%
1240 \edef\reserved@a{\string#1}%
1241 \def\reserved@b{#1}%
1242 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
1244 \ifx\reserved@a\reserved@b
1245 \noexpand\x@protect\noexpand#1%
1247 \noexpand\protect\expandafter\noexpand
1248 \csname\expandafter\@gobble\string#1\space\endcsname}%
1250 {\@latex@info{The control sequence `\string#1' is already robust}}%
1253 %</2ekernel|latexrelease>
1254 %<latexrelease>\EndIncludeInRelease
1255 %<latexrelease>\IncludeInRelease{0000/00/00}{\MakeRobust}{\MakeRobust}%
1256 %<latexrelease>\let\MakeRobust\@undefined
1257 %<latexrelease>\EndIncludeInRelease
1262 % \subsection{Internal defining commands}
1264 % These commands are used internally to define other \LaTeX{}
1266 % \begin{macro}{\@ifundefined}
1267 % \changes{LaTeX2e}{1993/11/23}{Redefined to remove a trailing \cs{fi}}
1268 % Check if first arg is undefined or \cs{relax} and execute second or
1269 % third arg depending,
1271 \def\@ifundefined#1{%
1272 \expandafter\ifx\csname#1\endcsname\relax
1273 \expandafter\@firstoftwo
1275 \expandafter\@secondoftwo
1281 % \begin{macro}{\@qend}
1282 % \begin{macro}{\@qrelax}
1283 % The following define |\@qend| and |\@qrelax| to be the strings
1284 % `|end|' and `|relax|' with the characters |\catcode|d 12.
1286 \edef\@qend{\expandafter\@cdr\string\end\@nil}
1287 \edef\@qrelax{\expandafter\@cdr\string\relax\@nil}
1293 % \begin{macro}{\@ifnextchar}
1294 % \changes{LaTeX209}{1992/08/24}
1295 % {(Rms) \cs{@ifnextchar} didn't work if its
1296 % first argument was an equal sign.}
1297 % \changes{v1.2q}{1995/10/02}
1298 % {Use \cs{@let@token} }
1299 % \changes{v1.3a}{1999/01/07}
1301 % \changes{v1.3b}{1999/01/07}
1302 % {extra \cs{long}. latex/2902}
1303 % \changes{v1.3e}{1999/03/01}
1304 % {remove extra \cs{long}. internal/2967}
1305 % |\@ifnextchar| peeks at the following character and compares it
1306 % with its first argument. If both are the same it executes its
1307 % second argument, otherwise its third.
1309 \long\def\@ifnextchar#1#2#3{%
1311 \def\reserved@a{#2}%
1312 \def\reserved@b{#3}%
1313 \futurelet\@let@token\@ifnch}
1317 % \begin{macro}{\kernel@ifnextchar}
1318 % \changes{v1.3g}{2004/01/23}{Added macro (pr/3501)}
1319 % This macro is the kernel version of |\@ifnextchar| which is used
1320 % in a couple of places to prevent the AMS variant from being used
1321 % since in some places this produced chaos (for example
1322 % if an \texttt{fd} file
1323 % is loaded in a random place then the optional argument to
1324 % |\ProvidesFile| could get printed there instead of being written
1325 % only in the log file. This happened
1326 % when there was a space or a newline between the mandatory and
1327 % optional arguments! It should really be fixed in the
1328 % \texttt{amsmath} package one day, but\ldots
1330 % Note that there may be other places in the kernel where this version
1331 % should be used rather than the original, but variable, version.
1334 \let\kernel@ifnextchar\@ifnextchar
1339 % \begin{macro}{\@ifnch}
1340 % |\@ifnch| is a tricky macro to skip any space tokens that may
1341 % appear before the character in question. If it encounters a space
1342 % token, it calls \@xifnch.
1343 % \changes{v1.2q}{1995/10/02}
1344 % {Use \cs{@let@token} for internal/924, save \cs{reserved@e}}
1347 \ifx\@let@token\@sptoken
1348 \let\reserved@c\@xifnch
1350 \ifx\@let@token\reserved@d
1351 \let\reserved@c\reserved@a
1353 \let\reserved@c\reserved@b
1360 % \begin{macro}{\@sptoken}
1361 % The following code makes |\@sptoken| a space token. It is
1362 % important here that the control sequence |\:| consists of
1363 % a non-letter only, so that the following whitespace is
1364 % significant. Together with the fact that the equal sign
1365 % in a |\let| may be followed by only one optional space
1366 % the desired effect is achieved.
1367 % NOTE: the following hacking must precede the definition of |\:|
1368 % as math medium space.
1370 \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token
1374 % \begin{macro}{\@xifnch}
1375 % In the following definition of |\@xifnch|, |\:| is again used
1376 % to get a space token as delimiter into the definition.
1378 \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}
1382 % \changes{v1.0n}{1994/05/10}{Added \cs{makeatletter} and
1383 % \cs{makeatother} ASAJ.}
1385 % \begin{macro}{\makeatletter}
1386 % \begin{macro}{\makeatother}
1387 % Make internal control sequences accessible or inaccessible.
1389 \def\makeatletter{\catcode`\@11\relax}
1390 \def\makeatother{\catcode`\@12\relax}
1396 % \begin{macro}{\@ifstar}
1397 % \changes{v1.2u}{1995/10/16}{(DPC) New implementation, for /1910}
1398 % The new implementation below avoids passing the \meta{true code}
1399 % Through one more |\def| than the \meta{false code}, which previously
1400 % meant that |#| had to be written as |####| in one argument, but |##|
1401 % in the other. The |*| is gobbled by |\@firstoftwo|.
1403 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
1407 % \begin{macro}{\@dblarg}
1408 % \begin{macro}{\@xdblarg}
1409 % \changes{v1.1g}{2004/01/23}{Use kernel version of
1410 % \cs{@ifnextchar} (pr/3501)}
1412 \long\def\@dblarg#1{\kernel@ifnextchar[{#1}{\@xdblarg{#1}}}
1413 \long\def\@xdblarg#1#2{#1[{#2}]{#2}}
1418 % \begin{macro}{\@sanitize}
1419 % The command |\@sanitize| changes the catcode of all special characters
1420 % except for braces to `other'. It can be used for commands like
1421 % |\index| that want to write their arguments verbatim. Needless to
1422 % say, this command should only be executed within a group, or chaos
1426 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
1427 \@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~}
1431 % \begin{macro}{\@onelevel@sanitize}
1432 % \changes{v1.2c}{1994/10/30}{Macro added}
1434 % This makes the whole ``meaning'' of |#1| (its one-level
1435 % expansion) into catcode 12 tokens: it could be used in
1436 % |\DeclareRobustCommand|.
1438 % If it is to be used on default float specifiers, this should be
1439 % done when they are defined.
1441 \def \@onelevel@sanitize #1{%
1442 \edef #1{\expandafter\strip@prefix