% This is an example of a LaTeX document, intended for teaching purposes only.
% Author: Marge Coahran
% Date: August 2008
% Note: Additional examples may be added as needed.

% this specifies the documentclass. others include letter, book, report, etc.
\documentclass{article}

% this is a comment

% these settings are related to paper size
\setlength{\paperheight}{11in}
\setlength{\headheight}{0pt}
\setlength{\headsep}{0pt}     
\setlength{\footskip}{0pt}    
%\setlength{\topmargin}{-.1in}
\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.5truein}
\setlength{\textheight}{9.75in}
\setlength{\parindent}{0 in}
\addtolength{\parskip}{\baselineskip}  % 1 blank line between paragraphs
\pagestyle{empty} % no page numbers (or anything else in header/footer)

% these define new commands. we can use the new commands in this document,
% by simply \la or \ra.
\newcommand{\la}{\leftarrow}
\newcommand{\ra}{\rightarrow}

% end of settings

% all documents need this line. stuff from here on gets included in the
% output. stuff before this is called the "preamble".
\begin{document}

{\Large {\bf LaTex Example Sheet}}

\vspace{0.6cm}  % insert some "vertical space"

First, some text formatting instructions. It is easy to make text  
{\bf bold}, set it in {\em italics}, or \underline{underline} it. 

We can make (un-numbered) lists like this:
\vspace{-0.4cm}  % I like to use a little "negative" space here
\begin{itemize}
  \item LaTex is fun and reasonably easy.
  \item Algorithms are fun and reasonably hard.
\end{itemize}

If you want your list items to be numbered, then ``enumerate'' them.
\vspace{-0.4cm}
\begin{enumerate}
  \item Eat.
  \item Sleep.
  \item Exercise.
  \item Really.
\end{enumerate}

You may also want to make a table someday. Here is an example.\\
\begin{tabular}{l|c|l}
  {\em Item} & {\em Weight} & {\em Date}\\ \hline
  Homeworks       & 30\% & approximately every week \\
  Midterm Test I  & 22.5\% & Fri, October 3 (in class) \\
  Midterm Test II & 22.5\% & Wed, November 19 (in class)\\
  Final exam      & 25\% & Thurs, December 18 (2:00-5:00 pm)\\
\end{tabular}
% Regarding the syntax used in this table...
% The notation {l|c|l} specifies that the column justifications should be
%  {left,center,left}, and that there should be vertical lines between them.
% The & is used to delimit the columns in the table.
% A double-backslash \\ in LaTex is like a newline ('\n') in C and Java.

You can use ``verbatim'' for writing pseudocode. It automatically uses a
monospace font and keeps all spacing exactly as it appears in your source.
\vspace{-0.4cm}
\begin{verbatim}
  int count = 0;
  for (int i=n-1; i<=0; i=i/2) {
    count++;
  }
\end{verbatim}


But the real strength of LaTex (for the purposes of this course) is
typesetting math. To place math snippets directly in text, place the
snippet inside a pair of \$ signs like this: $a + b = c$. For more
extensive equations, use equation mode instead, which places the equation
on a separate line:

\begin{displaymath}
  r_1 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}
\end{displaymath}

In either of these math modes, there are many commands available that produce 
Greek letters and other math symbols. For example: $\Theta$, $\Omega$, 
$\omega$, $\pi$, $\exists$, $\forall$, $\ne$, $\le$, $\ge$,
$\subseteq$, $\in$, $\rightarrow$.

Things to notice in the source of the next example are: the tilde
which places a space before the $i$, the commands ({\em left} and 
{\em right}) for inserting large brackets, and the curly braces that cause
the full text of $i=0$ to be placed in the subscript. Long superscripts can 
be done similarly.

\vspace{-0.3cm}
\begin{equation}
 \sum_{i=0}^n ~i^3 = \left[ \frac{n(n+1)}{2} \right]^2
\end{equation}

Here is an ``equation array'', which allows you to align parts of
a multi-line math statement, much the way you align columns within tables:

\vspace{-0.3cm}
\begin{displaymath}
  \begin{array}{lll}
    \int t^2 \cos(1-t^3) dt & = & - \frac{1}{3} \int \cos udu \\\\ %2newline
     & = &  - \frac{1}{3} \sin(1-t^3) + C
  \end{array}
\end{displaymath}

\newpage   % just like it sounds

{\em Tips for using Latex:}

\vspace{-0.4cm}
\begin{itemize}
  \item[*] Your source file must have a ``.tex'' extension.

  \item[*] There are (at least) two ways to produce a pdf file from a LaTex
  (.tex) file. I find the following one-liner easiest, but it doesn't
  work if your document includes images: 

  \vspace{-0.4cm}
  \begin{verbatim}
    pdflatex file.tex       % compiles file.tex and outputs file.pdf
  \end{verbatim}

The following three-step alternative works even when you include images:
\vspace{-0.4cm}
\begin{verbatim}
  latex file.tex          % compiles .tex to .dvi (You can use xdvi to view
                          % a .dvi file.)
  dvips -Ppdf file.dvi    % converts .dvi to .ps (Including the -Ppdf option here
                          % makes the .pdf produced in the next step much prettier.)
  ps2pdf file.ps          % converts .ps to .pdf
\end{verbatim}


  \item[*] I find that I like to view my pdf file with the pdf viewer {\tt
      evince} as I write my LaTex document. Why? Because you can
    keep the pdf document open, recompile it from the terminal window, and
    then refresh the document within {\tt evince} with {\em Ctrl-r}.
 
  \item[*] When you compile your .tex file, if it has errors, you will get
    output something like the following. The ? is a prompt waiting for your
    input. You can press {\em Enter} to continue compiling until the next
    error, or type an {\tt x} to abort the compilation.

\begin{verbatim}
  ! Undefined control sequence.
  <argument> \footheight

  l.14 \setlength{\footheight}{0pt}

  ?
\end{verbatim}


  \item[*] There are lots of on-line resources available for help with
    LaTex. Here is a page I like. It is also linked from the course web page.

{\tt 
http://www.eng.cam.ac.uk/help/tpl/textprocessing/teTeX/latex/latex2e-html/ltx-2.html}

\end{itemize}

\end{document}

