You could wrap the two arguments in one:
\documentclass[]{article}
\usepackage{mathtools}
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[2][red]{%
\mathpalette\@mathcircled{{#1}{#2}}%
}
\newcommand\@mathcircled[2]{%
\@mathcircled@b{#1}#2%
}
\newcommand\@mathcircled@b[3]{%
\tikz[baseline=(math.base)] \node[draw,color=#2,circle,inner sep=1pt] (math) {$\m@th#1#3$};%
}
\makeatother
\begin{document}
$\mathcircled[blue]{55}$
\end{document}
Without a second helper macro, you could as well put \@mathcircled
and {#1}
in one argument of \mathpalette
:
\documentclass[]{article}
\usepackage{mathtools}
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[2][red]{%
\mathpalette{\@mathcircled{#1}}{#2}%
}
\newcommand\@mathcircled[3]{%
\tikz[baseline=(math.base)] \node[draw,color=#1,circle,inner sep=1pt] (math) {$\m@th#2#3$};%
}
\makeatother
\begin{document}
$\mathcircled[blue]{55}$
\end{document}
Both code blocks result in:

Edit: As requested a version taking more arguments (3 to be precise).
An approach taking two optional arguments in a row. If the first argument is empty it is set to red
(which makes red
the default, as it is empty by default). The second optional argument specifies the shape, defaulting to circle
. I tried to explain the code a bit in comments:
\documentclass[border=2mm]{standalone}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes}
\makeatletter
\newcommand\mathcircled[1][]
{%
% keeping stuff local
\begingroup
% check whether #1 is empty
\if\relax\detokenize{#1}\relax
% save red as the colour for later
\def\mathcircled@color{red}%
\else
% save #1 as the colour for later
\def\mathcircled@color{#1}%
\fi
% grab the next optional argument and the mandatory one
\mathcircled@b
}
\newcommand\mathcircled@b[2][circle]
{%
% expand the colour and read the expanded colour and the other two arguments
\expandafter\mathcircled@c\expandafter{\mathcircled@color}{#1}{#2}%
}
\newcommand\mathcircled@c[3]
{%
% putting the two optional arguments with \mathcircled@d into the first
% argument of \mathpalette
\mathpalette{\mathcircled@d{#1}{#2}}{#3}
\endgroup
}
\newcommand\mathcircled@d[4]
{%
\tikz[baseline=(math.base)]
\node[draw,color=#1,#2,inner sep=1pt] (math) {$\m@th#3#4$};%
}
\makeatother
\begin{document}
$\mathcircled[blue]{55}$
$\mathcircled[][ellipse]{69}$
$\mathcircled{5}$
\end{document}
Results:

A version of the edit using xparse
:
\documentclass[border=2mm]{standalone}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{xparse}
\makeatletter
% this will be used to parse the first optional argument of \mathcircled to
% set the default.
\newcommand \EmptyArgParse [2]
{%
\if\relax\detokenize{#2}\relax
\def\ProcessedArgument{#1}%
\else
\def\ProcessedArgument{#2}%
\fi
}
\NewDocumentCommand \mathcircled { >{\EmptyArgParse{red}}O{} O{circle} m }
{%
\mathpalette{\mathcircled@b{#1}{#2}}{#3}%
}
\newcommand\mathcircled@b[4]
{%
\tikz[baseline=(math.base)]
\node[draw,color=#1,#2,inner sep=1pt] (math) {$\m@th#3#4$};%
}
\makeatother
\begin{document}
$\mathcircled[blue]{55}$
$\mathcircled[][ellipse]{69}$
$\mathcircled{5}$
\end{document}
circle
withellipse
, but you have to\usetikzlibrary{shapes}
in your preamble.