Выберите одно из ключевых слов слева ...


Время чтения: ~15 min

TeX (pronounced tech) is an open-source typesetting engine for technical documents. It was created in the late 1970s by Donald Knuth, and it has since become almost universally adopted in the mathematical research community and widely adopted in other scientific communities. The most common way to use TeX is through LaTeX (lay-tex or lah-tex; both pronunciations are common), which provides extra tools that make TeX easier to use.

A LaTeX document consists of a plain text file which is processed by a command-line utility called pdflatex to produce a PDF. Here's a snippet of a TeX source file followed by the corresponding page in the resulting PDF (this is from a real project; the full source and PDF for which are available here):

In this course, we will not learn to typeset documents in LaTeX, because we will use more dynamic alternatives which are built on web technologies. However, these alternatives do rely on LaTeX's legacy for one important purpose: rendering mathematical expressions. For example, the text

\operatorname{KL}(p\|q) =
  \int_{\mathbb{R}^n}p(x) \log \frac{p(x)}{q(x)} \, \mathrm{d}x.

renders as

\begin{align*}\operatorname{KL}(p\|q) = \int_{\mathbb{R}^n}p(x) \log \frac{p(x)}{q(x)} \, \mathrm{d}x.\end{align*}

We will discuss some basics of specifying math expressions in LaTeX, but recent developments have made it easy to produce LaTeX source code without having to type it out directly. You can produce a math expression using a graphical user interphase like SymboLab and then use MathPix to snip the resulting expression on your screen and convert it to LaTeX. MathPix works directly from the taskbar, so the whole process is quite efficient. Alternatively, if you have an iPhone, you can use install a handwriting-input keyboard for LaTeX by installing the app MathKey.

LaTeX expression markup

Superscripts and subscripts

Inline mathematical expressions in LaTeX are delimited by dollar signs. For example:

The Pythagorean theorem says that $a^2 + b^2 = c^2$, where
$a$ and $b$ are the lengths of the legs and $c$ is the
length of the hypotenuse of a right triangle.

renders as:

The Pythagorean theorem says that a^2 + b^2 = c^2, where a and b are the lengths of the legs and c is the length of the hypotenuse of a right triangle.

As demonstrated in the example above, superscripts are indicated with carats. Subscripts are indicated with underscores:

a_1, a_2, a_3, \ldots, a_{100}


\begin{align*}a_1, a_2, a_3, \ldots, a_{100}\end{align*}

Curly braces are used for grouping and do not appear in the rendered expression. If you want a literal curly brace, it must be escaped with a backslash:


is the LaTeX code for



The syntax for fractions in LaTeX is \frac{numerator}{denominator}. For example, \frac{x^3}{3} renders as \frac{x^3}{3}. Fractions can be nested:


looks like


Greek symbols and math symbols

Greek letters may be typeset by putting a backslash in front of the letter name. For example, \alpha, \beta, \gamma becomes \alpha, \beta, \gamma.

Many common math symbols have built-in support in LaTeX:

\sum_{i=1}^{10} i^2 = 385 + 0 \times \int_1^\infty dx/x^2

\begin{align*}\sum_{i=1}^{10} i^2 = 385 + 0 \times \int_1^\infty dx/x^2\end{align*}

Styling text

Math text is styled using various commands which begin with \math. For example, \mathrm prevents letters in equations from rendering in italics, while \mathbf renders letters or numbers in boldface.

|\mathbf{a}|^2 = \mathbf{a} \cdot \mathbf{a}

is the code for

\begin{align*}|\mathbf{a}|^2 = \mathbf{a} \cdot \mathbf{a}\end{align*}

Blackboard bold symbols like \mathbb{R}, \mathbb{Z}, \mathbb{N} are typeset like \mathbb{R}, \mathbb{Z}, \mathbb{N}.


Delimiters (like parentheses or brackets) can be made to reach vertically as far as necessary to properly enclose the content they surround. The delimiting characters must be preceded by \left and right.

\mathrm{e}^x = \lim_{n \to \infty} \left( 1 + \frac{x}{n} \right)^n

renders as

\begin{align*}\mathrm{e}^x = \lim_{n \to \infty} \left( 1 + \frac{x}{n} \right)^n\end{align*}

Displayed equations

Multi-line displayed equations (which are rendered in the center of the page and on their own lines) open with \begin{align*} and close with \end{align*}. Lines are separated with a double backslash, and an ampersand goes in front of the character in each line that should be used for alignment (usually the equals sign):

(x+y)^2 &= (x+y)(x+y) \\\
        &= x^2 + 2xy + y^2

gives the equation

\begin{align*}(x+y)^2 &= (x+y)(x+y) \\ &= x^2 + 2xy + y^2\end{align*}


The easiest way to create a matrix is to use a bmatrix environment. Rows are separated with a double backslash, and entries within each row are separated by ampersands.

1 & 2 \\\
3 & 4


\begin{align*}\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}\end{align*}

Bruno Bruno