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 – David Carlisle Feb 7 '18 at 16:11



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 '18 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.