[Tex/LaTex] Using \mathtt{A} and the Package \usepackage{MnSymbol}

errorsmath-modemath-operators

How can you use the symbol \mathtt{A} and the Package \usepackage{MnSymbol}?

My code begin with

\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[a4paper]{book}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}
\usepackage{amssymb}
\usepackage{amsmath,amscd}
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{tikz}
\usepackage{tensor}
\usepackage{graphicx}
\usepackage{MnSymbol}
\usepackage{stmaryrd}
\usepackage{shuffle}
\usepackage{comment}
\usepackage[frenchb]{babel}
\usepackage{etex}
\usepackage[all]{xy}

\usepackage{float}
\usepackage{blkarray}
\usepackage{lipsum}
%\usepackage{mathtools}
%\usepackage{mathabx}
\usepackage[dvipsnames]{xcolor}
\usepackage{tkz-graph}

\usetikzlibrary{arrows}
\usepackage[french,linesnumbered,algoruled]{algorithm2e}
\usepackage{algorithmic}
\usepackage{pst-node,pstricks,multido,pst-plot,pst-text,pst-3d}%
\usetikzlibrary{arrows}

I get these warnings and errors

! 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.656 \mathtt B
_{n,k}(P_1,\dots,P_m,\dots)=\mathfrak B_{n,k}[\a^{( P)}_{\Ph...
Your command was ignored.

Best Answer

I can reproduce the issue with

\documentclass[a4paper]{book}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}
\usepackage{MnSymbol}
\usepackage{stmaryrd}
\usepackage{shuffle}

\begin{document}
$\mathbf{A}\mathit{A}\mathsf{A}\mathbb{A}\mathtt{A}$
\end{document}

where only the math font related packages have been kept.

One has to know that each \DeclareSymbolFont declaration uses up one of the available 16 math groups. The default setup allocates groups from 0 to 3, then amssymb allocates other two; four are used by MnSymbol, one by stmaryrd and one by shuffle. A total of twelve, so only three additional math alphabets can be used in the document.

Some \mathX command don't really use a new math alphabet, which is the case for \mathbb (it shares a math group with those defined by amssymb) but not of \mathfrak nor \mathbf and others. Math alphabets (loaded with \DeclareMathAlphabet) only allocate a math group at point of usage, so in the code above the first four instructions exhaust the available groups and \mathtt is not able to find a place for allocating a group.

You can avoid wasting math groups with various techniques. For instance, the shuffle package can be avoided by defining the symbols it provides in a different way:

\documentclass[a4paper]{book}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}
\usepackage{MnSymbol}
\usepackage{stmaryrd}
%\usepackage{shuffle}

\DeclareRobustCommand{\shuffle}{%
  \mathbin{\text{\usefont{U}{shuffle}{m}{n}\symbol{"001}}}%
}
\DeclareRobustCommand{\cshuffle}{%
  \mathbin{\text{\usefont{U}{shuffle}{m}{n}\symbol{"002}}}%
}


\begin{document}
$x\shuffle y\cshuffle z_{x\shuffle y\cshuffle z}$

$\mathbf{A}\mathit{A}\mathsf{A}\mathfrak{A}\mathtt{A}$
\end{document}

and now \mathtt can be used. This doesn't guarantee that math groups will not be used up again. For the most rarely used commands of the set, you can define (slower) substitutes; for instance, here's the preamble code for not allocating a math group with \mathtt:

\AtBeginDocument{%
  \DeclareRobustCommand{\mathtt}[1]{%
    \text{\normalfont\ttfamily #1}%
  }%
}
Related Question