0

Continuing

prevent page break inside a sentence

I would like to penalize page breaks within a sentence but allow the pagebreaks otherwise as usual. As opposed to the above, I am happy to edit the paragraphs involving sentences that are likely to be broken but should be prevented from being broken. Yes, I understood that LaTeX has no idea about what a sentence is. Here is what I tried:

\documentclass[a4paper]{article}
\usepackage[latin]{babel}
\begin{document}
\vspace*{123ex}

{\interlinepenalty=10000 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.{\interlinepenalty=0\penalty0\ }%
At vero eos et accusam et justo duo dolores et ea rebum.{\interlinepenalty=0\penalty0\ }%
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.{\interlinepenalty=0\penalty0\ }%
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.{\interlinepenalty=0\penalty0\ }%
At vero eos et accusam et justo duo dolores et ea rebum.{\interlinepenalty=0\penalty0\ }%
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.}
\end{document}

However, the result was not very promising:

pdflatex result

I would expect LaTeX to find a page break after "amet." and before the middle "Lorem" in the above example automatically. (I tried \pagebreak[i] for various i, and it led nowhere.)

Any idea on how to penalize page breaking inside a sentence?

2

enter image description here

Your \interlinepenalty settings are doing nothing as they are all within groups that finish within the paragraph. Similarly the \penalty0 are doing nothing as there is already a zero cost line break point at a space.

It would be possible (but fragile) to have automatic tests but I would do it manually, just set each sentence as an unbreakable paragraph and then join as many together as will fit on a page

\documentclass[a4paper]{article}
\usepackage[latin]{babel}
\begin{document}
\vspace*{123ex}

\begingroup
\interlinepenalty=10000


Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
% fits
At vero eos et accusam et justo duo dolores et ea rebum.
% fits
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\noindent % doesn't fit
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
% fits
At vero eos et accusam et justo duo dolores et ea rebum.
% fits
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\endgroup

\end{document}
  • 1
    @user49915 It would be possible (but require a lot more code and have a lot more conditions on when it works) to have a more automatic system, I suppose I may post something later if no one else does. The requirement seems so strange though! TeX's internal line and page breaking gives no help at all for this requirement. – David Carlisle Mar 19 at 12:56
  • 2
    I'd be tempted to do that by hand. go to the last end of sentence on the previous page and after the . add last sentence.{\parfillskip=0pt\par}\clearpage\noindent Start of new sentence... – David Carlisle Mar 19 at 13:45
  • 1
    @user49915 this is final edits hand tune figure placement stuff yes of course it is fragile, but any tuning of figure placement is fragile, but for a hand written document it is worth spending an afternoon hand checking page breaking and forcing adjustments where necessary. If you are doing automatic database dumps of thousands of pages a day, hand correction less attractive.... – David Carlisle Mar 19 at 13:54
  • 1
    @user49915 it can be extended with self checking eg use \pdfsavepos to save the current vertical position after the \par and if that changes give an error message to force you to reconsider this page break, or ... – David Carlisle Mar 19 at 13:56
  • 1
    if you look at the end notes in the latex companion you will see that in the final print version several hundred page breaks were manually adjusted, it took several days and you really want to know you have finished editing before you start but when it really comes to the pinch, people are still better at this than tex.... You have so many more options as a person, you can tweak the wording, or use \enlargethispage to squeeze in an extra line, or you can force a break as above. – David Carlisle Mar 19 at 13:59

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.