summaryrefslogtreecommitdiff
path: root/macros/latex-dev/base/ltdefns.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex-dev/base/ltdefns.dtx')
-rw-r--r--macros/latex-dev/base/ltdefns.dtx226
1 files changed, 209 insertions, 17 deletions
diff --git a/macros/latex-dev/base/ltdefns.dtx b/macros/latex-dev/base/ltdefns.dtx
index bd820e7cf2..c604bd9620 100644
--- a/macros/latex-dev/base/ltdefns.dtx
+++ b/macros/latex-dev/base/ltdefns.dtx
@@ -32,7 +32,7 @@
%<*driver>
% \fi
\ProvidesFile{ltdefns.dtx}
- [2022/05/22 v1.5r LaTeX Kernel (definition commands)]
+ [2022/11/24 v1.5s LaTeX Kernel (definition commands)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltdefns.dtx}
@@ -784,7 +784,9 @@
% not take arguments. (but may contain |\par|s)
%
% Make sure that an attempt to define a `graf' or `group' environment
-% fails.
+% fails by temporarily letting the undefined \verb=\...= (begin code) to
+% the definition of \verb=\end...= and as a result we get an error if that
+% has a definition.
% \begin{macrocode}
\long\def\@newenv#1#2#3#4{%
\@ifundefined{#1}%
@@ -1641,6 +1643,7 @@
% \end{macrocode}
%
% \begin{macro}{\declare@commandcopy}
+% \begin{macro}{\declare@commandcopy@do}
% Start by checking if the command is already defined. The proper action is
% taken by each specific command above. If all's good, then
% \cs{robust@command@act} is called with the proper arguments as described
@@ -1650,11 +1653,14 @@
\long\def\declare@commandcopy#1#2#3#4{%
\edef\reserved@a{\@expl@cs@to@str@@N#3}%
\@ifundefined\reserved@a{#1}{#2}%
- {\robust@command@act
- \@declarecommandcopylisthook#4%
- \declare@commandcopy@let{#3#4}}}
+ {\declare@commandcopy@do{#3}{#4}}}
+\long\def\declare@commandcopy@do#1#2{%
+ \robust@command@act
+ \@declarecommandcopylisthook#2%
+ \declare@commandcopy@let{#1#2}}
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
% \begin{macro}{\@declarecommandcopylisthook}
% The initial definition of \cs{@declarecommandcopylisthook} contains the
@@ -1694,6 +1700,64 @@
% \end{macro}
%
%
+% \begin{macrocode}
+%</2ekernel>
+%<latexrelease>\IncludeInRelease{2023-06-01}{\DeclareEnvironmentCopy}
+%<latexrelease> {Add \NewEnvironmentCopy, \RenewEnvironmentCopy, and \DeclareEnvironmentCopy}%
+%<*2ekernel|latexrelease>
+% \end{macrocode}
+%
+% \begin{macro}{\NewEnvironmentCopy}
+% \begin{macro}{\RenewEnvironmentCopy}
+% \begin{macro}{\DeclareEnvironmentCopy}
+% If \verb=\#1= or \verb=\end#1= already exist one gets an error
+% message talking about the problematical command (not the
+% environment).
+% The remainder of the \LaTeX{} run is probably badly
+% broken and it is unlikely that continuing it gives
+% reasonable results.
+% \changes{v1.5s}{2022/11/24}{Add \cs{NewEnvironmentCopy},
+% \cs{RenewEnvironmentCopy}, and \cs{DeclareEnvironmentCopy} (gh/963)}
+% \begin{macrocode}
+\def\NewEnvironmentCopy{%
+ \declare@environmentcopy
+ {\@firstofone}%
+ {\@firstoftwo\@notdefinable}}
+\def\RenewEnvironmentCopy{%
+ \declare@environmentcopy
+ {\@latex@error{Environment \reserved@a\space undefined}\@ehc
+ \@firstofone}%
+ {\@firstofone}}
+\def\DeclareEnvironmentCopy{%
+ \declare@environmentcopy
+ {\@firstofone}%
+ {\@firstofone}}
+\long\def\declare@environmentcopy#1#2#3#4{%
+ \edef\reserved@a{\@ifundefined{#3}{end#3}{#3}}%
+ \@ifundefined\reserved@a
+ {\def\reserved@a{#3}#1}%
+ {\def\reserved@a{#3}#2}%
+ {\ExpandArgs{cc}\declare@commandcopy@do{#3}{#4}%
+ \ExpandArgs{cc}\declare@commandcopy@do{end#3}{end#4}}}
+% \end{macrocode}
+%
+% Now the rollback code.
+% \begin{macrocode}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000-00-00}{\DeclareEnvironmentCopy}
+%<latexrelease> {Undefine \NewEnvironmentCopy, \RenewEnvironmentCopy, and \DeclareEnvironmentCopy}%
+%<latexrelease>\let\NewEnvironmentCopy\@undefined
+%<latexrelease>\let\RenewEnvironmentCopy\@undefined
+%<latexrelease>\let\DeclareEnvironmentCopy\@undefined
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+%
% \subsubsection{Showing robust commands}
%
% \begin{macro}{\ShowCommand}
@@ -1747,7 +1811,6 @@
% \end{macrocode}
% \end{macro}
%
-%
% \begin{macrocode}
%</2ekernel>
%<latexrelease>\IncludeInRelease{2020-10-01}{\@if@DeclareRobustCommand}
@@ -1836,6 +1899,7 @@
%
% \begin{macro}{\@show@DeclareRobustCommand}
% \begin{macro}{\show@kernel@robust@command}
+% \begin{macro}{\@show@macro}
% Showing the command is pretty simple. This command prints the top-level
% expansion as \TeX's \cs{show} would, but with |robust macro:| rather than
% just |macro:|, then a blank line and then \cs{show} the inner command.
@@ -1863,12 +1927,14 @@
\robust@command@chk@safe#1%
{\@if@newcommand#1%
{\@show@newcommand}%
- {\show}}%
- {\show}%
+ {\@show@macro}}%
+ {\@show@macro}%
#1}
+\let\@show@macro\show
% \end{macrocode}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \end{macro}
%
@@ -1931,7 +1997,7 @@
\typeout{->\@expl@cs@replacement@spec@@N#1.^^J}%
\expandafter\@show@newcommand@aux
\csname\@backslashchar\@expl@cs@to@str@@N#1\expandafter\endcsname
- \expandafter{#1}}
+ \expandafter{#1}\@show@tokens}
% \end{macrocode}
%
% For a macro defined with, say, |\newcommand\foo[1][opt]{bar}|, it will
@@ -1946,20 +2012,28 @@
% \end{verbatim}
% If the command was defined with \cs{DeclareRobustCommand}, then another pair
% of lines show the top-level expansion \verb*|\protect \foo |.
-%
-% The extra gymnastics with \cs{showtokens} ensures that \cs{showtokens}
-% itself, and the internals of this macro aren't showed in the context lines.
% \begin{macrocode}
-\long\def\@show@newcommand@aux#1#2{%
+\long\def\@show@newcommand@aux#1#2#3{%
\typeout{> \string#1=\@expl@cs@prefix@spec@@N#1macro:}%
- \edef\reserved@a{%
- default \string##1=\expandafter\detokenize\@gobblethree#2.^^J%
- \@expl@cs@argument@spec@@N#1->\@expl@cs@replacement@spec@@N#1}%
- \showtokens\expandafter\expandafter\expandafter{\expandafter\reserved@a}}
+ #3{default \string##1=\expandafter\detokenize\@gobblethree#2.^^J%
+ \@expl@cs@argument@spec@@N#1->\@expl@cs@replacement@spec@@N#1}}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\@show@tokens}
+% This macro prints the contents of the token list (macro) |#1| using
+% \cs{showtokens}. The \cs{expandafter} gymnastics ensures that
+% \cs{showtokens} itself, and the internals of this macro aren't
+% showed in the context lines.
+% \begin{macrocode}
+\long\def\@show@tokens#1{%
+ \edef\reserved@a{#1}%
+ \showtokens\expandafter
+ \expandafter\expandafter{\expandafter\reserved@a}}
+% \end{macrocode}
+% \end{macro}
+%
% Now the rollback code.
% \begin{macrocode}
%</2ekernel|latexrelease>
@@ -1985,6 +2059,124 @@
% \end{macro}
%
%
+% \subsubsection{Showing environments}
+%
+% \begin{macro}{\ShowEnvironment}
+% \changes{v1.5s}{2022/11/24}{Added \cs{ShowEnvironment}}
+%
+% \begin{macrocode}
+%</2ekernel>
+%<latexrelease>\IncludeInRelease{2023-06-01}{\ShowEnvironment}
+%<latexrelease> {Add \ShowEnvironment}%
+%<*2ekernel|latexrelease>
+% \end{macrocode}
+%
+% \cs{ShowEnvironment} is quite similar to \cs{ShowCommand}. We will
+% pass the environment \meta{env} around as the macro
+% \cs[no-index]{env}, because \cs{robust@command@act} expects a single
+% token.
+% \begin{macrocode}
+\def\ShowEnvironment#1{%
+ \expandafter\@show@environment\csname #1\endcsname}
+\long\def\@show@environment#1{%
+ \robust@command@act
+ \@showenvironmentlisthook#1%
+ \@show@normalenv#1}
+% \end{macrocode}
+%
+% \begin{macro}{\@showenvironmentlisthook}
+% This is similar to \cs{@showcommandlisthook}, but uses the dedicated
+% versions for environments.
+% \begin{macrocode}
+\def\@showenvironmentlisthook{%
+ {\@if@DeclareRobustCommand \@show@DeclareRobustCommand@env}%
+ {\@if@newcommand \@show@newcommand@env}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@show@newcommand@env}
+% \begin{macro}{\@show@DeclareRobustCommand@env}
+% These are similar to the command versions below, except they say
+% \enquote{environment} and call \cs{@show@environment@end} to print
+% the \cs{end} part.
+% \begin{macrocode}
+\long\def\@show@newcommand@env#1{%
+ \@show@environment@begin#1%
+ \expandafter\@show@newcommand@aux
+ \csname\@backslashchar\@expl@cs@to@str@@N#1\expandafter\endcsname
+ \expandafter{#1}\@show@typeout
+ \@show@environment@end#1}
+\long\def\@show@DeclareRobustCommand@env#1{%
+ \@show@environment@begin#1%
+ \begingroup
+ \let\@show@tokens\@show@typeout
+ \let\@show@macro\@show@nonstop
+ \expandafter\show@kernel@robust@command
+ \csname\@expl@cs@to@str@@N#1 \endcsname
+ \endgroup
+ \@show@environment@end#1}
+\long\def\@show@environment@begin#1{%
+ \typeout{> \string\begin{\@expl@cs@to@str@@N#1}=environment:}%
+ \typeout{\@expl@cs@argument@spec@@N#1->%
+ \@expl@cs@replacement@spec@@N#1.^^J}}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@show@normalenv}
+% \begin{macro}{\@show@environment@end}
+% A \enquote{normal} environment is straightforward.
+% \cs{@show@environment@end} needs to check if the \cs{end} part is
+% defined and show it accordingly, otherwise the output would show
+% gibberish.
+% \begin{macrocode}
+\long\def\@show@normalenv#1{%
+ \@show@environment@begin#1%
+ \@show@environment@end#1}
+\long\def\@show@environment@end#1{%
+ \expandafter\@show@environment@end@aux
+ \csname end\@expl@cs@to@str@@N#1\endcsname#1}
+\long\def\@show@environment@end@aux#1#2{%
+ \@show@tokens{\string\end{\@expl@cs@to@str@@N#2}%
+ \ifx\relax#1=undefined%
+ \else:^^J\@expl@cs@argument@spec@@N#1->%
+ \@expl@cs@replacement@spec@@N#1%
+ \fi}}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@show@nonstop}
+% \begin{macro}{\@show@typeout}
+% And here some auxiliaries:
+% \begin{description}
+% \item[\cs{@show@nonstop}] same output as \cs{show}, but doesn't
+% stop for interaction;
+% \item[\cs{@show@typeout}] same output as \cs{showtokens}, but
+% doesn't stop for interaction.
+% \end{description}
+% \begin{macrocode}
+\def\@show@nonstop#1{%
+ \typeout{> \string#1=\@expl@cs@prefix@spec@@N#1macro:^^J%
+ \@expl@cs@argument@spec@@N#1->\@expl@cs@replacement@spec@@N#1.}}
+\def\@show@typeout#1{\typeout{> #1.^^J}}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% Now the rollback code.
+% \begin{macrocode}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000-00-00}{\ShowEnvironment}
+%<latexrelease> {Undefine \ShowEnvironment}%
+%<latexrelease>\let\ShowEnvironment\@undefined
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
+% \end{macrocode}
+% \end{macro}
+%
+%
% \subsection{Internal defining commands}
%
% These commands are used internally to define other \LaTeX{}