\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{calc}
\usepackage{ifthen}

\usepackage{graphicx}

\usepackage{fancyhdr}

\usepackage{prettyref}

\newrefformat{fig}{Figure~\ref{#1}}
\newrefformat{sec}{section~\ref{#1}}
\newrefformat{eq}{equation~\eqref{#1}}
\newrefformat{prob}{Problem~\ref{#1}}
\newrefformat{tab}{Table~\ref{#1}}
\newcommand{\pref}[1]{\prettyref{#1}}

\newcommand{\term}[1]{\emph{#1}}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\I}{\mathbb{I}}
\newcommand{\C}{\mathbb{C}}

\newcommand{\suchthat}{\mid}
\newcommand{\union}{\cup}
\newcommand{\intersect}{\cap}

\DeclareMathOperator{\cis}{cis}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newlength{\margininc}
\setlength\margininc{30pt}

\newcommand{\pctitle}[1]{
  \noindent {\Huge #1} \medskip \\
  {\Large \today} \\
  \hrule \vspace{0.2in}
}

\newlength{\newmpwidth}
\setlength\newmpwidth{\marginparwidth+\margininc}

\newcommand{\assigntitle}[2]{
  \pctitle{\##1: #2}

  % set margins to fit marginal notes
  \setlength\oddsidemargin{\oddsidemargin+\margininc}
  \setlength\marginparwidth{\newmpwidth}
  \setlength\textwidth{\textwidth-(\margininc/2)}

  \pagestyle{fancy}
  \fancyhead{}
  \renewcommand\headrulewidth{0pt}
  \fancyfoot{}
  \fancyfoot[L]{\thepage}
  \fancyfoot[R]{{\scriptsize \copyright{} Brent Yorgey 2008. License:
    Creative Commons Attribution-Noncommercial 3.0 US.}}
}

\newcommand{\solutions}[2]{
  \pctitle{Assignment \##1 Solutions}
  \noindent #2
}

\newlength{\defnskip}
\setlength\defnskip{-2\baselineskip}
\newlength{\topicwidth}

\newlength{\mpboxwidth}
\setlength\mpboxwidth{\newmpwidth-2\fboxsep-2\fboxrule-8pt}

\newsavebox{\defnbox}
\newenvironment{defn}[1]
  {\settowidth{\topicwidth}{\textbf{#1}}\bigskip
   \topic{\fbox{
     \ifthenelse{\lengthtest{\topicwidth>\mpboxwidth}}
     {\parbox[t]{\mpboxwidth}{\raggedright\textbf{#1}}}
     {\textbf{#1}}
   }}
   \vspace{\defnskip}
   \begin{lrbox}{\defnbox}
     \begin{minipage}{0.8\textwidth}
     \vspace{1em}
  }
  {  \vspace{1em}
     \end{minipage}
   \end{lrbox}
   \begin{center}
     \framebox[1.1\width]{\usebox{\defnbox}}
   \end{center}
  }

\reversemarginpar
\newcommand{\topic}[1]{\mbox{}\marginpar{\raggedright\textit{\small{\hspace{0pt}#1}}}\ignorespaces}

\newcommand{\diagram}[2]{
  \begin{figure}[htp]
  \centering
  \includegraphics{diagrams/#1.eps}
  \caption{#2}
  \label{fig:#1}
  \end{figure}
}

\newcommand{\diagrampst}[2]{
  \begin{figure}[htp]
  \centering
  \input{diagrams/#1.pstex_t}
  \caption{#2}
  \label{fig:#1}
  \end{figure}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{subprobc}
\newenvironment{subproblems}
  {\mbox{}\begin{list}{(\alph{subprobc})}%
               {\usecounter{subprobc}}}%
  {\end{list}}

\theoremstyle{definition}
\newtheorem{problem}{Problem}

\newtheorem{solution}{Solution}

\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
\setlength{\parindent}{0pt}

\newcommand{\skipto}[1]{\setcounter{enumi}{#1-1}}

\newcommand{\smiley}{$\ddot \smile$}
