# Fixing interaction of bm and NFSS

I’m trying to get math boldified in less fragile way that what bm would do. (Compare with the last paragraphs in this answer.)

However, after hours of reading sources of NFSS (not for the first time! Maybe even not the 10th!) every time it looks like my understanding is not enough to predict what would work (with “math versions”), and what wouldn’t. In particular, the minimal example below seems to work, but I cannot explain why — so I do not know whether it would continue to work in more complicated situations.

Questions:

1. How to explain why the part of code marked as works only if… below works?

2. Is there a more robust way to extract which “Math alphabet” (like \mathfrak) is currently active?

Thanks!

\documentclass{amsart}
\usepackage{bm}

\makeatletter
\def\grabCurFam#1#2{%   A replacement for \install@mathalphabet \mathbf {DEF} DEF=\select@group 4args OR ...\use@mathgroup \M@U {10}
\grabCurFamA {#1}#2\use@mathgroup{}{-10}\@nil       % -10 is not a valid
}
\def\grabCurFamA #1#2\use@mathgroup#3#4#5\@nil{%
\ifnum #4>-10 %
\ifnum \the\fam = #4 \gdef\grabbedAlphabet{#1}%       \show #1%
\fi
\fi
}
\def\grabMathAlphabet{%
\begingroup           % does not create an empty math atom???
\xdef\grabbedAlphabet{\noexpand\fam\the\fam       % works only if family number is the same in normal/bold math versions,
% and the font is already preloaded.  However, in simplest examples these
% conditions actually seam to hold.
\noexpand\PackageWarning{--inline--}{Could not grab the current math alphabet for math version=\the\fam}}%
\let\install@mathalphabet\grabCurFam
\let\getanddefine@fonts\@gobbletwo
\csname mv@\math@version\endcsname
\PackageWarning{--inline--}{got: \meaning\grabbedAlphabet}%
\endgroup
}
\makeatother

\bmdefine\BgSimple{g}
\bmdefine\BgHairy{{\grabbedAlphabet{g_{\text{\the\fam}}}}}  % Infinite loop without enclosing braces!!! ???
\def\gBM{\ifnum\the\fam<0 \expandafter\BgSimple\else{}_{\text{\the\fam}}\grabMathAlphabet\expandafter\BgHairy\fi}

\begin{document}
%\tracingall

% To debug: preloading frak breaks the match of the family numbers between normal/bold math versions.
$\vphantom{\mathfrak{g}} 1 g \gBM$

$2 \mathrm{g \gBM}$

$2' \mathsf{g \gBM}$

$2'' \mathcal{g \gBM}$

$2''' \mathfrak{g \gBM}$

\end{document}


(The subscripts are math-family numbers)

• I am not sure that you want this to work. By design \mathxx commands do not combine in the way text font commands do. Even without bm \mathit{\mathbf{g}} is not bold italic, it is just the outer math alphabet that has an effect and it is normal weight italic. Similarly I would expect (and the package documents) that \mathfrak{\bm{g}} will give a normal weight fraktur g. – David Carlisle Aug 31 '18 at 7:04
• Sorry David, but I do not see how combinability of \mathALPH commands has anything to do with \bm — which is combinable with \mathALPH provided it is combined in the opposite order. – Ilya Zakharevich Aug 31 '18 at 8:46
• \bm{g} is designed to work like g except using a bold math italic font. so it is just exactly as if you had defined \mathbfit{g} in particular \mathfrak{\bm{g}} works like \mathfrak{\mathbfit{g}} and is the same as \mathfrak{g} by design. So you could ask how to change bm but not how to fix it as it is not a bug. – David Carlisle Aug 31 '18 at 8:50
• conversely \bm{\mathfrak{g}} is designed to work like \mathfrak{g} except using a bold fraktur. – David Carlisle Aug 31 '18 at 8:54
• @DavidCarlisle you have a typo in your comment: \mathit{\mathbf{g}} does not give "normal weight italic" but it gives "bold weight upright" (i.e.only the inner math alphabet counts in the end in the case of nesting). – user4686 Sep 30 '18 at 9:32

In general, the approach you want is to load separate bold alphabets such as \mathbfcal for bold calligraphic and \mathbfit for bold italic. The names vary slightly from package to package, so check the documentation.
If you are able to use either LuaLaTeX or XeLaTeX, I recommend writing new documents with unicode-math.
If you need or prefer to use PDFLaTeX, and need all those alphabets, a good solution is to load both isomath (for bold and sans-serif math alphabets that include Greek) and mathalfa (for script, calligraphic, Fraktur and double-struck). Both make a comprehensive set of NFSS fonts available.
An alternative is mathastext, which also enables you to use any legacy text font plus any LGR-encoded Greek font for math letters.