6

I have a whole section full of text that contains lots of letters with supscripts. I've been using math mode to do this, but the result doesn't look so nice with all the letters in italics (it looks like a math paper when it isn't).

I also know about \textsubscript to use subscripts outside of math mode. Is there a way I could wrap my entire section in an environment to disable italics in math mode?

\documentclass[11pt]{article}
\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.
\end{document}

enter image description here

DrummerB
  • 821
  • If you just want text subscripts, you could just make _ an active character, and define it to be \textsubscript. – Thruston Sep 18 '16 at 14:41

3 Answers3

10

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

egreg
  • 1,121,712
  • Elementary, Watson… ;-) – GuM Sep 18 '16 at 11:34
  • You're right, I might not need math mode at all. I like the answer Gustavo and you suggest and this solves my problem perfectly. But now I'm interested how you would write subscripts without math mode? Is there an other way, besides using \textsubscript, a shorter redefinition, or a custom command like \sub{A}{1}? – DrummerB Sep 18 '16 at 13:00
  • @DrummerB A\textsubscript{1} works out of the box. – egreg Sep 18 '16 at 13:12
  • @DrummerB: You shouldn’t like my answer: it’s silly. I hope you haven’t got anything to object if I remove it. – GuM Sep 18 '16 at 17:45
  • @GustavoMezzetti What's wrong with it? Seems to work. – DrummerB Sep 18 '16 at 23:20
  • That doesn't work completely. The π in the bottom example is still italic. – matj1 Sep 12 '23 at 16:38
  • @matj1 \pi doesn't obey math group changing. – egreg Sep 12 '23 at 16:53
  • @egreg Yes, but I would prefer that all letters would be treated in the same way, at least in Latin, Greek and Cyrillic scripts, which are compatible typographically. I guess that treating Greek letters specially is a vestige of 8-bit encodings, where Latin and Greek letters don't fit in the same character/glyph set. – matj1 Sep 12 '23 at 17:46
  • @matj1 You’d need to change the whole math font setup. – egreg Sep 12 '23 at 19:18
6

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.

N. Virgo
  • 4,289
  • 2
  • 26
  • 41
3

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

Fran
  • 80,769