# Vertical alignment of left/right subscripts

Using mathtools's \prescript, the subscripts in $\prescript{}{n}X_m$ are not vertically aligned. The problem does not seem to appear when using ${}_n X_m$, but this is undesirable for other reasons.

It seems \prescript does not take into account empty sub/superscripts, like TeX's mechanism does?

Of course I can do $\prescript{}{n}X^{\mbox{}}_m$, but I'd rather have the n up than the m down...

• This is something best reported to the author of mathtools. – barbara beeton Jul 2 at 16:28
• I think that, generally, the leftidx package has a better placement. – Bernard Jul 2 at 16:51
• Just ^{} suffices, instead of ^{\mbox{}} – egreg Jul 2 at 21:36
• This is not something we're going to fix in mathtools, as you can see from egregs example we'd need xparse in order to catch all combinations and we'd rather not make mathtools depend on xparse at this point in time. – daleif Jul 3 at 5:34

It's a bit more complicated than \prescript can deal with. One should add a “phantom” superscript on the other side, if one superscript is present.

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\xprescript}{e{_^}me{_^}}{%
\makexprescript{#1}{#2}{#3}{#4}{#5}%
}

\ExplSyntaxOn
\NewDocumentCommand{\makexprescript}{mmmmm}
{
\bool_lazy_and:nnTF { \tl_if_novalue_p:n { #2 } } { \tl_if_novalue_p:n { #5 } }
{% there is neither a presuperscript nor a postsuperscript
\vphantom{#3} % the nucleus for the prescripts
\tl_if_novalue:nF { #1 } { \sb{#1} } % the presubscript
#3 % the nucleus
\tl_if_novalue:nF { #4 } { \sb{#4} } % the postsubscript
}
{% there is either a presuperscript or a postsuperscript
\vphantom{#3} % the nucleus for the prescripts
\sp{\tl_if_novalue:nF { #2 } { #2 } }
\tl_if_novalue:nF { #1 } { \sb{#1} } % the presubscript
#3 % the nucleus
\sp{\tl_if_novalue:nF { #5 } { #5 } }
\tl_if_novalue:nF { #4 } { \sb{#4} } % the postsubscript
}
}
\ExplSyntaxOff

\begin{document}

$\xprescript_n{X}_m + \xprescript_n^2{X}_m + \xprescript_n{X}_m^2$

\end{document}