# How to make @ turn math symbols bold

I would like to change the meaning of @ in math mode to be such that it takes the object following it and makes it bold, e.g. $@x$ should produce a bold math x, $@\alpha$ should produce a bold alpha, and $@{\hat x^2}$ should make everything inside the curlies bold.

The following code doesn't work; I'm out of my depth.

\documentclass{article}

\usepackage{amsmath}
\usepackage{bm}

\begingroup
\lccode\~=@
\lowercase{\endgroup
\def~#1~{\boldsymbol{#1}}%
}%
\mathcode@="8000

\begin{document}
$@x$   % I want this to produce a boldface math x
\end{document}

• \def~#1{\bm{#1}} – egreg Aug 18 '16 at 19:24
• Add an answer and I'll $\checkmark$ it. – JPi Aug 18 '16 at 19:27

The syntax you're defining is $@x@. If you just want @, it should be \begingroup\lccode\~=@ \lowercase{\endgroup\def~#1}{\bm{#1}} \mathcode@="8000  Complete example \documentclass{article} \usepackage{amsmath} \usepackage{bm} \begingroup\lccode\~=@ \lowercase{\endgroup\def~#1}{\bm{#1}} \mathcode@="8000 \begin{document}$x+@x\$
`