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 :)

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

  • 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 '15 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. – Steven B. Segletes Oct 15 '15 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.