% Text that starts with a percent sign is ignored by LaTeX.  This is useful to write comments in the source file that won't show up in the pdf.


%%%%%%%%%%%%%%%%%%%%%%%%%%  Input Preamble files  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Files are located in the "LaTeX" folder along side the .tex files:
\newcommand{\LaTeXPath}{LaTeX/} 

% These files contain information about formating and command to load different packages:
\input{\LaTeXPath article}  %  article   book
\input{\LaTeXPath packages}
\input{\LaTeXPath portrait} %  portrait  landscape
%\usepackage[french]{babel} %  Use this package to write in French.

\renewcommand{\baselinestretch}{1}  % 2 = double space etc.

\begin{document}

% The title page is kept on a different file for convinience.
\input{IntroToLaTeX_title}


%%%%%%%%%%%%%%%%%%%%%%%%%%   Begin Document  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A new section.  The "*" after "\section" suppresses the numbering and prevents it from being added to the table of contents, which is standard for the introduction.
\section*{Introduction}


\LaTeX{} (pronounced lay-tek or lah-tek, but never lay-teks) is the standard method for laying out scientific and mathematical manuscripts.  According to Wikipedia:
\begin{quote}
``\LaTeX{} is widely used in academia for the communication and publication of scientific documents in many fields [...]

It also has a prominent role in the preparation and publication of books and articles that contain complex multilingual materials, such as Arabic and Greek [...]

The typesetting system offers programmable desktop publishing features and extensive facilities for automating most aspects of typesetting and desktop publishing, including numbering and cross-referencing of tables and figures, chapter and section headings, graphics, page layout, indexing and bibliographies [...]

\LaTeX{} was originally written in the early 1980s by Leslie Lamport at SRI International.''~\cite{WikipediaLaTeX}
\end{quote}

The idea is similar to how wikis are written: the writer worries about the content and the logic of the document, and the computer takes care the formatting.  There are many reasons for using \LaTeX{} instead of a word processor, but sometimes a word processor is preferable:

% Here's a bullet point list.
% Notice how the fourth item contains a citation and the sixed item contains a \footnote{} that will automatically be placed at the end of the page.  The extra indentation of the footnote doesn't change the text in the pdf, but makes the source text clearer to read.
Using \LaTeX{} instead of a word processor:
\begin{itemize}
\item It keeps the job of ``writing'' separate from the job of ``typesetting''. Thus, the writer only has to worry about the logical structure of the paper, not how it will look.~\cite{Cottrell}
\item It's very useful for any kind of document with a complex structure that might require a table of content, a reference page, heavy cross-referencing, or complicated mathematical expressions.
\item It's completely free software and OS agnostic.\footnote{
	The \LaTeX{} engine can run under Microsoft Windows, OS X, or GNU/Linux, and the PDF files it produces look the same on any system.}
\item It's much more ``future-proof'' than proprietary word-processors since the ``source text'' is saved in plain ascii text.~\cite{Smith}
\item It is widely used in the scientific community.
\item It creates beautiful documents that can easily be reformatted without changing the actual text.
\end{itemize}

Using a word processor instead of \LaTeX{}:
\begin{itemize}
\item To create a document rich in formatting like a flier or a presentation.
\item You simply want to write a short letter that needs no table of content or referencing.
\end{itemize}

For more details on how to install \LaTeX, see my online guide.~\cite{Truchon}

\newpage

% The next sections don't have a star so they will be numbered and included in the table of contents.  I personally like to put a few spaces at the beginning of a new section so that they are easier to spot in the tex file.  It doesn't change anything to the pdf however.

\section{Structure of a \TeX{} file}
A \verb+.tex+ file needs two main parts: the \emph{preamble} and the \emph{document}.




\subsection{Preamble}
The preamble contains instructions on how to format the text overall.  It usually starts with a \verb+\documentclass + line and ends just before the \verb+ \begin{document} + line.  You shouldn't edit anything there unless you want to tweak the overall formatting of your document.  Typically, you will be provided with a template that contains all of this stuff so you don't have to worry about it.

The preamble can be included at the beginning of the main document, or put into separate files that are then loaded one after the other.  In this documents the following lines at the beginning of the documents load the three files that contain the preamble information.
\begin{verbatim}
  \input{\LaTeXPath article} 
  \input{\LaTeXPath packages}
  \input{\LaTeXPath portrait}
\end{verbatim}

I've separated these into three files so that if I want to have chapters, I can use \verb+book+ instead of \verb+article+, and if I want landscape, I can write \verb+landscape+ instead of \verb+portrait+.

Every time you start a new \LaTeX{} document, you should create a new folder and place the following items in it:

\begin{itemize}
  \item A \verb+figures+ folder where you'll put your multimedia files.
  \item A copy of the \verb+LaTeX+ folder which contains the preamble and creative commons files.
  \item A copy of \verb+template.tex+  and \verb+template_title+ which you can then rename and use to start your documents.
\end{itemize}


\subsection{Document}
The body of the text is contained between the lines \verb+ \begin{document} +  and \verb+ \end{document} +.  This is where you will be writing your documents.  Usually you will be writing:

\begin{itemize}
\item A \textbf{Title Page}, which I like to have on a separate file.  It would contain:
	\begin{itemize}
	\item Your name, and date, and the line \verb+\maketitle +
	\item An \textbf{Abstract}, which is a super condensed description of what your paper is about.
	\item A \textbf{Table of Content}, which is automatically generated using the line \verb+ \tableofcontents +
	\item A \textbf{Creative Commons Notice}, which you can optionally add at the end of your title page to allow others to share your work while respecting your authorship.
	\end{itemize}
\item The \textbf{Document Body}, which is where you start your paper.  Usually the introduction section is not numbered and doesn't appear in the table of contents, but the other sections are.
\item A \textbf{Reference} section which is listed after the line: \\
	\verb+ \begin{thebibliography}{99}\label{biblio}+
\end{itemize}



\newpage
\section{Typing math}

In math papers, math expressions can either be typed \emph{inline} or \emph{displayed} on their own lines.


\subsection{Inline}
Inline math expressions can be inserted right in the text like this: $r = \sqrt{x^2 + y^2}$ by adding \verb@$ $@ around the expression.  Use this even when you're simply typing a variable.  For example, you should type:
\begin{itemize}
\item $x$ not x              (\verb+$x$ not x+)
\item $a = 1$ not a = 1      (\verb+$a = 1$+ not a = 1)
\item $f(x)$ not f(x)        (\verb+$f(x)$+ not f(x))
\end{itemize}




\subsection{Displayed}
Use  \verb@\[  \]@ to format bigger or more important equations that should appear centred on their own lines like this one:
%
\[
f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}
\]
%
\begin{quote}
\begin{verbatim}
\[
f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}
\]
\end{verbatim}
\end{quote}

Notice how that same equation is scaled down when written inline: $f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}$

\begin{quote}
\begin{verbatim}
$f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}$
\end{verbatim}
\end{quote}

It's still possible to force an inline equation to be formatted at regular scale: $\displaystyle f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}$ by adding \verb+\displaystyle+ in the \verb+$ $+.



\subsection{Numbered}\label{sec:Numbered}
In math papers, we often have to refer to previously written equations.  To do this, we number and label equations like so:
%
\begin{equation}\label{eq:DefDeriv}
f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}
\end{equation}
%
\begin{quote}
\begin{verbatim}
\begin{equation}\label{eq:DefDeriv}
f'(x) = \lim_{\Delta x \rightarrow 0} \frac{f(x + \Delta x) - f(x) }{\Delta x}
\end{equation}
\end{verbatim}
\end{quote}

Notice that \verb@ \label{eq:DefDeriv} @ allows you to refer to the equation by name instead of by number in your source code.  This is useful because when you edit your paper and move things around, all the numbering adjusts automatically.  So to refer to equation~(\ref{eq:DefDeriv}), we type  ``\verb@equation~(\ref{eq:DefDeriv})@'' instead of ``\verb@equation (1)@''.
Note that in \LaTeX{} the \verb+ ~ +  character creates a space that will glue the two characters together even when they are at the very end of a line.  

\verb@\label{SomeText} @  and \verb@ \ref{SomeText} @ can be used to label sections, equations, figures, tables, etc.    For example, this is section~\ref{sec:Numbered}.  Take a look at the source code to see how this works.



\subsection{Multi-step equation}
If you want to show multiple algebraic steps like this:
%
\begin{align*}
y &= 2(a + b)(c + d) \\
  &= 2(ac + ad + bc + bd)  \\
  &= 2ac + 2ad + 2bc + 2bd  \\
\end{align*}

It would be tempting to try something like:
%
\begin{quote}
\begin{verbatim}
\[   y = 2(a + b)(c + d)       \]
\[     = 2(ac + ad + bc + bd)  \]
\[     = 2ac + 2ad + 2bc + 2bd \]
\end{verbatim}
\end{quote}
But each line will be centred, instead of aligned at the equal signs:
\[   y = 2(a + b)(c + d)       \]
\[     = 2(ac + ad + bc + bd)  \]
\[     = 2ac + 2ad + 2bc + 2bd \]

The trick is to use the \verb+align*+ environment.\footnote{
   The use of the \texttt{eqnarray} environment is discouraged by some because of its inconsistent spacing.\cite{AMS}
} In this environment, we use \verb+&+ to align the \verb+=+ signs.  We can use a second \verb+&+ to separate different equations with more space, and a third to separate the equal signs of the second equations, etc.  Finally, \verb+\\+ is used to represent a row break.  The very last equation should not have a row break. Here are a few examples and their output:

No column break aligns the last character:
\begin{quote}
\begin{verbatim}
\begin{align*}
y = 2(a + b)(c + d) \\
  = 2(ac + ad + bc + bd)  \\
  = 2ac + 2ad + 2bc + 2bd  \\
\end{align*}\end{verbatim}
\end{quote}
%
\begin{align*}
y = 2(a + b)(c + d) \\
  = 2(ac + ad + bc + bd)  \\
  = 2ac + 2ad + 2bc + 2bd  \\
\end{align*}


\newpage
One column break at the start mis-aligns the equal signs:
\begin{quote}
\begin{verbatim}
\begin{align*}
&y = 2(a + b)(c + d) \\
&  = 2(ac + ad + bc + bd)  \\
&  = 2ac + 2ad + 2bc + 2bd  \\
\end{align*}\end{verbatim}
\end{quote}
%
\begin{align*}
&y = 2(a + b)(c + d) \\
&  = 2(ac + ad + bc + bd)  \\
&  = 2ac + 2ad + 2bc + 2bd  \\
\end{align*}
%
One column break before the \verb+=+ sign is perfect:
\begin{quote}
\begin{verbatim}
\begin{align*}
y &= 2(a + b)(c + d) \\
  &= 2(ac + ad + bc + bd)  \\
  &= 2ac + 2ad + 2bc + 2bd  \\
\end{align*}\end{verbatim}
\end{quote}
%
\begin{align*}
y &= 2(a + b)(c + d) \\
  &= 2(ac + ad + bc + bd)  \\
  &= 2ac + 2ad + 2bc + 2bd  \\
\end{align*}

Play with the location of the column breaks to see what happens.  Here is a more fancy example.  Have a look at the \verb+.tex+ file to see how it was made.
%
\begin{align}
a_{11} & =b_{11}    &    a_{12} & =b_{12}         &   & \text{this one has a number} \\
a_{21} & =b_{21}    &    a_{22} & =b_{22}+c_{22}  &   & \text{this one doesn't}  \nonumber \\
a_{33} & =b_{33}    &    a_{13} & =b_{13}         &   & \text{this one has one} 
\end{align}
\newpage

\section{Some Math Symbols}

Wikibooks~\cite{WikibooksLaTeX} and the \textit{Short Math Guide for \LaTeX{}}~\cite{AMS} have a lot of good and concise information on how to type symbols in \LaTeX{}.  Here are a few examples:

\begin{table}[h]
\begin{center}
\begin{tabular}{ll}
$\displaystyle x_{0}^{n}$					&   \verb@x_{0}^{n}@ \vspace{0.2cm}\\
$\displaystyle \sqrt{x}$					&   \verb@\sqrt{x}@ \vspace{0.2cm}\\
$\displaystyle \sqrt[3]{x}$					&   \verb@\sqrt[3]{x}@ \vspace{0.2cm}\\
$\displaystyle \frac{d}{dx}$					&   \verb@\frac{d}{dx}@ \vspace{0.2cm} \\
$\displaystyle \sum_{i=1}^{n}$				&  \verb@\sum_{i=1}^{n}@\vspace{0.2cm} \\
$\displaystyle \lim_{\Delta x \rightarrow 0}$    	& \verb@\lim_{\Delta x \rightarrow 0}@\vspace{0.2cm} \\
$\displaystyle \int_{a}^{b} f(x) dx$			&  \verb@\int_{a}^{b} f(x) dx@ \vspace{0.2cm}\\
$\displaystyle \equiv$					& \verb@\equiv@\vspace{0.2cm} \\
$\displaystyle \Leftrightarrow$				&  \verb+\Leftrightarrow+\vspace{0.2cm} \\
$\displaystyle \Rightarrow$				&   \verb+\Rightarrow+\vspace{0.2cm} \\
$\displaystyle \Leftarrow$					&   \verb+\Leftarrow+\vspace{0.2cm} \\
$\displaystyle \cdots$ 					&   \verb+\cdots+ \vspace{0.2cm}\\
$\displaystyle \ddots$					&  \verb+\ddots+ \vspace{0.2cm}\\
$\displaystyle \vdots$					&   \verb+\vdots+ \\
\end{tabular}
\end{center}
\end{table}%


The program EqualX \footnote{
   EqualX can be downloaded here: \url{http://equalx.sourceforge.net/index.html}
} for GNU/Linux and Windows are also very good sources of \LaTeX{} code.

\section{Misc}

To write quotation marks, like these `` '', you need to type  \verb@`` ''@, not \verb@" "@.  
\begin{itemize}
\item The \verb@`@ key is below of the \verb@esc@ key.
\item The \verb@'@ key is left of the \verb@return@ key.
\end{itemize}



\newpage
\section{Graphics}

Inserting diagrams is relatively easy in \LaTeX{}.
Here are a few general guidelines to make your graphs as clear as possible:
% Here's a numbered list.  Very similar to bullet points:
\begin{enumerate}
\item Scale of your graph so that it uses the entire width of the page while using as little of the height as possible (while still being clear).  Usually, this means that you should position your graphs and stretch your axes so that it fits in a rectangle that's about twice as wide as it is high.  Notice how, on all the following graphs, the $x$ and $y$ axes are scaled differently.
\item Make sure that the font size of the text embedded in your graphs is the same as the text in your main document.
\item Write a descriptive caption.
\end{enumerate}

\begin{figure}[h] 
  \centering
  \includegraphics[width=0.95\columnwidth]{figures/graphs.png}
  % here the width is 0.95 times the column width.  It could also be "width=7in" or "width=15cm"
     \caption{Hyperbolic trig functions are the odd and even components of the exponential function.  That is: $\cosh(x) + \sinh(x) = e^x$ where $\cosh(x)$ is even and $\sinh(x)$ is odd.}
    \label{fg:myfig} 
\end{figure}



\newpage
\section{Displayed text}

\subsection{Lists}

There are three standard list environments in \LaTeX. \\
Bullets use the \texttt{itemize} environment:
\begin{itemize}
	\item first item
	\item second item
	\item third item
\end{itemize}

Numbers use the \texttt{enumerate} environment:
\begin{enumerate}
	\item first item
	\begin{enumerate}
	    \item The list environments can be nested
	    \item second nested item
	\end{enumerate}
	\item second item
	\item third item
\end{enumerate}

The ``numbers'' of \verb+enumerate+ can also be customized:
\begin{enumerate}[i)]
    \item The list environments can be nested
    \item second nested item
\end{enumerate}
or
\begin{enumerate}[I]
    \item The list environments can be nested
    \item second nested item
\end{enumerate}
or
\begin{enumerate}[a.]
    \item The list environments can be nested
    \item second nested item
\end{enumerate}
or
\begin{enumerate}[(1)]
    \item The list environments can be nested
    \item second nested item
\end{enumerate}


The \texttt{description} environment puts its argument in bold face.
This is good for listing definitions:
\begin{description}
	\item[Columbia] A university in New York, or a recently disintegrated space shuttle
	\item[Colombia] A country in South America
\end{description}




\newpage
\subsection{Tables}
Here is an example of the standard table format.

\begin{table}[h]
  \begin{center}
    \caption{Table caption\label{tb:mytable}}
    \begin{tabular}{ rcc } % r=right, c=center, l=left (the letter ell, not the vertical line)
                   % one letter should be input for each column
                   % { r|c|c } puts vertical lines between columns (not the letter ell)
        \hline \hline
        $N_{\text{pix}}$  & $\sigma_{S}^{2}$  & $F^{-1/2}$ \\ \hline
        48         & 0.898             & 3.8$\times 10^{-2}$ \\
        192        & 1.49              & 7.8$\times 10^{-3}$ \\
        768        & 2.18              & 2.3$\times 10^{-3}$ \\
        3072       & 3.01              & 7.4$\times 10^{-4}$ \\
        12288      & 4.10              & 2.4$\times 10^{-4}$ \\
        49152      & 5.79              & 8.6$\times 10^{-5}$ \\
        \hline \hline
    \end{tabular}
    \end{center}
\end{table}

Tables and figures such as table~\ref{tb:mytable} can be referenced just like equations.
It is a standard convention to label equation, table, and figure keys as \texttt{eq:equationkey},
\texttt{tb:tablekey}, and \texttt{fg:figurekey}.

Here are two other simple examples:

\begin{tabularx}{\textwidth}{ |l| X| X| }
\hline
$x$    & a & b\\
\hline
$A(x)$ & a & b\\
\hline
\end{tabularx}
\vspace{1cm}

\begin{center}
\begin{tabular}{|l | *{2}{r}|}
\hline
$x$    & a & b\\
\hline
$A(x)$ & a & b\\
\hline
\end{tabular}
\end{center}


\section{Other Uses}
Typing math in this way might seem obscure at first, but once you get used to it, it's really quite convenient.  Here are other places where the \LaTeX{} math syntax can be used:
\begin{itemize}
\item Google Docs (See: \url{https://autolatex.com/})
\item LibreOffice (See: \url{https://extensions.libreoffice.org/en/extensions/show/librelatex})
\item Wordpress (See: \url{https://en.support.wordpress.com/latex})
\item Wikipedia (See: \url{https://en.wikipedia.org/wiki/Math_markup})
\item Dokuwiki (See: \url{https://www.dokuwiki.org/plugin:mathjax})
\end{itemize}


\section{Citing References}

Listing references is particularly easy in \LaTeX.  All the references
of the paper are listed in the \verb+thebibliography + section.  All
citations are then made by referencing the
``key,''  % notice how to use quotation marks.  You must use two single ` and '.
or argument of the \verb+ \bibitem + command.

To add a citation in the text, simply add \verb+ ~\cite{NotSoShort} + after the word.

\section{Cleaning Up}

To create the table of contents, references, and footnote symbols, \LaTeX{} must first create auxiliary files that contain details of this information.  That's why it we must always typeset \textbf{twice} in a row for the \verb+pdf+ to be up-to-date.

% Notice the following figure is flushed to the right with text wrapped on the left.
% [5] means that there are five lines to be wrapped
% The text to be wrapped needs to follow
\begin{wrapfigure}[7]{r}{0.35\textwidth}
  \includegraphics [width=0.35\textwidth]{figures/trash.png}
\end{wrapfigure}

Once you're done working with a document, you can clean up your folder by trashing these auxiliary files: \verb+ *.aux *.log *.out *.toc +

Some editors have an option that allows to quickly delete these files.

Only do this when you are finished working with your document, \emph{not} after every time you typeset your it.  However, typesetting errors sometimes occure because of errors in these files, so trashing them and re-typesetting \textbf{twice} sometimes helps.


\section{Acknowledgment}
Many thanks to Prof. Steve Dodge\footnote{
	Prof. Steve Dodge's SFU Website: \url{https://www.sfu.ca/physics/people/faculty/jsdodge.html}
} who introduced me to \LaTeX{} in my third year of university.  Some of this work is based on his examples.


\begin{thebibliography}{99}\label{biblio}

\bibitem{AMS} The American Mathematical Society,
\emph{Short Math Guide for \LaTeX{}},
\url{https://ctan.org/pkg/short-math-guide}

\bibitem{CTAN} Duane Bibby, 
\emph{CTAN Lion Drawing},
	\url{https://www.ctan.org/lion/}

\bibitem{Cottrell} Allin Cottrell,
\emph{Word Processors: Stupid and Inefficient},
\url{http://cda.psych.uiuc.edu/latex_class_2014/wp.html}

\bibitem{Lamport} Leslie Lamport,
    \emph{LaTeX: A Document Preparation System},
    Addison-Wesley, 1994.

\bibitem{NotSoShort} T.~Oetiker, 
\emph{The Not So Short Introduction to \LaTeX},
    \url{https://tobi.oetiker.ch/lshort/lshort.pdf}
    (2.2 MB)

\bibitem{Smith} Peter Smith,
	\emph{LaTeX: The Very Idea},
	\url{https://www.logicmatters.net/resources/pdfs/latex/LaTeXphilosophy.pdf}

\bibitem{Truchon} Patrick Truchon's Wiki Notes,
	\emph{LaTeX},
 \url{https://ptruchon.pagekite.me/wiki/doku.php?id=latex}

\bibitem{WikibooksLaTeX} Wikibooks, 
\emph{LaTeX/Mathematics},
	\url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}

\bibitem{WikipediaLaTeX} Wikipedia, 
\emph{LaTeX},
	\url{https://en.wikipedia.org/wiki/LaTeX}



\end{thebibliography}

\end{document}
