0% found this document useful (0 votes)
60 views10 pages

Diffcoeff 10

diffcoeff is a LaTeX package that provides commands to easily write derivatives of various types. Version 5.2 introduces more configurable templates to define derivatives, differentials, and Jacobians. It improves on earlier versions by fully embracing options from the xtemplate package and allowing customization of notation variants through the \difdef command and .def files.

Uploaded by

Charlie root
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Diffcoeff 10

diffcoeff is a LaTeX package that provides commands to easily write derivatives of various types. Version 5.2 introduces more configurable templates to define derivatives, differentials, and Jacobians. It improves on earlier versions by fully embracing options from the xtemplate package and allowing customization of notation variants through the \difdef command and .def files.

Uploaded by

Charlie root
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

diffcoeff

a LATEX package to ease the


writing of differential coefficients
Version 5.2

Andrew Parsloe
([email protected])

January 24, 2023


Abstract

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-
dy
ator or appended. Besides dx , 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 notice-
ably, 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. To avoid cluttering for-
mulas with a second square-bracket delimited optional argument before the
differentiand, the order-override option has been replaced by a new command
\difoverride. The 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 argu-
ment 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 configurability 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 Syntax and use 8


2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 General use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1 Spacing before the differentiand . . . . . . . . . . . . . . . 10
2.2.1.1 Spacing commands . . . . . . . . . . . . . . . . . 12
2.2.2 Higher order derivatives . . . . . . . . . . . . . . . . . . . 12
2.2.3 Appending the differentiand . . . . . . . . . . . . . . . . . 13
2.2.3.1 Transposing the argument order . . . . . . . . . 14
2.2.3.2 Operator parenthesizing . . . . . . . . . . . . . . 15
2.2.4 Point of evaluation/variables held constant . . . . . . . . 15
2.2.4.1 Superscripts . . . . . . . . . . . . . . . . . . . . 16
2.2.4.2 Empty trailing argument . . . . . . . . . . . . . 16
2.2.4.3 Use of the package mleftright . . . . . . . . . 17
2.2.5 Mixed partial derivatives . . . . . . . . . . . . . . . . . . 18
2.2.5.1 Algebraic orders of differentiation . . . . . . . . 19
2.2.5.2 Order-override command: \difoverride . . . . 19
2.2.5.3 Parentheses . . . . . . . . . . . . . . . . . . . . . 20
2.2.5.4 Error messages . . . . . . . . . . . . . . . . . . . 21
2.2.5.5 Comma list of variables of differentiation . . . . 22
2.2.5.6 Spacing in the denominator . . . . . . . . . . . . 22
2.2.6 Multi-token variables: parenthesizing . . . . . . . . . . . . 23

3 Templates, defaults & variants 25


3.1 Template structure . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2 Default values for template DIF . . . . . . . . . . . . . . . . . . . 26
3.2.1 Ordinary upright-fraction derivatives; template DIFF . . . 31
3.2.2 Ordinary slash-fraction derivatives; template DIFS . . . . 32
3.2.3 Ordinary compact-form derivatives; template DIFC . . . . 32
3.2.4 Partial derivatives; templates DIFFP, DIFSP, DIFCP . . . . 33
3.3 Variant forms: the \difdef command . . . . . . . . . . . . . . . 33

2
3.3.1 The .def file . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.3.1.1 Log file message . . . . . . . . . . . . . . . . . . 35
3.3.2 Examples of variants . . . . . . . . . . . . . . . . . . . . . 35
3.3.2.1 Editing variant forms . . . . . . . . . . . . . . . 37
3.3.2.2 Parenthesizing multi-token variables . . . . . . . 37
3.3.2.3 Point of evaluation . . . . . . . . . . . . . . . . . 38
3.3.2.4 Upright text-style derivatives . . . . . . . . . . . 39
3.3.2.5 Slash-fraction styles . . . . . . . . . . . . . . . . 40
3.3.2.6 Compact–form derivatives . . . . . . . . . . . . 41
3.3.2.7 D, \delta, \Delta derivatives . . . . . . . . . . . 41
3.3.3 Other notations . . . . . . . . . . . . . . . . . . . . . . . . 42
3.4 Defaults: setting your own . . . . . . . . . . . . . . . . . . . . . . 43
3.4.1 Changing defaults in DIF . . . . . . . . . . . . . . . . . . 44

4 Differentials and jacobians 46


4.1 Differentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.1.1 Template DIFL . . . . . . . . . . . . . . . . . . . . . . . . 47
4.1.2 Syntax and options . . . . . . . . . . . . . . . . . . . . . . 47
4.1.3 Variant forms of differential . . . . . . . . . . . . . . . . . 48
4.1.3.1 Line elements . . . . . . . . . . . . . . . . . . . . 49
4.1.4 Changing defaults . . . . . . . . . . . . . . . . . . . . . . 50
4.1.5 Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.2 Jacobians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.2.1 Template DIFJ . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2.2 Syntax and variant forms . . . . . . . . . . . . . . . . . . 51
4.2.3 Changing defaults . . . . . . . . . . . . . . . . . . . . . . 53

5 Reference 54
5.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.2 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.2.1 DIF (primogenitor) . . . . . . . . . . . . . . . . . . . . . . 56
5.2.2 DIFF (upright-fraction derivative) . . . . . . . . . . . . . . 56
5.2.2.1 DIFFP . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2.3 DIFS (slash-fraction derivative) . . . . . . . . . . . . . . . 57
5.2.3.1 DIFSP . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2.4 DIFC (compact derivative) . . . . . . . . . . . . . . . . . . 58
5.2.4.1 DIFCP . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2.5 DIFJ (jacobian) . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2.6 DIFL (differential) . . . . . . . . . . . . . . . . . . . . . . 59
5.3 The file diffcoeff5.def . . . . . . . . . . . . . . . . . . . . . . 59
5.4 Preamble definitions . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.5 \DeclareChildTemplate . . . . . . . . . . . . . . . . . . . . . . 63
5.6 Version history . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

3
Chapter 1

Introduction

diffcoeff.sty is written in the expl3 language of LATEX3, now part of standard


LATEX since February 2020. A LATEX distribution from or later than that date
is assumed. The package also requires the packages xtemplate (part of the
l3packages bundle) and mleftright. The package is loaded in the usual way
by entering
\usepackage{diffcoeff}

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 diffcoeff4.pdf.

1.1 Package options


There are four package options, which are entered in a comma-separated list in
the optional argument of the \usepackage command. The second and fourth
are new with version 5 of diffcoeff.
1. The first package option is the spaced option which takes three values:

(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 §2.2.4.3. 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 (see §3.3)
of derivative:

\usepackage[def-file=<filename>]{diffcoeff}

This is discussed in §3.3.1. The present document uses the package option
def-file=diffcoeff5.

4. The fourth package option DIF is a comma list of key=value statements


amending the built-in defaults for the ‘grandparent’ template DIF; see
§3.4.1. The present document does not use this package option.

To see the effect of the mleftright package, consider the expression

\[ \ln \left(\frac xy\right),\quad\sin\left(x^2\right). \] =∆


3 4
x ! "
ln , sin x2 .
y

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). \] =∆


3 4
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
=∆ 3 4
x ! "
ln , sin x2 .
y

For the present document, the call is


\usepackage[def-file=diffcoeff5,spaced=-1]{diffcoeff}

1.2 A Rogues’ Gallery of derivatives


Browsing through some (rather old) calculus textbooks and texts on statistical
mechanics, relativity and classical mechanics I find the following choice examples
of derivatives ‘disporting every which way’.
• Multi-character variables of differentiation un-parenthesized:

ˆÂ ˆ E/T d ln f ˆ 2 ˆL
, , , , . (1.1)
ˆ1 ˆ1/T d ln x0 ˆai ˆ 1 (r)
ˆ÷,i

• Multi-character variables of differentiation parenthesized in higher-order


derivatives, where the parentheses do not or (sometimes) do include the
operator:
ˆ 2q ˆ 2q ˆ 2Á d2 „i (xi )
! 1 "2 , 2, 2, 2 . (1.2)
ˆ ˆ(1/ ) ˆ(ai ) (dxi )
Should the d or ˆ be included within the parentheses, as in the last of (1.2),
or not, as in the others? Logic says ‘yes’; practice suggests (generally) ‘no’.
• Indicating a point of evaluation is similarly varied:
- - 5 —6 3 4
ˆ„ -- d2 „ -- ˆb du
, , , . (1.3)
ˆÁ - Á=Á0 dÁ 2 - Á=Á0 ˆa– dvb=0 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:
3 4 3 4
ˆ P ˆS
, , (ˆS/ˆT )V . (1.4)
ˆU T V ˆN2 U,V,N1

• Other symbols besides d and ˆ are used to denote derivative-like quanti-


ties. From introductory calculus and from classical mechanics and ther-
modynamics come ” and , from fluid mechanics comes D:
3 4
”y Dfl U ”L
, , , U / T, . (1.5)
”x Dt T V ”÷ (r)

• There are those, like the International Organization for Standardization


(ISO), who stipulate (or prefer) an upright d for their derivatives, and
there are those (like the author, through sixty years of habit) who prefer
a math-italic d:
dy dy
, , (1.6)
dx dx
and of course also in slash-fraction form dy/dx, dy/dx. Subscripted forms
of derivative are also used – for example, ˆx F , or in the discussion of
differential equations one sometimes comes across expressions like

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:
A B
d
ú
ˆ ˆ xi mqx
,  . (1.7)
ˆxlú ˆxkú dt 1 ≠ q2

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

Syntax and use

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
dy ˆy
to write (upright) fraction forms of ordinary and partial derivatives like dx , ˆx ,
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

\difx.name.*[order-spec]{differentiand}
{variable(s)}[pt of eval]
1 Suggested by a question on T X StackExchange: https://tex.stackexchange.com/
E
questions/652223/write-a-derivative-operator-without-denominator-using-diffcoef/
652298#652298

You might also like