\underline{0.1 General 1}

0.1 General

L^{A}TEX has a special mode for typesetting mathematics. Mathematical text within a paragraph is entered between \( and \), between $ and $ or between

\begin{math} and \end{math}.

Add $a$ squared and $b$ squared
to get $c$ squared. Or, using
a more mathematical approach:
$c^{2}=a^{2}+b^{2}$

Add a squared and b squared to get c squared. Or, using a more mathematical approach: c^{2} = a^{2} + b^{2}

\TeX{} is pronounced as
$\tau\epsilon\chi$.\\[6pt]
100~m$^{3}$ of water\\[6pt]
This comes from my $\heartsuit$

TEX is pronounced as τϵχ.

100 m^{3} of water

This comes from my ♡

\underline{2}

0.2 Displayed Equations

It is preferable to display larger mathematical equations or formulae, rather than to typeset them on separate lines. This means you enclose them in \[

and \] or between \begin{displaymath} and \end{displaymath}. This

produces formulae which are not numbered. If you want L^{A}TEX to number them, you can use the equation environment.

Add $a$ squared and $b$ squared
to get $c$ squared. Or, using
a more mathematical approach:
\begin{displaymath}
c^{2}=a^{2}+b^{2}
\end{displaymath}
And just one more line.

Add a squared and b squared to get c squared. Or, using a more mathematical approach:

c^{2} = a^{2} + b^{2}

And just one more line.

\underline{0.3 Labels 3}

0.3 Labels

You can reference an equation with \label and \ref

\begin{equation} \label{eq:eps}
\epsilon > 0
\end{equation}
From (\ref{eq:eps}), we gather
\ldots

ϵ > 0  (1)

From (1), we gather …

0.4 Inline vs Displayed

Note that expressions will be typeset in a different style if displayed:

$\lim_{n \to \infty}
\sum_{k=1}^n \frac{1}{k^2}
= \frac{\pi^2}{6}$

lim_{n→∞} ∑_{k=1}^{n} \frac{1}{k^{2}} = \frac{π^{2}}{6}

\begin{displaymath}
\lim_{n \to \infty}
\sum_{k=1}^n \frac{1}{k^2}
= \frac{\pi^2}{6}
\end{displaymath}

lim_{n→∞} ∑_{k=1}^{n} \frac{1}{k^{2}} = \frac{π^{2}}{6}

0.5 Math Mode vs Text Mode

There are differences between math mode and text mode. For example in math mode:

1. Most spaces and linebreaks do not have any significance, as all spaces either are derived logically from the mathematical expressions or have to be specified using special commands such as \,, \quad or \qquad.

2. Empty lines are not allowed. Only one paragraph per formula.

3. Each letter is considered to be the name of a variable and will be typeset as such. If you want to typeset normal text within a formula (normal upright font and normal spacing) then you have to enter the text using

the \textrm{...} commands.

\begin{equation}
\forall x \in \mathbf{R}:
\qquad x^{2} \geq 0
\end{equation}

∀x ∈ R :  x^{2} ≥ 0  (2)

\begin{equation}
x^{2} \geq 0\qquad
\textrm{for all }x\in\mathbf{R}
\end{equation}

x^{2} ≥ 0  for all x ∈ R  (3)

0.6 Symbols

Mathematicians can be very fussy about which symbols are used: it would be conventional here to use ‘blackboard bold’, which is obtained using \mathbb from the package amsfonts or amssymb. The last example becomes

\begin{displaymath}
x^{2} \geq 0\qquad
\textrm{for all }x\in\mathbb{R}
\end{displaymath}

x^{2} ≥ 0 for all x ∈ ℝ

0.7 Grouping in Math Mode

Most math mode commands act only on the next character. So if you want a command to affect several characters, you have to group them together using curly braces: {...}.

\begin{equation}
a^x+y \neq a^{x+y}
\end{equation}

a^{x} + y ≠ a^{x+y} (4)

\underline{8}

0.8 Greek Letters

Lowercase Greek letters are entered as \alpha, \beta, \gamma, …, uppercase letters are entered as \Gamma, \Delta, … ^{1}

$\lambda,\xi,\pi,\mu,\Phi,\Omega$      λ, ξ, π, μ, Φ, Ω

1There is no uppercase Alpha defined in L^{A}TEX 2ε because it looks the same as a normal roman A. Once the new math coding is done, things will change.

0.9 Exponents and Subscripts  9

0.9 Exponents and Subscripts

Exponents and Subscripts can be specified using the ^and the _character.

$a_{1}$ \qquad $x^{2}$ \qquad
$e^{-\alpha t}$ \qquad
$a^{3}_{ij}$\\
$e^{x^2} \neq {e^x}^2$

{a_{1}  x^{2}  e^{−αt}  a_{ij}^{3} \atop e^{x^{2}} ≠ e^{x}^{2}}

0.10 Square Roots

The square root is entered as \sqrt, the n^{th} root is generated with \sqrt[n]. The size of the root sign is determined automatically by L^{A}TEX. If just the sign is needed, use \surd.

$\sqrt{x}$ \qquad
$\sqrt{ x^{2}+\sqrt{y} }$
\qquad $\sqrt[3]{2}$\\[3pt]
$\surd[x^2 + y^2]$

\begin{matrix}\sqrt{x} & \sqrt{x^{2} + \sqrt{y}} & \sqrt[3]{2} \\ √[x^{2} + y^{2}] \end{matrix}

0.11 Long Horizontal Things

The commands \overline and \underline create horizontal lines directly over or under an expression.

$\overline\{m+n\}$                       \overline{m + n}

The commands \overbrace and \underbrace create long horizontal braces over or under an expression.

$\underbrace\{ a+b+\cdots+z \}_\{26\}$     \underbrace{a + b + · · · + z}_{26}

0.12 Accents

To add mathematical accents such as small arrows or tilde signs to variables, you can use the commands given in Table ?? on page ??. Wide hats and tildes covering several characters are generated with \widetilde and \widehat. The ' symbol gives a prime.

\begin{displaymath}
y=x^{2}\qquad y'=2x\qquad y''=2
\end{displaymath}

y = x^{2}  y′ = 2x  y′′ = 2

Vectors often are specified by adding small arrow symbols on top of a variable. This is done with the \vec command. The two commands \overrightarrow and \overleftarrow are useful to denote the vector from A to B.

\begin{displaymath}
\vec a\quad\overrightarrow{AB}
\end{displaymath}

a⃗ \overrightarrow{AB}

\underline{0.13 Names 13}

0.13 Names

Names of log-like functions are often typeset in an upright font and not in italic like variables. Therefore L^{A}TEX supplies the following commands to typeset the most important function names:

    \arccos  \cos   \csc  \exp  \ker     \limsup  \min  \sinh
    \arcsin  \cosh  \deg  \gcd  \lg      \ln      \Pr   \sup
    \arctan  \cot   \det  \hom  \lim     \log     \sec  \tan
    \arg     \coth  \dim  \inf  \liminf  \max     \sin  \tanh

\[\lim_{x \rightarrow 0}
\frac{\sin x}{x}=1\]

lim_{x→0} \frac{sin x}{x} = 1

For the modulo function, there are two commands: \bmod for the binary operator “a mod b” and \pmod for expressions such as “x ≡ a (mod b).”

0.14 Fractions

A built-up fraction is typeset with the \frac{...}{...} command. Often the slashed form 1/2 is preferable, because it looks better for small amounts of ‘fraction material.’

$1\frac{1}{2}$~hours
\begin{displaymath}
\frac{ x^{2} }{ k+1 }\qquad
x^{ \frac{2}{k+1} }\qquad
x^{ 1/2 }
\end{displaymath}

{1\frac{1}{2} hours \atop \frac{x^{2}}{k + 1}  x^{\frac{2}{k+1}}  x^{1/2}}

0.15 Binomials

To typeset binomial coefficients or similar structures, you can use either the

command {... \choose ...} or {... \atop ...}. The second command

produces the same output as the first one, but without braces. (Note that the usage of these old-style commands is expressly forbidden by the amsmath package. They are replaced by \binom and \genfrac. The latter is a superset of all related constructs. e.g. you may get a similar construct to \atop by

\newcommand{\newatop}[2]{\genfrac{}{}{0pt}{1}{#1}{#2}})

\begin{displaymath}
{n \choose k}\qquad {x \atop y+2}
\end{displaymath}

\binom{n}{k} {x \atop y + 2}

For binary relations it may be useful to stack symbols over each other. \stackrel puts the symbol given in the first argument in superscript-like size over the second which is set in its usual position.

0.16 Some Large Symbols

\begin{displaymath}
\int f_N(x) \stackrel{!}{=} 1
\end{displaymath}

∫ f_{N}(x) =^{!} 1

The integral operator is generated with \int, the sum operator with \sum and the product operator with \prod. The upper and lower limits are specified with ^and _like subscripts and superscripts. ^{2}

\begin{displaymath}
\sum_{i=1}^{n} \qquad
\int_{0}^{\frac{\pi}{2}} \qquad
\prod_\epsilon
\end{displaymath}

∑_{i=1}^{n}  ∫0^{\frac{π}{2}}  ∏_{ϵ}

2AMS-L^{A}TEXin addition has multiline super-/subscripts

0.17 Large Brackets

For braces and other delimiters, there exist all types of symbols in TEX (e.g. [ ⟨ ∥ ↕). Round and square braces can be entered with the corresponding keys, curly braces with \{, all other delimiters are generated with special commands (e.g. \updownarrow). For a list of all delimiters available, check table ?? on page ??.

\begin{displaymath}
{a,b,c}\neq\{a,b,c\}
\end{displaymath}

a, b, c ≠ {a, b, c}

If you put the command \left in front of an opening delimiter or \right in front of a closing delimiter, TEX will automatically determine the correct size of the delimiter. Note that you must close every \left with a corresponding \right, and that the size is determined correctly only if both are typeset on the same line. If you don’t want anything on the right, use the invisible ‘\right.’!

\begin{displaymath}
1 + \left( \frac{1}{ 1-x^{2} }
    \right) ^3
\end{displaymath}

1 + (\frac{1}{1 − x^{2}} )^{3}

In some cases it is necessary to specify the correct size of a mathematical delimiter by hand, which can be done using the commands \big, \Big, \bigg and \Bigg as prefixes to most delimiter commands.^{3}

$\Big( (x+1) (x-1) \Big) ^{2}$\\
$\big(\Big(\bigg(\Bigg($\quad
$\big\}\Big\}\bigg\}\Bigg\}$\quad
$\big\|\Big\|\bigg\|\Bigg\|$

\begin{matrix}((x + 1)(x − 1))^{2} \\ ( & ( & ( & ( & \} & \} & \} & \} & ∥ & ∥ & ∥ & ∥ \end{matrix}

3These commands do not work as expected if a size changing command has been used, or the 11pt or 12pt option has been specified. Use the exscale or amsmath packages to correct this behaviour.

0.18 Dots

To enter three dots into a formula, you can use several commands. \ldots typesets the dots on the baseline, \cdots sets them centred. Besides that, there are the commands \vdots for vertical and \ddots for diagonal dots. You can find another example in section 0.20.

\begin{displaymath}
x_{1},\ldots,x_{n} \qquad
x_{1}+\cdots+x_{n}
\end{displaymath}

x_{1}, …, x_{n} x_{1} + ⋯ + x_{n}

0.19 Math Spacing

If the spaces within formulae chosen by TEX are not satisfactory, they can be adjusted by inserting special spacing commands. There are some commands for small spaces: \, for \frac{3}{18} quad ( ), \: for \frac{4}{18} quad ( ) and \; for \frac{5}{18} quad ( ). The escaped space character \␣ generates a medium sized space and \quad ( ) and \qquad ( ) produce large spaces. The size of a \quad corresponds to the width of the character ‘M’ of the current font. The \! command produces a negative space of −\frac{3}{18} quad ( ).

\newcommand{\ud}{\mathrm{d}}
\begin{displaymath}
\int\!\!\!\int_{D} g(x,y)
  \, \ud x\, \ud y
\end{displaymath}
instead of
\begin{displaymath}
\int\int_{D} g(x,y)\ud x \ud y
\end{displaymath}

∫∫_{D} g(x, y) dx dy

instead of

∫ ∫_{D} g(x, y)dxdy

Note that ‘d’ in the differential is conventionally set in roman.

AMS-L^{A}TEX provides another way for finetuning the spacing between multiple integral signs, namely the \iint, \iiint, \iiiint, and \idotsint commands. With the amsmath package loaded, the above example can be typeset this way:

\newcommand{\ud}{\mathrm{d}}
\begin{displaymath}
\iint_{D} \, \ud x \, \ud y
\end{displaymath}

∫∫ _{D} dx dy

See the electronic document testmath.tex (distributed with AMS-L^{A}TEX) or Chapter 8 of “The LaTeX Companion” for further details.

0.20 Array Env

To typeset arrays, use the array environment. It works somewhat similar to the tabular environment. The \\ command is used to break the lines.

\begin{displaymath}
\mathbf{X} =
\left( \begin{array}{ccc}
x_{11} & x_{12} & \ldots \\
x_{21} & x_{22} & \ldots \\
\vdots & \vdots & \ddots
\end{array} \right)
\end{displaymath}

X = ( \begin{matrix}x_{11} & x_{12} & … \\ x_{21} & x_{22} & … \\ ⋮ & ⋮ & ... \end{matrix} )

The array environment can also be used to typeset expressions which have one big delimiter by using a “.” as an invisible \right delimiter:

\begin{displaymath}
y = \left\{ \begin{array}{ll}
 a & \textrm{if $d>c$}\\
 b+x & \textrm{in the morning}\\
 l & \textrm{all day long}
  \end{array} \right.
\end{displaymath}

y = \{ \begin{matrix}a & if d > c \\ b + x & in the morning \\ l & all day long \end{matrix}

As within the tabular environment you can also draw lines in the array environent, e.g. separating the entries of a matrix:

\begin{displaymath}
\left(\begin{array}{c|c}
 1 & 2 \\
\hline
3 & 4
\end{array}\right)
\end{displaymath}

( \begin{matrix}1 & 2 \\ 3 & 4 \end{matrix} )

0.21 Equation Array Env

For formulae running over several lines or for equation systems, you can use the environments eqnarray, and eqnarray* instead of equation. In eqnarray each line gets an equation number. The eqnarray* does not number anything.

The eqnarray and the eqnarray* environments work like a 3-column table of the form {rcl}, where the middle column can be used for the equal sign or the not-equal sign. Or any other sign you see fit. The \\ command breaks the lines.

\begin{eqnarray}
f(x) & = & \cos x     \\
f'(x) & = & -\sin x   \\
\int_{0}^{x} f(y)dy &
 = & \sin x
\end{eqnarray}

f(x) = cos x  (5)
f′(x) = − sin x  (6)
∫_{0}^{x} f(y)dy = sin x  (7)

Notice that the space on either side of the the equal signs is rather large. It can be reduced by setting \setlength\arraycolsep{2pt}, as in the next example.

0.22 Long Equations

Long equations will not be automatically divided into neat bits. The author has to specify where to break them and how much to indent. The following two methods are the most common ones used to achieve this.

{\setlength\arraycolsep{2pt}
\begin{eqnarray}
\sin x & = & x -\frac{x^{3}}{3!}
+\frac{x^{5}}{5!}-{}
          \nonumber\\
& & {}-\frac{x^{7}}{7!}+{}\cdots
\end{eqnarray}}

\begin{aligned}sin x & = & x − \frac{x^{3}}{3!} + \frac{x^{5}}{5!} − \\ & & − \frac{x^{7}}{7!} + ⋯ & (8) \end{aligned}

\begin{eqnarray}
\lefteqn{ \cos x = 1
-\frac{x^{2}}{2!} +{} }
          \nonumber\\
& & {}+\frac{x^{4}}{4!}
-\frac{x^{6}}{6!}+{}\cdots
\end{eqnarray}

\begin{matrix}cos x = 1 − \frac{x^{2}}{2!} + \\ + \frac{x^{4}}{4!} − \frac{x^{6}}{6!} + ⋯ & (9) \end{matrix}

The \nonumber command causes L^{A}TEX to not generate a number for this equation.

It can difficult be to get vertically aligned equations to look right with these methods; the package amsmath provides a more powerful set of alternatives. (see split and align environments).

\underline{0.23 Phantom 23}

0.23 Phantom

We can’t see phantoms, but they still occupy some space in the minds of a lot of people. L^{A}TEX is no different. We can use this for some interesting spacing tricks.

When vertically aligning text using ^and _L^{A}TEX sometimes is just a little bit too helpful. Using the \phantom command you can reserve space for characters which do not show up in the final output. Best is to look at the following examples.

\begin{displaymath}
{}^{12}_{\phantom{1}6}\textrm{C}
\qquad \textrm{as opposed to} \qquad
{}^{12}_{6}\textrm{C}
\end{displaymath}

_{6}^{12}C  as opposed to  _{6}^{12}C

\begin{displaymath}
\Gamma_{ij}^{\phantom{ij}k}
\qquad \textrm{as opposed to} \qquad
\Gamma_{ij}^{k}
\end{displaymath}

Γ_{ij}^{k}  as opposed to  Γ_{ij}^{k}

0.24 Math Font Size

In math mode, TEX selects the font size according to the context. Superscripts, for example, get typeset in a smaller font. If you want to typeset part of an equation in roman, don’t use the \textrm command, because the font size switching mechanism will not work, as \textrm temporarily escapes to text mode. Use \mathrm instead to keep the size switching mechanism active. But pay attention, \mathrm will only work well on short items. Spaces are still not active and accented characters do not work.^{4}

\begin{equation}
2^{\textrm{nd}} \quad
2^{\mathrm{nd}}
\end{equation}

2^{nd} 2^{nd} (10)

Nevertheless, sometimes you need to tell L^{A}TEX the correct font size. In math mode, the fontsize is set with the four commands:

\displaystyle (123), \textstyle (123), \scriptstyle (123) and
\scriptscriptstyle (123).

4The AMS-L^{A}TEX package makes the \textrm command work with size changing.

0.25 Limits and Styles  25

0.25 Limits and Styles

Changing styles also affects the way limits are displayed.

\begin{displaymath}
\mathop{\mathrm{corr}}(X,Y)=
 \frac{\displaystyle
   \sum_{i=1}^n(x_i-\overline x)
   (y_i-\overline y)}
  {\displaystyle\biggl[
 \sum_{i=1}^n(x_i-\overline x)^2
\sum_{i=1}^n(y_i-\overline y)^2
\biggr]^{1/2}}
\end{displaymath}

corr(X, Y) = \frac{∑_{i=1}^{n}(x_{i} − \overline{x})(y_{i} − \overline{y})}{[∑_{i=1}^{n}(x_{i} − \overline{x})^{2} ∑_{i=1}^{n}(y_{i} − \overline{y})^{2}]^{1/2}}

This is one of those examples in which we need larger brackets than the standard \left[ \right] provides.

0.26 Theorems, Laws, …

When writing mathematical documents, you probably need a way to typeset “Lemmas”, “Definitions”, “Axioms” and similar structures. L^{A}TEX supports this with the command

\newtheorem{name}[counter]{text}[section]

The name argument, is a short keyword used to identify the “theorem”. With the text argument, you define the actual name of the “theorem” which will be printed in the final document.

The arguments in square brackets are optional. They are both used to specify the numbering used on the “theorem”. With the counter argument you can specify the name of a previously declared “theorem”. The new “theorem” will then be numbered in the same sequence. The section argument allows you to specify the sectional unit within which you want your “theorem” to be numbered.

After executing the \newtheorem command in the preamble of your document, you can use the following command within the document.

     \begin{name}[text]

This is my interesting theorem

     \end{name}

0.27 Theorems etc Example  27

0.27 Theorems etc Example

This should be enough theory. The following examples will hopefully remove the final remains of doubt and make it clear that the \newtheorem environment is way too complex to understand.

% definitions for the document
% preamble
\newtheorem{law}{Law}
\newtheorem{jury}[law]{Jury}
%in the document
\begin{law} \label{law:box}
Don't hide in the witness box
\end{law}
\begin{jury}[The Twelve]
It could be you! So beware and
see law~\ref{law:box}\end{jury}
\begin{law}No, No, No\end{law}

Law 1 Don’t hide in the witness box

Jury 2 (The Twelve) It could be you! So beware and see law 1

Law 3 No, No, No

The “Jury” theorem uses the same counter as the “Law” theorem. Therefore it gets a number which is in sequence with the other “Laws”. The argument in square brackets is used to specify a title or something similar for the theorem.

\flushleft
\newtheorem{mur}{Murphy}[section]
\begin{mur}
If there are two or more
ways to do something, and
one of those ways can result
in a catastrophe, then
someone will do it.\end{mur}

Murphy 0.27.1 If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.

The “Murphy” theorem gets a number which is linked to the number of the current section. You could also use another unit, for example chapter or subsection.

0.28 Bold symbols

It is quite difficult to get bold symbols in L^{A}TEX; this is probably intentional as amateur typesetters tend to overuse them. The font change command \mathbf gives bold letters, but these are roman (upright) whereas mathematical symbols are normally italic. There is a \boldmath command, but this can only be used outside mathematics mode. It works for symbols too.

\begin{displaymath}
\mu, M \qquad \mathbf{M} \qquad
\mbox{\boldmath $\mu, M$}
\end{displaymath}

μ, M  M  μ, M

Notice that the comma is bold too, which may not be what is required.

The package amsbsy (included by amsmath) makes this much easier as it includes a \boldsymbol command.

\begin{displaymath}
\mu, M \qquad
\boldsymbol{\mu}, \boldsymbol{M}
\end{displaymath}

μ, M μ, M

0.28 Bold symbols  29