# How to make a command for a circled letter to work with all font sizes?

I introduced the following macros

\newcommand{\malcev}{\mathop{\text{\textcircled{\scriptsize M}}}\nolimits}
\newcommand{\imalcev}{\mathop{\text{\textcircled{\tiny M}}}\nolimits}


The code

$\mathbf{V} \malcev \mathbf{W} \qquad F_{\mathbf{V} \imalcev \mathbf{W}} \qquad S^{\mathbf{V} \imalcev \mathbf{W}}$


now produces an acceptable result

However, it is certainly not a clean solution since I have to manually switch between \malcev and \imalcev depending on the font size (not to speak about a possible double superscript). I am looking for a better solution (if possible avoiding tikz). I looked at the following questions

which are certainly relevant, but I was not able to get exactly what I wanted from their answers. One of the difficulties is that I use \textcircled on a scriptsized letter (otherwise my symbol would be too big), but this is probably not a good idea. Any help would be appreciated.

• An alternative, arguably cleaner, and in any case shorter solution is offered by John Kormylo on this question: tex.stackexchange.com/a/290956/65 . This relies on amsmath's \text, extract the actual height of a letter, and draws the operator in proportion to it. – Michaël Feb 3 '16 at 18:00
• @michaël This solution is nice, but it relies on tikz. – J.-E. Pin Feb 3 '16 at 18:14
• Not really; the symbol is drawn with TikZ, but it could be a simple textcircled. For instance: \newlength\oneex\def\malcev{\mathop{\text{\settoheight{\oneex}{x}\raisebox{0.3\oneex}{\resizebox{!}{\oneex}{\normalsize\textcircled{\scriptsize M}}}}}}. Basically, the circled M is written in a "normal" size, and it is then scaled to the height of an x. – Michaël Feb 3 '16 at 18:29

In this case using directly \mathchoice seems preferable:

\documentclass{article}
\usepackage{fix-cm} % make font arbitrarily scalable
\usepackage{amsmath}

\newcommand{\malcev}{\mathbin{
\mathchoice
{\mbox{\normalsize\textcircled{\scriptsize M}}}
{\mbox{\normalsize\textcircled{\scriptsize M}}}
{\mbox{\scriptsize\textcircled{\tiny M}}}
{\mbox{\tiny\textcircled{\fontsize{3.5}{3.5}\selectfont M}}}
}
}

\begin{document}
$\mathbf{V} \malcev \mathbf{W} \qquad F_{\mathbf{V} \malcev \mathbf{W}} \qquad S^{\mathbf{V} \malcev \mathbf{W}^{\malcev}}$
\end{document}