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{}$}}}

2 Answers 2

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

8
  • 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. Commented Oct 28, 2016 at 5:28
  • 1
    Relevant: When not to use \ensuremath for math macro?
    – Werner
    Commented Oct 28, 2016 at 5:33
  • @JérômeDequeker: Edited to add \ensuremath Commented Oct 28, 2016 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. Commented Oct 28, 2016 at 5:52
  • Has the hat to be bold too ? If Yes, @AmbikaVanchinathan knows what to edit in the answer. Commented Oct 28, 2016 at 5:54
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.

1
  • 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
    Commented Oct 28, 2016 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .