Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
1  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.