Scientyfic World

How to Write in LaTeX: A Beginner’s Tutorial With Examples

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...

Share:

Get an AI summary of this article

LaTex blog banner image

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.

LaTeXWord processor (Word, Google Docs)
How you writePlain text with commands, then compileWhat you see is what you get
FormattingSet once by the document class and packagesApplied by hand, paragraph by paragraph
Numbering and cross-referencesAutomatic for sections, equations, tables, figures, citationsPartly automatic, easy to break
MathsExcellentWorkable for simple formulas
Version controlPlain text, works well with GitBinary files, hard to diff
Learning curveSteeper at the startLow

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:

Compiled output of a first LaTeX document: title, author, date, a numbered Introduction section and two paragraphs
Output of the first document. The two source lines of the first paragraph were joined; the blank line started a new, indented paragraph.

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:

ClassUse it for
articlePapers, short reports, assignments, most documents
reportLonger reports and theses with chapters
bookBooks (two-sided layout, chapters, front matter)
beamerPresentation slides
letterLetters

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 command

And here are the two pages it produces. The sections below explain each part.

Page 1 of the compiled LaTeX tour: text formatting, font sizes, bullet and numbered lists, inline and numbered equations, aligned equations and a matrix
Page 1 of the compiled example: formatted text, font sizes, lists, inline and numbered equations, aligned equations and a matrix.
Page 2 of the compiled LaTeX tour: a booktabs table, a figure with caption and an automatically generated reference list
Page 2: the table and figure (which LaTeX moved here because they did not fit on page 1) and the reference list generated from the .bib file.

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 getWrite
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:

CharacterMeaning in LaTeXTo 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 equation environment. Give them a \label and refer to them with \eqref, which adds the brackets.
  • Multi-line equations use align from the amsmath package: & marks the alignment point and \\ ends a line. Each line gets a number; use align* for none.
  • Unnumbered display maths goes between \[ ... \].
  • Common building blocks: \frac{a}{b} for fractions, \sqrt{x}, x^2 and x_i for superscripts and subscripts, Greek letters such as \alpha and \pi, \sum and \int, and pmatrix or bmatrix for 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:

PackageWhat it does
geometryPage size and margins
amsmath, amssymbExtra maths environments (align, cases) and symbols
graphicxInclude images with \includegraphics
booktabsProfessional table rules
xcolorColoured text and backgrounds
hyperrefClickable links, cross-references and PDF bookmarks; load it last
listings or mintedCode blocks with syntax highlighting
biblatexModern bibliography handling
fancyhdrCustom headers and footers
tikzDiagrams 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 wroteError messageFix
Item #1 costs 5% moreYou can't use `macro parameter character #' in horizontal modeEscape it: \#. The % also needs \%; otherwise the rest of the line silently disappears as a comment
\includegraphics{photo.png} without graphicxUndefined control sequenceLoad the package (\usepackage{graphicx}) or fix the command’s spelling
\textbf{Unclosed bold text.File ended while scanning use of \textbfAdd the missing closing brace
\\ at the start of a paragraphLaTeX 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 pathLaTeX 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 \label and \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.

Snehasish Konger
Developed @scientyficworld.org | Technical writer @Nected | Content Developer
Connect with Snehasish Konger

On This page

Take a Pause with Intervals

A Sunday letter on building, writing, and thinking deeper as a developer — short, honest, and worth your time.

Snehasish Konger profile photo

"Hey there — I'm Snehasish. Hope this post saved you some head-scratching time! I've spent years turning technical chaos into clarity, and I'm here to be your guide through the maze of modern tech. Stick around for more lightbulb moments — we're just getting started."

Related Posts