% This line is a comment and will not be shown
%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREAMBLE
%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following command is necessary
\documentclass{article}
% This is a useful package. It provides the unnumbered section environment. You should always use it.
\usepackage{amsmath}
% This package provides fonts for natural numbers etc. Use with \mathbb
\usepackage{amsfonts}
% This package is used to import graphics.
\usepackage{graphicx}
% We can define our own commands. This one takes no arguments:
\newcommand{\ordo}{\mathcal{O}}
% This one takes an argument.
\newcommand{\mset}[1]{\lbrace #1 \rbrace}
% We need a title and author(s)
\title{A (Very) Short {\LaTeX} Example}
\author{Jari Stenman \and Jonathan Cederberg}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%
% The document begins here
\begin{document}
% This command creates the title
\maketitle
\section{Equations}
This is a mathematical equation:
\begin{equation*}
n^2 \log n \in \ordo(n^3)
\end{equation*}
In the source file, there is no blank lines between the text and the equation.
This is because {\LaTeX} sees a blank line as the end of the paragraph.
This is the start of new paragraph, and this is a more complicated mathematical equation:
\begin{equation*}
1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \dots
= \sum_{k=0}^\infty \frac{1}{2^k}
= \lim_{n \to \infty} \sum_{k=0}^n \frac{1}{2^k}
= 2
\end{equation*}
Here, we have a blank line after the equation and therefore a new paragraph. If you want to avoid this while still making the source
readable, you can put comment characters inbetween, like this:
%
%
\begin{equation} \label{eq:example}
| \mset{1,2,3,4} | = 4
\end{equation}
%
%
Wow, that worked great! We also used {\tt equation} instead of {\tt equation*}, so the equation is numbered.
The equation is also labelled in the source code, so we can refer to it as Equation \ref{eq:example} by using the {\tt ref} command.
We can also use \emph{inline} formatting by surrounding a block of text with {\tt \$}. For example, $\pi = 3.141592\dots$
and $\mathbb{N} = \mset{1,2,3, \dots}$.
\section{Other Stuff}
\subsection{Tables}
Table \ref{tbl:example} shows an example of a table.
\begin{table}
\centering
\begin{tabular}{l | c || c } % Three columns: left-aligned, centered and centered, with single and double lines inbetween.
% Here, & is a separator between columns, and \\ is a separator between rows
Row 1 & 1 & 2 \\
Row 2 & 3 & 4 \\
% Here, we add a horizontal line:
\hline
% We can also include inline math:
Row 3 & $\mathbb{R}$ & $f(n) = \Theta(g(n)) \implies f(n) = \Omega(g(n)) \text{ and } f(n) = \ordo(g(n))$ \\
\end{tabular}
\caption{Example of a Table}
\label{tbl:example}
\end{table}
\subsection{Including Images}
We can include images by using the {\tt graphicx} package. The preamble of this document includes it.
We can now include images by using the {\tt includegraphics} command. We can use the {\tt scale} option to control the size.
Often, we want to place the image in a {\tt figure} environment. For an example, see Figure \ref{fig:aww}.
\begin{figure}
\centering % Center the cat!
\includegraphics[scale=0.5]{cat.png}
\caption{Aww}
\label{fig:aww}
\end{figure}
\section{Compiling}
To compile this document on the Unix system, do the following:
\begin{itemize}
\item Download the source file and the image {\tt cat.png}, and put them in the same folder.
\item Using the terminal, navigate into that folder.
\item Run {\tt pdflatex example.tex} and wait. When the command completes, run {\tt pdflatex example.tex} again to get the references right.
\item You now have {\tt example.pdf} in that folder.
\end{itemize}
\end{document}