To write in LaTeX, you type plain text with short commands that describe the structure of your document (title, sections, lists, equations), and a LaTeX compiler turns that file into a typeset PDF. You don’t format anything by hand: you say “this is a section” or “this is an equation”, and LaTeX numbers, spaces and lays it out for you.
This tutorial takes you from an empty file to a complete document with formatted text, lists, maths, tables, figures and citations. Every example was compiled before publishing, and the screenshots show the real output. At the end there is a list of the errors beginners hit most often, with the exact messages LaTeX prints and how to fix each one.
What Is LaTeX?
LaTeX (pronounced “lay-tek” or “lah-tek”) is a document preparation system built on TeX, the typesetting program Donald Knuth released in 1978. Leslie Lamport wrote LaTeX in the early 1980s to add higher-level commands, such as sections and automatic numbering, on top of TeX. The version everyone uses today is LaTeX2e, maintained by the LaTeX Project.
The key idea is the separation of content and formatting. In a word processor, you change the look of each heading yourself. In LaTeX, you mark something as \section{...}, and the document class decides how every section looks. Change the class (for example to a journal’s template), and the whole document is reformatted. That is why LaTeX is the standard for maths-heavy papers, theses, technical reports and many CVs.
| LaTeX | Word processor (Word, Google Docs) | |
|---|---|---|
| How you write | Plain text with commands, then compile | What you see is what you get |
| Formatting | Set once by the document class and packages | Applied by hand, paragraph by paragraph |
| Numbering and cross-references | Automatic for sections, equations, tables, figures, citations | Partly automatic, easy to break |
| Maths | Excellent | Workable for simple formulas |
| Version control | Plain text, works well with Git | Binary files, hard to diff |
| Learning curve | Steeper at the start | Low |
Where to Write LaTeX
You need an editor and a TeX distribution (the compiler plus packages). There are two common setups:
- Online with Overleaf: nothing to install, real-time collaboration and hundreds of templates. The free plan is enough to learn. See what Overleaf is and how to use it.
- On your computer: install TeX Live (Windows, Linux, macOS), MiKTeX (Windows) or MacTeX (macOS), then use an editor such as TeXstudio, or VS Code with the LaTeX Workshop extension. This works offline and has no compile time limits.
For this tutorial I compiled every example with Tectonic 0.17, a self-contained TeX engine. The source files are standard LaTeX, so they compile the same way in Overleaf or TeX Live.
Your First LaTeX Document
Create a file called main.tex and type this:
\documentclass{article}
\title{My First LaTeX Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
Hello, LaTeX! This is a normal paragraph.
LaTeX joins these two lines into one paragraph.
A blank line starts a new paragraph.
\end{document}Compile it (the Recompile button in Overleaf, or the build button in your editor), and you get this PDF:

Notice what happened. The section was numbered “1” without you typing a number. The two lines in the first paragraph were joined into one, because a single line break in the source is just a space. The blank line started a new paragraph. This is the most important rule of LaTeX spacing: blank lines make paragraphs; extra spaces and single line breaks are ignored.
The Structure of a LaTeX Document
Every LaTeX file has two parts:
- The preamble, everything before
\begin{document}. It sets the document class, loads packages and defines settings such as the title and margins. - The body, between
\begin{document}and\end{document}. This is your content.
The first line, \documentclass{...}, picks the overall layout. The standard classes are:
| Class | Use it for |
|---|---|
article | Papers, short reports, assignments, most documents |
report | Longer reports and theses with chapters |
book | Books (two-sided layout, chapters, front matter) |
beamer | Presentation slides |
letter | Letters |
Options go in square brackets, such as \documentclass[11pt,a4paper]{article}. Journals and universities usually provide their own class files, which is how one source file can be reformatted for a different publisher.
Commands and environments
LaTeX has two kinds of markup. A command starts with a backslash and takes arguments in braces: \textbf{bold}, \section{Results}. An environment wraps a block between \begin{name} and \end{name}: lists, equations, tables and figures are all environments. Comments start with % and run to the end of the line.
A Complete Example: Text, Lists, Maths, Tables, Figures and Citations
The rest of this tutorial walks through one complete document. Here is its preamble, with a comment on what each package does:
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry} % page margins
\usepackage{amsmath} % align, cases, matrices
\usepackage{graphicx} % \includegraphics
\usepackage{booktabs} % professional table rules
\usepackage{xcolor} % colours
\usepackage[hidelinks]{hyperref} % clickable references, load last
\newcommand{\term}[1]{\textbf{#1}} % a custom commandAnd here are the two pages it produces. The sections below explain each part.


Sections
Use \section{}, \subsection{} and \subsubsection{} for headings; the report and book classes add \chapter{}. LaTeX numbers them, and \tableofcontents builds a contents page from them. Add an asterisk, as in \section*{Acknowledgements}, for an unnumbered heading.
Formatting text
\section{Text}
Use \textbf{bold}, \textit{italic}, \emph{emphasis}, \underline{underline},
\texttt{monospace} and \textcolor{blue}{colour}. A \term{custom command}
keeps formatting consistent. Special characters need a backslash:
\# \$ \% \& \_ \{ \}.
{\small small} {\large large} {\Large Larger} {\huge huge}| To get | Write |
|---|---|
| Bold | \textbf{text} |
| Italic | \textit{text} |
| Emphasis (italic, or upright inside italic text) | \emph{text} |
| Underline | \underline{text} |
| Monospace (code, file names) | \texttt{text} |
| Colour (needs xcolor) | \textcolor{blue}{text} |
| Font size for a group | {\large text}; sizes run \tiny, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge |
Prefer \emph to \textit for emphasis in running text: it describes meaning rather than appearance, which is the LaTeX way. The custom \term command used here is defined in the preamble with \newcommand; if you later decide terms should be italic instead of bold, you change one line.
Special characters
Ten characters have special meanings in LaTeX. Typing them directly causes errors or strange output, so escape them:
| Character | Meaning in LaTeX | To print it, write |
|---|---|---|
# | Macro parameter | \# |
$ | Starts and ends inline maths | \$ |
% | Starts a comment | \% |
& | Column separator in tables | \& |
_ | Subscript (maths only) | \_ |
{ } | Group arguments | \{ \} |
~ | Non-breaking space | \textasciitilde |
^ | Superscript (maths only) | \textasciicircum |
\ | Starts a command | \textbackslash |
For quotation marks, type two backticks for an opening quote and two apostrophes for a closing one: ``quoted''. A plain double-quote character gives the wrong opening quote in many setups.
Lists
\begin{itemize}
\item An unordered item
\item Another item
\end{itemize}
\begin{enumerate}
\item First step
\item Second step
\end{enumerate}itemize gives bullets and enumerate gives numbers. Lists can be nested up to four levels, and description gives labelled items (\item[Term] Definition).
Maths
Inline maths: $a^2 + b^2 = c^2$ or \(e^{i\pi} + 1 = 0\).
A numbered equation:
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\label{eq:quadratic}
\end{equation}
Equation~\eqref{eq:quadratic} is numbered automatically. Aligned lines:
\begin{align}
f(x) &= (x + 1)^2 \\
&= x^2 + 2x + 1
\end{align}
A matrix: $\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$.- Inline maths goes between
$...$or\(...\). - Numbered equations use the
equationenvironment. Give them a\labeland refer to them with\eqref, which adds the brackets. - Multi-line equations use
alignfrom the amsmath package:&marks the alignment point and\\ends a line. Each line gets a number; usealign*for none. - Unnumbered display maths goes between
\[ ... \]. - Common building blocks:
\frac{a}{b}for fractions,\sqrt{x},x^2andx_ifor superscripts and subscripts, Greek letters such as\alphaand\pi,\sumand\int, andpmatrixorbmatrixfor matrices.
Tables
\begin{table}[h]
\centering
\begin{tabular}{lrr}
\toprule
Endpoint & Before (ms) & After (ms) \\
\midrule
/search & 180 & 95 \\
/profile & 120 & 70 \\
\bottomrule
\end{tabular}
\caption{Median latency before and after caching.}
\label{tab:results}
\end{table}The column spec {lrr} means one left-aligned and two right-aligned columns (c centres). Inside the table, & separates cells and \\ ends a row. The \toprule, \midrule and \bottomrule commands from booktabs give the clean, professional look, with no vertical lines.
Figures
\begin{figure}[h]
\centering
\includegraphics[width=0.5\textwidth]{figures/latency.png}
\caption{Median latency per endpoint.}
\label{fig:latency}
\end{figure}Tables and figures are floats: LaTeX places them where they fit best, not necessarily where they appear in the source. In this example, both moved to page 2 even though I asked for [h] (“here”), because there wasn’t enough room left on page 1. This is normal. Always refer to floats by number (Table~\ref{tab:results}), never as “the table below”. The ~ is a non-breaking space, so “Table” and its number stay on one line.
Citations and bibliography
Put your references in a separate .bib file. Reference managers such as Zotero and Mendeley can export one for you.
@book{lamport1994,
author = {Leslie Lamport},
title = {{\LaTeX}: A Document Preparation System},
edition = {2nd},
publisher = {Addison-Wesley},
year = {1994}
}Then cite with the entry’s key and print the list where you want it:
\section{Citations}
LaTeX is documented in Lamport's book \cite{lamport1994}.
\bibliographystyle{plain}
\bibliography{refs}LaTeX produced the reference list on page 2 automatically, numbered and formatted in the plain style. Changing the style (for example to ieeetr or apalike) reformats every citation at once. For more control over citation styles, the biblatex package with the Biber processor is the modern alternative to BibTeX.
Packages Worth Knowing
Packages add features. Load them in the preamble with \usepackage{name}, with options in square brackets. These cover most documents:
| Package | What it does |
|---|---|
geometry | Page size and margins |
amsmath, amssymb | Extra maths environments (align, cases) and symbols |
graphicx | Include images with \includegraphics |
booktabs | Professional table rules |
xcolor | Coloured text and backgrounds |
hyperref | Clickable links, cross-references and PDF bookmarks; load it last |
listings or minted | Code blocks with syntax highlighting |
biblatex | Modern bibliography handling |
fancyhdr | Custom headers and footers |
tikz | Diagrams drawn in code |
Overleaf and full TeX Live installations include all of these, so you rarely need to install anything.
Splitting Large Documents
For a thesis or a long report, keep the preamble in main.tex and put each chapter in its own file:
main.tex
chapters/
introduction.tex
method.tex
results.tex\begin{document}
\include{chapters/introduction}
\include{chapters/method}
\include{chapters/results}
\end{document}\include starts each file on a new page and lets you compile only some chapters with \includeonly, which speeds up work on long documents. \input simply pastes the file in place, so use it for sections within a chapter. Separate files also make collaboration and version control much easier.
Common LaTeX Errors and How to Fix Them
LaTeX stops on errors instead of guessing, which feels harsh at first. Each message names the file and line number. These are the five I triggered on purpose, with the exact messages:
| What you wrote | Error message | Fix |
|---|---|---|
Item #1 costs 5% more | You can't use `macro parameter character #' in horizontal mode | Escape it: \#. The % also needs \%; otherwise the rest of the line silently disappears as a comment |
\includegraphics{photo.png} without graphicx | Undefined control sequence | Load the package (\usepackage{graphicx}) or fix the command’s spelling |
\textbf{Unclosed bold text. | File ended while scanning use of \textbf | Add the missing closing brace |
\\ at the start of a paragraph | LaTeX Error: There's no line here to end. | Use a blank line for a new paragraph, or \vspace{} for extra space |
\input{chapter1} with a wrong path | LaTeX Error: File `chapter1.tex' not found. | Check the file name and folder; paths are relative to the main file |
Two more tips: fix the first error in the log, because later errors are often knock-on effects. And when a citation or reference shows as [?] or ??, compile again; LaTeX needs more than one pass to resolve references (Overleaf and latexmk do this for you).
Beginner Habits That Save Time
- Let LaTeX number things. Never type “Section 2” or “(3)” by hand; use
\labeland\ref. - Use structure, not formatting.
\section{Introduction}, not\textbf{\Large Introduction}. - Compile often. An error after ten new lines is easy to find; after two hundred, it isn’t.
- Start from a template when a journal, university or employer provides one.
- Keep images as PDF for plots and diagrams, PNG for screenshots and JPEG for photos.
Conclusion
Writing in LaTeX comes down to a few ideas: a preamble that sets up the document, a body made of structural commands and environments, blank lines for paragraphs, escaped special characters, and labels instead of hand-typed numbers. With the example in this tutorial, you can already produce a document with sections, formatted text, lists, numbered equations, tables, figures and a bibliography. From here, open it in Overleaf or a local editor, start from a template, and look up each new package as you need it.
FAQs
How do I start writing in LaTeX?
Open Overleaf (no installation) or install TeX Live, MiKTeX or MacTeX with an editor. Create a .tex file with \documentclass{article}, \begin{document}, your text and \end{document}, then compile it to get a PDF.
Is LaTeX hard to learn?
The basics take an afternoon: sections, formatting, lists, equations and figures cover most documents. The harder part is fixing errors, and that gets easy once you know to read the first error message and its line number.
How do I start a new line in LaTeX?
Leave a blank line to start a new paragraph. Use \\ (two backslashes) to break a line inside a paragraph, but not at the start of a paragraph, which causes the “There’s no line here to end” error.
How do I write special characters like # $ % in LaTeX?
Put a backslash before them: \#, \$, \%, \&, \_, \{ and \}. The tilde, caret and backslash need \textasciitilde, \textasciicircum and \textbackslash.
What is the difference between LaTeX and TeX?
TeX is the low-level typesetting engine Donald Knuth created. LaTeX is a set of higher-level commands on top of TeX, written by Leslie Lamport, that handles document structure, numbering and cross-references.
Can I write LaTeX without installing anything?
Yes. Overleaf runs LaTeX in the browser with a full TeX distribution, so you can write and compile without installing software.








