Skip to main content
v2026.11,986 entries · CC-BY 4.0

Derivative in LaTeX: frac, partial and Three Packages

How to write a derivative in LaTeX: plain fractions plus the exact commands from the physics, derivative and diffcoeff CTAN manuals, with a comparison table.

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

  1. Write the expression in math mode (between dollar signs, or in an equation environment).
  2. Ordinary derivative: \frac{dy}{dx}.
  3. Partial derivative: \frac{\partial f}{\partial x}; second order: \frac{\partial^2 f}{\partial x^2}.
  4. For an upright differential d, as many style guides require, write \mathrm{d} in place of d, for example \frac{\mathrm{d}y}{\mathrm{d}x}.

Derivatives in LaTeX with the physics package

  1. 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}.
  2. Ordinary derivative: \dv{f}{x}. Higher order: \dv[n]{f}{x}. The starred form \dv*{f}{x} gives an inline df/dx.
  3. Partial derivative: \pdv{f}{x}, higher order \pdv[n]{f}{x}, mixed \pdv{f}{x}{y}.
  4. A bare differential: \dd{x}. Evaluation limits: \eval{x}_0^\infty. The long names \derivative, \partialderivative and \differential are also provided.

Derivatives in LaTeX with the derivative package

  1. 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 option upright=true is set and an italic d with italic=true.
  2. Ordinary derivative: \odv{f}{x}. The general syntax is \odv *[keyval list]{function}/{variables}_{point1}^{point2}.
  3. 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}.
  4. Point of evaluation: \pdv{f}{x,y}_{(x_1,y_1)}.
  5. 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}.
  6. 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

  1. 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].
  2. Ordinary derivative as a fraction: \diff{y}{x}. Slash form: \difs. Compact form: \difc.
  3. Partial derivatives use the same pattern with a p: \diffp, \difsp, \difcp.
  4. 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.
  5. With the star, \diff*{(ax^2+bx+c)}x places 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, \odv or \diff: the package has not been loaded. Add the matching \usepackage line 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} in physics gives an inline df/dx; derivative and diffcoeff offer 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.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Derivative in LaTeX: frac, partial and Three Packages

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →