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?

  • 2
    \catcode`_=12 (and then use \sb to get subscripts in math Feb 7, 2018 at 16:11

2 Answers 2




and then use \sb to get subscripts in math

enter image description here





This is a_document_with_underscores and _mathematics_ $x\sb{2}$

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

\catcode`\_=13  \let_=\sb
  • This looks ideal as I do have several equations I'd prefer to not have to modify as well.
    – Joe Healey
    Feb 8, 2018 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .