From 8f99cdeb54e7df0b47be8999e6b94c35cc9aef8f Mon Sep 17 00:00:00 2001 From: PhelypeOleinik Date: Fri, 18 Mar 2022 17:24:51 -0300 Subject: [PATCH 1/2] Fix cmd type detection fixes #795 --- base/changes.txt | 5 +++++ base/doc/ltnews35.tex | 10 ++++++++++ base/ltcmd.dtx | 23 ++++++++++------------- base/testfiles/github-0795.lvt | 8 ++++++++ base/testfiles/github-0795.tlg | 4 ++++ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 base/testfiles/github-0795.lvt create mode 100644 base/testfiles/github-0795.tlg diff --git a/base/changes.txt b/base/changes.txt index 5dbde25d9..14644f2e4 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,11 @@ completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2022-03-18 Phelype Oleinik + + * ltcmd.dtx (subsection{Utilities}): + Fix \@@_cmd_type_cases:NnnnnF prematurely expanding macros (gh/795). + 2022-03-18 Joseph Wright * ltkeys.dtx: diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex index 3a2f91d7b..9bf2279d8 100644 --- a/base/doc/ltnews35.tex +++ b/base/doc/ltnews35.tex @@ -603,6 +603,16 @@ \subsection{Make \cs{cite}\texttt{\textbraceleft\textbraceright} produce a warni +\subsection{Fix adding \hook{cmd} hooks to simple macros} + +A bug in how \LaTeX{} would detect the type of a command was causing a +premature forced expansion of such commands, which, depending on their +definition, could be harmless or could cause severe trouble. This has +been fixed in the latest release. +% +\githubissue{795} +\sxissue{q/637565} + \section{Changes to packages in the \pkg{amsmath} category} diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx index f52b32479..9f560daa5 100644 --- a/base/ltcmd.dtx +++ b/base/ltcmd.dtx @@ -34,8 +34,8 @@ %%% From File: ltcmd.dtx % % \begin{macrocode} -\def\ltcmdversion{v1.0k} -\def\ltcmddate{2022-02-28} +\def\ltcmdversion{v1.0l} +\def\ltcmddate{2022-03-18} % \end{macrocode} % %<*driver> @@ -4097,8 +4097,10 @@ % \begin{macro}{\@@_cmd_type_cases:Nnnnn} % \changes{v1.0d}{2021/04/19}{Renamed \cs{__cmd_cmd_if_xparse:NTF} to % \cs{__kernel_cmd_if_xparse:NTF} for cross-module usage} -% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:Nnnnn} for +% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:NnnnnF} for % \cs{NewCommandCopy} and \cs{ShowCommand} support} +% \changes{v1.0l}{2022/03/18}{Fix \cs{@@_cmd_type_cases:NnnnnF} +%" prematurely expanding macros (gh/795)} % \begin{macro}{\@@_cmd_if_xparse_aux:N} % % To determine whether the command is an \pkg{xparse} command check @@ -4119,20 +4121,15 @@ \exp_args:Nf \tl_if_empty:nT { \cs_argument_spec:N #1 } { \token_if_macro:NT #1 - { - \exp_after:wN \exp_after:wN - \exp_after:wN \token_to_str:N - \exp_after:wN \use_i_delimit_by_q_stop:nw - #1 \scan_stop: \q_stop - } + { \exp_not:N \exp_not:N \exp_not:e { \tl_head:N #1 } } } } { - { \token_to_str:N \@@_start:nNNnnn } {#2} - { \token_to_str:N \@@_start_expandable:nNNNNn } {#3} - { \token_to_str:N \@@_start_env:nnnnn } {#4} + { \exp_not:N \@@_start:nNNnnn } {#2} + { \exp_not:N \@@_start_expandable:nNNNNn } {#3} + { \exp_not:N \@@_start_env:nnnnn } {#4} { - \exp_after:wN \token_to_str:N + \exp_after:wN \exp_not:N \cs:w environment~ \exp_last_unbraced:Ne \use_none:nnn { \cs_to_str:N #1 } ~end~aux \cs_end: diff --git a/base/testfiles/github-0795.lvt b/base/testfiles/github-0795.lvt new file mode 100644 index 000000000..286ed5918 --- /dev/null +++ b/base/testfiles/github-0795.lvt @@ -0,0 +1,8 @@ +\input test2e +\START +\def\test{\typeout{test}\fi} +\AddToHook{cmd/test/after}{\typeout{hello}} +\@kernel@after@begindocument +\if11 % \fi comes from \test +\test +\END diff --git a/base/testfiles/github-0795.tlg b/base/testfiles/github-0795.tlg new file mode 100644 index 000000000..5a5b512ac --- /dev/null +++ b/base/testfiles/github-0795.tlg @@ -0,0 +1,4 @@ +This is a generated file for the LaTeX2e validation system. +Don't change this file in any respect. +test +hello From b317f9cb6431e5a985913dfa46340e829fa907bf Mon Sep 17 00:00:00 2001 From: PhelypeOleinik Date: Fri, 18 Mar 2022 20:34:41 -0300 Subject: [PATCH 2/2] Second attempt at 8f99cde If the first item is a braced group, more tokens are returned so a single \exp_not:N is not enough --- base/ltcmd.dtx | 5 +---- base/testfiles/github-0795.lvt | 4 ++++ base/testfiles/github-0795.tlg | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx index 9f560daa5..59aa5bf47 100644 --- a/base/ltcmd.dtx +++ b/base/ltcmd.dtx @@ -4119,10 +4119,7 @@ \exp_args:Ne \str_case_e:nnF { \exp_args:Nf \tl_if_empty:nT { \cs_argument_spec:N #1 } - { - \token_if_macro:NT #1 - { \exp_not:N \exp_not:N \exp_not:e { \tl_head:N #1 } } - } + { \exp_not:N \exp_not:n { \exp_not:e { \tl_head:N #1 } } } } { { \exp_not:N \@@_start:nNNnnn } {#2} diff --git a/base/testfiles/github-0795.lvt b/base/testfiles/github-0795.lvt index 286ed5918..ea823a972 100644 --- a/base/testfiles/github-0795.lvt +++ b/base/testfiles/github-0795.lvt @@ -1,8 +1,12 @@ \input test2e \START \def\test{\typeout{test}\fi} +\def\testx{{\typeout{test x}\fi}} \AddToHook{cmd/test/after}{\typeout{hello}} +\AddToHook{cmd/testx/after}{\typeout{hello x}} \@kernel@after@begindocument \if11 % \fi comes from \test \test +\if11 % \fi comes from \testx +\testx \END diff --git a/base/testfiles/github-0795.tlg b/base/testfiles/github-0795.tlg index 5a5b512ac..8b4753350 100644 --- a/base/testfiles/github-0795.tlg +++ b/base/testfiles/github-0795.tlg @@ -2,3 +2,5 @@ This is a generated file for the LaTeX2e validation system. Don't change this file in any respect. test hello +test x +hello x