4

I defined the following command

\NewDocumentCommand{\fam}{O{\mathbb{N}}mm}{\left\{ #2_#3 \right\}_{#3 \in #1}}     % Family notation (set with indices)

but I get the compile error Command '\fam' already defined. I thought I used some package that defined \fam, but I was wrong because the same error appears in a .tex file with no loaded packages. So what is \fam? (I didn't find anything online so far and the output of latexdef fam is meaningless to me). I'll rename my command to \family anyway.

Here is an example snippet:

\documentclass{article}
\newcommand{\fam}{whatever}
\begin{document}
\[\fam\]
\end{document}

As you can see the command \fam is not defined by any package (because I get the same error) and I can't figure out what it does

4

4 Answers 4

14

As mentioned in another answers, \fam is TeX primitive control sequence, it represents an integer register which is used by build-in TeX algorithms.

I add another point of view on it: In old days (when TeX begins) there were only fonts with no more than 128 characters per font. But math typesetting needs a palette of much more characters when you are creating math formulas (math alphabets Latin, Greek, calligraphic, ..., math symbols). So, D. Knuth took into consideration all such common math characters and divided them into more 128 subsets. Each 128 subset become single font (more precisely three very similar fonts: in given size, in script size and in scriptscripsize; this is a reason why it is called \fam, it represents a "family" of such three fonts). When TeX creates the math formula, then it must switch between these 128-chars fonts and it do this using setting of \fam register to different values.

Nowadays, we have Unicode fonts and Unicode math. All characters needed for creating the math formula are accessible from single font (all math alphabets, all symbols, moreover in all three sub-variants of sizes: given size, script size and sriptscriptsize). All material for creating math formulas is in single font today. We need not to switch between more fonts when we create math formulas. But \fam primitive is still here and it is still usable: You can load more Unicode math fonts with different \fam register and you can switch between these Unicode math fonts if you want to use a special symbol from another Unicode math font than the default one (for example for aesthetic reason or if a symbol is missing in default math font). Moreover, you can combine Unicode math fonts with old 128-chars fonts using \fam switching.

3
  • I liked all the answers, but this one is very fascinating because of the history behind \fam (I would have never thought it was that important!) and its link with the word "family", I thought the similarity was just a coincidence
    – Fral
    Oct 30, 2022 at 22:03
  • @Fral note though wipet isn't a latex user. in a latex context this is only "history" if you use unicode-math. \fam is still the primary math font mechanism, even with lualatex and xelatex by default Oct 31, 2022 at 8:01
  • 1
    I hope that also the LaTeX users are using Unicode math today. Of course, old LaTeX documents are based on old math fonts mechanism, but technology support of Unicode math in TeX is here over ten years. New users have no reason to run old non-Unicode TeX.
    – wipet
    Oct 31, 2022 at 10:41
10

\fam is a TeX primitive, and a very important one. TeXnically, it's an internal integer register.

When you type something like \mathrm{A}, TeX will unravel \mathrm which involves opening a group and choosing a four-bit integer (in this case 0, but other similar commands would choose a different one) that's been connected to \mathrm (the details are unimportant). Inside this group \fam is set to this integer.

Since the mathcode of A is, in hexadecimal, "7141: the last two digits represent the font slot to get the glyph from; the second digit tells TeX that the math symbol is an ordinary one; the first one tells TeX that the current value of \fam has to be used to choose the math font, when the value is nonnegative.

In LaTeX, \fam is aliased to \mathgroup, so, in theory, you might freely redefine \fam, but some packages might use \fam and the effects would be a disaster.

9

\fam is a TeX primitive, it can be set to a number between 0 and 15 (255 in luatex) which controls the math font used by letters. It is the foundation of \mathrm, \mathbf etc in LaTeX.

2

Addendum to the accepted answer: The output of latexdef in this case is

\fam:
\fam

and this is core TeX's cryptic way of identifying primitive commands, already defined by the interpreter on startup (even before the format is loaded). Compare:

$ latexdef hbox
\hbox:
\hbox
$ latexdef def
\def:
\def

It looks slightly less weird as the output of the \show operation (which latexdef is just wrapping):

$ initex
This is TeX, Version 3.141592653 (TeX Live 2022/Debian) (INITEX)
**\show\fam
> \fam=\fam.

(INI-TeX used here to underline that \fam and its ilk are built into TeX and not part of the format.)

There's a comprehensive list of primitive commands in chapter 37 of TeX by Topic, although it doesn't include e-TeX additions.

You must log in to answer this question.

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