\documentclass[12pt]{article}
\usepackage[implicit=true,colorlinks=true]{hyperref}
\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[in, headings]{fullpage}
\usepackage{boxedminipage}

\title{MAE 301/501 Notes}
\author{Samson Chan (with significant editing)}
\date{April 14, 2009}
\begin{document}
\maketitle

\section{Introduction}

Today's class is a brief overview of \LaTeX, which is a flavor of \TeX.
\TeX was designed as a markup language to format documents which include
mathematics and other technical typesetting.  It is {\bf not} a word
processor like Microsoft Word.  You write your document in ordinary text,
using any editor (notepad, emacs, or even Word), and then run \LaTeX\  to
produce the document.  We'll use 
\href{http://www.xm1math.net/texmaker/}{\TeX{}maker} in class today.  This
is a free \LaTeX\  editor which integrates many of the tools needed to develop
\LaTeX\  documents and runs on Windows, MacOS, and Linux.  This combines the
editor with the \LaTeX\ tools and previewers so you can just hit a button to
produce the document.  

If you want to install \LaTeX\ on your computer, I suggest you
download \href{http://www.tug.org/protext}{pro\TeX{}t} if you use
Windows, or \href{http://www.tug.org/mactex}{mac\TeX} for MacOS.  If
you use Linux, there is almost certainly a \TeX\ distribution as a
standard package.  In all cases I would also recommend you install
\href{http://www.xm1math.net/texmaker/}{\TeX{}maker}.

\bigskip
Aside from enabling us to incorporate mathematics much easier than in Word
or a non-technical word processor, another big advantage of \LaTeX\  is that 
it separates the content of the document from much of the formatting
decisions. \LaTeX\  uses the idea of {\em styles} to make many of the decisions
about the way a document appears.  For example, you can write an exam so
that by changing one line, it produces either the 
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/Exam-example/exam.pdf}{exam}
or the 
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/Exam-example/examsols.pdf}{solutions}.
You can see the \LaTeX\ 
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/Exam-example/exam.tex} {source file}, although this exam uses many subsidiary files (there are lots of pictures); all of the necessary files are at 
%\\ \centerline{%
  \url{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/Exam-example/}.
%}
%
Some much less complicated examples are the notes for several of the
meetings of this class:

\begin{tabular}{|l|r|}
\hline 
February~17:
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/2009-02-17.pdf}{PDF} and
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/2009-02-17.tex}
{\LaTeX\ source} &
March~19: 
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/2009-03-19.pdf}{PDF} and
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/2009-03-19.tex}
{\LaTeX\ source},\\
\relax & (also needs 
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/}{other files})
 \\ \hline
February~19:
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/2009-02-19.pdf}{PDF} and
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/2009-02-19.tex}
{\LaTeX\ source} &
April 14 (what you are reading) and
\href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/2009-04-14.tex}
{\LaTeX\ source}, \\
\relax & (also needs 
     \href{http://www.math.sunysb.edu/~scott/mae501.spr09/notes/TeX/}{other files})
\\ \hline
\end{tabular}




\bigskip
While we will go over some of the basic ideas and features of \LaTeX\ here
today, if you are planning to use \LaTeX\ to prepare documents, you should
refer to 
some more complete introductions such as
\url{http://en.wikibooks.org/wiki/LaTeX} or
\url{http://www.math.harvard.edu/texman/} instead. Google can be 
\href{http://www.google.com/search?hl=en&q=latex+tutorial}{your friend}, too.

\bigskip
What follows is a summary of what we actually discussed during the class
(with a few additions).  You might find it useful, or not.  


\section{Some \LaTeX}
\subsection{Getting started}
All \LaTeX\ documents have a common format. (\TeX{}maker can create a
basic version of this for us from the ``Quick Start'' button).  Below
is an extremely simple, but complete, \LaTeX\ document

\begin{verbatim}
\documentclass[12pt]{article}
\begin{document}
Here is some text, with some math $\int_0^1 x^2 dx = \frac{1}{3}$.
\end{document}
\end{verbatim}
%
When typeset, we should see a page like

\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
Here is some text, with some math $\int_0^1 x^2 dx = \frac{1}{3}$.
\\[.25in]\end{boxedminipage}\end{center}


We should first note that in \TeX, anything beginning with a backslash
($\backslash$) is a command. Curly braces (\{\ \}) are used for
grouping, much like parentheses in mathematics.  These usually
surround arguments to the commands, but are also used in other
contexts as well.  The square brackets are typically used for optional
arguments to the \LaTeX\ command.

In the example above, the first line
(\verb+\documentclass[12pt]{article}+) identifies that this document
is of the type \verb+article+, a very common type for a short note.
The optional argument \verb+[12pt]+ tells \LaTeX\ that we'd like to
use 12-point type, slightly larger than the usual default of 10-point
type.

The actual body of the document comes between \verb+\begin{document}+
and \verb+\end{document}+.  In this very short example, we have only
the one line of text.

The area between the \verb+\documentclass+ line and the
\verb+\begin{document}+ statement is called the {\it preamble} of the
document.   It is in this section that we include references to other
packages and commands which modify the overall look of the document.  I will
refer to this section several times below.

\subsection{Mathematics}
Mathematics is typeset differently that ordinary text, and
\TeX\ requires us to surround things we want to treat as math by
dollar signs (\$).  Certain command sequences (like \verb+\int+ for an
integral or \verb+\frac+ for a fraction) only make sense in math mode,
and will give an error if you use them in ordinary text.

There are ten characters which \TeX\ treats specially; we've seen
some of these already.  Here they all are:
\verb+ # $ % & ~ _ ^ \ { }+.  If you want to typeset one of these, you
need to treat it specially. 

Back to our example, sometimes we want to insert mathematics in the
ordinary flow of our text, for example if we want to say something
like ``if $x$ is a real number, then $x^2$ cannot be negative''.  But
sometimes we want to set off the mathematics on its own line; this is
called a ``displayed formula''.  This is indicated by using either
double dollar signs around the math mode, or surrounding it by
\verb+\[+ and \verb+\]+.

If we change our sample document to look like
\begin{verbatim}
\documentclass[12pt]{article}
\begin{document}
Here is some text, with some math \[ \int_0^1 x^2 dx = \frac{1}{3}.\]
\end{document}
\end{verbatim}
%
we get
\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
Here is some text, with some math \[ \int_0^1 x^2 dx = \frac{1}{3}.\]
\\[.25in]\end{boxedminipage}\end{center}


Math in display mode takes up more space than inline math, so, for
example, the limits of integration on an integral are placed
differently when the integral appears inline and as a display.

\subsection{Labels and references}\label{labelSection}
In some cases, we want to number our equations.  In this case, we
would use something like
\begin{verbatim}
\begin {equation}
\sum^{\infty}_{i=1} a_i x^i
\end {equation}
\end{verbatim}

which produces
\begin {equation} \label{first}
\sum^{\infty}_{i=1} a_i x^i
\end {equation}

However, usually we number the equation so that we can refer to it
elsewhere.  \LaTeX\ allows us to refer to these numbers by a symbolic
name, so that if the numbering changes, we don't have to update our
document.  This is done by inserting a \verb+\label+ inside the
equation environment, and then refering to that label using
\verb+\ref+.  For example, 

\begin{verbatim}
\begin {equation} \label{bSeries}
\sum^{\infty}_{i=1} b_i x^i
\end {equation}
The series of interest appears in (\ref{bSeries}).
\end{verbatim}
%
yielding
%
\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
\begin {equation} \label{bSeries}
\sum^{\infty}_{i=1} b_i x^i
\end {equation}
The series of interest appears in (\ref{bSeries}).  
\end{boxedminipage}\end{center}
%
\LaTeX\ calculates the
labels for us, so if we insert additional equations, we don't need to
renumber things.  If you see ({\bf ??}) where your reference should be, you 
just need to run \LaTeX\ again.
\medskip

In addition, we can label other things.  For example, at the start of the
current subsection, I typed 
\begin{verbatim}
\subsection{Labels and references}\label{labelSection}
\end{verbatim}
This means I can refer to this section as ``section~\ref{labelSection}''
by typing \verb+section~\ref{labelSection}+.

Refering to items in a bibliography is done by a similar process,
using \verb+\cite+ and \verb+\bibitem+, but I won't discuss them here.

Finally, you might wonder why my references are colored and act as
hyperlinks.  This is because I put
\begin{verbatim}
\usepackage[implicit=true,colorlinks=true]{hyperref}
\end{verbatim}
in the preamble (before the \verb+\begin{document}+ statement)
in these notes, which turns references into hyperlinks.  More detailed
discussion of the \verb+hyperref+ package can be found at 
\url{http://www.tug.org/applications/hyperref/manual.html}.


\subsection{Multi-line equations and alignment}
If we wanted to typeset a multi-line equation, we could use the
\verb+gather+ environment.  However, often you not only want several lines,
but you want to align them in certain places.  For that we use
the \verb+amsmath+ package and the \verb+aligned+ environment:

\begin{verbatim}
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
We have 
\[
\begin{aligned}
\frac{dS}{d\zeta}&= \frac{1}{2\pi i}  \int_{S_r} \frac{1} {z-\zeta}\frac{dz}{z}\\[5pt]
&= \frac{1}{2\pi i}  \int_{S_r} 
        \left(\frac{1/\zeta} {z-\zeta}-\frac{1/\zeta}{z}\right)dz\\[5pt]
&=0.
\end{aligned}
\]
\end{document}
\end{verbatim}
%
which looks like
\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
We have 
\[
\begin{aligned}
\frac{dS}{d\zeta}&= \frac{1}{2\pi i}  \int_{S_r} \frac{1} {z-\zeta}\frac{dz}{z}\\[5pt]
&= \frac{1}{2\pi i}  \int_{S_r} 
        \left(\frac{1/\zeta} {z-\zeta}-\frac{1/\zeta}{z}\right)dz \\[5pt]
&=0.
\end{aligned}
\]
\\[.25in]\end{boxedminipage}\end{center}

Here, the \verb+\\+ is used to indicate that the line should be broken
there, and 
we indicated that some extra space should be inserted with the
\verb+[5pt]+ option.  In the \verb+aligned+ environment (and some
others), the ampersand (\verb+&+) is used to indicate where the lines
should match up.  We could use multiple alignments on each line, if we
wanted to, but in this case it wasn't necessary.  

\bigskip
Below is an example with multiple points of alignment.
\goodbreak

\begin{verbatim}
We want to solve $x^2 -1 = 0$. Thus,
\[\begin{aligned}
      &&    x^2 - 1 &= 0   &&   \\
      &&  (x+1)(x-1)&= 0   &&   \\
 x+1&=0&       \text{or} &&    x-1&=0 \\
  x&=-1&       \text{or} &&      x&=1 \\
\end{aligned}\]
\end{verbatim}

\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
We want to solve $x^2 -1 = 0$. Thus,
\[\begin{aligned} 
      &&    x^2 - 1 &= 0   &&   \\
      &&  (x+1)(x-1)&= 0   &&   \\
 x+1&=0&       \text{or} &&    x-1&=0 \\
  x&=-1&       \text{or} &&      x&=1 \\[.1in]
\end{aligned}\]
\end{boxedminipage}\end{center}

\subsection{Macros}
\newcommand{\R}{\ensuremath{\mathbb R}}

One very useful thing in \TeX\ is the ability to define your own command
sequences.  Doing this can make your document much easier to type, and 
make the \LaTeX\ source more readable.  For example, to typeset the usual
notation for the real numbers (\R), we would use
\verb+$\mathbb R$+.  Besides being a little unwieldy to type, it is hard to
read in a statement like 

\begin{verbatim}
We have the function $f:{\mathbb R}^2\rightarrow{\mathbb R}^2$.
\end{verbatim}
I usually insert the line
\begin{verbatim}
\newcommand{\R}{\ensuremath{\mathbb R}}
\end{verbatim}
(along with several similar lines) in the preamble so
that I can just type \verb+\R+ to get \R.  The \verb+\ensuremath+ will
switch into math mode if the command is invoked outside of math mode, but
won't do anything in math mode, so that I can also type \verb+$\R^2$+ to get 
$\R^2$.  One can create much more elaborate macros with \verb+\newcommand+,
but that's enough for now.

\subsection{Graphics}
Often we want to insert pictures into our documents.  This is easiest to do
using the \verb+graphicx+ package in \LaTeX.  This lets us include graphics
in several formats, although if you are using pdf\LaTeX, you probably want
to use PDF graphics.

For example, we produced a graph of the sine function in Maple, and exported
it as an EPS file and converted it to PDF (Maple won't write PDF files
directly, but conversion is easy).  Doing something like the following

\begin{verbatim}
\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
Here is a graph of $\sin(x)$:
\begin{center}\includegraphics[height=2in]{sin.pdf}\end{center}
\end{document}
\end{verbatim}

will give us
\begin{center}\begin{boxedminipage}{5in}\vspace{.25in}
Here is a graph of $\sin(x)$:
\begin{center}\includegraphics[height=2in]{sin.pdf}\end{center}
\end{boxedminipage}\end{center}

I specified the desired height of the figure (I could specify the width if I
prefered.) 

\subsection{Minipages}
Sometimes you want to typeset two (or more) paragraphs side by side. This is
done with the \verb+minipage+ environment. For example, to produce the
following

\bigskip
\begin{minipage}{4.5in}
Euler's identity (right) relates the five most important numbers (0, 1, $e$,
$i$, and $\pi$), and has been described as one of the most 
beautiful formulae in all of mathematics.
\end{minipage}
\quad
\begin{boxedminipage}{1.25in}
\[
 e^{i\pi} - 1 = 0
\]
\smallskip
\end{boxedminipage}

\bigskip\noindent
I used

\begin{verbatim}
\begin{minipage}{4.5in}
Euler's identity (right) relates the five most important numbers 
(0, 1, $e$, $i$, and $\pi$), and has been described as
one of the most beautiful formulae in
all of mathematics.
\end{minipage}
\quad
\begin{boxedminipage}{1.25in}
\[
 e^{i\pi} - 1 = 0
\]
\smallskip
\end{boxedminipage}
\end{verbatim}

A minipage is a section of your document that is typeset like a page on its
own, and inserted like a big character.  While the previous example is
fairly contrived, minipages are particularly useful for putting pictures or
tables next to some text, or several pictures side-by-side.  For example,

\begin{center}\begin{boxedminipage}{5in} %\vspace{.25in}
\begin{minipage}{2.5in}
At right is a picture of a sign pointing out a fact that is 
ignored all too often.
\end{minipage}\qquad
\begin{minipage}{2in}
\includegraphics[width=2in]{alcohol-impairs.jpg}
\end{minipage}
\end{boxedminipage}\end{center}

I used
\begin{verbatim}
\begin{minipage}{2.5in}
At right is a picture of a sign pointing out a fact that is 
ignored all too often.
\end{minipage}\qquad
\begin{minipage}{2in}
\includegraphics[width=2in]{alcohol-impairs.jpg}
\end{minipage}
\end{verbatim}

(Actually, all of the samples in this document are inside a
\verb+boxedminipage+ environment, which puts a minipage inside a box.)

\section{KThnxBye!}
That should be enough information to get you going.  But the best way to use
\LaTeX\ is just to start.  Take an existing document that does some of what
you want, and just start going with it.  You will certainly get some error
messages, but when you do, don't just give up.  It will be worth it in the
end.

\end{document}
