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?
Asked
Active
Viewed 824 times
2 Answers
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.
Bordaigorl
- 15,135
-
My explanation is that the hyphenation algorithm cannot find a scheme for hyphenating
---somethingwhile 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 09: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 09: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 09: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
-
First of all, sorry for not providing a MWE (a newbie fault indeed).@Bordaigorl your \hspace proposal did the trick! However the macro would only be partially useful as not all dialogues in a novel end with a ---. Would be nice if LaTeX had a way of automagically replace all (for instance) "
---" with " – Antonio López Sep 11 '14 at 11:04\hspace{0pt}---". Search/replace editor capabilities aside of course. -
\newcommand{\dialogue}{\hspace{0pt}---\hspace{0pt}}would work better. – Antonio López Sep 11 '14 at 11:17 -
@AntonioLópez the
---at the end was just from intepreting "enclosed" as "surrounded by a pair of". Surely you can define a macro with just the symbol. – Bordaigorl Sep 11 '14 at 11:47
3
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---
Fran
- 80,769
-
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
\documentclass{...}and ending with\end{document}. – mvkorpel Sep 10 '14 at 08:52