I have the following command
\def\pderv#1#2{{#1}_{#2}}
which is supposed to denote partial derivatives. In some documents, I sometimes redefine it as the tradional
\def\pderv#1#2{\frac{\partial #1}{\partial #2}}
This works well in most cases. So that \pderv{f}{x}
is either f_x
or
\frac{\partial f}{\partial x}
depending on my definition.
However, sometimes I have a function f_i
. In this case, I would like to denote the derivative with either f_{i,x}
or \frac{\partial f_i}{\partial x}
. The later is doable with the second definition. However, the first definition obviously makes it {f_i}_x
.
Is there anyway to to modify the first definition so that if a subscripted expression is passed, like f_i
, the output is f_{i,x}
? I don't mind modifying the way I call the command (in both definitions) if that's the only way.
Obligatory MWE:
\documentclass{article}
\begin{document}
\def\pderv#1#2{\frac{\partial #1}{\partial #2}}
\[
\pderv{f}{x},\quad\pderv{f_{i}}{x}
\]
\def\pderv#1#2{{#1}_{#2}}
\[
\pderv{f}{x},\quad\pderv{f_{i}}{x}
\]
\end{document}