3

I'm using memoir class to write a novel. As it is widely known, writer comments inside novel characters' dialogues are usually enclosed between long dashes which in turn are written as a triple dash in LaTeX. However I'm experiencing trouble when those long dashes (which always follow or precede a word with no space between) are near a linebreak: breaking word is not hyphenated most of the time and thus the line exceed the break margin. How can this be fixed?

  • 2
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – mvkorpel Sep 10 '14 at 8:52
  • @LaRiFaRi Traditionally an em dash is used without white space (despite how odd that looks) or with a thin space on both sides. Both possibilities stop LaTeX from hyphenating. – Jim Oldfield Sep 10 '14 at 9:10
  • 1
    A “dialogue dash” is different from a punctuation dash; it should be preceded and followed by spaces and should never fall at the end of a line, but always next to the words it introduces, or the reader will be confused. – egreg Sep 10 '14 at 12:39
  • Would you add some examples? It would make simpler giving advice and better ways for inputting the text. – egreg Sep 10 '14 at 12:53
2

Usually a hard hyphen (-)do not allow hyphenation in other place of one word, but you can use \textemdash instead of the ligature ---:

\documentclass{article}

% only to show the margins
\usepackage[showframe]{geometry,xcolor} 
\makeatletter
\def\Gm@hrule{}%
\def\Gm@vrule{\color{gray!30}\vrule width 1pt height\textheight depth\z@}%
\def\Gm@hruled{}%
\makeatother


\begin{document}

Something something something something something something something something 
---something--- something something something something something something something something somethin something

Something something something something something something something something 
\textemdash something\textemdash something something something something something something something something somethin something

\end{document}

But indeed, the simplest solution is add a soft hyphen when required: ---some\-thing---

  • This is the best solution for me! Didn't know \textemdash and googling for it I found another full post on the matter:link – Antonio López Sep 11 '14 at 11:26
3

Adding an invisible space between the --- and the word allows LaTeX to correctly hyphenate the word.

\documentclass[draft]{article}

\begin{document}
\noindent
something something something something something something some
---something % no hyphenation resulting in overfull box
something something something something something something something something

\noindent
something something something something something something some
---\hspace{0pt}something
something something something something something something something something
\end{document}

So for a good solution I would suggest you write a macro that inserts the right spacing etc, along the lines of

\newcommand{\dialogue}[1]{---\hspace{0pt}#1\hspace{0pt}---}

or wathever is the format you are following.

  • My explanation is that the hyphenation algorithm cannot find a scheme for hyphenating ---something while the space makes it detect that the --- should be considered separately. But maybe somebody more expert can confirm/correct this – Bordaigorl Sep 10 '14 at 9:13
  • I wouldn't allow a line break immediately before an em-dash. – Mico Sep 10 '14 at 9:13
  • @Mico you mean between "some" and "---" in the example? That's up to the OP, he hasn't provided a MWE so I am just guessing this is the problem... – Bordaigorl Sep 10 '14 at 9:15
  • I think the OP's objective is to find a way to permit LaTeX to hyphenate words that precede or follow an em-dash. I think it's generally accepted that it's also OK to insert a line break immediately after an em-dash. What I don't think is desired is to permit a line break immediately before an em-dash. – Mico Sep 10 '14 at 9:18
  • First of all, sorry for not providing a MWE (a newbie fault indeed).Your \hspace proposal did the trick! However the macro would only be partially – Antonio López Sep 11 '14 at 10:54

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.