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