LaTeX basics

This is a collection of how to format simple things in LaTeX, mostly stuff that a novice may miss. It's to be used mostly as a simple guide or reference, especially when getting started.


Basic formatting




Note that emphasized and italic are often the same, but there can be differences.


Use the following snippet to insert images

  \caption{Description of the image}

Captions, labels, and references

Note the use of \caption and \label in the previous snippet. Remember this:

Labels can also be given to code listings, sections, subsections, tables, and so on.


\section{Lorem ipsum}\label{sec:lorem-ipsum}

As seen in Figure~\ref{fig:figure-x} and as described
in Section~\ref{sec:lorem-ipsum}.

Some rules on how to reference things

Citing sources

The rules are similar to the previous section:

If you have a bib file like this

  title = {Article title},
  author = {John Smith},
  year = {2013},

Then you can cite it like



LaTeX uses ` for opening quotes and ' for closing quotes. For example:

% For single quotes
`text here'

% For double quotes
``text here''

% Do NOT do
'wrong single quotes'
"wrong double quotes"

The result is:

Note: you can use 'text' and "text" inside listings, but remember to set upquotes. See later section.


Choose between numbered and non-numbered lists.

% Non-numbered lists
  \item Item 1
  \item Item 2
  \item Item 3

% Numbered lists
  \item Item 1
  \item Item 2
  \item Item 3

Do not use - or * to mark lists.


If the document is in UTF-8, use directly the normal accents, e.g., È, é and so on.

Otherwise use \ followed by the mark and the letter. Examples:

\`e \.e \~e
\'e \"e \=e


Paragraphs and newlines

Use a double newline to introduce a new paragraph. The new paragraph is often indented. Use \\ to force a newline inside a paragraph.

Note that a single newline behaves the same as a space.

This is the first paragraph.

This is the second paragraph, which also
has \\ a forced newline.

Unbreakable space

The character ~ is an unbreakable space. This means that a~b appears the same as a b, but the two won't break over different lines.

You have to use ~ in some cases to prevent ugly results, such as


Listings are used to show code. You have to use the listings package and the lstlisting environment.

A simple example, which also enables the correct quotes to use


  upquote=true, % fix quotes
  showstringspaces=false, % show ' ' for spaces in strings

print('Hello World')


You can use caption and label as parameters in the square brackets.


To insert math you have to go into math mode. This can be done in various ways:

The environments are numbered, and their variants with * are not (equation*, align*).

Once in math mode, you can do a lot of things. Check here for a complete list of symbols available.

Special characters

Here how to insert some tricky characters.

~ (low)$\sim$ or \texttildelow
~ (high)\~{}$ or \textasciitilde
_\_ or \textunderscore