LaTeX Tutorial

From your first document to a research-ready report

Write structured documents with LaTeX

LaTeX is a document preparation system. You write plain-text source with commands that describe structure and meaning; a compiler turns it into a polished PDF. It is especially useful for papers, theses, reports, and any document with lots of mathematics, citations, or cross-references.

Quick start: create main.tex in an online editor such as Overleaf, or install a TeX distribution locally. Paste the example below and compile with pdfLaTeX.

How to read the examples: source is on the left and an illustrative PDF-style preview is on the right. The preview shows the expected layout; compile the source in a LaTeX editor for the actual PDF.

1. Your first document

A LaTeX source file has a preamble (document settings and packages) and a document body (the content that appears in the PDF).

LaTeX source

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc} % often optional with modern engines
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\title{My First LaTeX Document}
\author{Your Name}
\date{\today}

\begin{document}
\maketitle

\section{Introduction}
This is a paragraph. Leave a blank line in the source to start a new paragraph.

This is the next paragraph. LaTeX handles line wrapping for you.
\end{document}

PDF preview

My First LaTeX Document

Your Name · November 17, 2026

1  Introduction

This is a paragraph. Leave a blank line in the source to start a new paragraph.

This is the next paragraph. LaTeX handles line wrapping for you.

2. Sections, text, and lists

Use section commands to build a navigable hierarchy. LaTeX numbers sections automatically; starred forms omit numbering.

\section{Background}
\subsection{Related work}
\subsubsection{A specific method}
\paragraph{Key idea.} This begins a run-in heading.

\textbf{Bold}, \textit{italic}, and \emph{emphasized} text.
Inline code: \texttt{python main.py}.

\begin{itemize}
  \item An unordered item
  \item Another item
\end{itemize}

\begin{enumerate}
  \item First step
  \item Second step
\end{enumerate}

Escape reserved characters when you want them printed literally: \%, \_, \&, \#, \$, \{, and \}. A blank line starts a new paragraph; use \\ for a deliberate line break only when needed.

3. Mathematics

Use $...$ for a short inline expression and a display environment for an equation on its own line. The amsmath package provides useful environments.

LaTeX source

\usepackage{amsmath,amssymb} % add in the preamble

Inline: the model predicts $y = mx + b$.

\begin{equation}\label{eq:loss}
  \mathcal{L}(\theta) = -\sum_{i=1}^{n} y_i\log p_\theta(y_i\mid x_i)
\end{equation}

We minimize Equation~\ref{eq:loss}.

\begin{align}
  (a+b)^2 &= (a+b)(a+b) \\
          &= a^2 + 2ab + b^2
\end{align}

Rendered output

Inline: the model predicts y = mx + b.

ℒ(θ) = −∑i=1n yi log pθ(yi | xi)

(1)

(a + b)² = (a + b)(a + b)
= a² + 2ab + b²

For unnumbered display math, use \[ ... \] or align*. See the mathematics guide for symbols, matrices, cases, and multi-line derivations.

4. Figures and images

Put image files beside your source (or in an images/ folder), load graphicx, and include a figure with a caption and label.

LaTeX source

\usepackage{graphicx} % preamble

\begin{figure}[tbp]
  \centering
  \includegraphics[width=0.75\linewidth]{images/architecture.png}
  \caption{Overview of the system architecture.}
  \label{fig:architecture}
\end{figure}

Figure~\ref{fig:architecture} shows the main components.

Rendered output

Client→API→Database

Figure 1: Overview of the system architecture.

Figure 1 shows the main components.

Use width=\linewidth to fit the current text area. The placement letters are suggestions to LaTeX: h here, t top, b bottom, and p a float page. More examples are in figure and image handling.

5. Tables

A tabular environment lays out cells; a surrounding table environment allows a caption and floating placement. Columns are separated by & and rows end with \\.

LaTeX source

\usepackage{booktabs} % preamble; clean horizontal rules

\begin{table}[tbp]
  \centering
  \caption{Example results.}
  \label{tab:results}
  \begin{tabular}{lrr}
    \toprule
    Method & Accuracy & F1 score \\
    \midrule
    Baseline & 0.82 & 0.79 \\
    Proposed & 0.91 & 0.89 \\
    \bottomrule
  \end{tabular}
\end{table}

See Table~\ref{tab:results} for the comparison.

Rendered output

Table 1: Example results.

MethodAccuracyF1 score
Baseline0.820.79
Proposed0.910.89

See Table 1 for the comparison.

Column specifiers l, c, and r mean left, center, and right alignment. The table guide covers wider tables, merged cells, and multi-page tables.

6. Algorithms

For numbered pseudocode, a common combination is algorithm and algpseudocode (provided by algorithmicx). These are for pseudocode, not executable source code.

LaTeX source

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{algorithm}
\caption{Binary search}\label{alg:binary-search}
\begin{algorithmic}[1]
  \Require Sorted array $A$, target $x$
  \Ensure Index of $x$, or $-1$ if absent
  \State $low \gets 1$, $high \gets |A|$
  \While{$low \leq high$}
    \State $mid \gets \lfloor(low+high)/2\rfloor$
    \If{$A[mid] = x$}
      \State \Return $mid$
    \ElsIf{$A[mid] < x$}
      \State $low \gets mid+1$
    \Else
      \State $high \gets mid-1$
    \EndIf
  \EndWhile
  \State \Return $-1$
\end{algorithmic}
\end{algorithm}

Rendered output

Algorithm 1: Binary search

  1. low ← 1, high ← |A|
  2. while low ≤ high
  3. mid ← ⌊(low + high)/2⌋
  4. if A[mid] = x: return mid
  5. else if A[mid] < x: low ← mid + 1
  6. else: high ← mid − 1
  7. return −1

Learn about loops, conditions, input/output, and algorithm references in the algorithm guide.

7. Labels, references, and citations

Give figures, tables, equations, and sections a unique label, then refer to them with \ref. Put a figure or table label after its caption so it captures the correct number.

\section{Method}\label{sec:method}
As described in Section~\ref{sec:method}, ...

% With biblatex in the preamble:
% \usepackage[backend=biber,style=numeric]{biblatex}
% \addbibresource{references.bib}
Prior work supports this choice \cite{smith2024}.
% Place near the end of the document:
% \printbibliography

Keep bibliography records in a .bib file and compile with the bibliography tool requested by your setup (for example, Biber with biblatex). Cross-references may need another LaTeX compile to settle.

8. A practical workflow

  1. Start with a small document and compile early.
  2. Add one package or feature at a time; package conflicts are easier to find that way.
  3. Use meaningful labels such as fig:system, tab:results, and eq:loss.
  4. Keep figures, bibliography data, and source files organized in folders.
  5. Read the first useful error in the compiler log; later errors may be consequences of it.

Specialized pages: images, tables, formulas, and algorithms.

Want to compile from the terminal?

Follow the dedicated Tectonic tutorial for installation on Linux, macOS, and Windows, creating a project, compiling PDFs, and troubleshooting common errors.