# linebreak fails for long lines in list of figures

When lines becoms long and there are many ~-characters (eg for citing) latex fails to break the line in the list of figures and prints into the margin. any ideas how to "force" a break before the margin?

\documentclass{book}

\begin{document}

\listoffigures

\begin{figure}
\caption{Long  Long  Long  Long Long  Long  Long  Long Long Long Long~Long~Long~Long/Long}
\end{figure}

\begin{figure}
\caption{Long  Long  Long  Long Long  Long  Long  Long Long Long Long~Long~Long~Long}
\end{figure}

\begin{figure}
\caption{Short}
\end{figure}

\end{document}

-
Could you be clearer what you want to happen. The only reason for using ~ rather than   is to prevent line breaks. –  David Carlisle Jun 19 '13 at 20:10
shure. but it's to prevent line breaks between exactly two words like "page~7". if "page~7" at the end of one line is too long, latex should break the line before. in the example it totaly doesn't break and prints the text into the margin. –  Christian Jun 19 '13 at 20:16
yes but is Long~Long~Long~Long really representative that doesn't give latex any options, long isn't hyphenatable and ~ doesn't break. –  David Carlisle Jun 19 '13 at 20:19
Two options for me: either having a shorter caption in the list of figure possible with \caption[Short description]{Long description} where the short description will appear in the list of figures and the long in the document, or having the same description and force break lines with  \\  somewhere in your caption and find the good option for the hyperref package. You may also need the caption package. –  Ludovic C. Jun 19 '13 at 20:20
Actually using \newline in the "short" description seems to work pretty well to force a line break. –  Ludovic C. Jun 19 '13 at 20:24

You can add a bit of glue to allow more stretch:

\documentclass{book}

\begin{document}

\makeatletter
\def\@tocrmarg{2.55em plus 3em}
\listoffigures

\begin{figure}
\caption{Long  Long  Long  Long Long  Long  Long  Long Long Long Long~Long~Long~Long/Long}
\end{figure}

\begin{figure}
\caption{Long  Long  Long  Long Long  Long  Long  Long Long Long Long~Long~Long~Long}
\end{figure}

\begin{figure}
\caption{Short}
\end{figure}

\end{document}

-
I played around with your idea and if I add another ~ before the already existing ones I got the same problem as previously. Is there a way to adapt your values for not having this kind of surprise or do we have to always check and adapt "manually"? –  Ludovic C. Jun 19 '13 at 20:37
@LudovicC. I was reasonably cautious in only giving 3em of extra stretch you could say plus \textwidth but that would allow the lines to be arbitrarily short. Unless you are doing automated runs of thousands of documents it's probably better to let some fail and force a short toc entry to be provided in \caption[..] rather than make it silently accept anything –  David Carlisle Jun 19 '13 at 20:45
Thanks, that might spare me a lot of "renaming" of my captions. –  Ludovic C. Jun 19 '13 at 20:51