# Using \mathtt{A} and the Package \usepackage{MnSymbol}

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{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...

• Do you really need MnSymbol? It produces symbols with shapes clashing with Latin Modern fonts. And it's hungry with respect to math alphabets, as you discovered. – egreg Oct 16 '15 at 8:37
• A workaround is to use \textnormal{\texttt{B}} instead of \mathtt[B}. Note that you allocate a math group (there are only 16 of them) for stmaryrd and shuffle. – egreg Oct 16 '15 at 8:44
• Weird, I compiled using this preamble with no problem. – Francis Oct 16 '15 at 8:46
• Unrelated to the problem, but there's no need to load amsmath or amssymb twice. – Ian Thompson Oct 16 '15 at 8:57

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}%
}%
}


It looks like you've got some redundant packages in there which are using up math family slots (of which there are only 16 total). (Note that amsart also loads the amsfonts package which uses up several more for \mathfrak, \mathbb, etc.).

I am not sure you really need the MnSymbol package. If I am not wrong it is enough to have the amssymb package.

I found an example on the internet:

\documentclass[11pt]{amsart}
\usepackage{amsmath, amssymb, amscd, MnSymbol,mathrsfs}
\DeclareMathAlphabet{\mathbbm}{U}{bbm}{m}{n}% from bbm.sty
\begin{document}
$\mathbf A \mathcal A \mathfrak A \mathscr A \mathsf A \mathbb A \mathbbm a$
\end{document}


Let me know if it compiles.