Partial derivatives in LaTeX: first, second, mixed, and evaluation notation

BlogEasyLaTeXPublished

The basic way to write a partial derivative in LaTeX is \frac{\partial f}{\partial x}. \partial produces the partial derivative symbol ∂, and \frac builds the fraction. Both commands only work in math mode, such as $...$, \[...\], or an equation environment. \partial is built into LaTeX, so no extra package is needed.

Start with this complete example

Save it as main.tex and compile with pdfLaTeX. The example uses the article class and loads only amsmath, which provides align for multi-line alignment and \eqref for references.

LaTeX
\documentclass[a4paper,11pt]{article}\usepackage{amsmath}​\begin{document}Let $f(x,y) = x^3y^2 + 2xy$.\begin{align}  \frac{\partial f}{\partial x} &= 3x^2y^2 + 2y, &  \frac{\partial f}{\partial y} &= 2x^3y + 2x, \label{eq:first}\\  \frac{\partial^2 f}{\partial x^2} &= 6xy^2, &  \frac{\partial^2 f}{\partial y^2} &= 2x^3, \label{eq:second}\\  \frac{\partial^2 f}{\partial x\,\partial y} &= 6x^2y + 2, &  \frac{\partial^2 f}{\partial y\,\partial x} &= 6x^2y + 2. \label{eq:mixed}\end{align}At the point $(1,2)$,\begin{equation}\label{eq:point}  \left.\frac{\partial f}{\partial x}\right|_{(x,y)=(1,2)} = 16,  \qquad  \frac{\partial^2 f}{\partial x\,\partial y}(1,2) = 14.\end{equation}In running text, write $\partial f/\partial x$ or $\partial_x f$;equations~\eqref{eq:first}--\eqref{eq:point} use the fraction form.\end{document}

The PDF should show three numbered lines of partial derivatives, one equation evaluated at a point, and two compact forms in the body text. The sections below explain each form and check every result.

First, second, and mixed partial derivatives

The whole article uses the same function, f(x,y) = x^3y^2 + 2xy, so you can compare each command with its result.

Notation overview: all three kinds share the numerator f. They differ in the order on ∂ and the variables in the denominator. The results match the source above.

TypeLaTeX sourceResult here
First order, in x\frac{\partial f}{\partial x}3x^2y^2 + 2y
First order, in y\frac{\partial f}{\partial y}2x^3y + 2x
Second order, x twice\frac{\partial^2 f}{\partial x^2}6xy^2
Second order, y twice\frac{\partial^2 f}{\partial y^2}2x^3
Mixed\frac{\partial^2 f}{\partial x\,\partial y}6x^2y + 2

A few details are easy to get wrong:

  • For a second-order partial, the order goes on the ∂ in the numerator (\partial^2 f) and the denominator is \partial x^2. Here x^2 means differentiating twice with respect to x, not differentiating with respect to x².
  • A mixed partial has two variables in the denominator. \, adds a thin space between \partial x and \partial y so they are easier to tell apart. It compiles without it too.
  • The order of the variables in the denominator indicates the order of differentiation, but textbooks do not agree on the convention. A common reading takes \frac{\partial^2 f}{\partial x\,\partial y} as differentiating with respect to y first and then x, while the subscript form f_{xy} often means x first, then y. State your convention the first time it appears in a paper. In this example both orders give 6x^2y + 2 because the mixed partials of this polynomial are continuous and therefore equal. Do not assume that for a general function.

To check: when differentiating with respect to x, treat y as a constant. x^3y^2 becomes 3x^2y^2 and 2xy becomes 2y. Differentiating that with respect to y gives 6x^2y + 2. Going the other way, the partial with respect to y is 2x^3y + 2x, and its partial with respect to x is also 6x^2y + 2.

Evaluating at a point: bar, parentheses, and function notation

There are three common ways to evaluate at the point (1,2):

LaTeX
\[  \left.\frac{\partial f}{\partial x}\right|_{(1,2)} = 16  \qquad  \frac{\partial f}{\partial x}\bigg|_{(1,2)} = 16  \qquad  f_x(1,2) = 16\]

Structure: the subscript at the lower right of the bar gives the evaluation point. Substituting into 3x^2y^2 + 2y gives 16 at (1, 2).

  • \left. ... \right| sizes the bar to match the fraction automatically. \left. is an invisible left delimiter. \left and \right must come in pairs, so it cannot be left out.
  • \bigg| sets the bar size by hand and needs no partner. For taller or shorter fractions, use \big|, \Big|, or \Bigg| instead.
  • f_x(1,2) or \frac{\partial f}{\partial x}(1,2) treats the partial derivative as a function and puts the point in parentheses. It takes up less vertical space.

Numeric check: 3x^2y^2 + 2y at x = 1, y = 2 is 3·1·4 + 2·2 = 16. The mixed partial 6x^2y + 2 at the same point is 6·1·2 + 2 = 14, which matches equation (4) in the complete example.

Inline and display math

In body text, $\frac{\partial f}{\partial x}$ is set in the smaller text style. The numerator and denominator shrink, and the fraction can also push lines apart. Two forms are more common inside paragraphs:

  • $\partial f/\partial x$: the slash form, close to the height of normal text.
  • $\partial_x f$: the operator-subscript form, common in fields such as partial differential equations.

When you need the full fraction, a higher-order derivative, or an evaluation bar, put the formula in \[...\], equation, or align. To apply the partial operator to an expression in parentheses, use \frac{\partial}{\partial x}\left( x^3y^2 + 2xy \right), and the parentheses will scale with the content.

∂, d, δ, and ∇ are not interchangeable

These symbols look similar, but they stand for different concepts. Swapping one for another changes the mathematical meaning, so pick them by meaning rather than typesetting habit.

ConceptTypical formSource
Ordinary derivative (one variable)dy/dt\frac{\mathrm{d}y}{\mathrm{d}t} or \frac{dy}{dt}
Partial derivative (several variables)∂u/∂t\frac{\partial u}{\partial t}
Variational or functional derivativeδJ/δy\frac{\delta J}{\delta y}
Gradient∇f\nabla f
  • Use d when the function has a single independent variable. An upright \mathrm{d} follows standards such as ISO 80000-2, while many journals keep an italic d. Follow the target journal and stay consistent throughout.
  • Use \partial when the function has several independent variables and you differentiate with respect to one of them.
  • \delta is the Greek letter δ. In the calculus of variations, \delta J/\delta y denotes a functional derivative. It is not a substitute for ∂.
  • \nabla f denotes the gradient. In this example, \nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right).

Optional: shorter commands with a package

If your paper has many derivatives, a package command may help. It is still worth knowing the \frac and \partial forms above: they need no extra package and are the most compatible with journal templates.

The derivative package provides \pdv. The following complete document compiled successfully:

LaTeX
\documentclass[a4paper,11pt]{article}\usepackage{amsmath}\usepackage{derivative}\begin{document}\[  \pdv{f}{x}  \qquad  \pdv[order=2]{f}{x}  \qquad  \pdv{f}{x,y}  \qquad  \pdv{f}{x}_{(1,2)}\]\end{document}

It outputs, in order, a first-order partial, a second-order partial in x, a mixed partial in x and y, and a partial evaluated at a point. In our test, the default style for the last one wraps the fraction in parentheses with the point at the lower right. It does not use a bar. If your journal requires a bar, keep the \left. ... \right| form from earlier, or check the package documentation to change the style.

When using a package:

  • The physics package also defines \pdv, with a different argument format. A mixed partial is \pdv{f}{x}{y} in physics and \pdv{f}{x,y} in derivative. Load only one of them in a document to avoid a clash between commands with the same name.
  • physics also defines commands such as \qty and \div, which may conflict with siunitx or other packages. If a coauthor or the template has already loaded one of these packages, check the preamble first.
  • You can also define your own partial derivative command with \newcommand. Just keep a single notation throughout the document.

Common problems

SymptomCauseFix
Missing $ inserted\partial or \frac used in text modePut the formula in $...$ or \[...\]
Undefined control sequence pointing at \pdvThe package that provides the command is not loadedLoad derivative, or use \frac{\partial f}{\partial x}
Wrong mixed partial outputBoth physics and derivative loaded, or the two argument formats mixedKeep one package and use one argument format
Missing \right. inserted\left. written without `\right`
Second-order partial shows ∂²/∂x² with no fFunction name missing from the numeratorWrite \partial^2 f
Fraction too small in body textInline math uses text styleUse the slash form or display math

Checking locally or in EasyLaTeX

With a local TeX Live or MiKTeX install, run the command twice in the folder that contains main.tex. The second run resolves cross-references:

Shell
pdflatex -interaction=nonstopmode -halt-on-error main.texpdflatex -interaction=nonstopmode -halt-on-error main.tex

Check main.log for errors or unresolved references, then open main.pdf and check the variables in the denominators, the orders, the bar height, and the equation numbers. You can also substitute (1,2) into the first-order and mixed partials and confirm you get 16 and 14, which catches coefficients changed while copying.

In EasyLaTeX, put the example in the project's main file, make sure the right main file is selected, and choose pdfLaTeX for this English article example. If compilation fails, look at the messages and the Original Log in the Bug panel. For help tracking down the problem, give the relevant source and log to the Agent, review each change, and compile again. For an existing journal template, keep the compiler and package settings the template requires.

The complete example, the evaluation snippet, and the derivative example in this article were compiled with pdfLaTeX on TeXLive.net. The logs showed no errors, and the PDFs were checked. They were not tested in the product compiler or in specific journal templates. When merging them into an existing paper, still check package compatibility.

For more basic syntax, see scripts, fractions, brackets, and matrices. For multi-line derivations, see the equation line breaks tutorial, and for common symbols, see the math symbols cheat sheet.

References