2

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}
2
  • 1
    \def~#1{\bm{#1}}
    – egreg
    Commented Aug 18, 2016 at 19:24
  • Add an answer and I'll $\checkmark$ it.
    – JPi
    Commented Aug 18, 2016 at 19:27

1 Answer 1

5

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$

\end{document}

enter image description here

2
  • 1
    Enter image description here...?
    – daleif
    Commented Aug 18, 2016 at 19:33
  • 5
    @daleif egreg is new here, he hasn't quite mastered the site format. Commented Aug 18, 2016 at 19:41

You must log in to answer this question.

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