Define a rule for all bold math letters

I have been using

\def\H{\bm{H}}


to define bold letters in math mode. Is there a way I can define a general rule for any letters? Like I want a rule that allow

\*anyletters*{\bm{*anyletter}*
% For example \I -> \bm{I} etc....

• just letters or do you want the whole expression bold, in which case \boldmath $x+y$ Feb 6 '16 at 23:16

The following code defines \bmA to be \bm{A} for A running over all letters in the alphabet. Please do not use single letter macros, as these tend to have special meaning (accents, special symbols).

\documentclass{article}
\usepackage{bm}
\makeatletter
\newcounter{letter}
\setcounter{letter}{1}
\@whilenum\value{letter}<27\do{% loop over all letters in the alphabet
% \def\bmA{\bm{A}}, where A runs over all letters
%   Remove letters bm'  vv  if you don't care about breaking LaTeX
\expandafter\edef\csname bm\Alph{letter}\endcsname{\noexpand\bm{\Alph{letter}}}
\expandafter\edef\csname bm\alph{letter}\endcsname{\noexpand\bm{\alph{letter}}}
\stepcounter{letter}%
}
\makeatother
\begin{document}
Hungarian umlaut \H{o}

Polish suppressed-L \L

Scandinavian O-with-slash \O

pilcrow \P

section symbol \S

$\bmA \bmZ \bma \bmz$
\end{document}


• returning after about a year - how do you make the same rule for lower case as well? Jan 23 '17 at 23:13
• @QuangThinhHa Just add another line in the loop, substituting \Alph by \alph` for lowercase letters. See updated answer. Jan 24 '17 at 10:01