pderiv square macro [duplicate]

How do I update the macro for partial derivative in order to accept standard second or bigger order?


I know I could use \pderiv{^2 Y}{X^2} to get the proper output but I want to make it easier. (MWE bellow)

\documentclass{article}
\newcommand{\pderiv}[2]{\frac{\partial #1}{\partial #2}}
%\newcommand{\pderiv2}[2]{\frac{\partial^2 #1}{\partial {#2}^2}}

\begin{document}
$\pderiv{^2 Y}{X^2}$ is ok!!

\verb|\pderiv2| doesn't work  :(
\end{document}

• Don't use numbers in macro names. Use \pderivtwo for example.
– user11232
Apr 3, 2015 at 13:22
• @Harish Kumar ok. Is it wrong and return error or is it just a recommendation? Apr 3, 2015 at 13:26
• It is wrong and won't work.
– user11232
Apr 3, 2015 at 13:26
• Have you seen Can I have a flexible partial derivative macro? Apr 3, 2015 at 13:28

commath has the higher-order partial derivatives implemented with the command \pd[order]{first argument}{second argument}

Quoting from their .sty if you want to adapt it:

% Command for partial derivatives. The first argument denotes the function and the second argument denotes the variable with respect to which the derivative is taken. The optional argument denotes the order of differentiation. The style (text style/display style) is determined automatically
\providecommand{\pd}[3][]{\ensuremath{
\ifinner
\tfrac{\partial{^{#1}}#2}{\partial{#3^{#1}}}
\else
\dfrac{\partial{^{#1}}#2}{\partial{#3^{#1}}}
\fi
}}


EDIT: Indeed, as noted by @HarishKumar, the only problem with your custom-defined command was using a number in the macro name.

• The \ifinner tests don't do anything remotely useful there. commath is full of such tests unfortunately Apr 3, 2015 at 13:33
• @DavidCarlisle As I understand, this sets the appearance of the derivative into inline or display math. Would you suggest simply using \frac instead? Apr 3, 2015 at 13:45
• Apr 3, 2015 at 14:06

Problem solved... thanks for the fast response.

\documentclass{article}
\newcommand{\pdev}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdevII}[2]{\frac{\partial^2 #1}{\partial {#2}^2}}
\newcommand{\pd}[3][]{\frac{\partial{^{#1}}#2}{\partial #3^{#1}}}
\begin{document}
$\pdev{^2 Y}{X^2}$ is ok!!

$\pdevII{Y}{X}$ does now work :)

Even better with $\pd[3]{Y}{X}$
\end{document}