\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage{titling}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage[labelfont=bf, labelsep=period]{caption}
\usepackage{booktabs}
\usepackage[numbers]{natbib}
\usepackage[top=1in, bottom=1in, right=1in, left=1in]{geometry}
%\usepackage[bitstream-charter]{mathdesign}
%\usepackage{palatino}
\usepackage{fouriernc}
\usepackage{xcolor}
\usepackage[normalem]{ulem}
\title{tutorial-latex-document}
\author{Bryan Herman}
\date{January 2014}
\fancyhead{} % clears the header
\fancyfoot{} % clears the footer
\chead{\thetitle}
\lfoot{B. Herman}
\rfoot{\thepage/\pageref{LastPage}}
\pagestyle{fancy}
\begin{document}
\maketitle
\thispagestyle{empty}
\section{Creating Your First Document}
\begin{itemize}
\item Explain sharelatex editing enviroment
\item Explain error messages and debugging
\item Choose a blank project
\item Latex commands begins with a backslash
\item Explain what a document class is, find a website with a list
\item Explain packages
\item Explain googling and CTAN
\item Explain title, author date and what this really means
\item Ends preamble
\item Latex environments begin/end
\item maketitle is a macro that sets up the title in the document
\item Simple section introduction
\end{itemize}
\section{Sections and Paragraphs}
Above is how we make a section title.
\subsection{This is a subsection}
\subsubsection{This is a subsubsection}
If we want a something unnumbered we add a star *
\subsubsection*{This is a subsubsection title unnumbered}
\subsection{Paragraphs}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc nec vulputate orci. Pellentesque non metus sed odio rutrum bibendum. Mauris imperdiet luctus ipsum, eget euismod nisl cursus eu. Phasellus convallis justo vel tortor mollis, id semper dolor egestas. Integer pharetra eu turpis non tempor. Duis tellus enim, viverra in consequat eu, consectetur sed est. Etiam ac diam ut nulla vehicula porttitor quis vitae nisl. Fusce feugiat sollicitudin odio euismod varius. Nullam vehicula quam at leo tincidunt, sit amet iaculis diam imperdiet.
This does not start a new paragraph. You need to leave an extra blank line like this.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc nec vulputate orci. Pellentesque non metus sed odio rutrum bibendum. Mauris imperdiet luctus ipsum, eget euismod nisl cursus eu. Phasellus convallis justo vel tortor mollis, id semper dolor egestas. Integer pharetra eu turpis non tempor. Duis tellus enim, viverra in consequat eu, consectetur sed est. Etiam ac diam ut nulla vehicula porttitor quis vitae nisl. Fusce feugiat sollicitudin odio euismod varius. Nullam vehicula quam at leo tincidunt, sit amet iaculis diam imperdiet.
Personally, I would rather have a blank line between paragraphs and not have an indent. Whenever you want to do something other than the default that Latex provides, simply search online and test it out. Here I will search in google "Latex no indent on paragraphs with spacing between". One website told me to use the package parskip. I added it at the top of the document and all looks good!
Finally, we will discuss commenting. To comment, just add a \% in front of a line and it will not be seen by Latex, just for your eyes only.
% Like this, I don't appear in the document
By the way, the lipsum package is nice for fake text:
\lipsum[1]
\section{Fonts, Size, Color}
There are many fonts you can choose when using latex. I usually choose a font that also has math fonts that look similar to the text fonts. First let's focus on font families. Here is a list of some font families I like to use:
\begin{itemize}
\item \textbackslash usepackage[bitstream-charter]\{mathdesign\}
\item \textbackslash usepackage\{palatino\}
\item \textbackslash usepackage\{fouriernc\}
\end{itemize}
To change font sizes we can use the following commands:
\begin{itemize}
\item tiny -- {\tiny I am tiny text} Need to surround by curly braces --- latex scoping
\item scriptsize -- {\scriptsize I am scriptsize text}
\item footnotesize -- {\footnotesize I am footnote size}
\item small -- {\small I am small size}
\item normalsize -- {\normalsize Default}
\item large -- {\large I am large size}
\item Large -- {\Large I am Large size}
\item huge -- {\huge I am huge size}
\item Huge -- {\Huge I am Huge size}
\end{itemize}
It should be noted that there are latex packages that give you more font sizes and custom font sizes. Just google! Now on to actual fonts. Here is a list of things you can do with a specific font family:
\begin{itemize}
\item shape
\begin{itemize}
\item Upright - textup -- \textup{I am upright text}
\item Italics - textit -- \textit{I am italics text}
\item Small caps - textsc -- \textsc{I am small caps text}
\item Slanted - textsl -- \textsl{I am slanted text}
\item Emphasize - emph -- \emph{Similar to italics (default), but behavior can change depending on packages}
\end{itemize}
\item family
\begin{itemize}
\item Roman family - textrm -- \textrm{I am Roman font}
\item San serif text - textsf -- \textsf{I am san serif text}
\item Typewriter text - texttt -- \texttt{I am typewriter}
\end{itemize}
\item weight
\begin{itemize}
\item Bold - textbf -- \textbf{I am bold}
\item Medium - textmd -- \textmd{I am medium}
\end{itemize}
\item misc
\begin{itemize}
\item Use package \texttt{ulem} to get underlining and strikethrough capability
\item Underline - ul -- \uline{I am underlined}
\item Strikethrough - sout -- \sout{I have a line through me}
\item There are many more options in the package documentation
\end{itemize}
\end{itemize}
Finally we discuss text coloring where we need the \texttt{xcolor}. For this we use latex scopes just like for fonts. Here is source code that makes some text blue and red.
\begin{verbatim}
{\color{blue}Let's start off blue} and {/color{red} switch to red}.
\end{verbatim}
{\color{blue}Let's start off blue} and {\color{red} switch to red}.
\section{Changing the layout of the pages}
\subsection{Margins}
In order to changes the margins, you need the geometry package. Just look it up online. We can use \textbackslash usepackage[top=1in, bottom=1in, right=1in, left=1in]\{geometry\}. You can also change the paper size with this package as well. The default is US letter.
\subsection{Page Styles}
Page styles are a way to customize the theme of a page. This is mainly for headers and footers. The default page style is called \texttt{plain}. This includes just the page number at the bottom. It is set with the command \textbackslash pagestyle\{plain\}. To remove the page style and have a blank header and footer just use \textbackslash pagestyle\{empty\}. This is useful for title pages where the page number may be shown by default. If you use the above command you will see that all the following pages are also empty. To switch back you would have to figure out which text is on the second page and put the command back in for plain style. However, there is a slightly easier way. Because we only want to change the page style on one page, we can use the command \textbackslash thispagestyle\{empty\}. Now it will just change the style for the one page. Note, that the title page is sometimes special and you may have to use thispagestyle always.
\subsubsection{FancyHDR}
There is a nice package to control the headers and footer to make you own custom style. The package is called \texttt{fancyhdr}. Let's use it and see what it gives us. Because we are using the article class, the default behavior for this package is to put the first subsection of the page as the leftmark in the header and the last section title as the right mark. Let's say we want none of these and we just want the title to be in the center of the header, our name to be on the left footer and the page to be on the right footer. We can do the following:
\begin{verbatim}
\fancyhead{} % clears the header
\fancyfoot{} % clears the footer
\chead{tutorial-document-basic}
\lfoot{B. Herman}
\rfoot{\thepage/\pageref{LastPage}}
\end{verbatim}
It should be noted that because I wanted to know the total number of pages, I used LastPage. This statement is part of the lastpage package and it has to be included. There is also a ton of more things that can be done. This includes predefinining multiple types of page styles, having even and odd customizations, taking into account book bindings, etc. Just search online!
\section{Mathematics and Equations}
Packages recommended for whenever you do any kind of equations: amsmath and amssymb.
\subsection{Inline Equations}
To do inline equations, we surround the equation by dollar signs: $2 + 3 = 5$. If you try to
\subsection{Greek Letters}
Greek letter are always important and Latex makes it easy to use them. Just put a backslash before the greek letter name. If you make the first letter captial you get the uppercase greek letter. Here are some examples - $\epsilon$, $\alpha$, $\omega$, $\Omega$. It should be noted that not all greek letters have an uppercase form because they are equivalent to English (e.g., Alpha (A), Beta (B)).
\subsection{Math functions and symbols}
There are an enormous amount of math functions. For example, all the trig you want - $\sin$, $\cos$, $\arctan$. There is also exponential and log - $\exp$, $\log$. There are a bunch of symbols - $\le$, $\equiv$, $\cdot$, $\in$. Just look them up online or you can use \emph{detexify} where you can write the symbol you are looking for and it will come back and tell you the command and what latex package it is apart of.
One last item here is fractions. The command is \verb|\frac{}{}|. In the first curly braces you but the numerator and for the last curly braces you but the denominator - $\frac{1}{2}$
\subsection{Displayed Equations / Labels and Cross Referencing}
Most of the time, you want you equation to be centered on its own line with an Equation number. This is no problem for latex when you use the equation environment.
\begin{equation}
2 + 3 = 5
\end{equation}
And another:
\begin{equation}
f(x) = a_0 + \sum_{i=1}^{\infty} a_i P_i(x)
\label{eq:expansion}
\end{equation}
Now, as you can see, the equation number is automatically generated. Now if we want to reference this equation number in the text, we could just state Eq. (1). However, if we put another equation above this one it will no longer be Equation 1. We can use labels and cross referencing to have latex link a reference to an equation. To do this we must put a label before the end of an equation. It looks like - \verb|\label{eq:expansion}|. It is good style to prefix the keyword expansion with the type of label it is: eq. We will have other prefixes for other label types later. Now that we added it to the expansion formula we can reference it with \verb|\eqref| which will automatically surround it by parenthesis. In Eq. \eqref{eq:expansion}, we show a series expansion.
Finally, if you don't want your equation to have a number just add a * after equation in the begin and end commands.
\begin{equation*}
3 + 3 \neq 5
\end{equation*}
\subsection{Equations on multiple lines}
With very complex equations it is nice to break them up across multiple lines. The first example will use the \texttt{multline} environment. With this, we can easily break up the equation amoung multiple lines by just adding two backslashes -
\begin{multline}
\nabla\cdot\hat\Omega\varphi\left(\vec{r},E,\hat\Omega\right) + \Sigma_t\left(\vec{r},E\right)\varphi\left(\vec{r},E,\hat\Omega\right) = \\
+ \int_0^\infty dE^\prime \int_{4\pi}d\Omega^\prime\sum_{j}\Sigma_s^j\left(\vec{r},E^\prime\rightarrow E,\hat\Omega^\prime\rightarrow\hat\Omega\right)\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right) \\
+ \frac{1}{k_{eff}}\frac{1}{4\pi}\int_0^\infty dE^\prime\sum_{j_f}\chi^{j_f}\left(E^\prime\rightarrow E\right)\nu^{j_f}\left(E^\prime\right)\Sigma_f^{j_f} \left(\vec{r},E^\prime\right)\int_{4\pi} d\Omega^\prime\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right)
\end{multline}
Sometimes, it is nice to have things line up. In the above equation, if we could line up all of the plus signs, the equation make look a little nicer. For this, we use the \texttt{align} environment. This basically works like a matrix which is described next. It basically makes the equation have as many rows a you want with two columns. Here we make the plus signs be the last item in the first column and the rest of the line in the second column. To separate columns we just add an \& in the equation.
\begin{align}
\nabla\cdot\hat\Omega\varphi\left(\vec{r},E,\hat\Omega\right) + & \Sigma_t\left(\vec{r},E\right)\varphi\left(\vec{r},E,\hat\Omega\right) = \\
+ & \int_0^\infty dE^\prime \int_{4\pi}d\Omega^\prime\sum_{j}\Sigma_s^j\left(\vec{r},E^\prime\rightarrow E,\hat\Omega^\prime\rightarrow\hat\Omega\right)\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right) \\
+ & \frac{1}{k_{eff}}\frac{1}{4\pi}\int_0^\infty dE^\prime\sum_{j_f}\chi^{j_f}\left(E^\prime\rightarrow E\right)\nu^{j_f}\left(E^\prime\right)\Sigma_f^{j_f} \left(\vec{r},E^\prime\right)\int_{4\pi} d\Omega^\prime\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right)
\end{align}
What you notice now is that this environment gives a number for each line. Let's say we just want an equation number for the last line - we put the \verb|\nonumber| command on the other lines.
\begin{align}
\overbrace{\nabla\cdot\hat\Omega\varphi\left(\vec{r},E,\hat\Omega\right)}^{\rm Leakage\,\,Term} + & \Sigma_t\left(\vec{r},E\right)\varphi\left(\vec{r},E,\hat\Omega\right) = \nonumber \\
+ & \int_0^\infty dE^\prime \int_{4\pi}d\Omega^\prime\sum_{j}\Sigma_s^j\left(\vec{r},E^\prime\rightarrow E,\hat\Omega^\prime\rightarrow\hat\Omega\right)\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right) \nonumber \\
+ & \frac{1}{k_{eff}}\frac{1}{4\pi}\int_0^\infty dE^\prime\sum_{j_f}\chi^{j_f}\left(E^\prime\rightarrow E\right)\nu^{j_f}\left(E^\prime\right)\Sigma_f^{j_f} \left(\vec{r},E^\prime\right)\int_{4\pi} d\Omega^\prime\varphi\left(\vec{r},E^\prime,\hat\Omega^\prime\right)
\label{eq:neut}
\end{align}
\subsection{Matrices}
To build a matrix, we just use the matrix environment from within the equation environment. It works just like the align above. We just double backslash to separate rows and we use \& to separate columns in a row.
\begin{equation*}
\begin{matrix}
2 & 3 \\
4 & 5 \\
\end{matrix}
\end{equation*}
There are a bunch of modifications to the matrix environment depending on how you want to enclose it. We make an unordered list of these using the \texttt{itemize} environment where each bullet begins with the command \verb|\item|:
\begin{itemize}
\item \texttt{pmatrix} environment - surrounds matrix by parenthesis
\item \texttt{bmatrix} environment - surrounds matrix by square brackets
\item \texttt{Bmatrix} environment - surrounds matrix by curly braces
\item \texttt{vmatrix} environment - surrounds matrix by single vertical bars
\item \texttt{Vmatrix} environment - surrounds matrix by double vertical bars
\end{itemize}
Here is an example for a determinant of a 2x2 matrix-
\[
\begin{vmatrix}
a & b \\
c & d \\
\end{vmatrix}
= ad - bc
\]
\subsection{Accents}
We all like to write in operator form so we dont have to write out Eq. \eqref{eq:neut} every time. Here are some options:
\begin{itemize}
\item \verb|\mathcal{M}| - $\mathcal{M}$ - used for continuous operator
\item \verb|\mathbb{M} | - $\mathbb{M}$ - used for discretized operator / matrix
\item \verb|\mathbf{x} | - $\mathbf{x}$ - used for bolding possible for vectors
\item \verb|\boldsymbol{\Phi}| - $\boldsymbol{\Phi}$ - another way of bolding
\end{itemize}
\begin{equation}
\mathbb{M}\mathbf{\Phi} = \frac{1}{k}\mathbb{F}\mathbf{\Phi}
\end{equation}
\section{Figures, Subfigures and Tables}
\subsection{Figures}
To include images into your document we must add the package \texttt{graphicx}. The command to include a graphic is \verb|\includegraphics[]{}|. In the curly braces goes the relative path to the image and in the square brackets are options for the image. Some common options are -
\begin{itemize}
\item \texttt{scale=} - scale the image by some factor, keep aspect ratio
\item \texttt{height=} - set the height of the image and keep the aspect ratio
\item \texttt{width=} - set the width of the image and keep the aspect ratio
\item \texttt{angle=} - rotate the image by some angle in degrees
\item \texttt{clip=} - set this to true if you want to crop the image
\item \texttt{trim=} - put in 4 values to crop the image. the order of the 4 values is left, bottom, right and top side.
\end{itemize}
It should be noted that if height and width are both used, the aspect ratio will not be kept constant unless those values keep that ratio. Let's play around with these by uploading the MIT seal image. Now let's include it -
\includegraphics{figs/MIT.png}
As you see, it is just thrown into the text. We will discuss how to make this fit correctly in your document later, but let's first show the options. We can scale this down -
\includegraphics[scale=0.4]{figs/MIT.png}. We can set the height as some measure value. There are a ton of units in Latex. You could leave it as unitless, in for inches or cm for centimeters. Lets make the height 3cm - \includegraphics[height=3cm]{figs/MIT.png} We could do the same thing for the width, but let's try both and see what happens to the aspect ratio - \includegraphics[height=3cm, width=1cm]{figs/MIT.png} Now we can also rotate it 45 degrees - \includegraphics[scale=0.4, angle=45]{figs/MIT.png}.
\newpage
Finally, let's say we just wanted the 1861 part of the image. We can first get it to the size we want and then crop around it.
\includegraphics[scale=1,clip=true,trim=3cm 2.5cm 3cm 3.4cm]{figs/MIT.png}
\subsubsection{Floating Figures}
Most of the time, you don't want to be just throwing you figure right between your text. If you want to include a nice figure with a caption that is displayed on a line by itself, we must put our image commands in a \texttt{figure} environment. This environment is also special because it is a \emph{floating} environment. What this means is that Latex will move this figure as it sees fit to minimize extra whitespace. An example of this is below:
\begin{verbatim}
\begin{figure}[t,p]
\centering
\includegraphics[scale=0.4]{figs/MIT.png}
\caption{MIT Seal}
\label{fig:MITseal}
\end{figure}
\end{verbatim}
After the environment begins, there are optional arguments [t,p] specified. This let's latex know your preferences on where the figure will be placed. If you include nothing, latex will do what it wants. Here we tell it that we would like this figure to be placed at the top of the page by putting at \texttt{t} first. Next, we put a \texttt{p} letting it know that if that doesn't work please put it on a separate page for floating environments. Other possibilities are bottom \texttt{b} and right here \texttt{h}. Also, if latex is not doing what you want, put the specifying that you want first followed by an ! to force it to do this.
Also we have included the command to center the image on the page called centering. Then follows the same includegraphics commands like before. To add a caption we use the caption command. Like equations, we put a label just before the end of the environment for cross referencing. This time we used the prefix fig.
Let's now put the figure code in right below this text:
\begin{figure}[t,p]
\centering
\includegraphics[scale=0.4]{figs/MIT.png}
\caption{MIT Seal}
\label{fig:MITseal1}
\end{figure}
As you see, the figure went to the top of the page just like we preferred. Let's now put the same figure code in, but now have it show up right below this text:
\begin{figure}[h]
\centering
\includegraphics[scale=0.4]{figs/MIT.png}
\caption{MIT Seal}
\label{fig:MITseal2}
\end{figure}
I don't really like the default style of the captions. Say I prefer that the Figure and number be bold, followed by a period and then my caption title. To do this we can use the caption package and include with some optional arguments for making the label boldface and the separator a period - \verb|\usepackage[labelfont=bf, labelsep=period]{caption}|
\subsection{Subfigures}
If you want subfigures, you must include the package \texttt{subfigure}. Now we first make a figure environment and then put the subfigures in. It goes like this -
\begin{verbatim}
\begin{figure}[h]
\centering
\subfigure[Type 1]{\includegraphics[scale=0.4]{figs/MIT.png}\label{fig:MITsealsub1}}
\qquad\qquad % this just puts spacing between the figures
\subfigure[Type 2]{\includegraphics[scale=0.4]{figs/MIT.png}\label{fig:MITsealsub}\label{fig:MITsealsub2}}
\caption{MIT Seals}
\label{fig:MITseal3}
\end{figure}
\end{verbatim}
Here it is displayed on the page -
\begin{figure}[h]
\centering
\subfigure[Type 1]{\includegraphics[scale=0.4]{figs/MIT.png}\label{fig:MITsealsub1}}
\qquad\qquad
\subfigure[Type 2]{\includegraphics[scale=0.4]{figs/MIT.png}\label{fig:MITsealsub}\label{fig:MITsealsub2}}
\caption{MIT Seals}
\label{fig:MITseal3}
\end{figure}
You can also cross reference subfigures as well as the whole figure environment. To cross reference things other than equations we just use \verb|\ref|. In Figure \ref{fig:MITseal3} exists subfigures \ref{fig:MITsealsub1} and \ref{fig:MITsealsub2}.
\subsection{Tables}
We have already talked about how to make new rows and columns from matrices. Here, we introduce the environment for tables called \texttt{tabular}. The structure of this environment is:
\begin{verbatim}
\begin{tabular}{l c c}
\hline
Fruit & At home & At work \\
\hline
\hline
Apples & 5 & 2 \\
\hline
Bananas & 3 & 1 \\
\hline
\end{tabular}
\end{verbatim}
What you will notice with this structure is that after the begin command there is an extra curly brace needed for input. Unlike matrices, we can specify the position at which the text appears in a cell. Here, the first column is left justified and the rest are centered. The other two options are \texttt{r} for right justified and \verb|p{3cm}| for a column of a certain size. To get horizontal lines we use the command hline. Let's see what this table looks like -
\begin{tabular}{l c c}
\hline
Fruit & At home & At work \\
\hline
\hline
Apples & 5 & 2 \\
\hline
Bananas & 3 & 1 \\
\hline
\end{tabular}
Sometimes you may want the columns to be separated by a vertical bar. To do this you add bars in the format specifier after begin like this -
\begin{verbatim}
\begin{tabular}{l|c|c}
\hline
Fruit & At home & At work \\
\hline
\hline
Apples & 5 & 2 \\
\hline
Bananas & 3 & 1 \\
\hline
\end{tabular}
\end{verbatim}
\begin{tabular}{l|c|c}
\hline
Fruit & At home & At work \\
\hline
\hline
Apples & 5 & 2 \\
\hline
Bananas & 3 & 1 \\
\hline
\end{tabular}
Just as with figures, there is a floating environment for tables called \texttt{table}. We use it just like for figures. Here we use the prefix \texttt{tab} for the label to cross reference Table \ref{tab:fruit}.
\begin{table}[h]
\centering
\caption{Where is my fruit?}
\begin{tabular}{l c c}
\hline
Fruit & At home & At work \\
\hline
\hline
Apples & 5 & 2 \\
\hline
Bananas & 3 & 1 \\
\hline
\end{tabular}
\label{tab:fruit}
\end{table}
There is another way of putting together a table which has a more professional look. It is called book tables in the package booktabs. The differences in constructing this nicer table are:
\begin{verbatim}
\begin{tabular}{l c c}
\toprule
Fruit & At home & At work \\
\midrule
\midrule
Apples & 5 & 2 \\
\midrule
Bananas & 3 & 1 \\
\bottomrule
\end{tabular}
\end{verbatim}
\begin{table}[h]
\centering
\caption{Where is my fruit?}
\begin{tabular}{l c c}
\toprule
Fruit & At home & At work \\
\midrule
\midrule
Apples & 5 & 2 \\
\midrule
Bananas & 3 & 1 \\
\bottomrule
\end{tabular}
\label{tab:fruitbook}
\end{table}
\section{Generating Bibliographies with Bibtex}
All bibliographic entries are placed in the .bib file. Although there are programs that can put these together for you, it is easy to just build it straight in the text file. To have the bibliography show up at the end of the document you put the following two commands:
\begin{verbatim}
\bibliographystyle{plain}
\bibliography{ref}
\end{verbatim}
The first thing you need is a bibliography style which you can look up online. Here we just use plain. The second entry is the bibliography file itself without the .bib extension. We just place these as the last thing in the document before the end document command.
Let's look at the .bib file. If you look online, you will see all the possibilities for bibtex entries. With each type of entry, there are mandatory and optional fields. The most common you may use are inproceedings, book, article, PhDthesis. Note that conferences and journals will give you specific instructions on how to cite things. In each bibtex entry there is a key that is used for referencing in the text. To cite Paul Romano's 2013 OpenMC paper we just do \verb|\cite{Romano2013_openmc}| \cite{Romano2013_openmc}. Now say we want to site two things, we can comma separate them \verb|\cite{Aviles2013,Horelik2013}| \cite{Aviles2013,Horelik2013}. Here we put, 3 in comma separated \cite{Lee2012,Romano2012,Herman2013}. As you will see, the plain style doesn't order the references in numerical order. We use a package called natbib which gives us more flexibility. By default it will do author year styles, but we can do numerical referencing with:
\begin{verbatim}
\usepackage[numbers]{natbib}
\end{verbatim}
For the bibliography style we can use \texttt{unsrtnat}.
\bibliographystyle{unsrtnat}
\bibliography{ref}
\end{document}