📘 The Complete LaTeX Tutorial: From Zero to Typesetting Mastery

Welcome to the definitive guide to LaTeX — the document preparation system trusted by scientists, mathematicians, engineers, and authors worldwide for producing beautifully typeset documents. This tutorial takes you from your very first document to advanced typesetting techniques, covering everything you need to become proficient. 🚀

Information

LaTeX (pronounced LAH-tekh or LAY-tekh) is not a word processor — it is a markup-based typesetting system. You write plain text with commands, and LaTeX compiles it into a professionally formatted document (usually a PDF).

🌟 1. Introduction to LaTeX

What is LaTeX?

LaTeX is a typesetting system built on top of Donald Knuth's TeX engine, created by Leslie Lamport. Instead of manually adjusting fonts, spacing, and layout like in a WYSIWYG editor (e.g., Microsoft Word), you describe the structure of your document, and LaTeX handles the visual formatting for you.

>>"LaTeX is not a word processor. Instead, LaTeX encourages authors not to worry too much about the appearance of their documents but to concentrate on getting the right content." — LaTeX Project Documentation

Why Use LaTeX?

  • 🧮 Unmatched typesetting of mathematical notation
  • 📑 Automatic numbering of sections, figures, tables, and equations
  • 🔗 Effortless cross-referencing and bibliography management
  • 🎨 Consistent, professional formatting across large documents
  • 🆓 Free, open-source, and cross-platform
  • 📚 Industry standard for academic papers, theses, and books

Tip

If your document is text-heavy with minimal formatting needs, a word processor might be faster. LaTeX shines when you need precision, consistency, and complex structures like math, citations, or long technical documents.

How LaTeX Works

âœī¸ You write .tex source file
âš™ī¸ LaTeX engine compiles it
📄 Output generated
PDF (most common)
DVI / PostScript (legacy)

đŸ› ī¸ 2. Installation & Setup

Choosing a TeX Distribution

DistributionPlatformNotes
TeX LiveWindows / macOS / LinuxMost complete, cross-platform standard
MiKTeXWindows / macOS / LinuxInstalls packages on-the-fly
MacTeXmacOSTeX Live packaged for Mac

Online Editors (No Installation Needed)

For beginners, online editors like Overleaf are the fastest way to start — no installation, real-time collaboration, and instant PDF previews.

Compiling Your First Document

Compiling from the command line

pdflatex document.tex
# Run twice if you have references/citations
pdflatex document.tex

Note

Common engines include pdflatex (most common, outputs PDF directly), xelatex (better font/Unicode support), and lualatex (modern, scriptable via Lua).

📄 3. Document Structure Basics

The Preamble and Body

Every LaTeX document is split into two parts: the preamble (setup before the document starts) and the body (the actual content).

minimal.tex

\documentclass{article}

% Preamble: packages and settings go here
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{My First Document}
\author{Jane Doe}
\date{\today}

\begin{document}

\maketitle

Hello, world! This is my first \LaTeX{} document.

\end{document}
đŸ“Ļ Document Class \documentclass{...}
🧰 Preamble
📝 Document Body
article — papers, short reports
report — longer, multi-chapter reports
book — full books
beamer — presentations/slides
Packages via \usepackage{}
Custom commands
Title/author metadata
\begin{document} ... \end{document}

Sectioning Commands

CommandLevelAvailable In
\part{}-1book, report
\chapter{}0book, report
\section{}1all
\subsection{}2all
\subsubsection{}3all
\paragraph{}4all

âœī¸ 4. Text Formatting

Basic Emphasis

Code Snippet

\textbf{Bold text}
\textit{Italic text}
\underline{Underlined text}
\emph{Emphasized text}
\texttt{Monospace text}
\textsc{Small Caps}

Font Sizes

Code Snippet

{\tiny tiny text}
{\small small text}
{\normalsize normal text}
{\large large text}
{\Large Larger text}
{\huge huge text}

Line Breaks, Spacing & Special Characters

Use \\ for a line break and a blank line for a new paragraph. Certain characters like %, &, and $ are reserved and must be escaped with a backslash.

Warning

Reserved characters: # $ % ^ & _ { } ~ \. Typing these directly (without escaping) will either cause errors or unexpected behavior.

📋 5. Lists

Itemized, Enumerated, and Description Lists

Code Snippet

\begin{itemize}
  \item First point
  \item Second point
\end{itemize}

\begin{enumerate}
  \item Step one
  \item Step two
\end{enumerate}

\begin{description}
  \item[LaTeX] A typesetting system
  \item[TeX] The engine underneath
\end{description}
  • itemize — bullet points
  • enumerate — numbered lists
  • description — term/definition pairs

🧮 6. Mathematics in LaTeX

Mathematics is where LaTeX truly excels. Math can be written inline within text or as a displayed block.

Inline vs Display Math

Code Snippet

Inline: $E = mc^2$

Display:
\[
  E = mc^2
\]

Or using amsmath:
\begin{equation}
  E = mc^2
\end{equation}

Common Mathematical Constructs

LaTeXRenders As
x^2Superscript
x_iSubscript
\frac{a}{b}Fraction
\sqrt{x}Square root
\sum_{i=1}^{n}Summation
\int_{a}^{b}Integral

Example: Quadratic Formula

Example: Summation and Limits

Matrices

Code Snippet

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

Aligning Multiple Equations

Code Snippet

\begin{align}
  a &= b + c \\
  x &= y - z
\end{align}

Best Practice

Always load the amsmath package (\usepackage{amsmath}) for access to environments like align, gather, and cases.

đŸ–ŧī¸ 7. Figures, Graphics & Tables

Inserting Images

Code Snippet

\usepackage{graphicx}

\begin{figure}[h]
  \centering
  \includegraphics[width=0.6\textwidth]{image.png}
  \caption{A descriptive caption}
  \label{fig:example}
\end{figure}

Note

The [h] placement specifier means "here". Other options include t (top), b (bottom), and p (dedicated page).

Creating Tables

Code Snippet

\begin{table}[h]
  \centering
  \begin{tabular}{|l|c|r|}
    \hline
    Name & Age & City \\
    \hline
    Alice & 30 & NYC \\
    Bob & 25 & LA \\
    \hline
  \end{tabular}
  \caption{Sample data table}
\end{table}

The {|l|c|r|} argument defines column alignment: l (left), c (center), r (right), and | draws vertical lines.

🔗 8. Cross-Referencing & Bibliography

Labels and References

Code Snippet

\section{Introduction}
\label{sec:intro}

As discussed in Section~\ref{sec:intro}...

See Figure~\ref{fig:example} on page~\pageref{fig:example}.

Bibliography with BibTeX

references.bib

@article{einstein1905,
  author  = {Einstein, Albert},
  title   = {Zur Elektrodynamik bewegter K{\"o}rper},
  journal = {Annalen der Physik},
  year    = {1905}
}

In your document

\usepackage{cite}
...
As shown by \cite{einstein1905}...

\bibliographystyle{plain}
\bibliography{references}

Tip

Modern documents often use biblatex with the biber backend instead of classic BibTeX — it offers more flexible citation styles and better Unicode support. Learn more at the CTAN biblatex page.

đŸ“Ļ 9. Packages & Custom Commands

Commonly Used Packages

PackagePurpose
amsmathAdvanced math typesetting
graphicxImage insertion
hyperrefClickable links & PDF metadata
geometryPage margins & layout
babelMultilingual typesetting
xcolorColored text and backgrounds
tikzVector graphics & diagrams
booktabsProfessional-looking tables

Defining Custom Commands

Code Snippet

% Simple command
\newcommand{\R}{\mathbb{R}}

% Command with arguments
\newcommand{\vect}[1]{\mathbf{#1}}

% Usage
The set \R represents real numbers.
The vector \vect{v} has magnitude...

Example

Custom commands reduce repetition and make documents easier to maintain — changing one definition updates every usage throughout the document.

🚀 10. Advanced Topics

Creating Presentations with Beamer

Code Snippet

\documentclass{beamer}
\usetheme{Madrid}

\title{My Presentation}
\author{Jane Doe}

\begin{document}

\frame{\titlepage}

\begin{frame}{Introduction}
  This is my first slide.
\end{frame}

\end{document}

Drawing Diagrams with TikZ

Code Snippet

\usepackage{tikz}

\begin{tikzpicture}
  \draw[thick,->] (0,0) -- (2,0) node[right]{$x$};
  \draw[thick,->] (0,0) -- (0,2) node[above]{$y$};
  \draw[blue,thick] (0,0) circle (1);
\end{tikzpicture}

Multi-file Projects

Large documents (like theses) are often split into multiple files for organization, combined using \input{} or \include{}.

main.tex

\documentclass{book}
\begin{document}

\include{chapters/chapter1}
\include{chapters/chapter2}

\end{document}

Version Control Tip

Best Practice

Since .tex files are plain text, they work beautifully with git. Combine this with Overleaf's Git integration or a local Git repo to track changes over time.

🐞 11. Troubleshooting Common Errors

ErrorLikely CauseFix
Undefined control sequenceMisspelled command or missing packageCheck spelling; add \usepackage{}
Missing $ insertedMath symbol used outside math modeWrap in $...$ or \[...\]
Undefined reference\ref{} used before compiling twiceRecompile the document
File not foundWrong image/file pathCheck path relative to .tex file

Caution

LaTeX often requires multiple compilation passes to correctly resolve references, citations, and the table of contents. Compile at least twice (or three times with a bibliography).

✅ 12. Best Practices

  1. Keep the preamble organized and only load packages you actually use
  2. Use semantic labels like fig:, tab:, eq: for readability
  3. Break large documents into multiple files
  4. Comment your code with % for future reference
  5. Use version control (Git) for collaborative or long-term projects
  6. Compile frequently to catch errors early

📚 13. Summary

Summary

You've now covered the full LaTeX journey: installation, document structure, text formatting, lists, mathematics, figures, tables, cross-referencing, bibliographies, custom commands, and advanced topics like Beamer and TikZ. With consistent practice, LaTeX will become second nature for producing publication-quality documents. 🎓

Further Resources