[latex3-commits] [git/LaTeX3-latex3-latex2e] hook-args: One-time-hooks after used don't take arguments (6ca42955)

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/6ca429550d884ec41115684eb06040ebb7561ff0

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

commit 6ca429550d884ec41115684eb06040ebb7561ff0
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Wed Feb 22 23:22:41 2023 -0300

    One-time-hooks after used don't take arguments


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

6ca429550d884ec41115684eb06040ebb7561ff0
 base/lthooks.dtx                       | 28 +++++++++++++++++++++++++---
 base/testfiles-lthooks/lthooks-033.lvt |  1 +
 base/testfiles-lthooks/lthooks-033.tlg | 10 ++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 482bf68f..39f29739 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -3288,7 +3288,7 @@
             \msg_error:nnnn { hooks } { without-args }
               {#1} { AddToHook }
           }
-        \@@_gput_code_store:nnNn
+        \@@_gput_code_normal:nnNn
       }
       { \@@_gput_code_normal:nnNn }
         {#1} {#2} #3
@@ -3301,7 +3301,10 @@
 % \changes{v1.0r}{2021/09/06}{Use dedicated conditional (gh/606)}
 %    \begin{macrocode}
     \@@_if_execute_immediately:nTF {#1}
-      { \use:n }
+      {
+        \msg_error:nnnn { hooks } { one-time-args } {#1} { AddToHook }
+        \use:n
+      }
       { \@@_gput_code_store:nnNn {#1} {#2} #3 }
   }
 \cs_new_protected:Npn \@@_gput_code_store:nnNn #1 #2 #3 #4
@@ -5989,6 +5992,9 @@
 %    \begin{macrocode}
 %<latexrelease>\IncludeInRelease{2023/06/01}{too-many-args}
 %<latexrelease>                 {Hooks~with~args}
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 \msg_new:nnnn { hooks } { too-many-args }
   { Too~many~arguments~for~hook~'#1'. }
   {
@@ -6005,10 +6011,26 @@
     You~tried~to~use~\iow_char:N\\#2WithArguments~
     on~a~hook~that~takes~no~arguments.\\
     Check~the~usage~of~the~hook~or~use~\iow_char:N\\#2~instead.\\
+    \\
     LaTeX~will~use~\iow_char:N\\#2.
   }
-%<latexrelease>\EndIncludeInRelease
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\msg_new:nnnn { hooks } { one-time-args }
+  { You~can't~have~arguments~in~used~one-time~hook~'#1'. }
+  {
+    You~tried~to~use~\iow_char:N\\#2WithArguments~
+    on~a~one-time~hook~that~has~already~been~used.~
+    You~have~to~add~the~code~before~the~hook~is~used,~
+    or~add~the~code~without~arguments~using~\iow_char:N\\#2~instead.\\
+    \\
+    LaTeX~will~use~\iow_char:N\\#2.
+  }
+%    \end{macrocode}
 %
+%    \begin{macrocode}
+%<latexrelease>\EndIncludeInRelease
 %<latexrelease>\IncludeInRelease{2020/10/01}{too-many-args}
 %<latexrelease>                 {Hooks~with~args}
 %<latexrelease>\EndIncludeInRelease
diff --git a/base/testfiles-lthooks/lthooks-033.lvt b/base/testfiles-lthooks/lthooks-033.lvt
index c8b1344a..7552ed0f 100644
--- a/base/testfiles-lthooks/lthooks-033.lvt
+++ b/base/testfiles-lthooks/lthooks-033.lvt
@@ -118,6 +118,7 @@
     \NewHookWithArguments{use-once}{2}
     \AddToHookWithArguments{use-once}{\typeout{once(#1,#2)}}
     \UseOneTimeHookWithArguments{use-once}{foo}{bar}
+    \AddToHookWithArguments{use-once}{\typeout{once(#1,#2)}}
   }
 
 \END
diff --git a/base/testfiles-lthooks/lthooks-033.tlg b/base/testfiles-lthooks/lthooks-033.tlg
index e8c61fc2..079454a1 100644
--- a/base/testfiles-lthooks/lthooks-033.tlg
+++ b/base/testfiles-lthooks/lthooks-033.tlg
@@ -215,4 +215,14 @@ no-next(##1,##2)
 TEST 5: One-time hook with arguments
 ============================================================
 once(foo,bar)
+! LaTeX hooks Error: You can't have arguments in used one-time hook
+(hooks)              'use-once'.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+You tried to use \AddToHookWithArguments on a one-time hook that has already
+been used. You have to add the code before the hook is used, or add the code
+without arguments using \AddToHook instead.
+LaTeX will use \AddToHook.
+once(##1,##2)
 ============================================================





More information about the latex3-commits mailing list.