[latex3-commits] [git/LaTeX3-latex3-latex2e] gh569: Showing commands (f0cfa6e5)
PhelypeOleinik
phelype.oleinik at latex-project.org
Mon Aug 9 21:58:53 CEST 2021
Repository : https://github.com/latex3/latex2e
On branch : gh569
Link : https://github.com/latex3/latex2e/commit/f0cfa6e5439b6d6fb96269aab1b8cacde64aa57d
>---------------------------------------------------------------
commit f0cfa6e5439b6d6fb96269aab1b8cacde64aa57d
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Mon Aug 9 16:58:53 2021 -0300
Showing commands
>---------------------------------------------------------------
f0cfa6e5439b6d6fb96269aab1b8cacde64aa57d
base/ltcmd.dtx | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 79 insertions(+), 2 deletions(-)
diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx
index 2e901fb3..1543b830 100644
--- a/base/ltcmd.dtx
+++ b/base/ltcmd.dtx
@@ -1935,7 +1935,7 @@
% \subsubsection{Copying a command and its internal structure}
%
%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_copy:NN}%
-%<latexrelease> {Support \NewCommandCopy and \ShowCommand in ltcmd}
+%<latexrelease> {Support \NewCommandCopy in ltcmd}
% Since the 2020-10-01 \LaTeXe{} release, support for copying and
% showing the definition of robust commands is available, but the
% specifics of each command is implemented separately. Here we'll add
@@ -2209,7 +2209,84 @@
%<latexrelease>\EndIncludeInRelease
%
%<latexrelease>\IncludeInRelease{0000/00/00}{\@@_copy:NN}%
-%<latexrelease> {Support \NewCommandCopy and \ShowCommand in ltcmd}
+%<latexrelease> {Support \NewCommandCopy in ltcmd}
+%<latexrelease>\EndIncludeInRelease
+% \end{macrocode}
+%
+% \subsubsection{Showing the definition of a command}
+%
+%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_show:N}%
+%<latexrelease> {Support \ShowCommand in ltcmd}
+% To show the definition of a command we need more or less the same
+% building blocks as for copying, except that instead of making a copy,
+% we'll just print stuff to the terminal.
+%
+% \begin{macro}{\@@_show:N}
+% This macro just branches to the proper copying command by using
+% \cs{@@_cmd_type_cases:NnnnF}. The copying command takes the names
+% of the commands to be copied to and from, and the actual commands
+% as its four arguments.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_show:N #1
+ {
+ \use:x
+ {
+ \int_set:Nn \tex_escapechar:D { 92 }
+ \exp_not:N \@@_cmd_type_cases:NnnnF \exp_not:N #1
+ { \@@_show_command:N }
+ { \@@_show_expandable:N }
+ { \@@_show_environment:N }
+ { \@@_cant_copy:nwn { non-ltcmd } }
+ \exp_not:N #1
+ \exp_not:N \@@_break_point:n { \cs_to_str:N #1 }
+ \int_set:Nn \tex_escapechar:D { \int_use:N \tex_escapechar:D }
+ }
+ }
+%
+\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} }
+\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} }
+\cs_new_protected:Npn \@@_show_command_aux:nNNn #1 #2 #3 #4
+ {
+ \iow_term:x { > ~ \token_to_str:N #2 = #1: }
+ \iow_term:x { > ~ signature = \tl_to_str:n {#4} . }
+ \iow_term:x
+ {
+ > ~ \token_to_str:N #3 ~ (
+ \int_eval:n
+ { \exp_args:Nf \str_count:n { \cs_argument_spec:N #3 } / 2 } ~
+ parameters ) : \cs_replacement_spec:N #3
+ }
+ }
+%
+\cs_new_protected:Npn \@@_show_environment:N #1
+ { \msg_error:nn { cmd } { env-show } }
+\msg_new:nnn { cmd } { env-show }
+ { Showing~environments~is~not~possible. }
+% \end{macrocode}
+%
+% And, of course, add \cs{__kernel_cmd_if_xparse:NTF} and
+% \cs{@@_show:N} to \cs{@showcommandlisthook}:
+% \begin{macrocode}
+\tl_gput_right:Nn \@showcommandlisthook
+ { { \__kernel_cmd_if_xparse:NTF \@@_show:N } }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% Not much to do regarding \pkg{latexrelease}: we could remove the
+% entries from \cs{@showcommandlisthook}, but it doesn't seem
+% worth it.
+% \begin{macrocode}
+%<latexrelease>\EndIncludeInRelease
+%
+%<latexrelease>\IncludeInRelease{0000/00/00}{\@@_show:N}%
+%<latexrelease> {Support \ShowCommand in ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
More information about the latex3-commits
mailing list.