[latex3-commits] [latex3/latex2e] develop: Raise different errors for empty label and empty hook (bd8616d0)
github at latex-project.org
github at latex-project.org
Mon Sep 2 15:00:14 CEST 2024
Repository : https://github.com/latex3/latex2e
On branch : develop
Link : https://github.com/latex3/latex2e/commit/bd8616d093fa909b637268ae7ff3a73f9f5951a6
>---------------------------------------------------------------
commit bd8616d093fa909b637268ae7ff3a73f9f5951a6
Author: Yukai Chou <muzimuzhi at gmail.com>
Date: Fri Aug 9 15:00:34 2024 +0800
Raise different errors for empty label and empty hook
See #1423.
>---------------------------------------------------------------
bd8616d093fa909b637268ae7ff3a73f9f5951a6
base/changes.txt | 4 +
base/doc/ltnews40.tex | 18 +++-
base/lthooks.dtx | 44 +++++++---
base/testfiles-lthooks/lthooks-errors.lvt | 94 +++++++++++++--------
base/testfiles-lthooks/lthooks-errors.tlg | 134 +++++++++++++++++++++++++++---
5 files changed, 231 insertions(+), 63 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index cf24264f..14b8d80c 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,10 @@ to completeness or accuracy and it contains some references to files that are
not part of the distribution.
================================================================================
+2024-08-09 Yukai Chou <muzimuzhi at gmail.com>
+ * lthooks.dtx: (subsection{Parsing a label})
+ Raise different errors for empty label and empty hook (gh/1423)
+
2024-07-27 Ulrike Fischer <Ulrike.Fischer at latex-project.org>
* lttagging.dtx: (subsection{Tagging support for table/tabular packages}):
Two sockets added to store and restore cell data when nesting tables to keep track
diff --git a/base/doc/ltnews40.tex b/base/doc/ltnews40.tex
index 7c639017..00f7b2ed 100644
--- a/base/doc/ltnews40.tex
+++ b/base/doc/ltnews40.tex
@@ -234,10 +234,26 @@ in a class would create two options, \texttt{draft} and \texttt{mode}. The
\texttt{draft} option will be treated in the normal way by packages using
keyvals, but they will ignore the \texttt{mode} option: it is effectively
marked as \enquote{private} to the class.
+%
+\githubissue{1279}
+\subsection{Improved error raised by empty hook}
+
+When using the hook management, both hook and label names (if specified)
+should be non-empty. Before empty hook and empty label both raised the
+same label-specific error.
+\begin{verbatim}
+! LaTeX hooks Error: Empty code label on line ....
+ Using 'top-level' instead.
+\end{verbatim}
+This has now been improved. Now empty hook raises
+\begin{verbatim}
+! LaTeX hooks Error: Empty hook on line ....
+\end{verbatim}
+%
+\githubissue{1423}
-\githubissue{1279}
\section{Bug fixes}
diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index aed23ab1..9e4450d6 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -32,7 +32,7 @@
%<*driver>
% \fi
\ProvidesFile{lthooks.dtx}
- [2024/07/08 v1.1h LaTeX Kernel (hooks)]
+ [2024/08/09 v1.1i LaTeX Kernel (hooks)]
% \iffalse
%
\documentclass{l3doc}
@@ -3298,21 +3298,26 @@
%
% \subsection{Parsing a label}
%
-% \begin{macro}[EXP]{\@@_parse_label_default:n}
+% \begin{macro}[EXP]{\@@_parse_label_default:nN}
% This macro checks if a label was given (not \cs{c_novalue_tl}), and
% if so, tries to parse the label looking for a leading \verb|.| to
% replace by \cs{@@_currname_or_default:}.
+% |#2| is a boolean representing if |#1| is a label name.
+% \changes{v1.1i}{2024/08/09}
+% {Distinguish between empty label and empty hook (gh/1423)}
% \begin{macrocode}
-\cs_new:Npn \@@_parse_label_default:n #1
+\cs_new:Npn \@@_parse_label_default:nN #1#2
{
\tl_if_novalue:nTF {#1}
{ \@@_currname_or_default: }
- { \tl_trim_spaces_apply:nN {#1} \@@_parse_dot_label:n }
+ { \tl_trim_spaces_apply:nN {#1} \@@_parse_dot_label:nN #2 }
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[EXP]{\@@_parse_dot_label:n}
+% \begin{macro}[EXP]{\@@_parse_dot_label:nN}
+% \changes{v1.1i}{2024/08/09}
+% {Distinguish between empty label and empty hook (gh/1423)}
% \begin{macro}[EXP]{
% \@@_parse_dot_label:w,
% \@@_parse_dot_label_cleanup:w,
@@ -3325,12 +3330,15 @@
% If these requirements are fulfilled, the leading
% \verb|.| is replaced with \cs{@@_currname_or_default:}. Otherwise
% the label is returned unchanged.
+% |#2| is a boolean representing if |#1| is a label name.
% \begin{macrocode}
-\cs_new:Npn \@@_parse_dot_label:n #1
+\cs_new:Npn \@@_parse_dot_label:nN #1#2
{
\tl_if_empty:nTF {#1}
{
- \msg_expandable_error:nn { hooks } { empty-label }
+ \bool_if:NTF #2
+ { \msg_expandable_error:nn { hooks } { empty-label } }
+ { \msg_expandable_error:nn { hooks } { empty-hook } }
\@@_currname_or_default:
}
{
@@ -3407,6 +3415,8 @@
% macro does the entire operation within a group so that csnames made
% by \cs{@@_make_name:n} are wiped off before continuing. This means
% that this function cannot be used for \cs{hook_use:n}!
+% \changes{v1.1i}{2024/08/09}
+% {Distinguish between empty label and empty hook (gh/1423)}
% \begin{macrocode}
\cs_new_protected:Npn \@@_normalize_hook_args_aux:Nn #1 #2
{
@@ -3420,24 +3430,24 @@
\cs_new_protected:Npn \@@_normalize_hook_args:Nn #1 #2
{
\@@_normalize_hook_args_aux:Nn #1
- { { \@@_parse_label_default:n {#2} } }
+ { { \@@_parse_label_default:nN {#2} \c_false_bool } }
}
\cs_new_protected:Npn \@@_normalize_hook_args:Nnn #1 #2 #3
{
\@@_normalize_hook_args_aux:Nn #1
{
- { \@@_parse_label_default:n {#2} }
- { \@@_parse_label_default:n {#3} }
+ { \@@_parse_label_default:nN {#2} \c_false_bool }
+ { \@@_parse_label_default:nN {#3} \c_true_bool }
}
}
\cs_new_protected:Npn \@@_normalize_hook_rule_args:Nnnnn #1 #2 #3 #4 #5
{
\@@_normalize_hook_args_aux:Nn #1
{
- { \@@_parse_label_default:n {#2} }
- { \@@_parse_label_default:n {#3} }
+ { \@@_parse_label_default:nN {#2} \c_false_bool }
+ { \@@_parse_label_default:nN {#3} \c_true_bool }
{ \tl_trim_spaces:n {#4} }
- { \@@_parse_label_default:n {#5} }
+ { \@@_parse_label_default:nN {#5} \c_true_bool }
}
}
% \end{macrocode}
@@ -7374,6 +7384,14 @@
}
% \end{macrocode}
%
+% \changes{v1.1i}{2024/08/09}{New message ``empty-hook'' (gh/1423).}
+% \begin{macrocode}
+\msg_new:nnn { hooks } { empty-hook }
+ {
+ Empty~hook~name~\msg_line_context:.
+ }
+% \end{macrocode}
+%
% \begin{macrocode}
\msg_new:nnn { hooks } { no-default-label }
{
diff --git a/base/testfiles-lthooks/lthooks-errors.lvt b/base/testfiles-lthooks/lthooks-errors.lvt
index 07ae6a6d..6ab9a691 100644
--- a/base/testfiles-lthooks/lthooks-errors.lvt
+++ b/base/testfiles-lthooks/lthooks-errors.lvt
@@ -10,22 +10,36 @@
\START
+\NewHook{xxx}
\NewReversedHook{yyy}
+\NewHookWithArguments{zzz}{1}
-% activate-error
-\DisableGenericHook{yyy}
+% no message!
+\TEST{activate-error}{
+ \DisableGenericHook{yyy}
+}
-% activate-disabled
-\ActivateGenericHook{yyy}
+\TEST{Message "activate-disabled"}{
+ \ActivateGenericHook{yyy}
+}
-% hook-disabled
-\AddToHook{yyy}{error}
+\TEST{Message "hook-disabled"}{
+ \AddToHook{yyy}{error}
+}
-% empty-label
-\AddToHook{yyy}[]{error}
+\TEST{Message "empty-hook"}{
+ \AddToHook{}{error}
+ \AddToHookWithArguments{}{error '#1'}
+}
-% no-default-label
-\PushDefaultHookLabel{}
+\TEST{Message "empty-label"}{
+ \AddToHook{yyy}[]{error}
+ \AddToHookWithArguments{zzz}[]{error '#1'}
+}
+
+\TEST{Message "no-default-label"}{
+ \PushDefaultHookLabel{}
+}
\AddToHook{xxx}[label1]{ foo1}
\AddToHook{xxx}[label2]{ foo2}
@@ -33,39 +47,47 @@
\AddToHook{xxx}[label4]{ foo3}
\AddToHook{xxx}[label5]{ foo5}
-% unknown-rule
-\DeclareHookRule {xxx} {label1} {unknown} {label2}
+\TEST{Message "empty-hook"}{
+ \DeclareHookRule{}{label1}{unrelated}{label2}
+}
-% labels-incompatible warning
-\DeclareHookRule {xxx} {label3} {incompatible-warning} {label4}
+\TEST{Message "empty-label"}{
+ \DeclareHookRule{xxx}{label1}{before}{}
+ \DeclareHookRule{xxx}{} {after} {label2}
+}
-% labels-incompatible error
-\DeclareHookRule {xxx} {label1} {incompatible-error} {label5}
+\TEST{Message "unknown-rule"}{
+ \DeclareHookRule {xxx} {label1} {unknown} {label2}
+}
-\LogHook{xxx}
+\TEST{"labels-incompatible" warning and error}{
+ \DeclareHookRule {xxx} {label3} {incompatible-warning} {label4}
+ \DeclareHookRule {xxx} {label1} {incompatible-error} {label5}
+ \LogHook{xxx}
+}
\makeatletter
\@expl@@@filehook at file@pop@@
-% set-top-level
-\SetDefaultHookLabel{my-document}
-
-\AddToHook{begindocument}[top-level]{\TIMO\typeout{allowed}\OMIT}
-\PushDefaultHookLabel{my-document}
- % top-level not allowed with other labels
- % misused-top-level
- \AddToHook{begindocument}[top-level]{not allowed}
- % set-top-level
- \SetDefaultHookLabel{top-level}
-\PopDefaultHookLabel
-
-% extra-pop-label
-\PopDefaultHookLabel
-
-% missing-pop-label
-\PushDefaultHookLabel{error}
-\PushDefaultHookLabel{should}
-\PushDefaultHookLabel{this}
+\TEST{Message "set-top-level" and "misused-top-level"}{
+ \SetDefaultHookLabel{my-document}
+ \AddToHook{begindocument}[top-level]{\TIMO\typeout{allowed}\OMIT}
+ \PushDefaultHookLabel{my-document}
+ % top-level not allowed with other labels
+ \AddToHook{begindocument}[top-level]{not allowed}
+ \SetDefaultHookLabel{top-level}
+ \PopDefaultHookLabel
+}
+
+\TEST{Message "extra-pop-label"}{
+ \PopDefaultHookLabel
+}
+
+\TEST{Message "missing-pop-label"}{
+ \PushDefaultHookLabel{error}
+ \PushDefaultHookLabel{should}
+ \PushDefaultHookLabel{this}
+}
\OMIT
\begin{document}
diff --git a/base/testfiles-lthooks/lthooks-errors.tlg b/base/testfiles-lthooks/lthooks-errors.tlg
index f39200d8..6cc9eb7d 100644
--- a/base/testfiles-lthooks/lthooks-errors.tlg
+++ b/base/testfiles-lthooks/lthooks-errors.tlg
@@ -1,17 +1,52 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
+============================================================
+TEST 1: activate-error
+============================================================
+============================================================
+============================================================
+TEST 2: Message "activate-disabled"
+============================================================
LaTeX hooks Warning: Cannot activate hook 'yyy' because it is disabled!
+============================================================
+============================================================
+TEST 3: Message "hook-disabled"
+============================================================
! LaTeX hooks Error: Cannot add code to disabled hook 'yyy'.
For immediate help type H <return>.
...
-l. ...\AddToHook{yyy}{error}
+l. ...}
The hook 'yyy' you tried to add code to was previously disabled with
\hook_disable_generic:n or \DisableGenericHook, so it cannot have code added
to it.
+============================================================
+============================================================
+TEST 4: Message "empty-hook"
+============================================================
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty hook name on line ....
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty hook name on line ....
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+============================================================
+============================================================
+TEST 5: Message "empty-label"
+============================================================
! Use of \??? doesn't match its definition.
<argument> \???
! LaTeX hooks Error: Empty code label on line .... Using 'to...
-l. ...\AddToHook{yyy}[]{error}
+l. ...}
If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
@@ -19,43 +54,104 @@ followed by the required stuff, so I'm ignoring it.
! LaTeX hooks Error: Cannot add code to disabled hook 'yyy'.
For immediate help type H <return>.
...
-l. ...\AddToHook{yyy}[]{error}
+l. ...}
The hook 'yyy' you tried to add code to was previously disabled with
\hook_disable_generic:n or \DisableGenericHook, so it cannot have code added
to it.
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty code label on line .... Using 'to...
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+============================================================
+============================================================
+TEST 6: Message "no-default-label"
+============================================================
! LaTeX hooks Error: Missing (empty) default label on line ....
(hooks) This command was ignored.
Type <return> to continue.
...
-l. ...\PushDefaultHookLabel{}
+l. ...}
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.
+============================================================
+============================================================
+TEST 7: Message "empty-hook"
+============================================================
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty hook name on line ....
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+============================================================
+============================================================
+TEST 8: Message "empty-label"
+============================================================
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty code label on line .... Using 'to...
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+! Use of \??? doesn't match its definition.
+<argument> \???
+ ! LaTeX hooks Error: Empty code label on line .... Using 'to...
+l. ...}
+If you say, e.g., `\def\a1{...}', then you must always
+put `1' after `\a', since control sequence names are
+made up of letters only. The macro here has not been
+followed by the required stuff, so I'm ignoring it.
+============================================================
+============================================================
+TEST 9: Message "unknown-rule"
+============================================================
! LaTeX hooks Error: Unknown relationship 'unknown' between labels 'label1'
(hooks) and 'label2' in hook 'xxx'. Perhaps a misspelling?
For immediate help type H <return>.
...
-l. ......HookRule {xxx} {label1} {unknown} {label2}
+l. ...}
The relation used not known to the system. Allowed values are 'before' or '<',
'after' or '>', 'incompatible-warning', 'incompatible-error', 'voids' or
'unrelated'.
+============================================================
+============================================================
+TEST 10: "labels-incompatible" warning and error
+============================================================
+LaTeX hooks Warning: Labels 'label4' and 'label3' are incompatible in hook
+(hooks) 'xxx'. You may see errors later.
+! LaTeX hooks Error: Labels 'label5' and 'label1' are incompatible in hook
+(hooks) 'xxx'. The code for both labels will be dropped.
+For immediate help type H <return>.
+ ...
+l. ...}
+LaTeX found two incompatible labels in the same hook. This indicates an
+incompatibility between packages.
-> The hook 'xxx':
-> The hook is not declared.
> Code chunks:
> label1 -> foo1
> label2 -> foo2
> label3 -> foo2
> label4 -> foo3
> label5 -> foo5
-> Document-level (top-level) code:
+> Document-level (top-level) code (executed last):
> ---
> Extra code for next invocation:
> ---
> Rules:
> label4|label3 with relation xW
> label5|label1 with relation xE
-> Execution order:
-> Not set because the hook is undeclared.
+> Execution order (after applying rules):
+> label1, label2, label3, label4, label5.
+============================================================
! LaTeX kernel Error: This should not happen. Tried to pop from an empty file
(kernel) name stack.
(kernel) Please report at https://github.com/latex3/latex2e.
@@ -65,13 +161,16 @@ l. ...\@expl@@@filehook at file@pop@@
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.
+============================================================
+TEST 11: Message "set-top-level" and "misused-top-level"
+============================================================
! LaTeX 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}
+l. ...}
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.
@@ -79,7 +178,7 @@ If that doesn't work, type X <return> to quit.
(hooks) 'top-level' is reserved for the user's document.
For immediate help type H <return>.
...
-l. ......ook{begindocument}[top-level]{not allowed}
+l. ...}
The 'top-level' label is meant for user code only, and should only be used
(sparingly) in the main document. Use the default label 'my-document' for this
file, or another suitable label.
@@ -89,18 +188,27 @@ file, or another suitable label.
(hooks) on line ....
Type <return> to continue.
...
-l. ... \SetDefaultHookLabel{top-level}
+l. ...}
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.
+============================================================
+============================================================
+TEST 12: Message "extra-pop-label"
+============================================================
! LaTeX hooks Error: Extra \PopDefaultHookLabel.
(hooks) This command will be ignored.
Type <return> to continue.
...
-l. ...\PopDefaultHookLabel
+l. ...}
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.
+============================================================
+============================================================
+TEST 13: Message "missing-pop-label"
+============================================================
+============================================================
allowed
! LaTeX hooks Error: Missing \PopDefaultHookLabel.
(hooks) The label 'this' was pushed but never popped. Something
More information about the latex3-commits
mailing list.