# Define commands for symbols with index, combine with accents

To facilitate writing of formulas that contain symbols with subscript, I often define custom commands. However, combining these with accents gives unpleasant results. Is there any way to define such abbreviations and to still obtain the 'right' placement of accents? For example,

\documentclass{article}

\newcommand{\ang}{\varphi_\mathrm{example}}
\begin{document}
$\ang$ is ok, but $\dot{\ang}$ is not. I'd rather obtain $\dot{\varphi}_\mathrm{example}$ without spelling it out. How?
\end{document}

-

Math accents work on the next math atom. \dot does not take an argument, the curly braces are generating a sub formula and the dot is placed above the sub formula. Without curly braces \ang is expanded and the dot is placed on \varphi.

\documentclass{article}

\newcommand{\ang}{\varphi_\mathrm{example}}

\begin{document}
\begin{tabular}{ll}
\verb|$\dot{\ang}$| & $\dot{\ang}$ \\
\verb|$\dot\ang$| & $\dot\ang$ \\
\end{tabular}
\end{document}


Update:

In case of package amsmath \dot and some other accents are redefined and catch its base character as argument. Then the above example will not work. This problem can be solved by using \expandafter. \ang is expanded once. Then \dot sees the first token (or token group) of the definition text of \ang, that is \varphi:

\documentclass{article}

\usepackage{amsmath}

\newcommand{\ang}{\varphi_\mathrm{example}}

\begin{document}
\begin{tabular}{ll}
\verb|$\dot{\ang}$| & $\dot{\ang}$ \\
\verb|$\expandafter\dot\ang$| & $\expandafter\dot\ang$ \\
\end{tabular}
\end{document}


-
This, unfortunately, doesn't work when amsmath is loaded. –  egreg Sep 10 '12 at 12:49
Thanks for the explanation. With an additional \def\Dot{\expandafter\dot} I probably have all I need. –  Alex Sep 10 '12 at 14:37