Trying to make sense of TeX decisions (stretching, tolerance)

For example, if I don't set stretch parameters (tolerance, badness, emergencystretch, sloppy, etc) I get some overfull boxes (full LaTeX code post at the end).

Notice that TeX seems unwilling to hyphenate "dificultades", in spite of knowing perfectly how to do it (as shown in the last paragraph). It works well if I explicitly suggest the hypen (5th paragraph). Why?

Things get a little better tweaking the stretch parameters (eg, using \sloppy), but it still is reluctant to hyphenate that word.

And if I try \tolerance=10000 I get something quite ridiculous:

I cannot make sense of the layout of the first paragraphs - nor of the drastic change that happens in the third, just by adding a dot. Now, that's certainly not a hyphenation thing. I know, that \tolerance=10000 is not advisable in general, but I understand that it basically means: "use as much blank space (glue) as you want, even if it looks bad, don't overfull never"; but surely there are lots of many more reasonable layouts than that.

Is there a simple explanation of why TeX uses this "strategy"?

\documentclass[a4paper, 11pt]{book}
\usepackage[spanish]{babel}
\usepackage[paperwidth=140mm, paperheight=210mm, top=21mm, left=14mm, right=10mm,textheight=173mm]{geometry}
%\tolerance=10000

\begin{document}
\begin{quotation}
Hola, llego desde muy lejos ---con grandes dificultades--- y le ruego quiera escucharme.

Hola,... llego desde muy lejos ---con grandes dificultades--- y le ruego  quiera escucharme.

Hola,...... llego desde muy lejos ---con grandes dificultades--- y le ruego quiera  escucharme.

Hola,....... llego desde muy lejos ---con grandes dificultades--- y le ruego quiera  escucharme.

Hola, llego desde muy lejos ---con grandes dificulta\-des--- y le ruego quiera escucharme.

\end{quotation}
\end{document}


TeX does not hyphenate words containing an explicit hyphen, and a trailing --- counts as an explict hyphen in this context. You could use \linebreak[0]--- or some other penalty to keep the word separate from the -.

TeX truncates its badness calculation at 10000: any badness greater than that is essentially infinite, so despite the fact that some cases are worse than others they are all infinitely bad according to its least cost algorithm and so you get what you get. That is precisely why TeX3 introduced \emergencystretch to allow the badness to be more evenly distributed over the paragraph.

One way to rationalise the result that you get with \tolerance=10000 and \emergencystretch=0pt is to note that all settings of that paragraph are equally bad to TeX (over 10000) but that setting used minimises the number of bad lines as all the excess space is concentrated in one massively stretched space. \emergencystretch allows all spaces to stretch more then their specified stretch component without them all being considered infinitely bad.

With \linebreak[0]---\linebreak[0] you get:

If you want to forbid line breaks at the --- but allow hyphenation on a word directly connected at either side then:

\documentclass[a4paper, 11pt]{book}
\usepackage[spanish]{babel}
\usepackage[paperwidth=140mm, paperheight=210mm, top=21mm, left=14mm, right=10mm,textheight=173mm]{geometry}
%\tolerance=10000

\begin{document}
\begin{quotation}
Hola, llego desde muy lejos ---\nolinebreak\hspace{0pt}con grandes dificultades\nolinebreak--- y le ruego quiera escucharme.

Hola,... llego desde muy lejos ---\nolinebreak\hspace{0pt}con grandes dificultades\nolinebreak--- y le ruego  quiera escucharme.

Hola,...... llego desde muy lejos ---\nolinebreak\hspace{0pt}con grandes dificultades\nolinebreak--- y le ruego quiera  escucharme.

Hola,....... llego desde muy lejos ---\nolinebreak\hspace{0pt}con grandes dificultades\nolinebreak--- y le ruego quiera  escucharme.

Hola, llego desde muy lejos ---\nolinebreak\hspace{0pt}con grandes dificulta\-des\nolinebreak--- y le ruego quiera escucharme.


• another strategy for separating the em dash from the text is to use \kern0pt---. the result is the same as the examples here with \linebreak[0] both before and after the em dash. May 7, 2013 at 13:01
• @barbarabeeton yes the kern doesn't introduce a breakpoint so it's same as \nolinebreak rather than \linebreak rules about whether a break is allowed of course depend on the locale, the phase of the moon and the proof reader:-) May 7, 2013 at 13:17
• @leonbloy OK use \nolinebreak rather than \linebreak[0] or as barbara suggested, a 0 kern. May 7, 2013 at 13:19