# Subscript vertical position dependent on presence of superscript - how to change? [duplicate]

Possible Duplicate:
Subscripts for primed variables

If I have a variable which is always subscripted but only sometimes superscripted, the vertical position of the subscript varies. For instance, $s^*_i$ and $s^{}_i$ are different from $s_i$. Can I define the subscript such that it is always in the same position regardless of the presence of a superscript?

-

## marked as duplicate by Werner, egreg, yo', Loop Space, lockstepApr 13 '12 at 18:47

\usepackage{subdepth}


Example

\documentclass{article}
\usepackage{subdepth}
\begin{document}
$a_i a_i^2$
\end{document}


-

I would define a macro to handle this in a consistent way. The following minimal example defines \var[<var>]{<sub>}[<sup>] that sets <var>_{<sub>}^{<sup>} (<var> and <sup> are optional). The addition of an empty <sup> ensures a consistent height for your superscripts. If your optional <sup> is something other than a "normal superscript" (let's call it "bizarre"), adding \vphantom{<bizarre sup>} before #3 should take care of the vertical alignment:

\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\var}{O{s} m O{}}{%
}
\begin{document}
$s_i\ s_i^*$\ \var{i}\ \var{i}[*]\ \var[a]{k}\ \var[a]{k}[*]
\end{document}​


<var> has a default of s. If <sup> contains other (more complex) elements, you could use \mathstrut. That is, with some knowledge of the input, you can optimise the output.

It would also be possible to modify the macro to allow you to use superscript notation ^{..} as needed, rather than an optional <sup> argument, but this enforce the use of math mode, rather than using \ensuremath.

xparse provides the macro definition interface.

-
Actually ^{} is sufficient (no need of \vphantom). And here \ensuremath is very questionable. –  egreg Apr 12 '12 at 17:17
@egreg: I've incorporated your first suggestion. :) –  Werner Apr 12 '12 at 17:25
Thanks -- elegant but I will keep this in mind as an example of xparse... –  crippledlambda Apr 12 '12 at 18:29