[latex3-commits] [git/LaTeX3-latex3-latex2e] hotfix/gh441: Changing the top-level label is an error (9d1b243c)

PhelypeOleinik phelype.oleinik at latex-project.org
Wed Dec 16 01:37:48 CET 2020


Repository : https://github.com/latex3/latex2e
On branch  : hotfix/gh441
Link       : https://github.com/latex3/latex2e/commit/9d1b243cce4323e92782c2e926d7ae0568814801

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

commit 9d1b243cce4323e92782c2e926d7ae0568814801
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Tue Dec 15 21:37:48 2020 -0300

    Changing the top-level label is an error
    
    Changing to top-level from within a package, and changing from top-level to another label


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

9d1b243cce4323e92782c2e926d7ae0568814801
 base/lthooks.dtx                       | 19 ++++++++++++++++++-
 base/testfiles-lthooks/lthooks-024.tlg | 18 ++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index e4ba442c..45f46761 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -4088,7 +4088,23 @@
 %   argument, and updates \cs{g_@@_hook_curr_name_tl} accordingly.
 %    \begin{macrocode}
 \NewDocumentCommand \SetDefaultHookLabel { m }
-  { \tl_gset:Nx \g_@@_hook_curr_name_tl { \@@_make_name:n {#1} } }
+  {
+    \seq_if_empty:NTF \g_@@_name_stack_seq
+      { \msg_error:nnnn { hooks } { set-top-level } { for } {#1} }
+      { \exp_args:Nx \@@_set_default_label:n { \@@_make_name:n {#1} } }
+  }
+\cs_new_protected:Npn \@@_set_default_label:n #1
+  {
+    \str_if_eq:nnTF {#1} { top-level }
+      { \msg_error:nnnn { hooks } { set-top-level } { to } {#1} }
+      { \tl_gset:Nx \g_@@_hook_curr_name_tl {#1} }
+  }
+\msg_new:nnn { hooks } { set-top-level }
+  {
+    You~cannot~change~the~default~label~#1~`top-level'.~Illegal \\
+    \use:nn { ~ } { ~ } \iow_char:N \\SetDefaultHookLabel{#2} \\
+    \msg_line_context:.
+  }
 \NewDocumentCommand \DeclareDefaultHookLabel { m }
   {
     \msg_error:nn { hooks } { ddhl-deprecated }
@@ -4110,6 +4126,7 @@
 \NewDocumentCommand \PopDefaultHookLabel { }
   { \@@_curr_name_pop: }
 %    \end{macrocode}
+%
 %   The current label stack holds the labels for all files but the
 %   current one (more or less like \cs{@currnamestack}), and the current
 %   label token list, \cs{g_@@_hook_curr_name_tl}, holds the label for
diff --git a/base/testfiles-lthooks/lthooks-024.tlg b/base/testfiles-lthooks/lthooks-024.tlg
index 4cb8a770..db335288 100644
--- a/base/testfiles-lthooks/lthooks-024.tlg
+++ b/base/testfiles-lthooks/lthooks-024.tlg
@@ -165,9 +165,19 @@ and I'll forget about whatever was undefined.
 >     ---
 > Execution order:
 >     top-level/foo.
+! Package hooks Error: You cannot change the default label for `top-level'.
+(hooks)                Illegal
+(hooks)                  \SetDefaultHookLabel{my-document}
+(hooks)                on line ....
+Type <return> to continue.
+ ...                                              
+l. ...\SetDefaultHookLabel{my-document}
+LaTeX does not know anything more about this error, sorry.
+Try typing <return> to proceed.
+If that doesn't work, type X <return> to quit.
 -> The hook 'foo':
 > Code chunks:
->     my-document/foo -> my-document/foo
+>     top-level/foo -> my-document/foo
 > Document-level (top-level) code (executed last):
 >     ---
 > Extra code for next invocation:
@@ -175,7 +185,7 @@ and I'll forget about whatever was undefined.
 > Rules:
 >     ---
 > Execution order:
->     my-document/foo.
+>     top-level/foo.
 (lthooks-024-pkgA.sty
 -> The hook 'foo':
 > Code chunks:
@@ -239,7 +249,7 @@ and I'll forget about whatever was undefined.
 )
 -> The hook 'foo':
 > Code chunks:
->     my-document/foo -> my-document/foo
+>     top-level/foo -> my-document/foo
 > Document-level (top-level) code (executed last):
 >     ---
 > Extra code for next invocation:
@@ -247,4 +257,4 @@ and I'll forget about whatever was undefined.
 > Rules:
 >     ---
 > Execution order:
->     my-document/foo.
+>     top-level/foo.





More information about the latex3-commits mailing list.