Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Quick answer: in plain LaTeX a derivative is a fraction typed in math mode: $\frac{dy}{dx}$ for an ordinary derivative and $\frac{\partial f}{\partial x}$ for a partial derivative. Three CTAN packages shorten this: physics (\dv, \pdv), derivative (\odv, \pdv) and diffcoeff (\diff, \diffp). This guide gives the exact commands from each package’s own manual, so you can pick one route and use it consistently across a paper or thesis.
What derivative notation is used for in research
Derivatives appear wherever a manuscript states a rate of change: model equations in physics and engineering, loss gradients in statistics and machine learning, and rate laws in chemistry. Typesetting them by hand with \frac works, but long expressions, repeated higher-order derivatives and mixed partials make source files hard to read and easy to get inconsistent. Derivative packages give each derivative one short command and apply the same differential style (upright or italic d) everywhere. For other notation in the same family see the CASRAI guides on the Laplacian in LaTeX, the Laplace transform in LaTeX and sigma and summation in LaTeX.
Install or access (official source only)
The basic \frac and \partial commands need no package. The packages below are distributed through CTAN, the Comprehensive TeX Archive Network, and each has a manual on CTAN. A current TeX Live or MiKTeX installation, or an online editor such as Overleaf, normally provides them, so the usual step is just loading the package in the preamble.
- physics: manual by Sergio C. de la Barrera, dated December 12, 2012 (physics.pdf on CTAN).
- derivative: version 1.4, 2024/02/08, by Simon Jensen. It is written in expl3 and requires the l3kernel and l3package bundles; the mleftright package is optional (derivative.pdf on CTAN).
- diffcoeff: version 5.6, December 19, 2025, by Andrew Parsloe (diffcoeff.pdf on CTAN).
Step-by-step: write a derivative in LaTeX
Derivative in LaTeX without any package
- Write the expression in math mode (between dollar signs, or in an
equationenvironment). - Ordinary derivative:
\frac{dy}{dx}. - Partial derivative:
\frac{\partial f}{\partial x}; second order:\frac{\partial^2 f}{\partial x^2}. - For an upright differential d, as many style guides require, write
\mathrm{d}in place ofd, for example\frac{\mathrm{d}y}{\mathrm{d}x}.
Derivatives in LaTeX with the physics package
- In the preamble add
\usepackage{physics}. The package’s default differential symbol is an upright d; to get an italic d load it as\usepackage[italicdiff]{physics}. - Ordinary derivative:
\dv{f}{x}. Higher order:\dv[n]{f}{x}. The starred form\dv*{f}{x}gives an inline df/dx. - Partial derivative:
\pdv{f}{x}, higher order\pdv[n]{f}{x}, mixed\pdv{f}{x}{y}. - A bare differential:
\dd{x}. Evaluation limits:\eval{x}_0^\infty. The long names\derivative,\partialderivativeand\differentialare also provided.
Derivatives in LaTeX with the derivative package
- In the preamble add
\usepackage{derivative}. Options are given as a key-value list in square brackets; the differential is an upright d when the package optionupright=trueis set and an italic d withitalic=true. - Ordinary derivative:
\odv{f}{x}. The general syntax is\odv *[keyval list]{function}/{variables}_{point1}^{point2}. - Partial derivative:
\pdv{f}{x}. A mixed partial is written\pdv{f}{x,y}, and the package works out the total order for you. An explicit order list is passed as\pdv[order={2,3}]{f}{x,y,z}. - Point of evaluation:
\pdv{f}{x,y}_{(x_1,y_1)}. - The star placed first,
\pdv*{f}{x,y}, changes where the function sits relative to the fraction bar; the manual also shows a slash-separated input form,\pdv{f}/{x,y}. - The same package also provides
\mdv(material derivative, D),\jdv(Jacobian) and\odif(differential). You can define your own derivative command with\DeclareDerivative.
Derivatives in LaTeX with the diffcoeff package
- In the preamble add
\usepackage{diffcoeff}, optionally with a list of options in square brackets. To keep the behaviour of version 4, the manual gives\usepackage[<options>]{diffcoeff}[=v4]. - Ordinary derivative as a fraction:
\diff{y}{x}. Slash form:\difs. Compact form:\difc. - Partial derivatives use the same pattern with a p:
\diffp,\difsp,\difcp. - Order goes in square brackets:
\diff[2]{y}{x},\diff[n+1]{y}{x},\diffp[2]{y}{x}. The order can also be attached to the variable, as in\diff y{x:2}. For mixed partials the package computes the total order. - With the star,
\diff*{(ax^2+bx+c)}xplaces the differentiand after the operator.
Output and how to read it
Each route produces the same mathematical object, a quotient of differentials, and they differ mainly in the typeset d and in how the source is written. The table compares the four routes using only the commands documented above.
| Route | Ordinary derivative | Partial derivative | Upright / italic d | Manual date or version |
|---|---|---|---|---|
| Plain LaTeX | \frac{dy}{dx} |
\frac{\partial f}{\partial x} |
Write \mathrm{d} for upright |
No package |
| physics | \dv{f}{x} |
\pdv{f}{x} |
Upright by default; italicdiff option for italic |
December 12, 2012 |
| derivative | \odv{f}{x} |
\pdv{f}{x,y} |
upright=true or italic=true |
v1.4, 2024/02/08 |
| diffcoeff | \diff{y}{x} |
\diffp{y}{x} |
See the package options in its manual | v5.6, December 19, 2025 |
Notice that physics and derivative both define \pdv, but with different argument syntax (\pdv{f}{x}{y} in physics, \pdv{f}{x,y} in derivative). Load only one of them in a document so a given command always means one thing. The physics manual is dated 2012, while the derivative and diffcoeff manuals were updated in 2024 and 2025 respectively; if you submit to a journal that supplies its own class file, check that class with your chosen package before the final submission.
Troubleshooting
- “Undefined control sequence” on
\dv,\pdv,\odvor\diff: the package has not been loaded. Add the matching\usepackageline to the preamble, before\begin{document}. - Derivative package fails to compile: it is built on expl3 and requires l3kernel and l3package; an old TeX installation may need updating.
- The d is italic and you want upright, or the reverse: use the option listed in the table for the package you loaded.
- Command works inline but the layout is too tall:
\dv*{f}{x}inphysicsgives an inline df/dx;derivativeanddiffcoeffoffer slash and compact forms (\difs,\difc).
Free alternatives
The \frac route needs no package at all. The table lists the three packages covered above; each is distributed on CTAN with its own manual.
| Option | Where to get it | Best known for (per its manual) |
|---|---|---|
Plain \frac and \partial |
Part of LaTeX | No dependencies |
| physics | CTAN | Short \dv and \pdv commands plus other physics notation |
| derivative | CTAN | Automatic order for mixed partials, point of evaluation, material derivative and Jacobian |
| diffcoeff | CTAN | Fraction, slash and compact forms for ordinary and partial derivatives |
FAQ
How do I write a derivative in LaTeX?
Use \frac{dy}{dx} in math mode, or load a package such as physics and write \dv{y}{x}.
How do I write derivatives in LaTeX for higher orders?
In plain LaTeX use exponents, for example \frac{d^2y}{dx^2}. In physics use \dv[2]{y}{x}; in diffcoeff use \diff[2]{y}{x}.
How do I write a partial derivative in LaTeX?
Use \frac{\partial f}{\partial x}, or \pdv{f}{x} with physics or derivative, or \diffp{f}{x} with diffcoeff.
How do I get an upright d in a derivative?
Write \mathrm{d} in plain LaTeX. The physics package is upright by default; derivative uses upright=true.
Sources (official documentation)
- derivative package manual, v1.4, 2024/02/08, Simon Jensen, CTAN: derivative.pdf. Read 2026-11-08.
- physics package manual, Sergio C. de la Barrera, December 12, 2012, CTAN: physics.pdf. Read 2026-11-08.
- diffcoeff package manual, v5.6, Andrew Parsloe, December 19, 2025, CTAN: diffcoeff.pdf. Read 2026-11-08.
More tools for researchers are collected on the research tools hub; for formatting a finished manuscript see setting margins in LaTeX.







