[Tex/LaTex] too many math alphabets used in version bold (can’t find a solution)

amsmathboldmath-mode

I know this is a common problem, but I searched for a solution and can't find one.
I tried to play with bmmax/hmmax but it does not help.
Below is the minimum part of the code to reproduce the problem.
I would be grateful for any advice/help.

\documentclass[12pt]{article}
\newcommand{\bmmax}{2}
\newcommand{\hmmax}{0}

\usepackage{array,float,epsf,latexsym,psfrag,amssymb,eurosym,theorem,amsmath,verbatim}

\usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{bbm}
\usepackage{mathrsfs}

\usepackage[dvips]{color}
\usepackage[ansinew]{inputenc}
\usepackage{srcltx}

\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}

\def\bsf  #1{           \mbox{\boldmath $\sf #1$}}
\def\bsfh #1{\widehat  {\mbox{\boldmath $\sf #1$}}}

\begin{document}

\begin{equation}
\bsf x ~ \bsfh x
\end{equation}

\end{document}

P.S. I have a 70-pages document which compiles fine but as soon as I delete some first 40 pages with formulas I encounter that error. That's something I can't explain to myself.

Best Answer

That definition of \bsf and \bsfh produces many more errors, not only the "Too many math alphabets" one.

Actually the error is caused by your definition of \bsfh, that causes a loop which is stopped by the "Too many math alphabets" error and at the end prints the required symbol correctly (but doing so it exhausts the number of math families in the \boldmath version).

A more sensible definition for \bsf and \bsfh can be

\DeclareMathAlphabet{\bsf}{OT1}{cmss}{bx}{n}
\newcommand{\bsfh}[1]{\widehat{\bsf{#1}}}

that shouldn't cause the problem with math alphabets (I checked and only 9 out of 16 are used). In this way \bsf{x} will give correct results also in subscripts and superscripts. Shouldn't you need them in such positions, a simpler definition can be used:

\newcommand{\bsf}[1]{\mbox{\normalfont\sffamily\bfseries #1}}
\newcommand{\bsfh}[1]{\widehat{\bsf{#1}}}

Don't load latexsym, which is obsolete (so doing you'll reduce the math alphabet usage); the symbols it provides are available through amssymb.