4

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}

1 Answer 1

4

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}

Result

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}

Example with amsmath

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .