Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Mathematical Formulas in LaTeX

LaTeX is the standard for writing mathematical formulas. This guide covers the basics: math modes, fractions, roots, sums, integrals, matrices, and common symbols.

Recommended packages Add \usepackage{amsmath, amssymb, amsfonts} in your preamble to access all advanced math features.

Math modes

LaTeX distinguishes two modes for mathematics: inline mode and display mode.

Inline mode

To insert a formula within a paragraph, surround it with $...$ or \(...\):

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath, amssymb}

\begin{document}

The equation $E = mc^2$ is famous.
We also have \(a^2 + b^2 = c^2\) for a right triangle.
\end{document}
L'équation \(E = mc^2\) est célèbre.

Display mode

To display an equation centered on its own line, use \[...\] or the equation environment:

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath, amssymb}

\begin{document}

% Without numbering
\[
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]

% With automatic numbering
\begin{equation}
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}

\end{document}
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]

Fractions and roots

Fractions

Use \frac{numerator}{denominator}:

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

\[ \frac{1}{2} + \frac{3}{4} = \frac{5}{4} \]

\[ \frac{a+b}{c+d} \]

% Nested fractions
\[ \frac{1}{1 + \frac{1}{x}} \]

\end{document}
\[\frac{1}{2} + \frac{3}{4} = \frac{5}{4}\]

Roots

Use \sqrt{} for the square root and \sqrt[n]{} for the nth root:

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

\[ \sqrt{2} \qquad \sqrt{x^2 + y^2} \]

\[ \sqrt[3]{8} = 2 \qquad \sqrt[n]{a} \]

\end{document}
\[\sqrt{x^2 + y^2} \qquad \sqrt[3]{8} = 2\]

Superscripts and subscripts

Use ^ for superscripts and _ for subscripts:

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

$x^2$ --- simple superscript
$x^{10}$ --- multiple superscript (braces required)
$x_i$ --- simple subscript, $x_{ij}$ --- multiple subscript
$a_n^2$ --- both combined, $x_1^{(k)}$ --- advanced notation
% Limits\[ \lim_{n \to \infty} a_n \]

\end{document}
\[x^2 \quad x^{10} \quad x_i \quad x_{ij} \quad a_n^2 \quad \lim_{n \to \infty} a_n\]

Sums, products and integrals

Sums and products

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

% Sum
\[ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} \]

% Product
\[ \prod_{i=1}^{n} i = n! \]

% Double sum
\[ \sum_{i=1}^{n} \sum_{j=1}^{m} a_{ij} \]

\end{document}
\[\sum_{i=1}^{n} i = \frac{n(n+1)}{2}\]

Integrals

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

% Simple integral
\[ \int_0^1 x^2 \, dx \]

% Double integral
\[ \iint_D f(x,y) \, dx \, dy \]

% Triple integral
\[ \iiint_V f(x,y,z) \, dx \, dy \, dz \]

% Contour integral
\[ \oint_C f(z) \, dz \]

\end{document}
\[\int_0^1 x^2 \, dx = \frac{1}{3}\]
Spacing Use \, for a thin space before dx. This improves the readability of integrals.

Matrices

The matrix environment (with the amsmath package) allows you to create matrices:

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

% Matrix with parentheses
\[ \begin{pmatrix}
    a & b \\
    c & d
\end{pmatrix} \]

% Matrix with brackets
\[ \begin{bmatrix}
    1 & 2 & 3 \\
    4 & 5 & 6
\end{bmatrix} \]

% Matrix with bars (determinant)
\[ \begin{vmatrix}
    a & b \\
    c & d
\end{vmatrix} = ad - bc \]

\end{document}
\[\begin{pmatrix} a & b \\ c & d \end{pmatrix} \quad \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}\]
Environment Delimiters Usage
matrix None Matrix without delimiters
pmatrix ( ) Parentheses
bmatrix [ ] Brackets
vmatrix | | Determinant
Vmatrix || || Norm

Common symbols

Greek letters

Command Output Command Output
\alpha \(\alpha\) \beta \(\beta\)
\gamma \(\gamma\) \delta \(\delta\)
\epsilon \(\epsilon\) \theta \(\theta\)
\lambda \(\lambda\) \mu \(\mu\)
\pi \(\pi\) \sigma \(\sigma\)
\omega \(\omega\) \Omega \(\Omega\)

Operators and relations

Command Output Command Output
\times \(\times\) \div \(\div\)
\pm \(\pm\) \mp \(\mp\)
\leq \(\leq\) \geq \(\geq\)
\neq \(\neq\) \approx \(\approx\)
\in \(\in\) \notin \(\notin\)
\subset \(\subset\) \supset \(\supset\)
\cup \(\cup\) \cap \(\cap\)
\infty \(\infty\) \partial \(\partial\)

Number sets (with amssymb)

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

$\mathbb{N}$ --- Natural numbers,
$\mathbb{Z}$ --- Integers,
$\mathbb{Q}$ --- Rationals,
$\mathbb{R}$ --- Reals,
$\mathbb{C}$ --- Complex numbers
\[ \mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C} \]

\end{document}
\[\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}\]

Aligned equations

The align environment lets you align multiple equations on a common point (usually the = sign):

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath, amssymb}

\begin{document}

\begin{align}
    (a+b)^2 &= (a+b)(a+b) \\
            &= a^2 + ab + ba + b^2 \\
            &= a^2 + 2ab + b^2
\end{align}

% Without numbering
\begin{align*}
    f(x) &= x^2 + 2x + 1 \\
         &= (x+1)^2
\end{align*}

\end{document}
\[\begin{align*} (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + ab + ba + b^2 \\ &= a^2 + 2ab + b^2 \end{align*}\]

Mathematical functions

Standard functions must be written in roman (not italic). Use the dedicated commands:

LaTeX
\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

$\sin(x)$ \quad $\cos(x)$ \quad $\tan(x)$

$\log(x)$ \quad $\ln(x)$ \quad $\exp(x)$

\[ \lim_{x \to 0} f(x) \qquad \max(a,b) \qquad \min(a,b) \]

\end{document}
Common mistake Do not write $sin(x)$ which gives \(sin(x)\) (italic). Use $\sin(x)$ which gives \(\sin(x)\) (roman).

Complete example

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath, amssymb}

\title{Mathematical Formulas}
\author{Your name}

\begin{document}
\maketitle

\section{Quadratic equation}

The equation $ax^2 + bx + c = 0$ has solutions:
\[
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]

\section{Notable identities}

\begin{align*}
    (a+b)^2 &= a^2 + 2ab + b^2 \\
    (a-b)^2 &= a^2 - 2ab + b^2 \\
    (a+b)(a-b) &= a^2 - b^2
\end{align*}

\section{Calculus}

The derivative of $f(x) = x^n$ is:
\[
    f'(x) = nx^{n-1}
\]

The integral of $\sin(x)$:
\[
    \int \sin(x) \, dx = -\cos(x) + C
\]

\end{document}

Ready to write formulas?

Create your math documents on Sarmate.net

Create a free account