latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

PDF generation breaks with unstarred \enlargethispage and lualatex #1551

Open LupinoTech opened 3 days ago

LupinoTech commented 3 days ago

The following code breaks with luaLaTeX (texlive 2024) but not with pdflatex or plain latex:

\RequirePackage{latexbug}
\documentclass{article}
\usepackage[breaklinks=true]{hyperref}
\textheight50mm
\title{}
\author{}

\begin{document}
\hsize40mm
\parindent0pt
\null\vskip30mm
\enlargethispage{1sp}% tex error
% \enlargethispage*{1sp}% no tex error

Some multiline text with a rather long, breaking url \url{https://tex.stackexchange.com/questions/731156/the-bottom-margin-of-bibliography-frame-is-too-narrow}.

\end{document}

with the error message

! error:  (pdf backend): 'endlink' ended up in different nesting level than 'startlink'
!  ==> Fatal error occurred, no output PDF file produced!%                                                                                                                                                                                                                    

log file: test.log

The starred variant of \enlargethispage seems to work fine, though.

LupinoTech commented 3 days ago

I should add that the error occurs only when the link breaks across pages.

u-fischer commented 3 days ago

It is not a hyperref bug. You get the same error if you use the primitive:

\documentclass{article}
\textheight50mm
\title{}
\author{}

\begin{document}
\hsize40mm
\parindent0pt
\null\vskip30mm
\enlargethispage{1sp}% tex error

Some multiline text with a rather long, breaking url 
\pdfextension startlink
    attr {/Border[0 0 1]}
    user{
        /Subtype/Link%
        /A<<%
         /Type/Action%
         /S/URI%
         /URI(blkub)%
         >>%
        } https://tex.stackexchange.com/questions/731156/the-bottom-margin-of-bibliography-frame-is-too-narrow
\pdfextension endlink

\end{document}

The problem is that LaTeX boxes the two pages in different ways. With pdflatex there is no problem as (at my request) pdftex changed the error to a warning:

pdfTeX warning: \pdfendlink ended up in different nesting level than \pdfstartlink

Sadly, luatex didn't want to follow (https://mailman.ntg.nl/archives/list/dev-luatex@ntg.nl/thread/VSHCA4WEQJJ5C3JJPVTPTYWYLDZ7TBHA/)

A similar problem was resolved in 2018 in https://github.com/latex3/latex2e/issues/94 for another case of boxing, so perhaps some adjustments in the LaTeX output can be done here and I will transfer the issue to latex2e.

As a workaround add \enlargethispage{1sp} also on the next page, then box pages have the same boxing level. E.g.

\documentclass{article}
\usepackage[breaklinks=true]{hyperref}
\textheight50mm
\title{}
\author{}
\AddToHook{shipout/before}{\enlargethispage{1sp}}

\begin{document}
\hsize40mm
\parindent0pt
\null\vskip30mm
\enlargethispage{1sp}% tex error
% \enlargethispage*{1sp}% no tex error

Some multiline text with a rather long, breaking url \url{https://tex.stackexchange.com/questions/731156/the-bottom-margin-of-bibliography-frame-is-too-narrow}.

\end{document}
LupinoTech commented 3 days ago

just for my understanding; does the \@kludgeins on the followup page need to have the same height as the one on the previous page? Or is 1sp "enough"?