Skip to content

Commit

Permalink
Merge pull request #796 from latex3/gh795
Browse files Browse the repository at this point in the history
Gh795 [ltcmdhooks] Adding hooks to simple macros cause them to expand
  • Loading branch information
PhelypeOleinik committed Apr 22, 2022
2 parents 4d5db49 + 959492d commit c4a5a8c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
5 changes: 5 additions & 0 deletions base/changes.txt
Expand Up @@ -40,6 +40,11 @@ are not part of the distribution.

* ltfilehook.dtx: document include/excluded hooks

2022-03-18 Phelype Oleinik <phelype.oleinik@latex-project.org>

* ltcmd.dtx (subsection{Utilities}):
Fix \@@_cmd_type_cases:NnnnnF prematurely expanding macros (gh/795).

2022-03-18 Joseph Wright <joseph.wright@latex-project.org>

* ltkeys.dtx:
Expand Down
10 changes: 10 additions & 0 deletions base/doc/ltnews35.tex
Expand Up @@ -684,6 +684,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}

Expand Down
26 changes: 10 additions & 16 deletions base/ltcmd.dtx
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand All @@ -4117,22 +4119,14 @@
\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_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:
Expand Down
12 changes: 12 additions & 0 deletions base/testfiles/github-0795.lvt
@@ -0,0 +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
6 changes: 6 additions & 0 deletions base/testfiles/github-0795.tlg
@@ -0,0 +1,6 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
test
hello
test x
hello x

0 comments on commit c4a5a8c

Please sign in to comment.