LaTeX for beginners
What to install, what a document is made of, and the handful of commands that carry most of the work. If you have not met LaTeX at all, start withwhat LaTeX is.
1. Decide where to run it
You have two reasonable options, and the choice is mostly about whether you want to install anything.
- In a browser. Several services run the whole toolchain server-side. Nothing to install, easy to collaborate, and you can be typesetting within a minute. The usual trade-off is that you need to be online and your document lives on someone else's machine.
- On your own machine. Install a distribution — TeX Live on Linux, MacTeX on macOS, MiKTeX or TeX Live on Windows — plus an editor. A full distribution is a large download (several gigabytes, because it includes thousands of packages), but then everything works offline and forever.
2. Understand the shape of a document
Every LaTeX document has the same two parts. The preamble comes first and sets things up; the body is the actual content, between \begin{document} and\end{document}.
\documentclass[12pt,a4paper]{article} % preamble starts
\usepackage{graphicx}
\title{My First Document}
\author{A. Name}
\begin{document} % body starts
\maketitle
\section{Introduction}
This is a paragraph. A blank line starts a new one.
\end{document}Two rules that surprise everybody at first: a single line break in your source does not start a new paragraph — a blank line does. And a% starts a comment, so to print an actual per-cent sign you write \%.
3. Learn these commands first
| Command | What it does |
|---|---|
| \documentclass{...} | Chooses the overall design: article, report, book, beamer. |
| \usepackage{...} | Loads an extension — graphics, maths, colour, bibliographies. |
| \section{...} | A numbered heading. Also \subsection and \subsubsection. |
| \textbf{...} | Bold. \emph{...} is emphasis, and usually what you want. |
| \begin{itemize} | A bulleted list; \begin{enumerate} numbers it instead. |
| \includegraphics{...} | Places an image. Needs \usepackage{graphicx}. |
| \label / \ref | Name a thing, then refer to it. LaTeX keeps the number right. |
| \cite{...} | Cite a source from your bibliography database. |
4. Start from a template, not a blank file
This is the single biggest time-saver for a beginner. A working document that already compiles gives you something to change one line at a time, which is a far better way to learn than assembling a preamble from scratch and debugging all of it at once. Change one thing, recompile, see what moved.
5. Expect to read errors
LaTeX's error messages are famously terse, and the line number it reports is where it noticed the problem, not always where you made it. Three habits handle most cases:
- Fix the first error, then recompile. One mistake cascades into a screenful of consequences; the rest often vanish.
- Check your braces. An unmatched
{is the most common cause of a baffling message a long way from the real problem. - Distinguish errors from warnings. "Overfull hbox" means a line stuck out slightly past the margin. It is cosmetic, extremely common, and safe to ignore while you are drafting.
6. Compile more than once
Cross-references, tables of contents and bibliographies work by writing information to an auxiliary file on one pass and reading it on the next. So a document with references usually needs two compilations to settle, and one with a bibliography needs a bibliography tool run in between. Most editors and build tools do this for you — if a reference shows up as??, an extra compile is the usual fix.
A realistic first hour
Open a template, compile it unchanged, and confirm you get a PDF. Change the title and your name. Add a section. Add a list. Break something deliberately and read the error. That sequence teaches you more than any amount of reading, because it puts the compile loop — the thing you will actually spend your time in — into your hands straight away.