[Tex/LaTex] Make box in math mode with current math font

boxesfontsmath-mode

The commands

$\mathcal{\mbox{$M$}}$

and

\mbox{$\mathcal{M}$}

produce different output. I would like a replacement for \mbox that creates a box preserving all features of the current font in math mode. How can I do this?

Best Answer

Please always post complete documents:

\documentclass{article}
\usepackage{amsfonts}
\begin{document}
$\mathcal{\count0=\fam\mbox{$\fam=\count0 M$}}$
\end{document}