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

afterpage can lose a complete page #1698

Open
davidcarlisle opened this issue Mar 9, 2025 · 2 comments
Open

afterpage can lose a complete page #1698

davidcarlisle opened this issue Mar 9, 2025 · 2 comments
Assignees

Comments

@davidcarlisle
Copy link
Member

davidcarlisle commented Mar 9, 2025

Brief outline of the bug

If \afterpage is followed by more than a page worth of material before the output routine is called it can lose
the entire page and insert its material before the contributions held over.

Originally reported at

https://tex.stackexchange.com/questions/738483/afterpage-command-making-a-full-page-disappear

But this version is from @u-fischer and works with pdflatex, the problem shows on old releases so doesn't seem related to recent changes for marks or para hooks.

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass[]{book}%
\usepackage{afterpage}

\begin{document}
abc

\vspace{26\baselineskip}

abc

\afterpage{\clearpage Whatever \clearpage}

ups-A where is the rule?\\\rule{4pt}{\textheight}\\ups-B
%\\here is comes

abc

\end{document}

Log file (required) and possibly PDF file

afterpage-x.log

@FrankMittelbach
Copy link
Member

The problem is this part of \AP@savetop

  \begingroup
  \nointerlineskip\null
    \output{%
      \global\setbox\AP@partial\vbox{%
        \unvbox\@cclv
        \global\setbox\@ne\lastbox}%
       \global\setbox\AP@footins\box\footins}%
  \eject
  \endgroup}

If the galley has more material than a page than the \lastbox will not take out the \null box but something else (in this case the rule. So what you need is something like

  \nointerlineskip\null
  \output{%
     \ifnum\outputpenalty=-100013
      \typeout{---> special penalty reached}%
      \global\setbox\AP@partial\vbox{%
        \unvbox\@cclv
        \global\setbox\@ne\lastbox}%
      \global\setbox\AP@footins\box\footins
      \else
       \typeout{---> special penalty NOT reached}%
       \the\AP@output 
     \fi
  }%
  \penalty-100013

We don't have a registry for special penaltiers but I think 100013 is ok,

@davidcarlisle
Copy link
Member Author

@FrankMittelbach

If the galley has more material than a page than the \lastbox will not take out the \null box but something else

ah thanks, I got that far, but then got lost:-) Penalty looks good thanks, I'll do some testing and arrange an update

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

2 participants