Integrals, Sums and Limits in LaTeX
\int, \sum, \prod and \lim take their bounds as a subscript and a superscript. This guide shows where those bounds end up, how to move them, and the small details that make calculus look right.
Integrals
$\int f(x) \, dx$ % indefinite
$\int_a^b f(x) \, dx$ % definite
$\int_0^{\infty} e^{-x} \, dx$ % braces around anything longer than one character
\[
\int_0^1 x^2 \, dx = \left[ \frac{x^3}{3} \right]_0^1 = \frac{1}{3}
\]Put a thin space \, before dx so it does not stick to the function. Some styles also set the d upright, with \mathrm{d}x; pick one and keep it throughout. Unlike sums, integral bounds stay to the right of the sign even in display math. \int\limits_0^1 moves them above and below.
Multiple and contour integrals
\iint_D f(x,y) \, dA % double (amsmath)
\iiint_V \rho \, dV % triple (amsmath)
\idotsint % any number (amsmath)
\oint_C \mathbf{F} \cdot d\mathbf{r} % closed path\iint and \iiint draw the signs closer together than typing \int\int. A closed surface integral, \oiint, needs the esint package.
Sums and products
\[
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\qquad
n! = \prod_{k=1}^{n} k
\]
\sum_{i=1}^{m} \sum_{j=1}^{n} a_{ij} % double sum
\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i % two conditions under the signUse \sum, not \Sigma: \Sigma is the letter, small and with its indices at the side. The same goes for \prod and \Pi.
Limits
\lim_{x \to a} f(x)
\lim_{x \to \infty} \frac{1}{x} = 0
\lim_{x \to 0^+} \frac{1}{x} = +\infty % one-sided
\limsup_{n \to \infty} a_n \qquad \liminf_{n \to \infty} a_n
f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\to draws the arrow. \lim is set upright like other function names; typing lim without the backslash gives three italic variables.
Where the bounds go
In display math, the bounds of \sum, \prod and \lim sit above and below the sign. Inside a sentence they move to the side, so the line keeps its normal height. To change that:
| Write | Effect |
|---|---|
\sum\limits_{i=1}^{n} | Bounds above and below, even in a sentence |
\sum\nolimits_{i=1}^{n} | Bounds at the side, even in display |
\displaystyle\sum_{i=1}^{n} | Full-size sign and bounds in a sentence |
\int\limits_a^b | Integral bounds above and below |
Forcing the display form inside a paragraph pushes the lines apart. If a sum needs to be read at full size, it usually deserves its own line.
Series
\[
e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}
= 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots
\]
\[
\sum_{n=0}^{\infty} r^n = \frac{1}{1-r}, \quad |r| < 1
\]\cdots gives centred dots between plus signs; use \ldots between commas.
Other big operators
These take bounds the same way as \sum:
| Command | Meaning |
|---|---|
\bigcup, \bigcap | Union and intersection of many sets |
\bigoplus, \bigotimes | Direct sum, tensor product |
\bigvee, \bigwedge | Logical or, logical and over many terms |
\bigsqcup | Disjoint union |
\coprod | Coproduct |
\bigcup_{i=1}^{n} A_i \qquad \bigoplus_{k=1}^{n} V_kWorked examples
% Riemann sum
\[
\int_a^b f(x) \, dx = \lim_{n \to \infty} \sum_{i=1}^{n} f(x_i^*) \, \Delta x,
\qquad \Delta x = \frac{b - a}{n}
\]
% Expected value of a continuous variable
\[
\mathbb{E}[X] = \int_{-\infty}^{\infty} x \, f_X(x) \, dx
\]
% Cross-entropy loss over N samples and C classes
\[
\mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} \sum_{c=1}^{C} y_{i,c} \log \hat{y}_{i,c}
\]Common mistakes
| Wrong | Right | Why |
|---|---|---|
\int f(x)dx | \int f(x) \, dx | dx needs a little space |
\int_0^10 | \int_0^{10} | Without braces only the 1 is raised |
\Sigma_{i=1}^n | \sum_{i=1}^n | \Sigma is a letter, not an operator |
lim_{x \to 0} | \lim_{x \to 0} | Without the backslash it is three variables |
[\frac{x^2}{2}]_0^1 | \left[\frac{x^2}{2}\right]_0^1 | Brackets should grow to the fraction's height |