参考我可以有一个灵活的偏导数宏吗?,也许我应该对这个很酷的包裹感到满意,然后继续前进。但是……
inset/outset
如果可以将和指定shorten=true/false
为特定实例的选项,而不是单独的样式选项,那肯定会很好。例如: \pderiv[inset][n]{f}{x}
,或者也许\pderiv[n,inset]{f}{x}
。有人尝试过修改包以使其像这样运行吗?
另外,原文中楼主的请求能不能在表单里显示出来呢f_{xxy}
?
答案1
以下是我对获取选择键的答案的修改:\pder{f}{x}
或者\pder{f}{*{2}{x},y}}
将在显示模式或内联模式之间自动选择;在前一种情况下,我们将得到
\frac{\partial f}{\partial x}
\frac{\partial^{3} f}{\partial x^{2}\partial y}
后者
f_{x}
f_{xxy}
也可以说\pder[display]{f}{...}
得到分数形式或\pder[inline]{f}{...}
下标形式。
\documentclass[a4paper]{article}
\usepackage{xkeyval}
\makeatletter
\define@choicekey{pder}{style}[\der@val\der@nr]{auto,display,inline}{%
\ifcase\der@nr
\let\pder@do\pder@choose
\or
\let\pder@do\pder@display
\or
\let\pder@do\pder@inline
\fi}
\newcommand\pder[1][auto]{\setkeys{pder}{style=#1}\pder@do}
\def\pder@choose#1#2{%
\mathchoice{\pder@display{#1}{#2}}{\pder@inline{#1}{#2}}
{\pder@inline{#1}{#2}}{\pder@inline{#1}{#2}}}
\newcommand{\pder@display}[2]{\begingroup
\@tempswafalse\toks@={}\count@=\z@
\@for\next:=#2\do
{\expandafter\check@var\next
\advance\count@\der@exp
\if@tempswa
\toks@=\expandafter{\the\toks@\,}%
\else
\@tempswatrue
\fi
\toks@=\expandafter{\the\expandafter\toks@\expandafter\partial\der@var}}%
\frac{\partial\ifnum\count@=\@ne\else^{\number\count@}\fi#1}{\the\toks@}%
\endgroup}
\def\check@var{\@ifstar{\mult@var}{\one@var}}
\def\mult@var#1#2{\def\der@var{#2^{#1}}\def\der@exp{#1}}
\def\one@var#1{\def\der@var{#1}\chardef\der@exp\@ne}
\newcommand{\pder@inline}[2]{\begingroup
\toks@={}%
\@for\next:=#2\do
{\expandafter\check@varinline\next
\toks@=\expandafter{\the\expandafter\toks@\der@varinline}}%
#1_{\the\toks@}%
\endgroup}
\def\check@varinline{\@ifstar\mult@varinline\one@varinline}
\def\one@varinline#1{\def\der@varinline{#1}}
\def\mult@varinline#1#2{%
\def\der@varinline{}\count@\z@ % initialize
\loop\ifnum\count@<#1\relax
\expandafter\def\expandafter\der@varinline\expandafter{%
\der@varinline#2}%
\advance\count@\@ne
\repeat}
\makeatother
\begin{document}
\[
\pder{f}{x}\qquad \pder{f}{*{2}{x},y}\qquad \pder[inline]{f}{*{3}{x},y,*{4}{z}}
\]
$
\pder{f}{x}\qquad \pder{f}{*{2}{x},y}\qquad \pder[display]{f}{*{3}{x},y,*{4}{z}}
$
\end{document}
答案2
这是我用来编写全导数和偏导数的内容。
% Sources :
% * http://forum.mathematex.net/latex-f6/en-tete-de-ds-t12933.html#p124908
% * http://forum.mathematex.net/latex-f6/derivee-avec-un-d-droit-et-espace-t12932.html#p124930
% * http://forum.mathematex.net/latex-f6/remplacer-des-espaces-par-autre-chose-t12952.html#p125062
% * http://forum.mathematex.net/latex-f6/probleme-de-remplacement-de-cdots-t13047.html#p125782
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xstring}
\noexpandarg % This is necessary so as to '' \derFrac[3]{\cos}{x} '' works.
% Power writing of total derivate
\newcommand{\derPow}[2]{
#2^{\left( #1 \right)}
}
% Fractional writing of total derivate
\DeclareRobustCommand{\dder}{
\mathop{}\mathopen{}\mathrm{d}
}
\newcommand{\dd}[2][0]{
\IfStrEq{#1}{0}{
\dder #2
}{
\IfBeginWith{#2}{f}{
\dder^{#1} \! #2
}{
\dder^{#1} #2
}
}
}
\newcommand{\derFrac}[3][0]{
\IfStrEq{#1}{0}{
\ensuremath{\frac{\dd{#2}}{\dd{#3}}}
}{
\ensuremath{\frac{\dd[#1]{#2}}{\dd{#3}^{#1}}}
}
}
% Subscript writing of partial derivate
\makeatletter
\let\original@partial\partial
\renewcommand{\partial}{
\original@partial\mathopen{}
}
\makeatother
\newcommand\addPar[1]{(#1)}
\newcommand\partialSub[2]{
\def\indPartial{\StrSubstitute{#2}{^}{\addPar}} % This works because xstring traits {...} like a single character.
\ensuremath{\partial_{\indPartial} #1}
}
% Prime writing of partial derivate
\newcommand\partialPrime[2]{
\def\indPartial{\StrSubstitute{#2}{^}{\addPar}} % This works because xstring traits {...} like a single character.
\ensuremath{#1^{\prime}_{\indPartial}}
}
% Fractional writing of partial derivate
\newcommand{\pp}[2][0]{
\IfStrEq{#1}{0}{
\partial #2
}{
\IfBeginWith{#2}{f}{
\partial^{#1} \! #2
}{
\partial^{#1} #2
}
}
}
\newcommand\partialFrac[3][0]{%
\frac{\partial\IfStrEq{#1}0{}{^{#1}}#2}
{%
\StrSubstitute{\partial#3}{ }\partial[\temp]%
\expandafter\StrSubstitute\expandafter{\temp}{\partial\cdots}{\,\cdots{}\,\partial}
}
}
\begin{document}
\setlength{\parindent}{0pt}
\newcommand{\HH}{
\mathrm{H}
}
\section{Total derivate}
$ \cos'(x) = \derFrac{\cos}{x} (x) $
$ f'(x) = \derFrac{f}{x} (x)$
$ \derPow{5}{\HH} (x) = \derFrac[5]{\HH}{x} (x) $
$ \derPow{n}{G} (x) = \derFrac[n]{G}{x} (x) $
$ f'''(x) = \derFrac[3]{f}{x} (x) $
$ \cos'''(x) = \derFrac[3]{\cos}{x} (x) $
\section{Partial derivate}
$ \partialPrime{\cos}{x} (x) = \partialFrac{\cos}{x} (x) $
$ \partialPrime{f}{x} (x) = \partialFrac{f}{x} (x) $
$ \partialPrime{\HH}{x} (x) = \partialFrac{\HH}{x} (x) $
$ \partialPrime{f}{x^r y^s} (x,y) = \partialFrac[r + s]{f}{x^r y^s} (x,y) $
$ \partialPrime{f}{x^{5 + 2} y^{4} z} = \partialFrac[13]{f}{x^{5 + 2} y^{4} z} (x,y) $
$ \partialSub{G}{f^{5^2} h^4 r} (x,y) = \partialFrac[30]{G}{f^{5^2} h^4 r} (x,y) $
$ \partialSub{F}{x^n \cdots z^r} (x,\ldots,y) = \partialFrac[N + \cdots + r]{F}{x^n \cdots z^r} (x,\ldots,y) $
\end{document}