From 79583f92d6881a601bd41c3c6b2de67730a0facf Mon Sep 17 00:00:00 2001 From: Frank Mittelbach Date: Sat, 13 Jul 2024 10:45:01 +0200 Subject: [PATCH] fix for #1407 (#1408) * fix for #1407 * corrections * further suggestions by CAR --- base/changes.txt | 6 +++++ base/doc/ltnews40.tex | 13 +++++++++++ base/ltmiscen.dtx | 29 ++++++++++++++++++++++++- base/testfiles/github-1407-rollback.lvt | 13 +++++++++++ base/testfiles/github-1407-rollback.tlg | 21 ++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 base/testfiles/github-1407-rollback.lvt create mode 100644 base/testfiles/github-1407-rollback.tlg diff --git a/base/changes.txt b/base/changes.txt index 4a5df5b53..4cad19a13 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,12 @@ to completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2024-07-10 Frank Mittelbach + + * ltmiscen.dtx (subsection{Environments}): + Drop code chunks before adding them to avoid duplication in + rollback (gh/1407) + 2024-07-06 Yukai Chou * ltcmd.dtx (subsection{User functions}): diff --git a/base/doc/ltnews40.tex b/base/doc/ltnews40.tex index 19bb9fbf4..e7084d28c 100644 --- a/base/doc/ltnews40.tex +++ b/base/doc/ltnews40.tex @@ -273,6 +273,19 @@ \section{Improvement to \XeTeX\ \cs{showhyphens}} % \githubissue{1380} +\section{Avoid code duplication in rollback} + +When the kernel uses \cs{AddToHook} in a region that might be +rolled back (which happens in a few places) and a document requests a +rollback, then we have the situation that the hook already contains code to which we added the same +(or slightly different) code during the +rollback; this results in code duplication or, worse, in errors. This has +now been corrected by dropping any such code chunk (if there is one) prior to +adding the rollback code. +% +\githubissue{1407} + + %\section{Changes to packages in the \pkg{amsmath} category} %\section{Changes to packages in the \pkg{graphics} category} diff --git a/base/ltmiscen.dtx b/base/ltmiscen.dtx index bb7cdb3cf..423f51624 100644 --- a/base/ltmiscen.dtx +++ b/base/ltmiscen.dtx @@ -32,7 +32,7 @@ %<*driver> % \fi \ProvidesFile{ltmiscen.dtx} - [2024/06/23 v1.2d LaTeX Kernel (Misc. Environments)] + [2024/07/10 v1.2e LaTeX Kernel (Misc. Environments)] % \iffalse \documentclass{ltxdoc} \GetFileInfo{ltmiscen.dtx} @@ -276,6 +276,21 @@ % \changes{v1.0w}{1994/11/30}{(DPC) Use \cs{@dofilelist}} % \changes{v1.2a}{2022/11/06}{Repeat release info at the end (gh/944)} % \begin{macrocode} +% \end{macrocode} +% If we roll back we have to drop stuff before adding chunks, +% otherwise the code will just be appended, and thus doubled. +% This would result in a harmless warning during the format +% generation, because in that case the code chunk label doesn't +% exist, and therefore can't be dropped. +% \changes{v1.2e}{2024/07/10}{Drop code chunks before adding them to +% avoid duplication in rollback (gh/1407)} +% \begin{macrocode} +%\RemoveFromHook{enddocument/info}[kernel/filelist] +%\RemoveFromHook{enddocument/info}[kernel/warnings] +%\RemoveFromHook{enddocument/info}[kernel/release] +% \end{macrocode} +% +% \begin{macrocode} \AddToHook{enddocument/info}[kernel/filelist]{\@dofilelist} \AddToHook{enddocument/info}[kernel/warnings]{\@enddocument@kernel@warnings} \AddToHook{enddocument/info}[kernel/release]{% @@ -389,6 +404,18 @@ %\NewHook{enddocument/afteraux} %\NewHook{enddocument/info} %\NewHook{enddocument/end} +% \end{macrocode} +% If we roll back we have to drop stuff before adding chunks, +% otherwise the code will just be appended, and thus doubled. +% \changes{v1.2e}{2024/07/10}{Drop code chunks before adding them to +% avoid duplication in rollback (gh/1407)} +% \begin{macrocode} +%\RemoveFromHook{enddocument/info}[kernel/filelist] +%\RemoveFromHook{enddocument/info}[kernel/warnings] +%\RemoveFromHook{enddocument/info}[kernel/release] +% \end{macrocode} +% +% \begin{macrocode} %\AddToHook{enddocument/info}[kernel/filelist]{\@dofilelist} %\AddToHook{enddocument/info}[kernel/warnings]{\@enddocument@kernel@warnings} %\AddToHook{enddocument/info}[kernel/release]{% diff --git a/base/testfiles/github-1407-rollback.lvt b/base/testfiles/github-1407-rollback.lvt new file mode 100644 index 000000000..39ee9ac4e --- /dev/null +++ b/base/testfiles/github-1407-rollback.lvt @@ -0,0 +1,13 @@ +\RequirePackage[2023-11-01]{latexrelease} + +\documentclass{article} + +\input{test2e} + + +\START + +\typeout{--> Code should not be doubled in chunks} + +\ShowHook{enddocument/info} +\END diff --git a/base/testfiles/github-1407-rollback.tlg b/base/testfiles/github-1407-rollback.tlg new file mode 100644 index 000000000..2e8251f1e --- /dev/null +++ b/base/testfiles/github-1407-rollback.tlg @@ -0,0 +1,21 @@ +This is a generated file for the LaTeX2e validation system. +Don't change this file in any respect. +--> Code should not be doubled in chunks +-> The hook 'enddocument/info': +> Code chunks: +> kernel/filelist -> \@dofilelist +> kernel/warnings -> \@enddocument@kernel@warnings +> kernel/release -> \let \show@release@info \wlog \show@release@info { ***********}\the \LaTeXReleaseInfo \show@release@info { ***********} +> kernel/testmode -> +> Document-level (top-level) code (executed last): +> --- +> Extra code for next invocation: +> --- +> Rules: +> kernel/warnings|kernel/filelist with relation > +> kernel/release|kernel/filelist with relation < +> kernel/testmode|kernel/release with relation -> +> Execution order (after applying rules): +> kernel/release, kernel/testmode, kernel/filelist, kernel/warnings. + } +l. ...\ShowHook{enddocument/info}