Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish protected ltcmds with only m-type args #1013

Merged
merged 2 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================

2023-03-11 Yukai Chou <muzimuzhi@gmail.com>

* ltcmd.dtx (subsubsection{Showing the definition of a command}),
(subsubsection{Copying a command and its internal structure}):
Correctly recognize (non-expandable) document commands with empty or only
m-type arguments (gh/1009)

2023-01-30 Frank Mittelbach <Frank.Mittelbach@latex-project.org>

* ltpara.dtx (subsection{Providing hooks for paragraphs}):
Expand Down
10 changes: 10 additions & 0 deletions base/doc/ltnews37.tex
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ \subsection{Improve spacing at top of \env{minipages}}
\githubissue{989}


\subsection{A fix for \cs{NewCommandCopy} and \cs{ShowCommand}}

When copying and showing definitions of (non-expandable) document commands
(aka commands defined by \cs{NewDocumentCommand} and friends) containing empty
or only \texttt{m}-type arguments, these commands were wrongly recognized as
expandable ones.
This is fixed in the present \LaTeX{} release.
%
\githubissue{1009}


\section{Changes to packages in the \pkg{amsmath} category}

Expand Down
98 changes: 89 additions & 9 deletions base/ltcmd.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
%%% From File: ltcmd.dtx
%
% \begin{macrocode}
\def\ltcmdversion{v1.1b}
\def\ltcmddate{2022-11-29}
\def\ltcmdversion{v1.1c}
\def\ltcmddate{2023-03-12}
% \end{macrocode}
%
%<*driver>
Expand Down Expand Up @@ -2123,26 +2123,70 @@
% and possibly another auxiliary
% \cs{\meta{cmd}\textvisiblespace\textvisiblespace}, if the command
% has both long and short arguments. Then, its signature also has
% several specific bits that are unique to that command; this is in contrast to
% non-expandable commands, which use a common set of parsing functions.
% several specific bits that are unique to that command; this is in contrast
% to non-expandable commands, which use a common set of parsing functions.
%
% We start by copying the basics, then call
% \cs{@@_copy_expandable_signature:NnNNNNnnn} to parse the signature
% of the command and build up the modified copy in a temporary token list,
% then we call \cs{@@_copy_expandable:NnNNNNnnn} that will copy the
% top-level definition of the command, with the proper internal
% renames.
%
% \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_copy:NN}%
%<latexrelease> {Support~\NewCommandCopy~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \changes{v1.1c}{2023/03/12}
% {Distinguish (non-expandable) document commands starting with
% \cs{@@_start_expandable:nNNNNn}}
% There's one variant: a command begins with \cs{@@_start_expandable:nNNNNn}
% may still be un-expandable/protected if it's defined by
% \cs{NewDocumentCommand} and friends, with empty or only m-type arguments.
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2023/06/01}{\@@_copy_expandable:nnNN}%
%<latexrelease> {Distinguish~non-expandable~document~commands}
\cs_new_protected:Npn \@@_copy_expandable:nnNN #1 #2 #3 #4
{
\cs_set_eq:cc { #1 ~ code } { #2 ~ code }
\@@_set_eq_if_exist:cc { #1 ~ } { #2 ~ }
\@@_set_eq_if_exist:cc { #1 ~ \c_space_tl } { #2 ~ \c_space_tl }
\@@_set_eq_if_exist:cc { #1 ~ defaults } { #2 ~ defaults }
\exp_after:wN \@@_copy_expandable_signature:NnNNNNnnn #4 {#1} {#2}
\cs_set_nopar:Npx #3
\token_if_protected_macro:NTF #4
{ \cs_set_protected_nopar:Npx }{ \cs_set_nopar:Npx }
#3
{ \exp_after:wN \@@_copy_expandable:NnNNNNnnn #4 {#1} {#2} }
}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_copy_expandable:nnNN}%
%<latexrelease> {Support~\NewCommandCopy~in~ltcmd}
%<latexrelease>\cs_new_protected:Npn \@@_copy_expandable:nnNN #1 #2 #3 #4
%<latexrelease> {
%<latexrelease> \cs_set_eq:cc { #1 ~ code } { #2 ~ code }
%<latexrelease> \@@_set_eq_if_exist:cc { #1 ~ } { #2 ~ }
%<latexrelease> \@@_set_eq_if_exist:cc { #1 ~ \c_space_tl } { #2 ~ \c_space_tl }
%<latexrelease> \@@_set_eq_if_exist:cc { #1 ~ defaults } { #2 ~ defaults }
%<latexrelease> \exp_after:wN \@@_copy_expandable_signature:NnNNNNnnn #4 {#1} {#2}
%<latexrelease> \cs_set_nopar:Npx #3
%<latexrelease> { \exp_after:wN \@@_copy_expandable:NnNNNNnnn #4 {#1} {#2} }
%<latexrelease> }
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_copy_expandable:nnNN}%
%<latexrelease> {Support~\NewCommandCopy~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_copy:NN (part 2)}%
%<latexrelease> {Support~\NewCommandCopy~in~ltcmd}
% \end{macrocode}
%
% \begin{macrocode}
\cs_new:Npn \@@_copy_expandable:NnNNNNnnn #1 #2 #3 #4 #5 #6 #7 #8 #9
{
\exp_not:N #1 \exp_not:n { {#2} }
Expand Down Expand Up @@ -2355,7 +2399,7 @@
% worth it.
% \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_copy:NN}%
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_copy:NN (part 2)}%
%<latexrelease> {Support~\NewCommandCopy~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
Expand Down Expand Up @@ -2418,11 +2462,47 @@
}
\cs_new_protected:Npn \@@_show_expandable:N #1
{ \exp_after:wN \@@_show_expandable:NnNNNNnN #1 #1 }
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_show:N}%
%<latexrelease> {Support~\ShowCommand~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \changes{v1.1c}{2023/03/12}
% {Distinguish (non-expandable) document commands starting with
% \cs{@@_start_expandable:nNNNNn}}
% There's one variant: a command begins with \cs{@@_start_expandable:nNNNNn}
% may still be un-expandable/protected if it's defined by
% \cs{NewDocumentCommand} and friends, with empty or only m-type arguments.
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2023/06/01}{\@@_show_expandable:NnNNNNnN}%
%<latexrelease> {Distinguish~non-expandable~document~commands}
\cs_new_protected:Npn \@@_show_expandable:NnNNNNnN #1 #2 #3 #4 #5 #6 #7 #8
{
\@@_show_command_aux:NnNNn \tl_show:x
{ expandable~document~command } #8 #5 {#2}
\exp_args:NNe \@@_show_command_aux:NnNNn \tl_show:x
{ \token_if_protected_macro:NF #8 { expandable~ } document~command }
#8 #5 {#2}
}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_show_expandable:NnNNNNnN}%
%<latexrelease> {Support~\ShowCommand~in~ltcmd}
%<latexrelease>\cs_new_protected:Npn \@@_show_expandable:NnNNNNnN #1 #2 #3 #4 #5 #6 #7 #8
%<latexrelease> {
%<latexrelease> \@@_show_command_aux:NnNNn \tl_show:x
%<latexrelease> { expandable~document~command } #8 #5 {#2}
%<latexrelease> }
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_show_expandable:NnNNNNnN}%
%<latexrelease> {Support~\ShowCommand~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_show:N (part 2)}%
%<latexrelease> {Support~\ShowCommand~in~ltcmd}
% \end{macrocode}
%
% Now just print everything in the required format. The auxiliary
Expand Down Expand Up @@ -2675,7 +2755,7 @@
% \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_show:N}%
%<latexrelease>\IncludeInRelease{2020/10/01}{\@@_show:N (part 2)}%
%<latexrelease> {Support~\ShowCommand~in~ltcmd}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
Expand Down
44 changes: 44 additions & 0 deletions base/testfiles-ltcmd/github-1009.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
\input{regression-test}

\START

\TEST{Non-expandable Document Commands with m-type arguments}{
\DeclareDocumentCommand{\foo}{ }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}

\DeclareDocumentCommand{\foo}{ m }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}

\DeclareDocumentCommand{\foo}{ +m }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}

\DeclareDocumentCommand{\foo}{ >{\foo}m }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}
}

\TEST{Expandable Document Commands with m-type arguments}{
\DeclareExpandableDocumentCommand{\foo}{ }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}

\DeclareExpandableDocumentCommand{\foo}{ m }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}

\DeclareExpandableDocumentCommand{\foo}{ +m }{}
\ShowCommand{\foo}
\DeclareCommandCopy{\baz}{\foo}
\ShowCommand{\baz}
}

\END
76 changes: 76 additions & 0 deletions base/testfiles-ltcmd/github-1009.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
============================================================
TEST 1: Non-expandable Document Commands with m-type arguments
============================================================
> \foo=document command:
->.
<recently read> }
l. ...}
> \baz=document command:
->.
<recently read> }
l. ...}
> \foo=document command:
#1:m
->.
<recently read> }
l. ...}
> \baz=document command:
#1:m
->.
<recently read> }
l. ...}
> \foo=document command:
#1:+m
->.
<recently read> }
l. ...}
> \baz=document command:
#1:+m
->.
<recently read> }
l. ...}
> \foo=document command:
#1:>{\foo }m
->.
<recently read> }
l. ...}
> \baz=document command:
#1:>{\foo }m
->.
<recently read> }
l. ...}
============================================================
============================================================
TEST 2: Expandable Document Commands with m-type arguments
============================================================
> \foo=expandable document command:
->.
<recently read> }
l. ...}
> \baz=expandable document command:
->.
<recently read> }
l. ...}
> \foo=expandable document command:
#1:m
->.
<recently read> }
l. ...}
> \baz=expandable document command:
#1:m
->.
<recently read> }
l. ...}
> \foo=expandable document command:
#1:+m
->.
<recently read> }
l. ...}
> \baz=expandable document command:
#1:+m
->.
<recently read> }
l. ...}
============================================================
10 changes: 10 additions & 0 deletions base/testfiles/github-0479-often.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ BEGIN module: ltcmd (....-..-..) on input line ....
Skipping module ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Testing for empty or blank on input line ....
Expand Down
10 changes: 10 additions & 0 deletions base/testfiles/github-0479-often.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ BEGIN module: ltcmd (....-..-..) on input line ....
Skipping module ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Testing for empty or blank on input line ....
Expand Down
10 changes: 10 additions & 0 deletions base/testfiles/github-0479-often.xetex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ BEGIN module: ltcmd (....-..-..) on input line ....
Skipping module ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Applying: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Applying: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Testing for empty or blank on input line ....
Expand Down
20 changes: 20 additions & 0 deletions base/testfiles/tlb-latexrelease-rollback-003-often.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ BEGIN module: ltcmd (....-..-..) on input line ....
Skipping module ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Testing for empty or blank on input line ....
Expand Down Expand Up @@ -727,6 +737,16 @@ BEGIN module: ltcmd (....-..-..) on input line ....
Skipping module ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \NewCommandCopy in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Distinguish non-expandable document commands on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Support \ShowCommand in ltcmd on input line ....
Skipping: [....-..-..] Testing for empty or blank on input line ....
Expand Down
Loading