I often use shortcuts defined via \newcommand. However sometimes it causes a "double subscript" problem if a shortcut contains a subscript and I try to add one more subscript when using it.
I am aware of all kinds of workarounds, as illustrated in the example below. But what is the most robust way to define such shortcuts?
Example of the code:
\documentclass{article}
% define some shortcuts
\newcommand\xa{x_a}
\newcommand\xb{{x_b}}
\def\cmpto{\quad\textrm{compare to}\quad}
\begin{document}
% this produces a "double subscript" error
%\[ \xa_i \]
This is a workaround, which produces a good result
\[ \xa{}_i \cmpto x_{ai} \]
But still not ideal: watch the position of the superscript
\[ \xa{}_i^2 \cmpto x_{ai}^2 \]
The \verb+{x_b}+ below produces no error, but does not look good
(watch the baseline of the subscripts)
%
\[ \xb_i \cmpto x_{bi} \]
Also superscript does not look good
%
\[ \xb^2 \cmpto x_b^2 \]
\end{document}

\newcommand#1{\ensuremath#2\sc@sub{#3}}– amorua Nov 01 '11 at 19:46\ensuremath. :) Seriously: you gain nothing from it, in these cases. – egreg Nov 01 '11 at 20:20\xainstead of\(\xa\)saves my time and improves readability. – amorua Nov 01 '11 at 20:38