Mathematical expressions
Introduction
LaTeX's features for typesetting mathematics make it a compelling choice for writing technical documents. This article shows the most basic commands needed to get started with writing maths using LaTeX.
The well known Pythagorean theorem was
proved to be invalid for other exponents.
Meaning the next equation has no integer solutions:
Mathematical modes
LATEX allows two writing modes for mathematical expressions: the inline math mode and display math mode:
- inline math mode is used to write formulas that are part of a paragraph
- display math mode is used to write expressions that are not part of a paragraph, and are therefore put on separate lines
Inline math mode
You can use any of these "delimiters" to typeset your math in inline mode:
\(...\)
$...$
\begin{math}...\end{math}
They all work and the choice is a matter of taste, so let's see some examples.
In physics, the mass-energy equivalence is stated
by the equation , discovered in 1905 by Albert Einstein.
In physics, the mass-energy equivalence is stated
by the equation , discovered in 1905 by Albert Einstein.
In physics, the mass-energy equivalence is stated
by the equation \begin{math}E=mc^2\end{math}, discovered in 1905 by Albert Einstein.
Display math mode
Use one of these constructions to typeset maths in display mode:
$$...$$
\begin{displaymath}...\end{displaymath}
\begin{equation}...\end{equation}
The mass-energy equivalence is described by the famous equation
discovered in 1905 by Albert Einstein.
In natural units (), the formula expresses the identity
\begin{equation}
E=m
\end{equation}
\begin{equation}
c2=a2+b^2
\end{equation}
Reference guide
description | code | examples |
---|---|---|
Greek letters | \alpha \beta \gamma \rho \sigma \delta \epsilon | |
Binary operators | \times \otimes \oplus \cup \cap | |
Relation operators | < > \subset \supset \subseteq \supseteq | |
Others | \int \oint \sum \prod |
Aligning equations with amsmath
Introduction
The amsmath package provides a handful of options for displaying equations. You can choose the layout that better suits your document, even if the equations are really long, or if you have to include several equations in the same line.
Let's start with a basic example:
\begin{equation} \label{eq1}
\begin{split}
A & = \frac{\pi r^2}{2} \
& = \frac{1}{2} \pi r^2
\end{split}
\end{equation}
Writing a single equation
\begin{equation} \label{eu_eqn}
e^{\pi i} + 1 = 0
\end{equation}
The beautiful equation \ref{eu_eqn} is known as the Euler equation.
Displaying long equations
\begin{equation*}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \
- 12x2y4 - 12xy^5 + 2y^6 - a3b3
\end{equation*}
\begin{equation}
\begin{array}{r}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \
- 12x2y4 - 12xy^5 + 2y^6 - a3b3
\end{array}
\end{equation}
\begin{equation}
\begin{aligned}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \
- 12x2y4 - 12xy^5 + 2y^6 - a3b3
\end{aligned}
\end{equation}
Aligning several equations
\begin{align}
2x - 5y &= 8 \
3x + 9y &= -12
\end{align}
\begin{align}
x&=y & w &=z & a&=b+c\
2x&=-y & 3w&=\frac{1}{2}z & a&=b\
-4 + 5x&=2+y & w+2&=-1+w & ab&=cb
\end{align}
Grouping and centering equations
\begin{gather}
2x - 5y = 8 \
3x^2 + 9y = 3a + c
\end{gather}
Subscripts and superscripts
Introduction
Definite integrals are some of the most common mathematical expressions, so let's see an example:
The command \limits changes the way the limits are displayed in the integral, if not present the limits would be next to the integral symbol instead of being on top and bottom:
More detailed examples
Operators using subscripts and superscripts
Reference guide
LATEX markup | Renders as |
---|---|
a_{n_i} | |
\int_{i=1}^n | |
\sum_{i=1}^{\infty} | |
\prod_{i=1}^n | |
\cup_{i=1}^n | |
\cap_{i=1}^n | |
\oint_{i=1}^n | |
\coprod_{i=1}^n |
Integrals, sums and limits
Integrals
Integral inside text
Multiple integrals
Example of multiple integrals
\begin{gather}
\iint_V \mu(u,v) ,du,dv
\
\iiint_V \mu(u,v,w) ,du,dv,dw
\
\iiiint_V \mu(t,u,v,w) ,dt,du,dv,dw
\
\idotsint_V \mu(u_1,\dots,u_k) ,du_1 \dots du_k
\end{gather}
Example of integrals
Sums and products
Sum inside text
Product inside text
Limits
Limit inside text
Fractions and Binomials
The binomial coefficient, , is defined by the expression:
Displaying fractions
Fractions can be used inline within the paragraph text, for
example , or displayed on their own line,
such as this:
Text-style fractions
Without the \verb|\text{...}| command the result
looks like this:
Size and spacing within typeset mathematics
Fractions typeset within a paragraph typically look like this: . You can force \LaTeX{} to use the larger display style, such as , which also has an effect on line spacing. The size of maths in a paragraph can also be reduced: or . For the \verb|\scriptscriptstyle| example note the reduction in spacing: characters are moved closer to the \textit{vinculum} (the line separating numerator and denominator).
Equally, you can change the style of mathematics normally typeset in display style:
Continued fractions
Fractions can be nested but, in this example, note how the default math styles, as used in the denominator, don't produce ideal results...
\noindent ...so we use \verb|\displaystyle| to improve typesetting:
Here is an example which uses the \texttt{amsmath} \verb|\cfrac| command:
Here is another example, derived from the \texttt{amsmath} documentation, which demonstrates left
and right placement of the numerator using \verb|\cfrac[l]| and \verb|\cfrac[r]| respectively:
A final example
This is the vector .
Brackets and Parentheses
Introduction
Here's an table of listing some common math braces and parentheses used in LATEX:
Type | LATEX markup | Renders as |
---|---|---|
Parentheses; round brackets | (x+y) | |
Brackets; square brackets | [x+y] | |
Braces; curly brackets | { x+y } | |
Angle brackets | \langle x+y \rangle | |
Pipes; vertical bars | x+y| | |
Double pipes | \ \ |x+y\ \ |
常用符号
\begin{array}{r}
\sqrt{x},\sqrt[n]{y}
\end{array}