LaTeX Package for Differential Coefficients
LaTeX Package for Differential Coefficients
Andrew Parsloe
(ajparsloe@[Link])
diffcoeff is a LATEX package to ease the writing of ordinary, partial and other
derivatives of arbitrary algebraic or numeric order. For mixed partial deriva-
tives, the total order of differentiation is calculated by the package. Optional
arguments allow for points of evaluation (ordinary derivatives), or variables held
constant (partial derivatives), and the placement of the differentiand in numer-
ator or appended. Besides dx dy
, forms like dy/dx and ∂x y are also available, as
well as derivatives built from D, ∆, δ, and configurable jacobians and differ-
entials. Other notations like line elements (dx 2 + dy 2 + dz 2 ) and bra-kets are
easily produced.
Version 5 of diffcoeff more fully embraces the configurability offered by
xtemplate than earlier versions. Some incompatibilities have arisen, but all is
not lost: version 4 is still available with the command
\usepackage[<options>]{diffcoeff}[=v4]
For users of version 4
The \diff and \diffp commands of version 4 of diffcoeff remain, but lack
the ‘spacing switch’ ! (which on reflection was a mistake) and, more noticeably,
the ‘slash switch’ /. Slash-fraction derivatives are now created with the \difs
and \difsp commands. New commands \difc and \difcp produce derivatives
in ‘compact notation’ like dx y and ∂x y. The order-override option (for mixed
partial derivatives) has been changed to use angle brackets (for clarity) or a
command \difoverride. The sequential order of differentiand and variable(s)
of differentiation can now be reversed, when the differentiand is appended, by
using a second star, e.g., \diffp**. The two-argument \diffdef command of
earlier versions has been replaced by the three-argument command \difdef,
the additional argument determining which one or more of the f, s, c, fp, sp
or cp forms the defined variant applies to. The differential command \dl has
been rewritten and is now fully template-configurable (allowing easy writing of
line elements like dx 2 + dy 2 + dz 2 ), and the jacobian command \jacob is also
configurable. Indeed version 5 of diffcoeff more fully embraces the configura-
bility offered by the xtemplate package than previous versions, bringing other
notations – like those of the braket package – within its compass.
ISO defaults
The ISO package option is redundant. Unlike the default set-up in version 4,
the defaults in version 5 of diffcoeff are chosen to reflect ISO recommenda-
tions (see the standard ISO 80000-2). In particular this means upright ‘d’s and
subscripted parentheses enclosing a derivative to indicate a point of evaluation.
This document is written with those defaults. For those (like the author) who
prefer math-italic ‘d’s and a subscripted vertical rule to indicate a point of eval-
uation, the means of creating ‘variant forms’ or changing the defaults is readily
available; see §§3.3, 3.4.
1
Contents
1 Introduction 4
1.1 Package options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 A Rogues’ Gallery of derivatives . . . . . . . . . . . . . . . . . . 6
2
3.2.4 Partial derivatives; templates DIFFP, DIFSP, DIFCP . . . . 34
3.3 Variant forms: the \difdef command . . . . . . . . . . . . . . . 34
3.3.1 The .def file . . . . . . . . . . . . . . . . . . . . . . . . . 35
[Link] Log file message . . . . . . . . . . . . . . . . . . 36
3.3.2 Examples of variants . . . . . . . . . . . . . . . . . . . . . 36
[Link] Editing variant forms . . . . . . . . . . . . . . . 38
[Link] Parenthesizing multi-token variables . . . . . . . 38
[Link] Point of evaluation . . . . . . . . . . . . . . . . . 39
[Link] Upright text-style derivatives . . . . . . . . . . . 40
[Link] Slash-fraction styles . . . . . . . . . . . . . . . . 41
[Link] Compact–form derivatives . . . . . . . . . . . . 42
[Link] D, \delta, \Delta derivatives . . . . . . . . . . . 42
3.3.3 Other notations . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4 Defaults: setting your own . . . . . . . . . . . . . . . . . . . . . . 44
3.4.1 Changing defaults in DIF . . . . . . . . . . . . . . . . . . 45
5 Reference 55
5.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.2 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.2.1 DIF (primogenitor) . . . . . . . . . . . . . . . . . . . . . . 57
5.2.2 DIFF (upright-fraction derivative) . . . . . . . . . . . . . . 57
[Link] DIFFP . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2.3 DIFS (slash-fraction derivative) . . . . . . . . . . . . . . . 58
[Link] DIFSP . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2.4 DIFC (compact derivative) . . . . . . . . . . . . . . . . . . 59
[Link] DIFCP . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2.5 DIFJ (jacobian) . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2.6 DIFL (differential) . . . . . . . . . . . . . . . . . . . . . . 60
5.3 The file [Link] . . . . . . . . . . . . . . . . . . . . . . 60
5.4 Preamble definitions . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.5 \DeclareChildTemplate . . . . . . . . . . . . . . . . . . . . . . 65
5.6 Version history . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3
Chapter 1
Introduction
in the preamble of your document or, if package options are being used,1
\usepackage[<options>]{diffcoeff}
The interface of diffcoeff with version 5 has changed from earlier versions. If
you want the familiar behaviour of version 4, add to these commands a trailing
optional argument like this,
\usepackage[<options>]{diffcoeff}[=v4]
(with no space after the ‘=’ sign!). Of course you will not get the new features of
version 5. Working with version 4 is described in the document [Link].
(a) spaced=1 inserts a small space before the differentiand; this is the
default so that entering spaced is equivalent to spaced=1;
1 Angle brackets indicate possible user input (without the angle brackets).
4
(b) spaced=0 inserts no space before the differentiand; diffcoeff is ini-
tialized to spaced=0 so that if the spaced option is not used spaced=0
is assumed;
(c) spaced=-1 inserts a small space before the differentiand if it contains
more than one token, and no space otherwise. The present document
uses spaced=-1.
This option is discussed in §2.2.1.
2. For the second package option, by entering mleftright in the options list
the command \mleftright is automatically inserted in the preamble. The
effect is to change all occurrences of \left, \right in the document to
\mleft, \mright so that the spacing around scalable delimiters modified
by \left, \right is reduced; see the box below and §[Link]. The present
document does not use this package option.
3. The third package option requires the <filename> of a file with extension
.def, <filename>.def, containing definitions of variant forms of deriva-
tive (see §3.3):
\usepackage[def-file=<filename>]{diffcoeff}
This is discussed in §3.3.1. The present document uses the package option
def-file=diffcoeff5.
in which there is significant whitespace before and after the parentheses. The
package mleftright enables this whitespace to be reduced by using \mleft,
\mright in place of \left, \right:
\[ \ln \mleft(\frac xy\mright),\quad\sin\mleft(x^2\mright). \] =⇒
x
ln , sin x2 .
y
5
If you put \mleftright in the preamble, which is what the mleftright pack-
age option does, then all occurrences of \left, \right in the document will
be affected. \left, \right can be restored to their normal behaviour by the
command \mleftrightrestore. Rather than use \mleft, \mright explicitly,
as in the example, the same effect can be obtained by using \left, \right and
preceding the expression with the command \mleftright:
\mleftright
\[ \ln \left(\frac xy\right),\quad\sin \left(x^2\right). \]
\mleftrightrestore
=⇒
x
ln sin x2 .
,
y
d2 ϕ du
β
∂ϕ ∂b
, , , . (1.3)
∂ε ε=ε0 dε 2 ε=ε0 ∂aα b=0 dv v=0
6
ISO 80000-2 (item 2.11.13) favours the last of these – parentheses – for
ordinary derivatives. Presumably, partial derivatives should follow suit,
although parentheses are also used to indicate variables held constant:
∂ P ∂S
, , (∂S/∂T )V . (1.4)
∂U T V ∂N2 U,V,N1
Dx2 y + 2Dx y − 4 = 0.
• When the differentiand is too big or awkward to sit in the numerator and is
appended to the operator, the d or ∂ in the numerator is generally centred
– but not always. In texts prior to the age of computerised typesetting
one will sometimes find the symbol pushed to the left:
∗
!
∂ ∂ xi d mqx
, . (1.7)
∂xl∗ ∂xk∗ dt 1 − q2
p
The keen-eyed will note an italic adjustment with the first expression, so
that the ∂s in the numerators are indented a little (to line up – more or
less – in a slanting column with the ∂s in the denominators).
• Then there is the case when the operator in the numerator differs from
that in the denominator. For instance, in tensor calculus acceleration is
sometimes written
∇ vi d vi d yk
= + Γkih v h
dt dt dt
where ∇v i is the ‘absolute differential’ of the velocity v i .
The diffcoeff package has the generative power to cope with all these varia-
tions – see §3.3 – although it is unlikely an author should need to call on this
capacity to anything like the extent required for this Rogues’ Gallery.
7
Chapter 2
diffcoeff aims to ease the writing of derivatives (sometimes also called dif-
ferential coefficients). There are long-established shorthands available in a few
cases: ẋ and ẍ for the time derivatives of a function x of time t; y ′ and y ′′
for the derivatives of a function y (usually) of x. But mostly derivatives are
expressed in fraction form and require more keystrokes to compose. It is here
that diffcoeff is aimed. It uses three pairs of commands: \diff and \diffp
to write (upright) fraction forms of ordinary and partial derivatives like dx , ∂x ,
dy ∂y
generally intended for display-style environments; \difs and \difsp for slash-
fraction forms of ordinary and partial derivatives like dy/dx, ∂y/∂x, generally
intended for text-style environments; and \difc and \difcp to write compact
forms of ordinary and partial derivatives like dx y and ∂x y. (Of these, the ‘s’
forms replace the slash argument for the \diff, \diffp commands in version 4
of diffcoeff, and the ‘c’ form is new to version 5.1 )
Note
I refer throughout to the quantity or function being differentiated as the differ-
entiand or derivand (in line with integrand, operand, etc.) and shall sometimes
use \difx (resp. \difxp) to make general statements about any or all of \diff,
\difs or \difc (resp.\diffp, \difsp, \difcp).
2.1 Syntax
All commands, \difx, \difxp, share the same syntax. With options present
the syntax is
\[Link].*[order-spec]<override>{differentiand}
{variable(s)}[pt of eval]
1 Suggested by a question on T X StackExchange: [Link]
E
questions/652223/write-a-derivative-operator-without-denominator-using-diffcoef/
652298#652298
8
\[Link].**[order-spec]<override>{variable(s)}
{differentiand}[pt of eval]
The syntax is identical for \difxp. The seven arguments have the following
meanings:
Both mandatory arguments may be empty, but require empty brace pairs to in-
dicate as much. (Omitting the differentiand makes sense for all forms of deriva-
tive, \difx, \difxp, but omitting the variable or variables of differentiation is
sensible only for the compact forms, \difc, \difcp – see §[Link].)
9
in display style (placed, for instance, between \[ \] ). In fact \diff yx (omit-
ting the braces) will produce these results, with a saving on keystrokes. The
braces are needed only when an argument – the variable of differentiation, or
the differentiand – is multi-token:
\[ \diff{\ln x}x \] =⇒
d ln x
dx
• If you want math-italic ‘d’s as default, see §3.4 on changing default set-
tings. As noted earlier, upright ‘d’s conform to the standard ISO 80000-2
and are used in this document.
For inclusion in a line of text you might prefer to use a slash-fraction form of
derivative. That is achieved with the \difs command: $ \difs yx $ produces
dy/dx. If you want still more compactness, you can use the \difc (‘c’ for
compact) command: $ \difc yx $ produces the form dx y.
Partial derivatives follow the same pattern as ordinary derivatives. The
commands this time are \diffp, \difsp and \difcp for (upright) fraction,
slash fraction and compact forms of partial derivative. Thus \diffp{F}{x}, or
\diffp Fx with a saving on keystrokes, produce ∂F ∂x in text style and
∂F
∂x
in display style. (As for \diff, the omission of braces is possible when deal-
ing with a single-token differentiand or differentiation variable.) For inline
use, \difsp Fx, displays as ∂F /∂x and \difcp displays as ∂x F . Given that
\partial takes 8 keystrokes to type, all forms economise on keystrokes.
We write
dy
dx
for the limit of δx
δy
. It is natural following this line of argument to think of dy
and dx as tiny lengths, like δy and δx, in which case it would be quite wrong to
insert space between the d and the y (let alone the d and the x). dy is a single
object, called a differential, and we write expressions like
dy
dy = dx
dx
10
and justly call the fraction in this expression a differential coefficient.
But there is another way of viewing differentiation: as a process producing
(or deriving) one function, y ′ (x), from another, y(x). Here the sense is of
applying dx
d
to a quite separate object, the function y(x). Although we include
y(x) in the numerator it is distinct from the d and should be separated from it
by a small space:2
d y(x)
y ′ (x) = .
dx
Here the fraction on the right is another name for the derived function y ′
and is justly called the derivative of y. As you can see a small space has
been inserted between the d and the y in the numerator. By default the
space is 3 mu but with the ability to stretch by 1 mu or shrink by 2 mu –
3 mu plus 1 mu minus 2 mu in TEX-speak3 – as TEX adjusts lines to fit on
the page. (A ‘mu’ is a ‘math unit’ and is one eighteenth of a quad.) The size of
the space inserted by default can be easily changed; see §3.3 and §3.4.
• You may want all or most of your derivatives to have this space before
the derivand. The spaced=1 package option switches this behaviour on.
However, I have used the spaced=-1 option for the present document
which inserts space only if the derivand contains more than one token.
Thus y(x) will have space inserted before it, but y alone will not. This (I
think) maintains the distinction between a differential coefficient, thought
of as a ratio of tiny lengths, and a derivative, thought of as an operator
applied to a function. spaced=0 inserts no space before the derivand.
• In version 4 of diffcoeff an argument was added to the \diff command
to manually introduce a space (the ! switch) before the differentiand. This
was a mistake and has been removed. If you wish to adjust the spacing,
there are plenty of (short) commands in LATEX and diffcoeff to do the
job; see immediately below, §[Link].
Slash-form derivatives also allow space before the derivand. By default this
is 2 mu plus 1 mu minus 2 mu, slightly reduced from the fraction-form value
to avoid visually detaching the initial ‘d’ operator from the derivative as a
whole. The value can be changed; see §3.3 and §3.4. For the present document,
with spaced=-1, multi-token derivands have the space inserted, single-token
derivands do not:
$ \difs{\ln\sin x}x, \quad \difs st $ =⇒ d ln sin x/dx, ds/dt.
For compact-form derivatives the space before the derivand is always inserted,
irrespective of the setting of the spaced package option, since the subscript pre-
cludes the entire symbol ever being viewed as a differential – it is always an oper-
ator operating on a function. The inserted space, 1 mu plus 1 mu minus 1 mu
by default, can be changed should you wish; see §3.3 and §3.4:
2 I thank Hans Schülein for first raising this issue with me and for subsequent thoughtful
comments.
3 Or even 3muplus1muminus2mu.
11
$ \difc{\ln\sin x}x, \quad \difc st $ =⇒ dx ln sin x, dt s.
(The space is less for compact forms since the subscript already provides some
visual separation.) The spaced package option has the same effects on partial
derivatives. Thus with spaced=1 or spaced=-1, 3 mu plus 1 mu minus 2 mu
of space is inserted before the differentiand F(x,y) in the first member of the
following example, space of 2 mu plus 1 mu minus 2 mu in the second, and
space of 1 mu plus 1 mu minus 1 mu in the third:
\[ \diffp{F(x,y)}x,\;\difsp{F(x,y)}x,\;\difcp{F(x,y)x, \]
=⇒
∂ F (x, y)
, ∂ F (x, y)/∂x, ∂x F (x, y).
∂x
But for single-token differentiands in this document the space is not inserted for
upright and slash-form derivatives:
∂F
, ∂F /∂x.
∂x
If you always want the space present, use spaced=1; if you never want the space
for upright- or slash-form derivatives, or wish to insert such space always ‘by
hand’, use spaced=0.
12
\[ \diff[2]yx, \quad \diff[n+1]yx. \] =⇒
d2 y dn+1 y
, .
dx 2 dx n+1
As mentioned, the braces can be and have been omitted around the x and y
since they are single tokens. The square brackets around the optional order-of-
differentiation argument are essential. In slash form,
$ \difs[2]yx, \quad \difs[n+1]yx $ =⇒ d2 y/dx 2 , dn+1 y/dx n+1 ,
For partial derivatives when differentiating in only one variable the pattern is
the same:
\[ \diffp[2]yx, \quad \diffp[n+1]yx. \] =⇒
∂ 2y ∂ n+1 y
, .
∂x 2 ∂x n+1
For the slash forms,
$ \difsp[2]yx,\quad \difsp[n+1]yx $ =⇒ ∂ 2 y/∂x 2 , ∂ n+1 y/∂x n+1 .
∂ 2y ∂ n+1 y
, .
∂x 2 ∂x n+1
A colon separates the variable from its order of differentiation. This is more
relevant when there is more than one variable subject to different orders of
differentiation – so-called mixed partial derivatives.
13
2.2.3 Appending the differentiand
Some differentiands are too big or awkward to be placed neatly in the numerator
of a derivative and it is natural to append them to a preceding differential op-
erator. One could leave the numerator argument empty in the \diff or \diffp
command and follow the command with the differentiand, but diffcoeff offers
a better way: star the \diff or \diffp command. This tells diffcoeff to
append the differentiand. Thus suppose the differentiand is a polynomial, say
ax2 + bx + c. Add a star (an asterisk) to the \diff command:
\[ \diff*{(ax^2+bx+c)}x \] =⇒
d
(ax2 + bx + c).
dx
Or, for a partial derivative, one might want to indicate in the differentiand all
the variables on which it depends:
\[ \diffp*[2]{\Phi(x,y,z)}x \] =⇒
∂2
Φ(x, y, z).
∂x 2
A virtue of using an asterisk to append the differentiand is that if one isn’t sure
whether to append or not, it is an easy matter to simply insert or delete the
asterisk to compare the results.
For instance, a second derivative is an iterated derivative – one in which a
derivative forms the differentiand of another . Thus
\[ \diff[2]yx = \diff*{\diff yx}x \] =⇒
d2 y d dy
= .
dx 2 dx dx
This result is more elegant to my eye than what results when removing the
asterisk,
d2 y d ddxy
= ,
dx 2 dx
although whether the meaning is clearer is moot.
Since the differentiand is appended by default in compact-form derivatives,
starring such a derivative has no effect other than when a second asterisk is used
to transpose the order of arguments.
14
[Link] Transposing the argument order
If a second asterisk follows the first, the order of the arguments specifying the
differentiand on the one hand and variable or variables of differentiation on the
other are reversed. Thus it is clearer to the eye to write
\[ \diff**x{(ax^2+bxy+cy^2)} \] =⇒
d
(ax2 + bxy + cy 2 )
dx
than \[ \diff*{(ax^2+bxy+cy^2)}x \], where the eye has to search for the
variable of differentiation. This is especially the case if the differentiand contains
more than one variable and includes commands like \frac or \sqrt requiring
braced arguments:
\[ \diffp**x{\frac1{\sqrt{x^2-y^2}}} \] =⇒
∂ 1
p
∂x x − y 2
2
∂x y, ∂x y, ∂y x
dx 2 0
15
Note that there must be no space before the left square bracket of the trailing
argument, otherwise it will be treated as part of the wider mathematical ex-
pression of which the derivative is part and typeset as such. (This should not
cause a LATEX error.)
• If you prefer to use subscripted square brackets
∂ F (x, y)
∂x (0,0)
to indicate a point of evaluation, then this can easily be done; see specif-
ically §[Link] (or §3.4 on changing default settings). Parentheses are the
ISO recommendation; see ISO 80000-2.
Because the slash form spreads the derivative out horizontally, parentheses are
the natural way in this case to indicate a point of evaluation:
$ \difs{\ln sin x}{sin x}[x=\pi/3] $ =⇒ (d ln sin x/d sin x)x=π/3 .
A vertical rule can easily become too remote from the opening d of the differ-
ential coefficient: d ln sin x/d sin x|x=π/3 . Parentheses tie the whole cluster of
symbols together.
One reason to query the ISO preference for subscripted parentheses to indi-
cate a point of evaluation is that subscripted parentheses are used with partial
derivatives to indicate variables held constant. This occurs frequently in thermo-
dynamics for example. In the following well-known relation in thermodynamics,
the differentiands are appended and the trailing argument is used to indicate
the variables held constant:
\[ \diffp*{\frac PT}U[V] = \diffp*{\frac 1T}V[U] \] =⇒
∂ 1
∂ P
= .
∂U T V ∂V T U
This is much easier to write than building the expressions ‘by hand’, starting
with \left( and finishing with _U.
[Link] Superscripts
It is easy to add a superscript to a derivative to indicate evaluation at two points
and the difference between the values:
\[ \diff {\sin x}x[0]^{\mkern-10mu\pi/2} \] =⇒
π/2
d sin x
dx 0
16
but to my eye either square brackets or a vertical rule are clearer for this purpose
(and do not involve nudging the subscript or superscript closer to the right
delimiter); see §3.3.
d ∂L
∂L
− = 0.
∂qk dt ∂ q̇k
(See §[Link] for the double asterisk.) Like the author, you may feel that there is
too much whitespace between dt d
and the left parenthesis in this expression. One
obvious remedy is to insert a negative thin space \! before the second \diffp
command. Another is to use the package mleftright.
=⇒
d
∂L ∂L
− = 0.
∂qk dt ∂ q̇k
which is better, but better still to my eye is to also add a negative thin space
\! before the second \diffp command:
17
\mleftright
\[ \diffp L{q_k}-\diff**t{ \!\diffp L{\dot{q}_k}[] } = 0 \]
=⇒
d ∂L
∂L
− = 0.
∂qk dt ∂ q̇k
The problem is that in addition to the space around \left, \right pairs (which
is reduced by issuing the command \mleftright), there is also the space in-
serted by diffcoeff before a multi-token differentiand. The user should be
aware of this, and may wish to define a ‘variant form’ (see §3.3) that introduces
no space before an appended differentiand.
18
Notice that the overall order of the derivative – 6 – in the first of these is again
automatically calculated and inserted as a superscript on the ∂ symbol in the
numerator.
In the example, the comma list of orders has only two members, although
there are three variables. It is assumed that the orders given in the comma
list apply in sequence to the variables, the first order to the first variable, the
second to the second variable, and so on, and that any subsequent orders not
listed in the optional argument are, by default, 1. Thus we need to specify
only 2 and 3 in the example; the order of differentiation of z is 1 by default.
But you cannot use an order specification like [,,2]; instead write [1,1,2]
(which is the natural thing to do in any case). It is only the tail of an order
specification which can be omitted. In the other direction, if there are more
orders of differentiation specified than there are variables, the list of orders is
truncated to match the number of variables.
∂ 3m+2 F
∂x 2m−1 ∂y m+1 ∂z 2
The total order of differentiation is still calculated by diffcoeff. Or again,
\[ \diffp[1,km+1,m+k-1]{F(x,y,z)}{x,y,z} \] =⇒
∂ m+k+km+1 F (x, y, z)
.
∂x ∂y km+1 ∂z m+k−1
\[ \diffp{F(x,y,z)}{x,y:km+1,z:m+k-1} \] =⇒
∂ m+k+km+1 F (x, y, z)
.
∂x ∂y km+1 ∂z m+k−1
In the example, note that it suffices to write x rather than x:1.
If, in a fit of absent-mindedness, one specifies the orders of differentiation by
both methods, it is the orders in the variable argument that prevail:
4I thank Christophe Bal for this suggestion.
19
\[ \diffp[1,2,3]{F(x,y,z)}{x:4,y:5,z:6} \] =⇒
∂ 15 F (x, y, z)
∂x 4 ∂y 5 ∂z 6
\[ \diffp<(k+1)(m+1)>{F(x,y,z)}{x,y:km+1,z:m+k-1}. \]
=⇒
∂ (k+1)(m+1) F (x, y, z)
.
∂x ∂y km+1 ∂z m+k−1
When the override option is used, the algorithm that calculates the total
order is sidestepped. It does not get called at all. In this way not only can the
total order be presented in whatever manner one wishes but essentially arbitrary
material can be attached as a superscript to the ∂ symbol in the numerator.
(For compact-form derivatives, which do not use a total order of differentiation,
the override option is irrelevant.)
brackets.
20
=⇒
∂ (k+1)(m+1) F (x, y, z) ∂ m+k+km+1 F (x, y, z)
,
∂x ∂y km+1 ∂z m+k−1 ∂x ∂y km+1 ∂z m+k−1
Note that in the example \difoverride has been used within the math envi-
ronment. This is good practice. It prevents the contents of the command erro-
neously overriding the orders of later derivatives in other math environments;
but it does mean cancelling the override (with the statement \diffoverride{})
in this environment if a second derivative is present, to prevent the second
derivative also displaying the factorized form.
[Link] Parentheses
Auto-calculation of the total order accommodates the simple use of parentheses:
\[ \diffp[2m-(k+1),2(k+1)-m]{F(x,y,z)}{x,y,z} \] =⇒
∂ m+k+2 F (x, y, z)
∂x 2m−(k+1) ∂y 2(k+1)−m ∂z
This is an example of the use of dynamic parentheses: the left parenthesis in
each case is preceded by a number or a sign. In evaluating the total order
diffcoeff multiplies out the expression (or that is the effect).
On the other hand, an order specification like [f(n+1),f(n-1)] is an exam-
ple of the use of static parentheses where they are part of the familiar ‘function
of’ notation – in this case a function f of some variable, say x, evaluated at
x = n ± 1. diffcoeff always interprets a left parenthesis preceded by some-
thing that is neither number nor sign in this way. It does not try to multiply
out such expressions when calculating the total order.
The following example combines both uses – and includes a nested pair of
(dynamic) parentheses:
\[\diffp[2(f(n)-(m-1)),5-(f(n)+m)]F{x,y}\] =⇒
∂ 7−3m+f (n) F
∂x 2(f (n)−(m−1)) ∂y 5−(f (n)+m)
Where confusion arises is with specifications like [m(k-1)+1,m(k+1)-1] where
m could be interpreted as either a function or a variable. As stated, diffcoeff
always interprets a left parenthesis preceded by something that is not a number
or a sign as signalling ‘function of’. Hence:
\[\diffp[m(k-1)+1,m(k+1)-1]F{x,y}\] =⇒
∂ m(k−1)+m(k+1) F
∂x m(k−1)+1 ∂y m(k+1)−1
If, in fact, m is intended as a variable then the order-override option or command
is there to rescue the situation:
21
\[ \diffp<2mk>F{x:m(k-1)+1,y:m(k+1)-1} \]
=⇒
∂ 2mk F
∂x m(k−1)+1 ∂y m(k+1)−1
22
to write the minimal {xy} rather than {x,y} when two variables x and y are in-
volved, the extra writing is trivial and the comma list allows a simpler handling
of multi-character variables. For instance in tensor calculus we get expressions
like
\[ \diffp{A_i}{x^j,x^k} \] =⇒
∂ 2 Ai
.
∂xj ∂xk
It is easier to write {x^j,x^k} here than, say, {{x^j}{x^k}} to distinguish
the variables. It’s also easier to read, particularly if the indices themselves get
ornamented and need surrounding braces:
\[ \diffp{A_i}{x^{j’},x^{k’}} \] =⇒
∂ 2 Ai
.
∂xj ′ ∂xk′
Compare that variable specification with {{x^{j’}}{x^{k’}}}. Admittedly
some extra whitespace would help here, but the point stands: the comma list
requires fewer nested braces – unless a variable of differentiation includes a
comma, for then the comma needs to be enclosed in braces. There are plenty
of instances of this out in the world (see, e.g., the last equation of (1.1)) but it
is overall a rare occurrence.
23
When the variables themselves are super- or subscripted, as happens in ten-
sor calculus, no automatic adjustment is made. Any fine-tuning must be done
by the user using explicit spacing commands – like \negmu (a space of -1 mu);
see §[Link]:
\[ \diffp{A_i}{ x^j\negmu,x^k } \] =⇒
∂ 2 Ai
.
∂xj ∂xk
The \negmu decreases the spacing between the terms from the default 2 mu
(with stretch and shrink) to 1 mu.
24
outer pair of parentheses then seems too fussy and detracts from comprehending
the symbol ‘at a glance’:
d2 f (x)
2.
(d(x/k))
Customary but illogical notations are familiar in mathematics – think of the
position of the superscripts in an identity like sin2 θ + cos2 θ = 1. In any case,
the manner of this wrapping in parentheses – if any – of long variables for higher
order derivatives is customisable (§3.4).
For first order derivatives parenthesizing does not occur automatically. If
you want the variable of differentiation to be parenthesized, you need to do it
yourself:
d f (x) d f (x)
, .
dx/k d(x/k)
∂ 2q
.
1 2
∂ Θ
∂ 2q
.
1
∂( Θ ) ∂V
25
Chapter 3
in version 4 of diffcoeff.
2 And – see Chapter 4 – of the differential and jacobian commands, \dl and \jacob.
26
Table 3.1: Template inheritance
DIF
↙ $ ↓ % ↘
DIFC DIFS DIFF DIFJ DIFL
↓ ↓ ↓
DIFCP DIFSP DIFFP
from these child templates children of their own (grandchild templates) in which
again some further defaults are adjusted.
In diffcoeff, the template that is the ‘primogenitor’ of the lines of default
inheritance is named DIF. It is the repository of all possible keys used in all
possible forms of derivative (at least in diffcoeff!) and so has keys appropriate
to upright-fraction, slash-fraction and compact forms of derivative; it has keys
appropriate to multi-variable partial derivatives and single-variable ordinary
derivatives, but it is not actually used to form derivatives. That is the role of
its child templates DIFF, DIFS and DIFC corresponding to derivatives of upright-
fraction, slash-fraction and compact forms. These child templates inherit the
defaults of DIF save for some settings explicitly changed in the child template
relevant to the specific forms of fraction specified by each.
Apart from the operator symbol, most of the settings in the child templates
DIFF, DIFS and DIFC are also appropriate for partial derivatives. From a code
design point of view, there is a certain neatness at not multiplying the number of
templates in play, but actual use – for instance, forming the ‘Rogues’ gallery’ of
§1.2 – suggests the further step of creating additional templates specifically for
partial derivatives in the three fraction forms. Apart from the operator symbol,
the templates DIFFP, DIFSP and DIFCP inherit nearly all the defaults of their
parents DIFF, DIFS and DIFC respectively.
Again, actual use suggests two further templates, both direct children of DIF,
for the creation of jacobians, template DIFJ, and differentials, template DIFL,
with default values appropriate to each. In all diffcoeff uses nine templates,
the arrows in Table 3.2 indicating lines of inheritance of default values. Only
the child and grandchild templates of DIF are used for actual construction of
derivatives (and jacobians and differentials). DIF itself ‘sits above the fray’.
27
3. ordinary compact-form derivatives in text-style environments
The first column in table 3.2 lists key names, the second column default
values, and the third column to which form or forms of derivative the key is
relevant – meaning that assigning a different value to the key can change the
appearance of the corresponding derivative in some way. The identifiers have
these meanings:
f, fp upright fraction ordinary derivative, partial derivative;
s, sp slash fraction ordinary derivative, partial derivative;
c, cp compact ordinary derivative, partial derivative;
j jacobian;
l differential.
In Table 3.2 and following tables, all values specifying a space require the unit
(mu) to be included; a number alone does not suffice. (A ‘mu’ is a ‘math unit’,
1/18 of a quad. A thin space \, is 3 mu.) ‘Elastic’ spaces with stretch and shrink
can be compacted, like 3muplus1muminus2mu for 3 mu plus 1 mu minus 2 mu.
Available keys and their defaults are the following (if you are dissatisfied
with some choices, they can be changed; see the discussion at §3.4):
28
Table 3.2: DIF defaults
29
– / forms the slash fraction with /, not scalable
– auto forms the slash fraction with \left. \middle/ \right.,
scalable
– big, Big, bigg and Bigg form the slash fraction with \big/,
\Big/, \bigg/ and \Bigg/ respectively, not scalable
– default in templates DIFS, DIFSP = /
• for compact-form derivatives, \difc, \difcp, and differentials, a
choice of _ or dl or d^
– _ forms derivatives of compact form like dx y, ∂x ∂y2 z
– d^ is a synonym for _
– dl forms differentials like dx and ∂x 2 ∂y∂z
– default in templates DIFC, DIFCP = _
• overall default in template DIF = frac
slash-tok token or tokens used for the slash fraction; (see §3.3.3 for a different
assignment) default /
slash-sep space inserted on either side of the slash-tok; default 0 mu
derivand-sep horizontal space added before the differentiand if the spaced
package option is set to 1, or before a multi-tokened differentiand if the
spaced package option is set to -1; note that compact-form derivatives al-
ways have this space inserted; default (appropriate for an upright-fraction
derivative) = 3mu plus 1mu minus 2mu
op-symbol the operator symbol; for ordinary derivatives generally one of d or
\mathrm{d}, for partial derivatives \partial; default = \mathrm{d}
op-symbol-alt if different from op-symbol then used in the denominator of
a fraction-form derivative while op-symbol is used in the numerator; e.g.
i
for the acceleration ∇dtv , op-symbol = \nabla and op-symbol-alt = d;
defaults to op-symbol default
op-order-nudge extra horizontal space added between the op-symbol and the
superscripted order of differentiation in higher order derivatives; for math-
italic forms compare d2 with d 2 , ∂ 2 with ∂ 2 where the first symbol in each
case has no extra space and the second has an extra 1 mu; since op-
symbol defaults to an upright ‘d’, default = 0 mu
var-sup-nudge extra horizontal space added between a variable in the de-
nominator of a derivative and the superscripted order of differentiation in
higher order derivatives (cf op-order-nudge); default = 1 mu
multi-term-sep horizontal spacing inserted between the differentials in, for
example, the denominator of a mixed partial derivative to avoid a solid
cluster like ∂x∂y∂z; with the default 2 mu this is spread a little, ∂x∂y∂z;
default = 2 mu plus 1 mu minus 1 mu
30
term-sep-adjust adjustment (usually a reduction) to multi-term-sep when
differentiation in a variable occurs to an order other than 1; if, e.g.,
∂x 2 ∂y∂z is the denominator of a mixed partial derivative in three vari-
ables, because of the superscript the spacing between ∂x2 and ∂y is re-
duced by term-sep-adjust from the spacing between ∂y and ∂z; default
= -1 mu
long-var-wrap to avoid ambiguity in higher order derivatives it may aid clarity
to wrap multi-token variables of differentiation in parentheses; the choices
are
2
dv no wrapping, e.g. dx2i or ∂ Θ
1
,
d(v) wrap the variable only, e.g. d(xi )2 or ∂( Θ ) ,
1 2
default = d(v)
lvwrap-Ldelim left delimiter when wrapping a long variable in a higher order
derivative; also applies to the left delimiter used in a jacobian; default =
\mleft (
lvwrap-Rdelim right delimiter when wrapping a long variable in a higher
order derivative; also applies to the right delimiter used in a jacobian;
default = \mright )
lvwrap-sup-nudge horizontal adjustment to the superscript position when a
multi-token variable is wrapped in (e.g.) parentheses and its order of
differentiation is not 1; default = -2 mu
outer-Ldelim the left member of a delimiter pair wrapping the derivative, the
right member of which is subscripted to indicate a point of evaluation or
variables held constant; ISO recommends parentheses for this purpose,
hence default = \left (
outer-Rdelim the right member of a delimiter pair wrapping the derivative
and subscripted to indicate a point of evaluation or variables held constant;
ISO recommends parentheses for this purpose, hence default = \right )
elbowroom adjustment to the whitespace between outer-Ldelim, outer-
Rdelim and the enclosed derivative; negative values reduce the space;
default = 0 mu
sub-nudge horizontal adjustment of the subscript’s placing relative to the
outer-Rdelimiter for a point of evaluation or variable held constant; a
negative value compensates for the curving inwards of a large right paren-
thesis; default = -5 mu
op-sub-nudge horizontal adjustment of the position of the subscript in deriva-
tives of compact form relative to the operator; since \mathrm{d} is the
default operator, default = 0 mu
31
*derivand-sep when the derivand is appended, horizontal space added before
the differentiand (derivand) depending on the setting of the spaced pack-
age option; default = derivand-sep default
*op-set-left a choice of true or false indicating whether the op-symbol is left-
aligned or not when the differentiand is appended; generally it is centred;
applies only to upright-fraction forms of the derivative; default = false
*italic-nudge if *op-set-left is true, makes an italic adjustment in the nu-
merator, so that the op-symbols in numerator and denominator align in
the same slanting column; for d or \partial an appropriate value might
be 3 mu; because of the default \mathrm{d}, default = 0 mu
32
Table 3.3: Defaults differing from the parent template
The \diff command uses the values in the DIFF template to form an upright-
fraction derivative. Only keys with an ‘f’ in the third column of Table 3.2 are
used in this process. Keys without an ‘f’ play no part in the process and their
default values are ignored. See §5.2.2 for the complete list of relevant DIFF
defaults.
33
3.2.4 Partial derivatives; templates DIFFP, DIFSP, DIFCP
The default values given in the tables so far apply to ordinary derivatives. For
partial derivatives, only a few defaults change. These are listed in Tables 3.3c,
3.3d. All other keys take the default values of the respective parent templates,
DIFF, DIFS and DIFC.
34
This defines a variant, with name p, of an ordinary upright-fraction derivative
(the f in the first argument) that displays as a partial derivative. To use the
variant simply append the name, as a dot-delimited argument, to the \diff
command. For instance, repeating an earlier example from thermodynamics,
\[ \diff.p.*{\frac PT}U[V] = \diff.p.*{\frac 1T}V[U] \] =⇒
∂ 1
∂ P
=
∂U T V ∂V T U
The effect is exactly the same as previously and it would have been possible to
define \diffp as this variant by following the definition of the variant with the
statement,
\NewDocumentCommand \diffp { } { \diff.p. }
diffcoeff has not followed this path, instead choosing to put the status and
configurability of partial derivatives on the same footing as ordinary derivatives.
35
but it does mean copying the .def file from directory to directory to work on
different documents. To make a definition file available for all documents, place
it in the texmf tree, preferably not the one created by your TEX distribution,
but your own personal texmf tree. Provided your TEX distribution knows about
your personal texmf tree and the files it contains, then a .def file placed within
it will be accessible to all documents.
[Link]
In earlier versions of diffcoeff, if there was no explicit def-file=<filename>
package option statement, then a file [Link] was sought and if found
loaded. This is no longer the case. Version 5 of diffcoeff searches for a .def
only if it is explicitly named in a package option statement. (This decision
was made at least in part to avoid conflict with a [Link] file from
an earlier version of diffcoeff tucked away in some non-obvious place and
producing obscure errors in the current version 5.)
36
Acceleration In tensor calculus acceleration is sometimes written ∇ v i /dt,
where different operator symbols occur in numerator and denominator. In the
preamble to this document I have included the definition
\difdef { f, s } { n }
{
op-symbol = \nabla,
op-symbol-alt = \mathrm{d}
}
to give both upright- (the f) and slash-fraction (the s) forms of the accelera-
tion. Appending the dot-delimited name n to \difs, $ \difs.n.{v^i}t $ =⇒
∇ v i /dt, and appending the dot-delimited name n to \diff,
\[ \diff.n.{v^i}t. \] =⇒
∇ vi
.
dt
Detached subscripts To show the effect of the key sub-nudge, the preamble
contains the definition
\difdef { fp } { wsp }
{ sub-nudge = 0 mu }
37
The first thing to notice is that the name of the variant, *0, is not formed
from letters (there are other examples below). Now Lagrange’s equations are
rendered (just right to my eye!)
\[ \diffp L{q_{k}}-\diff.*0.**t{\diffp L{\dot{q}_{k}}[]}=0 \]
d ∂L
∂L
− = 0.
∂qk dt ∂ q̇k
Bug in xtemplate If you wish to successfully edit a variant form that has
(already) been defined – by you or in diffcoeff or in the .def file – then
you will need a version of xtemplate from 2022-12-17 or later. Earlier versions
contained a bug that didn’t otherwise affect the workings of diffcoeff but did
prevent changes being made to already defined variants.
You may wish to edit an already defined variant form – perhaps to give a
negative value to *derivand-sep in the last example. You don’t need to repeat
the full definition. It suffices to change the setting only of the relevant key or
keys:
\difdef { f, fp } { *0 }
{ *derivand-sep = -3 mu }
which gives for Lagrange’s equations (too tight to my eye!)
d ∂L
∂L
− = 0.
∂qk dt ∂ q̇k
\difdef { f, fp }{ dv }
{ long-var-wrap = dv }
The three possibilities for wrapping multitoken variables can now be illustrated:
\[ \diffp[2]f{x^{i}},\quad
\[Link].[2]f{x^{i}},\quad
\diffp.(dv).[2]f{x^{i}} \]
38
=⇒
∂ 2f ∂ 2f ∂ 2f
2, i2
, 2
∂(xi ) ∂x (∂xi )
To my eye parenthesizing seems unnecessary in this case, but in the following
desirable (as in the first, default, setting):
\[ \diffp[2]F{1/T},\quad
\[Link].[2]F{1/T},\quad
\diffp.(dv).[2]F{1/T} \]
=⇒
∂ 2F ∂ 2F ∂ 2F
2, 2, 2
∂(1/T ) ∂1/T (∂1/T )
where the ‘pipe’ character is used for the name of the variant.
\[ \diffp.|.{F(x,y)}x[x=1] \] =⇒
∂ F (x, y)
∂x x=1
For slash fractions, I think parentheses give a better result than a vertical rule:
39
\difdef { f, fp, s, sp } { ] }
{
outer-Ldelim = \left [ ,
outer-Rdelim = \right ],
elbowroom = 1 mu,
sub-nudge = 0 mu
}
giving the result
$ \difs.].{F(x)}{(2x)}[x=0] $ =⇒ [d F (x)/d(2x)]x=0 ,
which both avoids ‘parenthesis overload’ and is ‘tied together’ by the square
brackets (and at least gives a nod in the direction of the ISO standard).
40
For a non-scaling display-style derivative using \dfrac, given the defaults in
templates DIFF and DIFFP, the definition would be much simpler,
\difdef { f, fp } { d } { style = dfrac }
but there seems little point in so doing.
41
But for small size increases, the results can be pleasing. To the author’s eye,
both 0 and 1 variants give better results than the default:
$ \difsp.1.{F(x,y)}{\tfrac1x}[0] $ =⇒ ∂ F (x, y) ∂ x1 0
$ \difsp.0.{F(x,y)}{\tfrac1x}[0] $ =⇒ ∂ F (x, y) ∂ x1 0
42
\difdef { f, s } { gd }
{ op-symbol = \delta }
\difdef { f, s } { gD }
{ op-symbol = \Delta }
\difdef { f, s } { D }
{ op-symbol = \mathrm{D} }
\difdef { c } { bD }
{
op-symbol = \mathbf{D},
op-sub-nudge = -2mu
}
(where the ‘g’ in the first two suggests ‘greek’), meaning one can write expres-
sions like $ \[Link] $ =⇒ δy/δx, or $ \[Link] $ =⇒ ∆s/∆t (for
the average speed), or
\[ \diff.D.{\rho}t=\diffp\rho t + \mathbf{u\cdot}\nabla\rho \]=⇒
Dρ ∂ρ
= + u·∇ρ
Dt ∂t
for the total derivative of ρ (perhaps in fluid dynamics), or
$ \[Link].[2]y{x\,}+2\[Link].y{x\,}-4=0 $ =⇒ Dx2 y + 2Dx y − 4 = 0
\difdef{ s }{ bk }
{
slash-tok = ,
op-symbol = ,
multi-term-sep = 3mu\middle|\mskip3mu ,
43
outer-Ldelim = \left\langle ,
outer-Rdelim = \right\rangle
}
and supplemented it with the definition:
\NewDocumentCommand \Braket { m }
{
\difoverride {\negmu}
\[Link].{}{#1}[]
}
Comparison with the \Braket command of the braket package, which uses | as
the separator in the argument rather than commas, shows the displayed results
to be the same (as far as I can judge).
If this is placed in the preamble of your document or in your .def file (see
§3.3.1) then the command \diff yx[0] will produce
dy
dx 0
44
by default. By leaving the second argument empty the \difdef command has
changed the default value of those templates indicated by the list of identifiers
in the first argument – in the present case only the template DIFF. In particular,
note that the new default is not inherited by DIFFP. Inheritance occurs only at
load time. How to change defaults that will be inherited is discussed below in
§3.4.1.
If you wish to change other defaults of other templates follow the same
procedure. In the first argument of the \difdef command insert a comma-list
of the derivative identifiers (f, s, c, fp, sp, cp, j or l) that you want the new
defaults to apply to, leave the second argument empty, and in the third argument
provide the key=value list of new defaults.
For instance, you might prefer math-italic ‘d’s rather than the upright ISO
recommendation, and you want this to apply across all ordinary-derivative tem-
plates. The most straightforward way of achieving that would be through the
definition
\difdef { f, s, c, l } {}
{
op-symbol = d ,
op-order-nudge = 1 mu
}
which includes the list of identifiers f, s, c, l in the first argument (the l
referring to the template DIFL of the differential – see §4.1) and leaves the
second argument empty. Thereafter, all ordinary derivatives will be graced
with math-italic rather than upright ‘d’s.
op-symbol = d,
op-order-nudge = 1 mu,
outer-Ldelim = \left . ,
outer-Rdelim = \right |,
sub-nudge = 0 mu
45
By locating the file in a place where your TEX distribution can find it – either
in the directory of the current document or in your personal texmf tree (see the
earlier discussion at §3.3.1, and in particular the need to alert your TEX distro
to the presence of the file) – [Link] will be read at load time and
the new defaults not only incorporated into template DIF but inherited by all
child and grandchild templates unless explicitly countermanded (for example
by op-symbol = \partial and similar statements in the definitions of those
templates).
The second method is to use the package option DIF. For instance loading
diffcoeff with the call
\usepackage
[ DIF =
{
op-symbol = d,
op-order-nudge = 1 mu,
outer-Ldelim = \left . ,
outer-Rdelim = \right |,
sub-nudge = 0 mu
}
]{diffcoeff}
will overwrite the built-in defaults with these new values, which will be inherited
by child (and grandchild) templates unless explicitly countermanded. Notice
that since DIF is a comma list it requires braces around the list of key=value
statements.
If both methods of changing the template DIF are employed, the order of
use is, first, read and act on the file [Link], then read and act on
the package option DIF. (In other words, to avoid complicating the preamble,
preferably use the file [Link]; use the package option DIF only for
fine-tuning – perhaps a setting specific to that particular document.)
46
Chapter 4
In addition to the six derivative commands, \difx and \difxp, the diffcoeff
package has two further commands, \dl and \jacob, for writing differentials
and jabobian determinants respectively. These commands use the settings of
the templates DIFL and DIFJ, and both are correspondingly configurable by
means of the \difdef command.
4.1 Differentials
Forms like dx occur not only as components of derivatives but also in other
contexts like the expression for a total differential,
∂P ∂P ∂P
dP = dx + dy + dz,
∂x ∂y ∂z
´
or in integrals, like sin x dx, or multi-variable integrals like
˚∞
V (x, y, z) dx dy dz,
−∞
V (x1 , x2 , x3 ) dx , or
3
V (x1 , x2 , x3 ) d3 x.
−∞ −∞
They also occur in differential geometry and elsewhere in the form of line ele-
ments like
dx 2 + dy 2 + dz 2 and c2 dt 2 − dx 2 − dy 2 − dz 2 .
Surely we want the ‘d’s in these expressions to correspond to their form (upright
or math italic) in derivatives?
47
To this end, diffcoeff provides a command \dl to write the ‘d’ in a differ-
ential in a manner consistent with the default form used in derivatives. In the
present document, the default form is upright and so
$ \dl x $ =⇒ dx.
(From version 5.4 of diffcoeff, following the pattern of \diff, \difs and
\difc, the command \difl is also available: $ \difl x $ =⇒ dx.) To use
the command before a multi-token variable of differentiation, put the variable
in braces:
$ \dl{\vec{x}},\quad \dl{\mathbf{x}} $ =⇒ d⃗x, dx.
For the first triple integral above, writing the differentials required not three
but just the one command:
$ \dl{x,y,z} $ =⇒ dx dy dz.
For the second triple integral, dx 3 was just \dl[3]x, and for the third I used a
dot-delimited argument producing a variant form of the differential \[Link].[3]x
(which could be compacted further into a macro if it were to be used often); see
§4.1.3 below.
To write the line elements I again made use of a variant form of the differ-
ential (and again see §[Link]):
$ \dl.+.{x,y,z}^2 $ =⇒ dx 2 + dy 2 + dz 2 ,
$ c^2\dl.-.{t,x,y,z}^2 $ =⇒ c2 dt 2 − dx 2 − dy 2 − dz 2 .
48
That so few of the DIF defaults are changed in DIFL indicates that much of
the machinery of derivative formation is irrelevant for forming a differential. A
list of relevant keys for the creation of differentials – those that have some effect
on the appearance of the thing – can be found at §5.2.6.
49
$ \dl.p.x $ =⇒ ∂x
which is seven keystrokes in all versus ten (space included) for \partial x.
Defining \dlp by writing
\NewDocumentCommand \dlp {} { \dl.p. }.
saves another keystroke. However, I doubt the few keystrokes saved justify the
trouble of defining such a variant. The real reason one might do so is to ease the
writing of expressions like ∂x 3 ∂y 2 ∂z – perhaps in a document like the present
one to discuss the minutiae of spacing in the denominators of mixed partial
derivatives.
$\dl.p.[3,2]{x,y,z},\quad \dl.p.{x:3,y:2,z}$ =⇒
∂x 3 ∂y 2 ∂z, ∂x 3 ∂y 2 ∂z
As you can see from the example, just as for mixed partial derivatives, if more
than one variable is specified but the order-spec contains fewer than that
number of entries, diffcoeff assumes the missing entries are 1.
A second example of a variant form of differential is provided by the definition
\difdef { l } { b }
{ op-symbol = \mathrm{d}\mathbf }
which can be found in the file [Link]. If you distinguish vectors, say,
by boldface type, then you can avoid writing \mathbf for differentials of vectors
by using the variant form \dl.b.:
$ \dl.b.x,\quad \dl.b.{x,y,z} $ =⇒ dx, dx dy dz.
A third example is of a differential raised to a power in which the superscript
is attached to the d, as provided by the definition
\difdef { l } { dn } { style = d^ }
With this definition
\[ \iiintop_{-\infty}^{\infty}
V(x_{1},x_{2},x_{3})\[Link].[3]x.
=⇒
˚∞
V (x1 , x2 , x3 ) d3 x.
−∞
If you are going to need this form of differential often, you could save some
keystrokes with a macro definition like
\NewDocumentCommand \dn { m m } { \[Link].[#1]{#2} }
In fact I have added this and the associated \difdef command to the preamble
of the present document, so that it suffices to write \dn3x to obtain d3 x.
50
[Link] Line elements
Variant forms can be used to write line elements of Pythagorean or Minkowskian
form. The definition
\difdef { l } { + }
{
multi-term-sep = 0 mu +,
term-sep-adjust = 0 mu ,
outer-Ldelim =
}
which can be found in the file [Link], inserts a + sign between terms in
the variable specification. Notice that the value assigned to the key multi-term-sep
begins with 0 mu. A dimension here initially is essential. Also note that the thin
space inserted by default before a differential by means of the outer-Ldelim
setting is now removed. But the intriguing feature of the definition is what
follows the 0 mu in the multi-term-sep value: a + sign. Applying this vari-
ant to {x,y,z} the result is dx + dy + dz, which may be mildly interesting but
definitely becomes so when we add an exponent to the variable spec.:
$ \dl.+.{x,y,z}^2 $ =⇒ dx 2 + dy 2 + dz 2 .
The exponent acts as if an order specification [2,2,2] had been included. If an
order specification is included, whatever the values listed, the trailing exponent
overrides it.
Similarly, the file [Link] contains an identical definition save that
the plus sign is replaced by a minus. This enables the writing of a Minkowski
metric:
$ c^2\dl.-.{t,x,y,z}^2 $ =⇒ c2 dt 2 − dx 2 − dy 2 − dz 2 .
51
4.1.5 Rationale
But why bother with the differential command at all? It only seems to com-
plicate the simple typing of d followed by x. Admittely typing \dl x requires
fewer keystrokes than typing \mathrm{d}x (or even \mathrm dx), but there are
other, more substantive, reasons why one might prefer an explicit command.
4.2 Jacobians
diffcoeff provides a command \jacob for writing jacobians – not the deter-
minant as such but the symbol conventionally used to denote the determinant.
For example
\[ \jacob{u,v}{x,y},\quad \jacob{u,v,w}{x,y,z}. \] =⇒
∂(u, v) ∂(u, v, w)
, .
∂(x, y) ∂(x, y, z)
The comma lists can contain any number of variables, even one or none, nor
need the numbers in numerator and denominator be equal. \jacob does not
check such things. (It may be possible to exploit this fact when defining variant
forms of jacobian, or other notations – like the \Braket example in §3.3.3.)
From version 5.4 of diffcoeff, following the pattern of \diff, \difs and
\difc, the command \difj is also available and is equivalent to \jacob.
52
in Table 4.2. Note that the keys outer-Ldelim and outer-Rdelim are both
empty and, as with the differential, are always inserted – which is why they are
empty by default.
The lack of entries in Table 4.2 is because many keys are irrelevant for
forming jacobians – it doesn’t matter what their default values are. For a list
of relevant keys – ones that have some effect on the appearance of a jacobian –
see §5.2.5.
53
\difdef { j } { [ }
{
lvwrap-Ldelim = \onemu\mleft [,
lvwrap-Rdelim = \mright ]
}
the \onemu giving, to my eye, better spacing between the \partial symbols
and the left brackets. This definition, too, has been added to the preamble so
that
\[ \jacob.[.{u,v,w}{x,y,z} \] =⇒
∂ [u, v, w]
.
∂ [x, y, z]
54
Chapter 5
Reference
For convenience I list here the commands of diffcoeff, the template defaults,
and the files and preamble definitions associated with this document.
5.1 Commands
\diff, \diffp, \difs, \difsp, \difc, \difcp (sometimes summarised as \difx
and \difxp), ordinary and partial derivatives of upright-fraction, slash-fraction
and compact forms respectively, with arguments (all optional unless otherwise
indicated) and their delimiters:
1. .name. name of variant form of derivative;
2. * append-differentiand switch;
3. * reverse order of mandatory arguments 6 and 7 when differentiand is
appended, available only if first star is also present;
4. [order(s)] order of differentiation, or comma list of orders of differenti-
ation (for mixed partial derivatives);
5. <override> total order of differentiation override (for mixed partial deriva-
tives);
6. {differentiand} (mandatory) function being differentiated;
7. {variable(s)} (mandatory) differentiation variable or, for mixed partial
derivatives, comma list of differentiation variables;
8. [pt of eval/const vars] point of evaluation or, for partial derivatives,
variables held constant.
\difoverride order-override command with one mandatory argument:
1. {total order} total order of differentiation; may be (and generally is)
empty.
55
\jacob (also \difj) jacobian with arguments and delimiters:
5.2 Templates
The following lists record the default values of the templates used by diffcoeff.
For templates other than DIF, only relevant keys have been listed – those which
affect the appearance of the derivative (or jacobian or differential).
56
5.2.1 DIF (primogenitor)
style = frac,
slash-tok = /,
slash-sep = 0 mu,
derivand-sep = 3 mu plus 1 mu minus 2 mu,
op-symbol = \mathrm{d},
op-symbol-alt = \KeyValue{ op-symbol },
op-order-nudge = 0 mu,
var-sup-nudge = 1 mu,
multi-term-sep = 2 mu plus 1 mu minus 1 mu,
term-sep-adjust = -1 mu,
long-var-wrap = d(v),
lvwrap-Ldelim = \mleft (,
lvwrap-Rdelim = \mright ),
lvwrap-sup-nudge = -2 mu,
outer-Ldelim = \left (,
outer-Rdelim = \right ),
elbowroom = 0 mu,
sub-nudge = -5 mu,
op-sub-nudge = 0 mu,
*derivand-sep = \KeyValue{ derivand-sep },
*op-set-left = false,
*italic-nudge = 0 mu,
*inner-wrap = false,
*inner-Ldelim = (,
*inner-Rdelim = ),
*outer-Ldelim = \big [,
*outer-Rdelim = \big ],
*sub-nudge = 0 mu
57
outer-Ldelim = \left (,
outer-Rdelim = \right ),
elbowroom = 0 mu,
sub-nudge = -5 mu,
*derivand-sep = \KeyValue { derivand-sep },
*op-set-left = false,
*italic-nudge = 0 mu
[Link] DIFFP
DIFF defaults as above with the following changes (a marginal >> indicates where
a setting differs from that in DIFF):
>> op-symbol = \partial,
>> op-order-nudge = 1 mu,
>> *italic-nudge = 3 mu
> style = /,
slash-tok = /,
slash-sep = 0 mu,
> derivand-sep = 2 mu plus 1 mu minus 2 mu,
op-symbol = \mathrm{d},
op-symbol-alt = \KeyValue { op-symbol },
op-order-nudge = 0 mu,
var-sup-nudge = 1 mu,
multi-term-sep = 2 mu plus 1 mu minus 1 mu,
term-sep-adjust = -1 mu,
long-var-wrap = d(v),
lvwrap-Ldelim = \mleft (,
lvwrap-Rdelim = \mright ),
lvwrap-sup-nudge = -2 mu,
> outer-Ldelim = (,
> outer-Rdelim = ),
elbowroom = 0 mu,
> sub-nudge = 0 mu,
*derivand-sep = \KeyValue { derivand-sep },
> *inner-wrap = true,
*inner-Ldelim = (,
*inner-Rdelim = ),
*outer-Ldelim = \big [,
*outer-Rdelim = \big ],
*sub-nudge = 0 mu
58
[Link] DIFSP
DIFS defaults as above with the following changes (a marginal >> indicates where
a setting differs from that in DIFS):
>> op-symbol = \partial,
>> op-order-nudge = 1 mu
> style = _ ,
> derivand-sep = 1 mu plus 1 mu minus 2 mu,
op-symbol = \mathrm{d},
op-order-nudge = 0 mu,
> multi-term-sep = 1 mu,
> term-sep-adjust = 0 mu,
> outer-Ldelim = \bigl (,
> outer-Rdelim = \bigr ),
elbowroom = 0 mu,
> sub-nudge = -2 mu,
op-sub-nudge = 0 mu,
*derivand-sep = \KeyValue { derivand-sep }
[Link] DIFCP
DIFC defaults as above with these changes (a marginal >> indicates where a
setting differs from that in DIFC):
>> op-symbol = \partial,
>> op-order-nudge = 1 mu
59
elbowroom = 0 mu ,
*op-set-left = false,
*italic-nudge = 0 mu
60
{ op-symbol = \delta }
\difdef { f, s } { gD }
{ op-symbol = \Delta }
% spaceless appending
\difdef { f, fp } { *0 }
{
*derivand-sep = 0 mu ,
outer-Ldelim = \mleft ( ,
outer-Rdelim = \mright )
}
% tfrac, nonscalable
\difdef { f, fp } { t }
{
style = tfrac ,
derivand-sep = 1 mu plus 1 mu minus 1 mu,
multi-term-sep = 0 mu ,
term-sep-adjust = 0 mu ,
lvwrap-sup-nudge = 0 mu ,
outer-Ldelim = \bigl (,
outer-Rdelim = \bigr ),
elbowroom = -2 mu ,
sub-nudge = -3 mu
}
% slash fractions: 0=scalable,
% 1=big, 2=Big, 3=bigg, 4=Bigg
% but > 1 gives eyesores
\difdef { s, sp } { 0 }
{
style = auto ,
outer-Ldelim = \left [ ,
outer-Rdelim = \right ] ,
sub-nudge = 0 mu ,
*inner-Ldelim = \mleft ( ,
*inner-Rdelim = \mright ),
*outer-Ldelim = \left [ ,
*outer-Rdelim = \right ]
}
\difdef { s, sp } { 1 }
{
style = big ,
outer-Ldelim = \bigl (,
outer-Rdelim = \bigr ),
sub-nudge = -2 mu ,
*inner-Ldelim = \bigl (,
*inner-Rdelim = \bigr ),
*outer-Ldelim = \bigl [,
61
*outer-Rdelim = \bigr ]
}
% vrule point of evaluation
\difdef { f, fp, s, sp } { | }
{
outer-Ldelim = \left . ,
outer-Rdelim = \right |,
sub-nudge = 0 mu
}
% sq. bracket pt of eval.
\difdef { f, fp, s, sp } { ] }
{
outer-Ldelim = \left [ ,
outer-Rdelim = \right ],
elbowroom = 1 mu,
sub-nudge = 0 mu
}
% long var wrap
\difdef { f, fp } { (dv) }
{ long-var-wrap = (dv) }
\difdef { f, fp } { dv }
{ long-var-wrap = dv }
% compact, D operator
\difdef { c } { D }
{
op-symbol = \mathrm{D},
op-sub-nudge = -2mu
}
\difdef { c } { D’ }
{
op-symbol = D,
op-sub-nudge = -2mu
}
% bold
\difdef { c } { bD }
{
op-symbol = \mathbf{D},
op-sub-nudge = -2mu
}
% differential style
\difdef { c, cp } { dl }
{ style = dl }
%%%%%%%%%%% differential %%%%%%%%%%
% partial
\difdef { l } { p }
{ op-symbol = \partial }
62
% bold
\difdef { l } { b }
{ op-symbol = \mathrm{d}\mathbf }
63
% align op left; italic nudge
\difdef { fp } { left }
{
op-symbol = \partial,
op-order-nudge = 1 mu,
*op-set-left = true,
*italic-nudge = 3 mu
}
% partial variant of \diff
\difdef { f } { p }
{
op-symbol = \partial,
op-order-nudge = 1 mu
}
% partial, 3mu sep of terms
\difdef { fp, sp } { 3mu }
{ multi-term-sep = 3 mu }
% D jacobian
\difdef { j } { D }
{ op-symbol = D }
% square bracket jabobian
\difdef { j } { [ }
{
lvwrap-Ldelim = \onemu\mleft [,
lvwrap-Rdelim = \mright ]
}
% differential d^n x
\difdef { l } { dn }{ style=d^ }
\NewDocumentCommand \dn { m m }
{ \[Link].[#1]{#2} }
% mimicking the \Braket command
% of the braket package
\difdef{ s }{ bk }
{
slash-tok = ,
op-symbol = ,
multi-term-sep = 3mu\middle|\mskip3mu ,
outer-Ldelim=\left\langle ,
outer-Rdelim=\right\rangle
}
\NewDocumentCommand \Braket { m }
{
\difoverride {\negmu}
\[Link].{}{#1}[]
}
64
5.5 \DeclareChildTemplate
xtemplate provides only a single function, \DeclareRestrictedTemplate, for
creating a child template from a parent. All the keys of the child template are
present in the parent. The child inherits not only the keys of the parent but the
default settings of those keys. Some of those settings are ‘marked’ so that they
cannot be changed by any instance of the child (the restricted keys) .
Unfortunately there is no similar function available in xtemplate at present
by which one can create a child with new as well as restricted default values. I
found I could achieve this functionality with the following code cobbled together
from publicly declared functions in xtemplate.
% Child template with both new and restricted defaults
% #1 object; #2 parent template; #3 child template;
% #4 restricted, #5 new defaults (both key=value)
\NewDocumentCommand \DeclareChildTemplate { m m m m m }
{
\DeclareRestrictedTemplate {#1} {#2} {#3} {}
\EditTemplateDefaults {#1} {#3} {#5}
\DeclareRestrictedTemplate {#1} {#3} {#3} {#4}
}
The first \DeclareRestrictedTemplate call creates the child template #3 from
the parent template #2, inheriting all its keys and default values. No restrictions
are imposed at this stage because the following \EditTemplateDefaults would
immediately cancel them. That statement specifies the new defaults #5 of the
child – those that differ from the parent. The default settings #4 of the parent
that are restricted to particular values in the child are imposed by the second
\DeclareRestrictedTemplate call through the aritifice of treating the child
template #3 as a child of itself. In that way its new defaults are not lost.
65
(c) adds a second star option to reverse the order of differentiand and
variable(s) of differentiation when the differentiand is appended;
(d) replaces the two-argument \diffdef command of earlier versions
with the three-argument command \difdef command, the additional
argument determining which one or more of the f, s, c, fp, sp or cp
forms the defined variant applies to;
(e) rewrites the differential command \dl which is now template-configurable
(e.g. allowing easy writing of line elements like dx 2 + dy 2 + dz 2 );
(f) rewrites the jacobian command \jacob which is now template-configurable;
(g) uses ISO defaults;
(h) includes version conflict messages.
2. Version 5.1 (2023-01-16)
(a) adds a now-redundant ISO package option and related version conflict
message;
(b) makes some corresponding tweaks to documentation (including this
version 5 history).
3. Version 5.2 (2023-01-24)
(a) Simplifies the treatment of the empty argument of an absent differ-
entiation variable;
(b) initializes (clears) two sequence variables that otherwise caused error
when scrbook class was used;
(c) amends documentation.
4. Version 5.3 (2023-04-10)
(a) Fixes a bug when \dl was used in a particular way in beamer (e.g.
\[\alert{\dl x}\]).
(b) Provides an alternative method of specifying orders of differentiation
by means of colon separators in the variable argument.
(c) Reinstates (from v.4) the order-override option as an alternative to
\difoverride but now angle-bracket delimited.
5. Version 5.4 (2023-11-08)
(a) Adjusts both code and documentation about the differential to enable
forms like d[]3 x (sometimes used in multiple integrals).
66