I wish to make a command \DDF
that prints $\delta\Delta\Phi$
with optional scripts. Could you please help me do this?
Here are desired inputs to give desired outputs:
\DDF
should give$\delta\Delta\Phi$
\DDF{a}{b}
should give$\delta\Delta\Phi_a^b$
\DDF{a}{}
should give$\delta\Delta\Phi_a$
\DDF{a}
should give$\delta\Delta\Phi_a$
\DDF{}{b}
should give$\delta\Delta\Phi^b$
I think the following may (almost) work -- except for (4) -- but even so I'm not sure it's the rigorous or elegant way to do it:
\newcommand{\DDF}[2]{\delta\Delta\Phi_{#1}^{#2}}
\newcommand{\DDF}{\delta\Delta\Phi}
then use\DDF
or\DDF_a
or\DDF^b
?\DDF
- defined as intended by you - is used with mathmode, e.g.,$a^2+\DDF{a}{b}+b^2$
, then you get$a^2+$\delta\Delta\Phi_a^b$+b^2$
which is a problem as\delta\Delta\Phi_a^b
is not in math-mode. If you do$a^2+$\DDF{a}{b}$+b^2$
, then you get three separate adjacent formulas which probably is not what you want. Thus I suggest not to wrap entire definition-texts into$
.\DDF{a}{\empty}
or\DDF{\@gobbletwo{x}{y}}{b}
?^
and_
syntax is preferable here, it makes it far more natural to have both optional, as your case 5 shows, you can't omit the first argument if you want to use the second.