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

phase-III issue (allows \frontmatter with report.cls), or more general AddToHook issue... #1643

Closed
alexanderperlis opened this issue Jan 28, 2025 · 2 comments

Comments

@alexanderperlis
Copy link

(Reporting here because I believe this is ultimately more about \AddToHook than about phase-III of the tagging project.)

This report is about LaTeX2e <2024-11-01> patch level 1 L3 programming layer <2024-12-25>, as well as about LaTeX2e <2025-06-01> pre-release-1 (develop 2025-1-27 branch) L3 programming layer <2025-01-18>.

The following should not compile (yet surprisingly does):

\DocumentMetadata{testphase=phase-III}
\documentclass{report}
\begin{document}
\frontmatter   % Why no error? Not defined by "report.cls".
\end{document}

By using phase-III, the various book.cls commands \frontmatter, \mainmatter, \backmatter, \appendix will be defined even when book isn't the document class.

This behavior strikes me as unexpected, although likely benign. Tracing this back a bit, it seems that latex-lab-testphase-sec.sty says things like \AddToHook{cmd/frontmatter/before}{...}, which occurs before it is known which document class will be loaded and thus before it is known whether a particular command like \frontmatter will eventually exist. Of course it is intentional that the hook system allows you to do this kind of thing, to potentially hook packages before it is known whether those packages will be loaded. But if such a hooked package doesn't get loaded, so that there ends up being nothing to hook, should the hook system nonetheless proceed to define things that otherwise wouldn't exist? This strikes me as incorrect, but perhaps the behavior is intentional or unavoidable. For example, I contend the following should not compile:

\AddToHook{cmd/mycommand/before}{tremendous\ }
\documentclass{article}
%\newcommand{\mycommand}{}
\begin{document}
I believe \TeX\ is \mycommand fun. % Undefined command should be an error.
\end{document}

Is this behavior of \AddToHook intentional/unavoidable? In that case, should phase-III do its hooking in a manner that can detect the document class and only hook the particular commands that will be part of the particular document class? (The case I stumbled across seems totally benign, but I imagine there could be some unusual third-party macros that have conditional behavior based on the existence of certain other macros, essentially a strange way of detecting the document class or detecting the presence of certain features, and that conditional behavior would stop working as originally intended.)

@cfr42
Copy link
Contributor

cfr42 commented Jan 28, 2025

#1591 looks like the same issue.

@FrankMittelbach
Copy link
Member

This is being fixed in latex-dev (#1591) and will show up in the next distribution of latex-dev in a few days.

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

No branches or pull requests

4 participants