# How to define your own shorter command in place of the default longer command?

I would like to not type $\mathbf{\hat{x}}$ every time I want a bold x with a hat over it. I've used \def successfully for other things, but with this I am not sure how to properly use \def or \newcommand in order for me to just type \bhat{x} and have it bold the input letter (whatever that may be - could be an x, y, z, etc.).

I've tried this, but it does not work:

\newcommand{\mathbf{\hat{}}}[1][1]{\bhat} % or...
\def\bhat{{\mbox{$\hat \mathbf{}$}}}


Hope this is what you want:

\documentclass{article}
\newcommand\bhat[1]{\ensuremath{\hat{\mathbf{#1}}}}
\begin{document}
some text $\bhat{x}$ or \bhat{y}
\end{document}


Output:

• Why not using \ensuremath if the new command is used in a mathematical environment $...\bhat{x}...$ ? I would suggest \newcommand{\bhat}[1]{\ensuremath{\hat{\mathbf{#1}}}}, then you do not need to put the \bhat command between dollars. Oct 28 '16 at 5:28
• Oct 28 '16 at 5:33
• @JérômeDequeker: Edited to add \ensuremath Oct 28 '16 at 5:35
• @Werner: Thanks for the link. I think in this kind of usage, the argument in the \bhat command is only a letter, but thank you to notice we should not put dollars in the arguments. Oct 28 '16 at 5:52
• Has the hat to be bold too ? If Yes, @AmbikaVanchinathan knows what to edit in the answer. Oct 28 '16 at 5:54

\def \hope#1{\bf{\hat{#1}}} \begin{document} This is $\hope{V}$ \end{document}% this works for me. You can use any term inside curly bracket where V is added. It gives proper result.

• The command \bf has been deprecated more than 20 years ago. And no, this doesn't give proper results, because $\hope{V}W$ will make bold also the W. Oct 28 '16 at 6:53