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}Leibniz notation.
\frac{d^2 y}{dx^2}Second derivative.
\frac{d^n y}{dx^n}nth derivative.
f'(x)Prime notation; an apostrophe becomes a prime.
f''(x)Second derivative with two primes.
f^{(n)}(x)nth derivative in prime-style notation.
\dot{x}, \; \ddot{x}Newton’s dot notation for time derivatives.
\frac{\mathrm{d}y}{\mathrm{d}x}Upright d, as ISO and some journals require.
- Text mode, no math preview
\odv{y}{x}Shortcut from the
derivativepackage (\dvinphysics); 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.
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
LaTeX\frac{d}{dx} x^n = n x^{n-1}Chain rule
LaTeX\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}Prime notation
LaTeXf(x) = x^3 \quad f'(x) = 3x^2 \quad f''(x) = 6xTaylor series
LaTeXf(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x - a)^nEquation of motion
LaTeXm \ddot{x} + c \dot{x} + k x = 0Evaluated at a point
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
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}}.
% 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 off^'(x)Writef'(x)\dvcomes 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/\ddotwork in any document;\dddotneeds amsmath.\odvneeds\usepackage{derivative},\dvneeds\usepackage{physics}.MathJax and KaTeX
MathJax and KaTeX render
\frac{dy}{dx}, primes and\dot{x}/\ddot{x}directly. Package shortcuts such as\dvand\odvare 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/dxalso 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
derivativeandphysicspackages add commands such as\odvand\dv; without them, or on the web, write the fraction\frac{d}{dx}.
Related LaTeX reference
- Partial Derivative in LaTeXThe ∂ symbol (\partial) inside \frac for first, second and mixed partials, subscript notation, evaluation bars and shortcut macros.
- How to Write a Fraction in LaTeX\frac{numerator}{denominator}, \dfrac and \tfrac for size, continued fractions with \cfrac, slanted fractions and the a/b form.
- Limit in LaTeX\lim_{x \to a}, one-sided limits, limits at infinity, limsup and liminf, and how to keep the condition under lim in running text.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
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