Derivative in LaTeX

Write Leibniz notation as a fraction, \frac{dy}{dx}, and prime notation with an apostrophe, f'(x). Higher orders are \frac{d^2 y}{dx^2} and f''(x), and time derivatives in physics use dots: \dot{x}, \ddot{x}.

Derivative notation

  • \frac{dy}{dx}
    d y d x

    Leibniz notation.

  • \frac{d^2 y}{dx^2}
    d 2 y d x 2

    Second derivative.

  • \frac{d^n y}{dx^n}
    d n y d x n

    nth derivative.

  • f'(x)
    f ′ ( x )

    Prime notation; an apostrophe becomes a prime.

  • f''(x)
    f ″ ( x )

    Second derivative with two primes.

  • f^{(n)}(x)
    f ( n ) ( x )

    nth derivative in prime-style notation.

  • \dot{x}, \; \ddot{x}
    x ˙ , x ¨

    Newton’s dot notation for time derivatives.

  • \frac{\mathrm{d}y}{\mathrm{d}x}
    d y d x

    Upright d, as ISO and some journals require.

  • \odv{y}{x}
    Text mode, no math preview

    Shortcut from the derivative package (\dv in physics); not available in MathJax or KaTeX.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Derivative examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

  • Power rule

    d d x x n = n x n − 1
    LaTeX
    \frac{d}{dx} x^n = n x^{n-1}
  • Chain rule

    d y d x = d y d u ⋅ d u d x
    LaTeX
    \frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}
  • Prime notation

    f ( x ) = x 3 f ′ ( x ) = 3 x 2 f ″ ( x ) = 6 x
    LaTeX
    f(x) = x^3 \quad f'(x) = 3x^2 \quad f''(x) = 6x
  • Taylor series

    f ( x ) = ∑ n = 0 ∞ f ( n ) ( a ) n ! ( x − a ) n
    LaTeX
    f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x - a)^n
  • Equation of motion

    m x ¨ + c x ˙ + k x = 0
    LaTeX
    m \ddot{x} + c \dot{x} + k x = 0
  • Evaluated at a point

    d y d x | x = 1 = 2
    LaTeX
    \left. \frac{dy}{dx} \right|_{x=1} = 2

    \left. is an invisible opening delimiter that lets \right| grow to the fraction’s height.

  • Upright differential

    d 2 x d t 2 = − ω 2 x
    LaTeX
    \frac{\mathrm{d}^2 x}{\mathrm{d}t^2} = -\omega^2 x

Choosing a notation

Leibniz fractions (\frac{dy}{dx}) are clearest in displayed equations and when the variable matters. Primes (f'(x)) are shorter and read well inside a sentence. Dots (\dot{x}) are the physics convention for derivatives with respect to time.

The power in Leibniz notation goes on the d in the numerator and on the variable in the denominator: \frac{d^2 y}{dx^2}. For more than three primes switch to f^{(4)}(x).

Whether the d is italic or upright is a style choice: math books mostly use italic dx, while ISO 80000-2 and many physics journals use upright \mathrm{d}x.

Derivative packages and the web

The derivative package (\odv, \pdv) and the physics package (\dv, \pdv) save typing in Overleaf and handle orders and upright d for you. MathJax and KaTeX do not ship them by default, and our editor rejects them too, so for web pages and Markdown write the fractions out, or define your own macro such as \newcommand{\od}[2]{\frac{d #1}{d #2}}.

LaTeX
% Overleaf, with the derivative package:
\usepackage{derivative}
% ...
\[ \odv{y}{x} \]

% Anywhere, including MathJax:
\newcommand{\od}[2]{\frac{d #1}{d #2}}
\[ \od{y}{x} \]

Common mistakes

  • In the denominator the square belongs to dx as a whole (dx·dx), so it goes on the x.

    Instead of
    \frac{d^2y}{d^2x}
    Write
    \frac{d^2 y}{dx^2}
  • In math mode the apostrophe already becomes a superscript prime; adding ^ causes an error.

    Instead of
    f^'(x)
    Write
    f'(x)
  • \dv comes from the physics package, which MathJax and KaTeX do not load by default.

    Instead of
    \dv{y}{x}  (in Markdown or on a web page)
    Write
    \frac{dy}{dx}

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    Fractions, primes and \dot / \ddot work in any document; \dddot needs amsmath. \odv needs \usepackage{derivative}, \dv needs \usepackage{physics}.

  • MathJax and KaTeX

    MathJax and KaTeX render \frac{dy}{dx}, primes and \dot{x} / \ddot{x} directly. Package shortcuts such as \dv and \odv are not available by default.

  • Microsoft Word

    Word does not convert pasted LaTeX reliably. Build the derivative in the editor here and use Copy for Word to paste it as an editable Word equation.

Derivative in LaTeX: questions

How do I write dy/dx in LaTeX?
As a fraction: \frac{dy}{dx}. Inline, dy/dx also reads well and keeps the line height normal.
How do I write f prime of x?
Type an apostrophe: f'(x). Two apostrophes give the second derivative, f''(x).
How do I write a derivative with a dot on top?
Use \dot{x} for the first time derivative and \ddot{x} for the second. \dddot{x} (amsmath) gives three dots.
Is there a derivative command in LaTeX?
Not in LaTeX itself. The derivative and physics packages add commands such as \odv and \dv; without them, or on the web, write the fraction \frac{d}{dx}.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX