% latex lecture macros -- David Steurer, Aug 25, 2012

% {{{ etex }}}

\usepackage{etex}

% {{{ nag }}}

\usepackage[l2tabu, orthodox]{nag}

% {{{ common }}}

\usepackage{xspace,enumerate}

\usepackage[dvipsnames]{xcolor}

\usepackage[T1]{fontenc}
\usepackage[full]{textcomp}

% {{{ babelamerican }}}

\usepackage[american]{babel}

% {{{ mathtools }}}

\usepackage{mathtools}

% {{{ boldmath }}}

% fix for "too many math alphabets" problem
\newcommand\hmmax{0} % default 3
\newcommand\bmmax{0} % default 3

\usepackage{bm}


% {{{ amsthm }}}

\usepackage{amsthm}

% parentcounter for theorem environments, 
% either section, chapter, or empty
% depending on document type
\newcounter{parentcounter}

% by default make it equal to section
\makeatletter
    \let\c@parentcounter\c@section
\makeatother

% boldface header, italic body
\newtheorem{theorem}{Theorem}[parentcounter]
\newtheorem*{theorem*}{Theorem}

\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{proposition*}{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem*{lemma*}{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem*{corollary*}{Corollary}
\newtheorem{fact}[theorem]{Fact}
\newtheorem*{fact*}{Fact}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem*{conjecture*}{Conjecture}
\newtheorem{hypothesis}[theorem]{Hypothesis}
\newtheorem*{hypothesis*}{Hypothesis}
\newtheorem{assumption}[theorem]{Assumption}
\newtheorem*{assumption*}{Assumption}

% no boldface for the following theorem-like environments
\theoremstyle{remark}

\newtheorem{claim}[theorem]{Claim}
\newtheorem*{claim*}{Claim}
\newtheorem{subclaim}{Claim}[theorem] % nested inside theorem proofs

% boldface header, regular body
\theoremstyle{definition}

\newtheorem{definition}[theorem]{Definition}
\newtheorem{construction}[theorem]{Construction}
\newtheorem{example}[theorem]{Example}
\newtheorem{question}[theorem]{Question}
\newtheorem{goal}[theorem]{Goal}
\newtheorem{openquestion}[theorem]{Open Question}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{protocol}[theorem]{Protocol}

% no boldface for the following theorem-like environments
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem*{remark*}{Remark}
\newtheorem{observation}[theorem]{Observation}
\newtheorem*{observation*}{Observation}



% {{{ geometry-nice }}}

\usepackage[letterpaper,
top=1.3in,
bottom=1.3in,
left=1.6in,
right=1.6in]{geometry}

% {{{ pxfonts }}}

\usepackage[varg]{pxfonts} % varg - uses nicer g,v,y,w


% {{{ hyperref-option2 }}}

\ifnum\showcolorlinks=1
\usepackage[
pagebackref,
colorlinks=true,
urlcolor=blue,
linkcolor=blue,
citecolor=OliveGreen,
]{hyperref}
\fi

\ifnum\showcolorlinks=0
\usepackage[
pagebackref,
colorlinks=false,
pdfborder={0 0 0}
]{hyperref}
\fi


% {{{ prettyref }}}
\usepackage{prettyref}

% From manual:
% \newrefformat{eq}{\textup{(\ref{#1})}}
% \newrefformat{lem}{Lemma~\ref{#1}}
% \newrefformat{thm}{Theorem~\ref{#1}}
% \newrefformat{cha}{Chapter~\ref{#1}}
% \newrefformat{sec}{Section~\ref{#1}}
% \newrefformat{tab}{Table~\ref{#1} on page~\pageref{#1}}
% \newrefformat{fig}{Figure~\ref{#1} on page~\pageref{#1}}

\newcommand{\savehyperref}[2]{\texorpdfstring{\hyperref[#1]{#2}}{#2}}

\newrefformat{eq}{\savehyperref{#1}{\textup{(\ref*{#1})}}}
\newrefformat{lem}{\savehyperref{#1}{Lemma~\ref*{#1}}}
\newrefformat{def}{\savehyperref{#1}{Definition~\ref*{#1}}}
\newrefformat{thm}{\savehyperref{#1}{Theorem~\ref*{#1}}}
\newrefformat{cor}{\savehyperref{#1}{Corollary~\ref*{#1}}}
\newrefformat{cha}{\savehyperref{#1}{Chapter~\ref*{#1}}}
\newrefformat{sec}{\savehyperref{#1}{Section~\ref*{#1}}}
\newrefformat{app}{\savehyperref{#1}{Appendix~\ref*{#1}}}
\newrefformat{tab}{\savehyperref{#1}{Table~\ref*{#1}}}
\newrefformat{fig}{\savehyperref{#1}{Figure~\ref*{#1}}}
\newrefformat{hyp}{\savehyperref{#1}{Hypothesis~\ref*{#1}}}
\newrefformat{alg}{\savehyperref{#1}{Algorithm~\ref*{#1}}}
\newrefformat{rem}{\savehyperref{#1}{Remark~\ref*{#1}}}
\newrefformat{item}{\savehyperref{#1}{Item~\ref*{#1}}}
\newrefformat{step}{\savehyperref{#1}{step~\ref*{#1}}}
\newrefformat{conj}{\savehyperref{#1}{Conjecture~\ref*{#1}}}
\newrefformat{fact}{\savehyperref{#1}{Fact~\ref*{#1}}}
\newrefformat{prop}{\savehyperref{#1}{Proposition~\ref*{#1}}}
\newrefformat{prob}{\savehyperref{#1}{Problem~\ref*{#1}}}
\newrefformat{claim}{\savehyperref{#1}{Claim~\ref*{#1}}}
\newrefformat{relax}{\savehyperref{#1}{Relaxation~\ref*{#1}}}
\newrefformat{red}{\savehyperref{#1}{Reduction~\ref*{#1}}}
\newrefformat{part}{\savehyperref{#1}{Part~\ref*{#1}}}



% {{{ sref }}}

% short section reference
\newcommand{\Sref}[1]{\hyperref[#1]{\S\ref*{#1}}}

% {{{ nicefrac }}}
% commands for fractions
\usepackage{nicefrac}
% poor man's fraction
\newcommand{\flatfrac}[2]{#1/#2}
\newcommand{\varflatfrac}[2]{#1\textfractionsolidus#2}

\let\nfrac=\nicefrac
\let\ffrac=\flatfrac
% similar commands: tfrac,dfrac

\newcommand{\half}{\nicefrac12}
\newcommand{\onequarter}{\nicefrac14}
\newcommand{\threequarter}{\nicefrac34}




% {{{ microtype-option }}}

\ifnum\usemicrotype=1
\usepackage{microtype}
\fi



% {{{ boxedminipage }}}
\usepackage{boxedminipage}

\newenvironment{mybox}
{\center \noindent\begin{boxedminipage}{1.0\linewidth}}
{\end{boxedminipage}
\noindent
}


% {{{ parentheses }}}
% various bracket-like commands
% round parentheses
\newcommand{\paren}[1]{(#1)}
\newcommand{\Paren}[1]{\left(#1\right)}
\newcommand{\bigparen}[1]{\big(#1\big)}
\newcommand{\Bigparen}[1]{\Big(#1\Big)}
% square brackets
\newcommand{\brac}[1]{[#1]}
\newcommand{\Brac}[1]{\left[#1\right]}
\newcommand{\bigbrac}[1]{\big[#1\big]}
\newcommand{\Bigbrac}[1]{\Big[#1\Big]}
% absolute value
\newcommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\Abs}[1]{\left\lvert#1\right\rvert}
\newcommand{\bigabs}[1]{\big\lvert#1\big\rvert}
\newcommand{\Bigabs}[1]{\Big\lvert#1\Big\rvert}
% cardinality
\newcommand{\card}[1]{\lvert#1\rvert}
\newcommand{\Card}[1]{\left\lvert#1\right\rvert}
\newcommand{\bigcard}[1]{\big\lvert#1\big\rvert}
\newcommand{\Bigcard}[1]{\Big\lvert#1\Big\rvert}
% set
\newcommand{\set}[1]{\{#1\}}
\newcommand{\Set}[1]{\left\{#1\right\}}
\newcommand{\bigset}[1]{\big\{#1\big\}}
\newcommand{\Bigset}[1]{\Big\{#1\Big\}}
% norm
\newcommand{\norm}[1]{\lVert#1\rVert}
\newcommand{\Norm}[1]{\left\lVert#1\right\rVert}
\newcommand{\bignorm}[1]{\big\lVert#1\big\rVert}
\newcommand{\Bignorm}[1]{\Big\lVert#1\Big\rVert}
% 2-norm
\newcommand{\normt}[1]{\norm{#1}_2}
\newcommand{\Normt}[1]{\Norm{#1}_2}
\newcommand{\bignormt}[1]{\bignorm{#1}_2}
\newcommand{\Bignormt}[1]{\Bignorm{#1}_2}
% 2-norm squared
\newcommand{\snormt}[1]{\norm{#1}^2_2}
\newcommand{\Snormt}[1]{\Norm{#1}^2_2}
\newcommand{\bigsnormt}[1]{\bignorm{#1}^2_2}
\newcommand{\Bigsnormt}[1]{\Bignorm{#1}^2_2}
% norm squared
\newcommand{\snorm}[1]{\norm{#1}^2}
\newcommand{\Snorm}[1]{\Norm{#1}^2}
\newcommand{\bigsnorm}[1]{\bignorm{#1}^2}
\newcommand{\Bigsnorm}[1]{\Bignorm{#1}^2}
% 1-norm
\newcommand{\normo}[1]{\norm{#1}_1}
\newcommand{\Normo}[1]{\Norm{#1}_1}
\newcommand{\bignormo}[1]{\bignorm{#1}_1}
\newcommand{\Bignormo}[1]{\Bignorm{#1}_1}
% infty-norm
\newcommand{\normi}[1]{\norm{#1}_\infty}
\newcommand{\Normi}[1]{\Norm{#1}_\infty}
\newcommand{\bignormi}[1]{\bignorm{#1}_\infty}
\newcommand{\Bignormi}[1]{\Bignorm{#1}_\infty}
% inner product
\newcommand{\iprod}[1]{\langle#1\rangle}
\newcommand{\Iprod}[1]{\left\langle#1\right\rangle}
\newcommand{\bigiprod}[1]{\big\langle#1\big\rangle}
\newcommand{\Bigiprod}[1]{\Big\langle#1\Big\rangle}


% {{{ probability }}}
% expectation, probability, variance
\newcommand{\Esymb}{\mathbb{E}}
\newcommand{\Psymb}{\mathbb{P}}
\newcommand{\Vsymb}{\mathbb{V}}


\DeclareMathOperator*{\E}{\Esymb}
\DeclareMathOperator*{\Var}{\Vsymb}
\DeclareMathOperator*{\ProbOp}{\Psymb}

\renewcommand{\Pr}{\ProbOp}

% TODO: make case distinction if optional argument is not set
\newcommand{\prob}[1]{\Pr\set{#1}}
\newcommand{\Prob}[2][]{\Pr_{{#1}}\Set{#2}}

\newcommand{\ex}[1]{\E\brac{#1}}
\newcommand{\Ex}[2][]{\E_{{#1}}\Brac{#2}}
\newcommand{\varex}[1]{\E\paren{#1}}
\newcommand{\varEx}[1]{\E\Paren{#1}}

\newcommand{\given}{\;\middle\vert\;}

% {{{ mathfonts }}}

\usepackage{dsfont}
\usepackage{yfonts}
\usepackage{mathrsfs}


% {{{ miscmacros }}}

% middle delimiter in the definition of a set
\newcommand{\suchthat}{\;\middle\vert\;}

% tensor product
\newcommand{\tensor}{\otimes}

% add explanations to math displays
\newcommand{\where}{\text{where}}
\newcommand{\textparen}[1]{\text{(#1)}}
\newcommand{\using}[1]{\textparen{using #1}}
\ifx\because\undefined
\newcommand{\because}[1]{\textparen{because #1}}
\else
\renewcommand{\because}[1]{\textparen{because #1}}
\fi
\newcommand{\by}[1]{\textparen{by #1}}


% spectral order (Loewner order)
\newcommand{\sge}{\succeq}
\newcommand{\sle}{\preceq}

% smallest and largest eigenvalue
\newcommand{\lmin}{\lambda_{\min}}
\newcommand{\lmax}{\lambda_{\max}}

\newcommand{\signs}{\set{1,-1}}
\newcommand{\varsigns}{\set{\pm 1}}
\newcommand{\maximize}{\mathop{\textrm{maximize}}}
\newcommand{\minimize}{\mathop{\textrm{minimize}}}
\newcommand{\subjectto}{\mathop{\textrm{subject to}}}

\renewcommand{\ij}{{ij}}

% symmetric difference
\newcommand{\symdiff}{\Delta}
\newcommand{\varsymdiff}{\bigtriangleup}

% set of bits
\newcommand{\bits}{\{0,1\}}
\newcommand{\sbits}{\{\pm1\}}

% no stupid bullets for itemize environmentx
\renewcommand{\labelitemi}{--}

% control white space of list and display environments
\newcommand{\listoptions}{\labelsep0mm\topsep-0mm\itemindent-6mm\itemsep0mm}
\newcommand{\displayoptions}[1]{\abovedisplayshortskip#1mm\belowdisplayshortskip#1mm\abovedisplayskip#1mm\belowdisplayskip#1mm}

% short for emptyset
%\newcommand{\eset}{\emptyset}
% moved to mathabbreviations

% short for epsilon
%\newcommand{\e}{\epsilon}
% moved to mathabbreviations

% super index with parentheses
\newcommand{\super}[2]{#1^{\paren{#2}}}
\newcommand{\varsuper}[2]{#1^{\scriptscriptstyle\paren{#2}}}

% tensor power notation
\newcommand{\tensorpower}[2]{#1^{\tensor #2}}


% multiplicative inverse
\newcommand{\inv}[1]{{#1^{-1}}}

% dual element
\newcommand{\dual}[1]{{#1^*}}

% subset
%\newcommand{\sse}{\subseteq}
% moved to mathabbreviations

% vertical space in math formula
\newcommand{\vbig}{\vphantom{\bigoplus}}

% setminus
\newcommand{\sm}{\setminus}

% define something by an equation (display)
\newcommand{\defeq}{\stackrel{\mathrm{def}}=}

% define something by an equation (inline)
\newcommand{\seteq}{\mathrel{\mathop:}=}

% declare function f by $f \from X \to Y$
\newcommand{\from}{\colon}

% big middle separator (for conditioning probability spaces)
\newcommand{\bigmid}{~\big|~}
\newcommand{\Bigmid}{~\Big|~}
\newcommand{\Mid}{\;\middle\vert\;}

% better vector definition and some variations
\renewcommand{\vec}[1]{{\bm{#1}}}
\newcommand{\bvec}[1]{\bar{\vec{#1}}}
\newcommand{\pvec}[1]{\vec{#1}'}
\newcommand{\tvec}[1]{{\tilde{\vec{#1}}}}

% punctuation at the end of a displayed formula
\newcommand{\mper}{\,.}
\newcommand{\mcom}{\,,}

% inner product for matrices
\newcommand\bdot\bullet

% transpose
\newcommand{\trsp}[1]{{#1}^\dagger}

% indicator function / vector
%\ifx\mathds\undefined % use double stroke fonts if available
\newcommand{\Ind}{\mathbb I}
%\else
%\newcommand{\Ind}{\mathds 1}
%\fi

% place a qed symbol inside display formula
%\qedhere

% {{{ superscripts }}}

\renewcommand{\th}{\textsuperscript{th}\xspace}
\newcommand{\st}{\textsuperscript{st}\xspace}
\newcommand{\nd}{\textsuperscript{nd}\xspace}
\newcommand{\rd}{\textsuperscript{rd}\xspace}


% {{{ mathoperators }}}
\DeclareMathOperator{\Inf}{Inf}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\SDP}{SDP}
\DeclareMathOperator{\sdp}{sdp}
\DeclareMathOperator{\val}{val}
\DeclareMathOperator{\LP}{LP}
\DeclareMathOperator{\OPT}{OPT}
\DeclareMathOperator{\opt}{opt}
\DeclareMathOperator{\vol}{vol}
\DeclareMathOperator{\poly}{poly}
\DeclareMathOperator{\qpoly}{qpoly}
\DeclareMathOperator{\qpolylog}{qpolylog}
\DeclareMathOperator{\qqpoly}{qqpoly}
\DeclareMathOperator{\argmax}{argmax}
\DeclareMathOperator{\polylog}{polylog}
\DeclareMathOperator{\supp}{supp}
\DeclareMathOperator{\dist}{dist}
\DeclareMathOperator{\sign}{sign}
\DeclareMathOperator{\conv}{conv}
\DeclareMathOperator{\Conv}{Conv}

\DeclareMathOperator{\rank}{rank}

% operators with limits
\DeclareMathOperator*{\median}{median}
\DeclareMathOperator*{\Median}{Median}

% smaller summation/product symbols
\DeclareMathOperator*{\varsum}{{\textstyle \sum}}
\DeclareMathOperator{\tsum}{{\textstyle \sum}}

\let\varprod\undefined

\DeclareMathOperator*{\varprod}{{\textstyle \prod}}
\DeclareMathOperator{\tprod}{{\textstyle \prod}}




% {{{ differentials }}}

\newcommand{\diffmacro}[1]{\,\mathrm{d}#1}

\newcommand{\dmu}{\diffmacro{\mu}}
\newcommand{\dgamma}{\diffmacro{\gamma}}
\newcommand{\dlambda}{\diffmacro{\lambda}}
\newcommand{\dx}{\diffmacro{x}}
\newcommand{\dt}{\diffmacro{t}}



% {{{ textabbreviations }}}

% some abbreviations
\newcommand{\ie}{i.e.,\xspace}
\newcommand{\eg}{e.g.,\xspace}
\newcommand{\Eg}{E.g.,\xspace}
\newcommand{\phd}{Ph.\,D.\xspace}
\newcommand{\msc}{M.\,S.\xspace}
\newcommand{\bsc}{B.\,S.\xspace}

\newcommand{\etal}{et al.\xspace}

\newcommand{\iid}{i.i.d.\xspace}

% {{{ foreignwords }}}

\newcommand\naive{na\"{\i}ve\xspace}
\newcommand\Naive{Na\"{\i}ve\xspace}
\newcommand\naively{na\"{\i}vely\xspace}
\newcommand\Naively{Na\"{\i}vely\xspace}



% {{{ names }}}
% Hungarian/Polish/East European names
\newcommand{\Erdos}{Erd\H{o}s\xspace}
\newcommand{\Renyi}{R\'enyi\xspace}
\newcommand{\Lovasz}{Lov\'asz\xspace}
\newcommand{\Juhasz}{Juh\'asz\xspace}
\newcommand{\Bollobas}{Bollob\'as\xspace}
\newcommand{\Furedi}{F\"uredi\xspace}
\newcommand{\Komlos}{Koml\'os\xspace}
\newcommand{\Luczak}{\L uczak\xspace}
\newcommand{\Kucera}{Ku\v{c}era\xspace}
\newcommand{\Szemeredi}{Szemer\'edi\xspace}
\newcommand{\Hastad}{H{\aa}stad\xspace}

% {{{ numbersets }}}
% number sets
\newcommand{\Z}{\mathbb Z}
\newcommand{\N}{\mathbb N}
\newcommand{\R}{\mathbb R}
\newcommand{\C}{\mathbb C}
\newcommand{\Rnn}{\R_+}
\newcommand{\varR}{\Re}
\newcommand{\varRnn}{\varR_+}


% {{{ problems }}}

% macros to denote computational problems

% use texorpdfstring to avoid problems with hyperref (can use problem
% macros also in headings
\newcommand{\problemmacro}[1]{\texorpdfstring{\textsc{#1}}{#1}\xspace}

% list of problems
\newcommand{\uniquegames}{\problemmacro{Unique Games}}
\newcommand{\maxcut}{\problemmacro{Max Cut}}
\newcommand{\multicut}{\problemmacro{Multi Cut}}
\newcommand{\vertexcover}{\problemmacro{Vertex Cover}}
\newcommand{\balancedseparator}{\problemmacro{Balanced Separator}}
\newcommand{\maxtwosat}{\problemmacro{Max $2$-Sat}}
\newcommand{\maxthreesat}{\problemmacro{Max $3$-Sat}}
\newcommand{\maxthreelin}{\problemmacro{Max $3$-Lin}}
\newcommand{\threesat}{\problemmacro{$3$-Sat}}
\newcommand{\labelcover}{\problemmacro{Label Cover}}
\newcommand{\maxksat}{\problemmacro{Max $k$-Sat}}
\newcommand{\mas}{\problemmacro{Maximum Acyclic Subgraph}}
\newcommand{\kwaycut}{\problemmacro{$k$-way Cut}}
\newcommand{\sparsestcut}{\problemmacro{Sparsest Cut}}
\newcommand{\betweenness}{\problemmacro{Betweenness}}
\newcommand{\uniformsparsestcut}{\problemmacro{Uniform Sparsest Cut}}
\newcommand{\grothendieckproblem}{\problemmacro{Grothendieck Problem}}
\newcommand{\maxfoursat}{\problemmacro{Max $4$-Sat}}
\newcommand{\maxkcsp}{\problemmacro{Max $k$-CSP}}
\newcommand{\maxdicut}{\problemmacro{Max DiCut}}
\newcommand{\maxcutgain}{\problemmacro{Max Cut Gain}}
\newcommand{\smallsetexpansion}{\problemmacro{Small-Set Expansion}}
\newcommand{\minbisection}{\problemmacro{Min Bisection}}
\newcommand{\minimumlineararrangement}{\problemmacro{Minimum Linear Arrangement}}
\newcommand{\maxtwolin}{\problemmacro{Max $2$-Lin}}
\newcommand{\gammamaxlin}{\problemmacro{$\Gamma$-Max $2$-Lin}}
\newcommand{\basicsdp}{\problemmacro{Basic Sdp}}
\newcommand{\dgames}{\problemmacro{$d$-to-$1$ Games}}
\newcommand{\maxclique}{\problemmacro{Max Clique}}
\newcommand{\densestksubgraph}{\problemmacro{Densest $k$-Subgraph}}


% {{{ alphabet }}}

\newcommand{\cA}{\mathcal A}
\newcommand{\cB}{\mathcal B}
\newcommand{\cC}{\mathcal C}
\newcommand{\cD}{\mathcal D}
\newcommand{\cE}{\mathcal E}
\newcommand{\cF}{\mathcal F}
\newcommand{\cG}{\mathcal G}
\newcommand{\cH}{\mathcal H}
\newcommand{\cI}{\mathcal I}
\newcommand{\cJ}{\mathcal J}
\newcommand{\cK}{\mathcal K}
\newcommand{\cL}{\mathcal L}
\newcommand{\cM}{\mathcal M}
\newcommand{\cN}{\mathcal N}
\newcommand{\cO}{\mathcal O}
\newcommand{\cP}{\mathcal P}
\newcommand{\cQ}{\mathcal Q}
\newcommand{\cR}{\mathcal R}
\newcommand{\cS}{\mathcal S}
\newcommand{\cT}{\mathcal T}
\newcommand{\cU}{\mathcal U}
\newcommand{\cV}{\mathcal V}
\newcommand{\cW}{\mathcal W}
\newcommand{\cX}{\mathcal X}
\newcommand{\cY}{\mathcal Y}
\newcommand{\cZ}{\mathcal Z}

\newcommand{\bbB}{\mathbb B}
\newcommand{\bbS}{\mathbb S}
\newcommand{\bbR}{\mathbb R}
\newcommand{\bbZ}{\mathbb Z}
\newcommand{\bbI}{\mathbb I}
\newcommand{\bbQ}{\mathbb Q}
\newcommand{\bbP}{\mathbb P}
\newcommand{\bbE}{\mathbb E}

\newcommand{\sfE}{\mathsf E}


% {{{ leqslant }}}
% slanted lower/greater equal signs
\renewcommand{\leq}{\leqslant}
\renewcommand{\le}{\leqslant}
\renewcommand{\geq}{\geqslant}
\renewcommand{\ge}{\geqslant}


% {{{ varepsilon }}}

\let\epsilon=\varepsilon

% {{{ numberequationwithinsection }}}
\numberwithin{equation}{section}


% {{{ bibliography }}}

% add section for references to table of contents
\newcommand{\addreferencesection}{
  \phantomsection
  \addcontentsline{toc}{section}{References}
}


% {{{ mathabbreviations }}}

\newcommand{\la}{\leftarrow}
\newcommand{\sse}{\subseteq}
\newcommand{\ra}{\rightarrow}
\newcommand{\e}{\epsilon}
\newcommand{\eps}{\epsilon}
\newcommand{\eset}{\emptyset}


% {{{ paragraphperiod }}}


\let\origparagraph\paragraph
\renewcommand{\paragraph}[1]{\origparagraph{#1.}}


% {{{ allowdisplaybreaks }}}
% allows page breaks in large display math formulas

\allowdisplaybreaks



% {{{ sloppy }}}
% avoid math spilling on margin

\sloppy



% {{{ complexityclasses }}}

\newcommand{\cclassmacro}[1]{\texorpdfstring{\textbf{#1}}{#1}\xspace}
\newcommand{\p}{\cclassmacro{P}}
\newcommand{\np}{\cclassmacro{NP}}
\newcommand{\subexp}{\cclassmacro{SUBEXP}}


% {{{ fancy headers }}}

\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\pagestyle{fancy}


% {{{ course macros }}}

% fix the symbol for variance
\renewcommand{\Vsymb}{Var}

% initialize variables

\def\courseshort{COURSENUM}
\def\university{UNIVERSITY}
\def\coursenum{COURSENAME}
\def\duedate{DUEDATE}
\def\homeworknumber{999}
\def\instructor{INSTRUCTOR}
\def\semester{SEMESTER}
\def\studentname{NAME}
\def\studentnetid{NETID}
\def\scribename{NAME}
\def\scribenetid{NETID}
\def\lecturenumber{NUM}
\def\lecturedate{DATE}
\def\lecturetitle{TITLE}

\def\homeworktype{0}
\def\submissiontype{1}
\def\scribetype{2}
\def\type{\homeworktype}

% macros for setting variables

\newcommand{\setcourseshort}[1]{\def\courseshort{#1}}
\newcommand{\setuniversity}[1]{\def\university{#1}}
\newcommand{\setcourselong}[1]{\def\courselong{#1}}
\newcommand{\setduedate}[1]{\def\duedate{#1}}
\newcommand{\sethomeworknumber}[1]{\def\homeworknumber{#1}}
\newcommand{\setinstructor}[1]{\def\instructor{#1}}
\newcommand{\setsemester}[1]{\def\semester{#1}}
\newcommand{\setstudentname}[1]{\def\studentname{#1}}
\newcommand{\setstudentnetid}[1]{\def\studentnetid{#1}}
\newcommand{\setscribename}[1]{\def\scribename{#1}}
\newcommand{\setscribenetid}[1]{\def\scribenetid{#1}}
\newcommand{\setlecturenumber}[1]{\def\lecturenumber{#1}}
\newcommand{\setlecturedate}[1]{\def\lecturedate{#1}}
\newcommand{\setlecturetitle}[1]{\def\lecturetitle{#1}}
\newcommand{\submission}{\def\type{\submissiontype}}
\newcommand{\homework}{\def\type{\homeworktype}}
\newcommand{\scribenote}{\def\type{\scribetype}}

% decide between title for homework and submission 
\renewcommand{\maketitle}{
  \ifnum\type=\homeworktype
  \makehomeworktitle
  \fi\ifnum\type=\submissiontype
  \makesubmissiontitle
  \fi\ifnum\type=\scribetype
  \makescribetitle
  \fi
}

\newcommand{\makehomeworktitle}{

  % count homeworks like sections
  \setcounter{section}{\homeworknumber}

  % header for homework
  \lhead{\large \courseshort{} -- \courselong \vspace{1mm}}
  \rhead{\large \instructor, \semester\vspace{1mm}}
  
  % title for homework
  \begin{center}
    \noindent\mbox{}\\
    {\huge Homework \homeworknumber}\\[4mm]
    {\large Due \duedate}\\[10mm]
  \end{center}
}

\newcommand{\makesubmissiontitle}{
  
  % count homeworks like sections
  \setcounter{section}{\homeworknumber}

  % header for homework submission
  \lhead{\large \courseshort{} -- \courselong \vspace{1mm}}
  \rhead{\large \studentname{} (\studentnetid), \semester\vspace{1mm}}

  % title for homework submission
  \begin{center}
    \noindent\mbox{}\\
    {\huge Homework \homeworknumber}\\[4mm]
    {\huge Submission}\\[4mm]
    {\small Due \duedate}\\[10mm]
  \end{center}
}

% environment for homework solutions
\newenvironment{solution}{
  \noindent \emph{Solution:}
}{
  \hfill \qedsymbol
}

\makeatletter
\newcommand{\makescribetitle}{

  % simpler header for first page
  \thispagestyle{plain}

  % headers for remaining pages
  \lhead{\courseshort, \semester, Lecture \lecturenumber}
  \rhead{Scribe: \scribename}

  % count lectures like chapters
  \setcounter{chapter}{\lecturenumber}
  
  % use chapter counter as parent for theorems
  \let\c@parentcounter\c@chapter

  % title for scribe note
  \noindent
  {\huge\bfseries  \lecturenumber\quad }
  \begin{minipage}[t]{0.9\linewidth}
    {\huge \bfseries \raggedright \lecturetitle\bigskip

    }
    
    \bigskip
    
    \small     
    \noindent \courseshort{} -- \courselong, \semester
    \smallskip
    
    \noindent
    Instructor: \instructor
    \smallskip
    
    \noindent
    Scribe: \scribename{} (\scribenetid)
    \smallskip
    
    \noindent
    Date: \lecturedate{}
    \bigskip
    
  \end{minipage} 
  \normalsize   
}
\makeatother