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.

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).

share|improve this question
    
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 '12 at 16:11
    
Use your editor's text replace feature and make a habit of writing ~-- from now on. –  Andrey Vihrov Feb 16 '12 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). –  Ulrike Fischer Feb 16 '12 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 '12 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. –  Roelof Spijker Feb 16 '12 at 16:33

1 Answer 1

up vote 0 down vote accepted

Found a workaround for XeTeX:

\usepackage{ifxetex}

\ifxetex
    \usepackage{xesearch}
    \UndoBoundary{-}
    \SearchList{dash}{--}{-}
\else
    \typeout{Well, too bad.}
\fi

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

share|improve this answer

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.