← All cheat sheets

latex

Authorized use only. Offensive reference for systems you own or are explicitly permitted to test. You are responsible for staying within the law.

DOCUMENT STRUCTURE#

\documentclass[12pt,a4paper]{article}   % Document class
\usepackage[utf8]{inputenc}              % UTF-8 encoding
\usepackage[T1]{fontenc}                 % Font encoding
\usepackage{amsmath}                     % Math package
\usepackage{graphicx}                    % Images
\usepackage{hyperref}                    % Hyperlinks

\title{Document Title}
\author{Author Name}
\date{\today}

\begin{document}
\maketitle
\tableofcontents
\newpage

% Content here

\end{document}

DOCUMENT CLASSES#

article                             # Articles, short documents
report                              # Longer reports, thesis
book                                # Books
letter                              # Letters
beamer                              # Presentations
memoir                              # Flexible class

CLASS OPTIONS#

10pt, 11pt, 12pt                    # Font size
a4paper, letterpaper                # Paper size
onecolumn, twocolumn                # Column layout
oneside, twoside                    # Printing sides
landscape                           # Landscape orientation
draft                               # Draft mode

SECTIONS#

\part{Part Title}
\chapter{Chapter Title}             % (book, report only)
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\paragraph{Paragraph Title}
\subparagraph{Subparagraph Title}

\section*{Unnumbered Section}       # No numbering

TEXT FORMATTING#

\textbf{bold}                       # Bold text
\textit{italic}                     # Italic text
\underline{underlined}              # Underlined text
\texttt{monospace}                  # Monospace/typewriter
\textsc{Small Caps}                 # Small capitals
\emph{emphasized}                   # Emphasized (italic)
{\tiny tiny}                        # Tiny text
{\small small}                      # Small text
{\large large}                      # Large text
{\Large larger}                     # Larger text
{\LARGE even larger}                # Even larger
{\huge huge}                        # Huge text
{\Huge largest}                     # Largest text

ALIGNMENT#

\begin{center}                      # Centered text
Centered text
\end{center}

\begin{flushleft}                   # Left aligned
Left aligned
\end{flushleft}

\begin{flushright}                  # Right aligned
Right aligned
\end{flushright}

LISTS#

% Unordered list
\begin{itemize}
    \item First item
    \item Second item
    \item Nested:
    \begin{itemize}
        \item Nested item
    \end{itemize}
\end{itemize}

% Ordered list
\begin{enumerate}
    \item First item
    \item Second item
\end{enumerate}

% Description list
\begin{description}
    \item[Term] Definition
    \item[Another] Another definition
\end{description}

MATHEMATICS#

% Inline math
$E = mc^2$

% Display math
\[ E = mc^2 \]

% Equation with number
\begin{equation}
    E = mc^2
\end{equation}

% Multiple equations aligned
\begin{align}
    f(x) &= x^2 + 2x + 1 \\
    g(x) &= x^3 - 1
\end{align}

MATH SYMBOLS#

% Operators
+ - * / =                           # Basic operators
\times                              # Multiplication
\div                                # Division
\pm \mp                             # Plus/minus
\cdot                               # Dot product
\neq                                # Not equal
\leq \geq                           # Less/greater than or equal
\approx                             # Approximately
\equiv                              # Equivalent
\sim                                # Similar to
\propto                             # Proportional to

% Fractions and roots
\frac{a}{b}                         # Fraction
\sqrt{x}                            # Square root
\sqrt[n]{x}                         # nth root

% Powers and indices
x^2                                 # Superscript
x_i                                 # Subscript
x^{2n}                              # Grouped superscript
x_{ij}                              # Grouped subscript
x_i^2                               # Both

% Greek letters
\alpha \beta \gamma \delta \epsilon
\zeta \eta \theta \iota \kappa
\lambda \mu \nu \xi \pi
\rho \sigma \tau \upsilon \phi
\chi \psi \omega
\Gamma \Delta \Theta \Lambda \Xi
\Pi \Sigma \Phi \Psi \Omega

% Functions
\sin \cos \tan \cot \sec \csc
\log \ln \exp \lim \max \min
\sum \prod \int

% Sum and integral
\sum_{i=1}^{n} x_i                  # Sum
\prod_{i=1}^{n} x_i                 # Product
\int_{a}^{b} f(x) dx                # Integral
\oint                               # Contour integral
\iint \iiint                        # Multiple integrals

% Brackets
(x)  [x]  \{x\}                     # Parentheses, brackets, braces
\langle x \rangle                   # Angle brackets
|x|  \|x\|                          # Absolute value, norm
\left( \frac{a}{b} \right)          # Auto-scaling brackets

% Matrices
\begin{matrix}
    a & b \\
    c & d
\end{matrix}

\begin{pmatrix}                     # Parentheses
    a & b \\
    c & d
\end{pmatrix}

\begin{bmatrix}                     # Square brackets
    a & b \\
    c & d
\end{bmatrix}

TABLES#

\begin{table}[htbp]
    \centering
    \caption{Table caption}
    \label{tab:mytable}
    \begin{tabular}{|l|c|r|}
        \hline
        Left & Center & Right \\
        \hline
        1 & 2 & 3 \\
        4 & 5 & 6 \\
        \hline
    \end{tabular}
\end{table}

% Column specifiers
l                                   # Left aligned
c                                   # Centered
r                                   # Right aligned
p{5cm}                              # Paragraph with width
|                                   # Vertical line
@{}                                 # Remove spacing

FIGURES#

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.8\textwidth]{image.png}
    \caption{Figure caption}
    \label{fig:myfigure}
\end{figure}

% Figure placement
h                                   # Here
t                                   # Top of page
b                                   # Bottom of page
p                                   # Separate page
!                                   # Override restrictions

REFERENCES#

\label{sec:intro}                   # Create label
\ref{sec:intro}                     # Reference section number
\pageref{sec:intro}                 # Reference page number
\eqref{eq:1}                        # Reference equation

% Bibliography (BibTeX)
\bibliographystyle{plain}
\bibliography{references}

\cite{key}                          # Citation
\cite[p.~42]{key}                   # Citation with page

FOOTNOTES#

Text with footnote\footnote{This is a footnote.}
\usepackage{hyperref}
\url{https://example.com}
\href{https://example.com}{Link text}
\hyperref[label]{Link to label}

CODE LISTINGS#

\usepackage{listings}

\begin{lstlisting}[language=Python]
def hello():
    print("Hello, World!")
\end{lstlisting}

\lstinline|inline code|

VERBATIM#

\begin{verbatim}
    Verbatim text preserves    spaces
\end{verbatim}

\verb|inline verbatim|

COLORS#

\usepackage{xcolor}

\textcolor{red}{Red text}
\colorbox{yellow}{Yellow background}
{\color{blue} Blue text}

% Define colors
\definecolor{mycolor}{RGB}{100,150,200}

SPACING#

\hspace{1cm}                        # Horizontal space
\vspace{1cm}                        # Vertical space
\quad                               # Quad space
\qquad                              # Double quad
~                                   # Non-breaking space
\\                                  # Line break
\newline                            # New line
\newpage                            # New page
\clearpage                          # Clear and start new page
\noindent                           # No paragraph indent

LENGTH UNITS#

pt                                  # Point (1/72.27 inch)
mm                                  # Millimeter
cm                                  # Centimeter
in                                  # Inch
em                                  # Width of 'M' in current font
ex                                  # Height of 'x' in current font
\textwidth                          # Text width
\linewidth                          # Line width
\pagewidth                          # Page width

SPECIAL CHARACTERS#

\%                                  # Percent
\$                                  # Dollar
\&                                  # Ampersand
\#                                  # Hash
\_                                  # Underscore
\{  \}                              # Braces
\textbackslash                      # Backslash
\textasciitilde                     # Tilde
\textasciicircum                    # Caret
--                                  # En dash
---                                 # Em dash
``quoted''                          # Curly quotes

COMMENTS#

% This is a comment

\begin{comment}                     % Requires verbatim package
Multi-line comment
\end{comment}

CUSTOM COMMANDS#

\newcommand{\R}{\mathbb{R}}         # Define command
\newcommand{\norm}[1]{\|#1\|}       # With argument
\renewcommand{\vec}[1]{\mathbf{#1}} # Redefine command

PACKAGES#

\usepackage{amsmath}                # Advanced math
\usepackage{amssymb}                # Math symbols
\usepackage{graphicx}               # Images
\usepackage{hyperref}               # Hyperlinks
\usepackage{geometry}               # Page layout
\usepackage{fancyhdr}               # Headers/footers
\usepackage{listings}               # Code listings
\usepackage{xcolor}                 # Colors
\usepackage{tikz}                   # Graphics
\usepackage{booktabs}               # Better tables
\usepackage{multicol}               # Multiple columns
\usepackage{enumitem}               # List customization

COMPILATION#

pdflatex document.tex               # Compile to PDF
latex document.tex                  # Compile to DVI
bibtex document                     # Process bibliography
makeindex document                  # Process index

# Full compilation
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex