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?
-
1Duplicate? tex.stackexchange.com/questions/158872/… and this: tex.stackexchange.com/questions/156641/…. The second question in particular, shows automation techniques.– Steven B. SegletesSep 22, 2017 at 12:27
-
As I do not want to change the existing text body, I would like to redefine the aforementioned commands in the preamble. The change should hold for sub-/superscripts with and without curly braces.– MathiasSep 22, 2017 at 12:37
1 Answer
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}
-
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?– MathiasSep 22, 2017 at 12:55
-
@Mathias With
memoir
, I get\rm
not supported in math mode error. Sep 22, 2017 at 13:02 -
-
In memoir following is necessary: \renewcommand{\sl}{\textsl} \renewcommand{\rm}{\textrm}– MathiasSep 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