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}
a_guest
  • 351
  • Do you want this in all equations or just in selected ones? It's bad style anyway, however. – egreg Feb 04 '15 at 16:55
  • Do any of the ideas in http://tex.stackexchange.com/q/4155/15925 help? – Andrew Swann Feb 04 '15 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 04 '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 04 '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 04 '15 at 17:20
  • @Manuel: You are right, in fact I didn't want the effect of \rm in the first place, I just wanted the font of the scope to be upright and \rm was the only "easy" thing I could think of which did this (amongst other effects). Because \mathrm{} actually changes the font of the scope it does more than "required" (which is no problem for me, just as a general comment). – a_guest Feb 04 '15 at 17:24

4 Answers4

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}
0 _
  • 958
Andrew Swann
  • 95,762
  • 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 04 '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 04 '15 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|.

Manuel
  • 27,118
  • 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 04 '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 04 '15 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 04 '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 04 '15 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 04 '15 at 17:57
  • @Manuel, (+1) that is awesome, great answer! I'm always doing _{\text{stuff}}, it makes the code too polluted. Though sometimes upright superscripts come in handy, could you implement that to your answer? (I don't know how to fiddle with catcodes to do it myself :/) – Guilherme Zanotelli Nov 25 '16 at 10:20
  • @GuilhermeZ.Santos Done. May be you prefer A_|text|, I added an explanation below. – Manuel Nov 25 '16 at 11:41
  • @Manuel, that is wonderful! I know it's very little code (thus easy to copy paste), but perhaps it could be made into a package easyscripts or something, with option to set the active character between ||, [] and/or others. I know I'd be an active user... Unless it has compatibility issues I'm (we're?) unware of. – Guilherme Zanotelli Nov 25 '16 at 11:50
  • @GuilhermeZ.Santos If you mean that it could be broken with some rare code, almost definitely, but that depends on what weird things are you planning to write there. If it's just text then absolutely zero problems, for instance, if you write A_[abc[def]ghi] well, it doesn't work as you expect, but if you need that I can write a workaround. About the package, I see no need. You can write your own package if you prefer. If you need anything particular just ask. – Manuel Nov 25 '16 at 11:55
  • @Manuel, I meant about conflict with other packages, if it was made into one... I'll put definetely only text there, maybe some \theta but nothing extraordinary. I think I'll write the package, to me this is very useful. Thank's for the update. :) – Guilherme Zanotelli Nov 25 '16 at 12:50
  • @GuilhermeZ.Santos Remember that if you want to write \theta you should use A_\theta or A_{\theta}, not A_[\theta] because that would be equivalent to A_{\text{\theta}} which gives an error. And it may conflict, but not very probable. If you have a particular problem, don't hesitate to ask. – Manuel Nov 25 '16 at 13:23
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

egreg
  • 1,121,712
  • Didn't we have something similar not so long ago? I remember some discussion about \mathcode versus other approaches. – Joseph Wright Feb 04 '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 04 '15 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 04 '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 04 '15 at 17:36
  • 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 05 '15 at 00:52
  • I'm pretty sure that doesn't work with unicode-math. – Henri Menke Aug 21 '17 at 02:31
  • 1
    @HenriMenke Sure. Did I claim it does? I said, instead, it's a bad idea to begin with. – egreg Aug 21 '17 at 08: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.

Cicada
  • 10,129