TransWikia.com

Alignment of subscripts and superscripts that employ mathchoice

TeX - LaTeX Asked on October 15, 2020

I have defined a macro which, for the purposes of demonstration, I have stripped down to the following:

newcommand{sub}[1]{mathchoice{_{#1}}{}{}{}}

However, with this macro the subscript no longer plays nicely with superscripts. That is to say, depending on the order in which the two are applied, one of them does not align to the right edge of the base symbol. Consider, for example, xsub{i}^{2} and x^{2}sub{i}:

Subscripts & superscripts do not align nicely.

I’d like to get the canonical behavior where both subscript and superscript are basically flush up against the x:

enter image description here

One Answer

You should move the _ out of the mathchoice.

newcommand{sub}[1]{_{mathchoice{}{}{scriptstyle#1}{scriptscriptstyle#1}}}

I left the first two branches empty as they will not be taken as the style inside the _{...} will be scriptstyle or scriptscriptstyle depending on the nesting level, never display or text style.

Answered by David Carlisle on October 15, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP