Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 38 ยท Math Typesetting

Fractions, Roots, Sums and Integrals

Typeset fractions, roots, sums, products, integrals, limits and binomials in LaTeX, control limits placement and sizes with \displaystyle, \dfrac and \tfrac, with examples.

Fractions, roots, sums and integrals are the formulas most people open LaTeX for. Each one is a command that takes arguments in braces, and you build larger formulas by nesting them. This lesson covers the constructs you will use in nearly every paper, the rules for limits and sizes, and the ways to keep big expressions readable. All formulas use amsmath conventions, and the editors render them live with KaTeX.

Fractions

\frac{numerator}{denominator} makes a fraction. Both arguments are braced groups, and they can contain anything, including more fractions.

LATEX
\[ \frac{1}{2} \qquad \frac{a+b}{c-d} \qquad \frac{1}{1+\frac{1}{x}} \]

In running text, fractions are shrunk to fit the line. For control, amsmath gives two variants:

Command Effect
\frac{a}{b} Size depends on context (display or text style)
\dfrac{a}{b} Always display size, even inline
\tfrac{a}{b} Always small text size, even in display
\cfrac{a}{b} Continued fractions with full-size parts
a/b or a \over b Slashed or old style. \over is not recommended

A simple numeric fraction in a sentence ("half of it is $1/2$") reads better with a slash than with a tiny stacked \frac.

Roots

\sqrt{x} gives a square root and \sqrt[n]{x} an n-th root. The sign stretches to cover its argument.

LATEX
\[ \sqrt{2} \qquad \sqrt{x^2+y^2} \qquad \sqrt[3]{27} = 3 \qquad \sqrt{1+\sqrt{1+\sqrt{x}}} \]

Sums, products and big operators

The big operators \sum, \prod, \bigcup, \bigcap and \coprod take limits with _ and ^.

LATEX
\[ \sum_{k=1}^{n} k = \frac{n(n+1)}{2}
   \qquad
   \prod_{i=1}^{n} i = n! \]

Inline, the limits sit beside the symbol so the line spacing stays even; in display mode they go above and below. You can override this with \limits and \nolimits:

LATEX
$\sum\limits_{k=1}^{n} k$     % limits above and below, even inline
\[ \sum\nolimits_{k=1}^{n} k \]  % limits at the side, even in display

For a condition under the sum (several lines), use \substack from amsmath:

LATEX
\[ \sum_{\substack{0 \le i \le m \\ 0 < j < n}} P(i,j) \]

Integrals

LATEX
\[ \int_0^1 x^2 \, dx = \frac{1}{3} \]
\[ \int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi} \]
\[ \iint_D f(x,y)\,dA \qquad \oint_C \mathbf{F}\cdot d\mathbf{r} \]

Detail points that separate good typesetting from sloppy:

  • Put a thin space \, before the differential: f(x)\,dx, not f(x)dx.
  • The integral sign leans to the right and puts limits at the side by default (display). \int\limits_a^b puts them above and below.
  • \iint, \iiint, \oint need amsmath in real LaTeX.
  • Some authors write the differential upright: \mathrm{d}x. Choose one style for the whole document, or define a command \newcommand{\dd}{\mathrm{d}}.

Limits and derivatives

\lim, \limsup, \max and similar operators take their limits below in display mode.

LATEX
\[ \lim_{x \to 0} \frac{\sin x}{x} = 1 \]
\[ f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h} \]
\[ \frac{d}{dx} x^n = n x^{n-1} \qquad \frac{\partial^2 u}{\partial x^2} \]

Primes are typed with the apostrophe: f', f''. Derivative fractions are just fractions; the physics and derivative packages offer shortcuts, but plain \frac always works.

Binomials and choose

amsmath provides \binom{n}{k} and its sized variants \dbinom and \tbinom:

LATEX
\[ \binom{n}{k} = \frac{n!}{k!\,(n-k)!} \]

Try it

Play with the formulas below. Each line is a separate formula in display style. Change numbers, swap \frac with \dfrac, and add limits. Errors appear in red.

Fractions, roots, sums and integrals (KaTeX)

Sizes of fractions and sums: the style commands

LaTeX math has four styles: display, text, script and scriptscript. They set sizes automatically. You can force one:

LATEX
$\displaystyle \sum_{k=1}^{n} \frac{1}{k}$   % full size inline
$\textstyle \frac{a}{b}$

Use \displaystyle sparingly in text; if a formula is so large it disturbs the line, it should be displayed on its own instead.

Dots, ellipses and underbraces

LATEX
\[ 1 + 2 + \cdots + n \qquad a_1, a_2, \ldots, a_n \]
\[ \underbrace{1 + 2 + \cdots + n}_{n \text{ terms}} \qquad \overbrace{a+b}^{\text{sum}} \]

\underbrace and \overbrace annotate a part of the formula. Put the label in the subscript or superscript; use \text for words.

Absolute values and norms

Use \lvert x \rvert (from amsmath) instead of |x|, because the first has correct spacing, and \lVert x \rVert for norms. The next lesson covers growing delimiters with \left and \right, plus matrices.

Common mistakes

  • \frac12 works for single digits but \frac{1}{2} is clearer; always brace more than one character.
  • A thin-space omission: \int f(x)dx collides; write \int f(x)\,dx.
  • Using \over in new documents; \frac is the supported form.
  • Writing \sqrt{x}^2 versus \sqrt{x^2}: the root covers only its braced argument.
  • Forgetting amsmath: \dfrac, \binom, \substack and \iint raise "Undefined control sequence" without it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you write the cube root of x?

    The optional argument in square brackets is the index of the root.
  2. 2. Where do the limits of \sum go in display mode by default?

    In display style limits sit above and below; inline they sit at the side. \limits and \nolimits override this.
  3. 3. Why write f(x),dx with , before dx?

    A thin space separates the integrand from the differential, a standard typographic convention.
  4. 4. Which command forces a display-sized fraction inside running text?

    \dfrac always uses display style; \tfrac the small text style.

Summary

  • \frac{a}{b}, \sqrt[n]{x}, \sum, \prod, \int and \lim are the core constructs; nest them freely.
  • amsmath adds \dfrac, \tfrac, \binom and \substack.
  • Limits go beside the symbol inline and above or below in display; \limits and \nolimits override.
  • Always add \, before differentials.
  • Use \underbrace and \overbrace for annotations.

Next: Matrices, Arrays and Delimiters