14

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.

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

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{}?

\begin{equation}
    \text{A}_{\text{something}} + \text{B}_{\text{another}} = \text{C}_{\text{whatever}}
\end{equation}
6
  • Do you want this in all equations or just in selected ones? It's bad style anyway, however.
    – egreg
    Feb 4, 2015 at 16:55
  • Do any of the ideas in tex.stackexchange.com/q/4155/15925 help? Feb 4, 2015 at 16:56
  • I want it for some equations (not all of them). Preferably this would result in an extra environment and if I use renewcommand or newcommand doesn't matter then.
    – a_guest
    Feb 4, 2015 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, 2015 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, 2015 at 17:20

4 Answers 4

12

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}
2
  • 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, 2015 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. Feb 4, 2015 at 19:32
7

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|.

11
  • 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, 2015 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, 2015 at 17:42
  • 2
    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, 2015 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, 2015 at 17:53
  • 2
    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, 2015 at 17:57
3

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

7
  • Didn't we have something similar not so long ago? I remember some discussion about \mathcode versus other approaches.
    – Joseph Wright
    Feb 4, 2015 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, 2015 at 17:12
  • 1
    @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, 2015 at 17:17
  • 1
    @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, 2015 at 0:52
  • 1
    @HenriMenke Sure. Did I claim it does? I said, instead, it's a bad idea to begin with.
    – egreg
    Aug 21, 2017 at 8:13
1

The question asks how to write equations, so this is not an answer in that sense. Here, I suggest a method on how to draw them.

Since + is an operation of coalescence, in general, and = indicates identity (such that C is A and B combined together), and since everything algebraic can be represented visually, the TikZ solution

raindrops

is presented by:

MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}
  \begin{tikzpicture}[%
    >=stealth,
    node distance=1.6cm,
    on grid,
    auto
  ]
    \node[state] (A)  [align=center,fill=blue!5]{{\large\textit{A}}};
    \node        (A1) [align=center,pos=0.25,left = of A,fill=green!15]{Raindrop\textit{\textsubscript{s\textsubscript{1}}}};
    \node        (S1) [below = of A]{};
    \node[state] (B)  [align=center,fill=blue!5,below=of S1]{{\large\textit{B}}};    
    \node        (B1) [align=center,left = of B,fill=green!15]{Raindrop\textit{\textsubscript{s\textsubscript{2}}}};
    \node[state,double] (C)  [align=center,fill=blue!5,right=of S1,minimum size=3.8em]{{\large\textit{AB}}};    
    \node        (C1) [align=center,right = of C,fill=green!15]{Raindrop\textit{\textsubscript{B\textsubscript{1}}}};
    \draw[->]   (A) edge (C);
    \draw[->]   (B) edge (C);    
      \end{tikzpicture}
\end{document}

which may be easier for some to grasp, since mixing two styles (algebra and plain language) adds a cognitive load for the reader since they have to untangle the two and then compare how their meanings intertwine.

It becomes immediately apparent upon inspection that the AB combination, C, has properties different to its constituents (e.g., evenness), implying that the identity (=) is only a partial description. A transformation has also occurred, with the creation of a new entity.

The letters can be upright or italic, as one pleases.

You must log in to answer this question.

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