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

\UseOneTimeHook changes undeclared hook to non-empty #1519

Open
muzimuzhi opened this issue Oct 30, 2024 · 0 comments
Open

\UseOneTimeHook changes undeclared hook to non-empty #1519

muzimuzhi opened this issue Oct 30, 2024 · 0 comments

Comments

@muzimuzhi
Copy link
Contributor

Brief outline of the bug

When used on an undeclared hook, \UseOneTimeHook changes it to non-empty. That is, \HookIfEmptyTF would use the false branch. \UseHook doesn't have this problem.

The hook becomes non-empty because its \__hook_next <hook> is defined by \UseOneTimeHook. Is this expected behavior? If so my fix in #1515 is partially wrong.

Found when digging into #1513.

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\ExplSyntaxOn
\cs_new_protected:Npn \test_hook:Nn #1#2
  {
    \iow_term:e {
      [before]~ if~empty:~ \hook_if_empty:nTF {#2} T
        { F \iow_newline: [before]~ next~code:~\cs_meaning:c { __hook_next~#2 } }
    }
    \iow_term:n { [execute]~#1 {#2} }
    #1 {#2}
    \iow_term:e {
      [after]~ if~empty:~ \hook_if_empty:nTF {#2} T
        { F \iow_newline: [after]~ next~code:~\cs_meaning:c { __hook_next~#2 } }
      \iow_newline:
    }
  }

\iow_log:n { !~debug }
\test_hook:Nn \hook_use_once:n { undeclared~hook }
\test_hook:Nn \hook_use_once:n { package/amsmath/after } % issue #1513

\test_hook:Nn \hook_use:n { undeclared~hook2 }
\ExplSyntaxOff

\begin{document}
\end{document}
[before] if empty: T
[execute] \hook_use_once:n {undeclared hook}
[after] if empty: F
[after] next code: \long macro:#1#2#3#4#5#6#7#8#9->\__hook_use_once_clear:n {un
declared hook}

[before] if empty: T
[execute] \hook_use_once:n {package/amsmath/after}
[after] if empty: F
[after] next code: \long macro:->\__hook_use_once_clear:n {package/amsmath/afte
r}

[before] if empty: T
[execute] \hook_use:n {undeclared hook2}
[after] if empty: T

Log file (required) and possibly PDF file

latex2e-UseOneTimeHook-changes-undeclared-hook-to-non-empty.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant