summaryrefslogtreecommitdiff
path: root/macros/latex-dev/base/ltcmdhooks.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex-dev/base/ltcmdhooks.dtx')
-rw-r--r--macros/latex-dev/base/ltcmdhooks.dtx87
1 files changed, 62 insertions, 25 deletions
diff --git a/macros/latex-dev/base/ltcmdhooks.dtx b/macros/latex-dev/base/ltcmdhooks.dtx
index 40cd55e52c..b6c57a41ac 100644
--- a/macros/latex-dev/base/ltcmdhooks.dtx
+++ b/macros/latex-dev/base/ltcmdhooks.dtx
@@ -13,8 +13,8 @@
%
%%% From File: ltcmdhooks.dtx
%
-\def\ltcmdhooksversion{v1.0b}
-\def\ltcmdhooksdate{2021/05/26}
+\def\ltcmdhooksversion{v1.0d}
+\def\ltcmdhooksdate{2021/08/25}
%
%
%
@@ -400,24 +400,44 @@
%
% \subsection{Patching or delaying}
%
-% \begin{macro}{\@@_try_put_cmd_hook:n,\@@_try_put_cmd_hook:w}
% Before |\begin{document}| all patching is delayed.
+%
+% \begin{macro}{\@@_try_put_cmd_hook:n,\@@_try_put_cmd_hook:w}
% This function is called from within \cs{AddToHook}, when code is
-% added to a generic |cmd| hook is newly declared. It checks whether
-% the patch position is valid, then proceeds to trying to patch or
-% delaying to |\begin{document}| if in the preamble.
+% first added to a generic |cmd| hook.
+% If it is called within in the preamble, it delays the action
+% until |\begin{document}|;
+% otherwise it tries to update the hook.
+% \changes{v1.0d}{2021/08/25}{Simplify generic hook detection}
% \begin{macrocode}
+%<latexrelease>\IncludeInRelease{2021/11/15}{\@@_try_put_cmd_hook:n}%
+%<latexrelease> {Standardise~generic~hook~names}
\cs_new_protected:Npn \@@_try_put_cmd_hook:n #1
{ \@@_try_put_cmd_hook:w #1 / / / \s_@@_mark {#1} }
\cs_new_protected:Npn \@@_try_put_cmd_hook:w
#1 / #2 / #3 / #4 \s_@@_mark #5
{
\@@_debug:n { \iow_term:n { ->~Adding~cmd~hook~to~'#2'~(#3): } }
- \str_case:nnTF {#3}
- { { before } { } { after } { } }
- { \exp_args:Nc \@@_patch_cmd_or_delay:Nnn {#2} {#2} {#3} }
- { \msg_error:nnnn { hooks } { wrong-cmd-hook } {#2} {#3} }
+ \exp_args:Nc \@@_patch_cmd_or_delay:Nnn {#2} {#2} {#3}
}
+%<latexrelease>\EndIncludeInRelease
+% \end{macrocode}
+%
+% \begin{macrocode}
+%<latexrelease>\IncludeInRelease{2021/06/01}{\@@_try_put_cmd_hook:n}%
+%<latexrelease> {Standardise~generic~hook~names}
+%<latexrelease>\cs_new_protected:Npn \@@_try_put_cmd_hook:n #1
+%<latexrelease> { \@@_try_put_cmd_hook:w #1 / / / \s_@@_mark {#1} }
+%<latexrelease>\cs_new_protected:Npn \@@_try_put_cmd_hook:w
+%<latexrelease> #1 / #2 / #3 / #4 \s_@@_mark #5
+%<latexrelease> {
+%<latexrelease> \@@_debug:n { \iow_term:n { ->~Adding~cmd~hook~to~'#2'~(#3): } }
+%<latexrelease> \str_case:nnTF {#3}
+%<latexrelease> { { before } { } { after } { } }
+%<latexrelease> { \exp_args:Nc \@@_patch_cmd_or_delay:Nnn {#2} {#2} {#3} }
+%<latexrelease> { \msg_error:nnnn { hooks } { wrong-cmd-hook } {#2} {#3} }
+%<latexrelease> }
+%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
% \end{macro}
%
@@ -592,17 +612,28 @@
%
% With \cs{@@_patch_DeclareRobustCommand:Nnn} we check if the command
% has an optional argument (with a test counter-intuitively called
-% \tn{@if@newcommand}). If so, we forward the action to
-% \cs{@@_patch_newcommand:Nnn}, otherwise call the patching engine
+% \tn{@if@newcommand}; also make sure the command doesn't take args by
+% calling \cs{robust@command@chk@safe}). If so, we pass the patching action
+% to \cs{@@_patch_newcommand:Nnn}, otherwise we call the patching engine
% \cs{@@_patch_expand_redefine:NNnn} with a \cs{c_false_bool} to
% indicate that there is no optional argument.
+%
+% \changes{v1.0c}{2021/07/20}
+% {Use \cs{robust@command@chk@safe} before \cs{@if@newcommand}.}
% \begin{macrocode}
\cs_new_protected:Npn \@@_patch_DeclareRobustCommand:Nnn #1
{
- \exp_args:Nc \@if@newcommand { \cs_to_str:N #1 ~ }
- { \exp_args:Nc \@@_patch_newcommand:Nnn }
- { \exp_args:NNc \@@_patch_expand_redefine:NNnn \c_false_bool }
- { \cs_to_str:N #1 ~ }
+ \exp_args:Nc \@@_patch_DeclareRobustCommand_aux:Nnn
+ { \cs_to_str:N #1 ~ }
+ }
+\cs_new_protected:Npn \@@_patch_DeclareRobustCommand_aux:Nnn #1
+ {
+ \robust@command@chk@safe #1
+ { \@if@newcommand #1 }
+ { \use_ii:nn }
+ { \@@_patch_newcommand:Nnn }
+ { \@@_patch_expand_redefine:NNnn \c_false_bool }
+ #1
}
% \end{macrocode}
% \end{macro}
@@ -1039,15 +1070,21 @@
% \subsection{Messages}
%
% \begin{macrocode}
-\msg_new:nnnn { hooks } { wrong-cmd-hook }
- {
- Generic~hook~`cmd/#1/#2'~is~invalid.
-% The~hook~should~be~`cmd/#1/before'~or~`cmd/#1/after'.
- }
- {
- You~tried~to~add~a~generic~hook~to~command~\iow_char:N \\#1,~but~`#2'~
- is~an~invalid~component.~Only~`before'~or~`after'~are~allowed.
- }
+%<latexrelease>\IncludeInRelease{2021/11/15}{wrong-cmd-hook}%
+%<latexrelease> {Standardise~generic~hook~names}
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{2021/11/15}{wrong-cmd-hook}%
+%<latexrelease> {Standardise~generic~hook~names}
+%<latexrelease>\msg_new:nnnn { hooks } { wrong-cmd-hook }
+%<latexrelease> {
+%<latexrelease> Generic~hook~`cmd/#1/#2'~is~invalid.
+%<latexrelease>% The~hook~should~be~`cmd/#1/before'~or~`cmd/#1/after'.
+%<latexrelease> }
+%<latexrelease> {
+%<latexrelease> You~tried~to~add~a~generic~hook~to~command~\iow_char:N \\#1,~but~`#2'~
+%<latexrelease> is~an~invalid~component.~Only~`before'~or~`after'~are~allowed.
+%<latexrelease> }
+%<latexrelease>\EndIncludeInRelease
\msg_new:nnnn { hooks } { cant-patch }
{
Generic~hooks~cannot~be~added~to~'#1'.