Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The title question is plainly posed—is there a simpler way of doing this (or at least one that actually works?

When dealing with em-dashes (—), I've read that it's important to keep a small amount of space between the dash and the text it separates. I'm guessing at half of an inter-word skip, whatever that may be. (I might change it to 2/3 depending, but that's irrelevant to the core question.)

With ideal inter-word spacing, it's recommended (though I can't recall where) that this spacing be a \thinspace. (Try this---separation vs. this --- separation—neither look very good.) However, as you can see from the (exaggerated) screenshot below, this can cause visual inconsistencies (particularly noticeable in the first line of the second paragraph). (I recognize that this is also influenced by the font used.)

original problem screenshot

My attempt to fix this problem:

\documentclass{article}

\newlength\halfinterwordspace
\newsavebox\interwordspace

\newcommand\Dash{%
  \savebox\interwordspace{\ }
  \setlength\halfinterwordspace{.5\wd\interwordspace}
  \typeout{\the\halfinterwordspace}
%
  \unskip                       % remove all previous skips
  \hspace* \halfinterwordspace  % unbreakable half-interword space
  \textemdash                   % dash, equivalent to "---"
  \hspace \halfinterwordspace   % breakable half-interword space
  % ^ also plays nice with microtype protrusion; see q/163116
}

% Uncomment to see the problem I am ultimately trying to fix.
% \def\Dash{\unskip\thinspace\textemdash\thinspace}

\sloppy
\hyphenpenalty=10000

\begin{document}
Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit.  Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus.  Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus.  Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi.  Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula.  Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.

Curabitur faucibus \Dash feugiat porttitor.  Lorem ipsum dolor sit
amet \Dash consectetur adipiscing elit.  Vestibulum elementum ipsum id
nisl accumsan \Dash sed rutrum sapien tincidunt.  Cras sodales
sagittis neque vitae sollicitudin. Mauris at viverra quam. In nec
interdum diam \Dash ut ultrices velit. Nulla dapibus vulputate
luctus. Etiam vel faucibus augue \Dash ut aliquet massa. Vivamus eu
nunc at velit varius volutpat at eget eros.  Nulla at justo quis quam
sagittis aliquam eget in tellus.  Nunc est sem \Dash congue et tempus
a \Dash aliquet et nibh.  Sed malesuada \Dash nisi eu placerat porta
\Dash orci augue pellentesque ante \Dash ac sollicitudin urna nunc sit
amet tellus. Curabitur hendrerit et enim non vehicula. Donec in nibh
fringilla \Dash sodales arcu eu \Dash hendrerit massa.
\end{document}

Result:

attempt screenshot

share|improve this question
    
The thin space around en-dashes is proper of French typography, but not in American typography. –  egreg Mar 22 at 16:03
    
@egreg Really? I honest-to-goodness think it looks loads better. There's a typography book (a good 300 pages or so) sitting on the stacks near where I work on my thesis; hopefully when I'm done I'll have time to check it out :-) It's difficult to find typography resources (especially online) that aren't overly artsy. –  Sean Allred Mar 22 at 16:08

1 Answer 1

up vote 7 down vote accepted

The normal interword space for the current font is available as

\fontdimen2\font

You're mistaken in considering \hspace* as “non breaking space”: it's a “non disappearing space”.

Here are two pretty similar definitions for your \Dash:

\documentclass{article}

\newcommand\Dash{%
  \leavevmode
  \unskip\nobreak\hspace{.5\fontdimen2\font}%
  \textemdash
  \hspace{.5\fontdimen2\font}%
}

\sloppy
\hyphenpenalty=10000

\begin{document}
Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit.  Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus.  Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus.  Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi.  Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula.  Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.

\renewcommand\Dash{%
   \leavevmode\unskip
   \thinspace\textemdash
   \allowbreak\thinspace}

Lorem ipsum dolor sit amet \Dash consectetur adipiscing elit.  Fusce
pharetra velit in sem congue \Dash quis malesuada lectus
vulputate. Quisque eu scelerisque nunc. Nam at dui eget metus
ullamcorper rutrum quis et tellus.  Interdum et malesuada fames ac
ante ipsum primis in faucibus. Donec vitae augue vel nisi sollicitudin
tempus.  Nam neque sapien \Dash ullamcorper vitae sapien at \Dash
volutpat cursus nisi.  Nullam lorem ante \Dash fermentum sit amet
fermentum et \Dash rhoncus id ligula.  Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas.
Integer congue \Dash sem eu tincidunt pharetra \Dash mi nunc accumsan
neque \Dash in auctor elit eros eget eros. Vestibulum quis varius
lectus.

\end{document}

Points to note:

  1. With \nobreak\hspace{...} we set a non breaking space

  2. A kern, and \thinspace is one, cannot be used as a line break point unless it's followed by glue; a penalty will be a feasible line break point and \allowbreak just adds a zero penalty.

  3. The normal interword space for the Computer Modern font at 10pt size is 3.33pt; a thin space is .16667em and an em is 10pt, so at the end a thin space (at least with this font setup) is just the same as a half space.

enter image description here

If you want to add flexibility to the space around the em-dash, then

\newcommand\Dash{%
  \leavevmode\unskip\nobreak
  \hspace{\halfspace}%
  \textemdash
  \hspace{\halfspace}%
}
\newcommand{\halfspace}{%
  .5\fontdimen2\font plus .5\fontdimen3\font minus .5\fontdimen4\font
}

We use the fact that \fontdimen3 and \fontdimen4 contain the default stretchability and shrinkability of the interword space.

See What does different \fontdimen<num> mean for a list of what \fontdimen parameter mean.

share|improve this answer
    
So I think I understand everything here (thanks!), but it doesn't seem like it had any effect. Look closely at the third-to-last line of either paragraph—Integer congue—sem eu tincidunt…. The space on either side of the dash doesn't seem to be half of the space that separates Integer and congue. My knowledge of the core of TeX is getting better but isn't nearly complete yet—wouldn't this 'space' rather be a 'skip'? –  Sean Allred Mar 22 at 16:29
    
@SeanAllred You can also add flexibility to the space around the dash, if this is what you mean. –  egreg Mar 22 at 16:43
    
Yes, I'm sorry if I was confusing. –  Sean Allred Mar 22 at 16:46
    
@SeanAllred I added it. –  egreg Mar 22 at 16:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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