\documentclass[12pt]{article}
\usepackage{natbib} % used for science journal style citations
\usepackage{amsmath} % used for some extra mathematics commands
\usepackage[dvips,xdvi]{graphicx} % used for importing graphics
%Uncomment the command below to ``double space''
%\renewcommand{\baselinestretch}{1.7}
\renewcommand{\Pr}{\mbox{P}} % override the default probability command
\pagestyle{plain}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\marginparwidth}{0in}
\setlength{\marginparsep}{0in}
\setlength{\topmargin}{0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.75in}
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{1ex}
%\setlength{\columnsep}{0.25in}
\raggedbottom

\begin{document}
\title{Sample Article to Illustrate Features in \LaTeXe}
\author{Bret Larget\\Duquesne University\\Department of Mathematics and Computer Science}
\date{31 October, 2001}
\maketitle
\begin{abstract}
\LaTeXe is the standard tool to typeset material with mathematical notation.
However, it can be difficult for new users to learn to use this tool effectively.
This brief article provides examples of many features in \LaTeXe
including commands for creating sections in a paper,
some examples of displaying mathematical notation,
importing graphics,
and automatically creating a bibliography.
\end{abstract}

\section{Introduction}

\LaTeXe is a powerful tool for typesetting mathematical work.
Most journals in the mathematical and computational sciences require
that articles be submitted in \LaTeXe.
Better yet, it is free.
If you take the time to master \LaTeXe,
you will find that it makes many writing tasks much easier.

However, there is a fairly steep learning curve to learning \LaTeXe.
Unlike word processing programs such as Microsoft Word,
\LaTeXe is not a `what you see is what you get' computational tool.
To format text, you need to create a plain text file that contains
both content and special commands for formatting the end result.
You then process this file to create a document that can be viewed on a computer monitor
or printed on paper.

This article should give you enough examples to write short reports for the course.
If you take on a larger project, such as a thesis,
you will want to obtain a better source of information.
There are many books that give extensive descriptions and instructions of all the features of \LaTeXe.
One excellent example is \citet{kopka-daly}.

\section{The Basics}

These instructions will describe how to create a lab report
using the Department of Mathematics and Computer Science Linux system.
There are also Windows versions of \LaTeXe that you can use as well,
but you are on your own to learn how to use \LaTeXe on that platform.

There are several steps to create a finished lab report using \LaTeXe.
\begin{enumerate}
\item Create a file (with a \texttt{.tex} extension) that contains the content of your report
and special formatting commands.
You may use any text editor for this.
My favorite is emacs.
It is probably easiest to begin by editing the \texttt{.tex} file used to create this document.
\item If you will include graphics,
use another program (such as S-PLUS) to create either PostScript (\texttt{.ps})
or Encapsulated PostScript (\texttt{.eps}) files with the graphics.
\item If your report includes an automatically formatted bibliography,
create a bibliographic data base in a file with extension \texttt{.bib}.
\item Use the program \texttt{bibtex} to create the bibliography.
\item Use the program \texttt{latex} to create a device independent file (\texttt{.dvi}) file
that can be viewed on the computer with the program \texttt{xdvi}.
\item Use the program \texttt{dvips} to create a PostScript file that may be printed
on a Postscript printer (with \texttt{lp} or \texttt{lpr})
or viewed on the computer monitor (with \texttt{ghostview}).
\end{enumerate}

\subsection{The .tex file}
The first step in using \LaTeXe to write a lab report
is to create the \texttt{.tex} file which contains the content of your report
and special formatting commands.
This file must begin with the special command
\verb+\documentclass+.
The beginning of an article in twelve point font is declared as
\verb+\documentclass[12pt]{article}+.
The \texttt{[12pt]} is an example of an optional argument.
You could choose a different font size with \texttt{[11pt]} or \texttt{[10pt]}.
The second argument is the type of document.
You might choose \texttt{report} instead of \texttt{article}.
There are some formatting differences between reports and articles including
section numbering and abstract placement.

\paragraph{The preamble.}
The preamble is a section of special commands that set margins
and other layout parameters as well as user definitions of commands.
See the \texttt{.tex} file of this document for examples.

\paragraph{The document.}
The remainder of the document begins with the declaration
\verb=\begin{document}=
and ends with \verb=\end{document}=.
The remainder of this article provides more details on the content of the document.

\section{Parts of an article}

\subsection{Displayed mathematics equations.}
Mathematics symbols are written in mathematics mode.
In regular text, you can set mathematics between dollar signs.
For example, the code \verb+$\mu = 10.2$ and $\sigma = 2.3$+
produces
$\mu = 10.2$ and $\sigma = 2.3$.
You can create displayed formulas without equation numbers using double dollar signs.
\begin{verbatim}
$$
s = \sqrt{ \frac{\sum_{i=1}^n (x_i - \bar{x})^2}{n-1} }
$$
\end{verbatim}
creates
$$
s = \sqrt{ \frac{\sum_{i=1}^n (x_i - \bar{x})^2}{n-1} }
$$
Alternatively you can create numbered equations with an expression between
\verb+\begin{equation}+ and \verb+\end{equation}+.

\subsection{Tables.}
Tables are created in the \texttt{tabular} environment.
In a paper, tables should be numbered and have titles and captions.
These are included in the \texttt{table} environment.
This table object is a float, which means it may be placed in a different place in the paper,
such as the top or bottom of a nearby page.

This first example is a non-labeled table.
\begin{verbatim}
\begin{center}
\begin{tabular}{l|c|c|c|c}
& \multicolumn{4}{c}{possible values} \\
$x$ & 0 & 1 & 2 & 3 \\\hline
$\Pr(X=x)$ & $\binom{3}{0}p^0(1-p)^3$ & $\binom{3}{1}p^1(1-p)^2$ &
$\binom{3}{2}p^2(1-p)^1$ & $\binom{3}{3}p^3(1-p)^0$
\end{tabular}
\end{center}
\end{verbatim}
produces
\begin{center}
\begin{tabular}{l|c|c|c|c}
& \multicolumn{4}{c}{possible values} \\
$x$ & 0 & 1 & 2 & 3 \\\hline
$\Pr(X=x)$ & $\binom{3}{0}p^0(1-p)^3$ & $\binom{3}{1}p^1(1-p)^2$ &
$\binom{3}{2}p^2(1-p)^1$ & $\binom{3}{3}p^3(1-p)^0$
\end{tabular}
\end{center}
We can add a caption and label like below.
\begin{verbatim}
\begin{table}
\begin{center}
\begin{tabular}{l|c|c|c|c}
& \multicolumn{4}{c}{possible values} \\
$x$ & 0 & 1 & 2 & 3 \\\hline
$\Pr(X=x)$ & $\binom{3}{0}p^0(1-p)^3$ & $\binom{3}{1}p^1(1-p)^2$ &
$\binom{3}{2}p^2(1-p)^1$ & $\binom{3}{3}p^3(1-p)^0$
\end{tabular}
\end{center}
\caption{\label{binomial.table}
\textbf{A binomial distribution.}
This table shows the binomial distribution for $n=3$
and an unspecified $p$.}
\end{table}
\end{verbatim}
The label should appear in (or after) the caption for numbering to be correct.
This code produces a table that is placed somewhere in the article on a page
where the text declaring it appears or later.

\begin{table}
\begin{center}
\begin{tabular}{l|c|c|c|c}
& \multicolumn{4}{c}{possible values} \\
$x$ & 0 & 1 & 2 & 3 \\\hline
$\Pr(X=x)$ & $\binom{3}{0}p^0(1-p)^3$ & $\binom{3}{1}p^1(1-p)^2$ &
$\binom{3}{2}p^2(1-p)^1$ & $\binom{3}{3}p^3(1-p)^0$
\end{tabular}
\end{center}
\caption{\label{binomial.table}
\textbf{A binomial distribution.}
This table shows the binomial distribution for $n=3$
and an unspecified $p$.}
\end{table}

At any other place in the text I can use the command \verb=\ref=
to refer to the table.
For example, the command
\verb=Table~\ref{binomial.table}=
will result in Table~\ref{binomial.table} in the processed text.

\subsection{Figures and imported graphics.}
Suppose that you created a PostScript file named \texttt{scatterplot.ps}
with S-PLUS.
This code will import the plot
and put it into a figure whose position will float to a good choice.
\begin{verbatim}
\begin{figure}
\rotatebox{270}{\includegraphics{scatterplot.eps}}
\caption{\label{scatterplot.fig}
\textbf{A scatterplot.}
The diagram shows a scatterplot of two variables
with an approximate bivariate normal distribution and a positive association.
The correlation coefficient is $r=0.50$.}
\hrulefill
\end{figure}
\end{verbatim}
The actual figure will appear after this point.
The \verb=\rotatebox= command is not always necessary,
but by default the Encapsulated PostScript file will be placed so the wider dimension is vertical,
whether that is what you intended or not.
\begin{figure}
\rotatebox{270}{\includegraphics{scatterplot.eps}}
\caption{\label{scatterplot.fig}
\textbf{A scatterplot.}
The diagram shows a scatterplot of two variables
with an approximate bivariate normal distribution and a positive association.
The correlation coefficient is $r=0.50$.}
\hrulefill
\end{figure}
We may refer to Figure~\ref{scatterplot.fig}
with the command \verb=Figure~\ref{scatterplot.fig}=.

\subsection{Citations.}
The data for cited work should be in a file with extension \texttt{.bib}.
See the file \texttt{sample.bib} for an example of formatting.
Each reference has a key.
You refer to it in the text with the command \verb=\cite{=\textit{key}\verb=}=.
By default \LaTeXe will give numerical citations in the body of the text.

A more common citation style is to refer to author last name and year of publication
in the body of the text.
To do this, we need to include the \texttt{natbib}
package in the preamble.
Then, we will use the commands \verb=\citet= and \verb=\citep= to make citations in the text.
The `t' refers to `text'
and is appropriate when the author's name is part of the body of the text and the date
follows in parentheses.
The `p' means `parentheses'
and is used when both names and year are parenthetically cited.
Here are several examples.

\begin{verbatim}
\citet[page 251]{nolan-speed} include an appendix
that provides an excellent guide to effective writing.
An early lab assignment
discusses maternal smokinf and low birth weight \citep{yer64}.
Chapter~5 in the book \emph{A Guide to \LaTeX} by \citet{kopka-daly} 
contains many examples for formatting mathematical notation.
\end{verbatim}

This code produces the following text.
\begin{quote}
\citet[page 251]{nolan-speed} include an appendix
that provides an excellent guide to effective writing.
An early lab assignment
discusses maternal smoking and low birth weight \citep{yer64}.
Chapter~5 in the book \emph{A Guide to \LaTeX} by \citet{kopka-daly} 
contains many examples for formatting mathematical notation.
\end{quote}

\paragraph{The Bibliography.}
At the end of your \texttt{.tex} file, but before the \verb=\end{document}= declaration,
you should include two commands that declare the bibliography.
These commands are \verb=\bibliographystyle= and \verb=\bibliography=.
Each command has an argument.
In this example, we use a bibliography style in the file \texttt{rss.bst}
created to conform to the specifications of the journals of the Royal Statistical Society.
The second command specifies the bibliographic data base.
In this example, these commands are
\begin{verbatim}
\bibliographystyle{rss}
\bibliography{sample}
\end{verbatim}

\section{Putting it all together.}

Once you have created all of the files, here is how to put it all together
to create your report.

The first step is to run \LaTeXe.

\begin{verbatim}
latex sample.tex
\end{verbatim}

This will format everything that can be formatted.
Cross references may be wrong and citations will be missing.
You will likely need to correct some errors in your \texttt{.tex} file,
such as run on commands or poorly formatted mathematics.
Line numbers of errors are output.
Eventually, you get a corrected file.
One side effect of running \LaTeXe is the creation of a \texttt{.aux} file
that contains auxiliary information.
The Bibtex program needs this file to format the bibliographic information.

Now, create the \texttt{.bbl} file with \texttt{bibtex}.

\begin{verbatim}
bibtex sample
\end{verbatim}
Do not include the \texttt{.tex} extension to the filename.

Now that you have the bibliographic information, run \texttt{latex} twice,
once to realize it has the bibliographic information handy and the second time
to add the proper citations to the body of the text.

\begin{verbatim}
latex sample.tex
latex sample.tex
\end{verbatim}

You can now view the file with the \texttt{xdvi} command.

\begin{verbatim}
xdvi sample.dvi
\end{verbatim}

Also, you can create a PostScript file and a pdf file.

\begin{verbatim}
dvips sample.dvi -o
dvipdf sample.dvi
\end{verbatim}

\section{Summary}

\LaTeXe is a very powerful tool for formatting scientific writing.
This guide contains enough information to get you started.
Please do see me for help if you have any questions on making this work.
Most new users of \LaTeXe find that it is easiest to learn from a local
`texpert' instead of from written documentation, and I am that resource for you.

\bibliographystyle{rss}
\bibliography{sample}

\end{document}
