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 have a large LaTeX document, where hyphens are typeset with a single dash ("-") throughout. In my font, this shows up as a bold and vertically slightly off-center blob, but I'd like it to look like \textendash.

I tried to define - as a command that would translate to \textendash (by inserting \newcommand{-}{\textendash} in the preamble) but of course it didn't work. However I'd like it to work with the current "-" left in, since I 1) don't want to have to go through the entire document to replace the correct ones, and 2) don't want to rely on the next person editing the document avoiding "-" in favor of something else.

Is there any way to make "-" render in a nicer way?

Clarification:

  • It is not necessary for me to use the \textendash specifically - my main concern is that the dashes that are produced, both by my - in the source, and by LaTeX's hyphenation at line-breaks, are ugly. I want a nicer rendering, but I have no specific requirement on which character should be used.
  • The document can contain math minuses, and will definitely contain hyphens in references to file names. I only want to change the actual hyphens - basically, change the character TeX uses when it sees - in the source, and in every place that character would be used in a document.
share|improve this question
    
Note: This also applies to the hyphens inserted by LaTeX when breaking words across lines. –  Tomas Lycken Nov 21 '10 at 12:54
    
Maybe you could get what you want by creating a virtual font to replace the hyphen character. (Having never tried anything like it myself, I can't elaborate.) –  Harald Hanche-Olsen Nov 21 '10 at 13:08
3  
I don't really think that \endash is adequate here; see this post. –  Hendrik Vogt Nov 21 '10 at 13:34
    
Hendrik: That might very well be. But it doesn't change the fact that my hyphens are ugly :) –  Tomas Lycken Nov 21 '10 at 14:26
    
@Tomas: I just meant that changing to \endash might not be a great improvement. I could even be better to take the CM hyphen instead. –  Hendrik Vogt Nov 21 '10 at 17:25

4 Answers 4

Well you can make the - active and then define it. But it will affect all hyphens: real hyphens, math minus, hyphens in file names. On the whole I would say: don't do it. The trouble you get will cost you more time than changing you document.

\documentclass{article}
\begin{document}
\catcode`\-=\active
\newcommand-{hallo}

a - b

so-called

$1-1=0$

%\input{test-hyphen} %error
\end{document}
share|improve this answer
    
Thanks for the reply, but unfortunately this is not an option. I need this to work with both math and file names, too... –  Tomas Lycken Nov 21 '10 at 22:47
7  
Rereading your question I realize that you are not trying to correct bad input (word - word instead of word -- word) but that you don't like the look of the hyphen of your font. This is a decision of the font designer and the general advice if one doesn't like the look of a font is: use another font. In special cases it is also possible to exchange one glyph, but you should give more informations about the font and your engine. –  Ulrike Fischer Nov 22 '10 at 8:38

One option is to make - an active character:

\documentclass{article}
\let\saveminus=-
\catcode`-=\active
\newcommand-{\ifmmode\saveminus\else\textendash\fi}
\begin{document}
well-known $a-b$
\end{document}

In this solution, - in mathmode still acts as a normal minus sign. But making - active may cause other problems, e.g. if you want to use \vspace{-1ex}.

Update: To change the automatically inserted hyphens, use

\hyphenchar\font=\textendash
share|improve this answer
    
Did you actually try \hyphenchar\font=\textendash? I have a hard time seeing how that could possibly work, as \textendash is not an integer. –  Harald Hanche-Olsen Nov 21 '10 at 14:57
1  
@Harald: Yes, I did, and to my surprise it worked. (As a principle, I try to test everything before I post it.) –  Hendrik Vogt Nov 21 '10 at 15:52
    
The \hyphenchar\font=\textendash approach seems promising, but unfortunately it only seems to affect hyphens at line breaks. Is there a similar command for what char will be used when LaTeX sees - in the source? –  Tomas Lycken Nov 21 '10 at 22:48
    
Surprising indeed. I had to run a test with macro and command tracing turned on to see why it works. It turns out not to be totally accidental: \textendash expands into some tests for protectedness and math mode – with an empty result – followed by a command sequence that has ben chardef'd to the endash character. So I guess this goes in the “somewhat dirty hacks” category. –  Harald Hanche-Olsen Nov 21 '10 at 23:06
    
@Tomas: In a word, no. Not in standard (e)latex, anyhow. I don't know what can be achieved with luatex. That is a whole different kettle of fish. –  Harald Hanche-Olsen Nov 21 '10 at 23:09

Here's an answer that is more robust than using an active character but it will only work in XeTeX (not LuaTeX). It will only affect hyphens that have spaces around them, so (rightly) something like «co-ordinate» will still use a regular hyphen.

\documentclass{article}
\usepackage{xesearch}
\UndoBoundary{-}
\SearchList{dash}{--}{-}
\begin{document}
There is no just ground, therefore, for the charge brought against me by
certain ignoramuses - that I have never written a moral tale, or, in more
precise words, a tale with a moral. They are not the critics predestined
to bring me out, and \emph{develop} my morals: - that is the secret. By and by
the ``North American Quarterly Humdrum'' will make them ashamed of their
stupidity. In the meantime, by way of staying execution - by way of
mitigating the accusations against me - I offer the sad history appended, -
a history about whose obvious moral there can be no question whatever,
since he who runs may read it in the large capitals which form the title
of the tale. I should have credit for this arrangement - a far wiser one
than that of La Fontaine and others, who reserve the impression to be
conveyed until the last moment, and thus sneak it in at the fag end of
their fables.
\end{document}

Courtesy Paul Isambert's nice xesearch package for the convenient interface to XeTeX's interchar toks feature.

share|improve this answer

What about just using --? It is not so esoteric since it is pretty common to write en-dashes in such way in ASCII formatted media.

share|improve this answer
    
This doesn't take into account point 2) in the question. –  Hendrik Vogt Nov 22 '10 at 15:55
    
@Hendrik Yeach, but this is something pretty easy to enforce (especially in comparison to \textendash). Also other solutions will mess up all minuses. –  mbq Nov 22 '10 at 15:58

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.