How does LaTeX implement the differences between the dashes? -, --, and --- all print different dashes, but - is not an active character: it has catcode 12, the same as digits like 2.

2 Answers 2


This answer does not apply to newer TeX engines, such as XeTeX and LuaTeX. By default, these will not treat -- as anything other than --. fontspec can emulate the traditional engines' behaviour.

These are, as Tobi pointed out, implemented as ligatures just like fi, fl etc. More specifically, the TeX Font Metric file (which just is a font as far as TeX is concerned) contains information about the ligatures for the font. A 'font' in this sense is a font in a particular encoding - either an encoding which more-or-less corresponds to the kind you would use in a document (OT1, T1 etc.) or an encoding with some other purpose.

When TeX needs a font, it looks for a TeX Font Metric file e.g. ec-lmr5.tfm. This doesn't contain any actual glyphs - no pictures of the characters. ec-lmr5.tmf only tells TeX about boxes, which is all TeX itself really cares about. (Everything is a box.) But the .tfm includes information about what to do when the box which corresponds to - is followed by another box of the same kind. It tells TeX to replace those two boxes with a different box, corresponding to . It also tells it that if that box is directly followed by another instance of the first box, it should do another replacement for the boxes, using the box corresponding to .

This is dependent on the encoding used to write or generate the TeX Font Metric files. This is not the same sense of 'encoding' as the familiar input and output 'encodings' used in documents e.g. utf8 or T1. Let's call these encodings 'tfm-generation encodings' for clarity. It is because the tfm-generation encodings which correspond to the standard text encodings (e.g. OT1, T1 etc.) are defined to include these ligatures that .tfm files are configured in this way. So the tfm-generation encoding files provided by fontinst, for example, include one which corresponds to T1 and which defines the relevant ligatures. When this is used to create .tfm files, fontinst inserts instructions implementing the ligatures. In contrast, for typewriter fonts, for example, the .tfm is usually set up in a way which does not include such ligatures. This ensures that you get what you expect to get as output when you feed TeX given input.

  • 3
    I wouldn't say it's “encoding dependent”: there's no way to disable the ligature (at least in classical TeX) if the font defines it. Indeed, the verbatim mode make - active defining it as a kern followed by a hyphen, so the ligature is “never seen”.
    – egreg
    Commented Dec 13, 2014 at 12:04
  • @egreg It is dependent on the encoding files used to generate the metric files. (Or dependent on the mental encoding if you were to write the metric file by hand.) It is not dependent on either the input or output encoding used in the document - is that what you mean? There are multiple kinds of encoding here...
    – cfr
    Commented Dec 13, 2014 at 17:14
  • T1 and OT1 usually refer to the LaTeX output encodings. You're probably referring to the encodings used with fontinst or similar method. This should be kept distinguished, in my opinion.
    – egreg
    Commented Dec 13, 2014 at 17:18
  • @egreg I've already edited my answer. (I agree.)
    – cfr
    Commented Dec 13, 2014 at 17:26

I add three things to the @cfr answer.

  • These TeX-ligature-features are possible in XeTeX and LuaTeX too. First, they are able to load classic TFMs and this feature is native here. Second, they implements this feature as a special font feature in their OTF font loader. This feature is activated differently in both engines: by mapping=tex-text in XeTeX and by +tlig in LuaTeX.

  • First, these ligatures was implemented by Metafont in Computer Modern fonts. Then these ligatures were autogenerated when new font from Type1 to TFM was prepared because of the the last part of the typical .enc files, where these ligatures are configured.

  • If the font isn't converted to TFM then this ligature feature isn't included. This ligature-feature is unknown and not adopted in typography outside TeX.

  • 1
    They are not in the .enc files, are they? Or maybe I should ask, which .enc files? Look at lm-ec.enc, for example. No ligatures are defined there. .etx files include them (although not in the 'last part' if by that you mean 'after the main part of the file').
    – cfr
    Commented Dec 13, 2014 at 17:32
  • @cfr When I do cd ..texmf../fonts/enc and grep -r LIGKERN . | grep endash then I get the occurrences in 64 various files. For example in the ec.enc or xl2.enc files.
    – wipet
    Commented Dec 13, 2014 at 18:36
  • And those are not commented lines? I get results for comments for some files in the lm package, for example. (Actually only one file.)
    – cfr
    Commented Dec 13, 2014 at 18:57
  • No, these "commented lines" are interpreted by afm2tfm, for example.
    – wipet
    Commented Dec 13, 2014 at 19:00
  • I'd forgotten that. But they are not interpreted by TeX. And they are not the way that, say, ligatures end up in the .tfm files provided by cfr-lm.
    – cfr
    Commented Dec 13, 2014 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .