Skip to main content
โšก Calmops

LaTeX Essential Commands: A Practical Reference

Introduction

LaTeX is a document preparation system widely used in academia, mathematics, and scientific publishing. Unlike word processors, LaTeX separates content from formatting โ€” you write plain text with markup commands, and LaTeX handles the typesetting. This guide covers the essential commands you’ll use in most documents.

Document Structure

\documentclass[12pt, a4paper]{article}  % or report, book, beamer

% Preamble โ€” packages and settings
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}        % math
\usepackage{graphicx}       % images
\usepackage{hyperref}       % hyperlinks
\usepackage{geometry}       % page margins
\geometry{margin=2.5cm}

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

\begin{document}

\maketitle
\tableofcontents
\newpage

\section{Introduction}
Your content here.

\end{document}

Text Formatting

% Font styles
\textbf{bold text}
\textit{italic text}
\underline{underlined text}
\texttt{monospace / code}
\textsc{Small Caps}
\emph{emphasized text}  % italic in normal text, normal in italic

% Font sizes
{\tiny tiny}
{\small small}
{\normalsize normal}
{\large large}
{\Large Large}
{\LARGE LARGE}
{\huge huge}

% Alignment
\begin{center} centered text \end{center}
\begin{flushleft} left aligned \end{flushleft}
\begin{flushright} right aligned \end{flushright}

% Line and paragraph spacing
\\          % line break
\newline    % line break
\newpage    % page break
\vspace{1cm}  % vertical space
\hspace{1cm}  % horizontal space

Sections and Structure

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

% Unnumbered sections
\section*{Unnumbered Section}

% Table of contents
\tableofcontents

Lists

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

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

% Description list
\begin{description}
  \item[Term 1] Definition of term 1
  \item[Term 2] Definition of term 2
\end{description}

% Nested lists
\begin{itemize}
  \item Level 1
  \begin{itemize}
    \item Level 2
    \begin{itemize}
      \item Level 3
    \end{itemize}
  \end{itemize}
\end{itemize}

Mathematics

% Inline math
The formula $E = mc^2$ is famous.

% Display math (centered, numbered)
\begin{equation}
  \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
\end{equation}

% Display math (unnumbered)
\[
  f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
\]

% Aligned equations
\begin{align}
  a &= b + c \\
  d &= e + f \\
  g &= h + i
\end{align}

% Common math symbols
x^{2}           % superscript
x_{i}           % subscript
\frac{a}{b}     % fraction
\sqrt{x}        % square root
\sqrt[n]{x}     % nth root
\sum_{i=1}^{n}  % summation
\prod_{i=1}^{n} % product
\int_{a}^{b}    % integral
\lim_{x \to 0}  % limit
\infty          % infinity
\alpha \beta \gamma \delta \epsilon  % Greek letters
\pi \sigma \mu \lambda \omega        % more Greek
\leq \geq \neq \approx \equiv        % comparison
\in \notin \subset \cup \cap         % set operations
\forall \exists \neg \land \lor      % logic
\mathbb{R} \mathbb{Z} \mathbb{N}     % number sets (requires amssymb)

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

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

Tables

\begin{table}[h]
  \centering
  \caption{Sample Table}
  \label{tab:sample}
  \begin{tabular}{|l|c|r|}  % l=left, c=center, r=right, |=vertical line
    \hline
    Left & Center & Right \\
    \hline
    Alice & 95 & Pass \\
    Bob   & 72 & Pass \\
    Carol & 45 & Fail \\
    \hline
  \end{tabular}
\end{table}

% Reference the table
See Table~\ref{tab:sample}.

% Booktabs (cleaner tables โ€” requires \usepackage{booktabs})
\begin{tabular}{lcc}
  \toprule
  Name  & Score & Grade \\
  \midrule
  Alice & 95    & A \\
  Bob   & 72    & C \\
  \bottomrule
\end{tabular}

Figures and Images

\usepackage{graphicx}  % in preamble

\begin{figure}[h]      % h=here, t=top, b=bottom, p=page
  \centering
  \includegraphics[width=0.8\textwidth]{image.png}
  \caption{A descriptive caption}
  \label{fig:myimage}
\end{figure}

% Reference the figure
As shown in Figure~\ref{fig:myimage}.

% Side-by-side figures (requires subcaption package)
\usepackage{subcaption}

\begin{figure}[h]
  \begin{subfigure}{0.45\textwidth}
    \includegraphics[width=\textwidth]{fig1.png}
    \caption{First figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.45\textwidth}
    \includegraphics[width=\textwidth]{fig2.png}
    \caption{Second figure}
  \end{subfigure}
  \caption{Two figures side by side}
\end{figure}
\usepackage{hyperref}  % in preamble

% Clickable URL
\url{https://www.latex-tutorial.com}

% Hyperlink with custom text
\href{https://www.latex-tutorial.com}{LaTeX Tutorial}

% Email link
\href{mailto:[email protected]}{[email protected]}

% Internal cross-reference (clickable)
See Section~\ref{sec:intro}.

% Hyperref setup (in preamble)
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  urlcolor=cyan,
  citecolor=green,
  pdftitle={My Document},
  pdfauthor={Author Name}
}

Code Listings

% Inline code
Use the \texttt{grep} command.

% Code block (requires listings package)
\usepackage{listings}
\usepackage{xcolor}

\lstset{
  basicstyle=\ttfamily\small,
  keywordstyle=\color{blue},
  commentstyle=\color{gray},
  stringstyle=\color{red},
  numbers=left,
  frame=single,
  breaklines=true
}

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

hello("World")
\end{lstlisting}

% Or use minted (requires Python Pygments)
\usepackage{minted}

\begin{minted}{python}
def hello(name):
    print(f"Hello, {name}!")
\end{minted}

Bibliography

% In preamble
\usepackage{biblatex}
\addbibresource{references.bib}

% In text
According to \cite{knuth1984}, ...

% At end of document
\printbibliography

% references.bib file
@book{knuth1984,
  author    = {Donald E. Knuth},
  title     = {The TeXbook},
  publisher = {Addison-Wesley},
  year      = {1984}
}

@article{lamport1994,
  author  = {Leslie Lamport},
  title   = {LaTeX: A Document Preparation System},
  journal = {Addison-Wesley},
  year    = {1994}
}

Useful Packages

Package Purpose
amsmath Advanced math environments
amssymb Math symbols (โ„, โ„ค, etc.)
graphicx Include images
hyperref Hyperlinks and PDF metadata
geometry Page margins and layout
booktabs Professional tables
listings Code listings
minted Syntax-highlighted code
biblatex Bibliography management
subcaption Side-by-side figures
tikz Diagrams and drawings
pgfplots Plots and charts
algorithm2e Algorithm pseudocode
todonotes Margin notes and TODOs

Compilation

# Basic compilation
pdflatex document.tex

# With bibliography
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex

# With latexmk (handles multiple passes automatically)
latexmk -pdf document.tex
latexmk -pdf -pvc document.tex  # continuous compilation on save

Resources

Comments