| 1 |
%\iffalse |
| 2 |
% |
| 3 |
%esdiff.dtx version 1.2 April 2008 |
| 4 |
%Eddie Saudrais ([email protected]) |
| 5 |
%Code slightly revised by Christophe Jorssen |
| 6 |
% |
| 7 |
%<*driver> |
| 8 |
\documentclass[a4paper]{ltxdoc} |
| 9 |
\usepackage{esdiff} |
| 10 |
\parindent 0cm |
| 11 |
\topmargin -1cm |
| 12 |
\begin{document} |
| 13 |
\DocInput{esdiff.dtx} |
| 14 |
\end{document} |
| 15 |
%</driver> |
| 16 |
%\fi |
| 17 |
%\CheckSum{486} |
| 18 |
%\title{Writing derivatives} |
| 19 |
%\author{Eddie Saudrais} |
| 20 |
%\date{\today} |
| 21 |
%\maketitle |
| 22 |
%\MakeShortVerb{\|} |
| 23 |
%\begin{abstract} |
| 24 |
%This document describes the package \textsf{esdiff} that makes |
| 25 |
%writing derivatives very easy. |
| 26 |
%It allows to write derivatives, partial derivatives, multiple |
| 27 |
%derivatives. |
| 28 |
%Some typographic options are available. |
| 29 |
%The macro about crossed derivatives was given on |
| 30 |
%\texttt{comp.text.tex} by Peter Schmitt. |
| 31 |
%\end{abstract} |
| 32 |
%\section{Derivatives} |
| 33 |
% |
| 34 |
%\DescribeMacro{\diff} |
| 35 |
% |
| 36 |
%Derivatives are obtained with the command \textsf{diff}. |
| 37 |
% |
| 38 |
%To get $\diff{f}{x}$, just write |$\diff{f}{x}$|. |
| 39 |
% |
| 40 |
%The ordre of the derivative can be set in square brackets. |
| 41 |
%So |$\diff[n]{f}{x}$| gives $\diff[n]{f}{x}$. |
| 42 |
% |
| 43 |
%\DescribeMacro{\diff*} |
| 44 |
% |
| 45 |
%It's easy to precise the point where the derivative is calculated: |
| 46 |
% |
| 47 |
% |$\diff*{f}{x}{x_0}$| |
| 48 |
%gives $\diff*{f}{x}{x_0}$. |
| 49 |
% |
| 50 |
%Of course, those two options can be used together: |
| 51 |
%|$\diff*[2]{g}{y}{0}$| gives as expected $\diff*[2]{g}{y}{0}$. |
| 52 |
% |
| 53 |
%\section{Partial derivatives} |
| 54 |
% |
| 55 |
%\DescribeMacro{\diffp} |
| 56 |
% |
| 57 |
%Partial derivatives are obtained with the macro |
| 58 |
%\textsf{diffp}, using the same syntaxe as with \textsf{diff}: |
| 59 |
%a star version to put a subscript, and square brackets to set |
| 60 |
%the order of the derivative according to only one variable. |
| 61 |
% |
| 62 |
%To get $\diffp{f}{x}$, just write |
| 63 |
%|$\diffp{f}{x}$|. |
| 64 |
% |
| 65 |
%We obtain $\diffp[2]{f}{x}$ writing |$\diffp[2]{f}{x}$|. |
| 66 |
% |
| 67 |
%\DescribeMacro{\diffp*} |
| 68 |
% |
| 69 |
%The notation $\diffp*{p}{V}{T}$ is the result of |
| 70 |
%|$\diffp*{p}{V}{T}$|. |
| 71 |
% |
| 72 |
%The notation of crossed derivatives is automatic. |
| 73 |
%To get $\diffp{f}{{x}{y^2}}$, write |
| 74 |
% |
| 75 |
%|$\diffp{f}{{x}{y^2}}$|. |
| 76 |
%This method can be used to write a partial derivative, without |
| 77 |
%square beackets. So |$\diffp{f}{{x^2}}$| gives $\diffp{f}{{x^2}}$. |
| 78 |
% |
| 79 |
%We can mix options: |
| 80 |
% |$\diffp*{f}{{x^2}{y^3}}{z}$| |
| 81 |
%gives $\diffp*{f}{{x^2}{y^3}}{z}$. |
| 82 |
% |
| 83 |
%\section{Options} |
| 84 |
% |
| 85 |
%Several options are available: |
| 86 |
%\begin{itemize} |
| 87 |
%\item |
| 88 |
%by default, derivatives are written in displaystyle on text mode. |
| 89 |
%The \textsf{display} option set this default. With the \textsf{text} |
| 90 |
%option, derivatives are written in textstyle on text mode; |
| 91 |
%\item |
| 92 |
%by default, the \texttt{d} of the derivative is written in roman. |
| 93 |
%Available options are \textsf{roman} and \textsf{italic}; |
| 94 |
%\item |
| 95 |
%we can set the space between the \texttt{d} and the symbol of the |
| 96 |
%function or of the variable. By default, this space is null. |
| 97 |
%Available options are \textsf{thin}, \textsf{med} and |
| 98 |
%\textsf{big}. It may be fine to add a space when the \texttt{d} |
| 99 |
%is in italic; |
| 100 |
%\item |
| 101 |
%We can set the space between the $\partial$ and the symbol of the |
| 102 |
%function or of the variable. By default, this space is null. |
| 103 |
%Available options are \textsf{thinp}, \textsf{medp} and |
| 104 |
%\textsf{bigp}; |
| 105 |
%\item |
| 106 |
%the space between $\partial x$ and $\partial y$ in crossed derivatives may be too |
| 107 |
%narrow. It is null by default. Available options are |
| 108 |
%\textsf{thinc}, \textsf{medc} and \textsf{bigc}; |
| 109 |
%\end{itemize} |
| 110 |
% |
| 111 |
%\section{The code} |
| 112 |
%\StopEventually{} |
| 113 |
%The package presents itself. |
| 114 |
% \begin{macrocode} |
| 115 |
%<*package> |
| 116 |
\NeedsTeXFormat{LaTeX2e} |
| 117 |
\ProvidesPackage{esdiff} |
| 118 |
% \end{macrocode} |
| 119 |
%We set default values for the options. |
| 120 |
% \begin{macrocode} |
| 121 |
\newcommand*{\ES@taille}[1]{\displaystyle{#1}} |
| 122 |
\newcommand*{\ES@difint}{\mkern 0mu} |
| 123 |
\newcommand*{\ES@derpint}{\mkern 0mu} |
| 124 |
\newcommand*{\ES@croisint}{\mkern 0mu} |
| 125 |
% \end{macrocode} |
| 126 |
%The \textsf{d} is roman by default.. |
| 127 |
% \begin{macrocode} |
| 128 |
\newcommand*{\ES@dop}{\mathrm{d}} |
| 129 |
% \end{macrocode} |
| 130 |
%Options: |
| 131 |
% \begin{macrocode} |
| 132 |
\DeclareOption{display}{\renewcommand*{\ES@taille}[1]{\displaystyle{#1}}} |
| 133 |
\DeclareOption{text}{\renewcommand*{\ES@taille}[1]{\textstyle{#1}}} |
| 134 |
\DeclareOption{roman}{\renewcommand*{\ES@dop}{\ensuremath{\mathrm{d}}}} |
| 135 |
\DeclareOption{italic}{\renewcommand*{\ES@dop}{\ensuremath{d}}} |
| 136 |
\DeclareOption{thin}{\renewcommand*{\ES@difint}{\ensuremath{\,}}} |
| 137 |
\DeclareOption{med}{\renewcommand*{\ES@difint}{\ensuremath{\;}}} |
| 138 |
\DeclareOption{big}{\renewcommand*{\ES@difint}{\ensuremath{\:}}} |
| 139 |
\DeclareOption{thinp}{\renewcommand*{\ES@derpint}{\ensuremath{\,}}} |
| 140 |
\DeclareOption{medp}{\renewcommand*{\ES@derpint}{\ensuremath{\;}}} |
| 141 |
\DeclareOption{bigp}{\renewcommand*{\ES@derpint}{\ensuremath{\:}}} |
| 142 |
\DeclareOption{thinc}{\renewcommand*{\ES@croisint}{\ensuremath{\,}}} |
| 143 |
\DeclareOption{medc}{\renewcommand*{\ES@croisint}{\ensuremath{\;}}} |
| 144 |
\DeclareOption{bigc}{\renewcommand*{\ES@croisint}{\ensuremath{\:}}} |
| 145 |
\ProcessOptions\relax |
| 146 |
% \end{macrocode} |
| 147 |
% |
| 148 |
%\subsection{Derivative} |
| 149 |
%Test of star version. |
| 150 |
% \begin{macrocode} |
| 151 |
\newcommand*{\diff}{} |
| 152 |
\def\diff{\@ifstar{\ES@diffstar}{\ES@diffnostar}} |
| 153 |
% \end{macrocode} |
| 154 |
%Star version. The subscript is given. |
| 155 |
% \begin{macrocode} |
| 156 |
\def\ES@diffstar{\@ifnextchar[{\ES@diffstar@i}{\ES@diffstar@ii}} |
| 157 |
% \end{macrocode} |
| 158 |
%The ordre is given in square brakets, and there is a subscript. |
| 159 |
% \begin{macrocode} |
| 160 |
\def\ES@diffstar@i[#1]#2#3#4{% |
| 161 |
\mathchoice{% |
| 162 |
\left(\frac{\ES@dop^{#1}\ES@difint#2}% |
| 163 |
{\ES@dop\ES@difint#3^{#1}}\right)_{\mkern-7mu#4}}% |
| 164 |
{\ES@taille{\left(\frac{\ES@dop^{#1}\ES@difint#2}% |
| 165 |
{\ES@dop\ES@difint#3^{#1}}\right)_{\mkern-7mu#4}}}% |
| 166 |
{\scriptstyle{\left(\frac{\ES@dop^{#1}\ES@difint#2}% |
| 167 |
{\ES@dop\ES@difint#3^{#1}}\right)_{\mkern-7mu#4}}}% |
| 168 |
{\scriptstyle{\left(\frac{\ES@dop^{#1}\ES@difint#2}% |
| 169 |
{\ES@dop\ES@difint#3^{#1}}\right)_{\mkern-7mu#4}}}} |
| 170 |
% \end{macrocode} |
| 171 |
%There is only a subscript. |
| 172 |
% \begin{macrocode} |
| 173 |
\def\ES@diffstar@ii#1#2#3{% |
| 174 |
\mathchoice{\left(\frac{\ES@dop\ES@difint#1}% |
| 175 |
{\ES@dop\ES@difint#2}\right)_{\mkern-7mu#3}}% |
| 176 |
{\ES@taille{\left(\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}% |
| 177 |
\right)_{\mkern-7mu#3}}}{\scriptstyle{\left(% |
| 178 |
\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}\right)% |
| 179 |
_{\mkern-7mu#3}}}% |
| 180 |
{\scriptstyle{\left(\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}\right)% |
| 181 |
_{\mkern-7mu#3}}}} |
| 182 |
% \end{macrocode} |
| 183 |
% |
| 184 |
%No star version (no subscript). |
| 185 |
% \begin{macrocode} |
| 186 |
\def\ES@diffnostar{\@ifnextchar[{\ES@diffnostar@i}{\ES@diffnostar@ii}} |
| 187 |
% \end{macrocode} |
| 188 |
%The ordre is given in square brackets. |
| 189 |
% \begin{macrocode} |
| 190 |
\def\ES@diffnostar@i[#1]#2#3{\mathchoice{\frac{\ES@dop^{#1}\ES@difint#2}% |
| 191 |
{\ES@dop\ES@difint#3^{#1}}}% |
| 192 |
{\ES@taille{\frac{\ES@dop^{#1}\ES@difint#2}{\ES@dop\ES@difint#3^{#1}}}}% |
| 193 |
{\scriptstyle{\frac{\ES@dop^{#1}\ES@difint#2}{\ES@dop\ES@difint#3^{#1}}}}% |
| 194 |
{\scriptstyle{\frac{\ES@dop^{#1}\ES@difint#2}{\ES@dop\ES@difint#3^{#1}}}}} |
| 195 |
% \end{macrocode} |
| 196 |
%Basic notation. |
| 197 |
% \begin{macrocode} |
| 198 |
\def\ES@diffnostar@ii#1#2{\mathchoice% |
| 199 |
{\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}}% |
| 200 |
{\ES@taille{\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}}}% |
| 201 |
{\scriptstyle{\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}}}% |
| 202 |
{\scriptstyle{\frac{\ES@dop\ES@difint#1}{\ES@dop\ES@difint#2}}}} |
| 203 |
% \end{macrocode} |
| 204 |
% |
| 205 |
%\subsection{Partial derivatives} |
| 206 |
%Test of the star version. |
| 207 |
% \begin{macrocode} |
| 208 |
\newcommand*{\diffp}{} |
| 209 |
\def\diffp{\@ifstar{\ES@diffpstar}{\ES@diffpnostar}} |
| 210 |
% \end{macrocode} |
| 211 |
%Star version: a subscript is given. |
| 212 |
% \begin{macrocode} |
| 213 |
\def\ES@diffpstar{\@ifnextchar[{\ES@diffpstar@i}{\ES@diffpstar@ii}} |
| 214 |
% \end{macrocode} |
| 215 |
%Ordre of derivative is given, and there is a subscript. |
| 216 |
% \begin{macrocode} |
| 217 |
\def\ES@diffpstar@i[#1]#2#3#4{% |
| 218 |
\mathchoice{\left(\frac{\partial^{#1}% |
| 219 |
\ES@derpint#2}{\partial\ER@derpint#3^{#1}}\right)_{\mkern-7mu#4}}% |
| 220 |
{\ES@taille{\left(\frac{\partial^{#1}\ES@derpint#2}{\partial\ES@derpint#3^{#1}}% |
| 221 |
\right)_{\mkern-7mu#4}}}% |
| 222 |
{\scriptstyle{\left(\frac{\partial^{#1}\ES@derpint#2}% |
| 223 |
{\partial\ES@derpint#3^{#1}}% |
| 224 |
\right)_{\mkern-7mu#4}}}% |
| 225 |
{\scriptstyle{\left(\frac{\partial^{#1}\ES@derpint#2}% |
| 226 |
{\partial\ES@derpint#3^{#1}}% |
| 227 |
\right)_{\mkern-7mu#4}}}} |
| 228 |
% \end{macrocode} |
| 229 |
%There is only a subscript. |
| 230 |
% \begin{macrocode} |
| 231 |
\def\ES@diffpstar@ii#1#2#3{\mathchoice{\left({\begingroup |
| 232 |
\toks0={}\count0=0 |
| 233 |
\ES@degree #2\ES@degree |
| 234 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 235 |
{\the\toks0}% |
| 236 |
\endgroup}\right)_{\mkern-7mu#3}}% |
| 237 |
{\ES@taille{\left({\begingroup |
| 238 |
\toks0={}\count0=0 |
| 239 |
\ES@degree #2\ES@degree |
| 240 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 241 |
{\the\toks0}% |
| 242 |
\endgroup}\right)_{\mkern-7mu#3}}}% |
| 243 |
{\scriptstyle{\left({\begingroup |
| 244 |
\toks0={}\count0=0 |
| 245 |
\ES@degree #2\ES@degree |
| 246 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 247 |
{\the\toks0}% |
| 248 |
\endgroup}\right)_{\mkern-7mu#3}}}% |
| 249 |
{\scriptstyle{\left({\begingroup |
| 250 |
\toks0={}\count0=0 |
| 251 |
\ES@degree #2\ES@degree |
| 252 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 253 |
{\the\toks0}% |
| 254 |
\endgroup}\right)_{\mkern-7mu#3}}}} |
| 255 |
% \end{macrocode} |
| 256 |
% |
| 257 |
%No star version (no subscript is given). |
| 258 |
% \begin{macrocode} |
| 259 |
\def\ES@diffpnostar{\@ifnextchar[{\ES@diffpnostar@i}{\ES@diffpnostar@ii}} |
| 260 |
% \end{macrocode} |
| 261 |
%The ordre of derivative is given. |
| 262 |
% \begin{macrocode} |
| 263 |
\def\ES@diffpnostar@i[#1]#2#3{% |
| 264 |
\mathchoice{\frac{\partial^{#1}\ES@derpint#2}% |
| 265 |
{\partial\ES@derpint#3^{#1}}}% |
| 266 |
{\ES@taille{\frac{\partial^{#1}\ES@derpint#2}{\partial\ES@derpint#3^{#1}}}}% |
| 267 |
{\scriptstyle{\frac{\partial^{#1}\ES@derpint#2}{\partial\ES@derpint#3^{#1}}}}% |
| 268 |
{\scriptstyle{\frac{\partial^{#1}\ES@derpint#2}{\partial\ES@derpint#3^{#1}}}}} |
| 269 |
% \end{macrocode} |
| 270 |
%Basic notation. |
| 271 |
% \begin{macrocode} |
| 272 |
\def\ES@diffpnostar@ii#1#2{\mathchoice{\begingroup |
| 273 |
\toks0={}\count0=0 |
| 274 |
\ES@degree #2\ES@degree |
| 275 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 276 |
{\the\toks0}% |
| 277 |
\endgroup}% |
| 278 |
{\ES@taille{\begingroup |
| 279 |
\toks0={}\count0=0 |
| 280 |
\ES@degree #2\ES@degree |
| 281 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 282 |
{\the\toks0}% |
| 283 |
\endgroup}}% |
| 284 |
{\scriptstyle{\begingroup |
| 285 |
\toks0={}\count0=0 |
| 286 |
\ES@degree #2\ES@degree |
| 287 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 288 |
{\the\toks0}% |
| 289 |
\endgroup}}% |
| 290 |
{\scriptstyle{\begingroup |
| 291 |
\toks0={}\count0=0 |
| 292 |
\ES@degree #2\ES@degree |
| 293 |
\frac{\partial\ifnum\count0>1^{\the\count0 }\fi\ES@derpint#1}% |
| 294 |
{\the\toks0}% |
| 295 |
\endgroup}}} |
| 296 |
% \end{macrocode} |
| 297 |
% |
| 298 |
%Macros used for crossed derivatives. |
| 299 |
% \begin{macrocode} |
| 300 |
\def\ES@degree #1{\ifx #1\ES@degree \expandafter\ES@stopd |
| 301 |
\else \expandafter\ES@addd \fi #1^1$#1\ES@addd} |
| 302 |
\def\ES@stopd #1\ES@addd{} |
| 303 |
\def\ES@addd #1^#2#3$#4\ES@addd{\advance\count0 #2 |
| 304 |
\toks0=\expandafter{\the\toks0% |
| 305 |
{\partial\ES@derpint #4}% |
| 306 |
\ES@croisint}\ES@degree} |
| 307 |
%</package> |
| 308 |
% \end{macrocode} |
| 309 |
%\Finale |