4

I think this is a follow-up to How to capture the current math style?.

In this MWE, \bm{\testbox} works when used after \testbox. But it does not work on its own (commented line):

\documentclass{article}
\usepackage{scalerel,bm}
\newcommand{\testbox}{\ThisStyle{\mbox{$\SavedStyle X$}}}
\begin{document}
    $\testbox \bm{\testbox}$
%   $\bm{\testbox}$
\end{document}

The error is:

! Undefined control sequence.
\ThisStyle #1->\ifmmode \def \@mmode 
                                     {T}\mathchoice {\edef \m@switch {D}\LMe...
l.6     $\bm{\testbox}

What am I doing wrong?

Edit: I have found out that this works:

    $\ThisStyle{\@gobble\SavedStyle} \bm{\testbox}$

But I have no idea, why :)

1 Answer 1

3

In this well received answer, \bm package versus \boldsymbol, Philippe points out that sometimes, because of the way \bm is defined, it needs an extra set of braces about its argument. Thus,

\documentclass{article}
\usepackage{scalerel,bm}
\newcommand{\testbox}{\ThisStyle{\mbox{$\SavedStyle X$}}}
\begin{document}
    $\testbox \bm{\testbox}$
    $\scriptstyle\bm{{\testbox}}$
\end{document}

produces the desired result.

enter image description here

2
  • Hey, we've met before :) I did not dare to add this to my previous question because it just seemed to be too much of a special case. However, this applies very well to that other question. Thanks again!
    – bers
    Oct 15, 2015 at 13:04
  • Thanks! I'm real proud of my \ThisStyle macro, which can usually condense the syntax compared to the corresponding \mathchoice. Best wishes in its use. Oct 15, 2015 at 13:08

You must log in to answer this question.

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