[Tex/LaTex] How to make a command for a circled letter to work with all font sizes

circlesfontsizemath-operatorssymbols

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

Malcev example

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

  1. Good way to make \textcircled
    numbers?
  2. How do I put a circle around an
    operator?
  3. How to make a command for a composed symbol to work with all font
    sizes?

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.

Best Answer

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}

enter image description here