[latex3-commits] [git/LaTeX3-latex3-latex2e] hook-args: Correct one-time hooks with arguments (005d72e7)

PhelypeOleinik phelype.oleinik at latex-project.org
Sat Mar 11 03:06:36 CET 2023


Repository : https://github.com/latex3/latex2e
On branch  : hook-args
Link       : https://github.com/latex3/latex2e/commit/005d72e7c1b92080b8afc87432aeabee2f056ae0

>---------------------------------------------------------------

commit 005d72e7c1b92080b8afc87432aeabee2f056ae0
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Sun Feb 5 23:26:15 2023 -0300

    Correct one-time hooks with arguments


>---------------------------------------------------------------

005d72e7c1b92080b8afc87432aeabee2f056ae0
 base/lthooks.dtx                       | 10 +++++++++-
 base/testfiles-lthooks/lthooks-033.lvt |  6 ++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 6444cc95..482bf68f 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -5676,8 +5676,16 @@
   {
     \@@_preamble_hook:n {#1}
     \@@_use_once_set:n {#1}
+%    \end{macrocode}
+%   When a hook has arguments, the call to \cs{@@_use_initialized:n},
+%   should be the very last thing to happen, otherwise the arguments
+%   grabbed will be wrong.  So, to clean up after the hook we need to
+%   cheat a bit and sneak the cleanup code at the end of the hook,
+%   along with the next execution code.
+%    \begin{macrocode}
+    \@@_cs_gput_right:Nnnn \c_false_bool { _next }
+      {#1} { \@@_use_once_clear:n {#1} }
     \@@_use_initialized:n {#1}
-    \@@_use_once_clear:n {#1}
   }
 %<latexrelease>\EndIncludeInRelease
 %    \end{macrocode}
diff --git a/base/testfiles-lthooks/lthooks-033.lvt b/base/testfiles-lthooks/lthooks-033.lvt
index e01b7412..21def8e3 100644
--- a/base/testfiles-lthooks/lthooks-033.lvt
+++ b/base/testfiles-lthooks/lthooks-033.lvt
@@ -104,4 +104,10 @@
 \AddToHookNextWithArguments{no-args}{\typeout{no-next(#1,#2)}} % error, adds ##1, ##2
 \UseHook{no-args}
 
+%
+
+\NewHookWithArguments{use-once}{2}
+\AddToHookWithArguments{use-once}{\typeout{once(#1,#2)}}
+\UseOneTimeHookWithArguments{use-once}{foo}{bar}
+
 \END





More information about the latex3-commits mailing list.