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.

Could you explain to me why

a\_b {\ttfamily a\_b} \\
\chardef\_=`\_
a\_b {\ttfamily a\_b}

produces

alt text

?

I would like to have the short underscore in the normal text and the long one in fixed-width font. I cannot change {\ttfamily a\_b}. The other a\_b I can change.

Thanks for your help!


EDIT: I realized that a\textunderscore b solves my immediate problem in text. I would still like to know where the mysterious dot is comming from.

In math mode,

\chardef\_=`\_
$a\_b$

LaTeX stops compiling altogether on my installation (without error, it just halts).

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Your \chardef defines \_ to be the character in position "5F (ASCII for the underscore character), and that position just happens to contain the mysterious dot. At least it does in cmr10, and apparently it does in the font you're using as well (run (pdf)tex testfont to make font tables for any font you're curious about). The standard definition of \_ in plain TeX just typesets a rule of some suitable width, as there isn't any underscore glyph in the cmr font. I assume something similar is true in LaTeX, though I haven't bother to dig my way past the \textunderscore magic.

I am not too sure about what you can do, though. The whole LaTeX font selection business is a weak point of my TeX foo.

share|improve this answer

In a fix-width font every symbol should have the same width. So a long underscore is a bit unusual. In any case: in OT1-encoding (which you are obviously using) \_ calls internally \textunderscore, which in turn is define as a rule of width 0.3em and some space. You can redefine \_ to get a longer rule and use \textunderscore at other places:

\documentclass{book}
\DeclareTextCommand{\_}{OT1}{%
  \leavevmode \kern.06em\vbox{\hrule width.6em}}

\begin{document}
a\textunderscore b  {\ttfamily a\_b}
\end{document}

example

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.