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:

$V_N^*$ vs. $\optimal{V_N}$

enter image description here

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

  • 3
    \newcommand{\optimal}[1]{#1^*} – marmot Nov 6 '18 at 17:39
  • 1
    @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. ;-) – marmot Nov 6 '18 at 18:11
  • @marmot No, I leave it to egreg :) – CarLaTeX Nov 6 '18 at 18:40

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

enter image description here

 \item The original command, which I renamed \verb|\oldoptimal|, has additional
 \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:
 \verb|\newoptimal{V_N}|=\verb|V_N^*| \;.\]
  • 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? – marmot Nov 6 '18 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.