LaTeX

Beginner

LaTeX is pronounced Lay-tech or Lah-tech and is spelled in this way (even suggested by my editor - vim).

Typesetters / compilers

latex
Creates DVI files which can later be converted to PDF files. Supports EPS image files, but not PDF, PNG or JPG (more on that later).
pdflatex
Creates PDF files. If your final product is PDF I recommend this one over latex since it gives better typography
(see for example http://texblog.net/latex-archive/layout/pdflatex-microtype/)
Supports PDF, PNG and JPG but not EPS.
texmaker
“Texmaker is a free, modern and cross-platform LaTeX editor for linux, macosx and windows systems that integrates many tools needed to develop documents with LaTeX, in just one application.”
http://www.xm1math.net/texmaker/


Command structure

\command{argument}          % comment
\anothercommand{argument1}{argument2}
\optcommand[optional1,optional2]{argument}

Start comments with % Extra spaces and newlines are typically ignored in the latex file.

Hint : To manually insert spaces use \, \; \quad \qquad (sorted by size) or \hspace{1cm} for horizontal space and \vspace{1em} for vertical spacing (1 em is the width of the M character in the current font)


Typical document

A LaTeX project is divided into (at least) two parts:

In the preamble you write general settings for the document like margins, font, paragraph spacing etc. It is also here you define your own LaTeX commands.

Hint : It is useful to keep the preamble in a separate file (see below)

\documentclass[12pt]{article}
\begin{document}

Hello World!

\end{document}

Document classes (examples):


Math

Inline math

We got that $a = 1$ for $b = 2$.

$$ \text{We got that } a = 1 \text{ for } b = 2.
$$

Math environments

\begin{equation}
    \label{eq:simple}
    a + b = c
\end{equation}

$$ \begin{equation} \label{eq:simple} a + b = c \end{equation} $$

\begin{align}
    a + b &= c \\
    d &< e + f
\end{align}

$$ \begin{align} a + b &= c \\ d &< e + f \end{align} $$

\begin{equation}
    \begin{split}
        a + b &= c \\
        d &= e + f \\
        1 &= e^{2 \pi i}     
    \end{split}
\end{equation}

\begin{equation} \begin{split} a + b &= c \\ d &= e + f \\ 1 &= e^{2 \pi i}
\end{split} \end{equation}

Refer to an equation using \eqref{eq:simple} $\eqref{eq:simple}$
For figures, tables and sections use \ref{fig:plot}.

Making long equations often requires big parentheses

\left( \frac{P}{Q} \right) % gives automatic resizing
\big( \Big( \bigg( \Bigg(  % user specified

$$ \left( \frac{P}{Q} \right) \\ % gives automatic resizing \big( \Big( \bigg( \Bigg( % user specified $$

Most mathematical functions are predefined in LaTeX. Don’t forget the \

log(\phi) + \log(\varphi)

$$ log(\phi) + \log(\varphi) $$

When you want subscripts in text use \text{}

S_{fluctuations} + S_\text{classical}

$$ S_{fluctuations} + S_\text{classical} $$


Quotation marks and special characters

LaTeX uses different symbols to start and end a quote. Do not use ".

He said that ``it was amazing!''
Let's go for lunch "if you know what I mean"

Since LaTeX uses some characters for its syntax you sometimes need to tell it that you mean. It you write We made a 25% profit you tell LaTeX to comment out everything after 25. Use backslash before the following character if you want to type them.

$ & _ { } % #

Hint : Two special cases are \\ and \~ which are actually commands themselves (newline and “put a twiddle on next character”). Here you can use \textbackslash and \textasciitilde or $\sim$.


Font size and formatting

There are basically two ways of changing formatting and size: usual commands and declarations. Declarations reach to the end of the surrounding environment.

This is an \emph{important} word

\texttt{ This emphasize \em reaches to the end. }

How about {\em this} word

Useful formatting commands are:

Different sizes (used as declarations) in rising order \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge


Figures and tables

Figures and tables are (usually) put into floating environment. This separates it from the text and you are able to use captions and labels. The floating environments are figure and table.

LaTeX places the floats where they “fit”. You can add an optional argument (which for environments actually comes after the environment-specifier.

\begin{figure}[htb]
    ...
\end{figure}

\begin{figure[!h]
    ...
\end{figure}

Images are imported by \includegraphics{filename}.

Hint : A useful optional argument is \includegraphics[width=1.0\textwidht]{file} or with another prefactor.

Creating “tabulars” (the content of a table-float) is a bit complicated. Useful resources are:

Hint : One usually creates new pages by \newpage but if you want to make sure that all floats (figures and tables) are printed before you start on something new you can use \clearpage. This creates a new page after all floats from the previous section have been placed.


Resources