What does \mathgroup mean? How to use it?
TeX allows one to say
$a+{\fam4 x}$
which will print a
in the default math italic and x
in the font assigned to math family 4. In plain TeX such assignments are static and family 4 is assigned the text italic font.
In LaTeX the assignments are dynamic, depending on the document and the math font package loaded. So one doesn't know in advance what family is assigned the boldface font; the assignment is made once and for all when the first \mathbf
command is performed. This is in common with all macros defined with \DeclareMathAlphabet
.
LaTeX also calls \family
in a different way, namely \mathgroup
; they are synonyms.
You could do
\AtBeginDocument{%
\sbox0{$\mathbf{\xdef\mathbfgroup{\the\mathgroup}}$}%
}
and the macro \mathbfgroup
will hold the math group (family) number corresponding to \mathbf
.
However, doing also \everymath{\mathgroup\mathbfgroup}
will make all letters in math to appear boldface, together with numbers. This is definitely not what you want, I believe.
Example code.
\documentclass{article}
\AtBeginDocument{%
\sbox0{$\mathbf{\xdef\mathbfgroup{\the\mathgroup}}$}%
\everymath{\mathgroup\mathbfgroup\relax}%
}
\begin{document}
$2v+cw=u$
\end{document}
As you see, you cannot distinguish between vectors and scalars; the correct formula should be typeset as
$\mathrm{2}v+\mathnormal{c}w=u$
and I'm very dubious whether you really want to do it.
Define a macro for vectors, such as
\newcommand{\vv}[1]{\mathbf{#1}}
and type in your formula as
$2\vv{v}+c\vv{w}=\vv{u}$
The input is clearer and you can redefine \vv
at will, in case you decide that, after all, vectors should be boldface italic.
If you really want all letters in math to be boldface by default, the strategy is
\DeclareSymbolFont{boldfaceletters}{OT1}{cmr}{bx}{n}
\DeclareSymbolFontAlphabet{\mathbf}{boldfaceletters}
\DeclareMathSymbol{a}{\mathalpha}{boldfaceletters}{`a}
[...all letters...]
\DeclareMathSymbol{z}{\mathalpha}{boldfaceletters}{`z}
\DeclareMathSymbol{A}{\mathalpha}{boldfaceletters}{`A}
[...all letters...]
\DeclareMathSymbol{Z}{\mathalpha}{boldfaceletters}{`Z}
with perhaps also the uppercase Greek, depending on your preferences. You can use \mathnormal
or the other similar commands to change the shape.
@egreg’s answer has already given the best possible advice concerning this problem; anyway, it might be worthwhile to remark that one can shield the digits from being boldfaced when \fam
/\mathgroup
is set to the value used by \mathbf
simply by moving them from class 7 (\mathalpha
, which is where the LaTeX kernel puts them) to class 0 (\mathord
). For example:
\documentclass{article}
\newcommand*{\DeactivateMathAlpha}[1]{%
% Use of e-TeX extension could also be avoided here:
\mathcode`#1=\numexpr\mathcode`#1-"7000 \relax
}
\newenvironment*{automathbf}{%
% A loop could also be used here:
\DeactivateMathAlpha{0}%
\DeactivateMathAlpha{1}%
\DeactivateMathAlpha{2}%
\DeactivateMathAlpha{3}%
\DeactivateMathAlpha{4}%
\DeactivateMathAlpha{5}%
\DeactivateMathAlpha{6}%
\DeactivateMathAlpha{7}%
\DeactivateMathAlpha{8}%
\DeactivateMathAlpha{9}%
\everymath{\mathgroup\mathbfgroup\relax}%
}{}
\AtBeginDocument{%
\sbox0{$\mathbf{\xdef\mathbfgroup{\the\mathgroup}}$}%
}
\begin{document}
This is the normal setting: \( 2v+cw=u \).
\begin{automathbf}
We are now inside an \texttt{automathbf} environment: \( 2v+cw=u \).
\end{automathbf}
Back to the normal setting: \( 2v+cw=u \).
\end{document}
Of course, one still has the problem of letters intended to denote scalars; however, it seems to me that the above code does literally what the question asked for.