Derivatives in LaTeX: Primes, Leibniz and \frac{d}

f', f'' and \frac{dy}{dx}: which notation to use where, how to write partials, and the prime-spacing trap.

Three notations compete and all three are correct: a prime, a Leibniz fraction, and an operator applied to a function. What changes between them is not the mathematics but what the reader needs to see — the variable, the point of evaluation, or only the order. The prime is a superscript with its own spacing (Sub & Sup), the Leibniz form is a sizing question (Fractions), and the evaluation bar is a bracket that must not close on the left (Brackets).

Which one to use

Situation Write this Because
One or two orders, short form
f'(x), f''(x)
Shortest; fine while the variable is obvious.
Variable must be named
\frac{dy}{dx}
Leibniz form makes it explicit.
Second order, Leibniz
\frac{d^2y}{dx^2}
Exponent on d and on x — never on the fraction.
Partial derivative
\frac{\partial f}{\partial x}
Different symbol, same shape.
Evaluated at a point
\left.\frac{dy}{dx}\right|_{x=0}
Empty left partner plus a vertical bar.
Time derivative
\dot{x}, \ddot{x}
Physics convention; see accents.

The commands

What Type this Renders as
First derivative A prime is a superscript in disguise and sits higher than ^2 would.
f'(x)
f'(x)
Second derivative Two ASCII apostrophes, not a double quote.
f''(x)
f''(x)
nth derivative Braces are required, otherwise you get f^n followed by a parenthesised n.
f^{(n)}(x)
f^{(n)}(x)
Leibniz form A fraction, so it shrinks inline. Use \dfrac or display maths for legibility.
\frac{dy}{dx}
\frac{dy}{dx}
Second Leibniz Both the d and the dx carry their own superscript.
\frac{d^2y}{dx^2}
\frac{d^2y}{dx^2}
Partial The curved d. Same fraction structure as the ordinary derivative.
\frac{\partial f}{\partial x}
\frac{\partial f}{\partial x}
Mixed partial Order of differentiation reads right to left in the denominator.
\frac{\partial^2 f}{\partial x \partial y}
\frac{\partial^2 f}{\partial x \partial y}
Evaluating at a point The empty \left. keeps the tall bar without a matching bracket.
\left.\frac{dy}{dx}\right|_{x=0}
\left.\frac{dy}{dx}\right|_{x=0}
Dot notation Time derivatives, standard in mechanics.
\dot{x} \quad \ddot{x}
\dot{x} \quad \ddot{x}

Worked examples

Same fact, three notations

\frac{d}{dx}x^2 = 2x \qquad \frac{dy}{dx}=2x \qquad y'=2x
\frac{d}{dx}x^2 = 2x \qquad \frac{dy}{dx}=2x \qquad y'=2x

Operator form, Leibniz and prime — pick one per document and stay with it.

Chain rule

\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx}
\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx}

The dot is what stops two fractions reading as a product of letters.

Gradient

\nabla f = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}\right)
\nabla f = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}\right)

Nabla with partials, the usual multivariable form.

Common mistakes

  • Writing f'(x) as f^'(x). The prime is already a superscript; adding ^ produces a doubled mark.
  • Using a straight double quote f"(x) for a second derivative. That renders as two closing quotes, not two primes.
  • f^n(x) when f^{(n)} was meant — the first is f to the power n, the second is the nth derivative.
  • Setting d as an italic variable. Purists use \mathrm{d} for the differential operator; either is fine, but mixing them in one document is not.

Questions about this notation

How do I write d/dx upright?
Wrap it: \frac{\mathrm{d}y}{\mathrm{d}x}. The differential d is an operator rather than a variable, so many house styles set it Roman.
What is the difference between \partial and \delta?
They are different symbols with different meanings. \partial is reserved for partial derivatives; \delta is the lowercase Greek letter, usually a finite change or a variation.
Why does my prime sit too high?
That is correct. LaTeX raises primes above ordinary superscripts so f^2(x) and f'(x) are visually distinguishable.
How do I write a second derivative or a partial derivative?
Prime notation takes repeated marks: f^{\prime}, f^{\prime\prime}, or two bare apostrophes after the letter. Leibniz notation is \frac{d^2y}{dx^2}, and for mixed partials \frac{\partial^2 f}{\partial x \partial y}. Put a thin space before the last differential — \,dx — otherwise the roman d crowds whatever precedes it.

Keep reading

Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.