A Beginner's Guide to LaTeX

A Beginner’s Guide to LaTeX #

LaTeX works like this: write text and commands → compile → get a PDF. It handles layout, section numbering, and mathematical notation for you.

Start by compiling the example below, then try the features you need. You do not have to memorise every command.

Get started · Text and paragraphs · Sections and figures · Maths · Page layout · Troubleshooting

1. Create Your First Document

  1. Open TeXPage, sign in, and create a blank project. No local installation is needed.
  2. Open the main file (usually main.tex) and replace its contents with the code below.
  3. Select pdfLaTeX as the compiler in the project settings, then click Compile to preview the PDF.
\documentclass[a4paper]{article} % A short document
\usepackage{amsmath}            % Mathematical notation

\title{My First Document}
\author{Jane Doe}
\date{\today}

\begin{document}
\maketitle

\section{Hello, LaTeX}
This is my first document. I can write ordinary text here.

A blank line starts a new paragraph. I can also make text \textbf{bold}.

\section{An Equation}
The Pythagorean theorem is $a^2 + b^2 = c^2$.

\end{document}

Change the title, author, and a sentence, then compile again to see what changes.

Here is what the code does:

  • \documentclass{article} selects a document type suitable for notes, articles, and short reports.
  • The preamble, before \begin{document}, loads packages (extra features) and sets details such as the title.
  • The body, between \begin{document} and \end{document}, contains your text, maths, and figures. \maketitle prints the title here.
  • Commands start with \. Braces {} hold content; square brackets [] hold optional settings, as in \textbf{bold} and \documentclass[a4paper]{article}.
  • % starts a comment: everything after it on that line is left out of the PDF.

Build on this document for the examples below. Put snippets in the body unless stated otherwise. Put \usepackage{...} in the preamble, and load each package only once.

2. Write Text and Paragraphs

Type ordinary text directly. Remember three rules:

  • A blank line starts a new paragraph. A single line break in the source acts like a space.
  • LaTeX wraps lines and handles indentation automatically. Do not use repeated spaces to align text or \\ to start paragraphs.
  • Commands and environment names are case-sensitive: \textbf works, but \Textbf does not.
This is the first paragraph. Here is some \textbf{bold text}.
This sentence is still in the same paragraph.

This is the second paragraph, with \emph{emphasised text}.
Here is a footnote.\footnote{This appears at the bottom of the page.}

Some characters have special meanings. To print them as ordinary text, use these forms:

To print Type To print Type
Percent % \% Underscore _ \_
Dollar $ \$ Ampersand & \&
Hash # \# Braces { } \{ and \}

For example: 80\% complete or The file is data\_2026.

For English double quotation marks, use two backticks to open and two apostrophes to close:

``This text is in quotation marks.''

3. Add Sections, Lists, and Figures

Sections and Contents #

Use commands to mark heading levels. LaTeX supplies the numbers automatically.

\section{Introduction}
Write your introduction here.

\subsection{Background}
Write the background here.

To add a table of contents, insert \tableofcontents after \maketitle in the body.

Lists #

\begin{itemize}
  \item First point
  \item Second point
\end{itemize}

Change both occurrences of itemize to enumerate for a numbered list. This kind of block is called an environment: every \begin{...} needs a matching \end{...} with the same name.

Images #

Add \usepackage{graphicx} to the preamble. Upload an image to the same folder as your main file, for example demo.png, then insert this in the body:

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.6\textwidth]{demo.png}
  \caption{An example image}
  \label{fig:demo}
\end{figure}

Figure~\ref{fig:demo} shows the result.

0.6\textwidth means 60% of the text width. Replace demo.png with your actual filename, matching its capitalisation and path.

\caption adds a caption and number. The \label after it gives the figure a unique name; \ref uses that name to look up its number. References update when you add or remove figures. The ~ keeps “Figure” and its number on the same line.

Figures may move to the top of a page or to another page. [htbp] allows placement here, at the top, at the bottom, or on a separate page; it does not fix the image in place.

Tables #

This simple table needs no extra package:

\begin{tabular}{lc}
  \hline
  Name & Score \\
  \hline
  Alice & 95 \\
  Bob & 88 \\
  \hline
\end{tabular}

{lc} sets two columns: left-aligned and centred. & separates cells, \\ ends a row, and \hline draws a horizontal line.

4. Write Mathematical Formulae

The starter document already loads amsmath, so you can try these examples directly.

Inline and Display Maths #

Use $...$ for maths within a sentence and \[...\] for a formula on its own line:

The area of a circle is $A = \pi r^2$.

The quadratic formula is:
\[
  x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]

These common commands belong inside a formula:

Purpose Code
Superscript and subscript x^2, a_n
Longer superscripts and subscripts x^{10}, a_{ij}
Fraction and square root \frac{a}{b}, \sqrt{x}
Greek letters \alpha, \beta, \pi
Sum \sum_{i=1}^{n} i

Wrap a superscript or subscript in {} when it contains more than one character, as in x^{10}.

Equation Numbers and References #

For an automatically numbered equation, use equation instead of \[...\]:

\begin{equation}
  E = mc^2
  \label{eq:energy}
\end{equation}

Equation~\eqref{eq:energy} relates mass and energy.

\eqref inserts the equation number in parentheses. Do not add $ or \[ inside the equation environment.

5. Adjust the Page Layout

The default layout is a good starting point. To change the margins, add this to the preamble:

\usepackage[margin=2.5cm]{geometry}

This sets all four margins to 2.5 cm. To start a new page at a specific point, put \newpage in the body.

For a thesis or journal submission, start with the institution’s or publisher’s template and follow its instructions for the compiler and document setup.

Troubleshooting

Compile after each small addition. If compilation fails, read the first error in the log and check that line and the few lines before it. Fix it, then compile again.

Symptom or error What to check
Undefined control sequence Check command spelling and capitalisation, and load any required package in the preamble.
Missing $ inserted Put mathematical notation inside a formula. For an underscore in ordinary text, use \_.
File ... not found Upload the image and check that its filename, capitalisation, and path match the code.
Missing } or an unfinished environment Check that braces are paired and every \begin{...} has a matching \end{...}.
References show ?? or the contents list is empty Complete a compilation without errors, then compile again. For references, also check that the names in \label and \ref match.

What Next? #

Write a page of your own notes: change the title, add two paragraphs, a list, and a formula. Once it compiles, you are ready to start writing with LaTeX.

Continue with the detailed LaTeX guide, or jump to figures, tables, and cross-references, mathematical formulae, bibliographies, or fonts and page layout.