Derivatives and partial derivatives in LaTeX (frac, partial)

A derivative is a fraction: \frac{dy}{dx}. A partial derivative uses \partial: \frac{\partial f}{\partial x}. The short forms are a prime, f'(x), and a dot, \dot{x}.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{amsmath}

Derivative as a fraction

Numerator and denominator are normal letters. For a higher derivative the exponent goes on the d in the numerator and on the variable in the denominator.

\[
  \frac{dy}{dx}
  \qquad
  \frac{d}{dx} \sin x = \cos x
  \qquad
  \frac{d^2 y}{dx^2}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

dydxddxsin⁡x=cos⁡xd2ydx2\frac{dy}{dx} \qquad \frac{d}{dx} \sin x = \cos x \qquad \frac{d^2 y}{dx^2}

Open this formula in the editor

Partial derivatives

\partial prints the rounded d. \nabla prints the nabla operator for a gradient.

\[
  \frac{\partial f}{\partial x}
  \qquad
  \frac{\partial^2 f}{\partial x \, \partial y}
  \qquad
  \nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right)
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

∂f∂x∂2f∂x ∂y∇f=(∂f∂x,∂f∂y)\frac{\partial f}{\partial x} \qquad \frac{\partial^2 f}{\partial x \, \partial y} \qquad \nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right)

Open this formula in the editor

Primes and dots

An apostrophe after the function name prints a prime. \dot{x} and \ddot{x} put one or two dots over a letter, the usual form for time derivatives; amsmath adds \dddot and \ddddot.

\[
  f'(x)
  \qquad
  f''(x)
  \qquad
  f^{(n)}(x)
  \qquad
  \dot{x}
  \qquad
  \ddot{x}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

f′(x)f′′(x)f(n)(x)x˙x¨f'(x) \qquad f''(x) \qquad f^{(n)}(x) \qquad \dot{x} \qquad \ddot{x}

Open this formula in the editor

Define a derivative command

\newcommand{\deriv}[2]{...} defines a command with two arguments, #1 for the function and #2 for the variable. The example also sets the d upright with \mathrm{d}; change it in one place to switch the whole document.

\newcommand{\dd}{\mathrm{d}}
\newcommand{\deriv}[2]{\frac{\dd #1}{\dd #2}}
\[
  \deriv{y}{x}
  \qquad
  \deriv{}{t} \, e^{2t} = 2 e^{2t}
\]
Result
The compiled example

Open in the editor

Ready-made commands from the physics package

\dv{y}{x} from the physics package writes an ordinary derivative and \pdv{f}{x} a partial one. An optional argument sets the order, and \pdv{f}{x}{y} writes a mixed partial derivative.

Complete document:

\documentclass{article}
\usepackage{physics}
\begin{document}
\[
  \dv{y}{x}
  \qquad
  \dv[2]{y}{x}
  \qquad
  \pdv{f}{x}
  \qquad
  \pdv{f}{x}{y}
\]
\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages