# Superscript simply refuses to be superscripted

I'm getting slightly desperate because the following seemingly simple macro does not do what I want:

\newcommand{\Ma}[1][]{\ensuremath{M_{1}^{#1}}\xspace}
Hello $\Ma{a}$.


I would expect that $\Ma{a}$ would result in a as a superscript, but id does not. What's wrong here?

• #1 is the optional argument, you want either two argument [2] and #2 or should use [a] as input. xspace is quite useless here and I wouldn't use \ensuremath either. – Ulrike Fischer May 26 '18 at 10:12


Following up on Ulrike's comment, some links about xspace and \ensuremath:

And a complete example, with two possible macro definitions.

\documentclass{article}
\newcommand{\Ma}[1]{M_{1}^{#1}}
\newcommand{\Mb}[2][1]{M_{#1}^{#2}}
\begin{document}
$\Ma{a}, \Mb{b} \Mb[]{c} \Mb[2]{d}$.
\end{document}