I have a paragraph of lots of vectors symbols, so I need to type something like:


(just an example).

It is so inconvenient to write a \mathbf command everywhere. So I want to define a command that automatically distribute a \mathbf head into every atom symbol. How can I do this?

I seached a solution that close to it; everymath and set font for math used a \mathgroup:


But I don't understand what it means and how it works. I also googled the usage and mechanism of \mathgroup, but can't get one. Could someone explain this commands to me? And how can I turn this command into a more flexible one, that allows me to disable the automatic \mathbf if I temporarily don't want it?

  • \mathgroup is a synonym for \family. You definitely don't want to do like that, anyway. Define \vv to mean \mathbf (or whatever) and use \vv{a}\cdot\vv{b}. You don't want that $2x$ has a boldface “2”, do you?
    – egreg
    Feb 19, 2017 at 17:20
  • @egreg Can I use an if-else structure to filter only alphabets? Just works whenever the object is A-Z and a-z.
    – Eric
    Feb 19, 2017 at 17:29
  • you also (almost) never want \displaystyle in \everymath Feb 19, 2017 at 17:36
  • If you are willing to accept a reference to The TeXbook, the core of the mechanism is explained on pp. 154–155; \mathgroup is the LaTeX name for the \fam primitive. Keep in mind, however, that LaTeX2e adds the complexity of dynamic font allocation.
    – GuM
    Feb 19, 2017 at 19:23

2 Answers 2


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


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.






enter image description here

As you see, you cannot distinguish between vectors and scalars; the correct formula should be typeset as


and I'm very dubious whether you really want to do it.

Define a macro for vectors, such as


and type in your formula as


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

[...all letters...]
[...all letters...]

with perhaps also the uppercase Greek, depending on your preferences. You can use \mathnormal or the other similar commands to change the shape.

  • 1
    Unfortunately, I cannot upvote again after the edit… :-)
    – GuM
    Feb 19, 2017 at 19:16
  • 1
    +1 for the sentence: This is definitely not what you want Feb 19, 2017 at 19:54

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


  % Use of e-TeX extension could also be avoided here:
  \mathcode`#1=\numexpr\mathcode`#1-"7000 \relax
  % A loop could also be used here:


This is the normal setting: \( 2v+cw=u \).

    We are now inside an \texttt{automathbf} environment: \( 2v+cw=u \).

Back to the normal setting: \( 2v+cw=u \).


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.

You must log in to answer this question.

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