I'm trying to create a differentiation command. At the moment I have the following:
\newcommand{\diff}[1][]{%
\def\ArgI{{#1}}%
\diffRelay%
}
\newcommand{\diffRelay}[2][]{%
\frac{\textnormal{d}^{#1}\ArgI}{\textnormal{d}#2^{#1}}%
}
This allows me to use it like \diff{x}, diff[y]{x}, diff[y][2]{x} to create diff-by-x, diff-y-by-x, second-derivative-of-y-by-x. To simply write the n-th derivative of anything I have to use \diff[][n]{x}.
What I'm looking for is a way to check if the first optional argument is numerical, so I can omit the empty argument to create n-th derivative:
\newcommand{\diff}[1][]{%
\def\ArgI{{#1}}%
\diffRelay%
}
\newcommand{\diffRelay}[2][]{%
\if \ArgI is numerical % better: \and #1 is empty
\frac{\textnormal{d}^{\ArgI}}{\textnormal{d}#2^{\ArgI}}%
\else
\frac{\textnormal{d}^{#1}\ArgI}{\textnormal{d}#2^{#1}}%
}
n
which is perhaps harder to distinguish fromx
in general, unless that was a meta-example...