% This is an example of how to use LaTeX.
% It is based on a version Tom LoFaro developed for MCS-220 in 2009.
% This version is for Max Hailperin's MCS-236 in 2011.
% Anything after a percent sign is a comment.
%The next line defines the type of document; I specified one option, the 11pt primary font size.
\documentclass[11pt]{article}
% The part of the tex file between the documentclass and \begin{document} lines is
% called the preamble. Commands to set up the document appear in the preamble.
% You can probably use the same preamble as in this sample document, except
% that you will change the title and author.
\title{Introduction to \LaTeX\ for MCS-236}
\author{Max Hailperin, based on a version by Tom LoFaro}
% These packages from the American Mathematical Society often come in handy:
\usepackage{amssymb, amsmath}
% I've defined a bunch of theorem-like environments here; you'll probably only ever
% use a few of them.
\newtheorem{prop}{Proposition}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}
\newtheorem{corollary}{Corollary}
\newtheorem{terminology}{Terminology}
\newtheorem{notation}{Notation}
\newtheorem{exercise}{Exercise}
\newtheorem{note}{Note}
\newtheorem{comment}{Comment}
\newtheorem{claim}{Claim}
% The next mess defines an environment for proofs.
\newenvironment{proofhelper}[1]%
{\begin{trivlist}\item\textbf{Proof.}#1\quad\ignorespaces}%
{\hfill\rule{1ex}{1ex}\end{trivlist}}
\newenvironment{proof}%
{\begin{proofhelper}{}}%
{\end{proofhelper}}
% The following is a variant for when the method of proof is indicated.
\newenvironment{proofmethod}[1]%
{\begin{proofhelper}{ [#1]}}%
{\end{proofhelper}}
% Below I define some shortcuts for some common symbols.
\newcommand{\R}{\mathbf{R}} % boldface R for the real numbers
\newcommand{\Z}{\mathbf{Z}} % boldface Z for the integers
\newcommand{\Q}{\mathbf{Q}} % boldface Q for the rational numbers
\begin{document}
\maketitle
\section{Why \LaTeX?}\label{intro-section}
{\LaTeX} is a very strange document formatting system. Actually, it is a combination of two layers. The fundamental layer is called {\TeX}. It is essentially a compiler for a specialized programming language. You write a program for generating your document and run it through the compiler; out comes your document, ready to view or print. The {\LaTeX} system was built on top of {\TeX}. It is a carefully constructed library of predefined {\TeX} procedures, so that you can write your document-program more readily.
Like every piece of software, {\LaTeX} has its advantages and disadvantages, which depend on the purpose you have in mind. For a lot of document preparation purposes, other software might be more suitable. I certainly wouldn't recommend that you design a concert poster using {\LaTeX}. But for mathematical text, {\LaTeX} has no equal. It takes getting used to initially, but that effort is rewarded by all the details it takes care of for you. For example, consider an equation like
$2+x=3$. In properly formatted math text, the variable $x$ is italic, but the digits and other symbols aren't. Also, although this may not be obvious to you, the spacing around the equal sign is a bit bigger than the spacing around the plus sign. When you use {\LaTeX}, all of these issues are taken care of for you.
To an extremely good first approximation, every professional mathematician uses {\LaTeX} (or some other version of {\TeX}). So does every theoretical computer scientist and even most non-theoretical computer scientists in academic institutions and industrial research centers. So do lots of physicists. And so will you.
\section{Getting {\LaTeX}}
We have {\LaTeX} on all of the computers in the lab so you can always work there. If you want, you can also download it as free software. I've got the links on the course web page. For Windows and Linux systems, I recommend you use the TeX Live distribution, whereas under Mac OS X, you are better off with Mac TeX.
The easiest way to use {\LaTeX} is in an integrated environment that lets you edit your source file, compile it, and view the result. No matter whether you use Linux, Windows, or Mac OS X, one good option is to use TeXworks. Under Mac OS X, there is a slightly slicker option called TeXShop; whether you use it or TeXworks is likely to depend on whether you want to move seamlessly between operating systems. Both applications are included in Mac TeX. Only TeXworks is included in TeX Live.
If you have any questions about installing any of this software see Aaron Nienow, who manages the MCS Department computer resources. I can also try to help.
\section{Using \LaTeX}
\subsection{Basics}
As indicated in Section~\ref{intro-section}, you write your {\LaTeX} document as a source file in a specialized programming language and then run it through a compiler. The source file has a name ending in \verb|.tex| and compiling it normally produces a corresponding \verb|.pdf| file. I am providing this document to you in both forms, so that you can compare the two. You can see what source constructs are used to produce each visual result. You also can copy and paste from the source file as a starting point for your own documents. I'll provide other documents throughout the course in the same dual form for the same reason.
Lots of the features I use in the document, I don't explain. Moreover, there are lots of features I don't use, even though some of them will prove useful at some point in the semester. Sometimes it will surely feel like I am telling you enough to be confusing but too little to be helpful. Please be patient with me. Ask me lots of questions. If you email me a question, I can send the reply to the whole class, so that everyone benefits. You can also find lots of information on the web, as well as in the books in our lab. Last but not least, I would encourage you to help each other.
Every {\LaTeX} document begins with a \verb|\documentclass| statement that tells the compiler the type of document being produced and some default settings. You can always use the one at the beginning of this document. Place all the text in the body of the document between \verb|\begin{document}| and \verb|\end{document}|.
In {\LaTeX}, regular text is generally typed normally. You don't have to
worry about word spacing, paragraph spacing, line spacing, etc. One place where you may need to pay some attention is quotation marks; the marks at the beginning of a quotation are different from those at the end. In TeXworks, you can turn on the ``Smart Quotes'' preference setting to help with this detail.
Every {\LaTeX} command begins with a backslash. If you are reading
along in the source form of this document, you surely will have noticed that
every time I use the \verb|\LaTeX| command to generate the {\LaTeX} logo, I put it in curly braces. Curly braces can be used without harm almost anywhere in a {\LaTeX} document, just like adding extra parentheses in mathematical formulas. My reason for putting this command in braces is to avoid a common pitfall: if a command that ends in a letter is immediately followed by a space, the space is ignored.
You'll also notice that when I want something to show up ``verbatim'' in the output, I put use the \verb|\verb| command. This command is unusual in that its argument is not enclosed in curly braces. Instead, any character is used before the argument and then the same character afterward. I ordinarily choose to use the vertical bar character for this purpose, unless the material I want to display verbatim happens to include a vertical bar.
A new paragraph is preceded with a blank line. In-line mathematics is
enclosed in dollar signs such as \verb|$x_1=4$| and \verb|$f'(x)=3x^2-2$|, which result in $x_1=4$ and $f'(x)=3x^2-2$. Note that subscripts are indicated using the underscore (\verb|_|) and superscripts using the caret (\verb|^|). Subscripts or superscripts of more than one character must be included in curly braces (\verb|$M_{12}$| gives $M_{12}$, whereas \verb|$M_12$| gives $M_12$).
Specially formatted output is often created using a so-called ``environment,'' which is a section of code bracketed by \verb|\begin{whatever}| and \verb|\end{whatever}| statements. For example, you can produce displayed equations using the \verb|equation| environment. This environment automatically provides a reference number next to the equation, such as you will see in the PDF version of this identity concerning binomial coefficients:
% This is a displayed equation. Notice how the stuff below and above
% the summation sign is entered. Notice the binomial coefficient.
\begin{equation}
\label{binomial-sum}
\sum_{k=0}^{n} \binom{n}{k} = 2^{n}
\end{equation}
If you want to display a formula but have no use for the reference number, you can use the \verb|equation*| variant of the environment. This is so common that {\LaTeX} offers a shorter alternative; you can bracketed the formula with \verb|\[| \ and \verb|\]|. Here's an example:
\[
\sum_{n=0}^{\infty} \left( \frac{1}{2^n} - \frac{1}{2^{n+1}} \right)
\].
There are a few other things to note in these examples.
\begin{itemize}
\item Fractions are displayed using the \verb|\frac{}{}| command. The numerator goes in the first set of braces and the denominator in the second. Binomial coefficients similarly use \verb|\binom{}{}|.
\item The \verb|\left(| and \verb|\right)| commands resize parentheses to match the size of what's inside. You can use \verb|\left| and \verb|\right| with any grouping symbols.
\item The command \verb|\label{binomial-sum}| associates a name in {\LaTeX}'s memory with the equation number. (The same feature can also be used for other kinds of numbers, such as section numbers.) This lets you automatically get the correct number when you want to talk about it; in this case, we'd make reference to Equation~\ref{binomial-sum}. The only glitch is that the first time you compile your document, the numbers come out as question marks; you need to run {\LaTeX} a second time to get them right. Notice that standard writing style dictates capitalizing the word ``Equation'' or ``Section'' when you are referring to a specific one, just as with such compound proper nouns as President Lincoln. Also, note that in the source file, I used the \verb|~| symbol in place of a space between the word ``Equation'' and the reference number. This symbol indicates that a space should go there, but that line breaking is disallowed. Again, that's just a standard stylistic detail; it would apply equally well if you were writing about a flight leaving from Gate~17.
\end{itemize}
Sometimes you may want to display several relationships together as shown below:
\begin{eqnarray*}
v_i & \in & V = \{ v_1, v_2, v_3, \ldots \} \\
v_j & \in & V \\
(v_i, v_j) & \in & E \subseteq V \times V
\end{eqnarray*}
When reading the source code for the preceding list of relationships, note the following points:
\begin{itemize}
\item Use the \verb|eqnarray*| environment to create a displayed list of formulas if you don't want each one numbered. Use \verb|eqnarray| if you do want numbering.
\item In this particular case, the relationships weren't actually equations; they were set memberships. (The first one did have an equation off on the side.) One of my expectations for your writing is that if you refer to a formula as an ``equation,'' it better be asserting an equality. But {\LaTeX} isn't that finicky. You can put any formula you want in an \verb|equation| or \verb|eqnarray| environment.
\item Put ampersands (\verb|&|) around whatever you want aligned (in this case, the set membership symbol).
\item Indicate each line break within the list using \verb|\\|.
\item The letter \verb|l| on the front of the command \verb|\ldots| indicates that I wanted low dots. Sometimes centered dots are more appropriate, as in $a_0 + \cdots + a_n$.
\item I used a bunch of math symbols in this example. There are lots more. Often a web search is the quickest way to find one you need.
\end{itemize}
\subsection{Proving Theorems}
The \verb|theorem| environment brackets the statement of a theorem, but not the proof that usually follows. In the preamble of this document, I defined similar environments for definitions, corollaries, lemmas, etc. The proof goes in a \verb|proof| envionment. I defined this in the preamble to match our textbook's style; for a different style, only one place would need changing. Here is an example of a theorem and its proof:
\begin{theorem}\label{zero-solution-theorem}
Assume $a,\, b,\, c,$ and $d$ are not all zero. If $ad-bc \neq 0$, then the system of equations
\begin{eqnarray}
ax + by &=& 0 \label{eq:thm1}\\
cx + dy &=& 0 \label{eq:thm2}
\end{eqnarray}
has a unique solution of $x=0$, $y=0$.
\end{theorem}
\begin{proof}
Because $ad-bc \neq 0$, at least one of the four constants is non-zero. Without loss of generality assume $a \neq 0$. Solving Equation~\ref{eq:thm1} for $x$ implies
\begin{equation}\label{eq:thm3}
x = -\frac{b}{a}y.
\end{equation}
Substituting this into Equation~\ref{eq:thm2} and simplifying gives
\begin{equation}\label{eq:thm4}
\frac{ad-bc}{a} y = 0.
\end{equation}
Because of the assumption that $ad-bc \neq 0$, Equation~\ref{eq:thm4} implies that $y=0$. Equation~\ref{eq:thm3} then implies that $x=0$. Hence the system of equations has $x=0$, $y=0$ as a unique solution.
\end{proof}
Following our textbook's example, you should generally start your proof with an explicit indication of the method you use, such as direct proof or mathematical induction. For this purpose, I have provided a variant of the \verb|proof| environment called \verb|proofmethod|. Here is an example:
\begin{proofmethod}{by authority}
Because I said so, that's why.
\end{proofmethod}
Incidentally, the proof of Theorem~\ref{zero-solution-theorem} is a direct proof. However, it is also a proof by cases, because the assumption made ``without loss of generality'' is really a shorthand way of saying that there are three other cases that are entirely analogous.
\end{document}