

% this file was downloaded from website
% www.math.iastate.edu/burkardt/latex_intro/latex_intro.html

%  complex.tex
%  25 July 2001
%
\documentclass{article}

\title{Some Hard Stuff}
\author{Ima Otther}
\date{\today}

\usepackage{epsfig}

\graphicspath{{c:/2002/latex/}}
\begin{document}

\maketitle

\begin{abstract}
This article demonstrates a few of the more advanced uses of \LaTeX{},
including the use of labels to refer to sections, equations, figures,
and tables, the citation of bibliographic references, the creation of
tables, and the use of graphic figures.
\end{abstract}

\tableofcontents
\listoftables
\listoffigures

\section{Citations, Labels, References}
\label{section-labels}

You are familiar with the way in which a technical paper will have a 
numbered list of references at the end, and will refer to a particular
reference in the text, as we might refer, for instance, to the \LaTeX{}
manual by Oetiker and others\cite{Oetiker}.  To use this facility, you
set up a bibliography section at the end of your paper.  The bibligraphy
is a list of the reference works, but with each item you include
a short label (which is not printed), allowing you to refer to the
item in the text using the \textbf{cite} command.

Similarly, you may use the \textbf{label} command to stick labels onto
the sections, tables, figures, and equations of your report.  To make
a reference to a labeled item, you use the \textbf{ref} command, so that
we can refer to Figure~\ref{figure-voronoi}, to the discussion of
tables in Section~\ref{section-tables}, 
to the convergence results in Table~\ref{table-one}, or to the finite element
formulation in Equation~\ref{equation-fem}.

\section{Displaying Code}
\label{section-code}

Articles which discuss algorithms and computing often need to display
fragments of computer input data or code.  It is important that this material 
be displayed exactly as the author intends; \LaTeX{} must not rearrange items 
as though it were text.  

Computer input and output is traditionally displayed in the \textbf{texttt}
font; a short bit of text might simply be printed in an \textbf{mbox}, which
guarantees that it will be printed on one line.  This would be appropriate
if we wanted to mention that a particular program will begin by printing
``\texttt{\mbox{Snood 2.0 Ready}}''.  

For longer chunks of I/O and code fragments, you might want to use a 
\textbf{verbatim} environment.  This is easy; you can cut and paste a
chunk of text, and it will show up just as you entered it, using a 
monospaced or ``typewriter'' font:
\begin{verbatim}
  for i = 1 : 10
    x = x - f(x) / f'(x)
  end
\end{verbatim}

\textbf{Verbatim} is easy to use, but not flexible.  You can't change
fonts or use the symbol for $\pi$ or anything.  If this bothers you
enough that you're willing to put up with a lot of details, one 
possible way around this is to use tabbing and newlines, perhaps in a 
\textbf{quote} environment.
\begin{quote}
  \begin{tabbing}
%
%  The following line sets tabs every 5 spaces.
%  The \kill command keeps it from printing out.
%
12345\=67890\=12345\=67890\=12345\= \kill
%
%  The tab is carried out using the symbols \>
%
%  You must use a \\ command to force line breaks.
%
\>x = 0 \emph{(initialize x)}\\
\>for i = 1 : 10\\
\>\>x = x - $\pi$ / f'(x)\\
\>\>if ( x == 0 )\\
\>\>\>disp ( 'The algorithm has broken down!' )\\
\>\>\>\textbf{exit}\\
\>\>end\\
\>end\\
  \end{tabbing}
\end{quote}

\section{Tables}
\label{section-tables}

A common item in technical reports is a table containing rows and columns
of data and words, perhaps with an initial row of labels.  We will only
discuss simple tables here.  For more information, see
Gr\"atzer\cite{Graetzer} or Kopka\cite{Kopka}.

Here's an example of a common sort of table, in which we simply want
to report the value of several quantities.  The table begins with a
\textbf{table} environment.  Here we may make suggestions or demands
about how the table is to show up in the text.  In the example, the
placement information is \textbf{[htb]}, which means we'd like the 
table to be placed "right here", or else at the top or bottom of the
current page.   We can also specify a caption to appear with the table.
It will appear above or below the table, depending on whether we give
the caption before or after the table information.  We can specify a 
label for the table, so that we can make symbolic
references to the table, such as ``\ldots{}notice the surprising results
reported in Table~\ref{table-one}''.  Note that, for no good reason, the 
label must be given \emph{after} the caption.

Once these preliminary matters are specified, the 
actual text of the table comes, inside a \textbf{tabular} environment.  
We can include a string of letters like \verb+{|c|r|l|l|}+ which tells 
\LaTeX{} we want center, right, or left alignment of the text in each 
entry.  And if we want to refer to the table by number, we need to 
add a \textbf{label}.

\begin{table}[htb]

\caption{Convergence results for the algorithms.}\label{table-one}

\begin{tabular}{|c|r|l|l|}
\hline
Algorithm & Steps & Accuracy & Comment \\
\hline
Bisection & 100 & 0.0013      & Did not converge.\\
Secant    &  34 & 0.000002    & Final step made things worse! \\
Newton    &   5 & 0.000000001 & Convergence rate quadratic \\
\hline
\end{tabular}

\end{table}

Notice that the table is printed flush left.  If you want it to be
centered, you can put the tabular information in a \textbf{centerline}
environment.

\begin{table}[htb]

\centerline{
  \begin{tabular}{|l|c|l|}
  \hline
  Movie & Year & Comment \\
  \hline
  AI    & 2001 & Ugh.\\
  ET    & 1982 & Reese's Pieces \\
  F/X   & 1985 & Bryan Brown blows things up\\
  IQ    & 1992 & Walter Matthau was Einstein?\\
  \hline
  \end{tabular}
}

\caption{A centered table with caption \textit{below}.}\label{table-two}

\end{table}

\section{Including Graphics}
\label{section-graphics}

To include graphics in your \LaTeX{} document, you need to save a graphic
image as an \textit{Encapsulated PostScript File}, also called an \textit{eps}
file, access the \textit{epsfig} package inside your document, and place
the image using the \textbf{figure} command.

\begin{figure}[htb]

\centerline{
  \psfig{file=voronoi.ps,width=4in}
}
\caption{A Voronoi Diagram for 30 Random Points.}\label{figure-voronoi}
\end{figure}

An \textit{eps} file is a PostScript File containing a single image.  Most
graphics packages include a way to create \textit{eps} files.  In particular,
in \textbf{MATLAB}, this is done by going to the \textbf{File} menu on
the \textbf{Figure} window and selecting \textbf{Export}.  Then, under
\textbf{Save as Type} you select \textbf{EPS files} or \textbf{Color EPS files};
then specify the name of the file, which might be something like 
\textit{my\_figure.eps}.  (Make sure you notice \textit{where} the file is 
placed, or you'll waste some time hunting around for it!)

An \textit{eps} file is useful all by itself.  You should be able to view
it, print it, or mail it to someone, or take it home on a disk.  However,
for our purposes, it is most convenient if that file is moved to the
directory or folder containing your \LaTeX{} document so it will be easy
to include.

The second step is simply to warn \LaTeX{} that you'll be including \textit{eps}
graphics; you do this by inserting the command \verb+\usepackage{epsfig}+
in the preamble of your document.

Finally, you place the figure by using the \textbf{figure} environment.

You may set a caption, which will appear above or below the figure, depending
on whether it occurs before or after the \textbf{psfig} command.  
You may also assign a label, so you can refer to the figure in the text,
in phrases like ``\ldots{}refer to Figure~\ref{figure-voronoi} to see
the mistakes in \textbf{MATLAB}'s Voronoi plots.'
Note that, for no good reason, the label must be given \emph{after} the caption.

A \textbf{centerline} environment can be used to force the picture to be 
centered in the text.  The figure itself is defined by the command 
\textbf{psfig}, which allows you to specify the file name.  You can also 
resize the picture by specifying the width in inches.  If you specify both 
the width and height, the picture may be distorted.

\begin{figure}[htb]

\psfig{file=voronoi.ps,width=2.5in}
\psfig{file=voronoi.ps,width=2.5in}

\caption{Two Graphics in One Figure.}\label{figure-voronoi2}
\end{figure}

If you have lots of simple graphs, you may want to try to conserve space
by putting them together.  One way to do this is to include them all in 
one figure, and make them small enough that LaTeX{} will automatically
realize it can place them side by side.  In this example, we've taken
two copies of our Voronoi picture, and by specifying the width to be
2.5 inches for each, gotten them to appear on one line.

\section{A Little More on Equations}
\label{section-equations}

The rules that work so well for short and simple equations need some help
when a single equation is too long to print on one line, or when your
equation is really a string of several equations.  You generally have a
very definite layout in mind, but in order for this to appear on the
paper, you need to give \LaTeX{} some guidance.

Suppose, first off, that we have a single equation that is rather long,
and will have to be broken over two lines.  If we let \LaTeX{} process
the equation once, it will try to print the whole equation on one line.
But if we see that it will be necessary to use several lines, 
we can convert from the \textbf{equation} to \textbf{eqnarry} environment.
Then we can specify where the line will break by using a double
backslash \verb+\\+.  \LaTeX{} will want to number both pieces of the
equation, but we can stop this by using the \textbf{nonumber} command
on each line that is to be left unnumbered.

\begin{eqnarray}
\label{equation-fem}
  \int_{\Omega}
  (- \nu ( \frac{\partial^2 u}{\partial x^2} 
  + \frac{\partial^2 u}{\partial y^2}
  + \frac{\partial^2 u}{\partial z^2} ) 
  + u \frac{\partial u}{\partial x} 
  + v \frac{\partial u}{\partial y} 
  + w \frac{\partial u}{\partial z} 
  +   \frac{\partial p}{\partial x} ) \phi(x,y,z) \, d \Omega 
  \nonumber \\
%
  = \int_{\Omega} f(x,y,z) \phi(x,y,z) \, d \Omega
\end{eqnarray}

Another common problem is when you want to display several equations as
a unit, and you want to line them up, typically around the \textbf{=} sign.
For this, you can use the \textbf{eqnarray} environment with alignment.  
Here, each equation in the group will include a pair of ampersands around
the symbol or text that is to be vertically aligned.

\begin{eqnarray}
\label{equation-ns}
%
  - \Delta {\bf u} + Re ({\bf u} \cdot \nabla {\bf u} + \nabla p )  & = & 0 
  \nonumber \\
%
  \nabla \cdot {\bf u} & = & f(x,y)
%
\end{eqnarray}

\section{Boxing Things}
\label{section-boxing}

Sometimes it's nice to put a box around a word or a block of text to set
it off or emphasize it.  It's pretty easy to do this for a word; simply
use the \textbf{fbox} command.  However, this doesn't work well if the
thing you're putting a box around is too long to fit on one line.  So
\fbox{make sure it fits!}

To set off a block of text, you need to combine the \textbf{fbox} command
with the \textbf{minipage} environment, which requires that you specify
how wide you want your block of text to be.  You can specify this width
in inches, or use a symbolic value like \verb+\textwidth+.

\centerline{
  \fbox{
    \begin{minipage}{0.75 \textwidth}
      Here's some text which should show up with a box around it.  The
      box should be 3/4 as wide as the main text area.  
    \end{minipage}
  }
}

\section{Summary}
\label{section-summary}

This complex document has demonstrated a lot of material, without really
explaining it all.  You may well be able to understand what you need by
looking at the raw \LaTeX{} file, and comparing it to the final result.
If not, you can experiment, or refer to the references.
 
This concludes our overview of \LaTeX{}.

\begin{thebibliography}{99}

\bibitem{Graetzer}
George Gr\"atzer, 
\emph{Math into \LaTeX{}}, 
Birkh\"auser, 2000.

\bibitem{Kopka}
Helmut Kopka and Patrick Daly, 
\emph{A Guide to LaTeX2E{}}, 
Addison-Wesley, 1995.

%
%  In the following item, I want the web address to appear as a single
%  string without being broken up, so I put it in an MBOX.
%
\bibitem{Oetiker}
Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Shlegl, 
\emph{The Not So Short Introduction to \LaTeX2E{}},
\mbox{ftp://ctan.tug.org/tex-archive/info/lshort/english/lshort.pdf}.

\end{thebibliography}

\end{document}
