From 170d363743c5097c7a94443599d1f7ae3d18f037 Mon Sep 17 00:00:00 2001 From: Frank Mittelbach Date: Thu, 2 Jan 2025 22:51:32 +0100 Subject: [PATCH] fix for #1604 --- base/changes.txt | 5 +++++ base/ltclass.dtx | 18 +++++++++++++++--- base/testfiles-lthooks/lthooks-034.lvt | 3 +++ base/testfiles-lthooks/lthooks-034.tlg | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/base/changes.txt b/base/changes.txt index 663354dfe..f92cbcd88 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,11 @@ to completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2025-01-02 Frank Mittelbach + + * ltclass.dtx (subsection{Hooks}): + Do not make \AtBeginDocument preamble only (gh/1604) + 2024-12-27 Frank Mittelbach * ltsockets.dtx: diff --git a/base/ltclass.dtx b/base/ltclass.dtx index 8fa1acf39..3e7aff03c 100644 --- a/base/ltclass.dtx +++ b/base/ltclass.dtx @@ -33,7 +33,7 @@ %<*driver> % \fi \ProvidesFile{ltclass.dtx} - [2024/08/28 v1.5m LaTeX Kernel (Class & Package Interface)] + [2025/01/02 v1.5n LaTeX Kernel (Class & Package Interface)] % \iffalse \documentclass{ltxdoc} \GetFileInfo{ltclass.dtx} @@ -2808,8 +2808,20 @@ %<*2ekernel> % \end{macrocode} % -% \begin{macrocode} -\@onlypreamble\AtBeginDocument +% In its initial implementation (not using the hook system) +% \cs{AtBeginDocument} was made \cs{@preambleonly} because using it +% later had no effect whatsoever, thus was most certainly an +% unintended programming error. With the reimplementation, using +% the \texttt{begindocument} hook internally, this has changed +% because adding to a onetime hook after it has already been used +% simply executes the additional code immediately. We therefore no +% longer generate an error if it is used inside the document so +% that \verb=\AddToHook{begindocument}= and \cs{AtBeginDocument} +% are truly equivalent (as claimed in the hook documentation). +% \changes{v1.5n}{2025/01/02}{Do not make \cs{AtBeginDocument} +% preamble only (gh/1604)} +% \begin{macrocode} +%\@onlypreamble\AtBeginDocument % \end{macrocode} % \end{macro} % \end{macro} diff --git a/base/testfiles-lthooks/lthooks-034.lvt b/base/testfiles-lthooks/lthooks-034.lvt index 2f3d44a04..c7b2637a4 100644 --- a/base/testfiles-lthooks/lthooks-034.lvt +++ b/base/testfiles-lthooks/lthooks-034.lvt @@ -20,4 +20,7 @@ \typeout{====== E} \UseHook{foo} +\AtBeginDocument{\typeout{--> A (test for gh/1604)}} +\AddToHook{begindocument}{\typeout{--> B (test for gh/1604)}} + \END diff --git a/base/testfiles-lthooks/lthooks-034.tlg b/base/testfiles-lthooks/lthooks-034.tlg index cd959fdb8..2d66c4247 100644 --- a/base/testfiles-lthooks/lthooks-034.tlg +++ b/base/testfiles-lthooks/lthooks-034.tlg @@ -36,3 +36,5 @@ l. ...\ShowHook{foo} ====== E pkgb pkga +--> A (test for gh/1604) +--> B (test for gh/1604)