我如何更新偏导数的宏以接受标准二阶或更大的阶数?
到目前为止,我已经得到了\newcommand{\pderiv}[2]{\frac{\partial #1}{\partial #2}}
一阶导数。我尝试使用不同的命令 ( \newcommand{\pderiv2}[2]{\frac{\partial^2 #1}{\partial {#2}^2}}
) 来生成二阶导数,但出现错误,因为参数 #2 不接受下标或上标。如何解决这个问题?
我知道我可以使用 \pderiv{^2 Y}{X^2} 来获得正确的输出,但我想让它更容易一些。(MWE 咆哮)
\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}
答案1
commath
使用命令实现高阶偏导数\pd[order]{first argument}{second argument}
如果您想改编它,请引用他们的.sty:
% 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
}}
编辑:确实,正如@HarishKumar 所指出的,自定义命令的唯一问题是在宏名称中使用数字。
答案2
问题解决了...感谢您的快速回复。
\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}