[latex3-commits] [git/LaTeX3-latex3-latex2e] develop: Shipout lastpage (#814) (538c0f44)

GitHub noreply at github.com
Mon May 9 13:13:55 CEST 2022


Repository : https://github.com/latex3/latex2e
On branch  : develop
Link       : https://github.com/latex3/latex2e/commit/538c0f443fceb5a3ffe5c4343d55a57c7a44c214

>---------------------------------------------------------------

commit 538c0f443fceb5a3ffe5c4343d55a57c7a44c214
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Mon May 9 13:13:55 2022 +0200

    Shipout lastpage (#814)
    
    * implementation but no rollback
    
    * fix logic
    
    * update message and tests


>---------------------------------------------------------------

538c0f443fceb5a3ffe5c4343d55a57c7a44c214
 base/changes.txt                         |  6 +++++
 base/doc/ltnews35.tex                    | 13 +++++++++++
 base/ltshipout.dtx                       | 36 ++++++++++++++++++++++++----
 base/testfiles-lthooks/shipout-004.tlg   |  2 ++
 base/testfiles-lthooks2/shipout2-017.lvt | 40 ++++++++++++++++++++++++++++++++
 base/testfiles-lthooks2/shipout2-017.tlg | 14 +++++++++++
 base/update-lthooks-tests.sh             |  3 +++
 7 files changed, 109 insertions(+), 5 deletions(-)

diff --git a/base/changes.txt b/base/changes.txt
index f1ad2672..db889fb1 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -24,6 +24,12 @@ are not part of the distribution.
 	* ifthen.dtx:
 	use new expandable version for \pageref and \ref
 
+2022-05-08  Frank Mittelbach  <Frank.Mittelbach at latex-project.org>
+
+	* ltshipout.dtx (subsection{Handling the end of job hook}):
+	Handle case where shipout/lastpage is run too early and issue
+	a warning (gh/813)
+
 2022-04-21  Joseph Wright <Joseph.Wright at latex-project.org>
 
 	* ltfinal.dtx (subsection{Lccodes and uccodes}):
diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex
index aa508ea7..741542a2 100644
--- a/base/doc/ltnews35.tex
+++ b/base/doc/ltnews35.tex
@@ -719,6 +719,18 @@ been fixed in the latest release.
 \sxissue{q/637565}
 
 
+\subsection{Warn if \hook{shipout/lastpage} hook is executed too early}
+
+The hook \hook{shipout/lastpage} is intended to place \cs{special}s
+into the last page shipped out. This is needed for some use cases,
+e.g., tagging. If that hook is nonempty and the user has added additional
+pages since the last run, then \LaTeX{} executes this hook too early,
+but until now without giving any indication that the document needs
+rerunning. This has now been corrected and an appropriate warning is
+given.
+%
+\githubissue{813}
+
 
 \subsection{More consistent use of cramped math styles in \LuaTeX}
 
@@ -740,6 +752,7 @@ to a document.
 
 
 
+
 \section{Changes to packages in the \pkg{amsmath} category}
 
 
diff --git a/base/ltshipout.dtx b/base/ltshipout.dtx
index 09495dde..83fab820 100644
--- a/base/ltshipout.dtx
+++ b/base/ltshipout.dtx
@@ -32,8 +32,8 @@
 %%% From File: ltshipout.dtx
 %
 %    \begin{macrocode}
-\providecommand\ltshipoutversion{v1.0l}
-\providecommand\ltshipoutdate{2022/01/06}
+\providecommand\ltshipoutversion{v1.0m}
+\providecommand\ltshipoutdate{2022/05/08}
 %    \end{macrocode}
 %
 %<*driver>
@@ -1014,8 +1014,14 @@
                       \_@@_add_foreground_box:n
                           { \UseHook{shipout/lastpage}
                             \@kernel at after@shipout at lastpage }
+                      \bool_gset_true:N \g_@@_lastpage_handled_bool
+%    \end{macrocode}
+%    We record that we have handled the \hook{shipout/lastpage} hook
+%    but only if we really did.
+% \changes{v1.0m}{2022/05/08}{Handle case where shipout/lastpage is
+%    run too early (gh/813)}
+%    \begin{macrocode}
                     }
-                    \bool_gset_true:N \g_@@_lastpage_handled_bool
                 }
               \@@_finalize_box:
 %    \end{macrocode}
@@ -1723,15 +1729,35 @@
           \gdef\string\@abspage at last {\int_use:N \g_shipout_readonly_int}}
      \fi
 %    \end{macrocode}
-%    But we may have guessed wrongly earlier and we still have to run the
+%    But we may have guessed wrongly earlier and have run it too early
+%    or we still have to run the
 %    \hook{shipout/lastpage} even though there is no page to place
 %    it into. If that is the case we make a trivial extra page and put
 %    it there. This temporary page will then vanish again on the next
 %    run but helps to keep pdf viewers happy.
+%    In either case we should put out an appropriate ``rerun'' warning.
+% \changes{v1.0m}{2022/05/08}{Handle case where shipout/lastpage is
+%    run too early (gh/813)}
+%    \begin{macrocode}
+      \bool_if:NTF \g_@@_lastpage_handled_bool
+         {
+%    \end{macrocode}
+%    If the hook was already executed, we have to test if that total
+%    shipouts match the shipouts from last run (because that
+%    corresponds to the page it was executed). If not we output a warning.
 %    \begin{macrocode}
-      \bool_if:NF \g_@@_lastpage_handled_bool
+           \int_compare:nNnF \@abspage at last = \g_shipout_readonly_int
+            {
+              \@latex at warning@no at line{Hook~ 'shipout/lastpage'~ executed~
+                on~ wrong~ page~ (\@abspage at last\space not~
+                \int_use:N\g_shipout_readonly_int).\MessageBreak
+                Rerun~ to~ correct~ this}%
+            } 
+         }
          {
 %    \end{macrocode}
+%    If the hook was not run, we need to add an extra page and place
+%    it there.
 %    However, making this extra page in case the hook is actually
 %    empty would be forcing a rerun without any reason, so we check
 %    that condition and also check if
diff --git a/base/testfiles-lthooks/shipout-004.tlg b/base/testfiles-lthooks/shipout-004.tlg
index 9573e5cb..60364fa7 100644
--- a/base/testfiles-lthooks/shipout-004.tlg
+++ b/base/testfiles-lthooks/shipout-004.tlg
@@ -91,4 +91,6 @@ Completed box being shipped out [5]
 ....\glue 0.0 plus 1.0fil
 ....\OT1/cmr/m/n/10 5
 ....\glue 0.0 plus 1.0fil
+LaTeX Warning: Hook 'shipout/lastpage' executed on wrong page (4 not 5).
+               Rerun to correct this.
 (shipout-004.aux)
diff --git a/base/testfiles-lthooks2/shipout2-017.lvt b/base/testfiles-lthooks2/shipout2-017.lvt
new file mode 100644
index 00000000..bb7ee083
--- /dev/null
+++ b/base/testfiles-lthooks2/shipout2-017.lvt
@@ -0,0 +1,40 @@
+\RequirePackage[enable-debug]{expl3}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation }
+\ExplSyntaxOff
+
+\documentclass[a4paper]{article}
+
+
+\input{regression-test}
+
+\AddToHook{shipout/lastpage}{\label{LastPage}}
+
+\DebugShipoutsOn
+
+%\showoutput
+
+\gdef\extendthistest{0}
+
+\begin{document}
+
+\makeatletter
+\immediate\write\@auxout {\detokenize{\gdef\extendthistest{1}}}
+\makeatother
+
+\START
+
+Lastpage: \pageref{LastPage}
+
+
+\ifnum\extendthistest> 0  % second or third run
+  \typeout{========== adding more material in second run}
+  \newpage A  \newpage B
+\else
+  \typeout{========== no extra material added}
+\fi
+
+\end{document}
+
+
+
diff --git a/base/testfiles-lthooks2/shipout2-017.tlg b/base/testfiles-lthooks2/shipout2-017.tlg
new file mode 100644
index 00000000..60419322
--- /dev/null
+++ b/base/testfiles-lthooks2/shipout2-017.tlg
@@ -0,0 +1,14 @@
+This is a generated file for the l3build validation system.
+Don't change this file in any respect.
+========== adding more material in second run
+Absolute page = 1 (target: 1)
+Executing lastpage hook on page 1
+[1
+]
+Absolute page = 2 (target: 1)
+[2]
+Absolute page = 3 (target: 1)
+[3]
+LaTeX Warning: Hook 'shipout/lastpage' executed on wrong page (1 not 3).
+               Rerun to correct this.
+(shipout2-017.aux)
diff --git a/base/update-lthooks-tests.sh b/base/update-lthooks-tests.sh
index 84fac6f1..493f2fcb 100755
--- a/base/update-lthooks-tests.sh
+++ b/base/update-lthooks-tests.sh
@@ -15,6 +15,9 @@ l3build save -cconfig-lthooks2 \
    shipout2-012 \
    shipout2-013 \
    shipout2-014 \
+   shipout2-015 \
+   shipout2-016 \
+   shipout2-017 \
    github-0360  \
    github-0431  \
    ltpara-001 \





More information about the latex3-commits mailing list.