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

I'm using the document class scrartcl and I'm looking for a way to write equations in which all letters are upright like it appears when using \rm.

$$\rm A_{something} + B_{another} = C_{whatever}$$


Because the use of \rm is deprecated my question is: is there way to achieve the same without enclosing every bit of text in \text{}?

$$\text{A}_{\text{something}} + \text{B}_{\text{another}} = \text{C}_{\text{whatever}}$$

• Do you want this in all equations or just in selected ones? It's bad style anyway, however. – egreg Feb 4 '15 at 16:55
• Do any of the ideas in tex.stackexchange.com/q/4155/15925 help? – Andrew Swann Feb 4 '15 at 16:56
• @AndrewSwann: Well I don't want to "work around" this issue by selecting a whole new font I just want to be the current font upright in a certain scope. Is there a way to set this font-style explicitly? – a_guest Feb 4 '15 at 17:04
• @a_guest I think what you are after (at least what you said you are after) is wrong. \text{A}_{\text{something}} is wrong; the similar and correct thing would be \mathrm{A}_{\text{something}} (A is not text but a variable, if you want it to be upright then \mathrm is the way to go). – Manuel Feb 4 '15 at 17:20

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.

\documentclass{scrartcl}

\begin{document}

$$\mathrm{A_{something} + B_{another} = C_{whatever}}$$

\end{document}

• Neat solution for what I was asking! Just out of curiosity: I tried the same with \text{} instead of \textrm{} but this won't compile, I guess because of the underscores which can only be treated in math mode while \text{} "escapes" the math mode. Also using \textrm{} changes the whole font of the scope, doesn't it? And is there a way to make a new environment out of that? – a_guest Feb 4 '15 at 17:29
• \text is never going to work for this - it is switching you out of math mode, so underscores etc. are not allowed. \textrm is essentially \text followed by a selection of the roman font, so has the same problem. – Andrew Swann Feb 4 '15 at 19:32

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}

$$A_[something] + B_[another] = C_[whatever]$$

\end{document}


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 took me a while until I realized that \catcode\_=12  was necessary. I couldn't understand why the code didn't work. – Manuel Feb 4 '15 at 17:34
• This works for the subscripts but I also want A, B, C to be upright. Something like \mathrm{} wrapped around the whole equation as in AndrewSwann's answer. I'm curious whether there is a way without changing the whole font but only its style. – a_guest Feb 4 '15 at 17:42
• I still don't understand why would you want A to be upright. This sentence Because I think it looks clearer when dealing with long subscripts is what I don't understand. If you actually are going to have A_i meaning something similar to A_[something] and one is going to be upright just because it looks good when using long subscripts, I think it's definitely wrong. – Manuel Feb 4 '15 at 17:45
• I think it's not about right or wrong it's just a matter of taste. a+b=c is something which can be true or false (or right or wrong, whatever) but if I deal with equations it doesn't really matter (to me) if letters are italic or not (when regarding their meaning). At least for me variables don't change their meaning only by the font they are written in. And my question is not about "is it good style to have all characters upright in an equation" it's about "how you can achieve this". If you're not comfortable with the style then why don't you regard it just as a challenge ;). – a_guest Feb 4 '15 at 17:53
• Your question shouldn't be (at least in this site) “is it good style..” but of course, answers can contain suggestions :) I would solve your problem with this solution, altough you don't like it. I leave it here, it might be of use for other people. – Manuel Feb 4 '15 at 17:57

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
\repeat
\count255=a
\loop
\mathcode\count255=\numexpr\mathcode\count255-\string"100\relax
\ifnum\count255<z
\repeat
}

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


• Didn't we have something similar not so long ago? I remember some discussion about \mathcode versus other approaches. – Joseph Wright Feb 4 '15 at 17:10
• This is nice. Could you explain what you are doing? How to do the same with bold (like \bf in plain TeX). – Manuel Feb 4 '15 at 17:12
• @Manuel The mathcode of a is "7161 so the letter is taken from math family 1. What I do is subtracting "100` from the math code of all letters, so they're taken from family 0. Determine the number of the bold font family and you're done. – egreg Feb 4 '15 at 17:17
• Quite a complex solution but seems to do the job and also to have pretty much flexibility regarding the font which you want to use! Why I want to have some equations in upright font? Because I think it looks clearer when dealing with long subscripts. – a_guest Feb 4 '15 at 17:36
• @a_guest semantically speaking, the right thing to do is to put only the subscripts in upright font, because the subscripts are text. But the main letters (A, B, C) are variables and would remain in math (italic) font. – David Z Feb 5 '15 at 0:52