[latex3-commits] [git/LaTeX3-latex3-latex2e] gh373: Make \robust at command@act generic to be used with \ShowCommand (1f8fc25c)

PhelypeOleinik tex.phelype at gmail.com
Thu Aug 20 03:06:34 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : gh373
Link       : https://github.com/latex3/latex2e/commit/1f8fc25cfd2787dc02e07ad37bdd8d9fdbf30a16

>---------------------------------------------------------------

commit 1f8fc25cfd2787dc02e07ad37bdd8d9fdbf30a16
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Wed Aug 19 22:06:34 2020 -0300

    Make \robust at command@act generic to be used with \ShowCommand


>---------------------------------------------------------------

1f8fc25cfd2787dc02e07ad37bdd8d9fdbf30a16
 base/ltdefns.dtx | 159 +++++++++++++++++++++++++++----------------------------
 1 file changed, 78 insertions(+), 81 deletions(-)

diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index 8aabd24f..69de4397 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1286,7 +1286,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \subsection{Acting on robust definitions}
+% \subsection{Acting on robust commands}
 %
 %   With most document level commands being robust now there is more of a
 %   requirement to have a standard way of aliasing (or copying) a command to a
@@ -1309,11 +1309,19 @@
 %   that definition, if \cs{DeclareCommandCopy} (or similar) is used, or show
 %   the definition of the command, if \cs{ShowCommmand} is used.
 %
+% \begin{macro}{\robust at command@act}
+% \begin{macro}{\robust at command@act at loop}
+% \begin{macro}{\robust at command@act at loop@aux}
+% \begin{macro}{\robust at command@act at do}
+% \begin{macro}{\robust at command@act at end}
+% \changes{v1.5k}{2020/08/19}{Made \cs{robust at command@act}
+%     (was \cs{declare at command@copy}) more generic}
+%
 %   The looping machinery is generic and knows nothing about what is to be done
 %   for each case.  The syntax of the main macro \cs{robust at command@act} is:
 %   \begin{quote}
-%     |\robust at command@act|\meta{action-list}\meta{fallback-action}\\
-%       \meta{robust-cmd}\meta{act-arg}
+%     |\robust at command@act|\meta{action-list}\meta{robust-cmd}\\
+%       \meta{fallback-action}\meta{act-arg}
 %   \end{quote}
 %   \meta{action-list} is a token list of the form:
 %   \begin{quote}
@@ -1331,8 +1339,73 @@
 %   \meta{fallback-action}\meta{act-arg} is executed before
 %   \cs{robust at command@act} exits.
 %
-%   \cs{NewCommandCopy} checks if \verb=#1= is already defined, and raises an
-%   error if so, otherwise the definition is carried out.
+%   \cs{robust at command@act} will start by using \cs{robust at command@act at chk@args}
+%   to check if the \meta{robust-cmd} (|#2|) is a parameterless (possibly
+%   \cs{protected}) macro.  If it is not, the command is not a robust command:
+%   these always start with a parameterless user-level macro;  in that case,
+%   \cs{robust at command@act at end} is used to short-circuit the process and do the
+%   \meta{fallback-action} (|#3|).  This first test is necessary because later
+%   on we need to be able to expand the \meta{robust-cmd} without the risk of it
+%   Breaking Badly, and as a bonus, this speeds up the process in case we used
+%   \cs{NewCommandCopy} in a ``normal'' macro.
+%    \begin{macrocode}
+\def\robust at command@act#1#2#3#4{%
+  \begingroup
+    \escapechar=`\\
+  \expandafter\endgroup\expandafter
+  \robust at command@act at chk@args\meaning#2:->\@nil
+    {\expandafter\robust at command@act at loop
+       \expandafter#2%
+         #1{\@nnil\@nnil}%
+     \robust at command@act at end}%
+    {\robust at command@act at end}%
+      {#3}{#4}}%
+\def\robust at command@act at loop#1#2{\robust at command@act at loop@aux#1#2}
+%    \end{macrocode}
+%
+%   If \cs{robust at command@act at chk@args} branched to false, then
+%   \cs{robust at command@act at loop} will loop over the list of items in the
+%   \meta{action-list} (|#1|), and process each item as described earlier.
+%   If the \meta{if-type-$n$} command expands to \meta{true} then
+%   \cs{robust at command@act at do} is used to execute \meta{act-type-$n$} on the
+%   \meta{act-arg}, otherwise the loop resumes with the next item.
+%    \begin{macrocode}
+\def\robust at command@act at loop@aux#1#2#3{%
+  \ifx\@nnil#2%
+  \else
+    #2{#1}%
+      {\robust at command@act at do{#3}}%
+      {\expandafter\robust at command@act at loop\expandafter#1}%
+  \fi}
+\def\robust at command@act at do#1%
+  \fi#2%
+  \robust at command@act at end#3#4{%
+  \fi
+  #1#4}
+%    \end{macrocode}
+%
+%   If the end is reached and no action was taken, then do
+%   \meta{fallback-action}\meta{act-arg}.
+%    \begin{macrocode}
+\def\robust at command@act at end#1#2{#1#2}
+%    \end{macrocode}
+%
+% \begin{macro}{\robust at command@act at chk@args}
+%    \begin{macrocode}
+\def\robust at command@act at chk@args#1:->#2\@nil{%
+  \@expl at str@if at eq@@nnTF{#1}{macro}%
+    {\@firstoftwo}%
+    {\@expl at str@if at eq@@nnTF{#1}{\protected macro}%
+      {\@firstoftwo}%
+      {\@secondoftwo}}}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 %   \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}.
@@ -1377,83 +1450,7 @@
     {\declare at command@copy#3#4}}
 %    \end{macrocode}
 %
-% \begin{macro}{\declare at command@copy}
-% \begin{macro}{\declare at command@copy at loop}
-% \begin{macro}{\declare at command@copy at loop@aux}
-% \begin{macro}{\declare at command@copy at do}
-% \begin{macro}{\declare at command@copy at let}
-% \begin{macro}{\declare at command@copy at chk@args}
 % \begin{macro}{\@declarecommandcopylisthook}
-%   \cs{declare at command@copy at loop} will start by using
-%   \cs{declare at command@copy at chk@args} to check if the macro being copied
-%   (\verb=#2=) is a parameterless (\cs{protected}) macro.  If it is not, a
-%   simple \cs{let} is used to copy the definition and we're done.  This is so
-%   because the high-level commands that are in the scope of this macro are
-%   always defined so that the top-level macro doesn't take any argument.  This
-%   first test is necessary because later on we need to be able to expand the
-%   \verb=#2= without the risk of it Breaking Badly, and as a bonus, this speeds
-%   up the process in case we used \cs{NewCommandCopy} in a ``normal'' macro.
-%
-%   If \cs{declare at command@copy at chk@args} branched to false, then
-%   \cs{declare at command@copy at loop} will loop over the list of items in the
-%   \cs{@declarecommandcopylisthook} token list, and process each item with
-%   \verb=#1= (the command being defined) and \verb=#2= (the command being
-%   copied to \verb=#1=).  The token list \cs{@declarecommandcopylisthook}
-%   should be of the form
-% \begin{verbatim}
-%   {\IfTypeCommand \CopyTypeCommand}
-%   {\IfAnotherCommand \CopyAnotherCommand}
-%   ...
-% \end{verbatim}
-%   where each braced group represents one type of command, and within each
-%   the first token is a conditional which takes a command as argument, and
-%   tests that command, branching to true or false.  If this macro branched to
-%   true, then the second macro is used with the two macros (the one being
-%   copied to, and the one being copied from) to perform the assignment.
-%   If none of the tests in the \cs{@declarecommandcopylisthook} token list
-%   resulted true, then both macros are just \cs{let} to one another.
-%    \begin{macrocode}
-\def\declare at command@copy#1#2{%
-  \expandafter\declare at command@copy at chk@args\meaning#2:->\@nil
-    {\expandafter\declare at command@copy at loop\expandafter#2%
-       \@declarecommandcopylisthook{\@nnil\@nnil}%
-     \@declare at command@end}%
-    {\declare at command@copy at let}%
-  #1#2}%
-\def\declare at command@copy at loop#1#2{\declare at command@copy at loop@aux#1#2}
-\def\declare at command@copy at loop@aux#1#2#3{%
-  \ifx\@nnil#2%
-    \declare at command@copy at do\declare at command@copy at let
-  \else
-    #2{#1}%
-      {\declare at command@copy at do{#3}}%
-      {\expandafter\declare at command@copy at loop\expandafter#1}%
-  \fi}
-\def\declare at command@copy at do#1#2%
-  \fi#3%
-  \@declare at command@end#4#5{%
-  \fi
-  #1#4#5}
-\def\declare at command@copy at let#1#2{\let#1=#2\relax}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
-\def\declare at command@copy at chk@args#1:->#2\@nil{%
-  \@expl at str@if at eq@@nnTF{#1}{macro}%
-    {\@firstoftwo}%
-    {\@expl at str@if at eq@@nnTF{#1}{\protected macro}%
-      {\@firstoftwo}%
-      {\@secondoftwo}}}
-%    \end{macrocode}
-%
-%
-%    \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}





More information about the latex3-commits mailing list.