8

I'm writing a text in Spanish, and I have a phrase wrote between em-dashes (that work like parentheses). The problem is that if the "opening" em-dash is too near the end of the line, then it may happen that it remains in that line but the next word falls to the next:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
libero ---accumsan vulputate---. Praesent pretium dapibus est interdum 
hendrerit.

bad result

What I need to get in this example, is the opening em-dash and its next word to be in the same line, like this:

good result

where I had to use

\mbox{---accumsan}

Is there a simple way to make LaTeX not to break the opening em-dash with its next word, and also the ending em-dash with its previous word?

12

Since you are writing in Spanish, you surely are using the spanish option for babel. If this is the case, then you can use the shorthand "+-- to prevent a possible line break. A little example:

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

\begin{document}

%wrong output:
\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
 ---accumsan vulputate---. Praesent pretium dapibus est interdum 
hendrerit.

%right output:
\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
 "+--accumsan vulputate"+--. Praesent pretium dapibus est interdum 
hendrerit.

\end{document}

enter image description here

Another option is to use the \nobreakdash command implemented by the amsmath package; this command suppresses any line break after the dash (or hyphen). Of course, if you are going to use this a lot, you can define a new command to simplify the writing. In the following example I defined two commands using \nobreakdash: the first variant will prevent hyphenation of the word following the em-dash; the second variant will allow normal hyphenation in the following word:

\documentclass{article}
\usepackage{amsmath}

\newcommand\RayaN{\nobreakdash---}
\newcommand\Rayan{\nobreakdash---\hspace{0pt}}

\begin{document}

\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
 ---accumsan vulputate---. Praesent pretium dapibus est interdum 
hendrerit.

\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
 \RayaN accumsan vulputate\RayaN. Praesent pretium dapibus est interdum 
hendrerit.

\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a leo quis 
 \Rayan accumsan vulputate\Rayan. Praesent pretium dapibus est interdum 
hendrerit.

\end{document}​

enter image description here

|improve this answer|||||
  • I would suggest the addition of xspace to accommodate for the following scenario the requires an end-of-command-sequence space: ...a leo quis \Rayan accumsan vulputate\Rayan lorem ipsum.... This OP did mention that the em-dashes act like parentheses. – Werner Oct 25 '11 at 5:30
  • Thank you Gonzalo, it worked perfectly using "+-- with babel (which I was already using, as you correctly thought). – Nicolás Ozimica Oct 26 '11 at 2:54
2

You can set \exhyphenpenalty=10000. After this, the hyphen-like places (generated by - or -- or --- are unbreakable.

Advantage: The setting can be done only once at beginning of the document. You needn't to change the markup of the document.

Disadvantage: the word immediately followed after --- is not hyphenated. If this brings the problem, you can insert explicitly hyphen points in this word by \-.

|improve this answer|||||
  • You should note that also compound words will not be broken at the hyphen. – egreg Jan 31 '15 at 16:44

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.