| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 1993-2025 |
| 4 |
% The LaTeX Project and any individual authors listed elsewhere |
| 5 |
% in this file. |
| 6 |
% |
| 7 |
% This file is part of the LaTeX base system. |
| 8 |
% ------------------------------------------- |
| 9 |
% |
| 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 |
% https://www.latex-project.org/lppl.txt |
| 15 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 16 |
% version 2008 or later. |
| 17 |
% |
| 18 |
% This file has the LPPL maintenance status "maintained". |
| 19 |
% |
| 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 |
| 22 |
% information. |
| 23 |
% |
| 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. |
| 27 |
% |
| 28 |
% \fi |
| 29 |
% |
| 30 |
% \iffalse |
| 31 |
%%% From File: ltdefns.dtx |
| 32 |
%<*driver> |
| 33 |
% \fi |
| 34 |
\ProvidesFile{ltdefns.dtx} |
| 35 |
[2025/10/01 v1.5w LaTeX Kernel (definition commands)] |
| 36 |
% \iffalse |
| 37 |
\documentclass{ltxdoc} |
| 38 |
\GetFileInfo{ltdefns.dtx} |
| 39 |
\title{\filename} |
| 40 |
\date{\filedate} |
| 41 |
\author{% |
| 42 |
Johannes Braams\and |
| 43 |
David Carlisle\and |
| 44 |
Alan Jeffrey\and |
| 45 |
Leslie Lamport\and |
| 46 |
Frank Mittelbach\and |
| 47 |
Chris Rowley\and |
| 48 |
Rainer Sch\"opf} |
| 49 |
\begin{document} |
| 50 |
\MaintainedByLaTeXTeam{latex} |
| 51 |
\maketitle |
| 52 |
\DocInput{\filename} |
| 53 |
\end{document} |
| 54 |
%</driver> |
| 55 |
% \fi |
| 56 |
% |
| 57 |
% |
| 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} |
| 61 |
% which was |
| 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 |
| 67 |
% \cs{csname}.} |
| 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 |
| 72 |
% efficiently.} |
| 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 |
| 75 |
% lterror.dtx.} |
| 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} |
| 93 |
% \changes{v1.5l}{2020/08/21}{Integration of new hook management interface} |
| 94 |
% \changes{v1.5t}{2024/04/17} |
| 95 |
% {Rename \cs{@expl@cs@argument@spec@@N} to |
| 96 |
% \cs{@expl@cs@parameter@spec@@N} (gh/1014)} |
| 97 |
% |
| 98 |
% \section{Definitions} |
| 99 |
% |
| 100 |
% This section contains commands used in defining other macros. |
| 101 |
% |
| 102 |
% \MaybeStop{} |
| 103 |
% |
| 104 |
% \begin{macrocode} |
| 105 |
%<*2ekernel> |
| 106 |
% \end{macrocode} |
| 107 |
% |
| 108 |
% |
| 109 |
% \subsection{Initex initializations} |
| 110 |
% |
| 111 |
% \task{???}{This section needs extension} |
| 112 |
% |
| 113 |
% \begin{macro}{\two@digits} |
| 114 |
% \changes{LaTeX2e}{1993/11/23}{Macro added} |
| 115 |
% Prefix a number less than 10 with `0'. |
| 116 |
% \begin{macrocode} |
| 117 |
\def\two@digits#1{\ifnum#1<10 0\fi\number#1} |
| 118 |
% \end{macrocode} |
| 119 |
% \end{macro} |
| 120 |
% |
| 121 |
% \changes{v1.2e}{1994/11/04}{Added \cs{set@display@protect} to |
| 122 |
% \cs{typeout}. ASAJ.} |
| 123 |
% |
| 124 |
% \begin{macro}{\typeout} |
| 125 |
% Display something on the terminal. |
| 126 |
% \changes{v1.5g}{2020/05/15}{Allow \cs{par} in the argument (gh/335)} |
| 127 |
% \begin{macrocode} |
| 128 |
%</2ekernel> |
| 129 |
%<*2ekernel|latexrelease> |
| 130 |
%<latexrelease>\IncludeInRelease{2020/10/01}% |
| 131 |
%<latexrelease> {\typeout}{Allow "par" in \typeout}% |
| 132 |
\protected\long\def\typeout#1{\begingroup |
| 133 |
\set@display@protect |
| 134 |
\def\par{^^J^^J}% |
| 135 |
\immediate\write\@unused{#1}\endgroup} |
| 136 |
%</2ekernel|latexrelease> |
| 137 |
%<latexrelease>\EndIncludeInRelease |
| 138 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 139 |
%<latexrelease> {\typeout}{Allow "par" in \typeout}% |
| 140 |
%<latexrelease> |
| 141 |
%<latexrelease>\def\typeout#1{\begingroup\set@display@protect |
| 142 |
%<latexrelease> \immediate\write\@unused{#1}\endgroup} |
| 143 |
%<latexrelease>\EndIncludeInRelease |
| 144 |
%<*2ekernel> |
| 145 |
% \end{macrocode} |
| 146 |
% \end{macro} |
| 147 |
% |
| 148 |
% \begin{macro}{\newlinechar} |
| 149 |
% A char to be used as new-line in output to files. |
| 150 |
% \begin{macrocode} |
| 151 |
\newlinechar`\^^J |
| 152 |
% \end{macrocode} |
| 153 |
% \end{macro} |
| 154 |
% |
| 155 |
% \subsection{Saved versions of \TeX{} primitives} |
| 156 |
% |
| 157 |
% The TeX primitive |\foo| is saved as |\@@foo|. |
| 158 |
% The following primitives are handled in this way: |
| 159 |
% \begin{macro}{\@@par} |
| 160 |
% \begin{macrocode} |
| 161 |
\let\@@par=\par |
| 162 |
%\let\@@input=\input %%% moved earlier |
| 163 |
%\let\@@end=\end %%% |
| 164 |
% \end{macrocode} |
| 165 |
% \end{macro} |
| 166 |
% |
| 167 |
% \begin{macro}{\@@hyph} |
| 168 |
% Save original primitive definition. |
| 169 |
% \begin{macrocode} |
| 170 |
\let\@@hyph=\- |
| 171 |
% \end{macrocode} |
| 172 |
% \end{macro} |
| 173 |
% |
| 174 |
% |
| 175 |
% \begin{macro}{\@@italiccorr} |
| 176 |
% Save the original italic correction. |
| 177 |
% \changes{v1.0a}{1994/03/07}{Macro added} |
| 178 |
% \begin{macrocode} |
| 179 |
\let\@@italiccorr=\/ |
| 180 |
% \end{macrocode} |
| 181 |
% \end{macro} |
| 182 |
% |
| 183 |
% \begin{macro}{\@height} |
| 184 |
% \begin{macro}{\@depth} |
| 185 |
% \begin{macro}{\@width} |
| 186 |
% \begin{macro}{\@minus} |
| 187 |
% \changes{LaTeX2e}{1993/11/22}{Macro added} |
| 188 |
% \begin{macro}{\@plus} |
| 189 |
% \changes{LaTeX2e}{1993/11/22}{Macro added} |
| 190 |
% |
| 191 |
% The following definitions save token space. E.g., using |
| 192 |
% |\@height| instead of height saves 5 tokens at the cost in time |
| 193 |
% of one macro expansion. |
| 194 |
% \begin{macrocode} |
| 195 |
\def\@height{height} \def\@depth{depth} \def\@width{width} |
| 196 |
\def\@minus{minus} |
| 197 |
\def\@plus{plus} |
| 198 |
% \end{macrocode} |
| 199 |
% \begin{macro}{\hb@xt@} |
| 200 |
% \changes{v1.2k}{1995/05/07}{Macro added} |
| 201 |
% The next one is another 100 tokens worth. |
| 202 |
% \begin{macrocode} |
| 203 |
\def\hb@xt@{\hbox to} |
| 204 |
% \end{macrocode} |
| 205 |
% \end{macro} |
| 206 |
% \end{macro} |
| 207 |
% \end{macro} |
| 208 |
% \end{macro} |
| 209 |
% \end{macro} |
| 210 |
% \end{macro} |
| 211 |
% |
| 212 |
% \begin{macrocode} |
| 213 |
\message{hacks,} |
| 214 |
% \end{macrocode} |
| 215 |
% |
| 216 |
% \subsection{Command definitions} |
| 217 |
% |
| 218 |
% This section defines the following commands: |
| 219 |
% |
| 220 |
% \DescribeMacro |
| 221 |
% {\@namedef}\marg{NAME}\\ Expands to |\def\|\meta{NAME}, |
| 222 |
% except name can contain any characters. |
| 223 |
% |
| 224 |
% \DescribeMacro |
| 225 |
% {\@nameuse}\marg{NAME}\\ |
| 226 |
% Expands to |\|\meta{NAME}. |
| 227 |
% |
| 228 |
% \DescribeMacro |
| 229 |
% {\@ifnextchar} X\marg{YES}\marg{NO}\\ |
| 230 |
% Expands to \meta{YES} if next character is an `X', |
| 231 |
% and to \meta{NO} otherwise. |
| 232 |
% (Uses |\reserved@a|--|\reserved@c|.) |
| 233 |
% NOTE: GOBBLES ANY SPACE FOLLOWING IT. |
| 234 |
% |
| 235 |
% \DescribeMacro |
| 236 |
% {\@ifstar}\marg{YES}\marg{NO}\\ |
| 237 |
% Gobbles following spaces and then tests if next the |
| 238 |
% character is a '*'. If it is, then it gobbles the |
| 239 |
% `*' and expands to \meta{YES}, otherwise it expands to \meta{NO}. |
| 240 |
% |
| 241 |
% \DescribeMacro |
| 242 |
% {\@dblarg}\marg{CMD}\marg{ARG}\\ |
| 243 |
% Expands to |\|\marg{CMD}\oarg{ARG}\marg{ARG}. Use |
| 244 |
% |\@dblarg\CS| when |\CS| takes arguments |[ARG1]{ARG2}|, |
| 245 |
% where default is| ARG1| = |ARG2|. |
| 246 |
% |
| 247 |
% \DescribeMacro |
| 248 |
% {\@ifundefined}\marg{NAME}\marg{YES}\marg{NO}\\ |
| 249 |
% : If \cs{NAME} is undefined then it executes \meta{YES}, |
| 250 |
% otherwise it executes \meta{NO}. More precisely, |
| 251 |
% true if \cs{NAME} either undefined or = |\relax|. |
| 252 |
% |
| 253 |
% \DescribeMacro |
| 254 |
% {\@ifdefinable}|\NAME|\marg{YES} |
| 255 |
% Executes \meta{YES} if the user is allowed to define |\NAME|, |
| 256 |
% otherwise it gives an error. The user can define |\NAME| |
| 257 |
% if |\@ifundefined{NAME}| is true, '|NAME|' $\neq$ '|relax|' |
| 258 |
% and the first three letters of '|NAME|' are not |
| 259 |
% '|end|', and if |\endNAME| is not defined. |
| 260 |
% |
| 261 |
% \DescribeMacro |
| 262 |
% \newcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\ |
| 263 |
% User command to define |\FOO| to be a macro with |
| 264 |
% i arguments (i = 0 if missing) having the definition |
| 265 |
% \meta{TEXT}. Produces an error if |\FOO| already |
| 266 |
% defined. |
| 267 |
% |
| 268 |
% Normally the command is defined to be |\long| (ie it may |
| 269 |
% take multiple paragraphs in its argument). In the |
| 270 |
% star-form, the command is not defined as |\long| and a |
| 271 |
% blank line in any argument to the command would generate |
| 272 |
% an error. |
| 273 |
% |
| 274 |
% \DescribeMacro |
| 275 |
% \renewcommand|*|\marg{\cs{FOO}}\oarg{i}\marg{TEXT}\\ |
| 276 |
% Same as |\newcommand|, except it checks if |\FOO| already defined. |
| 277 |
% |
| 278 |
% \DescribeMacro |
| 279 |
% \newenvironment|*|\marg{FOO}\oarg{i}\marg{DEF1}\marg{DEF2}\\ |
| 280 |
% equivalent to:\\ |
| 281 |
% |\newcommand{\FOO}[i]{DEF1}| |\def{\endFOO}{DEF2}|\\ |
| 282 |
% (or the appropriate star forms). |
| 283 |
% |
| 284 |
% \DescribeMacro |
| 285 |
% \renewenvironment\\ Obvious companion to |\newenvironment|. |
| 286 |
% |
| 287 |
% \DescribeMacro |
| 288 |
% \@cons : See description of |\output| routine. |
| 289 |
% |
| 290 |
% \DescribeMacro{\@car} |
| 291 |
% |\@car T1 T2 ... Tn\@nil| == |T1| (unexpanded) |
| 292 |
% |
| 293 |
% \DescribeMacro{\@cdr} |
| 294 |
% |\@cdr T1 T2 ... Tn\@ni|l == |T2 ... Tn| (unexpanded) |
| 295 |
% |
| 296 |
% \DescribeMacro |
| 297 |
% \typeout\marg{message}\\ Produces a warning message on the terminal. |
| 298 |
% |
| 299 |
% \DescribeMacro |
| 300 |
% \typein\marg{message}\\ |
| 301 |
% Types message, asks the user to type in a command, then |
| 302 |
% executes it |
| 303 |
% |
| 304 |
% \DescribeMacro |
| 305 |
% \typein\oarg{\cs{CS}}\marg{MSG}\\ |
| 306 |
% Same as above, except defines |\CS| to be the input |
| 307 |
% instead of executing it. |
| 308 |
% |
| 309 |
% \changes{LaTeX209}{1992/03/18} |
| 310 |
% {(RMS) changed input channel from 0 to \cs{@inputcheck} to avoid |
| 311 |
% conflicts with other channels allocated by \cs{newread}} |
| 312 |
% |
| 313 |
% \begin{macro}{\typein} |
| 314 |
% |
| 315 |
% \changes{v1.2k}{1995/05/08}{Use \cs{@firstofone}} |
| 316 |
% \changes{v1.2l}{1995/05/08}{Remove unnecessary braces} |
| 317 |
% \changes{v1.2l}{1995/05/08}{Replace \cs{def} by \cs{let}} |
| 318 |
% \changes{v1.2m}{1995/05/24}{(DPC) New implementation} |
| 319 |
% \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911} |
| 320 |
% \begin{macrocode} |
| 321 |
\def\typein{% |
| 322 |
\let\@typein\relax |
| 323 |
\@testopt\@xtypein\@typein} |
| 324 |
% \end{macrocode} |
| 325 |
% |
| 326 |
% \changes{v1.2r}{1995/10/03} |
| 327 |
% {Add missing \cs{@typein} for /1710 (from patch file)} |
| 328 |
% \changes{v1.4a}{2015/01/03}{use modified definition in luatex} |
| 329 |
% \begin{macrocode} |
| 330 |
\ifx\directlua\@undefined |
| 331 |
% \end{macrocode} |
| 332 |
% |
| 333 |
% \begin{macrocode} |
| 334 |
\def\@xtypein[#1]#2{% |
| 335 |
\typeout{#2}% |
| 336 |
\advance\endlinechar\@M |
| 337 |
\read\@inputcheck to#1% |
| 338 |
\advance\endlinechar-\@M |
| 339 |
\@typein}% |
| 340 |
% \end{macrocode} |
| 341 |
% |
| 342 |
% \begin{macrocode} |
| 343 |
\else |
| 344 |
% \end{macrocode} |
| 345 |
% |
| 346 |
% \begin{macrocode} |
| 347 |
\def\@xtypein[#1]#2{% |
| 348 |
\typeout{#2}% |
| 349 |
\begingroup \endlinechar\m@ne |
| 350 |
\read\@inputcheck to#1% |
| 351 |
\expandafter\endgroup |
| 352 |
\expandafter\def\expandafter#1\expandafter{#1}% |
| 353 |
\@typein}% |
| 354 |
% \end{macrocode} |
| 355 |
% |
| 356 |
% \begin{macrocode} |
| 357 |
\fi |
| 358 |
% \end{macrocode} |
| 359 |
% \end{macro} |
| 360 |
% |
| 361 |
% \begin{macro}{\@namedef} |
| 362 |
% \begin{macrocode} |
| 363 |
\def\@namedef#1{\expandafter\def\csname #1\endcsname} |
| 364 |
% \end{macrocode} |
| 365 |
% \end{macro} |
| 366 |
% |
| 367 |
% \begin{macro}{\@nameuse} |
| 368 |
% \begin{macrocode} |
| 369 |
\def\@nameuse#1{\csname #1\endcsname} |
| 370 |
% \end{macrocode} |
| 371 |
% \end{macro} |
| 372 |
% |
| 373 |
% \begin{macro}{\@cons} |
| 374 |
% \begin{macrocode} |
| 375 |
\def\@cons#1#2{\begingroup\let\@elt\relax\xdef#1{#1\@elt #2}\endgroup} |
| 376 |
% \end{macrocode} |
| 377 |
% \end{macro} |
| 378 |
% |
| 379 |
% \begin{macro}{\@car} |
| 380 |
% \begin{macro}{\@cdr} |
| 381 |
% \begin{macrocode} |
| 382 |
\def\@car#1#2\@nil{#1} |
| 383 |
\def\@cdr#1#2\@nil{#2} |
| 384 |
% \end{macrocode} |
| 385 |
% \end{macro} |
| 386 |
% \end{macro} |
| 387 |
% |
| 388 |
% \begin{macro}{\@carcube} |
| 389 |
% |\@carcube T1 ... Tn\@nil| = |T1| |T2| |T3| , $n > 3$ |
| 390 |
% \changes{v1.5k}{2020/08/19}{Made \cs{long} for \cs{NewCommandCopy}} |
| 391 |
% \changes{v1.5o}{2020/11/25}{Added missing latexrelease entry} |
| 392 |
% \begin{macrocode} |
| 393 |
%</2ekernel> |
| 394 |
%<latexrelease>\IncludeInRelease{2020/10/01}{\@carcube}{Make \@carcube long}% |
| 395 |
%<*2ekernel|latexrelease> |
| 396 |
\long\def\@carcube#1#2#3#4\@nil{#1#2#3} |
| 397 |
%</2ekernel|latexrelease> |
| 398 |
%<latexrelease>\EndIncludeInRelease |
| 399 |
% |
| 400 |
%<latexrelease>\IncludeInRelease{0000/00/00}{\@carcube}{Undo: Make \@carcube long}% |
| 401 |
%<latexrelease>\def\@carcube#1#2#3#4\@nil{#1#2#3} |
| 402 |
%<latexrelease>\EndIncludeInRelease |
| 403 |
%<*2ekernel> |
| 404 |
% \end{macrocode} |
| 405 |
% \end{macro} |
| 406 |
% |
| 407 |
% |
| 408 |
% |
| 409 |
% \begin{macro}{\@onlypreamble} |
| 410 |
% \begin{macro}{\@preamblecmds} |
| 411 |
% This macro adds its argument to the list of commands stored in |
| 412 |
% |\@preamblecmds| to be |
| 413 |
% disabled after |\begin{document}|. These commands are redefined |
| 414 |
% to generate |\@notprerr| at this point. |
| 415 |
% \begin{macrocode} |
| 416 |
\def\@preamblecmds{} |
| 417 |
\def\@onlypreamble#1{% |
| 418 |
\expandafter\gdef\expandafter\@preamblecmds\expandafter{% |
| 419 |
\@preamblecmds\do#1}} |
| 420 |
\@onlypreamble\@onlypreamble |
| 421 |
\@onlypreamble\@preamblecmds |
| 422 |
% \end{macrocode} |
| 423 |
% \end{macro} |
| 424 |
% \end{macro} |
| 425 |
% |
| 426 |
% |
| 427 |
% \begin{macro}{\@star@or@long} |
| 428 |
% \changes{v1.2a}{1994/10/18}{macro added} |
| 429 |
% Look ahead for a |*|. If present reset |\l@ngrel@x| so that |
| 430 |
% the next definition, |#1|, will be non-long. |
| 431 |
% \begin{macrocode} |
| 432 |
%</2ekernel> |
| 433 |
%<*2ekernel|latexrelease> |
| 434 |
%<latexrelease>\IncludeInRelease{2025/11/01}% |
| 435 |
%<latexrelease> {\@star@or@long}{Macros without args are short}% |
| 436 |
% \end{macrocode} |
| 437 |
% |
| 438 |
% \begin{macrocode} |
| 439 |
\def\@star@or@long#1{% |
| 440 |
% \end{macrocode} |
| 441 |
% By default commands defined with \cs{newcommand} and friends are |
| 442 |
% not \cs{protected} so \cs{pr@tectedrel@x} is set to \cs{relax}. |
| 443 |
% \changes{v1.5w}{2025/10/01}{Handling protection status differently (gh/571)} |
| 444 |
% \begin{macrocode} |
| 445 |
\let\pr@tectedrel@x\relax |
| 446 |
\@ifstar |
| 447 |
{\let\l@ngrel@x\relax#1}% |
| 448 |
{\let\l@ngrel@x\long#1}} |
| 449 |
% \end{macrocode} |
| 450 |
% |
| 451 |
% \begin{macrocode} |
| 452 |
%</2ekernel|latexrelease> |
| 453 |
%<latexrelease>\EndIncludeInRelease |
| 454 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 455 |
%<latexrelease> {\@star@or@long}{Macros without args are short}% |
| 456 |
%<latexrelease> |
| 457 |
%<latexrelease>\def\@star@or@long#1{% |
| 458 |
%<latexrelease> \@ifstar |
| 459 |
%<latexrelease> {\let\l@ngrel@x\relax#1}% |
| 460 |
%<latexrelease> {\let\l@ngrel@x\long#1}} |
| 461 |
%<latexrelease> |
| 462 |
%<latexrelease>\EndIncludeInRelease |
| 463 |
%<*2ekernel> |
| 464 |
% \end{macrocode} |
| 465 |
% \end{macro} |
| 466 |
% |
| 467 |
|
| 468 |
% \begin{macro}{\l@ngrel@x} |
| 469 |
% This is either |\relax| or |\long| depending on whether the |*|-form |
| 470 |
% of a definition command is being executed. |
| 471 |
% \begin{macrocode} |
| 472 |
\let\l@ngrel@x\relax |
| 473 |
% \end{macrocode} |
| 474 |
% \end{macro} |
| 475 |
% |
| 476 |
% |
| 477 |
% \begin{macro}{\pr@tectedrel@x} |
| 478 |
% Same for the protection status. |
| 479 |
% \changes{v1.5w}{2025/10/01}{Handling protection status differently (gh/571)} |
| 480 |
% \begin{macrocode} |
| 481 |
\let\pr@tectedrel@x\relax |
| 482 |
% \end{macrocode} |
| 483 |
% \end{macro} |
| 484 |
% |
| 485 |
% |
| 486 |
% |
| 487 |
% |
| 488 |
% |
| 489 |
% |
| 490 |
% \begin{macro}{\newcommand} |
| 491 |
% \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended} |
| 492 |
% User level |\newcommand|.% |
| 493 |
% \begin{macrocode} |
| 494 |
\def\newcommand{\@star@or@long\new@command} |
| 495 |
% \end{macrocode} |
| 496 |
% |
| 497 |
% \begin{macro}{\new@command} |
| 498 |
% \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911} |
| 499 |
% \begin{macrocode} |
| 500 |
\def\new@command#1{% |
| 501 |
\@testopt{\@newcommand#1}0} |
| 502 |
% \end{macrocode} |
| 503 |
% \end{macro} |
| 504 |
% \end{macro} |
| 505 |
% |
| 506 |
% |
| 507 |
% \begin{macro}{\@newcommand} |
| 508 |
% \changes{LaTeX2e}{1993/11/23}{Macro added} |
| 509 |
% \begin{macro}{\@argdef} |
| 510 |
% \changes{LaTeX2e}{1993/11/23}{Macro added} |
| 511 |
% \begin{macro}{\@xargdef} |
| 512 |
% \changes{LaTeX2e}{1993/11/23}{Macro interface changed} |
| 513 |
% \changes{v1.1g}{2004/01/23}{Use kernel version of |
| 514 |
% \cs{@ifnextchar} (pr/3501)} |
| 515 |
% Handling arguments for |\newcommand|. |
| 516 |
% \begin{macrocode} |
| 517 |
\def\@newcommand#1[#2]{% |
| 518 |
\kernel@ifnextchar [{\@xargdef#1[#2]}% |
| 519 |
{\@argdef#1[#2]}} |
| 520 |
% \end{macrocode} |
| 521 |
% Define |#1| if it is definable. |
| 522 |
% |
| 523 |
% Both here and in |\@xargdef| the replacement text is absorbed as |
| 524 |
% an argument because if we are not allowed to make the definition |
| 525 |
% we have to get rid of it completely. |
| 526 |
% \begin{macrocode} |
| 527 |
\long\def\@argdef#1[#2]#3{% |
| 528 |
\@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}} |
| 529 |
% \end{macrocode} |
| 530 |
% |
| 531 |
% \changes{v1.2q}{1995/10/02} |
| 532 |
% {New implementation, using \cs{@test@opt}} |
| 533 |
% Handle the second optional argument. |
| 534 |
% \begin{macrocode} |
| 535 |
\long\def\@xargdef#1[#2][#3]#4{% |
| 536 |
\@ifdefinable#1{% |
| 537 |
% \end{macrocode} |
| 538 |
% Define the actual command to be:\\ |
| 539 |
% |\def\foo{\@protected@testopt\foo\\foo{default}}|\\ |
| 540 |
% where |\\foo| is a csname generated from applying |\csname| and |
| 541 |
% |\string| to |\foo|, ie the actual name contains a backslash and |
| 542 |
% therefore can't clash easily with existing command names. |
| 543 |
% ``Default'' is the contents of the second optional argument of |
| 544 |
% |(re)newcommand|. |
| 545 |
% |
| 546 |
% \changes{v1.2z2}{1998/03/04} |
| 547 |
% {Unnecessary \cs{expandafter} removed: pr/2758} |
| 548 |
% \begin{macrocode} |
| 549 |
\expandafter\def\expandafter#1\expandafter{% |
| 550 |
\expandafter |
| 551 |
\@protected@testopt |
| 552 |
\expandafter |
| 553 |
#1% |
| 554 |
\csname\string#1\endcsname |
| 555 |
{#3}}% |
| 556 |
% \end{macrocode} |
| 557 |
% Now we define the internal macro ie |\\foo| which is supposed to |
| 558 |
% pick up all arguments (optional and mandatory). |
| 559 |
% \begin{macrocode} |
| 560 |
\expandafter\@yargdef |
| 561 |
\csname\string#1\endcsname |
| 562 |
\tw@ |
| 563 |
{#2}% |
| 564 |
{#4}}} |
| 565 |
% \end{macrocode} |
| 566 |
% \end{macro} |
| 567 |
% \end{macro} |
| 568 |
% \end{macro} |
| 569 |
% |
| 570 |
% \begin{macro}{\@testopt} |
| 571 |
% \changes{v1.2q}{1995/10/02} |
| 572 |
% {Macro added} |
| 573 |
% \changes{v1.3a}{1999/01/07} |
| 574 |
% {made long and brace optional arg. latex/2896} |
| 575 |
% This macro encapsulates the most common call to |\@ifnextchar|, saving |
| 576 |
% several tokens each time it is used in the definition of a command |
| 577 |
% with an optional argument. |
| 578 |
% |#1| The code to execute in the case that there is a |[| \iffalse]\fi |
| 579 |
% need not be |
| 580 |
% a single token but can be any sequence of commands that `expects' to |
| 581 |
% be followed by |[|. \iffalse]\fi |
| 582 |
% If this command were only used in |\newcommand| |
| 583 |
% definitions then |#1| would be a single token and the braces could |
| 584 |
% be omitted from |{#1}| in the definition below, saving a bit of |
| 585 |
% memory. |
| 586 |
% \changes{v1.1g}{2004/01/23}{Use kernel version of |
| 587 |
% \cs{@ifnextchar} (pr/3501)} |
| 588 |
% \begin{macrocode} |
| 589 |
\long\def\@testopt#1#2{% |
| 590 |
\kernel@ifnextchar[{#1}{#1[{#2}]}} |
| 591 |
% \end{macrocode} |
| 592 |
% \end{macro} |
| 593 |
% |
| 594 |
% \begin{macro}{\@protected@testopt} |
| 595 |
% \changes{v1.2q}{1995/10/02} |
| 596 |
% {Macro added} |
| 597 |
% Robust version of |\@testopt|. The extra argument (|#1|) must be a |
| 598 |
% single token. If protection is needed the call expands to |\protect| |
| 599 |
% applied to this token, and the 2nd and 3rd arguments are |
| 600 |
% discarded (by |\@x@protect|). Otherwise |\@testopt| is called on |
| 601 |
% the 2nd and 3rd arguments. |
| 602 |
% |
| 603 |
% This method of making commands robust avoids the need for using up |
| 604 |
% two csnames per command, the price is the extra expansion time |
| 605 |
% for the |\ifx| test. |
| 606 |
% \begin{macrocode} |
| 607 |
\def\@protected@testopt#1{% |
| 608 |
\ifx\protect\@typeset@protect |
| 609 |
\expandafter\@testopt |
| 610 |
\else |
| 611 |
\@x@protect#1% |
| 612 |
\fi} |
| 613 |
% \end{macrocode} |
| 614 |
% \end{macro} |
| 615 |
% |
| 616 |
% \begin{macro}{\@yargdef} |
| 617 |
% \begin{macro}{\@yargd@f} |
| 618 |
% \changes{v1.3f}{1999/04/29}{New macro added} |
| 619 |
% |
| 620 |
% \changes{LaTeX2e}{1993/11/23}{Macro interface changed} |
| 621 |
% \changes{LaTeX2e}{1993/11/23}{Avoid \cs{@?@?} token} |
| 622 |
% \changes{v1.0b}{1994/03/12}{Name changed from \cs{XXX@argdef}} |
| 623 |
% \changes{v1.3c}{1999/01/18}{New implementation DPC /2942} |
| 624 |
% \changes{v1.3d}{1999/02/09}{catch bad argument forms by re-inserting \#3} |
| 625 |
% \changes{v1.3f}{1999/04/29}{Full expansion and conversion needed |
| 626 |
% for digit in new version, see pr/3013} |
| 627 |
% |
| 628 |
% These generate a primitive argument specification, from a |
| 629 |
% \LaTeX\ |[|\meta{digit}|]| form; in fact \meta{digit} can be |
| 630 |
% anything such that |\number|~\meta{digit} is single digit. |
| 631 |
% |
| 632 |
% Reorganised slightly so that |\renewcommand{\reserved@a}[1]{foo}| |
| 633 |
% works. I am not sure this is worth it, as a following |
| 634 |
% |\newcommand| would over-write the definition of |\reserved@a|. |
| 635 |
% |
| 636 |
% Recall that \LaTeX2.09 goes into an infinite loop with\\ |
| 637 |
% |\renewcommand[1]{\@tempa}{foo}|\\ |
| 638 |
% (DPC 6 October 93). |
| 639 |
% |
| 640 |
% Reorganised again (DPC 1999). Rather than make a loop to |
| 641 |
% construct the argument spec by counting, just extract the |
| 642 |
% required argument spec by using a delimited argument (delimited |
| 643 |
% by the digit). This is faster and uses less tokens. The coding |
| 644 |
% is slightly odd to preserve the old interface (using |#2| = |
| 645 |
% |\tw@| as the flag to surround the first argument with |[]|). But |
| 646 |
% the new method did not allow for the number of arguments |#3| not |
| 647 |
% being given as an explicit digit; hence (further expansion of |
| 648 |
% this argument and use of) |\number| was added later in 1999. |
| 649 |
% |
| 650 |
% It is not clear why these are still |\long|. |
| 651 |
% |
| 652 |
% \begin{macrocode} |
| 653 |
\long \def \@yargdef #1#2#3{% |
| 654 |
\ifx#2\tw@ |
| 655 |
\def\reserved@b##11{[####1]}% |
| 656 |
\else |
| 657 |
\let\reserved@b\@gobble |
| 658 |
\fi |
| 659 |
\expandafter |
| 660 |
\@yargd@f \expandafter{\number #3}#1% |
| 661 |
} |
| 662 |
% \end{macrocode} |
| 663 |
% |
| 664 |
% \begin{macrocode} |
| 665 |
%</2ekernel> |
| 666 |
%<*2ekernel|latexrelease> |
| 667 |
%<latexrelease>\IncludeInRelease{2025/11/01}% |
| 668 |
%<latexrelease> {\@yargd@f}{Macros without args are short}% |
| 669 |
%<latexrelease> |
| 670 |
\long \def \@yargd@f#1#2{% |
| 671 |
\def \reserved@a ##1#1##2##{% |
| 672 |
\expandafter\def\expandafter#2\reserved@b ##1#1% |
| 673 |
}% |
| 674 |
% \end{macrocode} |
| 675 |
% If the command needs to be \cs{protected} then |
| 676 |
% \cs{pr@tectedrel@x} has the appropriate value at this point. |
| 677 |
% \changes{v1.5w}{2025/10/01}{Handling protection status differently (gh/571)} |
| 678 |
% \begin{macrocode} |
| 679 |
\pr@tectedrel@x |
| 680 |
% \end{macrocode} |
| 681 |
% If the command has no arguments then we don't want to to be \cs{long} |
| 682 |
% (even if \cs{l@ngrel@x} has been set to \cs{long}). |
| 683 |
% \changes{v1.5w}{2025/10/01}{Ensure that commands without arguments |
| 684 |
% are not long (gh/571)} |
| 685 |
% \begin{macrocode} |
| 686 |
\ifnum#1>\z@ \l@ngrel@x \fi |
| 687 |
\reserved@a 0##1##2##3##4##5##6##7##8##9###1% |
| 688 |
} |
| 689 |
% \end{macrocode} |
| 690 |
% |
| 691 |
% \begin{macrocode} |
| 692 |
%</2ekernel|latexrelease> |
| 693 |
%<latexrelease>\EndIncludeInRelease |
| 694 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 695 |
%<latexrelease> {\@yargd@f}{Macros without args are short}% |
| 696 |
%<latexrelease> |
| 697 |
%<latexrelease>\long \def \@yargd@f#1#2{% |
| 698 |
%<latexrelease> \def \reserved@a ##1#1##2##{% |
| 699 |
%<latexrelease> \expandafter\def\expandafter#2\reserved@b ##1#1% |
| 700 |
%<latexrelease> }% |
| 701 |
%<latexrelease> \l@ngrel@x \reserved@a 0##1##2##3##4##5##6##7##8##9###1% |
| 702 |
%<latexrelease>} |
| 703 |
%<latexrelease> |
| 704 |
%<latexrelease>\EndIncludeInRelease |
| 705 |
%<*2ekernel> |
| 706 |
% \end{macrocode} |
| 707 |
% |
| 708 |
% \end{macro} |
| 709 |
% \end{macro} |
| 710 |
% |
| 711 |
% \begin{macro}{\@reargdef} |
| 712 |
% \changes{LaTeX2e}{1993/12/20} |
| 713 |
% {Kept old version of \cs{@reargdef}, for array.sty} |
| 714 |
% \changes{v1.0b}{1994/03/12}{New defn, in terms of \cs{@yargdef}} |
| 715 |
% \changes{v1.2y}{1996/07/26}{third arg picked up by \cs{@yargdef}} |
| 716 |
% \begin{macrocode} |
| 717 |
\long\def\@reargdef#1[#2]{% |
| 718 |
\@yargdef#1\@ne{#2}} |
| 719 |
% \end{macrocode} |
| 720 |
% \end{macro} |
| 721 |
% |
| 722 |
% \begin{macro}{\renewcommand} |
| 723 |
% Check the command name is already used. If not give an error |
| 724 |
% message. Then temporarily |
| 725 |
% disable |\@ifdefinable| then call |\newcommand|. (Previous |
| 726 |
% version |\let#1=\relax| but this does not work too well if |#1| |
| 727 |
% is |\@temp|\emph{a--e}.) |
| 728 |
% \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended} |
| 729 |
% \changes{v1.1f}{1994/05/02}{Removed surplus \cs{space} in error} |
| 730 |
% \begin{macrocode} |
| 731 |
\def\renewcommand{\@star@or@long\renew@command} |
| 732 |
% \end{macrocode} |
| 733 |
% |
| 734 |
% \begin{macro}{\renew@command} |
| 735 |
% \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg} |
| 736 |
% \changes{v1.2y}{1996/07/26}{use \cs{noexpand} instead of \cs{string}} |
| 737 |
% \changes{v1.2z1}{1997/10/21}{Use \cs{begingroup}/\cs{endgroup} rather |
| 738 |
% than braces for grouping, to avoid generating empty math atom.} |
| 739 |
% \changes{v1.5e}{2018/09/26}{Always explicitly generate a space after the csname and |
| 740 |
% not rely on \cs{noexpand} to save tokens (gh/41)} |
| 741 |
% \changes{v1.5u}{2025/06/03}{Strip trailing spaces from arg (gh/1708)} |
| 742 |
% \begin{macrocode} |
| 743 |
\def\renew@command#1{% |
| 744 |
\begingroup |
| 745 |
\escapechar\m@ne\xdef\@gtempa{{\expandafter\string\@car#1?\@nil}}% |
| 746 |
\endgroup |
| 747 |
\expandafter\@ifundefined\@gtempa |
| 748 |
{\@latex@error{Command \string#1 undefined}\@ehc}% |
| 749 |
\relax |
| 750 |
\let\@ifdefinable\@rc@ifdefinable |
| 751 |
\new@command#1} |
| 752 |
% \end{macrocode} |
| 753 |
% \end{macro} |
| 754 |
% \end{macro} |
| 755 |
% |
| 756 |
% \changes{v1.0n}{1994/05/10}{Removed braces around \cs{@ifundefined} |
| 757 |
% argument. ASAJ.} |
| 758 |
% \changes{v1.0s}{1994/05/13}{Coded more efficiently, thanks to FMi.} |
| 759 |
% |
| 760 |
% \begin{macro}{\@ifdefinable} |
| 761 |
% \begin{macro}{\@@ifdefinable} |
| 762 |
% \begin{macro}{\@rc@ifdefinable} |
| 763 |
% Test if user is allowed to define a command. |
| 764 |
% \begin{macrocode} |
| 765 |
\long\def\@ifdefinable #1#2{% |
| 766 |
\edef\reserved@a{\expandafter\@gobble\string #1}% |
| 767 |
\@ifundefined\reserved@a |
| 768 |
{\edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}% |
| 769 |
\ifx \reserved@b\@qend \@notdefinable\else |
| 770 |
\ifx \reserved@a\@qrelax \@notdefinable\else |
| 771 |
#2% |
| 772 |
\fi |
| 773 |
\fi}% |
| 774 |
\@notdefinable} |
| 775 |
% \end{macrocode} |
| 776 |
% Saved definition of |\@ifdefinable|. |
| 777 |
% \begin{macrocode} |
| 778 |
\let\@@ifdefinable\@ifdefinable |
| 779 |
% \end{macrocode} |
| 780 |
% Version of |\@ifdefinable| for use with |\renewcommand|. Does |
| 781 |
% not do the check this time, but restores the normal definition. |
| 782 |
% \begin{macrocode} |
| 783 |
\long\def\@rc@ifdefinable#1#2{% |
| 784 |
\let\@ifdefinable\@@ifdefinable |
| 785 |
#2} |
| 786 |
% \end{macrocode} |
| 787 |
% \end{macro} |
| 788 |
% \end{macro} |
| 789 |
% \end{macro} |
| 790 |
% |
| 791 |
% \begin{macro}{\newenvironment} |
| 792 |
% Define a new user environment. |
| 793 |
% |#1| is the environment name. |#2#| Grabs all the tokens up to |
| 794 |
% the first |{|. \iffalse}\fi |
| 795 |
% These will be any optional arguments. They are not |
| 796 |
% parsed at this point, but are just passed to |\@newenv| which |
| 797 |
% will eventually call |\newcommand|. Any optional arguments will |
| 798 |
% then be parsed by |\newcommand| as it defines the command that |
| 799 |
% executes the `begin code' of the environment. |
| 800 |
% |
| 801 |
% This |#2#| trick removed with version 1.2i as it fails if a |{| \iffalse}\fi |
| 802 |
% occurs in the optional argument. Now use |\@ifnextchar| directly. |
| 803 |
% \begin{macrocode} |
| 804 |
\def\newenvironment{\@star@or@long\new@environment} |
| 805 |
% \end{macrocode} |
| 806 |
% |
| 807 |
% \begin{macro}{\new@environment} |
| 808 |
% \changes{v1.2i}{1995/04/25}{Parse arguments slowly but safely /1507} |
| 809 |
% \changes{v1.2u}{1995/10/16}{(DPC) Use \cs{@testopt} /1911} |
| 810 |
% \begin{macrocode} |
| 811 |
\def\new@environment#1{% |
| 812 |
\@testopt{\@newenva#1}0} |
| 813 |
% \end{macrocode} |
| 814 |
% |
| 815 |
% \begin{macro}{\@newenva} |
| 816 |
% \changes{v1.1g}{2004/01/23}{Use kernel version of |
| 817 |
% \cs{@ifnextchar} (pr/3501)} |
| 818 |
% \begin{macrocode} |
| 819 |
\def\@newenva#1[#2]{% |
| 820 |
\kernel@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}} |
| 821 |
% \end{macrocode} |
| 822 |
% \end{macro} |
| 823 |
% |
| 824 |
% \begin{macro}{\@newenvb} |
| 825 |
% \changes{v1.3a}{1999/01/07} |
| 826 |
% {made long and brace optional arg. latex/2896} |
| 827 |
% \begin{macrocode} |
| 828 |
\def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][{#3}]}} |
| 829 |
% \end{macrocode} |
| 830 |
% \end{macro} |
| 831 |
% |
| 832 |
% \end{macro} |
| 833 |
% \end{macro} |
| 834 |
% |
| 835 |
% |
| 836 |
% \begin{macro}{\renewenvironment} |
| 837 |
% Redefine an environment. |
| 838 |
% For |\renewenvironment| disable |\@ifdefinable| and then call |
| 839 |
% |\newenvironment|. It is OK to |\let| the argument to |\relax| |
| 840 |
% here as there should not be a |@temp|\ldots\ environment. |
| 841 |
% \changes{LaTeX2e}{1993/11/23}{Macro reimplemented and extended} |
| 842 |
% \changes{v1.1f}{1994/05/02}{Removed surplus \cs{space} in error} |
| 843 |
% \begin{macrocode} |
| 844 |
\def\renewenvironment{\@star@or@long\renew@environment} |
| 845 |
% \end{macrocode} |
| 846 |
% |
| 847 |
% \begin{macro}{\renew@environment} |
| 848 |
% \changes{v1.2a}{1994/10/18}{reset end command} |
| 849 |
% \changes{v1.2y}{1996/07/26}{use \cs{relax} in place of empty arg} |
| 850 |
% \begin{macrocode} |
| 851 |
\def\renew@environment#1{% |
| 852 |
\@ifundefined{#1}% |
| 853 |
{\@latex@error{Environment #1 undefined}\@ehc |
| 854 |
}\relax |
| 855 |
\expandafter\let\csname#1\endcsname\relax |
| 856 |
\expandafter\let\csname end#1\endcsname\relax |
| 857 |
\new@environment{#1}} |
| 858 |
% \end{macrocode} |
| 859 |
% \end{macro} |
| 860 |
% \end{macro} |
| 861 |
% |
| 862 |
% |
| 863 |
% \begin{macro}{\@newenv} |
| 864 |
% \changes{LaTeX2e}{1993/11/23}{Macro interface changed} |
| 865 |
% \changes{v1.2h}{1994/11/24}{Added test for \cs{endgraf}} |
| 866 |
% The internal version of |\newenvironment|. |
| 867 |
% |
| 868 |
% Call |\newcommand| to define the \meta{begin-code} for the |
| 869 |
% environment. |\def| is used for the \meta{end-code} as it does |
| 870 |
% not take arguments. (but may contain |\par|s) |
| 871 |
% |
| 872 |
% Make sure that an attempt to define a `graf' or `group' environment |
| 873 |
% fails by temporarily letting the undefined \verb=\...= (begin code) to |
| 874 |
% the definition of \verb=\end...= and as a result we get an error if that |
| 875 |
% has a definition. |
| 876 |
% \begin{macrocode} |
| 877 |
\long\def\@newenv#1#2#3#4{% |
| 878 |
\@ifundefined{#1}% |
| 879 |
{\expandafter\let\csname#1\expandafter\endcsname |
| 880 |
\csname end#1\endcsname}% |
| 881 |
\relax |
| 882 |
\expandafter\new@command |
| 883 |
\csname #1\endcsname#2{#3}% |
| 884 |
\l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}} |
| 885 |
% \end{macrocode} |
| 886 |
% \end{macro} |
| 887 |
% |
| 888 |
% \begin{macro}{\newif} |
| 889 |
% \changes{v1.1l}{1995/05/24}{(DPC) New implementation} |
| 890 |
% And here's a different sort of allocation: |
| 891 |
% For example, |
| 892 |
% |\newif\iffoo| creates |\footrue|, |\foofalse| to go with |\iffoo|. |
| 893 |
% \begin{macrocode} |
| 894 |
\def\newif#1{% |
| 895 |
\count@\escapechar \escapechar\m@ne |
| 896 |
\let#1\iffalse |
| 897 |
\@if#1\iftrue |
| 898 |
\@if#1\iffalse |
| 899 |
\escapechar\count@} |
| 900 |
% \end{macrocode} |
| 901 |
% |
| 902 |
% \begin{macro}{\@if} |
| 903 |
% \begin{macrocode} |
| 904 |
\def\@if#1#2{% |
| 905 |
\expandafter\def\csname\expandafter\@gobbletwo\string#1% |
| 906 |
\expandafter\@gobbletwo\string#2\endcsname |
| 907 |
{\let#1#2}} |
| 908 |
% \end{macrocode} |
| 909 |
% \end{macro} |
| 910 |
% \end{macro} |
| 911 |
% |
| 912 |
% |
| 913 |
% \begin{macro}{\providecommand} |
| 914 |
% |\providecommand| takes the same arguments as |\newcommand|, but |
| 915 |
% discards them if |#1| is already defined, Otherwise it just acts like |
| 916 |
% |\newcommand|. This implementation currently leaves any discarded |
| 917 |
% definition in |\reserved@a| (and possibly |\\reserved@a|) this |
| 918 |
% wastes a bit of space, but it will be reclaimed as soon as these |
| 919 |
% scratch macros are redefined. |
| 920 |
% |
| 921 |
% \changes{LaTeX2e}{1993/11/22}{Macro added} |
| 922 |
% \begin{macrocode} |
| 923 |
\def\providecommand{\@star@or@long\provide@command} |
| 924 |
% \end{macrocode} |
| 925 |
% |
| 926 |
% \begin{macro}{\provide@command} |
| 927 |
% \changes{v1.2z}{1997/09/09}{Use \cs{begingroup} to avoid generating |
| 928 |
% math ords if used in math mode. pr/2573} |
| 929 |
% \changes{v1.5u}{2025/06/03}{Strip trailing spaces from arg (gh/1708)} |
| 930 |
% \begin{macrocode} |
| 931 |
\def\provide@command#1{% |
| 932 |
\begingroup |
| 933 |
\escapechar\m@ne\xdef\@gtempa{{\expandafter\string\@car#1?\@nil}}% |
| 934 |
\endgroup |
| 935 |
\expandafter\@ifundefined\@gtempa |
| 936 |
{\def\reserved@a{\new@command#1}}% |
| 937 |
{\def\reserved@a{\renew@command\reserved@a}}% |
| 938 |
\reserved@a}% |
| 939 |
% \end{macrocode} |
| 940 |
% \end{macro} |
| 941 |
% \end{macro} |
| 942 |
% |
| 943 |
% \begin{macro}{\CheckCommand} |
| 944 |
% \changes{LaTeX2e}{1993/11/22}{Macro added} |
| 945 |
% \changes{v1.1e}{1994/05/20}{Changed name from \cs{@checkcommand} to |
| 946 |
% \cs{CheckCommand}.} |
| 947 |
% |\CheckCommand| takes the same arguments as |\newcommand|. If |
| 948 |
% the command already exists, with the same definition, then |
| 949 |
% nothing happens, otherwise a warning is issued. Useful for |
| 950 |
% checking the current state before a macro package starts |
| 951 |
% redefining things. Currently two macros are considered to have |
| 952 |
% the same definition if they are the same except for different |
| 953 |
% default arguments. That is, if the old definition was: |
| 954 |
% |\newcommand\xxx[2][a]{(#1)(#2)}| then |
| 955 |
% |\CheckCommand\xxx[2][b]{(#1)(#2)}| would \emph{not} generate a |
| 956 |
% warning, but, for instance |\CheckCommand\xxx[2]{(#1)(#2)}| |
| 957 |
% would. |
| 958 |
% \begin{macrocode} |
| 959 |
\def\CheckCommand{\@star@or@long\check@command} |
| 960 |
% \end{macrocode} |
| 961 |
% |\CheckCommand| is only available in the preamble part of the |
| 962 |
% document. |
| 963 |
% \begin{macrocode} |
| 964 |
\@onlypreamble\CheckCommand |
| 965 |
% \end{macrocode} |
| 966 |
% |
| 967 |
% \begin{macro}{\check@command} |
| 968 |
% \begin{macrocode} |
| 969 |
\def\check@command#1#2#{\@check@c#1{#2}} |
| 970 |
\@onlypreamble\check@command |
| 971 |
% \end{macrocode} |
| 972 |
% \end{macro} |
| 973 |
% \end{macro} |
| 974 |
% |
| 975 |
% \begin{macro}{\@check@c} |
| 976 |
% \changes{v1.2i}{1995/04/25}{Make \cs{long} for latex/1346} |
| 977 |
% |\CheckCommand| itself just grabs all the arguments we need, |
| 978 |
% without actually looking for |[| \iffalse]\fi |
| 979 |
% optional argument forms. Now |
| 980 |
% define |\reserved@a|. If |\\reserved@a| is then defined, compare it |
| 981 |
% with the ``|\#1|' otherwise compare |\reserved@a| with |#1|. |
| 982 |
% \begin{macrocode} |
| 983 |
\long\def\@check@c#1#2#3{% |
| 984 |
\expandafter\let\csname\string\reserved@a\endcsname\relax |
| 985 |
\renew@command\reserved@a#2{#3}% |
| 986 |
\@ifundefined{\string\reserved@a}% |
| 987 |
{\@check@eq#1\reserved@a}% |
| 988 |
{\expandafter\@check@eq |
| 989 |
\csname\string#1\expandafter\endcsname |
| 990 |
\csname\string\reserved@a\endcsname}} |
| 991 |
\@onlypreamble\@check@c |
| 992 |
% \end{macrocode} |
| 993 |
% \end{macro} |
| 994 |
% |
| 995 |
% \begin{macro}{\@check@eq} |
| 996 |
% Complain if |#1| and |#2| are not |\ifx| equal. |
| 997 |
% \begin{macrocode} |
| 998 |
\def\@check@eq#1#2{% |
| 999 |
\ifx#1#2\else |
| 1000 |
\@latex@warning@no@line |
| 1001 |
{Command \noexpand#1 has |
| 1002 |
changed.\MessageBreak |
| 1003 |
Check if current package is valid}% |
| 1004 |
\fi} |
| 1005 |
\@onlypreamble\@check@eq |
| 1006 |
% \end{macrocode} |
| 1007 |
% \end{macro} |
| 1008 |
% |
| 1009 |
% \begin{macro}{\@gobble} |
| 1010 |
% \begin{macro}{\@gobbletwo} |
| 1011 |
% \begin{macro}{\@gobblethree} |
| 1012 |
% \changes{v1.5g}{2020/02/27}{Macro added} |
| 1013 |
% \begin{macro}{\@gobblefour} |
| 1014 |
% \changes{v1.2n}{1995/05/26}{(CAR) Added \cs{long}s} |
| 1015 |
% The |\@gobble| macro is used to get rid of its argument. |
| 1016 |
% \begin{macrocode} |
| 1017 |
\long\def \@gobble #1{} |
| 1018 |
\long\def \@gobbletwo #1#2{} |
| 1019 |
\long\def \@gobblethree #1#2#3{} |
| 1020 |
\long\def \@gobblefour #1#2#3#4{} |
| 1021 |
% \end{macrocode} |
| 1022 |
% \end{macro} |
| 1023 |
% \end{macro} |
| 1024 |
% \end{macro} |
| 1025 |
% \end{macro} |
| 1026 |
% |
| 1027 |
% There are also \cs{@gobble@om}, \cs{@gobble@som}, |
| 1028 |
% \cs{@gobble@with@sphack@om}, and \cs{@gobble@with@sphack@som}. They |
| 1029 |
% accept an optional and a mandatory argument, possibly preceeded by a |
| 1030 |
% star. In all cases the expansion is empty or just manipulates the |
| 1031 |
% spaces around the command. Used to disable commands such as |
| 1032 |
% \cs{index} or \cs{label} in certain situations. Since they are |
| 1033 |
% defined with \cs{DeclareDocumentCommand}, which is not yet available |
| 1034 |
% at this point, the actual definition happens in \texttt{ltsect.dtx}. |
| 1035 |
% |
| 1036 |
% \begin{macro}{\@firstofone} |
| 1037 |
% \begin{macro}{\@firstoftwo} |
| 1038 |
% \begin{macro}{\@secondoftwo} |
| 1039 |
% Some argument-grabbers. |
| 1040 |
% \begin{macrocode} |
| 1041 |
\long\def\@firstofone#1{#1} |
| 1042 |
\long\def\@firstoftwo#1#2{#1} |
| 1043 |
\long\def\@secondoftwo#1#2{#2} |
| 1044 |
% \end{macrocode} |
| 1045 |
% \begin{macro}{\@iden} |
| 1046 |
% |\@iden| is another name for |\@firstofone| for |
| 1047 |
% compatibility reasons. |
| 1048 |
% \begin{macrocode} |
| 1049 |
\let\@iden\@firstofone |
| 1050 |
% \end{macrocode} |
| 1051 |
% \end{macro} |
| 1052 |
% \end{macro} |
| 1053 |
% \end{macro} |
| 1054 |
% \end{macro} |
| 1055 |
% |
| 1056 |
% \begin{macro}{\@thirdofthree} |
| 1057 |
% Another grabber now used in the encoding specific |
| 1058 |
% section. |
| 1059 |
% \changes{v1.2z3}{1998/03/20}{Macro added} |
| 1060 |
% \begin{macrocode} |
| 1061 |
\long\def\@thirdofthree#1#2#3{#3} |
| 1062 |
% \end{macrocode} |
| 1063 |
% \end{macro} |
| 1064 |
% |
| 1065 |
% |
| 1066 |
% \begin{macro}{\@expandtwoargs} |
| 1067 |
% A macro to totally expand two arguments to another macro |
| 1068 |
% \changes{v1.5r}{2022/10/22}{Use \cs{protected@edef}.} |
| 1069 |
% \begin{macrocode} |
| 1070 |
%</2ekernel> |
| 1071 |
%<latexrelease>\IncludeInRelease{2022/11/01}% |
| 1072 |
%<latexrelease> {\@expandtwoargs}{protected edef}% |
| 1073 |
%<*2ekernel|latexrelease> |
| 1074 |
\def\@expandtwoargs#1#2#3{% |
| 1075 |
\protected@edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a} |
| 1076 |
%</2ekernel|latexrelease> |
| 1077 |
%<latexrelease>\EndIncludeInRelease |
| 1078 |
%<latexrelease>\IncludeInRelease{00/00/00}% |
| 1079 |
%<latexrelease> {\@expandtwoargs}{protected edef}% |
| 1080 |
%<latexrelease>\def\@expandtwoargs#1#2#3{% |
| 1081 |
%<latexrelease>\edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a} |
| 1082 |
%<latexrelease>\EndIncludeInRelease |
| 1083 |
%<*2ekernel> |
| 1084 |
% \end{macrocode} |
| 1085 |
% \end{macro} |
| 1086 |
% |
| 1087 |
% \begin{macro}{\@backslashchar} |
| 1088 |
% A category code 12 backslash. |
| 1089 |
% \begin{macrocode} |
| 1090 |
\edef\@backslashchar{\expandafter\@gobble\string\\} |
| 1091 |
% \end{macrocode} |
| 1092 |
% \end{macro} |
| 1093 |
% |
| 1094 |
% \changes{v1.0n}{1994/05/10}{Added \cs{DeclareProtectedCommand}} |
| 1095 |
% \changes{v1.0p}{1994/05/12}{Fixed a bug with \cs{relax } which was |
| 1096 |
% using \cs{@gobble} before defining it.} |
| 1097 |
% \changes{v1.0q}{1994/05/13}{Renamed \cs{DeclareProtectedCommand} to |
| 1098 |
% \cs{DeclareRobustCommand}. Removed \cs{@if@short@command}. |
| 1099 |
% Moved to after the definition of \cs{@gobble}.} |
| 1100 |
% \changes{v1.0r}{1994/05/13}{Added logging message to |
| 1101 |
% \cs{DeclareProtectedCommand}.} |
| 1102 |
% |
| 1103 |
% \subsection{Robust commands and protect} |
| 1104 |
% |
| 1105 |
% \changes{v1.1b}{1994/05/17}{Added the discussion of protected |
| 1106 |
% commands, defined the values that \cs{protect} should have.} |
| 1107 |
% \changes{v1.1c}{1994/05/18}{Redid the discussion and definitions, in |
| 1108 |
% line with the proposed new setting of \cs{protect} in the output |
| 1109 |
% routine.} |
| 1110 |
% |
| 1111 |
% Fragile and robust commands are one of the thornier issues in |
| 1112 |
% \LaTeX's commands. Whilst typesetting documents, \LaTeX{} makes use |
| 1113 |
% of many of \TeX's features, such as arithmetic, defining macros, and |
| 1114 |
% setting variables. However, there are (at least) three different |
| 1115 |
% occasions when these commands are not safe. These are called |
| 1116 |
% `moving arguments' by \LaTeX, and consist of: |
| 1117 |
% \begin{itemize} |
| 1118 |
% \item writing information to a file, such as indexes or tables of |
| 1119 |
% contents. |
| 1120 |
% \item writing information to the screen. |
| 1121 |
% \item inside an |\edef|, |\message|, |\mark|, or other command which |
| 1122 |
% evaluates its argument fully. |
| 1123 |
% \end{itemize} |
| 1124 |
% The method \LaTeX{} uses for making fragile commands robust is to |
| 1125 |
% precede them with |\protect|. This can have one of four possible |
| 1126 |
% values: |
| 1127 |
% \begin{itemize} |
| 1128 |
% \item |\relax|, for normal typesetting. So |\protect\foo| will |
| 1129 |
% execute |\foo|. |
| 1130 |
% \item |\string|, for writing to the screen. So |\protect\foo| will |
| 1131 |
% write |\foo|. |
| 1132 |
% \item |\noexpand|, for writing to a file. So |\protect\foo| will |
| 1133 |
% write |\foo| followed by a space. |
| 1134 |
% \item |\@unexpandable@protect|, for writing a moving argument to a |
| 1135 |
% file. So |\protect\foo| will write |\protect\foo| followed by a |
| 1136 |
% space. This value is also used inside |\edef|s, |\mark|s and |
| 1137 |
% other commands which evaluate their arguments fully. |
| 1138 |
% More precisely, whenever the content of an |\edef| or |\xdef| etc.\ |
| 1139 |
% can contain arbitrary user input not under the direct control of the |
| 1140 |
% programmer, one should use |\proetected@edef| instead of |\edef|, etc., |
| 1141 |
% so that |\protect| has a suitable definition and the user input will |
| 1142 |
% not break if it contains fragile commands. |
| 1143 |
% \end{itemize} |
| 1144 |
% |
| 1145 |
% \changes{1.1b}{1994/05/17} |
| 1146 |
% {(ASAJ) Added the \cs{@protect@...} commands.} |
| 1147 |
% \changes{1.1c}{1994/05/18} |
| 1148 |
% {(ASAJ) Renamed the commands, and removed |
| 1149 |
% one which is no longer needed.} |
| 1150 |
% |
| 1151 |
% \begin{macro}{\@unexpandable@protect} |
| 1152 |
% \changes{1.2w}{1995/12/05}{Removed \cs{unexpandable@noexpand} as never used. internal/1733} |
| 1153 |
% \begin{macrocode} |
| 1154 |
\def\@unexpandable@protect{\noexpand\protect\noexpand} |
| 1155 |
% \end{macrocode} |
| 1156 |
% \end{macro} |
| 1157 |
% |
| 1158 |
% \changes{v1.2e}{1994/11/04}{Rewrote protected short commands |
| 1159 |
% using \cs{x@protect}. ASAJ.} |
| 1160 |
% |
| 1161 |
% \begin{macro}{\DeclareRobustCommand} |
| 1162 |
% \begin{macro}{\declare@robustcommand} |
| 1163 |
% \changes{v1.5v}{2025-06-26}{Allow for active chars} |
| 1164 |
% \begin{macro}{\declare@robustcommand@auxi} |
| 1165 |
% \changes{v1.5v}{2025-06-26}{New macro} |
| 1166 |
% \begin{macro}{\declare@robustcommand@auxii} |
| 1167 |
% \changes{v1.5v}{2025-06-26}{New macro} |
| 1168 |
% \begin{macro}{\declare@robustcommand@auxiii} |
| 1169 |
% \changes{v1.5v}{2025-06-26}{New macro} |
| 1170 |
% This is a package-writers command, which has the same syntax as |
| 1171 |
% |\newcommand|, but which declares a protected command. It does |
| 1172 |
% this by having\\ |
| 1173 |
% |\DeclareRobustCommand\foo|\\ |
| 1174 |
% define |\foo| to be |
| 1175 |
% |\protect\foo<space>|,\\ |
| 1176 |
% and then use |\newcommand\foo<space>|.\\ |
| 1177 |
% Since the internal command is |\foo<space>|, when it is written |
| 1178 |
% to an auxiliary file, it will appear as |\foo|. |
| 1179 |
% |
| 1180 |
% We have to be a |
| 1181 |
% bit cleverer if we're defining a short command, such as |\_|, in |
| 1182 |
% order to make sure that the auxiliary file does not include a |
| 1183 |
% space after the command, since |\_ a| and |\_a| aren't the same. |
| 1184 |
% In this case we define |\_| to be: |
| 1185 |
%\begin{verbatim} |
| 1186 |
% \x@protect\_\protect\_<space> |
| 1187 |
%\end{verbatim} |
| 1188 |
% which expands to: |
| 1189 |
%\begin{verbatim} |
| 1190 |
% \ifx\protect\@typeset@protect\else |
| 1191 |
% \@x@protect@\_ |
| 1192 |
% \fi |
| 1193 |
% \protect\_<space> |
| 1194 |
%\end{verbatim} |
| 1195 |
% Then if |\protect| is |\@typeset@protect| (normally |\relax|) |
| 1196 |
% then we just perform |\_<space>|, and otherwise |
| 1197 |
% |\@x@protect@| gobbles everything up and expands to |
| 1198 |
% |\protect\_|. None of that works with an active char (as we have only one |
| 1199 |
% character token to play with), so we resort to using the engine mechanism |
| 1200 |
% there. (The braces in passing |#1| there are defensive in case someone has |
| 1201 |
% passed more than one token!) |
| 1202 |
% |
| 1203 |
% \emph{Note}: setting |\protect| to any value other than |\relax| |
| 1204 |
% whilst in `typesetting' mode will cause commands to go into an |
| 1205 |
% infinite loop! In particular, setting |\protect| to |\@empty| will |
| 1206 |
% cause |\_| to loop forever. It will also break lots of other |
| 1207 |
% things, such as protected |\ifmmode|s inside |\halign|s. If you |
| 1208 |
% really have to do such a thing, then please set |
| 1209 |
% |\@typeset@protect| to be |\@empty| as well. (This is what the |
| 1210 |
% code for |\patterns| does, for example.) |
| 1211 |
% |
| 1212 |
% More fun with |\expandafter| and |\csname|. |
| 1213 |
% \begin{macrocode} |
| 1214 |
\def\DeclareRobustCommand{\@star@or@long\declare@robustcommand} |
| 1215 |
% \end{macrocode} |
| 1216 |
% |
| 1217 |
% \begin{macrocode} |
| 1218 |
\def\declare@robustcommand#1{% |
| 1219 |
\ifx\@undefined#1\else\ifx\relax#1\else |
| 1220 |
\@latex@info{Redefining \string#1}% |
| 1221 |
\fi\fi |
| 1222 |
\ifcat\noexpand~\noexpand#1% |
| 1223 |
\expandafter\declare@robustcommand@auxi |
| 1224 |
\else |
| 1225 |
\expandafter\declare@robustcommand@auxiii |
| 1226 |
\fi |
| 1227 |
{#1}% |
| 1228 |
} |
| 1229 |
% \end{macrocode} |
| 1230 |
% For active chars, we cannot use an auxiliary so have to `pack' everything we need |
| 1231 |
% in one definition. To allow for use in file names, etc., we need \cs{ifincsname}] |
| 1232 |
% in the definition, so we use two steps to grab that. We also take advantage |
| 1233 |
% of the need for an extra auxiliary to do some expansion to give us the string |
| 1234 |
% we will want. |
| 1235 |
% \begin{macrocode} |
| 1236 |
\protected\long\def\declare@robustcommand@auxi#1#2#{% |
| 1237 |
\expandafter\declare@robustcommand@auxii\expandafter{\string#1}#1{#2}% |
| 1238 |
} |
| 1239 |
% \end{macrocode} |
| 1240 |
% |
| 1241 |
% \begin{macrocode} |
| 1242 |
%</2ekernel> |
| 1243 |
%<*2ekernel|latexrelease> |
| 1244 |
%<latexrelease>\IncludeInRelease{2025/11/01}% |
| 1245 |
%<latexrelease> {\declare@robustcommand@auxii}{Macros without args are short}% |
| 1246 |
\protected\long\def\declare@robustcommand@auxii#1#2#3#4{% |
| 1247 |
% \end{macrocode} |
| 1248 |
% Here we want a \cs{protected} command. |
| 1249 |
% \changes{v1.5w}{2025/10/01}{Handling protection status differently (gh/571)} |
| 1250 |
% \begin{macrocode} |
| 1251 |
\let\pr@tectedrel@x\protected |
| 1252 |
\let\@ifdefinable\@rc@ifdefinable |
| 1253 |
\new@command#2#3{% |
| 1254 |
\ifincsname |
| 1255 |
\expandafter\@firstoftwo |
| 1256 |
\else |
| 1257 |
\expandafter\@secondoftwo |
| 1258 |
\fi |
| 1259 |
{#1}{#4}% |
| 1260 |
}% |
| 1261 |
} |
| 1262 |
% \end{macrocode} |
| 1263 |
% |
| 1264 |
% \begin{macrocode} |
| 1265 |
%</2ekernel|latexrelease> |
| 1266 |
%<latexrelease>\EndIncludeInRelease |
| 1267 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 1268 |
%<latexrelease> {\declare@robustcommand@auxii}{Macros without args are short}% |
| 1269 |
%<latexrelease> |
| 1270 |
%<latexrelease>\protected\long\def\declare@robustcommand@auxii#1#2#3#4{% |
| 1271 |
%<latexrelease> \ifx\l@ngrel@x\relax |
| 1272 |
%<latexrelease> \let\l@ngrel@x\protected |
| 1273 |
%<latexrelease> \else |
| 1274 |
%<latexrelease> \def\l@ngrel@x{\protected\long}% |
| 1275 |
%<latexrelease> \fi |
| 1276 |
%<latexrelease> \let\@ifdefinable\@rc@ifdefinable |
| 1277 |
%<latexrelease> \new@command#2#3{% |
| 1278 |
%<latexrelease> \ifincsname |
| 1279 |
%<latexrelease> \expandafter\@firstoftwo |
| 1280 |
%<latexrelease> \else |
| 1281 |
%<latexrelease> \expandafter\@secondoftwo |
| 1282 |
%<latexrelease> \fi |
| 1283 |
%<latexrelease> {#1}{#4}% |
| 1284 |
%<latexrelease> }% |
| 1285 |
%<latexrelease> } |
| 1286 |
%<latexrelease> |
| 1287 |
%<latexrelease>\EndIncludeInRelease |
| 1288 |
%<*2ekernel> |
| 1289 |
% \end{macrocode} |
| 1290 |
% |
| 1291 |
% \begin{macrocode} |
| 1292 |
\protected\def\declare@robustcommand@auxiii#1{% |
| 1293 |
\edef\reserved@a{\string#1}% |
| 1294 |
\def\reserved@b{#1}% |
| 1295 |
\edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% |
| 1296 |
\edef#1{% |
| 1297 |
\ifx\reserved@a\reserved@b |
| 1298 |
\noexpand\x@protect |
| 1299 |
\noexpand#1% |
| 1300 |
\fi |
| 1301 |
\noexpand\protect |
| 1302 |
\expandafter\noexpand\csname |
| 1303 |
\expandafter\@gobble\string#1 \endcsname |
| 1304 |
}% |
| 1305 |
\let\@ifdefinable\@rc@ifdefinable |
| 1306 |
\expandafter\new@command\csname |
| 1307 |
\expandafter\@gobble\string#1 \endcsname |
| 1308 |
} |
| 1309 |
% \end{macrocode} |
| 1310 |
% \end{macro} |
| 1311 |
% \end{macro} |
| 1312 |
% \end{macro} |
| 1313 |
% |
| 1314 |
% |
| 1315 |
% \begin{macro}{\@x@protect} |
| 1316 |
% \begin{macro}{\x@protect} |
| 1317 |
% |
| 1318 |
% \begin{macrocode} |
| 1319 |
\def\x@protect#1{% |
| 1320 |
\ifx\protect\@typeset@protect\else |
| 1321 |
\@x@protect#1% |
| 1322 |
\fi |
| 1323 |
} |
| 1324 |
\def\@x@protect#1\fi#2#3{% |
| 1325 |
\fi\protect#1% |
| 1326 |
} |
| 1327 |
% \end{macrocode} |
| 1328 |
% \end{macro} |
| 1329 |
% \end{macro} |
| 1330 |
% \end{macro} |
| 1331 |
% \end{macro} |
| 1332 |
% |
| 1333 |
% \begin{macro}{\@typeset@protect} |
| 1334 |
% We set \cs{@typeset@protect} to \cs{relax} rather than \cs{@empty} |
| 1335 |
% to make sure that the protection mechanism stops the look-ahead |
| 1336 |
% and expansion performed at the start of \cs{halign} cells. |
| 1337 |
% \begin{macrocode} |
| 1338 |
\let\@typeset@protect\relax |
| 1339 |
% \end{macrocode} |
| 1340 |
% \end{macro} |
| 1341 |
% |
| 1342 |
% \changes{v1.2e}{1994/11/04}{Added commands for setting and restoring |
| 1343 |
% \cs{protect}. ASAJ.} |
| 1344 |
% |
| 1345 |
% \begin{macro}{\set@display@protect} |
| 1346 |
% \begin{macro}{\set@typeset@protect} |
| 1347 |
% These macros set |\protect| appropriately for typesetting or |
| 1348 |
% displaying. |
| 1349 |
% \changes{v1.2o}{1995/07/03}{Use \cs{@typeset@protect} for init} |
| 1350 |
% \begin{macrocode} |
| 1351 |
\def\set@display@protect{\let\protect\string} |
| 1352 |
\def\set@typeset@protect{\let\protect\@typeset@protect} |
| 1353 |
% \end{macrocode} |
| 1354 |
% \end{macro} |
| 1355 |
% \end{macro} |
| 1356 |
% |
| 1357 |
% \begin{macro}{\protected@edef} |
| 1358 |
% \begin{macro}{\protected@xdef} |
| 1359 |
% \begin{macro}{\unrestored@protected@xdef} |
| 1360 |
% \begin{macro}{\restore@protect} |
| 1361 |
% The commands |\protected@edef| and |\protected@xdef| perform |
| 1362 |
% `safe' |\edef|s and |\xdef|s, saving and restoring |\protect| |
| 1363 |
% appropriately. For cases where restoring |\protect| doesn't |
| 1364 |
% matter, there's an `unsafe' |\unrestored@protected@xdef|, useful |
| 1365 |
% if you know what you're doing! |
| 1366 |
% \begin{macrocode} |
| 1367 |
\def\protected@edef{% |
| 1368 |
\let\@@protect\protect |
| 1369 |
\let\protect\@unexpandable@protect |
| 1370 |
\afterassignment\restore@protect |
| 1371 |
\edef |
| 1372 |
} |
| 1373 |
\def\protected@xdef{% |
| 1374 |
\let\@@protect\protect |
| 1375 |
\let\protect\@unexpandable@protect |
| 1376 |
\afterassignment\restore@protect |
| 1377 |
\xdef |
| 1378 |
} |
| 1379 |
\def\unrestored@protected@xdef{% |
| 1380 |
\let\protect\@unexpandable@protect |
| 1381 |
\xdef |
| 1382 |
} |
| 1383 |
\def\restore@protect{\let\protect\@@protect} |
| 1384 |
% \end{macrocode} |
| 1385 |
% \end{macro} |
| 1386 |
% \end{macro} |
| 1387 |
% \end{macro} |
| 1388 |
% \end{macro} |
| 1389 |
% |
| 1390 |
% |
| 1391 |
% \begin{macro}{\protect} |
| 1392 |
% The normal meaning of |\protect| |
| 1393 |
% \changes{v1.2j}{1995/04/29}{Init \cs{protect} here} |
| 1394 |
% \begin{macrocode} |
| 1395 |
\set@typeset@protect |
| 1396 |
% \end{macrocode} |
| 1397 |
% \end{macro} |
| 1398 |
% |
| 1399 |
% \begin{macro}{\MakeRobust} |
| 1400 |
% \changes{v1.4a}{2015/01/08}{Added macro} |
| 1401 |
% \changes{v1.5f}{2019/08/27}{Make the assignments global as we may |
| 1402 |
% need to apply them inside a group} |
| 1403 |
% \changes{v1.5m}{2020/08/21}{Make \cs{MakeRobust} produce the same |
| 1404 |
% command structure as \cs{DeclareRobustCommand}} |
| 1405 |
% |
| 1406 |
% This macro makes an existing fragile macro robust, but only if it |
| 1407 |
% hasn't been robust in the past, i.e., it checks for the existence |
| 1408 |
% of the macro |
| 1409 |
% \verb*=\<name> = and if that exists it assumes that |
| 1410 |
% \verb=\<name>= is already robust. In that case either undefine |
| 1411 |
% the inner macro first or use \cs{DeclareRobustCommand} to |
| 1412 |
% define it in a robust way directly. We could probably test the |
| 1413 |
% top-level definition to have the right kind of structure, but |
| 1414 |
% this is somewhat problematical as we then have to distinguish |
| 1415 |
% between \cs{long} macros and others and also take into account |
| 1416 |
% that sometimes the top-level is deliberately done manually (like |
| 1417 |
% with \cs{begin}). |
| 1418 |
% |
| 1419 |
% The macro firstly checks if the control sequence in question exists |
| 1420 |
% at all. |
| 1421 |
% \changes{v1.5p}{2021/05/26}{Normalize error message in \cs{MakeRobust}} |
| 1422 |
% \begin{macrocode} |
| 1423 |
%</2ekernel> |
| 1424 |
%<latexrelease>\IncludeInRelease{2020/10/01}{\MakeRobust}{\MakeRobust}% |
| 1425 |
%<*2ekernel|latexrelease> |
| 1426 |
\def\MakeRobust#1{% |
| 1427 |
\count@=\escapechar |
| 1428 |
\escapechar=`\\ |
| 1429 |
\@ifundefined{\expandafter\@gobble\string#1}{% |
| 1430 |
\@latex@error{Command `\string#1' undefined.% |
| 1431 |
\MessageBreak There is nothing here to make robust}% |
| 1432 |
\@eha |
| 1433 |
}% |
| 1434 |
% \end{macrocode} |
| 1435 |
% Then we check if the macro is already robust. We do this by testing |
| 1436 |
% if the internal name for a robust macro is defined, namely |
| 1437 |
% \verb*=\foo =. If it is already defined do nothing, otherwise set |
| 1438 |
% \verb*=\foo = equal to \verb*=\foo= and redefine \verb*=\foo= so |
| 1439 |
% that it acts like a macro defined with \verb=\DeclareRobustCommand=. |
| 1440 |
% We use \cs{@kernel@rename@newcommand} to copy \verb*=\foo= over to |
| 1441 |
% \verb*=\foo =, including a possible default optional argument. |
| 1442 |
% \begin{macrocode} |
| 1443 |
{% |
| 1444 |
\@ifundefined{\expandafter\@gobble\string#1\space}% |
| 1445 |
{% |
| 1446 |
\expandafter\@kernel@rename@newcommand |
| 1447 |
\csname\expandafter\@gobble\string#1\space\endcsname |
| 1448 |
#1% |
| 1449 |
\edef\reserved@a{\string#1}% |
| 1450 |
\def\reserved@b{#1}% |
| 1451 |
\edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% |
| 1452 |
\xdef#1{% |
| 1453 |
\ifx\reserved@a\reserved@b |
| 1454 |
\noexpand\x@protect\noexpand#1% |
| 1455 |
\fi |
| 1456 |
\noexpand\protect\expandafter\noexpand |
| 1457 |
\csname\expandafter\@gobble\string#1\space\endcsname}% |
| 1458 |
}% |
| 1459 |
{\@latex@info{Command `\string#1' is already robust}}% |
| 1460 |
}% |
| 1461 |
\escapechar=\count@ |
| 1462 |
}% |
| 1463 |
% \end{macrocode} |
| 1464 |
% |
| 1465 |
% \begin{macro}{\@kernel@rename@newcommand} |
| 1466 |
% This macro renames a command, possibly with an optional argument (defined |
| 1467 |
% with \cs{newcommand}) from |#2| to |#1|, by renaming the internal macro |
| 1468 |
% \verb=\\#2= to \verb=\\#1= and defining \verb=\#1= appropriately, then |
| 1469 |
% undefining \verb=\#2= and \verb=\\#2=. The \cs{afterassignment} trick is |
| 1470 |
% to make both definitions in \cs{@copy@newcommand} global (which are local |
| 1471 |
% by default). |
| 1472 |
% |
| 1473 |
% In case the macro was defined with \cs{newcommand} and an optional |
| 1474 |
% argument, to replicate exactly the behaviour of \cs{DeclareRobustCommand} |
| 1475 |
% we have to move also the internal \verb*=\\foo= to \verb*=\\foo =. In that |
| 1476 |
% case, \verb=#1= will be a parameterless macro (\cs{robust@command@chk@safe} |
| 1477 |
% checks that), and \cs{@if@newcommand} will return true (both defined below |
| 1478 |
% in this file). If so, we can use \cs{@copy@newcommand} rather than plain |
| 1479 |
% \cs{let} to copy the command over. \cs{@kernel@rename@newcommand} does |
| 1480 |
% this test and carries out the renaming. |
| 1481 |
% \begin{macrocode} |
| 1482 |
\def\@kernel@rename@newcommand#1#2{% |
| 1483 |
\robust@command@chk@safe#2% |
| 1484 |
{\@if@newcommand#2% |
| 1485 |
{\afterassignment\global |
| 1486 |
\global\@copy@newcommand#1#2% |
| 1487 |
\global\let#2\@undefined |
| 1488 |
\global\expandafter\let\csname\string#2\endcsname\@undefined}% |
| 1489 |
{\global\let#1=#2}}% |
| 1490 |
{\global\let#1=#2}} |
| 1491 |
% \end{macrocode} |
| 1492 |
% \end{macro} |
| 1493 |
% |
| 1494 |
% \begin{macrocode} |
| 1495 |
%</2ekernel|latexrelease> |
| 1496 |
%<latexrelease>\EndIncludeInRelease |
| 1497 |
% |
| 1498 |
%<latexrelease>\IncludeInRelease{2019/10/01}{\MakeRobust}{\MakeRobust}% |
| 1499 |
%<latexrelease>\def\MakeRobust#1{% |
| 1500 |
%<latexrelease> \@ifundefined{\expandafter\@gobble\string#1}{% |
| 1501 |
%<latexrelease> \@latex@error{The control sequence `\string#1' is undefined!% |
| 1502 |
%<latexrelease> \MessageBreak There is nothing here to make robust}% |
| 1503 |
%<latexrelease> \@eha |
| 1504 |
%<latexrelease> }% |
| 1505 |
%<latexrelease> {% |
| 1506 |
%<latexrelease> \@ifundefined{\expandafter\@gobble\string#1\space}% |
| 1507 |
%<latexrelease> {% |
| 1508 |
%<latexrelease> \global\expandafter\let\csname |
| 1509 |
%<latexrelease> \expandafter\@gobble\string#1\space\endcsname=#1% |
| 1510 |
%<latexrelease> \edef\reserved@a{\string#1}% |
| 1511 |
%<latexrelease> \def\reserved@b{#1}% |
| 1512 |
%<latexrelease> \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% |
| 1513 |
%<latexrelease> \xdef#1{% |
| 1514 |
%<latexrelease> \ifx\reserved@a\reserved@b |
| 1515 |
%<latexrelease> \noexpand\x@protect\noexpand#1% |
| 1516 |
%<latexrelease> \fi |
| 1517 |
%<latexrelease> \noexpand\protect\expandafter\noexpand |
| 1518 |
%<latexrelease> \csname\expandafter\@gobble\string#1\space\endcsname}% |
| 1519 |
%<latexrelease> }% |
| 1520 |
%<latexrelease> {\@latex@info{The control sequence `\string#1' is already robust}}% |
| 1521 |
%<latexrelease> }% |
| 1522 |
%<latexrelease>}% |
| 1523 |
%<latexrelease>\let\@kernel@rename@newcommand\@undefined |
| 1524 |
%<latexrelease>\EndIncludeInRelease |
| 1525 |
% |
| 1526 |
%<latexrelease>\IncludeInRelease{2015/01/01}{\MakeRobust}{\MakeRobust}% |
| 1527 |
%<latexrelease>\def\MakeRobust#1{% |
| 1528 |
%<latexrelease> \@ifundefined{\expandafter\@gobble\string#1}{% |
| 1529 |
%<latexrelease> \@latex@error{The control sequence `\string#1' is undefined!% |
| 1530 |
%<latexrelease> \MessageBreak There is nothing here to make robust}% |
| 1531 |
%<latexrelease> \@eha |
| 1532 |
%<latexrelease> }% |
| 1533 |
%<latexrelease> {% |
| 1534 |
%<latexrelease> \@ifundefined{\expandafter\@gobble\string#1\space}% |
| 1535 |
%<latexrelease> {% |
| 1536 |
%<latexrelease> \expandafter\let\csname |
| 1537 |
%<latexrelease> \expandafter\@gobble\string#1\space\endcsname=#1% |
| 1538 |
%<latexrelease> \edef\reserved@a{\string#1}% |
| 1539 |
%<latexrelease> \def\reserved@b{#1}% |
| 1540 |
%<latexrelease> \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% |
| 1541 |
%<latexrelease> \edef#1{% |
| 1542 |
%<latexrelease> \ifx\reserved@a\reserved@b |
| 1543 |
%<latexrelease> \noexpand\x@protect\noexpand#1% |
| 1544 |
%<latexrelease> \fi |
| 1545 |
%<latexrelease> \noexpand\protect\expandafter\noexpand |
| 1546 |
%<latexrelease> \csname\expandafter\@gobble\string#1\space\endcsname}% |
| 1547 |
%<latexrelease> }% |
| 1548 |
%<latexrelease> {\@latex@info{The control sequence `\string#1' is already robust}}% |
| 1549 |
%<latexrelease> }% |
| 1550 |
%<latexrelease>}% |
| 1551 |
%<latexrelease>\let\@kernel@rename@newcommand\@undefined |
| 1552 |
%<latexrelease>\EndIncludeInRelease |
| 1553 |
% |
| 1554 |
%<latexrelease>\IncludeInRelease{0000/00/00}{\MakeRobust}{\MakeRobust}% |
| 1555 |
%<latexrelease>\let\MakeRobust\@undefined |
| 1556 |
%<latexrelease>\let\@kernel@rename@newcommand\@undefined |
| 1557 |
%<latexrelease>\EndIncludeInRelease |
| 1558 |
%<*2ekernel> |
| 1559 |
% \end{macrocode} |
| 1560 |
% \end{macro} |
| 1561 |
% |
| 1562 |
% \begin{macro}{\kernel@make@fragile} |
| 1563 |
% The opposite of |\MakeRobust| except that it doesn't do many |
| 1564 |
% checks as it is internal to the kernel. Why does one want such a |
| 1565 |
% thing? |
| 1566 |
% Only for compatibility reasons if \texttt{latexrelease} requests |
| 1567 |
% a rollback of the kernel. For this reason we pretend that this |
| 1568 |
% command existed in all earlier versions of \LaTeX{} i.e., we are |
| 1569 |
% not rolling it back since we need it precisely then. But we have |
| 1570 |
% to get it into the \texttt{latexrelease} file so that a roll |
| 1571 |
% forward is possible too. |
| 1572 |
% \begin{macrocode} |
| 1573 |
%</2ekernel> |
| 1574 |
%<*2ekernel|latexrelease> |
| 1575 |
%<latexrelease>\IncludeInRelease{2020/10/01}% |
| 1576 |
%<latexrelease> {\kernel@make@fragile}{Undo robustness}% |
| 1577 |
\def\kernel@make@fragile#1{% |
| 1578 |
\@ifundefined{\expandafter\@gobble\string#1\space}% |
| 1579 |
% \end{macrocode} |
| 1580 |
% If not robust do nothing. |
| 1581 |
% \begin{macrocode} |
| 1582 |
{}% |
| 1583 |
% \end{macrocode} |
| 1584 |
% Otherwise copy \verb*=\foo = back to \verb=\foo=. |
| 1585 |
% Then use \cs{@kernel@rename@newcommand} to check and copy |
| 1586 |
% \verb*=\\foo = back to \verb*=\\foo= in case the command has an optional |
| 1587 |
% argument. If so, also undefine \verb*=\\foo =, and at the end undefine |
| 1588 |
% \verb*=\foo =. |
| 1589 |
% \begin{macrocode} |
| 1590 |
{% |
| 1591 |
\global\expandafter\let\expandafter #1\csname |
| 1592 |
\expandafter\@gobble\string#1\space\endcsname |
| 1593 |
\expandafter\@kernel@rename@newcommand |
| 1594 |
\csname\expandafter\@gobble\string#1\expandafter\endcsname |
| 1595 |
\csname\expandafter\@gobble\string#1\space\endcsname |
| 1596 |
\global\expandafter\let\csname |
| 1597 |
\expandafter\@gobble\string#1\space\endcsname\@undefined |
| 1598 |
}% |
| 1599 |
} |
| 1600 |
% \end{macrocode} |
| 1601 |
% |
| 1602 |
% \begin{macrocode} |
| 1603 |
%<latexrelease>\EndIncludeInRelease |
| 1604 |
% |
| 1605 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 1606 |
%<latexrelease> {\kernel@make@fragile}{Undo robustness}% |
| 1607 |
%<latexrelease>\def\kernel@make@fragile#1{% |
| 1608 |
%<latexrelease> \@ifundefined{\expandafter\@gobble\string#1\space}% |
| 1609 |
%<latexrelease> {}% |
| 1610 |
%<latexrelease> {% |
| 1611 |
%<latexrelease> \global\expandafter\let\expandafter #1\csname |
| 1612 |
%<latexrelease> \expandafter\@gobble\string#1\space\endcsname |
| 1613 |
%<latexrelease> \global\expandafter\let\csname |
| 1614 |
%<latexrelease> \expandafter\@gobble\string#1\space\endcsname\@undefined |
| 1615 |
%<latexrelease> }% |
| 1616 |
%<latexrelease>} |
| 1617 |
%<latexrelease>\EndIncludeInRelease |
| 1618 |
%</2ekernel|latexrelease> |
| 1619 |
%<*2ekernel> |
| 1620 |
% \end{macrocode} |
| 1621 |
% \end{macro} |
| 1622 |
% |
| 1623 |
% |
| 1624 |
% \subsection{Acting on robust commands} |
| 1625 |
% |
| 1626 |
% \begin{macrocode} |
| 1627 |
%</2ekernel> |
| 1628 |
%<latexrelease>\IncludeInRelease{2020-10-01}{\robust@command@act} |
| 1629 |
%<latexrelease> {Add \robust@command@act}% |
| 1630 |
%<*2ekernel|latexrelease> |
| 1631 |
% \end{macrocode} |
| 1632 |
% |
| 1633 |
% With most document level commands being robust now there is more of a |
| 1634 |
% requirement to have a standard way of aliasing (or copying) a command to a |
| 1635 |
% new name, for example to save an original definition before changing a |
| 1636 |
% command. \cs{DeclareCommandCopy} is analogous to \TeX's \cs{let}, except |
| 1637 |
% that it copes with the different types of robust commands defined by |
| 1638 |
% \LaTeX's mechanisms. |
| 1639 |
% |
| 1640 |
% A couple of ``types of robustness'' are defined by the \LaTeXe{} kernel, |
| 1641 |
% namely robust commands defined with \cs{DeclareRobustCommand} and commands |
| 1642 |
% with optional arguments defined with \cs{newcommand}. However there are |
| 1643 |
% other types of robust commands that are frequently used, which are not |
| 1644 |
% defined in the \LaTeXe{} kernel, like commands defined with |
| 1645 |
% \textsf{xparse}'s \cs{NewDocumentCommand} and \textsf{etoolbox}'s |
| 1646 |
% \cs{newrobustcmd}. |
| 1647 |
% |
| 1648 |
% In this section we will define a generic extensible machinery to act on |
| 1649 |
% robust commands. This code will then be used to test if a command is |
| 1650 |
% robust, considered the different types of robustness, and then either copy |
| 1651 |
% that definition, if \cs{DeclareCommandCopy} (or similar) is used, or show |
| 1652 |
% the definition of the command, if \cs{ShowCommand} is used. |
| 1653 |
% |
| 1654 |
% \begin{macro}{\robust@command@act} |
| 1655 |
% \changes{v1.5k}{2020/08/19}{Made \cs{robust@command@act} |
| 1656 |
% (was \cs{declare@command@copy}) more generic} |
| 1657 |
% |
| 1658 |
% The looping machinery is generic and knows nothing about what is to be done |
| 1659 |
% for each case. The syntax of the main macro \cs{robust@command@act} is: |
| 1660 |
% \begin{quote} |
| 1661 |
% |\robust@command@act|\meta{action-list}\meta{robust-cmd}\\ |
| 1662 |
% \meta{fallback-action}\meta{act-arg} |
| 1663 |
% \end{quote} |
| 1664 |
% \meta{action-list} is a token list of the form: |
| 1665 |
% \begin{quote} |
| 1666 |
% |{|\meta{if-type-1} \meta{act-type-1}|}|\\ |
| 1667 |
% |{|\meta{if-type-2} \meta{act-type-2}|}|\\ |
| 1668 |
% \ldots |
| 1669 |
% \end{quote} |
| 1670 |
% \cs{robust@command@act} will iterate over the \meta{action-list}, evaluating |
| 1671 |
% each \meta{if-type-$n$} \meta{robust-cmd} |{|\meta{true}|}{|\meta{false}|}|. |
| 1672 |
% If the \meta{if-type-$n$} conditional returns \meta{true}, then |
| 1673 |
% \meta{act-type-$n$}\meta{act-arg} is executed, and the loop ends. If the |
| 1674 |
% conditional returns \meta{false}, then \meta{if-type-$n+1$} is executed in |
| 1675 |
% the same way, until either one of the conditionals return \meta{true}, or |
| 1676 |
% the end of the \meta{action-list} is reached. If the end is reached, then |
| 1677 |
% \meta{fallback-action}\meta{act-arg} is executed before |
| 1678 |
% \cs{robust@command@act} exits. |
| 1679 |
% |
| 1680 |
% \cs{robust@command@act} will start by using \cs{robust@command@act@chk@args} |
| 1681 |
% to check if the \meta{robust-cmd} (|#2|) is a parameterless (possibly |
| 1682 |
% \cs{protected}) macro. If it is not, the command is not a robust command: |
| 1683 |
% these always start with a parameterless user-level macro; in that case, |
| 1684 |
% \cs{robust@command@act@end} is used to short-circuit the process and do the |
| 1685 |
% \meta{fallback-action} (|#3|). This first test is necessary because later |
| 1686 |
% on we need to be able to expand the \meta{robust-cmd} without the risk of it |
| 1687 |
% Breaking Badly, and as a bonus, this speeds up the process in case we used |
| 1688 |
% \cs{NewCommandCopy} in a ``normal'' macro. |
| 1689 |
% \begin{macrocode} |
| 1690 |
\long\def\robust@command@act#1#2#3#4{% |
| 1691 |
\robust@command@chk@safe#2% |
| 1692 |
{\expandafter\robust@command@act@loop |
| 1693 |
\expandafter#2% |
| 1694 |
#1{\@nnil\@nnil}% |
| 1695 |
\robust@command@act@end}% |
| 1696 |
{\robust@command@act@end}% |
| 1697 |
{#3}{#4}}% |
| 1698 |
% \end{macrocode} |
| 1699 |
% |
| 1700 |
% \begin{macro}{\robust@command@act@loop} |
| 1701 |
% \begin{macro}{\robust@command@act@loop@aux} |
| 1702 |
% \begin{macro}{\robust@command@act@do} |
| 1703 |
% If \cs{robust@command@act@chk@args} branched to false, then |
| 1704 |
% \cs{robust@command@act@loop} will loop over the list of items in the |
| 1705 |
% \meta{action-list} (|#1|), and process each item as described earlier. |
| 1706 |
% If the \meta{if-type-$n$} command expands to \meta{true} then |
| 1707 |
% \cs{robust@command@act@do} is used to execute \meta{act-type-$n$} on the |
| 1708 |
% \meta{act-arg}, otherwise the loop resumes with the next item. |
| 1709 |
% \begin{macrocode} |
| 1710 |
\long\def\robust@command@act@loop#1#2{\robust@command@act@loop@aux#1#2} |
| 1711 |
\long\def\robust@command@act@loop@aux#1#2#3{% |
| 1712 |
\ifx\@nnil#2% |
| 1713 |
\else |
| 1714 |
#2{#1}% |
| 1715 |
{\robust@command@act@do{#3}}% |
| 1716 |
{\expandafter\robust@command@act@loop\expandafter#1}% |
| 1717 |
\fi} |
| 1718 |
\long\def\robust@command@act@do#1% |
| 1719 |
\fi#2% |
| 1720 |
\robust@command@act@end#3#4{% |
| 1721 |
\fi |
| 1722 |
#1#4} |
| 1723 |
% \end{macrocode} |
| 1724 |
% \end{macro} |
| 1725 |
% \end{macro} |
| 1726 |
% \end{macro} |
| 1727 |
% |
| 1728 |
% \begin{macro}{\robust@command@act@end} |
| 1729 |
% If the end is reached and no action was taken, then do |
| 1730 |
% \meta{fallback-action}\meta{act-arg}. |
| 1731 |
% \begin{macrocode} |
| 1732 |
\long\def\robust@command@act@end#1#2{#1#2} |
| 1733 |
% \end{macrocode} |
| 1734 |
% \end{macro} |
| 1735 |
% |
| 1736 |
% \begin{macro}{\robust@command@chk@safe} |
| 1737 |
% \begin{macro}{\robust@command@act@chk@args} |
| 1738 |
% \begin{macrocode} |
| 1739 |
\long\def\robust@command@chk@safe#1{% |
| 1740 |
\begingroup |
| 1741 |
\escapechar=`\\ |
| 1742 |
\expandafter\endgroup\expandafter |
| 1743 |
\robust@command@act@chk@args\meaning#1:->\@nil} |
| 1744 |
\def\robust@command@act@chk@args#1:->#2\@nil{% |
| 1745 |
\@expl@str@if@eq@@nnTF{#1}{macro}% |
| 1746 |
{\@firstoftwo}% |
| 1747 |
{\@expl@str@if@eq@@nnTF{#1}{\protected macro}% |
| 1748 |
{\@firstoftwo}% |
| 1749 |
{\@secondoftwo}}} |
| 1750 |
% \end{macrocode} |
| 1751 |
% \end{macro} |
| 1752 |
% \end{macro} |
| 1753 |
% |
| 1754 |
% \begin{macrocode} |
| 1755 |
%</2ekernel|latexrelease> |
| 1756 |
%<latexrelease>\EndIncludeInRelease |
| 1757 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\robust@command@act} |
| 1758 |
%<latexrelease> {Add \robust@command@act}% |
| 1759 |
%<latexrelease>\let\robust@command@act\@undefined |
| 1760 |
%<latexrelease>\let\robust@command@act@loop\@undefined |
| 1761 |
%<latexrelease>\let\robust@command@act@loop@aux\@undefined |
| 1762 |
%<latexrelease>\let\robust@command@act@do\@undefined |
| 1763 |
%<latexrelease>\let\robust@command@act@end\@undefined |
| 1764 |
%<latexrelease>\let\robust@command@chk@safe\@undefined |
| 1765 |
%<latexrelease>\let\robust@command@act@chk@args\@undefined |
| 1766 |
%<latexrelease>\EndIncludeInRelease |
| 1767 |
%<*2ekernel> |
| 1768 |
% \end{macrocode} |
| 1769 |
% |
| 1770 |
% \end{macro} |
| 1771 |
% |
| 1772 |
% |
| 1773 |
% \subsubsection{Copying robust commands} |
| 1774 |
% |
| 1775 |
% \begin{macrocode} |
| 1776 |
%</2ekernel> |
| 1777 |
%<latexrelease>\IncludeInRelease{2020-10-01}{\DeclareCommandCopy} |
| 1778 |
%<latexrelease> {Add \NewCommandCopy, \RenewCommandCopy, and \DeclareCommandCopy}% |
| 1779 |
%<*2ekernel|latexrelease> |
| 1780 |
% \end{macrocode} |
| 1781 |
% |
| 1782 |
% \begin{macro}{\NewCommandCopy} |
| 1783 |
% \begin{macro}{\RenewCommandCopy} |
| 1784 |
% \begin{macro}{\DeclareCommandCopy} |
| 1785 |
% \changes{v1.5j}{2020/05/09}{Added \cs{DeclareCommandCopy} (gh/239)} |
| 1786 |
% |
| 1787 |
% \cs{NewCommandCopy} starts by checking if \verb=#1= is already defined, and |
| 1788 |
% raises an error if so, otherwise the definition is carried out. |
| 1789 |
% \cs{RenewCommandCopy} does (almost) the opposite. If the command is |
| 1790 |
% \emph{not} defined, then an error is raised. But the definition is carried |
| 1791 |
% out anyhow, so the behaviour is consistent with \cs{renewcommand}. |
| 1792 |
% |
| 1793 |
% A \cs{ProvideCommandCopy} isn't defined because it's not reasonably useful. |
| 1794 |
% \verb=\provide...= commands mean ``define this if there's no other |
| 1795 |
% definition'', but copying a command (usually) implies that the command being |
| 1796 |
% copied is defined, so \cs{ProvideCommandCopy} doesn't make a lot of sense. |
| 1797 |
% But more importantly, the most common use case of copying a command is to |
| 1798 |
% redefine it later, while preserving the old definition, as in: |
| 1799 |
% \begin{verbatim} |
| 1800 |
% \ProvideCommandCopy \A \B |
| 1801 |
% \renewcommand \B { ... \A ... } |
| 1802 |
% \end{verbatim} |
| 1803 |
% then, if \verb=\A= is already defined the first line is skipped, an in this |
| 1804 |
% case \verb=\B= won't work as expected. |
| 1805 |
% |
| 1806 |
% The three versions call the internal \cs{declare@commandcopy} with the |
| 1807 |
% proper action. \cs{@firstofone} will carry out the copy. The only case |
| 1808 |
% when the copy is not made is the \meta{false} case for \cs{NewCommandCopy}, |
| 1809 |
% in which the command already exists and the definition is aborted. |
| 1810 |
% \begin{macrocode} |
| 1811 |
\def\NewCommandCopy{% |
| 1812 |
\declare@commandcopy |
| 1813 |
{\@firstofone}% |
| 1814 |
{\@firstoftwo\@notdefinable}} |
| 1815 |
\def\RenewCommandCopy{% |
| 1816 |
\declare@commandcopy |
| 1817 |
{\@latex@error{Command \@backslashchar\reserved@a\space undefined}\@ehc |
| 1818 |
\@firstofone}% |
| 1819 |
{\@firstofone}} |
| 1820 |
\def\DeclareCommandCopy{% |
| 1821 |
\declare@commandcopy |
| 1822 |
{\@firstofone}% |
| 1823 |
{\@firstofone}} |
| 1824 |
% \end{macrocode} |
| 1825 |
% |
| 1826 |
% \begin{macro}{\declare@commandcopy} |
| 1827 |
% \begin{macro}{\declare@commandcopy@do} |
| 1828 |
% Start by checking if the command is already defined. The proper action is |
| 1829 |
% taken by each specific command above. If all's good, then |
| 1830 |
% \cs{robust@command@act} is called with the proper arguments as described |
| 1831 |
% earlier, with \cs{@declarecommandcopylisthook} as the \meta{action-list} and |
| 1832 |
% \cs{declare@commandcopy@let} as the \meta{fallback-action}. |
| 1833 |
% \begin{macrocode} |
| 1834 |
\long\def\declare@commandcopy#1#2#3#4{% |
| 1835 |
\edef\reserved@a{\@expl@cs@to@str@@N#3}% |
| 1836 |
\@ifundefined\reserved@a{#1}{#2}% |
| 1837 |
{\declare@commandcopy@do{#3}{#4}}} |
| 1838 |
\long\def\declare@commandcopy@do#1#2{% |
| 1839 |
\robust@command@act |
| 1840 |
\@declarecommandcopylisthook#2% |
| 1841 |
\declare@commandcopy@let{#1#2}} |
| 1842 |
% \end{macrocode} |
| 1843 |
% \end{macro} |
| 1844 |
% \end{macro} |
| 1845 |
% |
| 1846 |
% \begin{macro}{\@declarecommandcopylisthook} |
| 1847 |
% The initial definition of \cs{@declarecommandcopylisthook} contains the |
| 1848 |
% tests for the two types of robust command in the kernel. |
| 1849 |
% \begin{macrocode} |
| 1850 |
\def\@declarecommandcopylisthook{% |
| 1851 |
{\@if@DeclareRobustCommand \@copy@DeclareRobustCommand}% |
| 1852 |
{\@if@newcommand \@copy@newcommand}} |
| 1853 |
% \end{macrocode} |
| 1854 |
% \end{macro} |
| 1855 |
% |
| 1856 |
% \begin{macro}{\declare@commandcopy@let} |
| 1857 |
% The initial definition of \cs{@declarecommandcopylisthook} contains the |
| 1858 |
% tests for the two types of robust command in the kernel. |
| 1859 |
% \begin{macrocode} |
| 1860 |
\long\def\declare@commandcopy@let#1#2{\let#1=#2\relax} |
| 1861 |
% \end{macrocode} |
| 1862 |
% \end{macro} |
| 1863 |
% |
| 1864 |
% Now the rollback code. |
| 1865 |
% \begin{macrocode} |
| 1866 |
%</2ekernel|latexrelease> |
| 1867 |
%<latexrelease>\EndIncludeInRelease |
| 1868 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\DeclareCommandCopy} |
| 1869 |
%<latexrelease> {Undefine \NewCommandCopy, \RenewCommandCopy, and \DeclareCommandCopy}% |
| 1870 |
%<latexrelease>\let\NewCommandCopy\@undefined |
| 1871 |
%<latexrelease>\let\RenewCommandCopy\@undefined |
| 1872 |
%<latexrelease>\let\DeclareCommandCopy\@undefined |
| 1873 |
%<latexrelease>\let\declare@commandcopy\@undefined |
| 1874 |
%<latexrelease>\let\@declarecommandcopylisthook\@undefined |
| 1875 |
%<latexrelease>\let\declare@commandcopy@let\@undefined |
| 1876 |
%<latexrelease>\EndIncludeInRelease |
| 1877 |
%<*2ekernel> |
| 1878 |
% \end{macrocode} |
| 1879 |
% \end{macro} |
| 1880 |
% \end{macro} |
| 1881 |
% \end{macro} |
| 1882 |
% |
| 1883 |
% |
| 1884 |
% \begin{macrocode} |
| 1885 |
%</2ekernel> |
| 1886 |
%<latexrelease>\IncludeInRelease{2023-06-01}{\DeclareEnvironmentCopy} |
| 1887 |
%<latexrelease> {Add \NewEnvironmentCopy, \RenewEnvironmentCopy, and \DeclareEnvironmentCopy}% |
| 1888 |
%<*2ekernel|latexrelease> |
| 1889 |
% \end{macrocode} |
| 1890 |
% |
| 1891 |
% \begin{macro}{\NewEnvironmentCopy} |
| 1892 |
% \begin{macro}{\RenewEnvironmentCopy} |
| 1893 |
% \begin{macro}{\DeclareEnvironmentCopy} |
| 1894 |
% If \verb=\#1= or \verb=\end#1= already exist one gets an error |
| 1895 |
% message talking about the problematical command (not the |
| 1896 |
% environment). |
| 1897 |
% The remainder of the \LaTeX{} run is probably badly |
| 1898 |
% broken and it is unlikely that continuing it gives |
| 1899 |
% reasonable results. |
| 1900 |
% \changes{v1.5s}{2022/11/24}{Add \cs{NewEnvironmentCopy}, |
| 1901 |
% \cs{RenewEnvironmentCopy}, and \cs{DeclareEnvironmentCopy} (gh/963)} |
| 1902 |
% \begin{macrocode} |
| 1903 |
\def\NewEnvironmentCopy{% |
| 1904 |
\declare@environmentcopy |
| 1905 |
{\@firstofone}% |
| 1906 |
{\@firstoftwo\@notdefinable}} |
| 1907 |
\def\RenewEnvironmentCopy{% |
| 1908 |
\declare@environmentcopy |
| 1909 |
{\@latex@error{Environment \reserved@a\space undefined}\@ehc |
| 1910 |
\@firstofone}% |
| 1911 |
{\@firstofone}} |
| 1912 |
\def\DeclareEnvironmentCopy{% |
| 1913 |
\declare@environmentcopy |
| 1914 |
{\@firstofone}% |
| 1915 |
{\@firstofone}} |
| 1916 |
\long\def\declare@environmentcopy#1#2#3#4{% |
| 1917 |
\edef\reserved@a{\@ifundefined{#3}{end#3}{#3}}% |
| 1918 |
\@ifundefined\reserved@a |
| 1919 |
{\def\reserved@a{#3}#1}% |
| 1920 |
{\def\reserved@a{#3}#2}% |
| 1921 |
{\ExpandArgs{cc}\declare@commandcopy@do{#3}{#4}% |
| 1922 |
\ExpandArgs{cc}\declare@commandcopy@do{end#3}{end#4}}} |
| 1923 |
% \end{macrocode} |
| 1924 |
% |
| 1925 |
% Now the rollback code. |
| 1926 |
% \begin{macrocode} |
| 1927 |
%</2ekernel|latexrelease> |
| 1928 |
%<latexrelease>\EndIncludeInRelease |
| 1929 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\DeclareEnvironmentCopy} |
| 1930 |
%<latexrelease> {Undefine \NewEnvironmentCopy, \RenewEnvironmentCopy, and \DeclareEnvironmentCopy}% |
| 1931 |
%<latexrelease>\let\NewEnvironmentCopy\@undefined |
| 1932 |
%<latexrelease>\let\RenewEnvironmentCopy\@undefined |
| 1933 |
%<latexrelease>\let\DeclareEnvironmentCopy\@undefined |
| 1934 |
%<latexrelease>\EndIncludeInRelease |
| 1935 |
%<*2ekernel> |
| 1936 |
% \end{macrocode} |
| 1937 |
% \end{macro} |
| 1938 |
% \end{macro} |
| 1939 |
% \end{macro} |
| 1940 |
% |
| 1941 |
% |
| 1942 |
% \subsubsection{Showing robust commands} |
| 1943 |
% |
| 1944 |
% \begin{macro}{\ShowCommand} |
| 1945 |
% \changes{v1.5k}{2020/08/19}{Added \cs{ShowCommand} (gh/373)} |
| 1946 |
% |
| 1947 |
% Most of the machinery defined for \cs{NewCommandCopy} can be used to show |
| 1948 |
% the definition of a robust command, in a similar fashion to \texttt{texdef}. |
| 1949 |
% The difference is that after the command is detected to have a given type |
| 1950 |
% of robustness, rather than making a copy, we use a separate routine to show |
| 1951 |
% its definition. |
| 1952 |
% |
| 1953 |
% With all the machinery in place, \cs{ShowCommand} itself is quite simple: we |
| 1954 |
% use \cs{robust@command@act} to iterate through the \cs{@showcommandlisthook} |
| 1955 |
% list, and if nothing is found, fallback to \cs{show}. |
| 1956 |
% \begin{macrocode} |
| 1957 |
%</2ekernel> |
| 1958 |
%<latexrelease>\IncludeInRelease{2020-10-01}{\ShowCommand}% |
| 1959 |
%<latexrelease> {Add \ShowCommand}% |
| 1960 |
%<*2ekernel|latexrelease> |
| 1961 |
% \end{macrocode} |
| 1962 |
% |
| 1963 |
% \begin{macrocode} |
| 1964 |
\long\def\ShowCommand#1{% |
| 1965 |
\robust@command@act |
| 1966 |
\@showcommandlisthook#1% |
| 1967 |
\show#1} |
| 1968 |
% \end{macrocode} |
| 1969 |
% |
| 1970 |
% \begin{macro}{\@showcommandlisthook} |
| 1971 |
% The initial definition of \cs{@showcommandlisthook} contains the same tests |
| 1972 |
% as used for copying, but \cs{@show@...} commands instead of \cs{@copy@...}. |
| 1973 |
% Same as before, it is initialized to cope with \cs{DeclareRobustCommand} and |
| 1974 |
% \cs{newcommand} with optional arguments. |
| 1975 |
% \begin{macrocode} |
| 1976 |
\def\@showcommandlisthook{% |
| 1977 |
{\@if@DeclareRobustCommand \@show@DeclareRobustCommand}% |
| 1978 |
{\@if@newcommand \@show@newcommand}} |
| 1979 |
% \end{macrocode} |
| 1980 |
% \end{macro} |
| 1981 |
% |
| 1982 |
% Now the rollback code. |
| 1983 |
% \begin{macrocode} |
| 1984 |
%</2ekernel|latexrelease> |
| 1985 |
%<latexrelease>\EndIncludeInRelease |
| 1986 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\ShowCommand} |
| 1987 |
%<latexrelease> {Undefine \ShowCommand}% |
| 1988 |
%<latexrelease>\let\ShowCommand\@undefined |
| 1989 |
%<latexrelease>\let\@showcommandlisthook\@undefined |
| 1990 |
%<latexrelease>\EndIncludeInRelease |
| 1991 |
%<*2ekernel> |
| 1992 |
% \end{macrocode} |
| 1993 |
% \end{macro} |
| 1994 |
% |
| 1995 |
% \begin{macrocode} |
| 1996 |
%</2ekernel> |
| 1997 |
%<latexrelease>\IncludeInRelease{2020-10-01}{\@if@DeclareRobustCommand} |
| 1998 |
%<latexrelease> {Add \@if@DeclareRobustCommand, \@if@newcommand, |
| 1999 |
%<latexrelease> \@copy@DeclareRobustCommand, \@copy@newcommand, |
| 2000 |
%<latexrelease> \@show@DeclareRobustCommand, \@show@newcommand}% |
| 2001 |
%<*2ekernel|latexrelease> |
| 2002 |
% \end{macrocode} |
| 2003 |
% |
| 2004 |
% \subsubsection{Commands defined with \cs{DeclareRobustCommand}} |
| 2005 |
% |
| 2006 |
% \begin{macro}{\@if@DeclareRobustCommand} |
| 2007 |
% \changes{v1.5j}{2020/05/09}{Added \cs{DeclareCommandCopy} (gh/239)} |
| 2008 |
% |
| 2009 |
% Now that we provided a generic way to copy one macro to another, we need to |
| 2010 |
% define a way to check if a command is one of \LaTeXe's robust types. These |
| 2011 |
% tests are heavily based on Heiko's \cs{LetLtxMacro}, but chopped into |
| 2012 |
% separate macros. |
| 2013 |
% |
| 2014 |
% The command \cs{@if@DeclareRobustCommand} checks if a command |
| 2015 |
% \verb=\cmd= was defined by |
| 2016 |
% \cs{DeclareRobustCommand}. The test returns true if the expansion of |
| 2017 |
% \verb=\cmd= is exactly \verb*=\protect\cmd =. |
| 2018 |
% |
| 2019 |
% \begin{macrocode} |
| 2020 |
\long\def\@if@DeclareRobustCommand#1{% |
| 2021 |
\begingroup |
| 2022 |
\escapechar=`\\ |
| 2023 |
\edef\reserved@a{\string#1}% |
| 2024 |
\edef\reserved@b{\detokenize{#1}}% |
| 2025 |
\xdef\@gtempa{% |
| 2026 |
\ifx\reserved@a\reserved@b |
| 2027 |
\noexpand\x@protect |
| 2028 |
\noexpand#1% |
| 2029 |
\fi |
| 2030 |
\noexpand\protect |
| 2031 |
\expandafter\noexpand\csname\@expl@cs@to@str@@N#1 \endcsname}% |
| 2032 |
\endgroup |
| 2033 |
\ifx\@gtempa#1\relax |
| 2034 |
\expandafter\@firstoftwo |
| 2035 |
\else |
| 2036 |
\expandafter\@secondoftwo |
| 2037 |
\fi} |
| 2038 |
% \end{macrocode} |
| 2039 |
% |
| 2040 |
% \begin{macro}{\@copy@DeclareRobustCommand} |
| 2041 |
% \begin{macro}{\copy@kernel@robust@command} |
| 2042 |
% If a command was defined by \cs{DeclareRobustCommand} (that is, |
| 2043 |
% \cs{@if@DeclareRobustCommand} returns true), then to make a copy of \verb=\cmd= |
| 2044 |
% into \verb=\foo= we define the latter such that it expands to |
| 2045 |
% \verb*=\protect\foo =, then make \verb*=\foo = equal to \verb*=\cmd =. |
| 2046 |
% |
| 2047 |
% There is one detail we need to take care of: if a command was defined with |
| 2048 |
% \cs{DeclareRobustCommand} it may still have an optional argument, in which |
| 2049 |
% case there is one more macro layer before the actual definition of the |
| 2050 |
% command. We use \cs{@if@newcommand} to check that and |
| 2051 |
% \cs{@copy@newcommand} to do the copying. |
| 2052 |
% \begin{macrocode} |
| 2053 |
\long\def\@copy@DeclareRobustCommand#1#2{% |
| 2054 |
\begingroup |
| 2055 |
\escapechar=`\\ |
| 2056 |
\edef\reserved@a{\string#1}% |
| 2057 |
\edef\reserved@b{\detokenize{#1}}% |
| 2058 |
\edef\reserved@a{% |
| 2059 |
\endgroup |
| 2060 |
\def\noexpand#1{% |
| 2061 |
\ifx\reserved@a\reserved@b |
| 2062 |
\noexpand\x@protect |
| 2063 |
\noexpand#1% |
| 2064 |
\fi |
| 2065 |
\noexpand\protect |
| 2066 |
\expandafter\noexpand\csname\@expl@cs@to@str@@N#1 \endcsname}% |
| 2067 |
\noexpand\copy@kernel@robust@command |
| 2068 |
\expandafter\noexpand\csname\@expl@cs@to@str@@N#1 \endcsname |
| 2069 |
\expandafter\noexpand\csname\@expl@cs@to@str@@N#2 \endcsname}% |
| 2070 |
\reserved@a} |
| 2071 |
\long\def\copy@kernel@robust@command#1#2{% |
| 2072 |
\robust@command@chk@safe#2% |
| 2073 |
{\@if@newcommand#2% |
| 2074 |
{\@copy@newcommand}% |
| 2075 |
{\declare@commandcopy@let}} |
| 2076 |
{\declare@commandcopy@let}% |
| 2077 |
#1#2} |
| 2078 |
% \end{macrocode} |
| 2079 |
% \end{macro} |
| 2080 |
% \end{macro} |
| 2081 |
% |
| 2082 |
% \begin{macro}{\@show@DeclareRobustCommand} |
| 2083 |
% \begin{macro}{\show@kernel@robust@command} |
| 2084 |
% \begin{macro}{\@show@macro} |
| 2085 |
% Showing the command is pretty simple. This command prints the top-level |
| 2086 |
% expansion as \TeX's \cs{show} would, but with |robust macro:| rather than |
| 2087 |
% just |macro:|, then a blank line and then \cs{show} the inner command. |
| 2088 |
% For a macro defined with, say, |\DeclareRobustCommand\foo[1]{bar}|, it will |
| 2089 |
% print: |
| 2090 |
% \begin{verbatim} |
| 2091 |
% > \foo=robust macro: |
| 2092 |
% ->\protect \foo . |
| 2093 |
% |
| 2094 |
% > \foo =\long macro: |
| 2095 |
% #1->bar. |
| 2096 |
% \end{verbatim} |
| 2097 |
% If the inner command is defined with an optional argument, then |
| 2098 |
% \cs{@show@newcommand} is also used. |
| 2099 |
% |
| 2100 |
% The value of \cs{escapechar} is deliberately not enforced, so |
| 2101 |
% \cs{ShowCommand} behaves more like \cs{show}. |
| 2102 |
% \begin{macrocode} |
| 2103 |
\long\def\@show@DeclareRobustCommand#1{% |
| 2104 |
\typeout{> \string#1=robust macro:}% |
| 2105 |
\typeout{->\@expl@cs@replacement@spec@@N#1.^^J}% |
| 2106 |
\expandafter\show@kernel@robust@command |
| 2107 |
\csname\@expl@cs@to@str@@N#1 \endcsname} |
| 2108 |
\long\def\show@kernel@robust@command#1{% |
| 2109 |
\robust@command@chk@safe#1% |
| 2110 |
{\@if@newcommand#1% |
| 2111 |
{\@show@newcommand}% |
| 2112 |
{\@show@macro}}% |
| 2113 |
{\@show@macro}% |
| 2114 |
#1} |
| 2115 |
\let\@show@macro\show |
| 2116 |
% \end{macrocode} |
| 2117 |
% \end{macro} |
| 2118 |
% \end{macro} |
| 2119 |
% \end{macro} |
| 2120 |
% |
| 2121 |
% \end{macro} |
| 2122 |
% |
| 2123 |
% \subsubsection{Commands defined with \cs{newcommand} (with optional argument)} |
| 2124 |
% |
| 2125 |
% \begin{macro}{\@if@newcommand} |
| 2126 |
% A command \verb=\cmd= (or \verb*=\cmd =, if it was defined with |
| 2127 |
% \cs{DeclareRobustCommand}) with an optional argument will expand to |
| 2128 |
% \verb*=\@protected@testopt\cmd\\cmd{<opt>}=. To check that we look at the |
| 2129 |
% first three tokens in the expansion of \verb=\cmd=, and return true or false |
| 2130 |
% accordingly. |
| 2131 |
% |
| 2132 |
% This test \emph{requires} that the command be a parameterless macro, |
| 2133 |
% otherwise it will not work (and probably break). This is ensured with |
| 2134 |
% \cs{robust@command@chk@safe} before calling \cs{@if@newcommand}. |
| 2135 |
% \begin{macrocode} |
| 2136 |
\long\def\@if@newcommand#1{% |
| 2137 |
\edef\reserved@a{% |
| 2138 |
\noexpand\@protected@testopt |
| 2139 |
\noexpand#1% |
| 2140 |
\expandafter\noexpand\csname\@backslashchar\@expl@cs@to@str@@N#1\endcsname}% |
| 2141 |
\edef\reserved@b{% |
| 2142 |
\unexpanded\expandafter\expandafter\expandafter |
| 2143 |
{\expandafter\@carcube#1{}{}{}\@nil}}% |
| 2144 |
\ifx\reserved@a\reserved@b |
| 2145 |
\expandafter\@firstoftwo |
| 2146 |
\else |
| 2147 |
\expandafter\@secondoftwo |
| 2148 |
\fi} |
| 2149 |
% \end{macrocode} |
| 2150 |
% |
| 2151 |
% \begin{macro}{\@copy@newcommand} |
| 2152 |
% Then, if a command \verb=\cmd= takes an optional argument, we copy it to |
| 2153 |
% \verb=\foo= by defining the latter to expand to |
| 2154 |
% \verb=\@protected@testopt\foo\\foo{<opt>}=. |
| 2155 |
% \begin{macrocode} |
| 2156 |
\long\def\@copy@newcommand#1#2{% |
| 2157 |
\edef#1{\noexpand\@protected@testopt |
| 2158 |
\noexpand#1% |
| 2159 |
\expandafter\noexpand\csname\@backslashchar\@expl@cs@to@str@@N#1\endcsname |
| 2160 |
\unexpanded\expandafter\expandafter\expandafter |
| 2161 |
{\expandafter\@gobblethree#2}}% |
| 2162 |
\expandafter |
| 2163 |
\let\csname\@backslashchar\@expl@cs@to@str@@N#1\expandafter\endcsname |
| 2164 |
\csname\@backslashchar\@expl@cs@to@str@@N#2\endcsname} |
| 2165 |
% \end{macrocode} |
| 2166 |
% \end{macro} |
| 2167 |
% |
| 2168 |
% \begin{macro}{\@show@newcommand} |
| 2169 |
% \begin{macro}{\@show@newcommand@aux} |
| 2170 |
% A command being \cs{show}n here is guaranteed to have an optional argument. |
| 2171 |
% Start by showing the top-level expansion of the command (using \cs{typeout} |
| 2172 |
% to avoid TeX asking for interaction and extra context lines), then call |
| 2173 |
% \cs{@show@newcommand@aux} with the internal command, which contains the |
| 2174 |
% actual definition, and with the expansion of the command to extract the |
| 2175 |
% default value of the optional argument. |
| 2176 |
% \begin{macrocode} |
| 2177 |
\long\def\@show@newcommand#1{% |
| 2178 |
\typeout{> \string#1=robust macro:}% |
| 2179 |
\typeout{->\@expl@cs@replacement@spec@@N#1.^^J}% |
| 2180 |
\expandafter\@show@newcommand@aux |
| 2181 |
\csname\@backslashchar\@expl@cs@to@str@@N#1\expandafter\endcsname |
| 2182 |
\expandafter{#1}\@show@tokens} |
| 2183 |
% \end{macrocode} |
| 2184 |
% |
| 2185 |
% For a macro defined with, say, |\newcommand\foo[1][opt]{bar}|, it will |
| 2186 |
% print: |
| 2187 |
% \begin{verbatim} |
| 2188 |
% > \foo=robust macro: |
| 2189 |
% ->\@protected@testopt \foo \\foo {opt}. |
| 2190 |
% |
| 2191 |
% > \\foo=\long macro: |
| 2192 |
% > default #1=opt. |
| 2193 |
% [#1]->bar. |
| 2194 |
% \end{verbatim} |
| 2195 |
% If the command was defined with \cs{DeclareRobustCommand}, then another pair |
| 2196 |
% of lines show the top-level expansion \verb*|\protect \foo |. |
| 2197 |
% \begin{macrocode} |
| 2198 |
\long\def\@show@newcommand@aux#1#2#3{% |
| 2199 |
\typeout{> \string#1=\@expl@cs@prefix@spec@@N#1macro:}% |
| 2200 |
#3{default \string##1=\expandafter\detokenize\@gobblethree#2.^^J% |
| 2201 |
\@expl@cs@parameter@spec@@N#1->\@expl@cs@replacement@spec@@N#1}} |
| 2202 |
% \end{macrocode} |
| 2203 |
% \end{macro} |
| 2204 |
% \end{macro} |
| 2205 |
% |
| 2206 |
% \begin{macro}{\@show@tokens} |
| 2207 |
% This macro prints the contents of the token list (macro) |#1| using |
| 2208 |
% \cs{showtokens}. The \cs{expandafter} gymnastics ensures that |
| 2209 |
% \cs{showtokens} itself, and the internals of this macro aren't |
| 2210 |
% showed in the context lines. |
| 2211 |
% \begin{macrocode} |
| 2212 |
\long\def\@show@tokens#1{% |
| 2213 |
\edef\reserved@a{#1}% |
| 2214 |
\showtokens\expandafter |
| 2215 |
\expandafter\expandafter{\expandafter\reserved@a}} |
| 2216 |
% \end{macrocode} |
| 2217 |
% \end{macro} |
| 2218 |
% |
| 2219 |
% Now the rollback code. |
| 2220 |
% \begin{macrocode} |
| 2221 |
%</2ekernel|latexrelease> |
| 2222 |
%<latexrelease>\EndIncludeInRelease |
| 2223 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\@if@DeclareRobustCommand} |
| 2224 |
%<latexrelease> {Undefine \@if@DeclareRobustCommand, \@if@newcommand, |
| 2225 |
%<latexrelease> \@copy@DeclareRobustCommand, \@copy@newcommand, |
| 2226 |
%<latexrelease> \@show@DeclareRobustCommand, \@show@newcommand}% |
| 2227 |
%<latexrelease>\let\@if@DeclareRobustCommand\@undefined |
| 2228 |
%<latexrelease>\let\@copy@DeclareRobustCommand\@undefined |
| 2229 |
%<latexrelease>\let\@show@DeclareRobustCommand\@undefined |
| 2230 |
%<latexrelease>\let\@if@newcommand\@undefined |
| 2231 |
%<latexrelease>\let\@copy@newcommand\@undefined |
| 2232 |
%<latexrelease>\let\@show@newcommand\@undefined |
| 2233 |
% |
| 2234 |
%<latexrelease>\let\copy@kernel@robust@command\@undefined |
| 2235 |
%<latexrelease>\let\show@kernel@robust@command\@undefined |
| 2236 |
%<latexrelease>\let\@show@newcommand@aux\@undefined |
| 2237 |
%<latexrelease>\EndIncludeInRelease |
| 2238 |
%<*2ekernel> |
| 2239 |
% \end{macrocode} |
| 2240 |
% |
| 2241 |
% \end{macro} |
| 2242 |
% |
| 2243 |
% |
| 2244 |
% \subsubsection{Showing environments} |
| 2245 |
% |
| 2246 |
% \begin{macro}{\ShowEnvironment} |
| 2247 |
% \changes{v1.5s}{2022/11/24}{Added \cs{ShowEnvironment}} |
| 2248 |
% |
| 2249 |
% \begin{macrocode} |
| 2250 |
%</2ekernel> |
| 2251 |
%<latexrelease>\IncludeInRelease{2023-06-01}{\ShowEnvironment} |
| 2252 |
%<latexrelease> {Add \ShowEnvironment}% |
| 2253 |
%<*2ekernel|latexrelease> |
| 2254 |
% \end{macrocode} |
| 2255 |
% |
| 2256 |
% \cs{ShowEnvironment} is quite similar to \cs{ShowCommand}. We will |
| 2257 |
% pass the environment \meta{env} around as the macro |
| 2258 |
% \cs[no-index]{env}, because \cs{robust@command@act} expects a single |
| 2259 |
% token. |
| 2260 |
% \begin{macrocode} |
| 2261 |
\def\ShowEnvironment#1{% |
| 2262 |
\expandafter\@show@environment\csname #1\endcsname} |
| 2263 |
\long\def\@show@environment#1{% |
| 2264 |
\robust@command@act |
| 2265 |
\@showenvironmentlisthook#1% |
| 2266 |
\@show@normalenv#1} |
| 2267 |
% \end{macrocode} |
| 2268 |
% |
| 2269 |
% \begin{macro}{\@showenvironmentlisthook} |
| 2270 |
% This is similar to \cs{@showcommandlisthook}, but uses the dedicated |
| 2271 |
% versions for environments. |
| 2272 |
% \begin{macrocode} |
| 2273 |
\def\@showenvironmentlisthook{% |
| 2274 |
{\@if@DeclareRobustCommand \@show@DeclareRobustCommand@env}% |
| 2275 |
{\@if@newcommand \@show@newcommand@env}} |
| 2276 |
% \end{macrocode} |
| 2277 |
% \end{macro} |
| 2278 |
% |
| 2279 |
% \begin{macro}{\@show@newcommand@env} |
| 2280 |
% \begin{macro}{\@show@DeclareRobustCommand@env} |
| 2281 |
% These are similar to the command versions below, except they say |
| 2282 |
% \enquote{environment} and call \cs{@show@environment@end} to print |
| 2283 |
% the \cs{end} part. |
| 2284 |
% \begin{macrocode} |
| 2285 |
\long\def\@show@newcommand@env#1{% |
| 2286 |
\@show@environment@begin#1% |
| 2287 |
\expandafter\@show@newcommand@aux |
| 2288 |
\csname\@backslashchar\@expl@cs@to@str@@N#1\expandafter\endcsname |
| 2289 |
\expandafter{#1}\@show@typeout |
| 2290 |
\@show@environment@end#1} |
| 2291 |
\long\def\@show@DeclareRobustCommand@env#1{% |
| 2292 |
\@show@environment@begin#1% |
| 2293 |
\begingroup |
| 2294 |
\let\@show@tokens\@show@typeout |
| 2295 |
\let\@show@macro\@show@nonstop |
| 2296 |
\expandafter\show@kernel@robust@command |
| 2297 |
\csname\@expl@cs@to@str@@N#1 \endcsname |
| 2298 |
\endgroup |
| 2299 |
\@show@environment@end#1} |
| 2300 |
\long\def\@show@environment@begin#1{% |
| 2301 |
\typeout{> \string\begin{\@expl@cs@to@str@@N#1}=environment:}% |
| 2302 |
\typeout{\@expl@cs@parameter@spec@@N#1->% |
| 2303 |
\@expl@cs@replacement@spec@@N#1.^^J}} |
| 2304 |
% \end{macrocode} |
| 2305 |
% \end{macro} |
| 2306 |
% \end{macro} |
| 2307 |
% |
| 2308 |
% \begin{macro}{\@show@normalenv} |
| 2309 |
% \begin{macro}{\@show@environment@end} |
| 2310 |
% A \enquote{normal} environment is straightforward. |
| 2311 |
% \cs{@show@environment@end} needs to check if the \cs{end} part is |
| 2312 |
% defined and show it accordingly, otherwise the output would show |
| 2313 |
% gibberish. |
| 2314 |
% \begin{macrocode} |
| 2315 |
\long\def\@show@normalenv#1{% |
| 2316 |
\@show@environment@begin#1% |
| 2317 |
\@show@environment@end#1} |
| 2318 |
\long\def\@show@environment@end#1{% |
| 2319 |
\expandafter\@show@environment@end@aux |
| 2320 |
\csname end\@expl@cs@to@str@@N#1\endcsname#1} |
| 2321 |
\long\def\@show@environment@end@aux#1#2{% |
| 2322 |
\@show@tokens{\string\end{\@expl@cs@to@str@@N#2}% |
| 2323 |
\ifx\relax#1=undefined% |
| 2324 |
\else:^^J\@expl@cs@parameter@spec@@N#1->% |
| 2325 |
\@expl@cs@replacement@spec@@N#1% |
| 2326 |
\fi}} |
| 2327 |
% \end{macrocode} |
| 2328 |
% \end{macro} |
| 2329 |
% \end{macro} |
| 2330 |
% |
| 2331 |
% \begin{macro}{\@show@nonstop} |
| 2332 |
% \begin{macro}{\@show@typeout} |
| 2333 |
% And here some auxiliaries: |
| 2334 |
% \begin{description} |
| 2335 |
% \item[\cs{@show@nonstop}] same output as \cs{show}, but doesn't |
| 2336 |
% stop for interaction; |
| 2337 |
% \item[\cs{@show@typeout}] same output as \cs{showtokens}, but |
| 2338 |
% doesn't stop for interaction. |
| 2339 |
% \end{description} |
| 2340 |
% \begin{macrocode} |
| 2341 |
\def\@show@nonstop#1{% |
| 2342 |
\typeout{> \string#1=\@expl@cs@prefix@spec@@N#1macro:^^J% |
| 2343 |
\@expl@cs@parameter@spec@@N#1->\@expl@cs@replacement@spec@@N#1.}} |
| 2344 |
\def\@show@typeout#1{\typeout{> #1.^^J}} |
| 2345 |
% \end{macrocode} |
| 2346 |
% \end{macro} |
| 2347 |
% \end{macro} |
| 2348 |
% |
| 2349 |
% Now the rollback code. |
| 2350 |
% \begin{macrocode} |
| 2351 |
%</2ekernel|latexrelease> |
| 2352 |
%<latexrelease>\EndIncludeInRelease |
| 2353 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\ShowEnvironment} |
| 2354 |
%<latexrelease> {Undefine \ShowEnvironment}% |
| 2355 |
%<latexrelease>\let\ShowEnvironment\@undefined |
| 2356 |
%<latexrelease>\EndIncludeInRelease |
| 2357 |
%<*2ekernel> |
| 2358 |
% \end{macrocode} |
| 2359 |
% \end{macro} |
| 2360 |
% |
| 2361 |
% |
| 2362 |
% \subsection{Internal defining commands} |
| 2363 |
% |
| 2364 |
% These commands are used internally to define other \LaTeX{} |
| 2365 |
% commands. |
| 2366 |
% \begin{macro}{\@ifundefined} |
| 2367 |
% \changes{LaTeX2e}{1993/11/23}{Redefined to remove a trailing \cs{fi}} |
| 2368 |
% Check if first arg is undefined or \cs{relax} and execute second or |
| 2369 |
% third arg depending, |
| 2370 |
% \changes{1.5c}{2018/01/06}{Avoid defining undefined commands to \cs{relax}} |
| 2371 |
% \begin{macrocode} |
| 2372 |
%</2ekernel> |
| 2373 |
%<latexrelease>\IncludeInRelease{2018-04-01}{\@ifundefined} |
| 2374 |
%<latexrelease>{Leave commands undefined in \@ifundefined}% |
| 2375 |
%<*2ekernel|latexrelease> |
| 2376 |
% \end{macrocode} |
| 2377 |
% Version using |\ifcsname| to avoid defining undefined tokens to |\relax|. |
| 2378 |
% Defined here to simplify using unmatched |\fi|. |
| 2379 |
% \begin{macrocode} |
| 2380 |
\def\@ifundefined#1{% |
| 2381 |
\ifcsname#1\endcsname\@ifundefin@d@i\else\@ifundefin@d@ii\fi{#1}} |
| 2382 |
% \end{macrocode} |
| 2383 |
% \begin{macrocode} |
| 2384 |
\long\def\@ifundefin@d@i#1\fi#2{\fi |
| 2385 |
\expandafter\ifx\csname #2\endcsname\relax |
| 2386 |
\@ifundefin@d@ii |
| 2387 |
\fi |
| 2388 |
\@secondoftwo} |
| 2389 |
% \end{macrocode} |
| 2390 |
% \begin{macrocode} |
| 2391 |
\long\def\@ifundefin@d@ii\fi#1#2#3{\fi #2} |
| 2392 |
% \end{macrocode} |
| 2393 |
% Now test of engine. |
| 2394 |
% \begin{macrocode} |
| 2395 |
\ifx\numexpr\@undefined |
| 2396 |
% \end{macrocode} |
| 2397 |
% Classic version (should not be needed as etex is assumed). |
| 2398 |
% \begin{macrocode} |
| 2399 |
\def\@ifundefined#1{% |
| 2400 |
\expandafter\ifx\csname#1\endcsname\relax |
| 2401 |
\expandafter\@firstoftwo |
| 2402 |
\else |
| 2403 |
\expandafter\@secondoftwo |
| 2404 |
\fi} |
| 2405 |
\else\ifx\directlua\@undefined |
| 2406 |
% \end{macrocode} |
| 2407 |
% Use the |\ifcsname| defined above. |
| 2408 |
% \begin{macrocode} |
| 2409 |
\else |
| 2410 |
% \end{macrocode} |
| 2411 |
% Optimised version for Lua\TeX, using |\lastnamedcs| |
| 2412 |
% \begin{macrocode} |
| 2413 |
\def\@ifundefined#1{% |
| 2414 |
\ifcsname#1\endcsname |
| 2415 |
\expandafter\ifx\lastnamedcs\relax\else\@ifundefin@d@i\fi |
| 2416 |
\fi |
| 2417 |
\@firstoftwo} |
| 2418 |
% \end{macrocode} |
| 2419 |
% \begin{macrocode} |
| 2420 |
\long\def\@ifundefin@d@i#1#2#3#4#5{#1#2#5} |
| 2421 |
% \end{macrocode} |
| 2422 |
% \begin{macrocode} |
| 2423 |
\fi |
| 2424 |
\fi |
| 2425 |
%</2ekernel|latexrelease> |
| 2426 |
%<latexrelease>\EndIncludeInRelease |
| 2427 |
%<latexrelease>\IncludeInRelease{0000-00-00}{\@ifundefined} |
| 2428 |
%<latexrelease>{Leave commands undefined in \@ifundefined}% |
| 2429 |
%<latexrelease>\def\@ifundefined#1{% |
| 2430 |
%<latexrelease> \expandafter\ifx\csname#1\endcsname\relax |
| 2431 |
%<latexrelease> \expandafter\@firstoftwo |
| 2432 |
%<latexrelease> \else |
| 2433 |
%<latexrelease> \expandafter\@secondoftwo |
| 2434 |
%<latexrelease> \fi} |
| 2435 |
%<latexrelease>\EndIncludeInRelease |
| 2436 |
%<*2ekernel> |
| 2437 |
% \end{macrocode} |
| 2438 |
% \end{macro} |
| 2439 |
% |
| 2440 |
% |
| 2441 |
% \begin{macro}{\@qend} |
| 2442 |
% \begin{macro}{\@qrelax} |
| 2443 |
% The following define |\@qend| and |\@qrelax| to be the strings |
| 2444 |
% `|end|' and `|relax|' with the characters |\catcode|d 12. |
| 2445 |
% \begin{macrocode} |
| 2446 |
\edef\@qend{\expandafter\@cdr\string\end\@nil} |
| 2447 |
\edef\@qrelax{\expandafter\@cdr\string\relax\@nil} |
| 2448 |
% \end{macrocode} |
| 2449 |
% \end{macro} |
| 2450 |
% \end{macro} |
| 2451 |
% |
| 2452 |
% |
| 2453 |
% \begin{macro}{\@ifnextchar} |
| 2454 |
% \changes{LaTeX209}{1992/08/24} |
| 2455 |
% {(Rms) \cs{@ifnextchar} didn't work if its |
| 2456 |
% first argument was an equal sign.} |
| 2457 |
% \changes{v1.2q}{1995/10/02} |
| 2458 |
% {Use \cs{@let@token} } |
| 2459 |
% \changes{v1.3a}{1999/01/07} |
| 2460 |
% {made long} |
| 2461 |
% \changes{v1.3b}{1999/01/07} |
| 2462 |
% {extra \cs{long}. latex/2902} |
| 2463 |
% \changes{v1.3e}{1999/03/01} |
| 2464 |
% {remove extra \cs{long}. internal/2967} |
| 2465 |
% |\@ifnextchar| peeks at the following character and compares it |
| 2466 |
% with its first argument. If both are the same it executes its |
| 2467 |
% second argument, otherwise its third. |
| 2468 |
% \begin{macrocode} |
| 2469 |
\long\def\@ifnextchar#1#2#3{% |
| 2470 |
\let\reserved@d=#1% |
| 2471 |
\def\reserved@a{#2}% |
| 2472 |
\def\reserved@b{#3}% |
| 2473 |
\futurelet\@let@token\@ifnch} |
| 2474 |
% \end{macrocode} |
| 2475 |
% \end{macro} |
| 2476 |
% |
| 2477 |
% \begin{macro}{\kernel@ifnextchar} |
| 2478 |
% \changes{v1.3g}{2004/01/23}{Added macro (pr/3501)} |
| 2479 |
% This macro is the kernel version of |\@ifnextchar| which is used |
| 2480 |
% in a couple of places to prevent the AMS variant from being used |
| 2481 |
% since in some places this produced chaos. For example, |
| 2482 |
% if an \texttt{fd} file |
| 2483 |
% is loaded in a random place then the optional argument to |
| 2484 |
% |\ProvidesFile| could get printed there instead of being written |
| 2485 |
% only in the log file. This happened |
| 2486 |
% when there was a space or a newline between the mandatory and |
| 2487 |
% optional arguments! It should really be fixed in the |
| 2488 |
% \texttt{amsmath} package one day, but\ldots |
| 2489 |
% |
| 2490 |
% Note that there may be other places in the kernel where this version |
| 2491 |
% should be used rather than the original, but variable, version. |
| 2492 |
% |
| 2493 |
% \begin{macrocode} |
| 2494 |
\let\kernel@ifnextchar\@ifnextchar |
| 2495 |
% \end{macrocode} |
| 2496 |
% \end{macro} |
| 2497 |
% |
| 2498 |
% |
| 2499 |
% \begin{macro}{\@ifnch} |
| 2500 |
% |\@ifnch| is a tricky macro to skip any space tokens that may |
| 2501 |
% appear before the character in question. If it encounters a space |
| 2502 |
% token, it calls \@xifnch. |
| 2503 |
% \changes{v1.2q}{1995/10/02} |
| 2504 |
% {Use \cs{@let@token} for internal/924, save \cs{reserved@e}} |
| 2505 |
% \begin{macrocode} |
| 2506 |
\def\@ifnch{% |
| 2507 |
\ifx\@let@token\@sptoken |
| 2508 |
\let\reserved@c\@xifnch |
| 2509 |
\else |
| 2510 |
\ifx\@let@token\reserved@d |
| 2511 |
\let\reserved@c\reserved@a |
| 2512 |
\else |
| 2513 |
\let\reserved@c\reserved@b |
| 2514 |
\fi |
| 2515 |
\fi |
| 2516 |
\reserved@c} |
| 2517 |
% \end{macrocode} |
| 2518 |
% \end{macro} |
| 2519 |
% |
| 2520 |
% \begin{macro}{\@sptoken} |
| 2521 |
% The following code makes |\@sptoken| a space token. It is |
| 2522 |
% important here that the control sequence |\:| consists of |
| 2523 |
% a non-letter only, so that the following whitespace is |
| 2524 |
% significant. Together with the fact that the equal sign |
| 2525 |
% in a |\let| may be followed by only one optional space |
| 2526 |
% the desired effect is achieved. |
| 2527 |
% NOTE: the following hacking must precede the definition of |\:| |
| 2528 |
% as math medium space. |
| 2529 |
% \begin{macrocode} |
| 2530 |
\def\:{\let\@sptoken= } \: % this makes \@sptoken a space token |
| 2531 |
% \end{macrocode} |
| 2532 |
% \end{macro} |
| 2533 |
% |
| 2534 |
% \begin{macro}{\@xifnch} |
| 2535 |
% In the following definition of |\@xifnch|, |\:| is again used |
| 2536 |
% to get a space token as delimiter into the definition. |
| 2537 |
% \begin{macrocode} |
| 2538 |
\def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch} |
| 2539 |
% \end{macrocode} |
| 2540 |
% \end{macro} |
| 2541 |
% |
| 2542 |
% |
| 2543 |
% \begin{macro}{\@ifstar} |
| 2544 |
% \changes{v1.2u}{1995/10/16}{(DPC) New implementation, for /1910} |
| 2545 |
% The new implementation below avoids passing the \meta{true code} |
| 2546 |
% Through one more |\def| than the \meta{false code}, which previously |
| 2547 |
% meant that |#| had to be written as |####| in one argument, but |##| |
| 2548 |
% in the other. The |*| is gobbled by |\@firstoftwo|. |
| 2549 |
% \begin{macrocode} |
| 2550 |
\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}} |
| 2551 |
% \end{macrocode} |
| 2552 |
% \end{macro} |
| 2553 |
% |
| 2554 |
% \begin{macro}{\@dblarg} |
| 2555 |
% \begin{macro}{\@xdblarg} |
| 2556 |
% \changes{v1.1g}{2004/01/23}{Use kernel version of |
| 2557 |
% \cs{@ifnextchar} (pr/3501)} |
| 2558 |
% \begin{macrocode} |
| 2559 |
\long\def\@dblarg#1{\kernel@ifnextchar[{#1}{\@xdblarg{#1}}} |
| 2560 |
\long\def\@xdblarg#1#2{#1[{#2}]{#2}} |
| 2561 |
% \end{macrocode} |
| 2562 |
% \end{macro} |
| 2563 |
% \end{macro} |
| 2564 |
% |
| 2565 |
% \begin{macro}{\@sanitize} |
| 2566 |
% The command |\@sanitize| changes the catcode of all special characters |
| 2567 |
% except for braces to `other'. It can be used for commands like |
| 2568 |
% |\index| that want to write their arguments verbatim. Needless to |
| 2569 |
% say, this command should only be executed within a group, or chaos |
| 2570 |
% will ensue. |
| 2571 |
% |
| 2572 |
% \begin{macrocode} |
| 2573 |
\def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&% |
| 2574 |
\@makeother\#\@makeother\^\@makeother\_\@makeother\%\@makeother\~} |
| 2575 |
% \end{macrocode} |
| 2576 |
% \end{macro} |
| 2577 |
% |
| 2578 |
% \begin{macro}{\@onelevel@sanitize} |
| 2579 |
% \changes{v1.2c}{1994/10/30}{Macro added} |
| 2580 |
% |
| 2581 |
% This makes the whole ``meaning'' of |#1| (its one-level |
| 2582 |
% expansion) into catcode 12 tokens: it could be used in |
| 2583 |
% |\DeclareRobustCommand|. |
| 2584 |
% |
| 2585 |
% If it is to be used on default float specifiers, this should be |
| 2586 |
% done when they are defined. |
| 2587 |
% \begin{macrocode} |
| 2588 |
\def \@onelevel@sanitize #1{% |
| 2589 |
\edef #1{\expandafter\strip@prefix |
| 2590 |
\meaning #1}% |
| 2591 |
} |
| 2592 |
% \end{macrocode} |
| 2593 |
% \end{macro} |
| 2594 |
% |
| 2595 |
% |
| 2596 |
% \begin{macro}{\string@makeletter} |
| 2597 |
% \begin{macro}{\@string@makeletter} |
| 2598 |
% \begin{macro}{\char@if@alph} |
| 2599 |
% Iterates through a string, turning each alphabetic character into |
| 2600 |
% a catcode-11 token (partly undoes a \cs{detokenize}). Useful for |
| 2601 |
% \cs{ifx}-based string comparisons where \cs{detokenize}-ing the |
| 2602 |
% other string would break too much code. |
| 2603 |
% |
| 2604 |
% \changes{v1.5n}{2020/09/06} |
| 2605 |
% {Macro added} |
| 2606 |
% |
| 2607 |
% The macro uses \textsf{expl3}'s \cs{@expl@str@map@function@@NN} to |
| 2608 |
% iterate on the string (without losing spaces) and applies |
| 2609 |
% \cs{@string@makeletter} on each character. The latter checks if |
| 2610 |
% character is between a--z or A--Z, and uses \cs{@alph} or \cs{@Alph} |
| 2611 |
% to get the corresponding catcode-11 token. Other tokens are passed |
| 2612 |
% through unchanged. |
| 2613 |
% \begin{macrocode} |
| 2614 |
%</2ekernel> |
| 2615 |
%<latexrelease>\IncludeInRelease{2020/10/01}{\string@makeletter} |
| 2616 |
%<latexrelease> {Add \string@makeletter}% |
| 2617 |
%<*2ekernel|latexrelease> |
| 2618 |
\def\string@makeletter#1{% |
| 2619 |
\@expl@str@map@function@@NN#1\@string@makeletter} |
| 2620 |
\def\@string@makeletter#1{% |
| 2621 |
\char@if@alph{#1}% |
| 2622 |
{\@expl@char@generate@@nn{`#1}{11}}% |
| 2623 |
{#1}} |
| 2624 |
\def\char@if@alph#1{% |
| 2625 |
\ifnum0\ifnum`#1<`A 1\fi\ifnum`#1>`z 1\fi |
| 2626 |
\if\ifnum`#1>`Z @\fi\ifnum`#1<`a @\fi01\fi>0 |
| 2627 |
\expandafter\@secondoftwo |
| 2628 |
\else |
| 2629 |
\expandafter\@firstoftwo |
| 2630 |
\fi} |
| 2631 |
%</2ekernel|latexrelease> |
| 2632 |
%<latexrelease>\EndIncludeInRelease |
| 2633 |
% |
| 2634 |
%<latexrelease>\IncludeInRelease{0000/00/00}{\string@makeletter} |
| 2635 |
%<latexrelease> {Undefine \string@makeletter}% |
| 2636 |
%<latexrelease>\let\string@makeletter\@undefined |
| 2637 |
%<latexrelease>\let\@string@makeletter\@undefined |
| 2638 |
%<latexrelease>\let\char@if@alph\@undefined |
| 2639 |
%<latexrelease>\EndIncludeInRelease |
| 2640 |
%<*2ekernel> |
| 2641 |
% \end{macrocode} |
| 2642 |
% \end{macro} |
| 2643 |
% \end{macro} |
| 2644 |
% \end{macro} |
| 2645 |
% |
| 2646 |
% |
| 2647 |
% \begin{macro}{\makeatletter} |
| 2648 |
% \begin{macro}{\makeatother} |
| 2649 |
% \changes{v1.0n}{1994/05/10}{Added \cs{makeatletter} and |
| 2650 |
% \cs{makeatother} ASAJ.} |
| 2651 |
% Make internal control sequences accessible or inaccessible. |
| 2652 |
% \begin{macrocode} |
| 2653 |
\DeclareRobustCommand\makeatletter{\catcode`\@11\relax} |
| 2654 |
\DeclareRobustCommand\makeatother{\catcode`\@12\relax} |
| 2655 |
% \end{macrocode} |
| 2656 |
% \end{macro} |
| 2657 |
% \end{macro} |
| 2658 |
% |
| 2659 |
% |
| 2660 |
% \section{Discretionary Hyphenation} |
| 2661 |
% \begin{macro}{\-} |
| 2662 |
% \changes{1.2x}{1995/12/13}{Documentation changed.} |
| 2663 |
% \changes{v1.5a}{2017/03/13}{Define \cs{-} in terms of \cs{hyphenchar}} |
| 2664 |
% \begin{macro}{\@dischyph} |
| 2665 |
% \changes{v1.0g}{1994/04/12} |
| 2666 |
% {Define \cs{@dischyph}, was previously in ltboxes.dtx} |
| 2667 |
% \changes{v1.5b}{2017/03/27}{Define \cs{@dischyph} after \cs{-}} |
| 2668 |
% \changes{v1.5j}{2020/05/11}{Do not overwrite \cs{-} under Lua\TeX} |
| 2669 |
% \end{macro} |
| 2670 |
% Moved here to be after the definition of |\DeclareRobustCommand|. |
| 2671 |
% |
| 2672 |
% The primitive |\-| command adds a discretionary hyphen using the |
| 2673 |
% current font's |\hyphenchar|. Monospace fonts are usually declared |
| 2674 |
% with |\hyphenchar| set to $-1$ to suppress hyphenation. |
| 2675 |
% |
| 2676 |
% \LaTeX, from \LaTeX2.09 in 1986 defined |\-| by |
| 2677 |
% \begin{verbatim} |
| 2678 |
% \def\-{\discretionary{-}{}{}} |
| 2679 |
% \end{verbatim} |
| 2680 |
% The following comment was added when these commands were first set |
| 2681 |
% up, 19 April 1986: |
| 2682 |
% \begin{quote} |
| 2683 |
% the |\-| command is redefined to allow it to work in the |\ttfamily| |
| 2684 |
% type style, where automatic hyphenation is suppressed by setting |
| 2685 |
% |\hyphenchar| to~$-1$. The original primitive \TeX{} definition is |
| 2686 |
% saved as |\@@hyph| just in case anyone needs it. |
| 2687 |
% \end{quote} |
| 2688 |
% |
| 2689 |
% \LaTeXe, between 1993 and 2017, had a comment at this point |
| 2690 |
% saying that the definition ``would probably change'' because |
| 2691 |
% the definition always uses |-|. The definition used below |
| 2692 |
% was given in comments at this point during time. |
| 2693 |
% |
| 2694 |
% In 2017 we finally enabled this definition by default, with the |
| 2695 |
% older \LaTeX\ definition accessible via \textsf{latexrelease} |
| 2696 |
% as usual. |
| 2697 |
% |
| 2698 |
% In Lua\LaTeX\ the primitive definition of \cs{-} is used directly |
| 2699 |
% because it's use of extended hyphenation parameters means that \cs{-} |
| 2700 |
% works correctly even with \cs{hyphenchar} set to $-1$. This change |
| 2701 |
% makes \cs{-} under Lua\LaTeX\ compatible with language specific |
| 2702 |
% hyphenation characters. |
| 2703 |
% |
| 2704 |
% Temporary definition of |\@latex@info|, final definition is later. |
| 2705 |
% \begin{macrocode} |
| 2706 |
\def\@latex@info#1{} |
| 2707 |
% \end{macrocode} |
| 2708 |
% |
| 2709 |
% \begin{macrocode} |
| 2710 |
%</2ekernel> |
| 2711 |
%<latexrelease>\IncludeInRelease{2020/10/01}{\-}{Use primitive \- in Lua\LaTeX}% |
| 2712 |
%<*2ekernel|latexrelease> |
| 2713 |
\ifx\directlua\@undefined |
| 2714 |
\DeclareRobustCommand{\-}{% |
| 2715 |
\discretionary{% |
| 2716 |
\char \ifnum\hyphenchar\font<\z@ |
| 2717 |
\defaulthyphenchar |
| 2718 |
\else |
| 2719 |
\hyphenchar\font |
| 2720 |
\fi |
| 2721 |
}{}{}% |
| 2722 |
} |
| 2723 |
\else |
| 2724 |
\let\-\@@hyph |
| 2725 |
\fi |
| 2726 |
%</2ekernel|latexrelease> |
| 2727 |
%<latexrelease>\EndIncludeInRelease |
| 2728 |
%<latexrelease>\IncludeInRelease{2017/04/15}{\-}{Use \hyphenchar in \-}% |
| 2729 |
%<latexrelease>\DeclareRobustCommand{\-}{% |
| 2730 |
%<latexrelease> \discretionary{% |
| 2731 |
%<latexrelease> \char \ifnum\hyphenchar\font<\z@ |
| 2732 |
%<latexrelease> \defaulthyphenchar |
| 2733 |
%<latexrelease> \else |
| 2734 |
%<latexrelease> \hyphenchar\font |
| 2735 |
%<latexrelease> \fi |
| 2736 |
%<latexrelease> }{}{}% |
| 2737 |
%<latexrelease>} |
| 2738 |
%<latexrelease>\EndIncludeInRelease |
| 2739 |
%<latexrelease>\IncludeInRelease{0000/00/00}{\-}{Use \hyphenchar in \-}% |
| 2740 |
%<latexrelease>\def\-{\discretionary{-}{}{}} |
| 2741 |
%<latexrelease>\EndIncludeInRelease |
| 2742 |
% \end{macrocode} |
| 2743 |
% |
| 2744 |
% \begin{macrocode} |
| 2745 |
%<*2ekernel|latexrelease> |
| 2746 |
\let\@dischyph=\- |
| 2747 |
%</2ekernel|latexrelease> |
| 2748 |
%<*2ekernel> |
| 2749 |
% \end{macrocode} |
| 2750 |
% \end{macro} |
| 2751 |
% |
| 2752 |
% Delayed from |ltvers.dtx| |
| 2753 |
% \begin{macrocode} |
| 2754 |
\newif\if@includeinrelease |
| 2755 |
\@includeinreleasefalse |
| 2756 |
% \end{macrocode} |
| 2757 |
% |
| 2758 |
% \changes{v1.5f}{2019/08/27}{Make various commands robust} |
| 2759 |
% |
| 2760 |
% Delayed from |ltplain.dtx| |
| 2761 |
% \begin{macrocode} |
| 2762 |
%</2ekernel> |
| 2763 |
%<*2ekernel|latexrelease> |
| 2764 |
%<latexrelease>\IncludeInRelease{2019/10/01}% |
| 2765 |
%<latexrelease> {\allowbreak}{Make various commands robust}% |
| 2766 |
\MakeRobust\allowbreak |
| 2767 |
\MakeRobust\bigbreak |
| 2768 |
\MakeRobust\break |
| 2769 |
\MakeRobust\dotfill |
| 2770 |
\MakeRobust\frenchspacing |
| 2771 |
\MakeRobust\goodbreak |
| 2772 |
\MakeRobust\hrulefill |
| 2773 |
\MakeRobust\medbreak |
| 2774 |
\MakeRobust\nobreak |
| 2775 |
\MakeRobust\nonfrenchspacing |
| 2776 |
\MakeRobust\obeylines |
| 2777 |
\MakeRobust\obeyspaces |
| 2778 |
\MakeRobust\slash |
| 2779 |
\MakeRobust\smallbreak |
| 2780 |
\MakeRobust\strut |
| 2781 |
\MakeRobust\underbar |
| 2782 |
%</2ekernel|latexrelease> |
| 2783 |
%<latexrelease>\EndIncludeInRelease |
| 2784 |
%<latexrelease>\IncludeInRelease{0000/00/00}% |
| 2785 |
%<latexrelease> {\allowbreak}{Make various commands robust}% |
| 2786 |
%<latexrelease> |
| 2787 |
%<latexrelease>\kernel@make@fragile\allowbreak |
| 2788 |
%<latexrelease>\kernel@make@fragile\bigbreak |
| 2789 |
%<latexrelease>\kernel@make@fragile\break |
| 2790 |
%<latexrelease>\kernel@make@fragile\dotfill |
| 2791 |
%<latexrelease>\kernel@make@fragile\frenchspacing |
| 2792 |
%<latexrelease>\kernel@make@fragile\goodbreak |
| 2793 |
%<latexrelease>\kernel@make@fragile\hrulefill |
| 2794 |
%<latexrelease>\kernel@make@fragile\medbreak |
| 2795 |
%<latexrelease>\kernel@make@fragile\nobreak |
| 2796 |
%<latexrelease>\kernel@make@fragile\nonfrenchspacing |
| 2797 |
%<latexrelease>\kernel@make@fragile\obeylines |
| 2798 |
%<latexrelease>\kernel@make@fragile\obeyspaces |
| 2799 |
%<latexrelease>\kernel@make@fragile\slash |
| 2800 |
%<latexrelease>\kernel@make@fragile\smallbreak |
| 2801 |
%<latexrelease>\kernel@make@fragile\strut |
| 2802 |
%<latexrelease>\kernel@make@fragile\underbar |
| 2803 |
%<latexrelease> |
| 2804 |
%<latexrelease>\EndIncludeInRelease |
| 2805 |
%<*2ekernel> |
| 2806 |
% \end{macrocode} |
| 2807 |
% |
| 2808 |
% |
| 2809 |
% \begin{macro}{\g@addto@macro} |
| 2810 |
% Globally add to the end of a macro. |
| 2811 |
% This macro is used by the kernel to add to its internal hooks. |
| 2812 |
% \changes{v0.2a}{1993/11/14}{Made global} |
| 2813 |
% \changes{v0.2w}{1994/01/31} |
| 2814 |
% {Use toks register to avoid `hash' problems} |
| 2815 |
% \changes{v1.0o}{1995/05/17} |
| 2816 |
% {Make long for latex/1522} |
| 2817 |
% \changes{v1.0w}{1996/12/17} |
| 2818 |
% {Use \cs{begingroup} to save making a mathord} |
| 2819 |
% \changes{v1.0x}{1997/02/05} |
| 2820 |
% {missing percent /2402} |
| 2821 |
% \begin{macrocode} |
| 2822 |
\long\def\g@addto@macro#1#2{% |
| 2823 |
\begingroup |
| 2824 |
\toks@\expandafter{#1#2}% |
| 2825 |
\xdef#1{\the\toks@}% |
| 2826 |
\endgroup} |
| 2827 |
% \end{macrocode} |
| 2828 |
% \end{macro} |
| 2829 |
% |
| 2830 |
% |
| 2831 |
% \begin{macrocode} |
| 2832 |
%</2ekernel> |
| 2833 |
% \end{macrocode} |
| 2834 |
% |
| 2835 |
% |
| 2836 |
% \Finale |
| 2837 |
% |