\documentclass[20pt,dvips,footrule]{foils}
% \usepackage{lucidbry}
\usepackage{amsmath}
\usepackage{epsfig}
\usepackage{graphicx}

\usepackage{alltt}

\newcommand{\bs}{\backslash}
\newcommand{\xbar}{\ensuremath{\bar{x}}}
\newcommand{\silly}[2]{\ensuremath{f(#1 + 2, #2 - 2)}}
\newcommand{\boldw}{{\mathbf{w}}}
\newcommand{\boldW}{{\mathbf{W}}}
\newcommand{\boldv}{{\mathbf{v}}}
\newcommand{\boldV}{{\mathbf{V}}}
\newcommand{\bolds}{{\mathbf{s}}}
\newcommand{\boldY}{{\mathbf{Y}}}
\newcommand{\boldX}{{\mathbf{X}}}
\newcommand{\boldZ}{{\mathbf{Z}}}
\newcommand{\boldc}{{\mathbf{c}}}
\newcommand{\boldd}{{\mathbf{d}}}
\newcommand{\bolde}{{\mathbf{e}}}
\newcommand{\boldC}{{\mathbf{C}}}
\newcommand{\boldD}{{\mathbf{D}}}
\newcommand{\boldE}{{\mathbf{E}}}
\newcommand{\boldm}{{\mathbf{m}}}
\newcommand{\boldp}{{\mathbf{p}}}
\newcommand{\boldq}{{\mathbf{q}}}
\newcommand{\boldr}{{\mathbf{r}}}
\newcommand{\boldP}{{\mathbf{P}}}
\newcommand{\boldQ}{{\mathbf{Q}}}
\newcommand{\boldR}{{\mathbf{R}}}
\newcommand{\boldO}{{\mathbf{0}}}
\newcommand{\boldK}{{\mathbf{K}}}
\newcommand{\boldA}{{\mathbf{A}}}
\newcommand{\boldcA}{{\boldsymbol{\mathcal A}}}
\newcommand{\boldcW}{{\boldsymbol{\mathcal W}}}
\newcommand{\boldcX}{{\boldsymbol{\mathcal X}}}
\newcommand{\boldcZ}{{\boldsymbol{\mathcal Z}}}
\newcommand{\bolddelta}{{\boldsymbol{\delta}}}
\newcommand{\boldepsilon}{{\boldsymbol{\epsilon}}}
\newcommand{\boldmu}{{\boldsymbol{\mu}}}
\newcommand{\boldnu}{{\boldsymbol{\nu}}}
\newcommand{\boldSigma}{{\boldsymbol{\Sigma}}}
\newcommand{\matlab}{{\tt MATLAB}}


\title{Introduction to \LaTeX}
\author{Mark E. Irwin \\
          Department of Statistics \\
          Harvard University}

\date{Thursday, November 20, 2003}

\MyLogo{Introduction to \LaTeX}

\begin{document}

\maketitle
\begin{abstract}
This class will discuss the use of \LaTeX, the most common
approach to writing papers in Science, particularly in the
Mathematical and Physical Sciences.
\end{abstract}


\foilhead{What is \TeX?}

\begin{quote}
\TeX\ represents the state-of-the-art in computer typesetting. It
is particularly valuable where the document, article, or book to
be produced contains a lot of mathematics, and where the user is
concerned about typographic quality.  \TeX\ software offers both
writers and publishers the opportunity to produce technical text,
in an attractive form, with the speed and efficiency of a computer
system.

(from the back cover of The \TeX book by Donald E. Knuth, the
initial developer of \TeX)

\end{quote}

Most of what is done today is not in plain \TeX, but with addon
macro packages.  Parts of \TeX\ tend to be cryptic, so these
addons have been created to make things easier.  The most popular
of these addons is \LaTeX.  Others you might come across are
AMS-\TeX and AMS-\LaTeX.

\foilhead{What is \LaTeX?}

\LaTeX\ is a document preparation system based on the \TeX\
formatter.  It is a set of macros which simplifies much of plain
\TeX. \LaTeX\ is the most popular approach to writing papers in
Science, particularly in Mathematics and Physical Sciences.  Much
publishing today is done in \LaTeX\.  I believe everything
published by Springer-Verlag, is prepared in \LaTeX.  Many
journals have also gone the \LaTeX\ route as well, with packages
prepared to assist with matching the journal format.

The most current version commonly available is \LaTeXe, though
\LaTeX3 is currently in development.  The previous version was
\LaTeX\ 2.09, which is quite a bit different.  While files written
in this version will run in \LaTeXe\ (usually), you want to stick
with \LaTeXe\ for your writing.

\LaTeX, and all \TeX\ derivatives are page markup languages, with
formatting commands mixed in with the text, similar to HTML.  It
is not a WYSIWYG approach, like Microsoft Word, though there are
products that try to bring this to the \LaTeX\ world.

A \LaTeX\ file, is a plain text file which is then processed to
give the desired output.  The output is usually in a {\tt .dvi}
file, which then can be converted to other formats, such as
postscript or pdf, if desired.

This approach to preparing documents allows for great flexibility
and many things to be automated.  These include

\begin{itemize}
\item Pagination

\item Equation numbering

\item Creation of tables of contents, list of figures, etc

\item Bibliography creation and proper citation in the text

\item Changing fonts and font sizes

\end{itemize}

\foilhead{How to Learn \LaTeX?}

While checking manuals, online searches, etc can be helpful, the
way most people learn \LaTeX\ is to see other \LaTeX files.  In
addition to these overheads, I will make available the \LaTeX\
file for this document, plus others, so you can see how things
work.

Even if you think you know how to do something, many things can be
done many ways, so it can be interesting to see how other people
will approach a problem.

For example \texttt{$\bs$textit\{italic\}} and {\texttt{\{$\bs$it
italic\}} will both italicize the word \textit{italic}.


\foilhead{Example \LaTeX file}

\begin{verbatim}
\documentclass[11pt]{article}
% define the title
\author{H. ~Partl}
\title{Minimalism}
\begin{document}
% generate the title
\maketitle
% insert the table of contents
\tableofcontents
\section{Some interesting words}
Well, and here begins my lovely article.
\section{Good Bye World}
\ldots{} and here it ends.
\end{document}

\end{verbatim}

\foilhead{Typical \LaTeX\ session}

\begin{enumerate}
\item Edit/Create your \LaTeX input file.  This file must be plain
ASCII text.  In addition, the file name must in in {\tt .tex}

\item Run \LaTeX\ on your input file.  It may be necessary to run
\LaTeX\ more than once to get the table of contents, table
numbers, citations, etc correct.  If there is a bug in your input
file, you will get an error message and processing will stop.  If
there are no errors you will get a {\tt .dvi} file.

In Unix, you can process your document with a command such as {\tt
latex foo.tex}.

\newpage
\item Viewing the {\tt .dvi} file.  There are a number of ways to
do this.  In Unix (under X windows), the file can be display on
your screen with {\tt xdvi foo.dvi \&}.  In Windows, you can use
the program {\tt yap}.  You can convert the file to postscript
with {\tt dvips foo.dvi -o foo.ps} or print it with {\tt dvips
foo.dvi} in Unix.  It can be converted to pdf with {\tt dvipdf
foo.dvi}.
\end{enumerate}

These three steps will be required regardless of your computer
setup, however how they are implemented can very greatly.  For
example, many people in the Unix world will often run \LaTeX from
within an {\tt emacs} session, where the approach is a bit more
unified.  However others tend to work from the command line. Also,
the {\tt emacs} setup can also be used in a Windows or Macintosh
setup, though I think these are less common.

\foilhead{Document Layout}

\begin{enumerate}
\item Document Classes.

\LaTeX\ needs to what type document is to be created.  This is
specified with the {\tt documentclass} command.

\framebox{\tt $\bs$documentclass[{\it options}]\{{\it class}\}}

{\it class} specifies the type of document to be created.  Common
choices are {\tt article}, {\tt report}, {\tt book}, and {\tt
slides}. These slides were created with {\tt foils}, a different
set of macros for preparing slides.  Note foils is not in the
standard \LaTeX\ installations, but can downloaded via CTAN. I'll
look into having Patrick install it on our Unix system.

The {\it options} parameter customize the behaviour of the
document class.  The options need to be separated by commas.
Popular options are {\tt 10pt}, {\tt 12pt}, {\tt onecolumn}, and
{\tt landscape}.

\item Packages

When preparing your document, you may find that there are things
you would like to do which aren't available in the default \LaTeX\
setup.  If you want to include graphics, add color, or include
source code from a file into your document, you will need to
enhance your setup.  These enhancements are known as packages and
can be activated with the

\framebox{\tt $\bs$usepackage[{\it options}]\{{\it class}\}}

For example, to typeset the document using Times-Roman instead of
the standard Computer Modern font, add the command

\begin{verbatim}
\usepackage{times}
\end{verbatim}

Note how a package acts may depend on the document style being
used.  For example, the above would actually make this document be
typeset in Helvetica, not Times (it a quirk of {\tt foils} is
designed). However for {\tt article}, {\tt report}, etc, you would
get times.

\item Page Styles

\LaTeX\ supports three different page styles (header/footer)
combinations.  The \textit{style} parameter of the command

\framebox{\tt $\bs$pagestyle\{{\it style}\}}

defines which to use.  The choices are {\tt plain} (page number at
the bottom of the page in the middle of the footer), {\tt heading}
(prints current chapter heading and the page number in the header,
while the footer remains empty), and {\tt empty} (both header and
footer are empty).

To change it only for the current page, use the command

\framebox{\tt $\bs$thispagestyle\{{\it style}\}}

To do more complicated things,  see either The \LaTeX\ Companion
or The Not so Short Introduction to \LaTeX2e\ (available on the
course web site).

\end{enumerate}

\foilhead{Document Structure - Sectioning}

For most document styles, documents are divided using the
different sectioning commands.  The standard ones are
\begin{verbatim}
  \part      \subsection      \paragraph
  \chapter   \subsubsection   \subparagraph
  \section
\end{verbatim}
The {\tt article} class doesn't contain the \verb+\chapter+
command. However this makes it easy to include an ``article'' as a
chapter of a ''report'' or ``book''.

The form of these commands is similar to \verb+\section{Example+
\verb+Section}+.

With this approach, it is easy to have your chapter, sections,
subsections, etc, to be automatically numbered.  For articles,
number is of the form Section 2, Subsection 3.4, Subsubsection
3.1.5.  For books and reports, the form is Chapter 3, Section 4.2,
etc.

If you want to have an unnumbered subsection, for example, you
need to add a {\tt *} to the command, such as
\verb+\subsection*{Unnumbered+ \verb+subsection}+.  Adding a {\tt
*} to the end of a command that deals with numbering, will often
remove that numbering from the object.

You can keep track off section numbers you use elsewhere in the
text with \verb+\label{+{\it keystring}\verb+}+ command.  To refer
to a stored label, use the \verb+\ref{+{\it keystring}\verb+}+ and
its page number with \verb+\pageref{+{\it keystring}\verb+}+
command.  These commands are particularly useful with equations.


\foilhead{Preparing and Input File}

As mentioned before, your input file should be a plain ASCII text
files with a filename ending with {\tt .tex}.  Only the standard
character set, numbers, and punctuation characters
\begin{center}
\verb+ . : ; , ? ! ` ' ( ) [ ] - / * @+
\end{center}
should be used.

There are 10 special characters
\begin{center}
\verb+# $ % & ~ _ ^ \ { }+
\end{center}
that are only used in \LaTeX\ commands.  For example \% initiates
a comment, \$ is used to indicate mathematics, and $\bs$ indicates
a command.

The characters \verb. + = | < >. are mainly used in mathematical
formulas, though + and = can be used in ordinary text.  Most of
the special characters can be included in text by preceding it
with a $\bs$.  For example {\tt $\bs$\$} will give a \$.

When entering text, the ends of words and sentences are marked by
spaces.  It doesn't matter how many spaces you leave when you
type; 100 spaces acts the same as 1.

To indicate a new paragraph, leave one or more blank lines before
the next paragraph.

\foilhead{Fonts}

\begin{table}[h]
\centering { \small
\begin{tabular}{lll}
Style & Approach 1 & Approach 2 \\
{\it italics} & {\tt \{$\bs$it italics\}} & {\tt $\bs$textit\{italics\}} \\
{\it slanted} & {\tt \{$\bs$sl slanted\}} & {\tt $\bs$textsl\{slanted\}} \\
{\bf boldface} & {\tt \{$\bs$bf boldface\}} & {\tt $\bs$textbf\{boldface\}} \\
{\tt typewriter} & {\tt \{$\bs$tt typewriter\}} & {\tt $\bs$textt\{typewriter\}} \\
{\rm roman} & {\tt \{$\bs$rm roman\}} & {\tt $\bs$textrm\{roman\}} \\
{\sc small caps} & {\tt \{$\bs$sc small caps\}} & {\tt
$\bs$textsc\{small caps\}}
\end{tabular}
} \caption{Font styles}
\end{table}

\begin{table}[h]
\centering { \small
\begin{tabular}{ll}
Size & Approach\\
{\tiny tiny} & {\tt \{$\bs$tiny tiny\}}  \\
{\scriptsize scriptsize} & {\tt \{$\bs$scriptsize scriptsize\}}  \\
{\footnotesize footnotesize} & {\tt \{$\bs$footnotesize footnotesize\}}  \\
{\small small} & {\tt \{$\bs$small small\}}  \\
{\normalsize normalsize} & {\tt \{$\bs$normalsize normalsize\}}  \\
{\large large} & {\tt \{$\bs$large large\}}  \\
{\Large Large} & {\tt \{$\bs$Large Large\}}  \\
{\huge huge} & {\tt \{$\bs$huge huge\}}  \\
{\Huge Huge} & {\tt \{$\bs$Huge Huge\}}  \\
\end{tabular} }
\caption{Font sizes}
\end{table}

\foilhead{Braces, Environments, and Delimeters}

In \LaTeX, braces \{ and \} are used to indicate pieces of text
that are to be treated in a certain way.  For example on the
previous page, construction like {\tt \{$\bs$Large match your
braces\}} were used to indicate a piece of text is to be displayed
in the {\tt Large} font size.  Missing the closing \}, could lead
to the rest of the document being created in the {\tt Large} font,
or more likely an error message when being processed. You have to
make sure your braces match.

This also occurs with other \LaTeX constructs.  For example,
in-line math formulas are usually indicated with {\tt \$ ... \$}.
If the closing {\tt \$} is missing you will usually get an error
message.  The other common situation where you need to be careful
is with \LaTeX environments, which are indicated with {\tt
$\bs$begin\{\} ... $\bs$end\{\}}.  Enviroments are used in many
situations, such as equations, lists, tables, figures, quotes, and
so on.

\newpage
Also when dealing with these sorts of constructs, you need to deal
with them in a LIFO (Last In, First Out) type approach.  For
example {\verb+{ $ \alpha } $+ probably will return an error
message, where {\verb+{ $ \alpha $ }+ will work fine, displaying
the greek letter $\alpha$.

These sorts of problems are probably the second most common errors
in \LaTeX, following omitting a backslash for a command.  For
example, typing {\verb+$bar{x}$+ instead of \verb+$\bar{x}$+,
which will lead to $bar{x}$, instead of displaying $\bar{x}$.


\foilhead{Mathematical Formulas}

All mathematical typesetting is done through one of the math
modes, {\tt math}, {\tt displaymath}, and {\tt equation}.  These
are used for \emph{in-text} formulas, unnumbered display
equations, and numbered display equations.

Math mode is usually indicated by \texttt{\$ ... \$}.  For example
the code
\begin{verbatim}
  The equation $\alpha + \beta = \gamma$
  is just for example.
\end{verbatim}
gives the output ``The equation $\alpha + \beta = \gamma$ is just
for example''.

\newpage
The other 2 environments deal with display equations.  Examples of
each are are
\begin{verbatim}
  \begin{equation}
  g(s, t; X_{t}) = \int \delta(r_{s,w})
  f(w|s, X_t)dw;~s \in D
  \end{equation}

  \begin{displaymath}
  g(s, t; X_{t}) = \int \delta(r_{s,w})
  f(w|s, X_t)dw;~s \in D
  \end{displaymath}
\end{verbatim}
These give the following output

\begin{equation}
g(s, t;X_{t}) = \int \delta(r_{s,w}) f(w|s, X_t)dw;~s \in D
\end{equation}

\begin{displaymath}
g(s, t;X_{t}) = \int \delta(r_{s,w}) f(w|s, X_t)dw;~s \in D
\end{displaymath}

\newpage
Note that the {\tt displaymath} environment can also be indicated
with \verb+\+{\tt begin\{equation*\} ... } \verb+\+{\tt
end\{equation*\}} or with the even easier \verb+$$ ... $$+

The {\tt displaymath} and {\tt equation} environments are designed
for one-line formulas.  For multiline formulas, you need to use
the {\tt eqnarray} and {\tt align} environments. For example
\begin{verbatim}
  \begin{eqnarray*}
  y & = & \int_a^b (f(x) + g(x))dx \\
    & = & \int_a^b f(x)dx + C
  \end{eqnarray*}
\end{verbatim}
gives
\begin{eqnarray*}
y & = & \int_a^b (f(x) + g(x))dx \\
  & = & \int_a^b f(x)dx + C
\end{eqnarray*}

\foilhead{Math Symbols}

There is a wide arrange of symbols available in \LaTeX. I suggest
checking any of the suggested reference on the web site. One
useful is at {\tt <http://www.agu.org/symbols.html>}.

Many of them are obvious, where a \verb+\+ proceeds the name, e.g.
\verb+\theta+ or \verb+\div+.  However some are a bit cryptic,
e.g. \verb+\pm+ for $\pm$.

A common convention in mathematical typesetting, is for functions
like {\tt log, sin, min} to in roman text, not italized.  For
these sorts of functions, adding a \verb+\+ to the command stops
the function name from begin italized.  For example
\verb+$\exp(x)$+ gives $\exp(x)$, whereas, \verb+$exp(x)$+ gives
$exp(x)$.

\foilhead{Common Structures}

\noindent {\bf Subscripts and Superscripts}
\newline
Subscripts and superscripts are made with the {\_} and
{\^~}commands.  These can be combined to make complicated
structures
\begin{table}
\begin{center}
\begin{tabular}{llll}
$x^{2y}$ & \verb+x^{2y}+ & $x^{y^2}$ & \verb+x^{y^2}+ \\
$x_{2y}$ & \verb+x_{2y}+ & $x_2^y$ & \verb+x_2^y+
\end{tabular}
\end{center}
\end{table}

\noindent {\bf Fractions}
\newline
Fractions can either be denoted with / with the \verb+\frac+
command.  For example \verb+$a/b$+ gives $a/b$ where as
\verb+\frac{a}{b}+ gives
$$
\frac{a}{b}.
$$
The \verb+\frac+ command can be used inline, but it tends not to
be.

\noindent {\bf Roots}
\newline
Roots are indicated with the \verb+\sqrt+ command.  A square root
is indicated with \verb+\sqrt{x*y}+ ($\sqrt{x*y}$) and an $n^{th}$
root with \verb+\sqrt[n]{3}+ ($\sqrt[n]{3}$).

\noindent {\bf Summation, Integrals, Products, ...}
\newline
The commands for these functions have the property that they they
adjust there size, depending on the formula.  The basic structure
is of the form
\begin{verbatim}
  \begin{equation}
  \frac{\pi^2}{8} = \sum_{k=1}^{\infty}
                         \frac{1}{(2k-1)^2}
  \end{equation}
\end{verbatim}
which gives
\begin{equation}
  \frac{\pi^2}{8} = \sum_{k=1}^{\infty} \frac{1}{(2k-1)^2}
\end{equation}


For integration use {\tt int}, products use {\tt prod}, unions
($\bigcup$) use {\tt bigcup}, intersections ($\bigcap$), use {\tt
bigcap}, etc.

\foilhead{Defining commands}

A useful feature in \LaTeX is the ability to define commands.
These are often used to create custom shortcuts for your commonly
used commands.    To do this use the \verb+\newcommand+ command.
Its first argument is the command name and the second argument
isthe command text.  For example to create a command for \xbar,
you could use
\begin{verbatim}
  \newcommand{\xbar}{\ensuremath{\bar{x}}}
\end{verbatim}

It is possible to create more complicated commands, such as ones
that take arguments.  An example, albeit silly is
\begin{verbatim}
  \newcommand{\silly}[2]
     {\ensuremath{f(#1 + 2, #2 - 2)}}
\end{verbatim}
for which \verb+\silly{2x}{z}+ gives \silly{2x}{z}.

You need to be a bit careful in naming your new commands.  You
don't want them to start with the names of built in commands.

\foilhead{Adding Graphics}

While there are many ways of adding graphics to a \LaTeX\
document, probably the most popular way currently is with the {\tt
graphicx} package, which I believe is now part of most standard
\LaTeX\ installations.  To use it, you just need to give the
command \verb+\usepackage{graphicx}+.

This is particularly useful with postscript graphics created by
either {\tt S-Plus/R} or \matlab.  I believe that the package will
handle other graphics format such as tiff, but I've never used
anything but encapsulated postscript.

The base command is

\framebox{\tt $\bs$includegraphics[{\it key=value, ...}]\{{\it
file}\}}}

The important {\it keys} are {\tt width}, {\tt height}, {\tt
angle}, and {\tt scale}.

\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.8]{rbox.ps}
\caption{\label{fig:rbox}Boxplot of Petal Width generated by R}
\end{center}
\end{figure}

{
\begin{verbatim}
  \begin{figure}[ht]
  \begin{center}
  \includegraphics*[scale=0.8]{rbox.ps}
  \caption{\label{fig:rbox}
  Boxplot of Petal Width generated by R}
  \end{center}
  \end{figure}
\end{verbatim}
}

\end{document}
