\documentclass[11pt]{article}


% first we include the packages we will need
\usepackage{fullpage} % make the margins a reasonable size
\usepackage{amsmath}  % some handy math symbols
\usepackage{amssymb}  % more handy math symbols
\usepackage{amsthm}   % this is necessary to create theorems/lemmas/etc.
\usepackage{comment}  % block comments with \begin{comment} ... \end{comment}
\usepackage{graphicx} % for figures
\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref} % for href links, and also makes \ref and \eqref clickable in the PDF



% title, author, and date are specified here; they will be used by the \maketitle command later
\title{\LaTeX\ Example\\ECS 120}
\author{David Doty}
\date{} % suppress the date; leaving this out will put the date in the title



% this starts the visible text that will be in the document
% the command \end{document} at the end of the file ends it
\begin{document}


% this displays the title, author, and date specified above
\maketitle







\section*{Non-numbered section}

Sections are a good way to break up homework solutions by problem.
















\section{Numbered section}

Or you can use a numbered section.















\section{How to do things that are easy in a word processor}

Normal text appears mostly as you type it.
A notable exception is ``quotation marks''; 
the left ones are wrong if you use the "normal quotes".
Whitespace            is            ignored,              but you \ \ \ \ can \ \ \ \ \ \ \ \  introduce \ \ more \ \ \ \ spaces \ \ \ \ \ \ \ \ between words if you want.
I like to keep sentences on separate lines in the \LaTeX\ code, but this will not introduce a new paragraph.

To start a new paragraph, you need two newlines in the \LaTeX\ code.


You can also force text to\\appear on the next line in the same paragraph.

You can make text \textbf{bold}, or in \textit{italics}, or \underline{underlined}.
Instead of italics, I prefer to use \emph{emphasis}, because of Theorem~\ref{thm:emph-better-than-italics}.



You can create numbered lists:

\begin{enumerate}
  \item first numbered list item

  \item \label{list-item-to-reference} By using labels, you can reference the list numbers so they automatically update if you add or delete items.

  \item This is a reference to the labeled list item, which is number~\ref{list-item-to-reference}. You may have to compile twice to get the number correct.
\end{enumerate}

You can also create bullet-point lists:

\begin{itemize}
  \item first bullet list item

  \item second bullet list item
\end{itemize}

The \verb!verbatim! environment is good for writing code, not only because it uses a fixed width font, but also because nothing in it is interpreted as a \LaTeX\ command:
\begin{verbatim}
    int x = 5; // \emph{initial} position
    double y = x*x;
\end{verbatim}
You can also use it \verb!inline!, but often what you really want instead is merely {\tt fixed width font, in which you can still have \LaTeX\ commands such as \textit{italics}.}

Hyperlinks show up in PDF documents compiled from \LaTeX: \href{https://smartsite.ucdavis.edu/portal/site/fall2015ecs120}{link to course page}

You can also just display a URL that is itself a link (for some reason this displays tilde characters better than the previous): \url{https://smartsite.ucdavis.edu/portal/site/fall2015ecs120}

















\section{How to write mathematics}

Readable mathematical notation is the main reason to use \LaTeX\ instead of a word processor.
There's much more to math in \LaTeX\ than this, but I want to give just the basics that will be most of what is needed for this course.

You can put math in the same line as the text like this: $x=5.$
Or you can put it on its own line like this: $$x=5.$$
You can also number equations:
\begin{equation}
  x \neq 6.             \label{eq-1}
\end{equation}
Now we can reference equation~\eqref{eq-1}.

Multiline equations are also useful:
\begin{eqnarray*}
  x & =    & y+z
  \\
    & \leq & 2y
  \\
    & <    & 3y  \ \ \ \ \ \ \ \ \text{if $y > 0$}
\end{eqnarray*}

It's possible to number these also, or number only some of them:
\begin{eqnarray}
  x & =    & y+z
  \\
    & \leq & 2y   \nonumber
  \\
    & <    & 3y   \label{last-ineq}
\end{eqnarray}
And we can make a reference to inequality~\eqref{last-ineq}.

Here's a list of common useful math symbols:

\begin{itemize}
  \item $x^2$. Use curly braces to superscript multiple characters, so you get $x^{100}$ instead of $x^100$.

  \item $n_2$, $x_{n^2}$, $x_n^2$, $O(n \log n)$, $\hat{x}$, $\overline{A}$, $x_1'$, $x_n''$

  \item Plain text in math mode: $\{ p \in \mathbb{N} \mid p \text{ is prime} \}$

  \item Spaces in math mode: $\{ \ p \in \mathbb{N} \mid p \text{ is prime} \ \}$

  \item $\frac{\pi^2}{6} = \sum_{n=1}^{\infty} \frac{1}{n^2}$
  
  \item $\zeta(z) = \prod\limits_{n=1}^{\infty} \frac{1}{1 - p_n^{-z}}$

  \item $\mathbb{N} = \{ 0, 1, 2, \ldots \} = \mathbb{Z} \setminus \{-1, -2, \ldots \} \subseteq \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \not\subseteq \mathbb{R}^+$

  \item Greek letters: $\alpha, \beta, \gamma, \Gamma, \delta, \Delta, \epsilon, \zeta, \eta, \theta, \Theta, \kappa, \lambda, \Lambda, \mu, \nu, \xi, \Xi, \pi, \Pi, \rho, \sigma, \tau, \phi, \Phi, \chi, \psi, \Psi, \omega, \Omega$

  \item complexity classes: $\mathsf{P}, \mathsf{NP}, \mathsf{DTIME}(n^3)$

  \item $\Sigma^*$, $\{0,1\}^*$

  \item $\delta: Q \times \Sigma \to Q$

  \item $(\forall X)\ |\mathcal{P}(X)| > |X|$

  \item $\lim_{n \to \infty} \frac{1}{n} = 0$

  \item $(\forall n \in \mathbb{N})(\exists m \in X) m > n \iff |X|=\infty \implies |X| \geq |\mathbb{N}|$

  \item $A \cup (B \cap C) = (A \cup B) \cap (A \cup C)$

  \item $\Sigma^* = \bigcup_{i=0}^{\infty} \Sigma^i$
\end{itemize}

Note how ugly this looks:
$$
( \frac{1}{n^2} )
$$

Use \verb!\left! and \verb!\right! to make pairs of matching delimiters big enough for the text they contain:
$$
\left( \frac{1}{n^2} \right)
$$

For defining sets where you want the vertical line in the middle to scale with the text size, it is useful to have a ``phantom delimiter'' (represented by a period):
$$
  X = \left\{ \left. \frac{n^2}{2^{n^3}} \right| n \in \mathbb{N} \right\}
$$

Of course this only works if you guess properly whether the left or right is bigger, which failed here:
$$
  X = \left\{ \left. n \right| \frac{n^2}{2^{n^3}} \geq \frac{1}{10} \right\}
$$


















\section{Commands}
\newcommand{\NP}{\mathsf{NP}}

You can define commands that act like macros.
These both look the same, but one is easier to type: $\mathsf{NP}$ and $\NP$.
If \LaTeX\ complains that the command is already defined, redefine it.

\renewcommand{\P}{\mathsf{P}}

And then use it: $\P$

Commands can take arguments.
We can make a command for the ``make set delimiter big enough for the left-hand text'' idea, which takes two arguments whose names are \verb!#1! and \verb!#2!,

\newcommand{\setl}[2]{\left\{ \left. #1 \right| #2 \right\}}

and then we can call it with two arguments: $X = \setl{ \frac{n^2}{2^{n^3}} } { n \in \mathbb{N} }$

In this document I'm defining commands as we go, but the normal way to do it would be to define them in the preamble (the part before \verb!\begin{document}!).






















\section{Theorems/Lemmas/Definitions/etc.}
Using the package \verb!amsthm! alone does not provide environments for theorem/lemma/definition/etc.
You have to define your own using the \verb!\newtheorem! command.


\newtheorem{theorem}{Theorem}[section]  % [section] means the numbering is based on the section
\newtheorem{corollary}[theorem]{Corollary}  % [theorem] means the numbering is based on however "theorem" is numbered
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}[theorem]{Definition}


\begin{definition}
  Given $n \in \mathbb{N}$, let $\pi(n) = |\{\ p \in \mathbb{N} \ |\ p \leq n \text{ and } p \text{ is prime}\ \}|$.
\end{definition}

\begin{theorem} \label{thm-prime-number}
  $\lim\limits_{n \to \infty} \frac{\pi(n)}{n / \ln n} = 1.$
\end{theorem}

\begin{proof}
  I don't remember.
\end{proof}

The following is a corollary of Theorem~\ref{thm-prime-number}:

\begin{corollary}
  There are an infinite number of primes.
\end{corollary}


\begin{theorem} \label{thm:emph-better-than-italics}
    In an environment where the text is already italicized, using the \textit{italics command} will not change it, but it can still be \emph{emphasized} with the command \verb!\emph!.
\end{theorem}

















\section{Figures}
To include a figure that is a PDF file or a PNG file, use the \verb!figure! environment.
It is famously difficult in \LaTeX\ to get figures to go where you want them to; that's why it's important to label them so you can refer to them, such as Figure~\ref{fig:picture}.

\begin{figure}
  \begin{centering}
  \includegraphics[width=15cm]{picture} % if the file extension is .png or .pdf, you can leave off the extension
  \caption{A figure}
  \label{fig:picture} % for some reason it's important to put label after caption, or the reference is wrong
  \end{centering}
\end{figure}






\end{document}
