This is a follow up to my previous question. I want listings to be able to handle valid python identifiers in listings using pdfLaTeX.

The MWE literate_mwe.tex produces the following output from the input file literate_test.txt: font testing output The commands to listings to produce these glyphs can be seen here. Notably, the third and last lines are supposed to have bold upright serif characters (latin letters and numbers resp.) but instead they only produce upright serif characters. The command to produce bold upright "g", for example, is almost exactly that given in the bm documentation (see section 3.1): \bm{{\mathrm{g}}}.

However, clearly this works for the other font families: for example, \bm{{\mathsf{0}}} works just fine in the last row to produce an upright bold sans-serif zero.

How can I diagnose what's happened to \bm? How can I avoid or fix this behavior to obtain upright bold serif math?

EDIT: changing the bolding command for just the upright serif characters to e.g. \mathbf{g} causes pdfLaTeX to choke and emit Too many math alphabets used in version normal when it hits the first monospace character. Could \bm be silently swallowing the error then?

  • 1
    It would be better to include your MWE inline, rather than link to an external site. Some questions here are still being used as references more than a decade later, so they should ideally be self-contained.
    – Davislor
    Mar 15 at 7:44
  • I’d also recommend that you use unicode-math for this unless your publisher is forcing you not to. Otherwise, you might have a look at isomath, which defines \mathbfit, \mathsfbfit, etc. as alternatives to \bm{\mathrm}, and also lets you load an OML-encoded upright version of Utopia as your \mathrm font.
    – Davislor
    Mar 15 at 7:47
  • pdftex only allows you to define 16 font families. You have posted no example code only an image but I suspect you are trying to use more. At its simplest bm doubles the use of font families making a bold version of each existing family. the bm manual documents how to control this and what it does when it runs out. Mar 15 at 8:15

Legacy LaTeX is limited to sixteen math alphabets. I would strongly, strongly recommend that you port your code to unicode-math and LuaLaTeX if you can. The OpenType successor to fourier is fourier-otf.

Even if someone is forcing you to use PDFTeX, you might want to use isomath, which defines the alphabets \mathbfit, \mathsfbfit, and so on, and also allows you to load an upright, OML-encoded Utopia math alphabet with Greek letters as \mathrm and \mathbf.

Even if you don’t do that, I’d highly recommend using standard names like \mathbf and \mathbfsfit in your source, rather than \bm{\mathrm{x}}. You can still define them as \providecommand\mathbfsfit[1]{\boldsymbol{\mathsfit{#1}}} and so on. (It is preferable to use \boldsymbol in this context instead of \bm, as it takes up fewer math alphabets and is compatible with more packages.) Note that mathalpha defines bolder versions of many other math alphabets, including calligraphic and blackboard-bold, so you should use those if you load it.

The minimal fix for your MWE is to re-declare \mathrm and \mathbf as the mdput family (Math Design Utopia, compatible with the Utopia used by fourier) in the OML encoding, which supports Greek letters. I likewise define \mathsfit to use the math alphabet from sansmathfonts, which contains Greek.

When you set your math font to an encoding that supports Greek, you can use \mathrm{\alpha}, \mathbf{\beta} or \boldsymbol{\mathrm{\gamma}}, but I also define \upalpha and the rest for backward-compatibility with upgreek. (The fourier package has its own versions, but you had been using upgreek.) In order to be able to use \DeclareMathSymbol on them, I redefine \mathrm as an alias for the new upletters symbol font, saving a few math alphabets.

\usepackage{amsmath, amsthm, amssymb}
\usepackage[bb=boondox, cal=boondox]{mathalpha}


\AtBeginDocument{% thanks fourier









Once we redefine each math alphabet to cover Latin and Greek in both bold and regular weights, the document does not run out of math alphabets. If you genuinely need so many that this is impossible, the workaround is to display the math alphabets as text, for example \newcommand\mathsfit[1]{\textnormal{\sffamily\itshape\selectfont #1}}. You can also display a symbol that doesn’t vary according to the math alphabet or version with, e.g. \newcommand\QED{\mathord{\text{\usefont{LS1}{stix}{m}{n}\symbol{"D1}}}}. This does not use up a math alphabet.

Rather than load bm and nearly-disabling it by setting \bmmax to 0, I here redefine it as \boldsymbol. (Don’t do this in your source! Use meaningful names like \vectorsym and \tensorsym.)

There are also a few other tweaks, such as mathalpha for mathalfa, removing a few packages that I made redundant, and replacing fix-cm with fontaxes when you are not using Computer Modern.

  • \boldsymbol always uses an \hbox and a nested math list so doesn't double the font families but is slower than bm and loses per-character kerning information. (that said, if you want this many families in pdftex you need to do something like that.) bm drops down to a method equivalent to boldsymbol once it gets past bmmax familiy allocations (which is why the too many falilies error was avoided as observed by the OP) Mar 15 at 8:24
  • @DavidCarlisle When I tweak the definitions here, particularly by using OML alphabets for both Latin and Greek, I don’t run out on this MWE even using \boldsymbol. That is an important consideration, though.
    – Davislor
    Mar 15 at 8:31
  • @DavidCarlisle Thanks for the correction on \bm and \boldsymbol being “equivalent.” I changed my wording.
    – Davislor
    Mar 15 at 8:32
  • note you have \newcommand\bmmax{0} so bm is all but disabled in any case here. Mar 15 at 8:32
  • Yes choosing just by hand the bold alphabets you need is the correct answer here. bm makes everything bold in particular all the symbol fonts that are not used here get allocated at both weights so you probably run out of math fam before you start on the math alphabets that are actually in this example. Mar 15 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.