Creating a macro for many partial differentiations

Needless to reinvent the wheel: there already exists a dedicated package: esdiff, which also manages evaluation points as indices:

\documentclass{article}

\usepackage{esdiff}

\begin{document}

    \[ \diffp{f(x, y, z)}{{x^{3333}}{y^{9999}}{z^{8888}}{t^{55555}}} \]%

    \[ \diffp*{f(x, y, z)}{{x^{3333}}{y^{9999}}{z^{8888}}{t^{55555}}}{(x_0,y_0,z_0,t_0)} \]%

\end{document} 

enter image description here


A listofitems approach that uses key values. The syntax is, for example

\pdiff[y=3,x,z,p=2,d=3,q,r=2,s]{f(x,y,z,p,d,q,r,s)}

Here is the MWE

\documentclass{article}
\usepackage{listofitems,tikz}
\newcounter{totalindex}
\newcommand\pdiff[2][1]{%
  \setsepchar{,/=}%
  \readlist\Partialvars{#1}%
  \setcounter{totalindex}{0}%
  \foreach \Varindex in {1,...,\listlen\Partialvars[]}%
    {%
      \ifnum\listlen\Partialvars[\Varindex]>1\relax%
        \addtocounter{totalindex}{\Partialvars[\Varindex,2]}%
      \else%
        \stepcounter{totalindex}%
      \fi%
    }%
    \frac{\partial\ifnum\thetotalindex>1\relax^{\thetotalindex}\fi#2}%
         {%
          \foreach\Varindex in {1,...,\listlen\Partialvars[]}%
           {%
             \partial\Partialvars[\Varindex,1]%
             \ifnum\listlen\Partialvars[\Varindex]>1\relax^{\Partialvars[\Varindex,2]}\fi%
           }%
         }%
}
\begin{document}
\[ \pdiff[y]{f(x,y,z)} \]
\[ \pdiff[y=3,x,z]{f(x,y,z)} \]
\[ \pdiff[y=9999, x=3333, z=8888]{f(x,y,z)} \]
\[ \pdiff[y=3,x,z,p=2,d=3,q,r=2,s]{f(x,y,z,p,d,q,r,s)} \]
\end{document}

enter image description here

While the tikz \foreach loop, used above, is a readily understandable construct for looping through an index, one can eliminate the use of the tikz package altogether, using the looping construct built in to the listofitems package. In this case though, the loop is through the items of the list, and one can indirectly access the index number by way of \<loop-variable>cnt.

\documentclass{article}
\usepackage{listofitems}
\newcounter{totalindex}
\newcommand\pdiff[2][1]{%
  \setsepchar{,/=}%
  \readlist\Partialvars{#1}%
  \setcounter{totalindex}{0}%
  \foreachitem \Var \in \Partialvars[]%
    {%
      \ifnum\listlen\Partialvars[\Varcnt]>1\relax%
        \addtocounter{totalindex}{\Partialvars[\Varcnt,2]}%
      \else%
        \stepcounter{totalindex}%
      \fi%
    }%
    \frac{\partial\ifnum\thetotalindex>1\relax^{\thetotalindex}\fi#2}%
         {%
          \foreachitem \Var \in \Partialvars%
           {%
             \partial\Partialvars[\Varcnt,1]%
             \ifnum\listlen\Partialvars[\Varcnt]>1\relax^{\Partialvars[\Varcnt,2]}\fi%
           }%
         }%
}
\begin{document}
\[ \pdiff[y]{f(x,y,z)} \]
\[ \pdiff[y=3,x,z]{f(x,y,z)} \]
\[ \pdiff[y=9999, x=3333, z=8888]{f(x,y,z)} \]
\[ \pdiff[y=3,x,z,p=2,d=3,q,r=2,s]{f(x,y,z,p,d,q,r,s)} \]
\end{document}

You can use a comma separated list for the list of variables. I use the convention that

x/2,y/3,z

stands for “twice x, three times y and once z”. You can also use x/2,y/3,z/1, if you prefer.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\pdiff}{smm}
 {
  \IfBooleanTF{#1}
   {% with \pdiff* call the inner function for inline
    \egreg_pdiff_inline:nn { #2 } { #3 } % TO DO
   }
   {% with \pdiff call the inner function for display
    \egreg_pdiff_frac:nn { #2 } { #3 }
   }
 }

% allocate some variables
\int_new:N \l__egreg_pdiff_total_int
\seq_new:N \l__egreg_pdiff_vars_seq
\seq_new:N \l__egreg_pdiff_var_seq
\tl_new:N \l__egreg_pdiff_denom_tl

\cs_new_protected:Nn \egreg_pdiff_frac:nn
 {
  % clear the variables to be given values later
  \int_zero:N \l__egreg_pdiff_total_int
  \tl_clear:N \l__egreg_pdiff_denom_tl
  % split the second argumen at commas
  \seq_set_split:Nnn \l__egreg_pdiff_vars_seq { , } { #2 }
  % map this sequence for adding to the denominator and
  % computing the number of derivatives
  \seq_map_function:NN \l__egreg_pdiff_vars_seq \__egreg_pdiff_var:n

  % now print:
  % \l__egreg_pdiff_total_int is set to the number of derivatives
  % \l__egreg_pdiff_denom_tl contains the denominator
  \frac
   {
    \partial
    \int_compare:nT { \l__egreg_pdiff_total_int > 1 }
     { \sp { \int_to_arabic:n { \l__egreg_pdiff_total_int } } }
    #1
   }
   {
    \tl_use:N \l__egreg_pdiff_denom_tl
   }
 }

\cs_new_protected:Nn \__egreg_pdiff_var:n
 {
  % split the argument at / (it should be in the form 'x' or 'x/2')
  \seq_set_split:Nnn \l__egreg_pdiff_var_seq { / } { #1 }
  % if the sequence has one term, no exponent is present
  \int_compare:nTF { \seq_count:N \l__egreg_pdiff_var_seq < 2 }
   {% simple variable: add to the denominator and increment the number
    \tl_put_right:Nn \l__egreg_pdiff_denom_tl { \partial #1 }
    \int_incr:N \l__egreg_pdiff_total_int
   }
   {% multiple: add to the denominator and increment the number
    % item 1 contains the variable, item 2 the exponent
    \tl_put_right:Nx \l__egreg_pdiff_denom_tl
     {
      \partial
      \seq_item:Nn \l__egreg_pdiff_var_seq { 1 }
      \sp { \seq_item:Nn \l__egreg_pdiff_var_seq { 2 } }
     }
    \int_add:Nn \l__egreg_pdiff_total_int { \seq_item:Nn \l__egreg_pdiff_var_seq { 2 } }
   }
 }
\ExplSyntaxOff

\begin{document}

\[
\pdiff{f(x,y)}{x}
\quad
\pdiff{f(x,y,z)}{x/20,y/32,z}
\]

\end{document}

enter image description here