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:
\DDFshould 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\DDFor\DDF_aor\DDF^b? – Phelype Oleinik Jan 07 '22 at 18:35\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^bis 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$. – Ulrich Diez Jan 07 '22 at 19:07\DDF{a}{\empty}or\DDF{\@gobbletwo{x}{y}}{b}? – Ulrich Diez Jan 07 '22 at 19:15^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. – David Carlisle Jan 07 '22 at 20:50