I would like to set up my LaTeX (XeTeX) document in such a way so that I could type a hyphen (-, the one on the keyboard) and it would get replaced with an en-dash (, the "longer" dash) in the resulting document.

For example, for a LaTeX source:

Lietuvos intelektualai - prieš liberaliąją demokratiją? % "Usual" dash typed

I would like to get the en-dash ("long" dash) in the rendering:

Lietuvos intelektualai – prieš liberaliąją demokratiją?

and not the usual hyphen ("short" dash):

Lietuvos intelektualai - prieš liberaliąją demokratiją?

I'm aware that this could be achieved by typing two hyphens (--) instead of a single hyphen (-), but is there a better way to do that?

(Due to the nature of documents I typeset and the requirements of the language I use, I'm required to type an en-dash 98% of all times and might need the "usual" hyphen just occasionally).

  • Better in what way? What do you find wrong with the way it is? Also, are you entirely sure that you will not want to write a hyphen at all? Or do you want to remap that to something else as well?
    – jonalv
    Feb 16, 2012 at 16:11
  • Use your editor's text replace feature and make a habit of writing ~-- from now on. Feb 16, 2012 at 16:13
  • 8
    One could define a mapping which replace the hyphen. But this would also affect hyphens inserted a hyphenation points – where such an en-dash is wrong. And quite probably you will soon fine other places where you actually don't want the en-dash (like in en-dash). In the long run you will probably spend more time to get around the side-effects than you gain now by avoiding a correct input (either -- or a real en-dash). Feb 16, 2012 at 16:15
  • Also, since you're using XeLaTeX, there's no reason not to simply type the relevant character directly in your source.
    – Alan Munn
    Feb 16, 2012 at 16:26
  • I agree with most others here that it's not a good idea, but if you really want it, you can make the dash active and replace it with \textendash. You can simply write \catcode`-=13\def-{\textendash} and then use - as if it were an endash. Feb 16, 2012 at 16:33

1 Answer 1


Found a workaround for XeTeX:


    \typeout{Well, too bad.}

Also, note the comments under the original question discussing why automatic replacements are not always a good idea.

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.