\chapter{Introduction to \LaTeX}
\label{cha:latex}

Even if you know the basics of \LaTeX\ I suggest you read this chapter. It may save you nerves and many hours of wasted time.

%-------------------------------------------------------------

\section{Basic rules}
\label{sec:basic:rules}

\begin{itemize}
\item Whitespace characters, such as blank or tab, are treated uniformly as space by \LaTeX. Several consecutive whitespace characters are treated as one space. Whitespace at the start of a line is generally ignored, and a single line break is treated as whitespace.

\item To obtain a \textit{non-breaking space}, use the tilde character instead of the space character.

\item An empty line between two lines of text defines the \textit{end of a paragraph}. Several empty lines are treated the same as one empty line. 

\item The characters \texttt{\$ \& \% \# \_ \{ \} \~}~ $\tt ^{\hat{~~}}\,$ $\tt \backslash$ have a special meaning under \LaTeX\ and cannot be entered directly in a text. 
These characters (except backslash) can be used in a document by using a prefix backslash, e.g. \verb!\\$!.

\item \LaTeX~is a high-quality typesetting system.t. Let us not try to improve it unless we really know what we are doing.

\item \LaTeX\ commands are case sensitive. Command names are terminated by a space, a number, or any other non-letter. \LaTeX\ ignores whitespace after commands.

\item Some commands require a parameter, which has to be given between curly brackets \verb!{ }! after the command name. Some commands take optional parameters, which are inserted after the command name in square brackets \verb![ ]!.

\item A \LaTeX\ \textit{environment} is a structure composed of two complementary commands \verb!\begin{name}! and \verb!\end{name}!. It is possible to use a command inside an environment, or to nest two or more environments. Arguments for an environment are placed after \verb!\begin{name}!.

\item \verb!``English''! (``English'') quotation marks are produced by: 2 x \textit{grave accent}, 2 x \textit{vertical quote}.

\item \verb!,,Polish''! (,,Polish'') quotation marks are produced by: 2 x \textit{comma}, 2 x \textit{vertical quote}.

\item \verb!-! (minus character) ~~ \textit{hyphen} is used between inter-related words, e.g. inter-related.

\item \verb!--! (2 x minus character) ~~ \textit{en-dash} is used to indicate a ranges, e.g. 11--13.

\item \verb!---! (3 x minus character) ~~ \textit{em-dash} is used to show the extension of an expression, e.g.\\ \textit{Weather condition --- like clear sky}\dots

\item \LaTeX~ assigns serial numbers to many environments or elements of an environment (e.g., table, figure, equation). This default numbering system eliminates the possibility of committing any mistake as may happen in manual numbering.
A unique reference key is defined using the \verb!\label{}! command. We can refer to the label using the \verb!\ref{}! and \verb!\pageref{}! commands.
When defining labels, it is a good idea to give them prefixes specifying the type of referenced item, e.g. \textit{eq}, \textit{cha}, \textit{sec}, \textit{fig}, \textit{def} etc. Spaces and diacritical marks may not be used in the labels!

\end{itemize}


%-------------------------------------------------------------

\section{Including graphics}
\label{sec:graphics}

\begin{figure}[!ht]
\centerline{\includegraphics[scale=1]{latex-project-logo}}
\caption{\LaTeX\ project logo.}
\label{fig:latex:logo}
\end{figure}

Elements such as tables and figures are placed as so-called \textit{floats}. Floats are created using the \textit{figure} and \textit{table} environments. Floats cannot be broken across pages. Any figure or table that does not fit on the current page is moved to a later page, while filling the current page with body text.

If a float cannot be placed on the current page, it is deferred either to the figures queue or the tables queue. When a new page is started, \LaTeX\ first checks if it is possible to fill a special \textit{float page} with floats from the queues. If this is not possible, the first float on each queue is treated as if it had just occurred in the text. If a figure cannot be placed it pushes all further figures to the end of the document.

\medskip

\textit{Placement specifier} (where the float is allowed to be moved): \verb!\begin{table}[...]!
\begin{description}
\item[h] -- here at the very place in the text where it occurred,
\item[t] -- at the top of a page,
\item[b] -- at the bottom of a page,
\item[p] -- on a special page containing only floats,
\item[!] -- without considering most of the internal parameters, which could otherwise stop this float from being placed.
\end{description}

\begin{figure}[!ht]
\centerline{\includegraphics[scale=1]{latex-project-logo-black}
\includegraphics[scale=0.8]{overleaf-logo}}
\caption{\LaTeX\ project logo (black version) and Overleaf logo.}
\label{fig:latex:logos}
\end{figure}

The label must be defined immediately after the \textit{caption} command.


%-------------------------------------------------------------

\section{Tables}
\label{sec:tables}


\begin{table}[htb]
\caption{Examples of Middle-earth peoples}
\label{tab:peoples}
\centering
\begin{tabular}{|l|l|l|l|l|}
\hline Wizards & Elves & Dwarves & Men & Hobbits \\ \hline \hline
Saruman & Legolas & Gimli & Aragorn & Bilbo Baggins \\
Gandalf & Elrond & Thorin Oakenshield & Boromir & Frodo Baggins \\
Radagast & Arwen & Gl\'oin & Faramir & Sam Gamgee \\ \hline
\end{tabular}
\end{table}

\begin{table}[htb]
\caption{Examples of Middle-earth peoples}
\label{tab:peoples:multicolumn}
\centering
\begin{tabular}{|l|l|l|l|l|} \hline
\multicolumn{2}{|c|}{Immortal} & \multicolumn{3}{c|}{Mortal} \\ \hline
Wizards & Elves & Dwarves & Men & Hobbits \\ \hline \hline
Saruman & Legolas & Gimli & Aragorn & Bilbo Baggins \\
Gandalf & Elrond & Thorin Oakenshield & Boromir & Frodo Baggins \\
Radagast & Arwen & Gl\'oin & Faramir & Sam Gamgee \\ \hline
\end{tabular}
\end{table}

\begin{table}[htb]
\caption{Examples of Middle-earth peoples}
\label{tab:peoples:multirow}
\centering
\begin{tabular}{|r|l|l|} \hline
\multirow{2}{*}{Immortal} & Wizards & Gandalf \\\cline{2-3}
 & Elves & Elrond \\\hline
\multirow{3}{*}{Mortal} & Dwarves & Gimli \\\cline{2-3}
 & Men & Aragorn \\\cline{2-3}
 & Hobbits & Frodo Baggins \\\hline
\end{tabular}
\end{table}



%-------------------------------------------------------------

\section{Mathematical expressions}
\label{sec:math}

A quadratic function $f$ is a function of the form 
\begin{equation}
\label{eq:quadratic:function}
f(x) = ax^2 + bx + c,
\end{equation} 
where $a \ne 0$.

\LaTeX~automatically selects the font size and spacing for each part of an equation:
\begin{equation*}   % number omitted
\lim_{n \to \infty} \sum_{k = 1}^n \frac{1}{k^2} = \frac{\pi^2}{6}
\end{equation*}

In in-line equations, some expressions are shrunk to fit the line 
 $\lim_{n \to \infty} \sum_{k = 1}^n \frac{1}{k^2} = \frac{\pi^2}{6}$.

If you need to place two or more equations one after the other, then use the \textit{align} environment (see in the source file where the labels are defined):

\begin{align}
& \left|z\right| = 0 \iff z = 0,\label{eq:comp1}\\
& \left|z\right| \geq 0,\label{eq:comp2}\\
& \left|\frac{z_1}{z_2}\right| = \frac{\left|z_1\right|}{\left|z_2\right|},\label{eq:comp3}
\end{align}

The \textit{split} environment allows us to break long mathematical formulas into multiple lines. The \& symbol indicates the left alignment of the expressions following it.

\begin{equation}
\label{eq:int1}
\begin{split}
\int x^2 e^x dx & = x^2 e^x - 2 \int x e^x dx = \\
& = x^2 e^x - 2 \left( x e^x - \int e^x dx \right ) = \\
& = x^2 e^x -2x e^x + 2 e^x + C
\end{split}
\end{equation}

Inside math mode any multi-letter name should be placed inside \textit{mathit} command. For example, \verb!$\mathit{off} + \mathit{on}$! produces this $\mathit{off} + \mathit{on}$, while \verb!$off + on$! produces this $off + on$ (look at those unnecessary ugly spaces around the letters \textit{f}). 


%-------------------------------------------------------------

\section{Definitions and theorems}
\label{sec:definitions:theorems}

All these examples are from my paper~\cite{Szp:RTCPnets:FI:06}. Examine the source file to see how label references are used.

\begin{definition}
\label{def:accessibility:age}
Let $p\in P$ be a place of an RTCP-net $\mathcal{N}$ and let $Out_{A}(p)$ denote the set of output arcs of the place $p$.

{\em The minimal accessibility age} of the place $p$ is the number:
\begin{equation}
\label{eq:min:accessibility:age}
\delta_{min}(p) = \min_{a \in Out_{A}(p)} \left\lbrace 
\min_{b \in \mathcal{B}(T(a))} E_S(a)_b \right\rbrace.
\end{equation} 

{\em The maximal accessibility age} of the place $p$ is the number:
\begin{equation}
\label{eq:max:accessibility:age}
\delta_{max}(p) = \max_{a \in Out_{A}(p)} \left\lbrace 
\max_{b \in \mathcal{B}(T(a))} E_S(a)_b \right\rbrace.
\end{equation}
\end{definition} 

\begin{definition}
\label{def:cover:states}
Let $\mathcal{N}$ be an RTCP-net and let $(M_1,S_1)$ and $(M_2,S_2)$ be states of the net. The state $(M_1,S_1)$ is said to {\em cover} the state $(M_2,S_2)$ ($(M_1,S_1) \simeq (M_2,S_2)$) iff $M_1 = M_2$ and the following condition holds:
\begin{equation}
\label{eq:coverability}
\forall p\in P\colon (S_1(p) = S_2(p)) \vee (S_1(p) \leq -\delta_{max}(p) \wedge S_2(p) \leq -\delta_{max}(p)).
\end{equation}  
\end{definition}

\begin{proposition}
\label{prop:coverability:relation}
The {\em coverability relation} $\simeq$ is an equivalence relation on $\mathcal{R}(M_0,S_0)$.
\end{proposition}

\begin{lemma}
\label{lem:coverability:relation:firing}
Let $(M_1,S_1)$ and $(M_2,S_2)$ be the states of an RTCP-net $\mathcal{N}$ such that $(M_1,S_1) \simeq (M_2,S_2)$. If $(M_1,S_1) \stackrel{(t,b)}{\longrightarrow} (M_1',S_1')$ and $(M_2,S_2) \stackrel{(t,b)}{\longrightarrow} (M_2',S_2')$, then $(M_1',S_1') \simeq (M_2',S_2')$.
\end{lemma}

\begin{proof}
$(M_1,S_1)\simeq (M_2,S_2)$, hence, by definition~\ref{def:cover:states}, $M_1 = M_2$ and the formula~(\ref{eq:coverability}) holds for functions $S_1$ and $S_2$. In both cases, the same transition $t$ in the same binding $b$ is fired, so it is evident that $M_1' = M_2'$.

If $p \in In(t) \cup Out(t)$, then $S_1'(p) = S_2'(p)$. If $p \notin In(t) \cup Out(t)$, then $S_1'(p) = S_1(p)$ and $S_2'(p) = S_2(p)$. Therefore, the states $(M_1',S_1')$ and $(M_2',S_2')$ cover each other.
\end{proof}

\begin{proposition}
\label{prop:cover:relation:L}
Let $(M_1,S_1)$ and $(M_2,S_2)$ be the states of an RTCP-net $\mathcal{N}$ such that $(M_1,S_1) \simeq (M_2,S_2)$. The following equality holds:
\begin{equation}
\label{eq:cover:relation:L}
\mathcal{L}(M_1,S_1) = \mathcal{L}(M_2,S_2).
\end{equation}
\end{proposition}

\begin{proof}
Suppose, a transition $t$ is enabled in the state $(M_1,S_1)$ in a binding $b$ and 
$(M_1,S_1) \stackrel{(t,b)}{\longrightarrow} (M_1',S_1')$.

$(M_1,S_1)\simeq (M_2,S_2)$ hence, by definition~\ref{def:cover:states}, $M_1 = M_2$ and the formula~(\ref{eq:coverability}) holds for functions $S_1$ and $S_2$. 
Thus, the transition $t$ is also enabled in the state $(M_2,S_2)$ in the same binding $b$.
Therefore, there exists a state $(M_2',S_2')$ such that $(M_2,S_2) \stackrel{(t,b)}{\longrightarrow} (M_2',S_2)'$.
Moreover, by lemma~\ref{lem:coverability:relation:firing}, $(M_1',S_1') \simeq (M_2',S_2')$.
From the above considerations, by induction, we may now conclude that the statement~(\ref{eq:cover:relation:L}) is satisfied.
\end{proof}




