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.

How can I produce the text Word_one_two in LaTeX?

I tried:

Samp\_Dist\_Corr

But, it doesn't quite look right. Also, I want it in the typewriter font, so actually, I'm doing:

\texttt{Samp\_Dist\_Corr}

I find it looks a bit like the underscore is merging in to the bottom of the "D", but maybe it's just because of the typewriter D?

share|improve this question
3  
This reminds me of one of my pet peeves : all these unneeded special characters in the text mode. If you use the underscore package, then you don't need to escape the _ in text mode. FWIW, in ConTeXt, _ has a letter catcode in text mode, so simply typing Samp_Distt_Corr works. –  Aditya Mar 20 '12 at 3:17
1  
underscore works, but Vim still highlights it as an error. To avoid, edit vimXX/syntax/tex.vim: texOnlyMath "[_^]" becomes "[\^]". –  Evgeni Sergeev Jul 16 '13 at 4:40
    
Hmm, an annoyance with the underscore package is that it's not bold in \textbf{a_b}. –  Evgeni Sergeev Jul 30 '13 at 7:34
1  
A greater annoyance is that one cannot \includegraphics{filename_with_underscore} when the underscore package is used. –  Evgeni Sergeev Aug 1 '13 at 2:27
    
The solution I've settled on was to \usepackage[Q=yes,pverb-linebreak=no]{examplep} and then \Q{identifier_typeset_in_monospace}. This suits me, because all my underscores occur in code: variables, function names, filenames, etc., all of which could be typeset in a verbatim-like environment. –  Evgeni Sergeev Aug 23 '13 at 4:00
add comment

3 Answers

up vote 21 down vote accepted

You may prefer the character from the tt font:

\documentclass{article}

\begin{document}

\texttt{Samp\_Dist\_Corr}

\verb|Samp_Dist_Corr|

\texttt{Samp\char`_Dist\char`_Corr}

enter image description here

Or probably better add \usepackage[T1]{fontenc} then all the above forms will use the character from the font.

\end{document}
share|improve this answer
    
I wonder why when _ is used in text mode LaTeX is not smart enough to send it to output directly? –  PHPst Oct 11 '13 at 18:23
    
@PHPst This is not LaTeX it is very low level TeX behaviour and in general TeX doesn't do such switches, compare the behaviour of say \alpha also in the original TeX OT1 encoded TeX fonts, they typically didn't have a _ character so it isn't clear what "output directly" means, choice of switching to tt which did have, or using a rule or... –  David Carlisle Oct 11 '13 at 18:27
    
' it isn't clear what "output directly" means,...' It could simply consider it similar to all other characters by default in non-math mode. –  PHPst Oct 12 '13 at 5:11
    
@PHPst in the standard OT1 encoding, that wouldn't be useful try setting \catcode`\_=12 (to make it a standard punctuation character) and you'll seee that unless in tt font you get a dot accent, same as < and > are not useful out of text mode and give spanish punctuation inverted ! and ? –  David Carlisle Jan 5 at 2:17
add comment

You can use \textunderscore also.

\documentclass{article}
%
\begin{document}
Samp\textunderscore Distt\textunderscore Corr

\texttt{Samp\textunderscore Distt\textunderscore Corr}
\end{document}

enter image description here

Underscore is not merging at the bottom of D actually. It is very close to it.

share|improve this answer
add comment

A fairly elementary way of stripping special meaning from things is to \detokenize them:

enter image description here

\documentclass{article}
\begin{document}
\texttt{\detokenize{Samp_Dist_Corr}}

\texttt{\detokenize{a@b\c_d&e~f g}}
\end{document}

Note how a space is inserted after a "control sequence". See What are the exact semantics of \detokenize?

share|improve this answer
add comment

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.