[latex3-commits] [git/LaTeX3-latex3-latex2e] gh963: Don't stop for interaction midway \ShowEnvironment (e0219296)

PhelypeOleinik phelype.oleinik at latex-project.org
Wed Nov 30 06:02:50 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : gh963
Link       : https://github.com/latex3/latex2e/commit/e02192969ef78e60500a30abf569c4293732667f

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

commit e02192969ef78e60500a30abf569c4293732667f
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Wed Nov 30 02:02:50 2022 -0300

    Don't stop for interaction midway \ShowEnvironment


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

e02192969ef78e60500a30abf569c4293732667f
 base/ltcmd.dtx                       |  35 ++++++++----
 base/ltdefns.dtx                     | 102 +++++++++++++++++++++--------------
 base/testfiles-ltcmd/github-0963.lvt |   8 +++
 base/testfiles-ltcmd/github-0963.tlg |  26 ++++++---
 4 files changed, 112 insertions(+), 59 deletions(-)

diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx
index 03cfb829..30a1908c 100644
--- a/base/ltcmd.dtx
+++ b/base/ltcmd.dtx
@@ -2401,21 +2401,28 @@
 %     \@@_show_command:NnNNwN,
 %     \@@_show_expandable:N,
 %     \@@_show_expandable:NnNNNNnN,
-%     \@@_show_command_aux:nNNn,
+%     \@@_show_command_aux:NnNNn,
 %     \@@_show_environment:N,
+%     \@@_show:x,
 %   }
 %   These commands just expand the command once to reveal its innards,
 %   then pass the type of command, the control sequence, the signature,
-%   and the code macro to \cs{@@_show_command_aux:nNNn}.
+%   and the code macro to \cs{@@_show_command_aux:NnNNn}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_show_command:N #1
   { \exp_after:wN \@@_show_command:NnNNwN #1 \q_@@ #1 }
 \cs_new_protected:Npn \@@_show_command:NnNNwN #1 #2 #3 #4 #5 \q_@@ #6
-  { \@@_show_command_aux:nNNn { document~command } #6 #4 {#2} }
+  {
+    \@@_show_command_aux:NnNNn \tl_show:x
+      { document~command } #6 #4 {#2}
+  }
 \cs_new_protected:Npn \@@_show_expandable:N #1
   { \exp_after:wN \@@_show_expandable:NnNNNNnN #1 #1 }
 \cs_new_protected:Npn \@@_show_expandable:NnNNNNnN #1 #2 #3 #4 #5 #6 #7 #8
-  { \@@_show_command_aux:nNNn { expandable~document~command } #8 #5 {#2} }
+  {
+    \@@_show_command_aux:NnNNn \tl_show:x
+      { expandable~document~command } #8 #5 {#2}
+  }
 %    \end{macrocode}
 %
 %   Now just print everything in the required format.  The auxiliary
@@ -2423,27 +2430,31 @@
 %   \cs{l_@@_tmpa_tl}, so we ust use that here:
 % \changes{v1.0j}{2021/13/31}
 %         {Make \cs{ShowCommand} stop for interaction}
+% \changes{v1.1b}{2022/11/30}
+%         {Don't stop for the \cs{begin} part of an environment}
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_show_command_aux:nNNn #1 #2 #3 #4
+\cs_new_protected:Npn \@@_show_command_aux:NnNNn #1 #2 #3 #4 #5
   {
-    \@@_split_signature:n {#4}
-    \tl_show:x
+    \@@_split_signature:n {#5}
+    #1
       {
-        \token_to_str:N #2 = #1: \iow_newline:
+        \token_to_str:N #3 = #2: \iow_newline:
         \tl_use:N \l_@@_tmpa_tl
-        -> \cs_replacement_spec:N #3
+        -> \cs_replacement_spec:N #4
       }
   }
 %    \end{macrocode}
 %
 %   We can reuse most of the above to show an environment, except that
 %   we need to ensure that the proper \cs[no-index]{environment~\ldots}
-%   are passed to \cs{@@_show_command_aux:nNNn}.  Additionally, when
+%   are passed to \cs{@@_show_command_aux:NnNNn}.  Additionally, when
 %   |\ShowCommand\foo| is used (if |foo| is an environment), we show
 %   |\endfoo| as well, and when |\ShowCommand\endfoo| is used, change
 %   that to |\ShowCommand\foo| and do the same.
 % \changes{v1.0j}{2021/13/31}
 %         {Make \cs{ShowCommand} stop for interaction}
+% \changes{v1.1b}{2022/11/30}
+%         {Don't stop for the \cs{begin} part of an environment}
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_show_environment:N #1
   {
@@ -2459,12 +2470,14 @@
   {
     \use:x
       {
-        \@@_show_command_aux:nNNn { document~environment }
+        \@@_show_command_aux:NnNNn \@@_show:x { document~environment }
           { \exp_not:N \begin {#3} }
           \exp_not:c { environment~ #3 ~ code }
           {#2}
       }
   }
+\cs_new_protected:Npn \@@_show:x #1
+  { \iow_term:x { > ~ #1 . \iow_newline: } }
 \cs_new_protected:Npn \@@_show_environment_end:N #1
   {
     \exp_args:NNx \@@_check_end:Nn \l_@@_tmpa_tl { \cs_to_str:N #1 }
diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index b3c34d67..a90e6a0f 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1899,6 +1899,7 @@
 %
 % \begin{macro}{\@show at DeclareRobustCommand}
 % \begin{macro}{\show at kernel@robust at command}
+% \begin{macro}{\@show at 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.
@@ -1926,12 +1927,14 @@
   \robust at command@chk at safe#1%
     {\@if at newcommand#1%
        {\@show at newcommand}%
-       {\show}}%
-    {\show}%
+       {\@show at macro}}%
+    {\@show at macro}%
   #1}
+\let\@show at macro\show
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \end{macro}
 %
@@ -1994,7 +1997,7 @@
   \typeout{->\@expl at cs@replacement at spec@@N#1.^^J}%
   \expandafter\@show at newcommand@aux
     \csname\@backslashchar\@expl at cs@to at str@@N#1\expandafter\endcsname
-    \expandafter{#1}}
+    \expandafter{#1}\@show at tokens}
 %    \end{macrocode}
 %
 %   For a macro defined with, say, |\newcommand\foo[1][opt]{bar}|, it will
@@ -2009,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 at newcommand@aux#1#2{%
+\long\def\@show at newcommand@aux#1#2#3{%
   \typeout{> \string#1=\@expl at cs@prefix at spec@@N#1macro:}%
-  \edef\reserved at a{%
-    default \string##1=\expandafter\detokenize\@gobblethree#2.^^J%
-    \@expl at cs@argument at spec@@N#1->\@expl at cs@replacement at spec@@N#1}%
-  \showtokens\expandafter\expandafter\expandafter{\expandafter\reserved at a}}
+  #3{default \string##1=\expandafter\detokenize\@gobblethree#2.^^J%
+    \@expl at cs@argument at spec@@N#1->\@expl at cs@replacement at spec@@N#1}}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\@show at 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}
+\def\@show at tokens#1{%
+  \edef\reserved at a{#1}%
+  \showtokens\expandafter
+    \expandafter\expandafter{\expandafter\reserved at a}}
+%    \end{macrocode}
+% \end{macro}
+%
 %   Now the rollback code.
 %    \begin{macrocode}
 %</2ekernel|latexrelease>
@@ -2090,18 +2101,24 @@
 %   the \cs{end} part.
 %    \begin{macrocode}
 \long\def\@show at newcommand@env#1{%
-  \typeout{> \string\begin{\@expl at cs@to at str@@N#1}=environment:}%
-  \typeout{->\@expl at cs@replacement at spec@@N#1.^^J}%
+  \@show at environment@begin#1%
   \expandafter\@show at newcommand@aux
     \csname\@backslashchar\@expl at cs@to at str@@N#1\expandafter\endcsname
-    \expandafter{#1}%
+    \expandafter{#1}\@show at typeout
   \@show at environment@end#1}
 \long\def\@show at DeclareRobustCommand@env#1{%
-  \typeout{> \string\begin{\@expl at cs@to at str@@N#1}=environment:}%
-  \typeout{->\@expl at cs@replacement at spec@@N#1.^^J}%
-  \expandafter\show at kernel@robust at command
-    \csname\@expl at cs@to at str@@N#1 \endcsname
+  \@show at environment@begin#1%
+  \begingroup
+    \let\@show at tokens\@show at typeout
+    \let\@show at macro\@show at nonstop
+    \expandafter\show at kernel@robust at command
+      \csname\@expl at cs@to at str@@N#1 \endcsname
+  \endgroup
   \@show at environment@end#1}
+\def\@show at environment@begin#1{%
+  \typeout{> \string\begin{\@expl at cs@to at str@@N#1}=environment:}%
+  \typeout{\@expl at cs@argument at spec@@N#1->%
+           \@expl at cs@replacement at spec@@N#1.^^J}}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -2114,30 +2131,35 @@
 %   gibberish.
 %    \begin{macrocode}
 \long\def\@show at normalenv#1{%
-  \@show at normalenv@meaning#1%
-    {\string\begin{\@expl at cs@to at str@@N#1}=environment}%
+  \@show at environment@begin#1%
   \@show at environment@end#1}
 \long\def\@show at environment@end#1{%
-  \@ifundefined{end\@expl at cs@to at str@@N#1}%
-    {\@show at normalenv@undefined}%
-    {\expandafter\@show at normalenv@meaning
-       \csname end\@expl at cs@to at str@@N#1\endcsname}%
-      {\string\end{\@expl at cs@to at str@@N#1}}}
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
-% \begin{macro}{\@show at normalenv@meaning}
-% \begin{macro}{\@show at normalenv@undefined}
-%   And here the auxiliaries that do the actual printing.
-%    \begin{macrocode}
-\def\@show at normalenv@meaning#1#2{%
-  \edef\reserved at a{#2:^^J%
-    \@expl at cs@argument at spec@@N#1->\@expl at cs@replacement at spec@@N#1}%
-  \showtokens\expandafter\expandafter\expandafter{\expandafter\reserved at a}}
-\def\@show at normalenv@undefined#1{%
-  \edef\reserved at a{#1=undefined}%
-  \showtokens\expandafter\expandafter\expandafter{\expandafter\reserved at a}}
+  \expandafter\@show at environment@end at aux
+    \csname end\@expl at cs@to at str@@N#1\endcsname#1}
+\long\def\@show at environment@end at aux#1#2{%
+  \@show at tokens{\string\end{\@expl at cs@to at str@@N#2}%
+    \ifx\relax#1=undefined%
+    \else:^^J\@expl at cs@argument at spec@@N#1->%
+             \@expl at cs@replacement at spec@@N#1%
+    \fi}}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@show at nonstop}
+% \begin{macro}{\@show at typeout}
+%   And here some auxiliaries:
+%   \begin{description}
+%     \item[\cs{@show at nonstop}] same output as \cs{show}, but doesn't
+%       stop for interaction;
+%     \item[\cs{@show at typeout}] same output as \cs{showtokens}, but
+%       doesn't stop for interaction.
+%   \end{description}
+%    \begin{macrocode}
+\def\@show at nonstop#1{%
+  \typeout{> \string#1=\@expl at cs@prefix at spec@@N#1macro:^^J%
+   \@expl at cs@argument at spec@@N#1->\@expl at cs@replacement at spec@@N#1.}}
+\def\@show at typeout#1{\typeout{> #1.^^J}}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/base/testfiles-ltcmd/github-0963.lvt b/base/testfiles-ltcmd/github-0963.lvt
index 28008ec7..f088dcc5 100644
--- a/base/testfiles-ltcmd/github-0963.lvt
+++ b/base/testfiles-ltcmd/github-0963.lvt
@@ -47,9 +47,14 @@
 \show\group
 \show\endgroup
 
+% \errorstopmode
+
 \typeout{---------- show 2e environment ----}
 \ShowEnvironment{center}
 
+\typeout{---------- show 2e env with arg ---}
+\ShowEnvironment{tabular*}
+
 \typeout{---------- show 2e env with opt ---}
 \renewenvironment{bar}[2][opt]{begin}{end}
 \ShowEnvironment{bar}
@@ -60,5 +65,8 @@
 \typeout{---------- show l3 environment ----}
 \ShowEnvironment{foo}
 
+\typeout{---------- show 2e robust + opt ---}
+\DeclareRobustCommand\myfont[1][opt]{\bfseries}
+\ShowEnvironment{myfont}
 
 \END
diff --git a/base/testfiles-ltcmd/github-0963.tlg b/base/testfiles-ltcmd/github-0963.tlg
index 08995a15..8bfbbf5c 100644
--- a/base/testfiles-ltcmd/github-0963.tlg
+++ b/base/testfiles-ltcmd/github-0963.tlg
@@ -74,20 +74,23 @@ l. ...\show\endgroup
 ---------- show 2e environment ----
 > \begin{center}=environment:
 ->\trivlist \centering \item \relax .
-<recently read> }
-l. ...\ShowEnvironment{center}
 > \end{center}:
 ->\endtrivlist .
 <recently read> }
 l. ...\ShowEnvironment{center}
+---------- show 2e env with arg ---
+> \begin{tabular*}=environment:
+#1->\setlength \dimen@ {#1}\edef \@halignto {to\the \dimen@ }\@tabular .
+> \end{tabular*}:
+->\crcr \egroup \egroup $\egroup .
+<recently read> }
+l. ...\ShowEnvironment{tabular*}
 ---------- show 2e env with opt ---
 > \begin{bar}=environment:
 ->\@protected at testopt \bar \\bar {opt}.
 > \\bar=\long macro:
 > default #1=opt.
 [#1]#2->begin.
-<recently read> }
-l. ...\ShowEnvironment{bar}
 > \end{bar}:
 ->end.
 <recently read> }
@@ -97,8 +100,6 @@ l. ...\ShowEnvironment{bar}
 ->\protect \bfseries  .
 > \bfseries =\long macro:
 ->\not at math@alphabet \bfseries \mathbf \expand at font@defaults \maybe at update@bfseries at defaults \ifx \f at family \rmdef at ult \fontseries \bfseries at rm \else \ifx \f at family \sfdef at ult \fontseries \bfseries at sf \else \ifx \f at family \ttdef at ult \fontseries \bfseries at tt \else \fontseries \bfdefault \fi \fi \fi \UseHook {bfseries}\selectfont .
-<argument> \bfseries  
-l. ...\ShowEnvironment{bfseries}
 > \end{bfseries}=undefined.
 <recently read> }
 l. ...\ShowEnvironment{bfseries}
@@ -106,9 +107,18 @@ l. ...\ShowEnvironment{bfseries}
 > \begin{foo}=document environment:
   #1:m
 ->\typeout {start foo #1}.
-<recently read> }
-l. ...\ShowEnvironment{foo}
 > \end{foo}:
 ->\typeout {end foo #1}.
 <recently read> }
 l. ...\ShowEnvironment{foo}
+---------- show 2e robust + opt ---
+> \begin{myfont}=environment:
+->\protect \myfont  .
+> \myfont =robust macro:
+->\@protected at testopt \myfont  \\myfont  {opt}.
+> \\myfont =\long macro:
+> default #1=opt.
+[#1]->\bfseries .
+> \end{myfont}=undefined.
+<recently read> }
+l. ...\ShowEnvironment{myfont}





More information about the latex3-commits mailing list.