# Uniform vertical subscript alignment

I was a bit annoyed that the vertical position of subscripts depends on whether or not a superscript is present:

\documentclass{standalone}
\begin{document}
$A_{xx}^{-1}A_{xx}$ vs $A_{xx}^{-1}A_{xy}^{}$
\end{document}


This has been discussed before: Subscript vertical position dependent on presence of superscript - how to change? and Subscripts for primed variables. There appear to be 2 solutions: either add ^{} everywhere, or use the subdepth package. However the former clutters code and I was wondering whether one could just tell tex to automatically include "empty" subscripts/superscripts if not provided. I discovered however that this has a strange effect: it spaces out variables horizontally.

\documentclass{standalone}
\begin{document}
\begin{tabular}{l}
$abcdefghijklmnopqrstuvwxyz$ \\
$a^{}_{}b^{}_{}c^{}_{}d^{}_{}e^{}_{}f^{}_{}g^{}_{}h^{}_{}i^{}_{}j^{}_{}k^{}_{}l^{}_{}m^{}_{}n^{}_{}o^{}_{}p^{}_{}q^{}_{}r^{}_{}s^{}_{}t^{}_{}u^{}_{}v^{}_{}w^{}_{}x^{}_{}y^{}_{}z^{}_{}$
\end{tabular}
\end{document}


Why does TeX add these horizontal spaces, even when all these sub/superscripts are empty? And what is the recommended way in 2019 to achieve uniform subscript alignment? (To be honest it feels really weird that adding "nothing" changes the formatting of the text!)

• TeX increases the width of the box holding a sub/superscript by \scriptspace, regardless of whether the box is empty or not. Oct 30, 2019 at 10:04

The width of boxes containing sub/superscripts is increased by a dimension called \scriptspace. Both plain TeX and LaTeX set this to 0.5pt. It doesn't matter whether the box is empty or not: as soon as TeX finds (assuming standard \catcodes) _ or ^ (or anything which has been \let to them), the corresponding field is non-empty.

\documentclass{article}

\newcommand*{\bbox}[1]{%
\begingroup
\setlength{\fboxrule}{0.1pt}%
\setlength{\fboxsep}{-0.1pt}%
\fbox{\mathsurround=0pt{$#1$}}%
\endgroup
}

\begin{document}

\bbox{a}\bbox{b}\bbox{c}\bbox{d}\bbox{e}\bbox{f}\bbox{g}

\bbox{a^{}_{}}\bbox{b^{}_{}}\bbox{c^{}_{}}\bbox{d^{}_{}}\bbox{e^{}_{}}\bbox{f^{}_{}}\bbox{g^{}_{}}

\scriptspace=0pt
\bbox{a^{}_{}}\bbox{b^{}_{}}\bbox{c^{}_{}}\bbox{d^{}_{}}\bbox{e^{}_{}}\bbox{f^{}_{}}\bbox{g^{}_{}}

\end{document}