4

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{}$}}}
Werner
  • 603,163
magnetar
  • 143

2 Answers2

6

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:

enter image description here

0

\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.

vaman
  • 81
  • 3
    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. – egreg Oct 28 '16 at 06:53