Here is an alternative to your current situation - using an optional argument to specify the derivative order. This way you don't have to define a macro for "each" derivative:
\deriv[<order>]{<func>}{<var>}
Here's a minimal example:
\documentclass{article}
\newcommand{\deriv}[3][]{% \deriv[<order>]{<func>}{<var>}
\ensuremath{\frac{\partial^{#1} {#2}}{\partial {#3}^{#1}}}}
\begin{document}
In text mode there is~\deriv{y}{x} and~\deriv[2]{y}{x}. In display mode there is
\[
\deriv{y}{x}\ \textrm{and}\ \deriv[2]{y}{x}\rlap{.}
\]
\end{document}
The default <order>
is empty, implying the first order partial derivative. If you want the default to be 2
, modify the definition to read
\newcommand{\deriv}[3][2]{...}
Technically it is possible to use a macro with numbers in them, but the usage is much less intuitive than adding something like an optional argument (as given above). Here's an implementation that now allows you to use \nameuse{deriv2}{y}{x}
:
\expandafter\def\csname deriv2\endcsname#1#2{%
\ensuremath{\frac{\partial^2 {#1}}{\partial {#2}^2}}}
\makeatletter
\newcommand{\nameuse}[1]{\@nameuse{#1}}%
\makeatother
The optional argument beats this hands down.
Best Answer
\limits
is a tex primitive. from victor eijkhout's "tex by topic" (pp. 287, 289):chapter 37 of "tex by topic" is a glossary of tex primitives. if you are using a tex live system with documentation loaded, you can refer to this book online by
texdoc texbytopic
.