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


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, x\sub{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

  • 1
    Welcome to TeX.SE.
    – Mico
    Commented Sep 28, 2020 at 18:19
  • 1
    \newcommand{\sub}[1]{_{\mathchoice{}{}{\scriptstyle#1}{\scriptscriptstyle#1}}} ? Commented Sep 28, 2020 at 21:47
  • @DavidCarlisle Thanks! Great suggestion — a simple solution that hadn't crossed my mind. The only thing I dislike about it is that it cannot detect the external context (not a TeX guru so forgive me if this is not the right terminology). What I mean is that, if used (for example) in a nested subscript, mathchoice will not be able to detect this. This is a bit of a fringe use case, however, and I don't think it would be a deal breaker to have to live with it.
    – corvus
    Commented Sep 29, 2020 at 1:17
  • @corvus in a top level script the style will be script so the thirds branch taken, in a nested script the style will be scriptscript so the 4th branch taken Commented Sep 29, 2020 at 7:39
  • It's hard to understand what this is for. With your macro, the subscript only appears when \sub is used in display math mode, with David's definition, it will appear exactly as if you type _{i} instead of \sub{i}, so what's the idea behind all this?
    – egreg
    Commented Sep 29, 2020 at 10:46

1 Answer 1


You should move the _ out of the mathchoice.


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.

You must log in to answer this question.

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