Skip to content

Commit 8f99cde

Browse files
Fix cmd type detection
fixes #795
1 parent ba246a8 commit 8f99cde

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

base/changes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ completeness or accuracy and it contains some references to files that
66
are not part of the distribution.
77
================================================================================
88

9+
2022-03-18 Phelype Oleinik <phelype.oleinik@latex-project.org>
10+
11+
* ltcmd.dtx (subsection{Utilities}):
12+
Fix \@@_cmd_type_cases:NnnnnF prematurely expanding macros (gh/795).
13+
914
2022-03-18 Joseph Wright <joseph.wright@latex-project.org>
1015

1116
* ltkeys.dtx:

base/doc/ltnews35.tex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,16 @@ \subsection{Make \cs{cite}\texttt{\textbraceleft\textbraceright} produce a warni
603603

604604

605605

606+
\subsection{Fix adding \hook{cmd} hooks to simple macros}
607+
608+
A bug in how \LaTeX{} would detect the type of a command was causing a
609+
premature forced expansion of such commands, which, depending on their
610+
definition, could be harmless or could cause severe trouble. This has
611+
been fixed in the latest release.
612+
%
613+
\githubissue{795}
614+
\sxissue{q/637565}
615+
606616

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

base/ltcmd.dtx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
%%% From File: ltcmd.dtx
3535
%
3636
% \begin{macrocode}
37-
\def\ltcmdversion{v1.0k}
38-
\def\ltcmddate{2022-02-28}
37+
\def\ltcmdversion{v1.0l}
38+
\def\ltcmddate{2022-03-18}
3939
% \end{macrocode}
4040
%
4141
%<*driver>
@@ -4097,8 +4097,10 @@
40974097
% \begin{macro}{\@@_cmd_type_cases:Nnnnn}
40984098
% \changes{v1.0d}{2021/04/19}{Renamed \cs{__cmd_cmd_if_xparse:NTF} to
40994099
% \cs{__kernel_cmd_if_xparse:NTF} for cross-module usage}
4100-
% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:Nnnnn} for
4100+
% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:NnnnnF} for
41014101
% \cs{NewCommandCopy} and \cs{ShowCommand} support}
4102+
% \changes{v1.0l}{2022/03/18}{Fix \cs{@@_cmd_type_cases:NnnnnF}
4103+
%" prematurely expanding macros (gh/795)}
41024104
% \begin{macro}{\@@_cmd_if_xparse_aux:N}
41034105
%
41044106
% To determine whether the command is an \pkg{xparse} command check
@@ -4119,20 +4121,15 @@
41194121
\exp_args:Nf \tl_if_empty:nT { \cs_argument_spec:N #1 }
41204122
{
41214123
\token_if_macro:NT #1
4122-
{
4123-
\exp_after:wN \exp_after:wN
4124-
\exp_after:wN \token_to_str:N
4125-
\exp_after:wN \use_i_delimit_by_q_stop:nw
4126-
#1 \scan_stop: \q_stop
4127-
}
4124+
{ \exp_not:N \exp_not:N \exp_not:e { \tl_head:N #1 } }
41284125
}
41294126
}
41304127
{
4131-
{ \token_to_str:N \@@_start:nNNnnn } {#2}
4132-
{ \token_to_str:N \@@_start_expandable:nNNNNn } {#3}
4133-
{ \token_to_str:N \@@_start_env:nnnnn } {#4}
4128+
{ \exp_not:N \@@_start:nNNnnn } {#2}
4129+
{ \exp_not:N \@@_start_expandable:nNNNNn } {#3}
4130+
{ \exp_not:N \@@_start_env:nnnnn } {#4}
41344131
{
4135-
\exp_after:wN \token_to_str:N
4132+
\exp_after:wN \exp_not:N
41364133
\cs:w environment~
41374134
\exp_last_unbraced:Ne \use_none:nnn
41384135
{ \cs_to_str:N #1 } ~end~aux \cs_end:

base/testfiles/github-0795.lvt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
\input test2e
2+
\START
3+
\def\test{\typeout{test}\fi}
4+
\AddToHook{cmd/test/after}{\typeout{hello}}
5+
\@kernel@after@begindocument
6+
\if11 % \fi comes from \test
7+
\test
8+
\END

base/testfiles/github-0795.tlg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is a generated file for the LaTeX2e validation system.
2+
Don't change this file in any respect.
3+
test
4+
hello

0 commit comments

Comments
 (0)