About

LaTeX is pronounced "lah-tek".
LaTeX stands for Lamport TeX or Lamport Typesetting System.

Beautiful typesetting made simple

Free online LaTeX editor: https://latexbase.com/
Document

Save a text document with a .tex file format. The LaTeX compiler will interpret that text file and generate a .pdf file from it.

Minimal document:

\documentclass{article}
\begin{document}
  Hello World!
\end{document}

Commands

Commands start with a \ (backslash) and may be followed by {options}.


\command{options}

Environment

An environment defines a section of the document with shared layout settings.

You define environments with "begin" and "end" commands

\begin{document}
    \begin{environment1}
        \begin{environment1}
        \end{environment2}
    \end{environment2}
\end{document}

Environments must be nested like a valid xml document.

The "document" environment must be the root environment of all other environments.

Preamble

The area before the \begin{document} command. Global variables, like Title, can be set here.

Comments

Start a line with %, everything to the end of line will be ignored by the compiler.


% my comments

You can also use the "comment" package to create whole environments that will be ignored.


\usepackage{comment}
\begin{comment}
    comments
    comments
\end{comment}

Sections

Sections and subsections will be automatically numbered.


\section{}
\subsection{}
\subsubsection{}
\paragraph{}
\subparagraph{}

Package

You can import additional LaTeX packages.


\usepackage{package_name}

Image

To subtitle an image or figure

\usepackage{graphicx}
\begin{figure}
  \includegraphics[width=\linewidth]{boat.jpg}
  \caption{A boat.}
  \label{fig:boat1}
\end{figure}

Figure \ref{fig:boat1} shows a boat.

Two images with individual subtitles and one shared subtitle

\usepackage{graphicx}
\begin{figure}[h!]
  \centering
  \begin{subfigure}[b]{0.4\linewidth}
    \includegraphics[width=\linewidth]{coffee.jpg}
    \caption{Coffee.}
  \end{subfigure}
  \begin{subfigure}[b]{0.4\linewidth}
    \includegraphics[width=\linewidth]{coffee.jpg}
    \caption{More coffee.}
  \end{subfigure}
  \caption{The same cup of coffee. Two times.}
  \label{fig:coffee}
\end{figure}

Table Of Contents


\documentclass{article}

\begin{document}

\tableofcontents
\newpage

\section{Section}

Dummy text

\subsection{Subsection}

Dummy text

\end{document}

Appendix

List of tables, list of figures.


\begin{document}

\begin{figure}
  \caption{Dummy figure}
\end{figure}

\begin{table}
  \caption{Dummy table}
\end{table}

\begin{appendix}
  \listoffigures
  \listoftables
\end{appendix}

\end{document}

Document Class

Document classes set default global layout settings for the document.

Ex: "article", "book"

Article

The "article" document class will automatically add page numbers to the pdf.


\documentclass{article}

\title{My first document}
\date{2013-09-01}
\author{John Doe}

\begin{document}
  \maketitle
  \newpage

  Hello World!
\end{document}

You can skip numbering a page, and then restart numbering, like this. Note that numbering will restart at 1.

\documentclass{article}

\title{My first document}
\date{2013-09-01}
\author{John Doe}

\begin{document}
  \pagenumbering{gobble}
  \maketitle
  \newpage
  \pagenumbering{arabic}

  Hello World!
\end{document}


Equation

Basic

Equation is a built-in environment. Use "equation" to format mathematical equations in "display mode". Display mode means the equation will be shown on its own line.


\begin{equation}
    f{x} = x^2
\end{equation}

Each equation will be automatically numbered for referencing.

You can only write one equation per "equation" environment.

Alternate formats:
    \[x^2\]
    $$x^2$$
    \begin{displaymath}x^2\end{displaymath}

Amsmath

Use the amsmath package to make not-numbered equations.


\usepackage{amsmath}
\begin{document}
\begin{equation*}
    f{x} = x^2
\end{equation*}
\end{document}

It will also align multiple statements along the zero-width & (ampersand) character. The \\ (double backslash) marks a line break.

\usepackage{amsmath}
\begin{document}
\begin{align*}
    1 + 2 &= 3\\
    1 &= 3 - 2
\end{align*}
\end{document}

Inline

Instead of enclosing your equations in an environment, you can use the $ (dollar sign) format to write equations inline with your text.


\begin{document}
    Words $f(x) = x^2$ Words
\end{document}

Or you can use the \( \) format.

\begin{document}

The well known Pythagorean theorem \(x^2 + y^2 = z^2\) was 
proved to be invalid for other exponents. 
\end{document}

Or use the inline math environment

\begin{document}

The well known Pythagorean theorem \begin{math}x^2 + y^2 = z^2\end{math} was 
proved to be invalid for other exponents.
\end{document}

Power

x to the power of 2

$x^2$

Root

square root of x

$\sqrt{x}

Fraction

1 over x

$\frac{1}{x}$

Integral

integral from a to b of one-third times x to the third power

$\int^a_b \frac{1}{3}x^3$

The a and b limits can be written in either order, but the one with ^ prefix will go on top and the _ prefix on the bottom.

This one displays the limits at the top and bottom of the integral sign, instead of inset within it.

$\int\limits^a_b \frac{1}{3}x^3$

Choose

n choose k

\usepackage{amsmath}
$\binom{n}{k}$

Brackets

Brackets, parentheses, and curly braces that will resize to surround the matrix or equation or whatever.


\left[
\begin{matrix}
1 & 0\\
0 & 1
\end{matrix}
\right]


\left(
\frac{1}{\sqrt{x}}
\right)

Subscript Superscript

^ for superscript
_ for subscript


\[ a_1^2 + a_2^2 = a_3^2 \]

Surround long scripts with brackets

\[ a_{ij} + a_{kl} = b \]

Complex example

\[ \sum_{i=1}^{\infty} \frac{1}{n^s} 
= \prod_p \frac{1}{1 - p^{-s}} \]

Greek Letters

Lowercase | Uppercase | Variable

\alpha | A
\beta | B
\gamma | \Gamma
\delta | \Delta
\epsilon | E | \varepsilon
\zeta | Z
\eta | H
\theta | \Theta | \vartheta
\iota | I
\kappa | K
\lambda | \Lambda
\mu | M
\nu | N
\xi | \Xi
o | O
\pi | \Pi
\rho | P | \varrho
\sigma | \Sigma
\tau | T
\upsilon | \Upsilon
\phi | \Phi | \varphi
\chi | X
\psi | \Psi
\omega | \Omega

Binary Operators

\times
\otimes
\oplus
\cup
\cap
\div
\neq
\leq
\geq
\in
\notin
\perp
\simeq
\approx
\wedge
\vee
\Box
\boxtimes
\equiv
\cong

Relation Operators

<
>
\subset
\supset
\subseteq
\supseteq

Misc Operators

\int = integral
\oint = o integral
\sum = big epsilon
\prod = big pi
\coprod = upside down big pi

\infty = infinity
\exists = backwards E
\nexists = crossed out backwards E
\forall = upside down A
\Re
\Im
\nabla = upside down triangle
\partial
\emptyset
\varnothing
\wp
\complement
\neg
\cdots = three dots in a row
\square = empty white square
\blacksquare = filled black square
\surd = start of root sign
\triangle = empty white triangle

Arrows

Single Line | Double Line

\leftarrow | \Leftarrow
\rightarrow | \Rightarrow
\leftrightarrow | \Leftrightarrow
\uparrow | \Uparrow
\downarrow | \Downarrow
\Updownarrow
\mapsto
\longmapsto
\nearrow
\searrow
\swarrow
\nwarrow
\leftharpoonup
\rightharpoonup
\leftharpoondown
\rightharpoondown
\rightleftharpoons

Custom Operators

Command "DeclareMathOperator" will define a custom operator that you can use throughout your document. The operator you define will be replaced (compiled to) whatever text or equation you define.


\documentclass{article}
 
\usepackage{amssymb}
\usepackage{amsmath}
 
\DeclareMathOperator{\Mr}{M_{\mathbb{R}}}
 
\begin{document}
 
User-defined operator for matrices with Real entries
 
\[
x \in \Mr
\]
\end{document}
Matrix


\begin{matrix}
1 & 0\\
0 & 1
\end{matrix}

Bibliography

Bib

Create a text file saved with .bib file format.
See BibTeX generator for full format details.

Sample

@BOOK{DUMMY:1,
AUTHOR="John Doe",
TITLE="The Book without Title",
PUBLISHER="Dummy Publisher",
YEAR="2100",
}

Citation

The "bibliography" command both gives the filename (sans file extension) of our bibliography.

The "bibliographystyle" command gives the format for displaying the bibliography.

The "displaybibliography" command prints the bibliography.


\documentclass{article}

\begin{document}

Random citation \cite{DUMMY:1} embeddeed in text.

\bibliography{filename} 
\bibliographystyle{ieeetr}
\printbibliography

\end{document}