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 \usepackage lines, 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 .bib file 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.

  1. Your first document (below) – the document class, preamble and body
  2. Special characters – escaping & % $ # _ so they print
  3. Bold, italics and underline – \textbf, \emph and friends
  4. Sections and headings, then the table of contents
  5. Lists – itemize, enumerate and description
  6. Mathematical expressions – inline and display math, fractions, roots
  7. Subscripts and superscripts and Greek letters
  8. Tables – tabular and booktabs
  9. Equation numbering and cross-references – \label, \ref, \eqref
  10. Bibliographies and citations – BibTeX and biblatex styles
  11. Page size and margins and hyperlinks
  12. 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 editorLocal install (TeX Live / MiKTeX)
SetupNone; open a browserDownload a few hundred MB (MiKTeX basic) to about 7 GB (full TeX Live), plus an editor
PackagesAll installed alreadyTeX Live: all; MiKTeX: fetched on first use
Works offlineNoYes
CollaborationShare a linkGit or file sharing
Best forLearning, coursework, papers with co-authorsLarge 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. document is 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 date

Document 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''.
CommandResult
\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 it

Numbering, 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 space

Lists

% 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-image is a placeholder picture that ships with every TeX distribution (the mwe package), so the snippet compiles as written; replace it with your own file name, such as plot.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 the float package forces “exactly here”.
  • width=0.8\textwidth scales the image to 80% of the text width; scale=0.5 and height=5cm also work.
  • PDF, PNG and JPEG are accepted by pdfLaTeX; an EPS file is converted to PDF on the fly (graphicx loads epstopdf for you), and SVG needs the svg package or a manual export to PDF.
  • Put images in a folder and point to it once: \graphicspath{{figures/}}.
  • Side-by-side images use the subcaption package; 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 extension

biblatex (modern)

\usepackage[backend=biber,style=authoryear]{biblatex}   % preamble
\addbibresource{references.bib}                        % also preamble

\textcite{knuth1984} wrote it; see also \parencite{einstein1905}.

\printbibliography

Both 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}
MessageUsual causeFix
Undefined control sequenceA misspelled command, or the package that defines it is not loadedCheck the spelling; add the \usepackage
Missing $ insertedA math symbol (^, _, \alpha) outside math mode, or an unescaped _ in a URL or file nameWrap 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 \endPair every \begin with its \end
File `foo.sty' not foundPackage not installedInstall it with your distribution's package manager (MiKTeX does it automatically)
Missing \begin{document}Printable text in the preamble, often a stray character after \usepackageMove the text after \begin{document}
Misplaced alignment tab character &A literal & in textWrite \&
Overfull \hbox (warning)A line that could not be broken, often a long URL or formulaUsually ignorable; otherwise rephrase or allow hyphenation
LaTeX Warning: Reference `fig:plot' undefinedLabels are resolved on the next runCompile 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

Page layout

Citations and academic formats

Mathematics

Tables, graphics and science

Errors

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 Templates

Get started quickly with our professional templates:

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 →