The key was to set your redefinition of \vec
in its own group (as denoted with the extra set of braces).
\documentclass{article}
\usepackage{bm}
\renewcommand{\vec}[1]{{\boldsymbol{#1}}}
\newcommand{\gyrobias}{\vec{b}_{g}}
\newcommand{\est}[1]{\hat#1}
\begin{document}
$\est{\gyrobias}$
\end{document}
If this approach does bad things to \vec
in some other way, one could always apply the extra group to the definition of \gyrobias
, instead:
\documentclass{article}
\usepackage{bm}
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\newcommand{\gyrobias}{{\vec{b}}_{g}}
\newcommand{\est}[1]{\hat#1}
\begin{document}
$\est{\gyrobias}$
\end{document}
FOLLOW UP
With this follow up, I address the issue of getting a \hat
or \dot
over the intended letter, using the syntax of the OP. However, it does not address the issue of multiple diacritics over the same letter, as in \dot{\est{\camrot}}
.
\documentclass{article}
\usepackage{bm}
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\newcommand{\gyrobias}{{\vec{b}}_{g}}
\newcommand{\rquat}[2]{{\overline{q}}^{#1}_{#2}}
\newcommand{\camrot}{\rquat{O}{C}}
\newcommand{\pos}[5][]{{_{#5}}#1{\vec{#2}}_{#3 #4}}
\newcommand{\trans}[4][]{\pos[#1]{t}{#2}{#3}{#4}} %\trans{from}{to}{in}
\newcommand{\campos}[1][]{\trans[#1]{O}{C}{O}}
\newcommand{\est}[1]{\applydiacritic{\hat}{#1}}
\newcommand{\Dot}[1]{\applydiacritic{\dot}{#1}}
\newcommand\applydiacritic[2]{\ifx\campos#2\campos[#1]\else\expandafter#1#2\fi}
\begin{document}
$\est{\gyrobias}$\medskip
$\camrot\quad\est{\camrot}\quad\Dot{\camrot}$\medskip
$\campos\quad\est{\campos}\quad\Dot{\campos}$\medskip
\end{document}
The OP points out that the above code does not work with amsmath
. Here is a fix for that, though I note that amsmath
package affects the placement of diacritical marks over the letter "t", and I have verified that it is not related to my solution here, which can be seen in the first line of my output (when amsmath
is inserted/removed).
\documentclass{article}
\usepackage{bm}
\usepackage{amsmath}% THIS PACKAGE EFFECTS PLACEMENT OF DIACRITICS OVER \boldsymbol{t}
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\newcommand{\gyrobias}[1][]{#1{\vec{b}}_{g}}
\newcommand{\rquat}[3][]{#1{\overline{q}}^{#2}_{#3}}
\newcommand{\camrot}[1][]{\rquat[#1]{O}{C}}
\newcommand{\pos}[5][]{{_{#5}}#1{\vec{#2}}_{#3 #4}}
\newcommand{\trans}[4][]{\pos[#1]{t}{#2}{#3}{#4}} %\trans{from}{to}{in}
\newcommand{\campos}[1][]{\trans[#1]{O}{C}{O}}
\newcommand{\est}[1]{\applydiacritic{\hat}{#1}}
\newcommand{\mydot}[1]{\applydiacritic{\dot}{#1}}
\newcommand\applydiacritic[2]{%
\ifx\gyrobias#2\gyrobias[#1]\else
\ifx\campos#2\campos[#1]\else
\ifx\camrot#2\camrot[#1]\else
#1#2\fi\fi\fi}
\begin{document}
$\boldsymbol{t}\quad\hat{\boldsymbol t}\quad\dot{\boldsymbol t}$\medskip
$\gyrobias\quad\est{\gyrobias}\quad\mydot{\gyrobias}$\medskip
$\camrot\quad\est{\camrot}\quad\mydot{\camrot}$\medskip
$\campos\quad\est{\campos}\quad\mydot{\campos}$\medskip
\end{document}
If you need the symbol _
you can use, e.g., \_
or an \underline
with a proper white space argument:
\documentclass{article}
\begin{document}
$n\_$ vs. $n\underline{\enskip}$
\end{document}
Best Answer
I can't explain why the problem arises in the first place, but one solution is to box the initial item, and apply the
\hat
at the end. I also provide a 2nd alternative where I apply the\hat
only to the\sigma
; that may be preferable.If one wanted the first approach, but with a really wide hat, my answer at Really wide hat symbol might be applicable: