Do the line breaking algorithms of TeX have a penalty for a QED symbol on a single line?
amsthm defines \qed
by
\DeclareRobustCommand{\qed}{%
\ifmmode \mathqed
\else
\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
\quad\hbox{\qedsymbol}%
\fi
}
so it already assigns the largest possible penalty short of 10000 (which is the maximum) that means that in your example there is no feasible breakpoint with penalty less than this.
There are a few strategies, but the main one is to edit the offending paragraph.
Strategy 1: \linebreak
Strategy 2: \looseness=1
Here strategy 2 comes into two variants, the latter with \mbox
to avoid hyphenation.
I'm afraid that making this automatic would be very complicated and fragile, but you could try and add \looseness=1
to the definition of \qed
, which might work in several cases.
\documentclass{article}
\usepackage{amsthm}
\begin{document}
\begin{proof}
asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdfa.
\end{proof}
\begin{proof}
asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
\linebreak asdfa.
\end{proof}
\begin{proof}
asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
asdfa.\looseness=1
\end{proof}
\begin{proof}
asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
\mbox{asdfa}.\looseness=1
\end{proof}
\end{document}