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?
Asked
Active
Viewed 996 times
1
Steven B. Segletes
- 237,551
Mathias
- 13
-
1Duplicate? https://tex.stackexchange.com/questions/158872/is-there-a-way-to-make-math-mode-subscripts-automatically-non-italic and this: https://tex.stackexchange.com/questions/156641/typeset-subscript-material-automatically-in-upright-font-shape. The second question in particular, shows automation techniques. – Steven B. Segletes Sep 22 '17 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. – Mathias Sep 22 '17 at 12:37
1 Answers
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}
Steven B. Segletes
- 237,551
-
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 '17 at 12:55
-
@Mathias With
memoir, I get\rmnot supported in math mode error. – Steven B. Segletes Sep 22 '17 at 13:02 -
-
In memoir following is necessary: \renewcommand{\sl}{\textsl} \renewcommand{\rm}{\textrm} – Mathias Sep 22 '17 at 13:09
-
@Mathias I think one wants
\mathrmrather than\textrm. That way, the supscripts can contain, for example,\cosand\alpha, etc.. – Steven B. Segletes Sep 22 '17 at 13:13 -
I figured out that the solution works fine unless the subscript contains a Greek letter such as \theta. Can you imagine why? – Mathias Sep 22 '17 at 14:01
-
@Mathias My solution works with
\thetain the subscript. It won't work if you use your\textrminstead of\mathrm. – Steven B. Segletes Sep 22 '17 at 14:03 -
The rm's were not the trouble makers. The upright Greek letters are another building site of usepackage newtxmath that I use. Thanks. – Mathias Sep 22 '17 at 14:11
-
@Mathias Oh, you are hoping to also have upright Greek? If you are using pdflatex, you might consider this answer as a possibility: https://tex.stackexchange.com/questions/145926/upright-greek-font-fitting-to-computer-modern/230220#230220 – Steven B. Segletes Sep 22 '17 at 14:17
