All letters upright in math mode (equivalent to \rm)

If you like the effect of \rm but don't like that it is deprecated, then taking a look its implementation gives a good clue of what you can do. In source2e you will find (see p.254 of source2e 2017-04-15, where \DeclareOldFontCommand is defined)

 \DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}

which means it is just \mathrm in math mode. Thus you could write \mathrm around your equation contents instead.

Sample output

\documentclass{scrartcl}

\begin{document}

\begin{equation}
    \mathrm{A_{something} + B_{another} = C_{whatever}}
\end{equation}

\end{document}

If what you are after is an easy way of writing \text in subscripts, here's a way. You write A_[something] if you want \text{..} to be applied to the subscript.

\documentclass{scrartcl}

\usepackage{mathtools}

\def\sbtext[#1]{\sb{\textnormal{#1}}}
\def\sptext[#1]{\sp{\textnormal{#1}}}
\makeatletter
\begingroup\lccode`\~=`\_\lowercase{\endgroup
  \def~}{\@ifnextchar[\sbtext\sb}
\begingroup\lccode`\~=`\^\lowercase{\endgroup
  \def~}{\@ifnextchar[\sptext\sp}
\makeatother

\AtBeginDocument{\catcode`\_=12 \mathcode`\_="8000 \catcode`\^=12 \mathcode`\^="8000 }

\begin{document}

\begin{equation}
  A_[something] + B_[another] = C_[whatever]
\end{equation}

\end{document}

enter image description here

Also if one prefers A_|something| + B^|something| rather than A_[something] + B^[something] just change the definitions of \sptext|#1| and \sbtext|#1| and subsitute \@ifnextchar|.


It's not clear why you would do this; however, here it is.

\documentclass{article}
\usepackage{amsmath}

\newenvironment{uprightmath}
 {\changecodes\ignorespaces}
 {\ignorespacesafterend}

\newcommand{\changecodes}{%
  \count255=`A
  \loop
  \mathcode\count255=\numexpr\mathcode\count255-\string"100\relax
  \ifnum\count255<`Z
    \advance\count255 1
  \repeat
  \count255=`a
  \loop
  \mathcode\count255=\numexpr\mathcode\count255-\string"100\relax
  \ifnum\count255<`z
    \advance\count255 1
  \repeat
}

\begin{document}
Here the letters are normal
\begin{equation}
A_{x}+B_{y}=Z
\end{equation}
\begin{uprightmath}
But here they're upright $A_{something} + B_{another} = Z_{whatever}$
\begin{equation}
A_{something} + B_{another} = Z_{whateverz}
\end{equation}
and back to normal
\end{uprightmath}
\begin{equation}
A_{x}+B_{y}=C
\end{equation}
\end{document}

enter image description here