[latex3-commits] [git/LaTeX3-latex3-latex2e] gh373: Adapt \NewCommandCopy to 1f8fc25 (78cf0c85)
PhelypeOleinik
tex.phelype at gmail.com
Thu Aug 20 03:12:26 CEST 2020
Repository : https://github.com/latex3/latex2e
On branch : gh373
Link : https://github.com/latex3/latex2e/commit/78cf0c85db0ff3a82fd5e637923fec8c524da7c2
>---------------------------------------------------------------
commit 78cf0c85db0ff3a82fd5e637923fec8c524da7c2
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date: Wed Aug 19 22:12:26 2020 -0300
Adapt \NewCommandCopy to 1f8fc25
>---------------------------------------------------------------
78cf0c85db0ff3a82fd5e637923fec8c524da7c2
base/ltdefns.dtx | 55 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 43 insertions(+), 12 deletions(-)
diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index 69de4397..cb319331 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1406,6 +1406,23 @@
% \end{macro}
% \end{macro}
%
+%
+% \subsubsection{Copying robust commands}
+%
+% \begin{macrocode}
+%</2ekernel>
+%<latexrelease>\IncludeInRelease{2020-10-01}{\DeclareCommandCopy}
+%<latexrelease> {Add \NewCommandCopy, \RenewCommandCopy, and \DeclareCommandCopy}%
+%<*2ekernel|latexrelease>
+% \end{macrocode}
+%
+% \begin{macro}{\NewCommandCopy}
+% \begin{macro}{\RenewCommandCopy}
+% \begin{macro}{\DeclareCommandCopy}
+% \changes{v1.5j}{2020/05/09}{Added \cs{DeclareCommandCopy} (gh/239)}
+%
+% \cs{NewCommandCopy} starts by checking if \verb=#1= is already defined, and
+% raises an error if so, otherwise the definition is carried out.
% \cs{RenewCommandCopy} does (almost) the opposite. If the command is
% \emph{not} defined, then an error is raised. But the definition is carried
% out anyhow, so the behaviour is consistent with \cs{renewcommand}.
@@ -1418,22 +1435,27 @@
% redefine it later, while preserving the old definition, as in:
% \begin{verbatim}
% \ProvideComandCopy \A \B
-% \renewcommand \B { ... \A ...}
+% \renewcommand \B { ... \A ... }
% \end{verbatim}
% then, if \verb=\A= is already defined the first line is skipped, an in this
% case \verb=\B= won't work as expected.
+%
+% The three versions call the internal \cs{declare at commandcopy} with the
+% proper action. \cs{@firstofone} will carry out the copy. The only case
+% when the copy is not made is the \meta{false} case for \cs{NewCommandCopy},
+% in which the command already exists and the definition is aborted.
% \begin{macrocode}
\def\NewCommandCopy{%
- \declare at commandcopy%
+ \declare at commandcopy
{\@firstofone}%
{\@firstoftwo\@notdefinable}}
\def\RenewCommandCopy{%
- \declare at commandcopy%
+ \declare at commandcopy
{\@latex at error{Command \@backslashchar\reserved at a\space undefined}\@ehc
\@firstofone}%
{\@firstofone}}
\def\DeclareCommandCopy{%
- \declare at commandcopy%
+ \declare at commandcopy
{\@firstofone}%
{\@firstofone}}
% \end{macrocode}
@@ -1441,20 +1463,20 @@
% \begin{macro}{\declare at commandcopy}
% 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{declare at command@copy} is called with the command being defined and the
-% command being copied.
+% \cs{robust at command@act} is called with the proper arguments as described
+% earlier, with \cs{@declarecommandcopylisthook} as the \meta{action-list} and
+% \cs{declare at commandcopy@let} as the \meta{fallback-action}.
% \begin{macrocode}
\def\declare at commandcopy#1#2#3#4{%
\edef\reserved at a{\@expl at cs@to at str@@N#3}%
\@ifundefined\reserved at a{#1}{#2}%
- {\declare at command@copy#3#4}}
+ {\robust at command@act
+ \@declarecommandcopylisthook#4%
+ \declare at commandcopy@let{#3#4}}}
% \end{macrocode}
+% \end{macro}
%
% \begin{macro}{\@declarecommandcopylisthook}
-% \begin{macro}{\NewCommandCopy}
-% \begin{macro}{\RenewCommandCopy}
-% \begin{macro}{\DeclareCommandCopy}
-% \changes{v1.5j}{2020/05/09}{Added \cs{DeclareCommandCopy} (gh/239)}
% The initial definition of \cs{@declarecommandcopylisthook} contains the
% tests for the two types of robust command in the kernel.
% \begin{macrocode}
@@ -1462,6 +1484,15 @@
{\@if at DeclareRobustCommand \@copy at DeclareRobustCommand}%
{\@if at newcommand \@copy at newcommand}}
% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\declare at commandcopy@let}
+% The initial definition of \cs{@declarecommandcopylisthook} contains the
+% tests for the two types of robust command in the kernel.
+% \begin{macrocode}
+\def\declare at commandcopy@let#1#2{\let#1=#2\relax}
+% \end{macrocode}
+% \end{macro}
%
% Now the rollback code.
% \begin{macrocode}
@@ -1563,7 +1594,7 @@
\def\copy at kernel@robust at command#1#2{%
\@if at newcommand#2%
{\@copy at newcommand#1#2}%
- {\declare at command@copy at let#1#2}}
+ {\declare at commandcopy@let#1#2}}
% \end{macrocode}
%
% \begin{macro}{\@if at newcommand}
More information about the latex3-commits
mailing list.