Markup

Text

Paragraphs are separated by a blank line. Comments are denoted by the percent sign %. Any additional white space is ignored. For example, the next two code blocks are equivalent.

This is a sentence.

This is another sentence.
This         is a          sentence.



This is another sentence. % This is a comment

Italics and bold are denoted with \emph{} and \textbf{}.

This is \emph{emphasized}.

This is \textbf{bold}.

The package amsthm is for automatically numbered theorems.

\documentclass[12pt]{article}

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This is a theorem.
\end{theorem}

\begin{proof}
This is a proof.
\end{proof}

\end{document}

The next code block is a simpler way to have a theorem and proof, but the theorem is not numbered.

\documentclass[12pt]{article}

\begin{document}

\noindent \textbf{Theorem} This is a theorem.

\noindent \emph{Proof.}
This is a proof.
\qed

\end{document}

Accents are added by escaping a character before the letter.

Poincar\'e, G\"odel and L'H\^optial were mathematicians.

Math

In LaTeX, there are inline and display mathematical environments. Inline mathematical environments are denoted by surrounding it with dollar signs $. Display mathematical environments are denoted by surrounding it with \[ and \].

The functions $f$ and $g$ are continuous.
The relation
\[
    2 + 2 = 4
\]
holds.

For display mathematics, the commands \begin{align} and \`end{align} align equations. These are part of the package amsmath, and they replace the use of \[ and \]. Ampersands & specify the alignment. In the next code block, the equal signs = are aligned. The double backslash \\ is a line break.

The relations
\begin{align}
    2 + 2 + 2 + 2
    &= 2 + 2 + 4 \\
    &= 2 + 6 \\
    &= 8 \\
\end{align}
hold.

Mathematical symbols and Greek letters are inserted by a backslash \ and the name of the symbol. For example, the command \geq is the greater-than-or-equal-to symbol, and the command \alpha is the lower-case Greek letter alpha.

Some trigonometric functions are $\sin(x)$, $\cos(x)$, and $\tan(x)$.
The Greek letter $\pi$ often denotes Archimedes's constant.
The relations
\[
\begin{split}
    2 \cdot 2 \cdot 2
    &= 2 \cdot 4 \\
    &= 8 \\
    &\geq 4 \\
\end{split}
\]
hold.
The relation
\[
    \sqrt{4} \geq \frac{1}{2}
\]
holds.

Subscripts and superscripts are indicated by an underscore _ and a caret ^. By default, only the next character is the subscript or superscript. Multiple characters are grouped by braces {}. Subscripts and superscript are automatically formatted correctly with sums, limits and integrals.

The numbers $a_1$ and $a_2$ are such that the relation
\[
    a_1^{10} + a_2^{10}  = 100
\]
holds.
The series
\[
    \sum_{n=1}^{\infinity} \frac{1}{2^n}
\]
converges.
The limit
\[
    \lim_{n \to \infinity} \frac{1}{n}
\]
is $0$.

The size of parentheses and brackets are automatically formatted by the commands \left and \right with their respective symbols. The commands \left. or \right. are placeholders for matching and do not display anything at their location.

The series
\[
    \sum_{n=1}^{\infinity} \left( \frac{1}{2} \right)^n
\]
is geometric.

The commands \begin{pmatrix} and \end{pmatrix} are for matrices.

This
\[
    \begin{pmatrix}
    1 & 2 \\
    3 & 4 \\
    \end{pmatrix}
\]
is a matrix.

Upright text is inserted in a mathematical environment with \mathrm.

The integral
\[
    \int_{0}^{1} x^2 \mathrm{d}x
\]
is $\frac{1}{3}$.

A list of common latex symbols is here.

Custom Commands

Custom commands are declared in the preamble with \newcommand or \DeclareMathOperator. If the command is already defined, then use \renewcommand instead. In the next code block, the [1] means that the commands takes one argument.

\DeclareMathOperator{\grad}{\nabla}
\newcommand{\union}{\cup}
\renewcommand{\phi}{\varphi}
\newcommand{\set}[1]{\left\{ #1 \right\}}