24

While investigating problems with hyphenation and em-dashes, I came across this:

a piece---perhaps an installation---, involving structural feedback

The document class is article. The problem was that installation was not hyphenated, and an overfull line was produced, with installation--- moving over the right margin, and the next line beginning with the comma.

Now I happened to try this, and it fixed the problem:

a piece---perhaps an installation\textemdash, involving structural feedback

properly breaking the line such as

...instal-
lation---, involving...

This seems counter-intuitive to me, and I really prefer to see the triple hyphens in my source code, much more readable. Is there a way to fix this problem?


It looks clearly like a latex error to me, because standard usage of em-dash states: "According to most American sources [...] and some British sources [...], an em dash should always be set closed, meaning it should not be surrounded by spaces."

1
  • Try your original construction with \sloppy? May 20, 2012 at 20:29

5 Answers 5

14

You have, at least, three possible options:

  1. Use \textemdash instead of ---. You already mentioned this in your question and it seems counter-intuitive for you.
  2. Manually declare the valid hyphenation points for the word preceding the ---.
  3. Load the babel package and use \allowhyphens---. I think this approach will give you something closer to what you want since you could declare some character as active (" for example) and define a command "--- to be \allowhyphens---; you then will write "--- to get an em-dash allowing hyphenation for the preceding word (this approach was used by Javier Bezos in his implementation of a similar shorthand in the spanish module for babel).

Here's some code showing the problem and the three alternatives I mentioned:

\documentclass{article}
\usepackage[english]{babel}

\begin{document}

some filler text to illustrate the problem here's a piece---perhaps an installation---, involving structural feedback

some filler text to illustrate the problem here's a piece---perhaps an installation\textemdash, involving structural feedback

some filler text to illustrate the problem here's a piece---perhaps an installation\allowhyphens---, involving structural feedback

some filler text to illustrate the problem here's a piece---perhaps an in\-stal\-la\-tion---, involving structural feedback

\end{document}

enter image description here

Here's some code that could be used to implement my suggestion in the third numeral above :

\documentclass{article}
\usepackage[english]{babel}

\catcode`"=13
\def"-{\allowhyphens-}

\begin{document}

some filler text to illustrate the problem here's a piece---perhaps an installation---, involving structural feedback

some filler text to illustrate the problem here's a piece---perhaps an installation"---, involving structural feedback

\end{document}

enter image description here

Yet another alternative, taken from this answer by Herbert to babel: Adding ngerman' s language shorthands to english as the main document language (thanks to egreg for pointing out this question) is to use the spanish modulo as a secondary language and use its already existing shorthand:

\documentclass{article}
\usepackage[spanish,english]{babel}
\useshorthands{"}
\addto\extrasenglish{\languageshorthands{spanish}}

\begin{document}

some filler text to illustrate the problem here's a piece---perhaps an installation---, involving structural feedback

some filler text to illustrate the problem here's a piece---perhaps an installation"---, involving structural feedback

\end{document}

enter image description here

2
  • But that's even more horrible than falling back to \textemdash, and I will need to hyphenate each word preceding an em-dash, just in case it ends up at a line end. To me this is clearly a latex error (see my addendum about common em-dash use).
    – Emit Taste
    May 20, 2012 at 18:30
  • @EmitTaste you're right. I've updated my answer now showing another possible solution. May 20, 2012 at 21:42
11

The reason why installation--- doesn't allow TeX to hyphenate the word is explained in the TeXbook (p. 95):

The most common case of a discretionary break is a simple discretionary hyphen

\discretionary{-}{}{}

for which TeX accepts the abbreviation ‘\-’. The next most common case is

\discretionary{}{}{}

(an “empty discretionary”), which TeX automatically inserts after ‘-’ and after every ligature that ends with ‘-’. In the case of plain TeX, empty discretionaries are therefore inserted after hyphens and dashes. (Each font has an associated \hyphenchar, which we can assume for simplicity is equal to ‘-’.)

Conversely, LaTeX defines

\DeclareTextSymbol{\textemdash}{OT1}{124}

or, with the T1 encoding,

\DeclareTextSymbol{\textemdash}{T1}{22}

so that the command \textemdash directly selects a character, without passing through the ligature mechanism, so that no empty discretionary is inserted.

In my opinion you should use ---, manually correcting possible bad breaks and deciding, in tough situations, whether hyphenating the word next to the dash is the lesser evil.

11

Another solution, besides the ones already mentioned in the other answers, consists of inserting \nobreak\hskip0pt between installation and ---. That way, TeX can hyphenate the word "installation", but there won't be line break right between tion and the em-dash.

0
8

Instead of the traditional --- ligature, I use the Unicode character , which is equivalent to \textemdash. In my opinion, there should be no line break at the em dash, but hyphenation within the adjacent words seems acceptable to me. To achieve this, I patch \textemdash as follows:

\documentclass{article}

\usepackage{etoolbox}

\usepackage[utf8]{inputenc}

\makeatletter

\apptocmd{\textemdash}{%
  \nobreak\hskip\z@skip%
}{%
}{%
}

\robustify\textemdash

\makeatother

\begin{document}

\showhyphens{hyphenation—hyphenation}

\end{document}
4
  • Undefined control sequence. \textemdash ...\PD1\textemdash \nobreak \hskip \z @skip
    – A T
    Jan 18, 2020 at 3:57
  • @AT: you forgot \makeatletter / \makeatother. Apr 15 at 4:45
  • No I didn't, it's above @ilya-zakharevich
    – A T
    Apr 16 at 12:24
  • @AT: I’m confused: “what is above” is written by a different person. Just in case, I double-checked: The message you quote appears indeed when one removes \makeatletter. Apr 18 at 1:16
2

In case of strange behavior or foreign languages, you can manually instruct LaTeX to hyphenate your word like this

in\-stal\-la\-tion

\- shows a possible hyphen.

1
  • 1
    It's not a problem of the dictionary. If I don't have the em-dash, it properly breaks e.g. at instal\-lation with english babel and install\-ation with UKenglish (the one I use now).
    – Emit Taste
    May 20, 2012 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .