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

2
  • 3
    never leave a blank line before a displayed math environment the spacing will be completely wrong as well as allowing bad page breaks Jul 13, 2017 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. Jul 13, 2017 at 10:28

1 Answer 1

4

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .