# Which version of LaTeX permits more than 16 alphabets?

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

I know that there is a limit of 16 alphabets at most allowed to one article. However this message specified version normal, so are there any other version of LaTeX permitting more than 16 alphabets?

-
–  Marco Daniel Mar 1 '13 at 13:00
The normal there refered to \mathversion{normal} as opposed to \mathversion{bold} not the latex engine. As @egreg says you can use xe/lua latex but usually you can arrange not to use so many math alphabets in standard latex as well. In particular any alphabets such as \mathrm \mathit etc could usually instead be accessed as text fonts \textrm{} etc and avoid using up one of the math font slots. –  David Carlisle Mar 1 '13 at 13:20
Why do you need more than 16 math alphabets? –  Martin Schröder Mar 5 '13 at 14:47
@MartinSchröder Well, says frankly I'm writing an article in logic. Thus need abundant fonts to avoid ambiguity. Take an example, we usually use \mathfrak{A} to denote a single structure, whereas use \mathsf{A} to denote a structure class. –  Popopo Mar 6 '13 at 10:44

You can use more that 16 math groups (math alphabets, in particular) with XeLaTeX or LuaLaTeX; here's an example. One must also change the allocation mechanism, of course.

\documentclass{article}
\makeatletter
\def\new@mathgroup{\alloc@8\mathgroup\mathchardef\@cclvi}
\def\document@select@group#1#2#3#4{%
\ifx\math@bgroup\bgroup\else\relax\expandafter\@firstofone\fi
{%
\ifmmode
\ifnum\csname c@mv@\math@version\endcsname<\@cclvi
\begingroup
\escapechar\m@ne
\getanddefine@fonts{\csname c@mv@\math@version\endcsname}#3%
\globaldefs\@ne  \math@fonts
\endgroup
\expandafter\extract@alph@from@version
\csname mv@\math@version\expandafter\endcsname
\expandafter{\number\csname
c@mv@\math@version\endcsname}%
#1%
\else
\let#1\relax
\@latex@error{Too many math alphabets used
in version \math@version}%
\@eha
\fi
\else \expandafter\non@alpherr\fi
#1{#4}%
}%
}
\def\select@group#1#2#3#4{%
\ifx\math@bgroup\bgroup\else\relax\expandafter\@firstofone\fi
{%
\ifmmode
\ifnum\csname c@mv@\math@version\endcsname<\@cclvi
\begingroup
\escapechar\m@ne
\getanddefine@fonts{\csname c@mv@\math@version\endcsname}#3%
\globaldefs\@ne  \math@fonts
\endgroup
\init@restore@version
\xdef#1{\noexpand\use@mathgroup\noexpand#2%
{\number\csname c@mv@\math@version\endcsname}}%
\else
\let#1\relax
\@latex@error{Too many math alphabets used in
version \math@version}%
\@eha
\fi
\else \expandafter\non@alpherr\fi
#1{#4}%
}%
}
\makeatother
\DeclareMathAlphabet{\mA}{OT1}{pcr}{m}{n}
\DeclareMathAlphabet{\mB}{OT1}{pcr}{m}{it}
\DeclareMathAlphabet{\mC}{OT1}{pcr}{b}{n}
\DeclareMathAlphabet{\mD}{OT1}{pcr}{b}{it}
\DeclareMathAlphabet{\mE}{OT1}{ptm}{m}{n}
\DeclareMathAlphabet{\mF}{OT1}{ptm}{m}{it}
\DeclareMathAlphabet{\mG}{OT1}{ptm}{b}{n}
\DeclareMathAlphabet{\mH}{OT1}{ptm}{b}{it}
\DeclareMathAlphabet{\mI}{OT1}{pag}{m}{n}
\DeclareMathAlphabet{\mJ}{OT1}{pag}{m}{it}
\DeclareMathAlphabet{\mK}{OT1}{pag}{b}{n}
\DeclareMathAlphabet{\mL}{OT1}{pag}{b}{it}
\DeclareMathAlphabet{\mM}{OT1}{pbk}{m}{n}
\DeclareMathAlphabet{\mN}{OT1}{pbk}{m}{it}
\DeclareMathAlphabet{\mO}{OT1}{pbk}{b}{n}
\DeclareMathAlphabet{\mP}{OT1}{pbk}{b}{it}

\begin{document}
$\mathbf{X} \mathit{X} \mathsf{X} \mathtt{X} \mA{X} \mB{X} \mC{X} \mD{X} \mE{X} \mF{X} \mG{X} \mH{X} \mI{X} \mJ{X} \mK{X} \mL{X} \mM{X} \mN{X} \mO{X} \mP{X}$
\end{document}


One could do without copying all that stuff with a simpler patch; the following code should replace all that in the previous one is between \makeatletter and \makeatother:

\usepackage{etoolbox}
\makeatletter
\def\new@mathgroup{\alloc@8\mathgroup\mathchardef\@cclvi}
\patchcmd{\document@select@group}{\sixt@@n}{\@cclvi}{}{}
\patchcmd{\select@group}{\sixt@@n}{\@cclvi}{}{}
\makeatother


Compiling the document with xelatex or lualatex will show the following horror; of course you'll have better use cases.

# Important remark

As Khaled Hosny quite rightly observes, there is a very important limitation: this can work only for math alphabets; it's impossible to define \mathchar values that use the extended set (the XeTeX or LuaTeX extensions should be used). Thus one has to be careful when using math symbol fonts which must be loaded in memory before the math alphabets. So, if , say, stmaryrd is loaded, it's best to ensure that a formula using it is typeset before using the new math alphabets; a \sbox0{$\Ydown$} in the preamble should be sufficient, because so a math group will be permanently allocated for stmaryrd.

-
It seems a bit "surreal" to declare new alphabets for LuaTeX and XeLaTeX with OT1 encoding:) –  Yiannis Lazarides Mar 1 '13 at 13:36
@YiannisLazarides That's only an example; probably \DeclareSymbolFont would make for a more interesting one. I was just too lazy for hunting through font catalogs. –  egreg Mar 1 '13 at 13:40
It's wonderful! –  Popopo Mar 1 '13 at 13:46
@YiannisLazarides This code might make easier the life for the maintainer of the LaTeX symbol list. –  egreg Mar 1 '13 at 13:50
@egreg ... Was thinking about it too! For most of the packages over the math alphabet limit they went the text route though. –  Yiannis Lazarides Mar 1 '13 at 13:56