# Modified soul command \hl will not accept \boldsymbol

In Cool Text Highlighting in LaTeX, Gumbo offered, in a comment to Caramdir's answer, \hlc, a modification of soul's \hl to allow choosing the highlighting color on the fly. \hlc accepts $2$ as argument but will not accept \boldsymbol{$2$}, complaining that Argument of \boldsymbol has an extra }. When I register the command \boldsymbol with soul, see the documentation of soul "Adding font commands" (page 15), nothing at all happens.

Here is a MWE:

\documentclass[11pt]{book}
\usepackage{xcolor}
\usepackage{bm}
\usepackage{soul}
\soulregister{\boldsymbol}{1}
\newcommand{\hlc}[2][yellow]{\sethlcolor{#1}\hl{#2}}
\begin{document}
A. \boldsymbol{$2$}

B. \hlc[yellow]{$2$}

C. \hlc[yellow]{\textbf{Two}}

%D. \hlc[yellow]{\boldsymbol{$2$}}

\end{document}

• Shouldn't it be $\boldsymbol{2}$? – egreg Jun 19 '17 at 15:47
• @egreg It sure should---and it works. Why didn't you make it an answer I could accept? – schremmer Jun 19 '17 at 15:51

I have no issue if I use the correct syntax:

\documentclass[11pt]{book}
\usepackage{xcolor}
\usepackage{bm}
\usepackage{soul}

\newcommand{\hlc}[2][yellow]{\sethlcolor{#1}\hl{#2}}

\begin{document}
A. $\boldsymbol{2}$

B. \hlc[yellow]{$2$}

C. \hlc[yellow]{\textbf{Two}}

D. \hlc[red]{$\boldsymbol{2}$}

E. \hlc{$\boldsymbol{2}$}

\end{document}