13

LaTeX manuals are full of examples such as Fig.~5 or Thm.~10. The tilde prohibits a line break after the abbreviation completely, to make sure that the reader doesn't see a period at the end of a line and think that the current sentence is over and the next line is numbered. However, sometimes it's better to break after the period because other alternatives would be worse, e.g., when a long Probl.~1.2.3.4.5.6 runs into the margin, to which the publisher rightfully says it quits the print area or the visible area.

What would be an elegant way to tell LaTeX to make a break after the full stop only if otherwise the typesetting gets really nasty? E.g., is there any better, short, elegant way of saying Probl.\@\penalty5000\ 1.2.3.4.5.6? I randomly took 5000 here; please feel free to adjust this number accordingly (and say why you take a different value if you adjust it). Of course, we would like the solution to work regardless of whether we use French or English spacing and, ideally, with cleveref. My attempts:

\documentclass{article}
\usepackage{float}
\usepackage{cleveref}
\crefname{figure}{Fig.\@\penalty5000}{Figs.\@\penalty5000}
\showoutput
\begin{document}
\nonfrenchspacing%% to have the most general solution
See Fig.\@\penalty5000\ \labelcref{figure_label}\@.%% Not elegant at all
\begin{figure}[H]
  \caption{No, this has nothing to do with the manual ``See Figure 1''. Don't search for it online, please.}
  \label{figure_label}
\end{figure}
See \cref{figure_label}. %% Produces \penalty5000\penalty10000 in the output :-(.
Consider the last \namecref{figure_label}%%% Let's say the sentence is logically over. In this case, having a huge \penalty5000\penalty10000 here is simply wrong.
\end{document}
0

1 Answer 1

9

You can use \nolinebreak[3], that issues \@highpenalty, whose standard value is 301.

I don't think that 5000 is a good value, but you can experiment with higher values than 301.

\documentclass{article}
\usepackage{cleveref}

\crefname{figure}{Fig.\nolinebreak[3]}{Figs.\nolinebreak[3]}

\begin{document}

\begin{figure}[htp]
\caption{No, this has nothing to do with the manual ``See Figure 1''. 
  Don't search for it online, please.}\label{figure_label}
\end{figure}

See \cref{figure_label}.
Consider the last \namecref{figure_label}.

\medskip

\parbox[t]{0pt}{See \cref{figure_label}.}

\medskip

\parbox[t]{4.2em}{See \cref{figure_label}.}

\medskip

\parbox[t]{4.5em}{See \cref{figure_label}.}

\end{document}

You don't need \@, because cleveref takes care about it.

enter image description here

You get the same with

\crefname{figure}{Fig.\penalty5000 }{Figs.\penalty5000 }

Note the space after the constant 5000.

3
  • 1
    Notice the two periods in „Consider the last Fig..“; the duplication is unwanted. Notice that the penalty after the second period in „Consider the last Fig..“ is 10000; this is also unwanted because the sentence is over. This being said, you solution is great; thanks a lot!
    – user224332
    Aug 9, 2022 at 1:06
  • 2
    @GeekestGeek I added the period just to show that no space is added
    – egreg
    Aug 9, 2022 at 7:36
  • Thx! And if you don't use cleveref, would you say See Fig.\@\nolinebreak[3]\ \ref{figure_label}\@. ? Or can this be expressed more elegantly?
    – user224332
    Aug 9, 2022 at 17:01

You must log in to answer this question.