Learn LaTeX: Tutorial for Beginners
LaTeX in 60 seconds
- LaTeX is plain text plus commands that a compiler turns into a PDF. Commands start with
\; arguments go in{...}. - Every document is
\documentclass{article}, a preamble of\usepackagelines, then the text between\begin{document}and\end{document}. - Math goes between
$...$; a blank line starts a new paragraph;%starts a comment. - No install needed: paste the document below into an online editor and compile.
\documentclass{article}
\usepackage{amsmath}
\title{Hello, \LaTeX}
\author{Your Name}
\begin{document}
\maketitle
\section{Introduction}
This is \textbf{bold}, this is \emph{emphasis}, and this is math:
$e^{i\pi} + 1 = 0$.
\end{document}This LaTeX tutorial takes you from nothing to a compiled PDF with a title, sections, formatted text, lists, an equation, a table, a figure and a citation. It explains what LaTeX is and when to use it, how to start with zero installation, what every line of the preamble does, how to read an error log, and where to go next. Every snippet compiles as written.
What LaTeX Is and When to Use It
LaTeX (pronounced “LAY-tek” or “LAH-tek”) is a document preparation system. You write plain text with commands that describe the structure of the document — this is a section, this is emphasised, this is an equation — and a compiler turns it into a PDF. Unlike a word processor, you do not arrange the page by hand; LaTeX makes the typographic decisions from the structure you give it, which is why documents written by two different people in the same class look consistent.
It is the right tool when:
- You write mathematics. LaTeX's math typesetting is still the standard that every other system imitates, and most journals and arXiv expect it.
- The document is long or structured. Numbering of sections, figures, tables and equations, cross-references, the table of contents and the bibliography are all automatic and stay correct as the document changes.
- You cite a lot. Keep references in one
.bibfile and switch citation style for a different journal by changing one line. - You work with others or with version control. Source files are plain text, so Git diffs, reviews and merges work.
- A template is required. Theses, conference papers, CVs and slides (Beamer) all have mature templates.
It is the wrong tool for a one-page letter you need in five minutes, for documents where a colleague must leave tracked changes in Word, or for layouts built around precise manual placement of images. For everything in between, it is worth the afternoon it takes to learn.
Learning Path: Learn LaTeX in 12 Steps
Work through these in order. Each step is a short guide with examples that compile as written; by step 10 you can write a full paper with citations, and the rest add polish.
- Your first document (below) – the document class, preamble and body
- Special characters – escaping
& % $ # _so they print - Bold, italics and underline –
\textbf,\emphand friends - Sections and headings, then the table of contents
- Lists – itemize, enumerate and description
- Mathematical expressions – inline and display math, fractions, roots
- Subscripts and superscripts and Greek letters
- Tables – tabular and booktabs
- Equation numbering and cross-references –
\label,\ref,\eqref - Bibliographies and citations – BibTeX and biblatex styles
- Page size and margins and hyperlinks
- TikZ diagrams and pgfplots charts
What You Need
To write LaTeX you need an editor and a TeX distribution that compiles the source to PDF. There are two ways to get them:
| Online editor | Local install (TeX Live / MiKTeX) | |
|---|---|---|
| Setup | None; open a browser | Download a few hundred MB (MiKTeX basic) to about 7 GB (full TeX Live), plus an editor |
| Packages | All installed already | TeX Live: all; MiKTeX: fetched on first use |
| Works offline | No | Yes |
| Collaboration | Share a link | Git or file sharing |
| Best for | Learning, coursework, papers with co-authors | Large theses, offline work, custom build setups |
To start right now, use an online editor. Octree is free, runs in the browser, compiles your document on every save and shows the PDF beside the source. Its AI assistant can write or fix LaTeX for you, which is a good way to learn a command you do not know yet. Overleaf is the other well-known online option.
For local, offline work install a TeX distribution and an editor:
- TeX Live (Windows, Linux; on macOS as MacTeX) – the complete distribution, several gigabytes with every package. Install once a year.
- MiKTeX (Windows, also macOS and Linux) – smaller; installs packages on demand the first time a document needs them.
- An editor – TeXstudio and TeXworks come with everything configured; VS Code with the LaTeX Workshop extension is popular with programmers.
Whichever you choose, the workflow is the same: write a .tex file, compile it with pdfLaTeX, look at the PDF, repeat.
Your First Document
Paste this into a new file called main.tex and compile it. It is a complete, valid document:
\documentclass{article}
\title{My First Document}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
Hello, \LaTeX{}! This is my first document.
\section{Mathematics}
Here is an inline equation: $E = mc^2$.
And a displayed equation:
\[
\int_0^\infty e^{-x^2} \, \mathrm{d}x = \frac{\sqrt{\pi}}{2}
\]
\end{document}Four things to notice:
- Commands start with a backslash:
\section,\maketitle. Their arguments go in curly braces. - Everything before
\begin{document}is the preamble; it configures the document but prints nothing. - Environments come in
\begin{...}/\end{...}pairs.documentis the outermost one. - A blank line starts a new paragraph. A single line break is just a space. A
%starts a comment that runs to the end of the line.
Ten characters have special meaning and must be escaped to print them literally: \& \% \$ \# \_ \{ \}, plus \textasciitilde, \textasciicircum and \textbackslash. Forgetting to escape a % or & is the most common beginner error; the special characters guide has the full list.
The Preamble Explained
A realistic preamble is a little longer. Here is one you can use for almost any article, with every line explained:
\documentclass[12pt,a4paper]{article} % class and its options
\usepackage[utf8]{inputenc} % source file is UTF-8 (default since 2018; harmless)
\usepackage[T1]{fontenc} % proper hyphenation and accented characters in the PDF
\usepackage{amsmath} % equations, align, cases, matrices
\usepackage{graphicx} % \includegraphics
\usepackage{booktabs} % professional table rules
\usepackage{hyperref} % clickable links and references; load last
\title{My First Document}
\author{Your Name}
\date{\today} % or \date{} for no dateDocument classes
The class sets the overall design. Options in square brackets adjust it: font size (10pt, 11pt, 12pt), paper (a4paper, letterpaper), two-sided printing (twoside), and so on.
article– papers, short reports, homework. Sections but no chapters.report– longer documents with chapters and a title page.book– books: chapters, front and back matter, two-sided layout.beamer– presentations.letter– formal letters.
Packages
Packages extend LaTeX, and almost every document loads a few. Beyond the ones above, the ones you will meet first are geometry (margins, see page size and margins), xcolor (colors), enumitem (list styling), siunitx (units) and biblatex (citations). Load a package once, in the preamble; loading it twice with different options is an error.
Text Formatting
\textbf{bold}, \textit{italic}, \emph{emphasised}, \underline{underlined},
\texttt{monospace}, \textsc{Small Caps}
{\large larger text} and {\small smaller text} % braces limit the scope
A long dash---like this---and an en dash for ranges: 1990--2000.
Quotes use ``two backticks and two apostrophes''.| Command | Result |
|---|---|
\textbf{bold} | bold |
\textit{italic} | italic |
\emph{emphasis} | emphasis (italic in upright text, upright in italic text) |
\underline{underline} | underline |
\texttt{monospace} | monospace |
Prefer \emph over \textit for emphasis, and use underlining sparingly; it is a typewriter habit. The bold, italics and underline guide covers nesting, bold math and the ulem and soul packages, and the font size guide lists every size command.
Sections and Structure
\section{Introduction} % 1
\subsection{Background} % 1.1
\subsubsection{Earlier work} % 1.1.1
\paragraph{A run-in heading} % bold, unnumbered, inline
\section*{Acknowledgements} % starred: no number, not in the contents
\tableofcontents % anywhere; compile twice to fill itNumbering, the table of contents and running heads are generated from these commands, which is why you never type “1.1” yourself. In report and book there is also \chapter above \section. Give a section a \label and refer to it with \ref; the number updates itself when sections move. The sections guide covers numbering depth, custom heading styles and unnumbered sections in the contents.
\section{Method}\label{sec:method}
...
As described in Section~\ref{sec:method}, ... % ~ is a non-breaking spaceLists
% Bullet points
\begin{itemize}
\item First item
\item Second item
\end{itemize}
% Numbered list
\begin{enumerate}
\item First step
\item Second step
\end{enumerate}
% Term and definition
\begin{description}
\item[Compiler] Turns .tex into .pdf.
\item[Preamble] Everything before \verb|\begin{document}|.
\end{description}Lists nest inside each other, and the enumitem package changes bullets, numbering (a), (b), (c) and spacing. See lists and bullet points in LaTeX.
Mathematics
Math goes in math mode: $...$ inside a sentence, \[...\] for a displayed formula on its own line, and equation for a numbered one. Load amsmath for anything beyond the basics.
% Inline math
The equation $a^2 + b^2 = c^2$ is Pythagoras' theorem.
% Display math
\[
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\]
% Numbered equation with a reference
\begin{equation}
a^2 + b^2 = c^2 \label{eq:pythagoras}
\end{equation}
Equation~\eqref{eq:pythagoras} holds for right triangles.
% Aligned equations (amsmath)
\begin{align}
f(x) &= x^2 + 2x + 1 \\
&= (x + 1)^2
\end{align}The building blocks are ^ and _ for superscripts and subscripts, \frac{a}{b} for fractions, \sqrt, Greek letters such as \alpha, and operators such as \sum and \int. Start with mathematical expressions, then integrals, sums and limits, matrices and Greek letters and symbols.
Tables
A tabular holds the rows: the argument lcc says there are three columns, the first left-aligned and the other two centred; & separates cells and \\ ends a row. The table environment around it makes it a floating, numbered table with a caption.
\usepackage{booktabs} % preamble
\begin{table}[htbp]
\centering
\begin{tabular}{lcc}
\toprule
Name & Score & Grade \\
\midrule
Alice & 95 & A \\
Bob & 87 & B \\
Charlie & 92 & A \\
\bottomrule
\end{tabular}
\caption{Student grades}
\label{tab:grades}
\end{table}
Table~\ref{tab:grades} lists the results.Use the three booktabs rules and no vertical lines; that is what journals expect. Column widths, merged cells, long tables and colour are in the tables guide, and the Excel to LaTeX converter turns a spreadsheet into this code.
Figures and Images
Images need the graphicx package and \includegraphics. The figure environment makes the image float to a good position, numbers it and adds the caption; the \label must come after the \caption so \ref picks up the right number.
\usepackage{graphicx} % preamble
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{example-image}
\caption{A descriptive caption.}
\label{fig:plot}
\end{figure}
See Figure~\ref{fig:plot}.example-imageis a placeholder picture that ships with every TeX distribution (themwepackage), so the snippet compiles as written; replace it with your own file name, such asplot.png.[htbp]lists the placements LaTeX may use: here, top of page, bottom, or a page of floats. It is a preference, not a command;[H]from thefloatpackage forces “exactly here”.width=0.8\textwidthscales the image to 80% of the text width;scale=0.5andheight=5cmalso work.- PDF, PNG and JPEG are accepted by pdfLaTeX; an EPS file is converted to PDF on the fly (graphicx loads
epstopdffor you), and SVG needs thesvgpackage or a manual export to PDF. - Put images in a folder and point to it once:
\graphicspath{{figures/}}. - Side-by-side images use the
subcaptionpackage; see subfigures. The figures guide covers placement, scaling and errors in depth.
Citations and Bibliography
References live in a .bib file, one entry per work. In the text, \cite{key} inserts the citation and the bibliography is generated from the entries you actually cited.
% references.bib
@article{einstein1905,
author = {Einstein, Albert},
title = {Zur Elektrodynamik bewegter K{\"o}rper},
journal = {Annalen der Physik},
year = {1905},
volume = {322},
number = {10},
pages = {891--921}
}
@book{knuth1984,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
year = {1984}
}BibTeX (classic)
As shown by Einstein~\cite{einstein1905}, and in~\cite[p.~5]{knuth1984}, ...
\bibliographystyle{plain} % or abbrv, unsrt, ieeetr, apalike
\bibliography{references} % the .bib file without extensionbiblatex (modern)
\usepackage[backend=biber,style=authoryear]{biblatex} % preamble
\addbibresource{references.bib} % also preamble
\textcite{knuth1984} wrote it; see also \parencite{einstein1905}.
\printbibliographyBoth need extra compilation runs: pdfLaTeX, then BibTeX or Biber, then pdfLaTeX twice more. Online editors and latexmk do this for you. BibTeX is what most journal templates still expect; biblatex is easier to customise and handles Unicode names and modern styles (APA, Chicago) better. The citation generator turns a DOI into a .bib entry.
Common Errors and How to Read the Log
When compilation fails, LaTeX writes a log. Scroll to the first line that begins with !; later errors are often consequences of it. The line number after l. says where LaTeX noticed the problem, which is usually at or just after the real mistake.
! Undefined control sequence.
l.42 \textbol
{important}| Message | Usual cause | Fix |
|---|---|---|
| Undefined control sequence | A misspelled command, or the package that defines it is not loaded | Check the spelling; add the \usepackage |
| Missing $ inserted | A math symbol (^, _, \alpha) outside math mode, or an unescaped _ in a URL or file name | Wrap in $...$, or write \_ |
| Runaway argument? / File ended while scanning use of ... | An unclosed brace { | Find the command named in the message and close its brace |
| \begin{itemize} ended by \end{document} | Mismatched or missing \end | Pair every \begin with its \end |
| File `foo.sty' not found | Package not installed | Install it with your distribution's package manager (MiKTeX does it automatically) |
| Missing \begin{document} | Printable text in the preamble, often a stray character after \usepackage | Move the text after \begin{document} |
| Misplaced alignment tab character & | A literal & in text | Write \& |
| Overfull \hbox (warning) | A line that could not be broken, often a long URL or formula | Usually ignorable; otherwise rephrase or allow hyphenation |
| LaTeX Warning: Reference `fig:plot' undefined | Labels are resolved on the next run | Compile again; if it persists, the label is misspelled or placed before the caption |
Two habits prevent most errors: compile often, so a mistake is in the few lines you just wrote, and comment out half the document with \iffalse ... \fi (see LaTeX comments) to find which half contains a stubborn one. Every message has its own page with causes and a broken and fixed example in LaTeX errors and warnings: meanings and fixes.
Next Steps: Every Guide
You now know enough LaTeX to write a complete document. Each guide below goes deep on one topic, with compiled examples you can copy.
Document structure and text
- Sections and Headings – \section, \subsection, numbering and the table of contents
- Document Classes – article, report, book, KOMA-Script and class options
- Title Page – \maketitle, the titlepage environment and custom designs
- Appendix – \appendix, lettered sections and the appendix package
- Environments – \begin, \end and \newenvironment
- Commands and Macros – \newcommand, \renewcommand and \def
- Bold, Italics & Underline – Text formatting commands and packages
- Font Size – \tiny to \Huge, class options and \fontsize
- Fonts – Serif, sans serif and monospace families and font packages
- Lists and Bullet Points – itemize, enumerate, description and enumitem
- Special Characters – Escaping &, %, $, # and typing accents and symbols
- Quotation Marks and Quotes – Correct quotes and block quotations
- Strikethrough & Cross Out – \sout, \cancel and track changes
- Footnotes – \footnote in text, tables and captions
- Hyperlinks – hyperref, \url, \href and link colours
- Comments – %, block comments and todo notes
- Colors – xcolor for text, boxes and tables
- Glossaries and Acronyms – The glossaries package and automatic acronym expansion
- Table of Contents – \tableofcontents, depth, links and styling
- Framebox and Boxed Text – \fbox, \framebox, boxed equations and colored frames
- Spacing – \hspace, \vspace, math spaces, line and paragraph spacing
- Paragraphs and Indentation – \noindent, \parindent, parskip and hanging indents
- Code Listings – listings, minted and verbatim
- Algorithms and Pseudocode – algpseudocode, algorithm2e and algorithmic
Page layout
- Page Size & Margins – The geometry package and landscape pages
- Page Numbering – Roman and arabic numbers, fancyhdr and “Page X of Y”
- Horizontal Lines – \hrule, \rule and table rules
- Two Columns – twocolumn, multicol and \multicolumn in tables
Citations and academic formats
- Bibliography Examples – APA, MLA, Chicago and IEEE with the LaTeX that produces them
- APA Title Page – APA 7 title pages and the apa7 class
- APA Headings – The five APA 7 heading levels
- MLA In-Text Citation – Examples for every case
- MLA Book Citation – Citing a book in MLA 9
- AMA Citation Format – In-text citations and reference examples
Mathematics
- Mathematical Expressions – Inline and display math, fractions, roots, cases and amsmath
- Piecewise Functions – The cases environment, conditions and dcases
- Subscripts & Superscripts – ^, _, exponents and text-mode scripts
- Brackets and Parentheses – \left, \right and every delimiter
- Underbrace and Overbrace – Annotated braces, \underset and \overset
- Integrals, Sums & Limits – \int, \sum, \lim and partial derivatives
- Multiline Equations – align, split, multline and breaking long equations
- Equation Numbering & Referencing – \label, \eqref, cleveref and custom tags
- Matrices – pmatrix, bmatrix, determinants and augmented matrices
- Math Functions – \sin, \log, \exp and \DeclareMathOperator
- LaTeX Symbols – The complete list: math, Greek, relations, logic, sets, arrows and brackets
- Greek Letters & Math Symbols – Epsilon vs varepsilon, bold and upright Greek
- The Greek Alphabet – All 24 letters with their LaTeX commands
- Theorems, Lemmas & Proofs – amsthm and the proof environment
- Blackboard Bold – \mathbb{R} and number sets
- Approximately Equal (≈) – \approx and its relatives
- Derivative Rules – Power, product, quotient and chain rules with LaTeX
- Laplace Transform Table – Common pairs and properties with LaTeX source
Tables, graphics and science
- Tables – booktabs, multicolumn, multirow, longtable and colour
- Figures and Images – \includegraphics, captions, placement and \ref
- Subfigures – Side-by-side figures and grids with subcaption
- TikZ – Diagrams and drawings in LaTeX
- PGFPlots – Publication-quality plots from data
- Molecular Orbital Diagrams – MO diagrams with TikZ and the modiagram package
- Beamer Presentations – Frames, themes, overlays and handouts
- Footnotes in Beamer – Footnotes on slides
Errors
- LaTeX Errors and Warnings – What 40 common log messages mean and how to fix them
Engines and languages
- XeLaTeX – Unicode input, system fonts with fontspec and when to use it
- Languages – babel, polyglossia, Spanish, Arabic, Chinese and more
Frequently Asked Questions
How long does it take to learn LaTeX?
The basics take an afternoon: a document is plain text with a handful of commands such as \section, \textbf and \begin{itemize}. Most people write a complete paper within a week by following the learning path on this page and looking up each new need (tables, figures, citations) when it comes up. You do not need to know everything to start.
Do I need to install anything to use LaTeX?
No. An online editor such as Octree compiles in the browser, so you can write and see the PDF without installing a TeX distribution. For offline work install TeX Live (Windows, Linux, macOS as MacTeX) or MiKTeX (Windows) plus an editor.
What is the difference between TeX and LaTeX?
TeX is the typesetting engine Donald Knuth wrote in 1978. LaTeX is a set of macros on top of TeX, written by Leslie Lamport, that gives you document-level commands like \section and \cite. When people say “LaTeX” they almost always mean writing documents with LaTeX macros, compiled by a modern engine such as pdfTeX, XeTeX or LuaTeX.
Should I use pdfLaTeX, XeLaTeX or LuaLaTeX?
pdfLaTeX is the default and works for most documents. Choose XeLaTeX or LuaLaTeX when you need system fonts (fontspec) or extensive non-Latin scripts. Journals and templates usually say which they expect; if nothing is specified, pdfLaTeX is the safe choice.
Why does my document not compile?
Open the log and find the first line starting with !. That is the error; everything after it may be a knock-on effect. The line number after l. tells you where. The most common causes are an unclosed brace or $, a misspelled command, and a package you forgot to load.
How do I convert a Word document to LaTeX?
Pandoc converts .docx to .tex with pandoc paper.docx -o paper.tex, and Octree can import a .docx or paste of formatted text. Expect to tidy the result: tables and equations in particular come out better when rewritten in LaTeX directly.
Free LaTeX Tools
- LaTeX Preview – Test your LaTeX code with live PDF preview
- Math to LaTeX – Convert handwritten equations to LaTeX
- Excel to LaTeX – Convert spreadsheets to LaTeX tables
- Citation Generator – Generate BibTeX citations from DOIs
- AI LaTeX Generator – Generate LaTeX from text descriptions
- LaTeX Symbols Reference – Browse math operators and Greek letters
LaTeX Templates
Get started quickly with our professional templates:
- Research Paper – IEEE-style academic paper
- PhD Thesis – Comprehensive thesis template
- Beamer Presentation – Academic slides
- View all templates →
Related LaTeX Articles
Angle Brackets ⟨ ⟩: Symbol, Copy and Paste, and LaTeX
Compile LaTeX from Claude Code or Cursor with the Octree MCP Server
Diameter Symbol (⌀): Meaning, ⌀ vs Ø, and How to Type It on Windows, Mac, Word, LaTeX
LaTeX on iPad: How to Write and Compile LaTeX on a Tablet
Write your first document now
Octree compiles in the browser, so there is nothing to install, and its AI assistant explains any error in the log in plain English.
Try Octree Free →