1

I want to set all sub-/superscripts in math mode of an existing document in non-italic style. How can I change the commands ^ and _, appropriately?

2

1 Answer 1

1

Stealing from and extending (for superscripts) wipet's answer at cited question, Typeset subscript material automatically in upright font shape

EDITED to replace \rm with \mathrm{}, since the memoir class (used by the OP) does not support \rm. Of course, this will break the use in plain TeX, which wipet touted.

\documentclass{memoir}
\def\subinrm#1{\sb{\mathrm{#1}}}
{\catcode`\_=13 \global\let_=\subinrm}
\mathcode`_="8000
\def\supinrm#1{\sp{\mathrm{#1}}}
{\catcode`\^=13 \global\let^=\supinrm}
\mathcode`^="8000
\def\upsubscripts{\catcode`\_=12 } \def\normalsubscripts{\catcode`\_=8 }
\def\upsupscripts{\catcode`\^=12 } \def\normalsupscripts{\catcode`\^=7 }
\begin{document}
\upsubscripts
$A_{lake}  a_x a_x^y$

\upsupscripts
$A_{lake}  a_x a_x^y$

\normalsubscripts\normalsupscripts
$A_{lake}  a_x a_x^y$
\end{document}

enter image description here

9
  • Thanks a lot. One comment: I use document class memoir. Only the first letter of subscript "lake" in the first and second formulation is typed non-italic. Maybe a conflict of document class?
    – Mathias
    Sep 22, 2017 at 12:55
  • @Mathias With memoir, I get \rm not supported in math mode error. Sep 22, 2017 at 13:02
  • @Mathias Please see my revision. Sep 22, 2017 at 13:07
  • In memoir following is necessary: \renewcommand{\sl}{\textsl} \renewcommand{\rm}{\textrm}
    – Mathias
    Sep 22, 2017 at 13:09
  • @Mathias I think one wants \mathrm rather than \textrm. That way, the supscripts can contain, for example, \cos and \alpha, etc.. Sep 22, 2017 at 13:13

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