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

  • 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
9

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

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

  • The current version of mhchem is 4. (And there is also an alternative: chemformula) – clemens Sep 18 '16 at 17:04
  • @clemens thanks, I didn't know that! I've updated the answer use use version 4. – Nathaniel Sep 19 '16 at 1:48
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.