377

I am trying to insert the symbol in the title of the question, which I copied from a PDF article, but it appears as space in the output file. What is the corresponding LaTeX command?

lockstep
  • 250,273
Tarek
  • 3,933
  • 3
  • 15
  • 6
  • Probably the input encoding does not have the em dash configured. I'd suggest to use the solution by Keks Dose. – topskip Apr 26 '12 at 10:58
  • 6
  • If my typographer's memory serves me, the first item in the list above is not known as a hyphen but as a tee dash. (Or was it simply a matter of tee spaces, en spaces, and em spaces?) Gosh, I used to all know this back when I did actual physical typography... – John Laudun Jan 09 '13 at 03:45
  • 1
    Just came here for an answer, since the em dash looked like a space in the PDF previewer I was using. Turns out the font just had a very thin line for a dash. I embiggened the previewer, and voila!--there were the em dashes! In case someone else has the same issue. – Mike Maxwell Nov 08 '21 at 21:50

5 Answers5

400

The LaTeX command for such a line are three small ones: ---

Keks Dose
  • 30,892
  • 133
    Alternatively \textemdash. – Torbjørn T. Apr 26 '12 at 15:20
  • 13
    Or use Xe/LuaLaTeX and just type . – Caramdir Apr 26 '12 at 20:48
  • 10
    @Caramdir: You don't even have to use Xe/LuaLaTeX; pdfLaTeX with \usepackage[utf8]{inputenc}\usepackage[T1]{fontenc} works fine for directly inputting an em dash . – doncherry Apr 28 '12 at 09:54
  • 5
    This is not a LaTeX command and it doesn't work universally: http://scripts.sil.org/cms/scripts/page.php?item_id=xetex_faq#ligs – Roman Cheplyaka Feb 14 '13 at 09:41
  • 1
    @RomanCheplyaka Yes, you are right, it's not a LaTeX command. But in ten years of using LaTeX it never failed, so thank you for your comment, but for most of the readers the answer contains what they need, doesn't it? – Keks Dose Feb 14 '13 at 11:22
  • 1
    @KeksDose Not for anyone using unicode fonts, as most of us do now. – Marcin Sep 25 '13 at 14:30
  • 11
    If you're using Unicode fonts (i.e. you're using XeTeX or LuaTeX), just add Ligatures = TeX as a font option. You need that for any of the typical TeX conversions such as `````, ', -- etc. – Sverre Sep 25 '13 at 15:08
  • 1
    does \textemdash work in comments, though? test: $\textemdash$ – Erich Mar 27 '15 at 04:16
  • This does not work for math mode. I am using \mbox{---}. Is there a better alternative? – Gautam Sreekumar Jun 10 '22 at 18:57
  • @Caramdir how do i "type" that? – user313032 Mar 06 '24 at 05:51
  • 1
    @user313032 On Linux with a german layout of the keyboard I get all the dashes using the dash key and "AltGr" or dash key and "AltGr" plus Ctrl. – Keks Dose Mar 06 '24 at 09:06
282

The question has already been answered, but for completeness' sake:

  • Hyphen: -
  • En-dash: --
  • Em-dash: ---
Waldheri
  • 2,987
  • 15
    To avoid misunderstandings, I like to call the first one (-) a hyphen, because it's usually not used as a dash. In Unicode it's called Minus-hyphen, that's the one normal keyboards enter. (Unicode also has a symbol called Hyphen. – doncherry May 01 '12 at 13:13
  • 23
    Donald Knuth, for completeness, adds the fourth one, the mathematical minus sign, $-$. (The TEXbook, page 4.) – Pål GD May 15 '13 at 14:57
  • 3
    Using xelatex (XeTeX, Version 3.1415926-2.4-0.9998 (MiKTeX 2.9)) this does not work. Two hyphens just come out as two hyphens. – Marcin Sep 10 '13 at 21:01
  • 4
    @Marcin Add Ligatures = TeX as an option when you load your font. – Sverre Sep 25 '13 at 15:09
  • @Sverre Did you get that from my answer? – Marcin Sep 25 '13 at 17:00
  • @Marcin: No. Your answer was at the bottom, so didn't see it until after I had commented. Anyways, Ligatures = TeX is as I understand the standard way of using traditional LaTeX conversions in XeTeX/LuaTeX. – Sverre Sep 25 '13 at 17:19
  • Also for em dash: | – Andy Barbour Jan 02 '14 at 18:23
92

The latex commands are:

  • Hyphen: -
  • En-dash: \textendash
  • Em-dash: \textemdash

With the latter two, you will likely want to append {}, because they swallow following space.

If you want to use the ligatures -- and --- with standard unicode fonts, use:

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
% and/or - see comments
\defaultfontfeatures{Ligatures=TeX}

This will emulate substitution of unicode characters for certain "latex standard" ligatures which are present as ordinary unicode characters in modern fonts.

Marcin
  • 3,111
  • 5
    It's preferable to use the Ligatures=TeX version, which works both with XeLaTeX and LuaLaTeX, while the other (older) version can't be interpreted by LuaLaTeX. The option can also be used when defining a specific font with \setmainfont, \newfontfamily and similar commands; it's not necessary to use \defaultfontfeatures. If one uses it, probably a declaration \setmonofont should go before \defaultfontfeatures{Ligatures=TeX}. – egreg Sep 25 '13 at 16:03
  • Question to anyone following this thread. Are there any known package clashes? I have \usepackage{fontspec} with \defaultfontfeatures{Ligatures=TeX} with \usepackage{libertine} and I compile with XeLaTeX and I don't get the --- emdash effect at all. I'm considering asking a separate question, but perhaps I'm overlooking something obvious. – PatrickT Apr 30 '16 at 12:06
  • 1
    package clash with \usepackage{xesearch} apparently... – PatrickT Apr 30 '16 at 13:14
  • @PatrickT Right, hence why I include the official latex commands. – Marcin Apr 29 '19 at 17:17
  • ! Fatal Package fontspec Error: The fontspec package requires either XeTeX or LuaTeX. - FWIW – i336_ Mar 25 '21 at 07:51
15

In some contexts it is appropriate to put thin spaces around an em dash, e.g., \,---\,. I defer to the Chicago Manual of Style and Bringhurst on typography for more.

2

I used the command to achieve long dash

\textemdash 

For example:

2021 \textemdash \ The Capability of Wavelet Convolutional Neural Network for Detecting Cyber Attack of Distributed Denial of Service in Smart Grid, ICCWAMTIP, (EI)

enter image description here

Happy N. Monday
  • 131
  • 1
  • 3