Environment that disables italics in math mode

I'm under the impression that this is an XY problem and you probably don't need math mode at all.

However, here's a simple way to do it:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\newenvironment{uprightmath}
 {\everymath{\fam0 }\everydisplay{\fam0 }}
 {}

\begin{document}

Lorem ipsum $A_1$ dolor sit $B_1$ amet, consetetur sadipscing $C_1$ elitr, sed
diam nonumy $AB_1$ eirmod tempor invidunt $BA_1$ ut labore et $ABC_1$ dolore
magna aliquyam $B_2$ erat, sed diam $A_1$, $A_2$, $A_3$ voluptua.  At vero eos
et $B_1$ accusam et justo duo $C_2$ dolores et ea rebum.
\begin{equation}
\int_{-\infty}^{+\infty} e^{-x^{2}} = \sqrt{\pi}
\end{equation}

\begin{uprightmath}
Lorem ipsum $A_1$ dolor sit $B_1$ amet, consetetur sadipscing $C_1$ elitr,
sed diam nonumy $AB_1$ eirmod tempor invidunt $BA_1$ ut labore et $ABC_1$
dolore magna aliquyam $B_2$ erat, sed diam $A_1$, $A_2$, $A_3$ voluptua.  At
vero eos et $B_1$ accusam et justo duo $C_2$ dolores et ea rebum.
\begin{equation}
\int_{-\infty}^{+\infty} e^{-x^{2}} = \sqrt{\pi}
\end{equation}
\end{uprightmath}

\end{document}

The trick is that upright letters in math are always taken from family 0.

enter image description here


Are your formulas chemical formulas? If they are (or, I suppose, even if they're not) you could use the mhchem package. After importing it with

\usepackage[version=4]{mhchem}

you can write an upright version of $ABC_1$ as \ce{ABC1}. (ce stands for 'chemical equation'.) The package also includes a lot of convenient and elegant ways to correctly typeset chemical equations and formulas, if that's of use to you. It works both inside and outside of math mode.


For laziness and readability, what I would do is let \_ act \textsubscript as I almost never use this command.

If you need underscores, you can still use \textunderscore:

\documentclass{article}
\let\_\textsubscript 
\begin{document}
 A\_1  A\textunderscore1
\end{document}

Alternatively, you can limit the scope of this change to a group, so you can use \_ as underscore in the rest of the document.

\documentclass {article}
\begin{document}
A\_1 {\let\_\textsubscript  A\_1} A\_1
\end{document}

Or if you are aware of the side effect, you can also use \url{_} (url package) or \verb|_|, or \detokenize. More about the subject in Underscores in words (text).