\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{graphicx}
\newenvironment{exercise}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\begin{document}
% --------------------------------------------------------------
% Start here
% --------------------------------------------------------------
\title{Math 301 \--- Homework x solutions} % replace homework number
\author{Name} % replace with your name(s)
\date{August 17, 1984} % put the due date here
\maketitle
% --------------------------------------------------------------
% First exercise
% --------------------------------------------------------------
\begin{exercise}{x.y.z}
Modify x.y.z to be the exercise number you are working on. Delete this text and write the exercise statement here. The text here is inside
an ``exercises environment.''
\end{exercise}
\begin{proof}[Solution]
Delete this and write your solution here.
\end{proof}
\bigskip
% --------------------------------------------------------------
% Second exercise
% --------------------------------------------------------------
\begin{exercise}{w.x.y}
Write the next question here. It's useful to have the question statement here when you're studying later.
\end{exercise}
\begin{proof}
This is a proof for you to write.
\end{proof}
% --------------------------------------------------------------
% Extra information
% --------------------------------------------------------------
\section*{A few commands and conventions}
Here are some useful commands for writing math in \LaTeX.
This is how you can use math mode within a sentence,
which is sometimes called in-line mode: $A\subseteq \mathbb{R}^n$.
We can also make math appear centered and on its own line.
This is often called a \emph{displayed} equation: $$\sup S=\infty \text{ and } \inf S=-2.$$
Remember, when writing math, punctuation matters.
Even displayed equations should have a period if they end a sentence.
For example, we have $$\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}.$$
Notice that
you need
a blank space in between lines of code to start a new paragraph.
Here is how to write limits in in-line mode: $\lim_{x\to x_0} f(x)=L.$
The output looks slightly different in displayed mode.
$$\lim_{x\to x_0} f(x)=L.$$
Either way, it looks funny if you forget the backslash before the \texttt{lim} command. Do you agree?
This is a limit with a missing backlash: $lim_{x\to x_0} f(x)=L.$
\subsection*{Align environment}
For equations that span several lines, we use the align environment. The \texttt{\&} symbol tells where to anchor each line of the equation. The double backslash makes a new line.
\begin{proof}
We claim that $\lim_{n\to\infty}a_{n}=7/3$. Let $\epsilon>0$ and let $N=\frac{1}{3}\left(\frac{106}{3\epsilon}-7\right)$. Observe that if $n>N$,
\begin{align*}
|a_{n}-7/3| &= \left|\frac{7n-19}{3n+7}-\frac{7}{3}\right| \\
&= \left|\frac{3(7n-19)-7(3n+7)}{3(3n+7)}\right| \\
&= \frac{106}{3(3n+7)} \\
&< \frac{106}{3(3N+7)} \\
&= \epsilon.
\end{align*}
\end{proof}
Notice above that we used \texttt{\textbackslash left} and \texttt{\textbackslash right} before the parentheses and absolute value bars to make them scale to the right size that would fit around the taller fractions.
\subsection{Equation labels} \label{subsec:eq-labels}
For equations that you'd like to label and refer back to, there are a couple of options. The first is the \texttt{equation} environment, along with the \texttt{label} and \texttt{ref} commands:
\begin{equation}
|\sin x|\leq 1 \label{eq:sine-bound}
\end{equation}
The displayed expression (\ref{eq:sine-bound}) gets labeled with a numbered value, so that you can refer back to in the main body discussion.
You can do this with the \texttt{align} environment as well. Notice that leaving out the asterisk introduces number labels to each line:
\begin{align}
|a+b|^2 &= (a+b)^2 \label{eq:square-abs-val} \\
&= a^2 + 2ab + b^2 \nonumber \\
&= |a|^2 + 2ab + |b|^2 \nonumber \\
&\leq |a|^2 + 2|a||b| + |b|^2 \label{eq:abs-val-inequality} \\
&= (|a|+|b|)^2. \nonumber
\end{align}
This way, you can again reference expressions \eqref{eq:abs-val-inequality} and \eqref{eq:square-abs-val} and not worry about keeping track of the numbers. You can also reference sections and subsections, like Subsection \ref{subsec:eq-labels}.
\newpage
\begin{exercise}{w.x.y}
You can start a new page with the \texttt{\char`\\newpage} command.
\end{exercise}
\end{document}