I am trying to expand the macro given in Can I have a flexible partial derivative macro? In particular, I would like to add a starred version that does not attempt to sum the exponents of the various derivatives, which is useful if the exponent isn't a number. My attempt is given below, but I didn't make much progress. The way I would like the command to work is shown in the second displayed math environment. Ideally, I would only have one command, and it would behave as shown in the third displayed math environment, but this seems overly ambitious.
\documentclass[12pt]{article}
\makeatletter
\newcommand\derivative[2]
{
\begingroup
\@temptokena{\@gobble}
\@tempcnta\z@
\@for\var:=#2\do
{
\expandafter\@derivative\var\relax
}
\frac
{
d
\ifnum \@tempcnta > \@ne
^{\the\@tempcnta}
\fi
#1
}
{\the\@temptokena}
\endgroup
}
\def\@derivative#1#2\relax
{
\ifx\relax#2\relax
\advance\@tempcnta by \@ne
\@temptokena\expandafter{\the\@temptokena \, d #1}
\else
\advance\@tempcnta by #2\relax
\@temptokena\expandafter{\the\@temptokena \, d #1^{#2}}
\fi
}
\makeatother
\makeatletter
\newcommand\derivativestar[2]
{
\begingroup
\@temptokena{\@gobble}
\@temptokenb{}
\@for\var:=#2\do
{
\expandafter\@derivativestar\var\relax
}
\frac
{
d^{\@temptokenb} #1
}
{\the\@temptokena}
\endgroup
}
\def\@derivativestar#1#2\relax
{
% need to test for first token
\ifx\relax#2\relax
\@temptokena\expandafter{\the\@temptokena \, d #1}
\@temptokenb\expandafter{\the\@temptokenb + 1}
\else
\@temptokena\expandafter{\the\@temptokena \, d #1^{#2}}
\@temptokenb\expandafter{\the\@temptokenb + #2}
\fi
}
\makeatother
\begin{document}
\[
\derivative{x}{{y}{2},{z}{3}}
\]
\[
% \derivative*{x}{{y}{m},{z}{n}}
\frac{d x^{m+n}}{d y^{m} \, d z^{n}}
\]
\[
% \derivative{x}{{v}{3},{w}{k,2},y,{z}{m}}
\frac{d x^{k+m+6}}{d v^{3} \, d w^{k+2} \, d y \, d z^{m}}
\]
\end{document}