# modify default underscore behaviour/interpretation

Is there any way to modify the default in-text underscore behaviour document-wide?

I'm utilising a lot of filenames, IDs and so on which often have underscores in, and LaTeX doesn't like this (missing $inserted....). Its becoming laborious to change these every time. Can I do something to resolve this once and for all document-wide without breaking anything? • \catcode_=12 (and then use \sb to get subscripts in math – David Carlisle Feb 7 '18 at 16:11 ## 2 Answers Use \catcode_=12  and then use \sb to get subscripts in math \documentclass{article} \usepackage[T1]{fontenc} \catcode_=12 \begin{document} This is a_document_with_underscores and _mathematics_$x\sb{2}\$
\end{document}


You can use _ as subscript prefix in math mode and the same _ as normal character outside math mode. Try this:

\catcode\_=13  \let_=\sb
\mathcode\_="8000
\catcode\_=12

• This looks ideal as I do have several equations I'd prefer to not have to modify as well. – Joe Healey Feb 8 '18 at 10:29