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
đ 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.
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
How LaTeX Works
đ ī¸ 2. Installation & Setup
Choosing a TeX Distribution
| Distribution | Platform | Notes |
|---|---|---|
| TeX Live | Windows / macOS / Linux | Most complete, cross-platform standard |
| MiKTeX | Windows / macOS / Linux | Installs packages on-the-fly |
| MacTeX | macOS | TeX 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.texNote
đ 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}Sectioning Commands
| Command | Level | Available In |
|---|---|---|
| \part{} | -1 | book, report |
| \chapter{} | 0 | book, report |
| \section{} | 1 | all |
| \subsection{} | 2 | all |
| \subsubsection{} | 3 | all |
| \paragraph{} | 4 | all |
âī¸ 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
đ 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
| LaTeX | Renders As |
|---|---|
| x^2 | Superscript |
| x_i | Subscript |
| \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
đŧī¸ 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
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
đĻ 9. Packages & Custom Commands
Commonly Used Packages
| Package | Purpose |
|---|---|
| amsmath | Advanced math typesetting |
| graphicx | Image insertion |
| hyperref | Clickable links & PDF metadata |
| geometry | Page margins & layout |
| babel | Multilingual typesetting |
| xcolor | Colored text and backgrounds |
| tikz | Vector graphics & diagrams |
| booktabs | Professional-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
đ 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
đ 11. Troubleshooting Common Errors
| Error | Likely Cause | Fix |
|---|---|---|
| Undefined control sequence | Misspelled command or missing package | Check spelling; add \usepackage{} |
| Missing $ inserted | Math symbol used outside math mode | Wrap in $...$ or \[...\] |
| Undefined reference | \ref{} used before compiling twice | Recompile the document |
| File not found | Wrong image/file path | Check path relative to .tex file |
Caution
â 12. Best Practices
- Keep the preamble organized and only load packages you actually use
- Use semantic labels like fig:, tab:, eq: for readability
- Break large documents into multiple files
- Comment your code with % for future reference
- Use version control (Git) for collaborative or long-term projects
- Compile frequently to catch errors early