10

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).

enter image description here

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:

enter image description here

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.

dificultades dificultades dificultades dificultades  
dificultades ... dificultades dificultades dificultades  
dificultades dificultades .. dificultades dificultades  
dificultades dificultades...... dificultades dificultades 
dificultades dificultades dificultades dificultades 
\end{quotation} 
\end{document}
10

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:

enter image description here


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

enter image description here

\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.

dificultades dificultades dificultades dificultades  
dificultades ... dificultades dificultades dificultades  
dificultades dificultades .. dificultades dificultades  
dificultades dificultades...... dificultades dificultades 
dificultades dificultades dificultades dificultades 
\end{quotation} 

\end{document}
  • 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. – barbara beeton May 7 '13 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:-) – David Carlisle May 7 '13 at 13:17
  • "to keep the word separate from the -" But one would expect that the trailing dash works the same as a trailing comma or dot (as it's semantically equivalent), I would want that the previous word is hyphenated but a linebreak is never placed inbetween... – leonbloy May 7 '13 at 13:18
  • @leonbloy OK use \nolinebreak rather than \linebreak[0] or as barbara suggested, a 0 kern. – David Carlisle May 7 '13 at 13:19
  • 1
    @DavidCarlisle -- to make your answer "complete", please add an example with the dash preceding a word that could be hyphenated, showing that a break after that dash would be suppressed by the suggested code. the handling of dashes that come in pairs like this is tricky, and if they're used in a document, it's likely that special handling of both will be needed. – barbara beeton May 8 '13 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.