Still learning about active characters, catcodes, mathcodes, and such.
I know how to make *hello* produce bold in text mode and $x$ produce a bold $x$ in math mode. I also know how to make *{hello} produce bold in text mode and $*x$ produce a bold $x$ in math mode.
What I don't know is how to make *hello* produce bold in text mode and $*x$ produce a bold $x$ in math mode. (Note the number of asterisks.)
(I've run out of upvotes for the day, but will reward good answers tomorrow)
This I can do:
\documentclass{article} \usepackage{amsmath} \usepackage{bm} \begingroup\lccode`\~=`*\lowercase{\endgroup\def~#1~}{\ifmmode\bm{#1}\else{\bfseries #1}\fi} \mathcode`*="8000 \catcode`*=13 \begin{document} *this bold* this not $*x*$ % produces bold math % I want $*x$ to produce a bold x \end{document} This I can do, also:
\documentclass{article} \usepackage{amsmath} \usepackage{bm} \begingroup\lccode`\~=`*\lowercase{\endgroup\def~#1}{\ifmmode\bm{#1}\else{\bfseries #1}\fi} \mathcode`*="8000 \catcode`*=13 \begin{document} *{this bold} this not $*x$ % produces bold math \end{document} 

\mathcodesetting isn't doing anything (also you break other uses of*such as in tabular preambles.