Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\ShowHook of package hook errors if called after the package has already been loaded #1513

Open
gusbrs opened this issue Oct 28, 2024 · 4 comments
Labels
bug category base (latex) fixed in dev Fixed in development branch, not in stable release

Comments

@gusbrs
Copy link

gusbrs commented Oct 28, 2024

Brief outline of the bug

An attempt to \ShowHook of a package hook after the package has already been loaded results in error ! File ended while scanning use of \prg_map_break:Nn.

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}

\usepackage{amsmath}

\ShowHook{package/amsmath/after}

\begin{document}
Hello World.
\end{document}

Log file (required) and possibly PDF file

This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=pdflatex 2024.10.23)  28 OCT 2024 16:22
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**document.tex
(./document.tex
LaTeX2e <2024-06-01> patch level 2
L3 programming layer <2024-10-09>
(/usr/local/texlive/2024/texmf-dist/tex/latex/latexbug/latexbug.sty
Package: latexbug 2024/06/17 v1.0o Bug-classification
)
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/article.cls
Document Class: article 2024/02/08 v1.4n Standard LaTeX document class
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2024/02/08 v1.4n Standard LaTeX file (size option)
)
\c@part=\count194
\c@section=\count195
\c@subsection=\count196
\c@subsubsection=\count197
\c@paragraph=\count198
\c@subparagraph=\count199
\c@figure=\count266
\c@table=\count267
\abovecaptionskip=\skip49
\belowcaptionskip=\skip50
\bibindent=\dimen141
)
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2024/05/23 v2.17q AMS math features
\@mathmargin=\skip51

For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2021/08/26 v2.01 AMS text

(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0 generic functions
\@emptytoks=\toks17
\ex@=\dimen142
))
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d Bold Symbols
\pmbraise@=\dimen143
)
(/usr/local/texlive/2024/texmf-dist/tex/latex/amsmath/amsopn.sty
Package: amsopn 2022/04/08 v2.04 operator names
)
\inf@bad=\count268
LaTeX Info: Redefining \frac on input line 233.
\uproot@=\count269
\leftroot@=\count270
LaTeX Info: Redefining \overline on input line 398.
LaTeX Info: Redefining \colon on input line 409.
\classnum@=\count271
\DOTSCASE@=\count272
LaTeX Info: Redefining \ldots on input line 495.
LaTeX Info: Redefining \dots on input line 498.
LaTeX Info: Redefining \cdots on input line 619.
\Mathstrutbox@=\box52
\strutbox@=\box53
LaTeX Info: Redefining \big on input line 721.
LaTeX Info: Redefining \Big on input line 722.
LaTeX Info: Redefining \bigg on input line 723.
LaTeX Info: Redefining \Bigg on input line 724.
\big@size=\dimen144
LaTeX Font Info:    Redeclaring font encoding OML on input line 742.
LaTeX Font Info:    Redeclaring font encoding OMS on input line 743.
\macc@depth=\count273
LaTeX Info: Redefining \bmod on input line 904.
LaTeX Info: Redefining \pmod on input line 909.
LaTeX Info: Redefining \smash on input line 939.
LaTeX Info: Redefining \relbar on input line 969.
LaTeX Info: Redefining \Relbar on input line 970.
\c@MaxMatrixCols=\count274
\dotsspace@=\muskip17
\c@parentequation=\count275
\dspbrk@lvl=\count276
\tag@help=\toks18
\row@=\count277
\column@=\count278
\maxfields@=\count279
\andhelp@=\toks19
\eqnshift@=\dimen145
\alignsep@=\dimen146
\tagshift@=\dimen147
\tagwidth@=\dimen148
\totwidth@=\dimen149
\lineht@=\dimen150
\@envbody=\toks20
\multlinegap=\skip52
\multlinetaggap=\skip53
\mathdisplay@stack=\toks21
LaTeX Info: Redefining \[ on input line 2953.
LaTeX Info: Redefining \] on input line 2954.
)

-> The generic hook 'package/amsmath/after':
> The hook is not declared.
> Code chunks:
)
Runaway argument?
{\int_gdecr:N \g__kernel_prg_map_int \cs_gset_eq:Nc \__prop_pair:wn {\ETC.
! File ended while scanning use of \prg_map_break:Nn.
<inserted text> 
                \par 
<*> document.tex
                
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

! Emergency stop.
<*> document.tex
                
*** (job aborted, no legal \end found)

 
Here is how much of TeX's memory you used:
 2294 strings out of 473577
 46787 string characters out of 5728195
 416206 words of memory out of 5000000
 25265 multiletter control sequences out of 15000+600000
 558069 words of font info for 36 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 56i,0n,65p,204b,1346s stack positions out of 10000i,1000n,20000p,200000b,200000s
!  ==> Fatal error occurred, no output PDF file produced!
@muzimuzhi
Copy link
Contributor

muzimuzhi commented Oct 28, 2024

Oh \ShowHook maps over an internal l3prop variable \g__hook_<hook-name>_code_prop (multiple times, see lines 6189 and 6240) without checking its existence first.

Need to check if there are similar remaining cases.

Update: The behavior that mapping over an undeclared prop raises errors only happens since l3kernel 2024-02-13 added linked property variable.

latex2e/base/lthooks.dtx

Lines 6185 to 6189 in b1e172c

\@@_log_line:x { Code~chunks: }
\prop_if_empty:cTF { g_@@_#1_code_prop }
{ \@@_log_line_indent:x { --- } }
{
\prop_map_inline:cn { g_@@_#1_code_prop }

latex2e/base/lthooks.dtx

Lines 6238 to 6240 in b1e172c

\@@_log_line:x { Rules: }
\bool_set_true:N \l_@@_tmpa_bool
\@@_list_rules:nn {#1}

@muzimuzhi
Copy link
Contributor

Aside: currently \hook_if_empty:nTF is true even if the corresponding \g__hook_<hook-name>_code_prop does not exist. Is this by design?

latex2e/base/lthooks.dtx

Lines 7056 to 7069 in b1e172c

\prg_new_conditional:Npnn \hook_if_empty:n #1 { p , T , F , TF }
{
\if:w
T
\prop_if_exist:cT { g_@@_#1_code_prop }
{ \prop_if_empty:cF { g_@@_#1_code_prop } { F } }
\@@_cs_if_empty:cF { @@_toplevel~#1 } { F }
\@@_cs_if_empty:cF { @@_next~#1 } { F }
T
\prg_return_true:
\else:
\prg_return_false:
\fi:
}

@FrankMittelbach
Copy link
Member

Aside: currently \hook_if_empty:nTF is true even if the corresponding \g__hook_<hook-name>_code_prop does not exist. Is this by design?

of the top of my head, yes. A conditional is either true or false, and saying that a not (yet) existing hook "empty" makes more sense than claiming it is non-empty. If I remember correctly it is documented as this.

@FrankMittelbach
Copy link
Member

Update: The behavior that mapping over an undeclared prop raises errors only happens since l3kernel 2024-02-13 added linked property variable.

hmm, yes, I can see that this may have stopped working but did so in the past (by mistake more or less).

muzimuzhi added a commit to muzimuzhi/latex2e that referenced this issue Oct 28, 2024
josephwright pushed a commit that referenced this issue Oct 29, 2024
* Skip mapping over undeclared `\g__hook_<hook>_code_prop` (#1513)

* add test github-1513

* switch to a package available to CI
@josephwright josephwright added the fixed in dev Fixed in development branch, not in stable release label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category base (latex) fixed in dev Fixed in development branch, not in stable release
Projects
Status: Pool (unscheduled issues)
Development

No branches or pull requests

4 participants