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:
How to explain why the part of code marked as
works only if…below works?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}

\mathxxcommands do not combine in the way text font commands do. Even withoutbm\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 07:04\mathALPHcommands has anything to do with\bm— which is combinable with\mathALPHprovided it is combined in the opposite order. – Ilya Zakharevich Aug 31 '18 at 08:46\bm{g}is designed to work likegexcept 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 08:50\bm{\mathfrak{g}}is designed to work like\mathfrak{g}except using a bold fraktur. – David Carlisle Aug 31 '18 at 08:54\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). – Sep 30 '18 at 09:32