# How to write the superscript above the subscript in newcommand?

I want to create a command for adding a superscript * to a variable, indicating its "optimal" value. However, when I do this, the superscript is added after the subscript instead of right above:

\documentclass{article}
\newcommand{\optimal}[1]{{#1}^*}
\begin{document}
$V_N^*$ vs. $\optimal{V_N}$
\end{document}


My question is: how can I write a newcommand which would add the superscript above the subscript?

• \newcommand{\optimal}[1]{#1^*} – user121799 Nov 6 '18 at 17:39
• @marmot Please add an answer, I think an explanation will be useful to future users (and to the OP, of course)! – CarLaTeX Nov 6 '18 at 18:00
• @CarLaTeX OK, I tried. If you find a better way, I will be very happy to remove my answer. ;-) – user121799 Nov 6 '18 at 18:11
• @marmot No, I leave it to egreg :) – CarLaTeX Nov 6 '18 at 18:40

## 1 Answer

For what it's worth: I suggest to define the command as \newcommand{\optimal}[1]{#1^*} because

\documentclass{article}
\newcommand{\oldoptimal}[1]{{#1}^*}
\newcommand{\newoptimal}[1]{#1^*}
\begin{document}
\begin{itemize}
\item The original command, which I renamed \verb|\oldoptimal|, has additional
braces:
$\oldoptimal{V_N}={V_N}^*\qquad\mbox{or}\qquad \verb|\oldoptimal{V_N}|=\verb|{V_N}^*|\;.$
\item In order to get the star where you want it to be, you thus need to remove
the braces. This is what \verb|\newoptimal| does:
$\newoptimal{V_N}=V_N^*\qquad\mbox{or}\qquad \verb|\newoptimal{V_N}|=\verb|V_N^*| \;.$
\end{itemize}
\end{document}

• How would you handle \newoptimal{V_N^1}? – Werner Nov 6 '18 at 18:20
• @Werner {\newoptimal{V_N}}^1 or define it with an optional argument. I guess that this was not the question, right? – user121799 Nov 6 '18 at 18:22