$\DeclareMathOperator{\p}{Pr}$ $\DeclareMathOperator{\P}{Pr}$ $\DeclareMathOperator{\c}{^C}$ $\DeclareMathOperator{\or}{ or}$ $\DeclareMathOperator{\and}{ and}$ $\DeclareMathOperator{\var}{Var}$ $\DeclareMathOperator{\E}{E}$ $\DeclareMathOperator{\std}{Std}$ $\DeclareMathOperator{\Ber}{Bern}$ $\DeclareMathOperator{\Bin}{Bin}$ $\DeclareMathOperator{\Poi}{Poi}$ $\DeclareMathOperator{\Uni}{Uni}$ $\DeclareMathOperator{\Exp}{Exp}$ $\DeclareMathOperator{\N}{N}$ $\DeclareMathOperator{\R}{\mathbb{R}}$ $\newcommand{\d}{\, d}$

Quick Guide to LaTeX

Handout by Roshini Ravi and Chris Piech

LaTeX is a typesetting system that creates beautiful scientific documents. It is the digital language of math, and it was invented right here at Stanford. You can still submit handwritten homeworks, but we recommend using LaTeX.

Below are some examples that should help you get started! As a helpful tip, you can access the LaTeX code for any equation in the course reader by right clicking the equation and clicking "Show Math As" then "TeX Commands".


Core Examples

ExampleLatex
$4^{20}$ 4^{20}
$x_{12}$ x_{12}
$\sqrt{4}$ \sqrt{4}
$\frac{1}{2}$ \frac{1}{2}
$\texttt{code}$ \texttt{code}
$\text{text}$ \text{text}
$4 \cdot 2$ 4 \cdot 2
$r!$ r!
$4 \times 2$ 4 \times 2
$5 \leq x$ 5 \leq x
$5 \geq x$ 5 \geq x
${6 \choose 3}$ {6 \choose 3}
$\sum_{i=1}^{n} i$ \sum_{i=1}^{n} i
$\sum\limits_{i=1}^{n} i$ \sum\limits_{i=1}^{n} i
$\prod_{i=1}^{n} i$ \prod_{i=1}^{n} i
$x_1 + x_2 + \cdots + x_n$ x_1 + x_2 + \cdots + x_n
$\begin{aligned} P(E) &= \frac{|E|}{|S|} \\ &= \frac{1}{4} = 0.25 \end{aligned}$
\begin{aligned}
  P(E) &= \frac{|E|}{|S|} \\
  &= \frac{1}{4} = 0.25
\end{aligned}
          

Compound Examples

ExampleLatex
$n^{m^{2p}}$ n^{m^{2p}}
$(n+m)^{x+y}$ (n+m)^{x+y}
$\frac{n+1}{\frac{m}{3}}$ \frac{n+1}{\frac{m}{3}}
$4^{\frac{2}{3}}$ 4^{\frac{2}{3}}
$\frac{\frac{n+1}{m} \cdot \frac{m-2}{n}}{\frac{m}{3}}$ \frac{\frac{n+1}{m} \cdot \frac{m-2}{n}}{\frac{m}{3}}
$\text{Bin}(n=2, p=3)$ \text{Bin}(n=2, p=3)
${n+m \choose n-3}$ {n+m \choose n-3}