I have two \newcommand defined as follows:
\newcommand{\hvar}[1]{\hat{\delta #1}}
\newcommand{\gbp}{{{\bar{\gamma}}_p}}
And they look like this:
\hvar{X} 
\gbp 
The problem is that, if I use them together I get this:
\hvar{\gbp} 
It seems like the \gamma was shifted to the right.
Is this a bug? Is there a way to fix it?
Here is a MWE:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\hvar}[1]{\hat{\delta #1}}
\newcommand{\gbp}{{{\bar{\gamma}}_p}}
\begin{document}
\begin{equation}
\hvar{X} \qquad \gbp \qquad \hvar{\gbp}
\end{equation}
\end{document}
EDIT:
As egreg mentioned, this is a bug on the accent implementation of amsmath. A work around is provided here: Why do arguments to nested \tilde or \breve commands reappear when amsmath is used? and a MWE presented below:
\documentclass{article}
\usepackage{amsmath}
\newsavebox{\accentbox}
\newcommand{\compacc}[2]{\sbox\accentbox{$#2$}#1{\usebox\accentbox}}
\newcommand{\compaccX}[2]{\let\accenttemp#1\mathpalette\docompacc{#2}}
\def\docompacc#1#2{\compacc\accenttemp{#1#2}}
\newcommand{\hvar}[1]{\compaccX{\hat}{\delta #1}}
\newcommand{\gbp}{{{\bar{\gamma}}_p}}
\begin{document}
\begin{equation}
\hvar{X} \qquad \gbp \qquad \hvar{\gbp} \qquad A_{\hvar{\gbp}}
\end{equation}
\end{document}
Looks like:


\hatwith\widehatseems to work, if that's an acceptable solution. – You Sep 09 '13 at 18:05\hatand\barare accents. Combining multiple accents onto one character is one of the "scary" parts of TeX. – kahen Sep 09 '13 at 18:24\dot{\gbp}in a subscript, which has the same problem. – Miguel Sep 09 '13 at 18:53amsmath.:-(Some macros that are set globally disrupt the working of the inner accent. This can be seen by trying\hvar{\text{$\gbp$}}which produces the dreaded undefined control sequence error about\macc@kerna. See also http://tex.stackexchange.com/questions/30327/why-do-arguments-to-nested-tilde-or-breve-commands-reappear-when-amsmath-is-us – egreg Sep 09 '13 at 19:48