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

\hook_debug_on: does not log changes made by AddToHookNext #1459

Open
ysalmon opened this issue Sep 6, 2024 · 3 comments
Open

\hook_debug_on: does not log changes made by AddToHookNext #1459

ysalmon opened this issue Sep 6, 2024 · 3 comments

Comments

@ysalmon
Copy link

ysalmon commented Sep 6, 2024

Brief outline of the bug

I am trying to debug some code that uses AddToHookNext and ClearHookNext with \hook_debug_on:. However, these do not seem to be tracked by it. When modifying a cmd hook, there is a trace in the log as lthooks analyses the command, but the actual update is not logged with as much precision as with AddToHook. And for the para hook, nothing shows.

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\hook_debug_on:
\ExplSyntaxOff
\AddToHookNext{cmd/par/before}{\relax}
\AddToHookNext{para/before}{\relax}
contenu...
\ExplSyntaxOn
\hook_debug_off:
\ExplSyntaxOff
\end{document}

Log file (required) and possibly PDF file

texstudio_FNpaGC.log

@FrankMittelbach
Copy link
Member

If your code really attempts to add a hook into \par then I'm not surprised that you need to debug it. This can't work, because LaTeX redefines \par back and forth all over the place, so the cmd/par/before would vanish again from the definition of \par leaving the whole setup in a strange state.

@FrankMittelbach
Copy link
Member

\documentclass{article}
\begin{document}
\DebugHooksOn

\AddToHookNext{cmd/par/before}{\typeout{-> cmdHook1}}
\AddToHook{para/before}{\typeout{-> before hook always}}
\AddToHookNext{para/before}{\typeout{-> before hook1}}
\ShowHook{cmd/par/before}
\ShowCommand\par
contenu...

\begin{itemize}
\item
\end{itemize}

\ShowHook{cmd/par/before}
\ShowCommand\par            % <--- cmd hook lost

\AddToHookNext{cmd/par/before}{\typeout{-> cmdHook2}}
\AddToHookNext{para/before}{\typeout{-> before hook2}}
\ShowHook{cmd/par/before}   % <--- but still believed to be there
\ShowCommand\par

test

\end{document}

I agree that \AddToHookNext should perhaps also write something like

**** Add to hook para/before (top-level) on input line 6 <- \typeout {-> before
 hook always}

but that wouldn't help here because the problem is that the command to which the cmd hook is added gets redefined.
Now that is something we can't really test for (ok for \par we know but to single that out seems pointless). What we can do is to add a warning in the documentation perhaps.

By the way, why do you try to use cmd/par/before, If there is a perfectly fine para/before already?

@ysalmon
Copy link
Author

ysalmon commented Sep 6, 2024

The use case is explained there, and indeed, the redefinitions of \par make it tricky. But I think I managed to get something that more or less works, and the present report is in fact not at all about having hooks into \par, but the way the hook debugging system works with \AddToHookNext for any hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Pool (unscheduled issues)
Development

No branches or pull requests

3 participants