Change Category Code
For those not interested the functionality of the underscore in LaTeX and just want it to function like any other character, the category code of the underscore can be changed to make it work as might be expected. Here, we assign the underscore the same category code that most punctuation has. Choose one of the following syntaxes according to your preference:
\catcode`\_=12 % alphabetic constant syntax
\catcode`_=12 % alphabetic constant syntax
\catcode"5F=12 % unicode decimal syntax
\catcode'137=12 % octal syntax
\catcode95=12 % decimal syntax
This way, you can go on about your happy life using the underscore as you normally would. If you need to subset text in math mode, the macro \sb
can still be used in math mode for subscript.
Revert Category Code Change
This explanation would not be complete without stating how to restore the underscore to its original category code. Pick one of the following syntaxes according to your preference:
\catcode`\_=8 % alphabetic constant syntax
\catcode`_=8 % alphabetic constant syntax
\catcode"5F=8 % unicode decimal syntax
\catcode'137=8 % octal syntax
\catcode95=8 % decimal syntax
See egreg's answer: Is it safe to set underscore to a non-active character?
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 typingSamp_Distt_Corr
works.underscore
works, but Vim still highlights it as an error. To avoid, editvimXX/syntax/tex.vim
:texOnlyMath "[_^]"
becomes"[\^]"
.underscore
package is that it's not bold in\textbf{a_b}
.\includegraphics{filename_with_underscore}
when theunderscore
package is used._
do, except annoy all of us?