[Tex/LaTex] Too many alphabets, how to avoid this error

errorspackagesterminal-output

I'm having a problem when I try to use too many different types of math symbols in LaTeX, such as in this example:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage{dsfont}
\usepackage{gensymb}
\usepackage{amssymb}
\usepackage{authblk}
\usepackage{amstext}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{upgreek}
\usepackage{textcomp}
\usepackage{bm}
\usepackage[mathscr]{euscript}
\let\euscr\mathscr \let\mathscr\relax
\usepackage[scr]{rsfso}
\usepackage{siunitx}
\usepackage[e]{esvect}
\begin{document}
$\mathbb{R}\mathscr{P}\euscr{B}\mathcal{C}\vv{x_0}$
\end{document}

When I try to compile that, the following error message appears in the terminal:

! LaTeX Error: Too many math alphabets used in version normal.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.21 $\mathbb{R}\mathscr{P}
                           \euscr{B}\mathcal{C}\vv{x_0}$
? 

What can I do to use more alphabets? I actually need all of those math symbols in my document.

Best Answer

First of all, remove latexsym and gensymb that add nothing really useful: the former is covered by amssymb and the latter’s symbols can easily be produced in a different way.

This already saves two math groups. Also loading dsfont is dubious, unless you want two different doublestroke fonts.

Probably also upgreek is inessential.

As a side note, amsfonts is automatically loaded by amssymb and amstext by amsmath.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{upgreek}
\usepackage{authblk}
\usepackage{textcomp}
\usepackage{bm}
\usepackage{siunitx}

% more calligraphic fonts
\usepackage[mathscr]{euscript}
\let\euscr\mathscr \let\mathscr\relax
\usepackage[scr]{rsfso}

\begin{document}

$\mathbb{R}\mathscr{P}\euscr{B}\mathcal{C}$

\end{document}

With this, the last allocated math group is 14. If you get into troubles later on, the only feasible alternative is to define some of the calligraphic fonts in a different way.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{upgreek}
\usepackage{authblk}
\usepackage{textcomp}
\usepackage{bm}
\usepackage{siunitx}

% more calligraphic fonts
\DeclareRobustCommand{\euscr}[1]{%
  \text{\usefont{U}{eus}{m}{n}#1}%
}
\DeclareRobustCommand{\mathscr}[1]{%
  \text{\usefont{U}{rsfso}{m}{n}#1}%
}

\begin{document}

$\mathbb{R}\mathscr{P}\euscr{B}\mathcal{C}$

\end{document}

No bold version, but I don't think you need it: it's already difficult to distinguish between \euscr{C} and \mathcal{C}.