0

Feeding

\documentclass{article}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.
\begin{theorem}
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

to pdflatex yields a para, in which the second line is overfull:

the second line is overfull

To avoid an overfull in the second line, you set \emergencystretch as locally as possible in the first para to a mostly small positive value. However, you also have to later set \emergencystretch to zero to avoid bad effects down the stream. In effect,

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
\setlength{\emergencystretch}{1.02em}%
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.
\begin{theorem}\setlength{\emergencystretch}{0em}%%% this is local
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\setlength{\emergencystretch}{0em}%%% this is global
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

yields

good output without overfull lines and extra effects

The output it good, but, clearly, setting the same variable at three different places (which need not be on the same screen of you LaTeX editor) is error-prone. Is there a better way that would NOT introduce additional vertical space or superfluous first-line indents?

  • This appears ti be equivalent to the situation in which one should use the sloppypar environment. See How to avoid using \sloppy document-wide to fix overfull \hbox problems? for more information. – barbara beeton Jun 25 '22 at 00:22
  • @barbarabeeton Thx. The answers in your link, essentially, suggest using the url package, adding hyphenation points, and using the sloppypar environment. My non-minimal example has no URLs. There, I do wish to break the “offending” long compound word after one of the hyphens that combines its subwords; hence, I don't need additional hyphenation points. Wrapping the first para into sloppypar introduces more eager breaking and removes also the hardly visible first-line–overfull problem. Not sure I want it in general. –  Jun 25 '22 at 00:52
  • 1
    Since sloppypar is mainly intended to isolate the problem paragraph, you might look at how it's defined, and substitute your preferred value of \emergencystretch for the equivalent in that definition. Give it a new name, of course. Or define a new environment that uses your value of \emergencystretch and is wrapped in \begingroup ... \par\endgroup. The \par is necessary for the \emergencystretch to be applied properly. – barbara beeton Jun 25 '22 at 01:37

1 Answers1

1

You can set \emergencystretch locally just for the one paragraph end before the theorem:

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.{\setlength{\emergencystretch}{1.02em}%

} \begin{theorem} Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos. \end{theorem}% A paragraph following the theorem. \begin{theorem} Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos. \end{theorem}% \end{document}

Although I would not do this. \sloppy and \emergencystrech are good tools to adjust default linebreaking for classes of paragraphs with hard to set material, but are a somewhat blunt instrument to adjust the linebreaking in a specific paragraph. Here, looking at the original setting, you know where you want to force a line break, so I would simply do that rather than second-guess what value of \emergencystretch makes a break there without changing the rest of the paragraph.

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-\\averylongword.
\begin{theorem}
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}
David Carlisle
  • 757,742
  • Thanks! Unfortunately, I cannot exclude the possibility that the print area is changed later on. So, forcing a new line (which is, as far as I know, simply \penalty-10000, right?) is not something I'd be too eager to do. –  Jun 29 '22 at 10:49
  • Moreover, {\setlength{\emergencystretch}{1.02em}%
[newline][newline]} adds vertical space. Not something I'd be eager to do either because the text before the theorem might introduce the theorem and be better kept together with it if you insist. –  Jun 29 '22 at 11:05
  • @GeekestGeek for your first comment I assume you mean later in time, not "later in the document" well true but that applies equally to your fine tuned stretch values, assuming they have the desired line breaking effect. The second comment sems incorrect as far as I undrerstand it, it should not have any extra vertical space and any setting of \emergencystretch only has an effect at the \par (blank line) at the of the paragraph so adding \emergencystretch that does not include a \par does nothing – David Carlisle Jun 29 '22 at 18:59
  • Yes, I meant “later in time”. The finely tuned stretch values are slightly better than a blunt \penalty-10000 because they don't force a line break at a particular text position regardless of the line width. –  Jul 05 '22 at 21:03
  • To see that superfluous vertical space is added, consider the diffpdf comparision of the output of https://pastebin.com/raw/Rh6aWrLw with the output of https://pastebin.com/raw/TJLH3JNz in https://i.imgur.com/LfIwhZI.png . –  Jul 05 '22 at 21:05