% First say what kind of document you're writing.  The most common are article and report
\documentclass[11pt,letterpaper]{article}

% You can load extra packages to get access to special symbols and commands here
\usepackage[margin=1in]{geometry}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{bbm}
\usepackage{url}

% Use this space to define/redefine commands.  This is a really useful trick if there's some 
% command sequence that you use quite frequently that you don't want to have to type over and over.
% For example, here I define new commands for floor and ceiling.  The syntax is
% 
% \newcommand{\commandname}[numberofargs]{stuff here}
%
% Use #1, #2, etc. in the "stuff here" section to refer to your arguments.  Here I define commands
% for "floor" and "ceiling"

\newcommand{\floor}[1]{{\left\lfloor #1 \right\rfloor}}
\newcommand{\ceil}[1]{{\left\lceil #1 \right\rceil}}

% Here I'm defining a theorem to be used later.  The syntax is
% \newtheorem{theoremname}{Text}

\newtheorem{thm1}{Theorem}

% I don't like the default proof symbol for the theorems, so I made my own.  (You can use this 
% command to redefine any LaTeX command you want.  Be careful, though!  This may break things!
% The syntax is identical to the \newcommand macro.)
\renewcommand{\qedsymbol}{$\scriptstyle\blacksquare$}

% All of your content needs to go between \begin{document}...\end{document}
\begin{document}

% You can use \begin{flushright}...\end{flushright} to right-justify your text, as well.  To change
% text size, choose one of (in decreasing order) \Huge, \huge, \LARGE, \Large, \large, \small,
% \footnotesize, \tiny.  By default, your text is \normalsize.
\begin{center}
{\huge \LaTeX{} Example Document}
\end{center}

% You can create sections, subsections, and subsubsections this way.  You can \label them and
% reference later in the document:
\section{Math Formatting}\label{mathformattingsec}

% Use $...$ for inline math mode.  Use \[...\] for full math mode.
\LaTeX{} has three different input modes: normal input mode, inline math mode, and full math mode.
Normal input mode is what you'll type most of your text in.  Inline math mode allows you to write
mathematics and equations in your paragraphs; full math mode will place all of your text on its
own line.  Here is an example of an equation in inline mode: $\sum_{i=1}^\infty 
\left(\frac{x}{i}\right)^2$.  Here is the same equation in full math mode:

% \left and \right may be used to correctly size parentheses and brackets.  You can manually size
% them by using \Bigg, \bigg, \Big, \big, but this is often much harder to do.  Note that \left
% and \right _must_ appear in pairs, or the compiler will complain at you.  If you want one side
% or the other not to show up, you can use a period: "\left[ stuff in bracket \right."  You can
% use this trick to define piecewise functions.
\[\sum_{i=1}^\infty \left(\frac{x}{i}\right)^2\]
Note that the same symbols will work in both modes, but may be displayed slightly differently.

\subsection{Symbols}
The following is a list of useful math symbols to know in \LaTeX:
% Create a bulleted list.  Use \item to add more things to the list:
\begin{itemize}

% If your sub/superscript has only one character, you can just write it.  Otherwise, you must
% enclose it in brackets:
\item Subscripts and superscripts: $x^2, y_0, 2^{n+1}, a_{i+1,n}, 2^{2^{2^n}}$

% Sometimes fractions don't look as good in inline math mode, so I just use a slash
\item Fractions: $\frac{x}{y}, 2/3$

% The \sqrt function takes an optional first argument in brackets if you want to write a cube root
\item Square roots: $\sqrt{16}, \sqrt[4]{x}$

% Floor and ceiling are a pain to write, so I defined my own function for them (see lines 19-20)
% Feel free to use it:
\item Floor/ceiling: $\floor{4.5}, \ceil{-9.7}$

% You can negate any symbol you want by prefixing it with \not.  So, for example, "Not less than
% or equal to" would be written $\not\leq$.
\item Lots of random symbols: $<, >, \geq, \leq, \neq, \in, \subset, \subseteq, \cap, \cup, \vee, 
\wedge, \equiv, \sim, \forall, \exists, |, \pm$

\item Arrows: $\leftarrow, \Leftarrow, \rightarrow, \Rightarrow, \leftrightarrow, \Leftrightarrow$

% Greek letters are easy.  Just write the name of the letter.  Some Greek letters have multiple 
% ways of drawing them.  You can get these alternate ways by sticking a "var" in front of the 
% command.  You can also get most of the capital letters by starting the command with a capital:
\item Greek letters: $\epsilon, \iota, \pi, \phi, \varphi, \theta, \Lambda, \Omega, \Psi$

% Traditional notation for the sets of natural numbers, integers, rationals, real numbers, 
% and complex numbers:
\item Sets: $\mathbb{N}, \mathbb{Z}, \mathbb{Q}, \mathbb{R}, \mathbb{C}$

\item Special numbers: $\infty, \mathbbm{e}, \mathbbm{i}$

% These use freakishly weird syntax:
\item Binomial coefficients and others: ${a \choose b}, {n \choose n - k}, {a \brack b}, 
{a \brace b}$
\end{itemize}

\subsection{Other Useful Tricks}
You already saw an example of formatting summations, so here's another example of product notation
(fun exercise: assume $a,b,c...,z$ are constant.  What does the following product equal?):

% You can control the limits of sums, products, and integrals using the subscript and superscript
% notation.  LaTeX will figure out the rest.
\[\prod_{X = a,b,c,...} (x - X)\]

You can do an integral the same way:
\[\int_{-\infty}^{\infty} \mathbbm{e}^{-x^2} dx = \sqrt{\pi}\]

% Sometimes you have to manually specify your page breaks
\pagebreak
Arrays and matrices are challenging in \LaTeX.  Here's how you do them:

% The array syntax can be intimidating at first.  Let's break down what's actually going on here:
% First, I start full math mode.  Next, I say I want an appropriately-size left parenthesis.  
% Third, I say that I want to start an array; the second argument to the \begin{array} command
% specifies the number and alignment of the columns.  In this case, I want 2 centered columns.  If
% I had said \begin{array}{crr} that would have implied 3 columns; the first centered, and the last
% two right-aligned.
%
% Once inside the array, I delimit columns using the & character, and I create new rows using \\.
% Once I've filled in all the rows and columns, I end the array using \end{array}; the \right) gives
% me an appropriately-size right parenthesis.
\[
% Array 1
\left(
\begin{array}{cc}
a & b\\
c & d
\end{array}
\right) \cdot 
% Array 2
\left(
\begin{array}{cc}
e & f\\
g & h
\end{array}
\right) =
%Array 3
\left(
\begin{array}{cc}
ae + bg & af + bh \\
ce + dg & cf + dh
\end{array}
\right)\]
There are two other really useful typesetting tricks that use similar syntax to the array syntax.
The first is piecewise functions:

% I'm going to use the array environment for my piecewise function as well.  The differences from
% above are as follows: 1) the { left bracket instead of a parenthesis, 2) No right bracket 
% (obtained using \right.), and 3) different alignment in the array columns:
\[
f(x) = \left\{\begin{array}{cl}
\frac{\sin{x}}{x} & x \neq 0\\
0 & x = 0
\end{array}\right.
\]
The other useful way you can use the array syntax is to line up a sequence of equations or
inequalities:

% This is so common that there is a special environment defined for it.  The eqnarray environment
% will number your equations by default, so you can reference them later.  If you don't want this
% to happen, use the \begin{eqnarray*}...\end{eqnarray*} environment instead.  
%
% The syntax is a little bit easier here; you only get three columns, and you don't have any control
% over the alignment.  You still use & to move between columns and \\ to add new rows.  Note that
% in both the eqnarray and array environments, you don't have to put anything in a particular cell.
\begin{eqnarray}
x^2 + 5x + 6 & = & x^2 + 2x + 3x + 6\\
& = & x(x + 2) + 3(x + 2)\label{eqn2}\\
& = & (x + 3)(x + 2)
\end{eqnarray}

If you're trying to write a formal theorem and a proof, you can do so in the following way (note
that you must define the theorem in your document header, much like you would define a new command):

% We defined this theorem on line 25.  If you want to cite your theorem as proved by someone else,
% do so in the square brackets following):
\begin{thm1}[Fermat]\label{thm1}
Let $n > 2$ be an integer.  There are no positive integers $a,b,c$ that satisfy the following 
equation:
\[a^n + b^n = c^n\]
\end{thm1}
\begin{proof}
This is trivial!  Go do something hard, like prove $P = NP$.
\end{proof}

\section{Other Formatting}

Normal input mode lets you type regular text, and \LaTeX{} will break this up into pages and 
paragraphs for you.  In general, white space doesn't matter in \LaTeX.  The one exception to the
rule is paragraph breaks, which are delimited by a blank line.

Here's the start of another paragraph.  You can also force line breaks:\\
Here's the start of a new line.  

You can write emphasized text in a number of different ways:
\textit{like this}, \textbf{like this}, \underline{like this}, or \textsc{like this}.

There are a number of formatting environments defined in normal mode that will let you typeset things
however you want.  You can do things like write numbered lists:

% If you want to create a list that uses some symbol other than numbers for its items, you can
% override the default with an optional argument to \item.  \item[a)], for example, would create
% an item marked with a).
\begin{enumerate}
\item Take CS173
\item ???
\item Profit!
\end{enumerate}

Here's how to create a table:
% Tables are the "normal mode" complement of the array environment.  They work identically, except
% that the tabular environment only works in normal mode, and the array environment only works in
% math mode.  In both, you can draw column breaks with | in the column specification field, and 
% draw horizontal lines with the \hfill command:

\begin{center}
\begin{tabular}{r|cc|l}
\textbf{Name} & \textbf{HW 1} & \textbf{HW 2} & \textbf{Average}\\\hline
John & 67 & 43 & 55\\
Jane & 72 & 65 & 68.5\\\hline
\textbf{Total:} & 139 & 108 & 123.5
\end{tabular}
\end{center}

% Each of the following references was defined previously in the document using a \label command.
% You can label pretty much anything you want and reference it later.  Note that in order to get
% the references to show up, you must compile your document _twice_.  Otherwise, it will show up
% as '??' in your document.  Also, note below my use of the '~' character.  This prevents LaTeX
% from putting any kind of break between the text and the reference number.  This is a good practice
% to get into, since Figure
% 9 looks weird.
%
% As an aside, the ~ also reduces the space after a period to be a single space instead of a double
% space.  So if you're writing someone's initials, you will want to stick in tildes:
% David R.~Morrison.
\LaTeX{} supports a rich cross-referencing and citation management system.  You can reference any
numbered element in your document, including sections, figures, equations, or pages.  For example,
see section~\ref{mathformattingsec}, eq.~\ref{eqn2}, or theorem~\ref{thm1}.

\section{Where to find stuff}

\LaTeX{} has a quite steep learning curve, but once you know it, you'll never want to use anything
else.  So how do you get to know it really well?  Here's a list of some resources:

\begin{itemize}
\item Google
\item The Not-So-Short Introduction to \LaTeXe: \url{http://fmwww.bc.edu/GStat/docs/latex2e.pdf}.  
This will be your best friend for a long time.  Read through the whole thing.
\item The Comprehensive \LaTeX{} Symbol List: 
\url{http://www.tex.ac.uk/tex-archive/info/symbols/comprehensive/symbols-a4.pdf}.  This 141-page
document lists just about every possible symbol you could ever want to typeset.  Don't get lost!
\item \LaTeX: A Document Preparation System (2nd ed.), by Leslie Lamport.  This book is definitely
a good investment; it was written by the creator of \LaTeX{}, and provides a lot of discussion of
the ins and outs of the system. ISBN: 978-0201529838
\item The \LaTeX{} Companion, by Michel Goossens, Frank Mittelbach, and Alexander Samarin.  Another
really useful reference, and is a much more substantial reference than the above book.
ISBN: 978-0201541991
\end{itemize}

\end{document}


