Elusive bug when using mathalfa with amsart

This is a “feature” of LaTeX, I'm afraid.

Since amsart automatically loads amsfonts, which defines \mathfrak; it appears that redefining commands defined with \DeclareMathAlphabet is not possible with the current kernel. The problem shows up with a very minimal document:

\documentclass{amsart}
\usepackage[frak=boondox]{mathalfa}

\begin{document}

{\small $\mathfrak{m}$}
$\mathfrak{m}$

\end{document}

because the font changing command causes \mathfrak to do some global assignments that, in a sense, “resurrect” the previous definition of \mathfrak leaving the system in an unstable state.

Workaround if you don't need the full force of amsfonts:

% pretend that amsfonts.sty has already been loaded
\expandafter\def\csname [email protected]\endcsname{3000/12/31}
% load the msb symbol font that's needed for \dh
\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}
% end of the hack

\documentclass{amsart}
\usepackage[frak=boondox]{mathalfa}

\begin{document}

{\small $\mathfrak{m}$}
$\mathfrak{m}$

\end{document}

Actually, there is a possibly better way to solve the issue, by redefining \mathfrak using \DeclareSymbolFontAlphabet that shouldn't resurrect the old definition, because math fonts defined with \DeclareMathAlphabet use a different mechanism that avoids wasting math families if the alphabet is not used in the document; since you'll be using Fraktur, this doesn't really matter.

The trick is to manually do what mathalfa does automatically, but using \DeclareSymbolFont.

\documentclass{amsart}

\makeatletter
\def\mathalfa@frakscaled{s*[1]}
\makeatother
\DeclareFontFamily{U}{BOONDOX-frak}{\skewchar \font =45}
\DeclareFontShape{U}{BOONDOX-frak}{m}{n}{
    <-> \mathalfa@frakscaled  BOONDOX-r-frak}{}
\DeclareFontShape{U}{BOONDOX-frak}{b}{n}{
    <-> \mathalfa@frakscaled  BOONDOX-b-frak}{}
\DeclareSymbolFont{boondoxfrak}{U}{BOONDOX-frak}{m}{n}
\SetSymbolFont{boondoxfrak}{bold}{U}{BOONDOX-frak}{b}{n}
\DeclareSymbolFontAlphabet{\mathfrak}{boondoxfrak}

\begin{document}

{\small $\mathfrak{m}$}
$\mathfrak{m}$

\end{document}