3

I need to bind single line paragraph and math display with \nobreak. \clubpenalty, \widowpenalty, \displaywidowpenalty has no effect because it's a single line and there is \par between math display. Uncommenting \nobreak the result is fine. Single line goes to the next page. Manual intervention to tex file is not an option.

MWE:

\documentclass{article}
\usepackage[paperwidth=5cm,paperheight=3cm]{geometry}
\geometry{verbose,tmargin=.5cm,bmargin=.5cm,lmargin=.5cm,rmargin=.5cm}
\clubpenalty=10000
\widowpenalty=10000
\displaywidowpenalty=10000

\begin{document}
Long long long long long long long long long text.

Single line paragraph:

%\nobreak
\begin{equation}
a+b
\end{equation}
\end{document}

Bad output:

wrong

Perfect:

enter image description here

I am using Luatex and with post_linebreak_filter callback I could recognise single line paragraphs, but I don't see math in here. I want to create penalty node and add it before display. mlist_to_hlist could find math but I don't see any correlation with other callbacks. It seems this callback works later. Any ideas would be wery helpfull

  • 3
    never leave a blank line before a displayed math environment the spacing will be completely wrong as well as allowing bad page breaks – David Carlisle Jul 13 '17 at 10:00
  • You say manual changes to the tex is not an option but the markup is wrong, unfortunately it just makes bad output rather than an error but it is still incorrect the bad spacing can still be seen even in your "perfect" image above. You could of course try to use lua's callback to edit the input on the fly to correct markup errors but that seems an inherently fragile way to address the problem. – David Carlisle Jul 13 '17 at 10:28
3

Never have a blank line before a displayed equation, this forces a spurious single line paragraph that just consists of white space to be generated before the equation (so it looks a bit like vertical space, but is not) so this makes poor vertical space and allows poor page breaks.

if you use

\documentclass{article}
\usepackage[paperwidth=5cm,paperheight=3cm]{geometry}
\geometry{verbose,tmargin=.5cm,bmargin=.5cm,lmargin=.5cm,rmargin=.5cm}
\clubpenalty=10000
\widowpenalty=10000
\displaywidowpenalty=10000

\begin{document}
Long long long long long long long long long text.

Single line paragraph:
\begin{equation}
a+b
\end{equation}
\end{document}

It all fits on one page and if you add one extra line

\documentclass{article}
\usepackage[paperwidth=5cm,paperheight=3cm]{geometry}
\geometry{verbose,tmargin=.5cm,bmargin=.5cm,lmargin=.5cm,rmargin=.5cm}
\clubpenalty=10000
\widowpenalty=10000
\displaywidowpenalty=10000

\begin{document}
Long long long long long long long long long text.\\
zz

Single line paragraph:
\begin{equation}
a+b
\end{equation}
\end{document}

Then the whole second paragraph (the equation is now part of the second paragraph) moves on to page 2.

  • David, I agree that it's incorrect input, but I want to fix it on the fly. – Linuxss Jul 14 '17 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.