StackExchange Post

Align and Aligned

1
2
3
4
5
6
7
\begin{align}
\sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\
 & = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\
 & = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\
 & = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\
 & \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right)
\end{align}
\[\begin{align} \sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\ & = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\ & = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\ & = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\ & \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right) \end{align}\]
1
2
3
4
5
6
7
\begin{aligned}
\sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\
 & = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\
 & = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\
 & = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\
 & \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right)
\end{aligned}
\[\begin{aligned} \sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\ & = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\ & = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\ & = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\ & \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right) \end{aligned}\]

Definitions by cases

1
2
3
4
5
6
7
8
$$
f(n) =
\begin{cases}
n/2,  & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd}
\end{cases}
$$

\[f(n) = \begin{cases} n/2, & \text{if $n$ is even} \\ 3n+1, & \text{if $n$ is odd} \end{cases}\]

To get a larger vertical space between cases we can use \[2ex] instead of \. For example, you get this:

1
2
3
4
5
f(n) =
\begin{cases}
\frac{n}{2},  & \text{if $n$ is even} \\[2ex]
3n+1, & \text{if $n$ is odd}
\end{cases}
\[f(n) = \begin{cases} \frac{n}{2}, & \text{if $n$ is even} \\[2ex] 3n+1, & \text{if $n$ is odd} \end{cases}\]

iint

For double and triple integrals, don’t use \int\int or \int\int\int. Instead use the special forms \iint and \iiint:

Using \newcommand

It’s enough to insert something like

1
$ \newcommand{\SES}[3]{ 0 \to #1 \to #2 \to #3 \to 0 } $

at the top of your post (remember the dollars!). Then you can just use your commands as you are used to do: in my example typing ` \SES{A}{B}{C} ` will produce the following:

$ \newcommand{\SES}[3]{ 0 \to #1 \to #2 \to #3 \to 0 } $

\[\SES{A}{B}{C}\]

It’s also possible to use plain \def:

1
\def\ses#1#2#3{0 \to #1 \to #2 \to #3 \to 0}

$\def\ses#1#2#3{0 \to #1 \to #2 \to #3 \to 0}$

and then \ses{A}{B}{C} will produce the same output.

\[\ses{A}{B}{C}\]

Tags and References

For longer calculations (or referring to other post’s results) it is convenient to use the tagging/labelling/referencing system. To tag an equation use \tag{yourtag}, and if you want to refer to that tag later on, add \label{somelabel} right after the \tag. It is not necessary that yourtag and somelabel are the same, but it usually is more convenient to do so:

1
$$ a := x^2-y^3 \tag{mmtag}\label{mmtag} $$
\[a := x^2-y^3 \tag{mmtag}\label{mmtag}\]

In order to refer to an equation, just use \eqref{somelabel}

1
$$ a+y^3 \stackrel{\eqref{mmtag}}= x^2 $$
\[a+y^3 \stackrel{\eqref{mmtag}}= x^2\]

or \ref{somelabel}

$\ref{mmtag}$

or \eqref{somelabel}

$\eqref{mmtag}$

1
Equations are usually referred to as $\eqref{*}$, but you can also use $\ref{*}$.

Multi-line equation

Multi-line equation is actually just one equation rather than several equations. So the correct environment is aligned instead of align.

\[\begin{equation}\begin{aligned} a &= b + c \\ &= d + e + f + g \\ &= h + i \end{aligned}\end{equation}\tag{2}\label{eq2}\]

Equation $\eqref{eq2}$ is a multi-line equation. The code to produce equation $\eqref{eq2}$ is

1
2
3
4
5
$$\begin{equation}\begin{aligned}
a &= b + c \\
  &= d + e + f + g \\
  &= h + i
\end{aligned}\end{equation}\tag{2}\label{eq2}$$

Multiple aligned equations

For multiple aligned equations, we use the align environment.

\[\begin{align} a &= b + c \tag{3}\label{eq3} \\ x &= yz \tag{4}\label{eq4}\\ l &= m - n \tag{5}\label{eq5} \end{align}\]

Equation $\eqref{eq3}$, $\eqref{eq4}$ and $\eqref{eq5}$ are multiple equations aligned together. The code to produce these equations is,

1
2
3
4
5
$$\begin{align}
a &= b + c \tag{3}\label{eq3} \\
x &= yz \tag{4}\label{eq4}\\
l &= m - n \tag{5}\label{eq5}
\end{align}$$

Reasoning

\implies (⟹) is a marginally preferable alternative to \Rightarrow (⇒) for implication.

There’s also \iff ⟺ and \impliedby ⟸.

\to (→) is preferable to \rightarrow or \longrightarrow for things like 𝑓:𝐴→𝐵. The reverse is \gets (←).

Linear programming

Formulation: A theoretical LPP can be typeset as

1
2
3
4
5
\begin{array}{ll}
\text{maximize}  & c^T x \\
\text{subject to}& d^T x = \alpha \\
&0 \le x \le 1.
\end{array}
\[\begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array}\]

To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients.

1
2
3
4
5
6
7
\begin{alignat}{5}
  \max \quad        & z = &   x_1  & + & 12 x_2  &   &       &         && \\
  \mbox{s.t.} \quad &     & 13 x_1 & + & x_2     & + & 12x_3 & \geq 5  && \tag{constraint 1} \\
                    &     & x_1    &   &         & + & x_3   & \leq 16 && \tag{constraint 2} \\
                    &     & 15 x_1 & + & 201 x_2 &   &       & =    14 && \tag{constraint 3} \\
                    &     & \rlap{x_i \ge 0, i = 1, 2, 3}
\end{alignat}
\[\begin{alignat}{5} \max \quad & z = & x_1 & + & 12 x_2 & & & && \\ \mbox{s.t.} \quad & & 13 x_1 & + & x_2 & + & 12x_3 & \geq 5 && \tag{constraint 1} \\ & & x_1 & & & + & x_3 & \leq 16 && \tag{constraint 2} \\ & & 15 x_1 & + & 201 x_2 & & & = 14 && \tag{constraint 3} \\ & & \rlap{x_i \ge 0, i = 1, 2, 3} \end{alignat}\]

Latex Math Blocks

this is some useful or important information.
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$ $\tag{them11}\label{thm11} $
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$
To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients. $$ \begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array} $$ $\tag{mylemma}\label{mylemma} $

this is the lemma $\eqref{mylemma}$.

this is the theorem $\eqref{thm11}$.

The link to the lemma is the lemma

The link to the example is the example

Comments