10 · LaTeX
LaTeX is the typesetting system universities and scientific journals have used for 40 years. It separates content from layout, produces stunning PDFs, and makes equations + references feel automatic. You'll use it to generate the PDF documentation in Lab 1.2 and any project report you write.
Why LaTeX?
For most writing, Markdown is easier. But LaTeX is essential when you need:
- Mathematical equations — nothing else comes close.
- Bibliographies and citations — add papers to a
.bibfile, cite with\cite{key}, get a formatted reference list automatically. - Consistency across 50+ pages — headers, page numbers, figure numbering, table of contents all "just work".
- Journal / conference templates — NeurIPS, IEEE, ACM all publish
.textemplates. - Reproducible PDFs — source control a
.texfile; anyone runningpdflatexgets the same output.
The Two Ways to Use LaTeX
Option A — Overleaf (the easy way)
Overleaf is a web-based LaTeX editor. No install, live preview, free for personal use, collaborative like Google Docs.
- Go to overleaf.com.
- Sign up (free tier is fine).
- New Project → Blank Project.
- Edit the left pane, watch PDF render on the right.
This is how 90% of students use LaTeX. Start here.
Option B — Local install with pandoc (for Lab 1.2)
For automated builds (CI, GitHub Actions), you want a local LaTeX + pandoc install.
macOS
# MacTeX is huge (~4 GB). For most people, BasicTeX is enough:
brew install --cask basictex
# Then add packages as needed:
sudo tlmgr update --self
sudo tlmgr install collection-fontsrecommended
# Pandoc for Markdown → LaTeX conversion
brew install pandoc
Linux (Ubuntu)
sudo apt install texlive-full pandoc # ~5 GB
# Or lighter:
sudo apt install texlive-latex-recommended texlive-fonts-recommended texlive-latex-extra pandoc
Verify:
pdflatex --version
pandoc --version
Your First Document
\documentclass[11pt]{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{hyperref} % clickable links
\usepackage{graphicx} % include images
\usepackage{amsmath, amssymb} % math
\title{Tools in Data Science}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
LaTeX turns plain text into \textbf{professional documents}.
\section{Math}
Einstein said $E = mc^2$. The fundamental theorem of calculus:
\begin{equation}
\int_a^b f'(x)\, dx = f(b) - f(a)
\end{equation}
\section{References}
Visit \url{https://iitm.ac.in}.
\end{document}
Compile:
pdflatex hello.tex # creates hello.pdf
LaTeX needs two passes to resolve forward references (table of contents, \ref{}, page numbers). Always run pdflatex twice, or use latexmk:
latexmk -pdf hello.tex
Essential Structure Commands
\documentclass[options]{class} % article | report | book | beamer (slides)
\usepackage{pkg} % import package (hyperref, graphicx, etc.)
\title{...} \author{...} \date{...}
\maketitle % render title block
\tableofcontents % auto-generated TOC
\section{Intro} % H1
\subsection{Background} % H2
\subsubsection{Details} % H3
\label{sec:intro} % attach a label
Refer to Section~\ref{sec:intro}. % reference it
Text Formatting
| LaTeX | Result |
|---|---|
\textbf{bold} | bold |
\textit{italic} | italic |
\texttt{code} | code (monospace) |
\emph{emphasis} | emphasis (context-aware) |
\underline{under} | underlined |
\footnote{note} | footnote superscript + note at page bottom |
Math Mode — LaTeX's Superpower
Inline math with $...$:
The speed of light is $c \approx 3 \times 10^8$ m/s.
Display math with \[ ... \] (or \begin{equation}...\end{equation} for numbering):
\[
\hat{y} = \arg\max_y P(y \mid x) = \arg\max_y \frac{P(x \mid y) P(y)}{P(x)}
\]
Common constructs:
| LaTeX | Math |
|---|---|
\frac{a}{b} | a/b as fraction |
\sqrt{x} | √x |
x^2, x_{ij} | superscript / subscript |
\sum_{i=1}^n, \prod, \int | Σ, Π, ∫ |
\alpha, \beta, \gamma, ... \omega | Greek letters |
\mathbb{R}, \mathbb{N} | ℝ, ℕ |
\mathbf{v} | bold vector |
\to, \leftarrow, \Rightarrow | arrows |
\leq, \geq, \neq, \approx | relations |
\in, \subset, \cup, \cap | set operations |
Matrices:
\[
A = \begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{pmatrix}
\]
Images and Figures
\usepackage{graphicx}
% Just the image
\includegraphics[width=0.6\linewidth]{plots/loss.png}
% Figure with caption + label
\begin{figure}[h] % h = here, t = top, b = bottom, p = page
\centering
\includegraphics[width=0.8\linewidth]{diagram.pdf}
\caption{Architecture of our RAG system.}
\label{fig:arch}
\end{figure}
Refer to Figure~\ref{fig:arch}.
Tables
\begin{table}[h]
\centering
\begin{tabular}{lcr} % l=left, c=center, r=right
\hline
Model & Accuracy & F1 \\
\hline
BM25 & 0.72 & 0.69 \\
Dense & 0.81 & 0.78 \\
Hybrid & \textbf{0.86} & \textbf{0.84} \\
\hline
\end{tabular}
\caption{Retrieval results on the TDS benchmark.}
\label{tab:retrieval}
\end{table}
For prettier tables, use the booktabs package (\toprule, \midrule, \bottomrule).
Citations with BibTeX
Create a references.bib file:
@article{vaswani2017attention,
title = {Attention Is All You Need},
author = {Vaswani, Ashish and others},
journal = {NeurIPS},
year = {2017}
}
@misc{astral2024uv,
title = {uv: An extremely fast Python package manager},
author = {{Astral Software}},
year = {2024},
url = {https://github.com/astral-sh/uv}
}
In your .tex:
\usepackage{natbib} % or: \usepackage{biblatex} for modern bibliography
Transformers were introduced by \cite{vaswani2017attention}.
\bibliographystyle{plain}
\bibliography{references}
Compile order: pdflatex → bibtex → pdflatex → pdflatex. Or just latexmk -pdf.
Pandoc — Markdown → PDF in One Command
For Lab 1.2 we'll convert Markdown docs to LaTeX-rendered PDFs. Pandoc is the tool.
# Basic
pandoc README.md -o README.pdf
# With nice engine (unicode fonts, better typography)
pandoc README.md -o README.pdf --pdf-engine=xelatex
# With title, TOC, sections, syntax highlighting
pandoc docs/intro.md -o intro.pdf \
--pdf-engine=xelatex \
--toc \
--number-sections \
-V geometry:margin=1in \
-V fontsize=11pt \
-V colorlinks=true \
--highlight-style=tango
A Custom Template
Create template.tex to control the look:
\documentclass[11pt, a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{$title$}
\rhead{\today}
\title{$title$}
\author{$author$}
\begin{document}
\maketitle
\tableofcontents
\newpage
$body$
\end{document}
Use it:
pandoc README.md -o README.pdf \
--template=template.tex \
--pdf-engine=xelatex
LaTeX Project Structure for Labs
project/
├── main.tex # document root
├── sections/
│ ├── intro.tex
│ ├── methods.tex
│ └── results.tex
├── figures/
│ ├── arch.pdf
│ └── loss.png
├── references.bib
└── Makefile
In main.tex:
\input{sections/intro}
\input{sections/methods}
\input{sections/results}
Makefile:
main.pdf: main.tex sections/*.tex references.bib
latexmk -pdf -interaction=nonstopmode main.tex
clean:
latexmk -C
rm -f *.bbl *.aux *.log
Common Pitfalls
These characters have special meaning in LaTeX: & % $ # _ { } ~ ^ \
To print them literally: \& \% \$ \# \_ \{ \} \~{} \^{} \textbackslash
Pandoc handles this for you when converting from Markdown.
! LaTeX Error: File xxx.sty' not found.On TeX Live, install withsudo tlmgr install xxx`. On MiKTeX, it auto-installs on demand.
5-Minute Exercise
- Open overleaf.com → New Project → Blank.
- Paste the
hello.texabove. - Click Recompile → see the PDF.
- Add an equation:
latex\[ \sum_{i=1}^{100} i = \frac{100 \cdot 101}{2} = 5050 \]
- Download PDF — share on Discourse.
Further Reading
- Overleaf Learn — the best LaTeX reference site
- A Short Introduction to LaTeX2e (lshort) — the classic 100-page PDF
- pandoc manual
- Detexify — draw a symbol, get the LaTeX command
- LaTeX Wikibook