\usepackage{hyperref} % options added via hypersetup below

%\RequirePackage[l2tabu, orthodox]{nag} % checks for deprecated/dodgy syntax

\usepackage{etex}  % increase number of dimension registers, since we now load enough packages to full the default number
\usepackage{soul}
\usepackage{graphicx}
\usepackage{paralist}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage{bbding}
\usepackage{xargs}
\usepackage{texpower} % options added via \PassOptionsToPackage in driver files
\usepackage{listings}
\usepackage{todonotes}
\usepackage{booktabs} % better rules for tables (use alone or with tabularx)
\usepackage[sharp]{easylist}  % simple nested lists
\usepackage{tikz}
\usepackage{changepage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% fonts                                                                     %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fontspec}
\usepackage{microtype}

\setmainfont[Ligatures=NoCommon, Scale=0.95]{Open Sans Light}
\setsansfont[Ligatures=NoCommon, Scale=MatchLowercase]{Roboto Condensed}
\setmonofont[Ligatures=NoCommon, Scale=MatchLowercase]{Inconsolata}

% make \emph do italics (just in case other environments change it)
\renewcommand{\emph}[1]{\textit{#1}}

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

\definecolor{SectionColor}{rgb}{0.32,0.32,0.32}

%
% PDF tex graphics extensions {graphicx}
\DeclareGraphicsExtensions{.jpg,.jpeg,.pdf,.png,.mps}

% slidemargins {seminar,powersem}
\setlength{\slidewidth}{280mm}
\setlength{\slideheight}{190mm}

\renewcommand{\slidetopmargin}{15mm}
\renewcommand{\slidebottommargin}{25mm} % 'correct' the bottom margin
\renewcommand{\slideleftmargin}{20mm}
\renewcommand{\sliderightmargin}{20mm}

\slidepagestyle{empty}

% don't frame the slides
\slideframe[\setlength{}{}]{none}

%%% source code highlighting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}          % syntax highlighting
\usepackage{lstautogobble}     % add-on for listings that auto-gobbles leading spaces in code

% first param is font size, second is baselineskip
\newcommand\codesize{\fontsize{8}{0.8em}\selectfont}
\newcommand{\codefont}{\ttfamily}
\newcommand\smallcodesize{\fontsize{7}{0.95em}\selectfont}

% define the colors for code highlighting (based on NetBeans colors)
\definecolor{KeywordColor}{rgb}{0.0,0,0.9}
\definecolor{CommentColor}{rgb}{0.45,0.45,0.45} % a bit darker than NetBeans
\definecolor{StringColor}{rgb}{0.81,0.48,0.0}

% create the fonts for code highlighting
\newcommand{\commentfont}{\sffamily\itshape}

% create a new environment for source code blocks
\lstnewenvironment{codeblock}[1][]
{
\lstset{
	language=Java,
	upquote=true,
	autogobble=true,
	basicstyle=\color{black}\codefont\codesize,
	keywordstyle=\color{KeywordColor}\codefont\codesize,
	commentstyle=\color{CommentColor}\commentfont\codesize,
	stringstyle=\color{StringColor}\codefont\codesize,
	aboveskip=0pt,
	belowskip=0pt,
	lineskip=-5pt,
	showstringspaces=false,
	tabsize=3,
	showtabs=false,
	columns=fullflexible,
	flexiblecolumns=true,
	xleftmargin=0pt,
	breaklines=true
}\lstset{#1}}
{}

% create a new environment for source code blocks
\lstnewenvironment{smallcodeblock}[1][]
{% set up source code highlighting environment {listings}
\lstset{
	language=Java,
	upquote=true,
	autogobble=true,
	basicstyle=\color{black}\codefont\smallcodesize,
	keywordstyle=\color{KeywordColor}\codefont\smallcodesize,
	commentstyle=\color{CommentColor}\commentfont\codesize,
	stringstyle=\color{StringColor}\codefont\smallcodesize,
	aboveskip=0pt,
	belowskip=0pt,
	lineskip=-9pt,
	showstringspaces=false,
	tabsize=2,
	showtabs=false,
	columns=fullflexible,
	flexiblecolumns=true,
	xleftmargin=0pt,
	breaklines=true
}\lstset{#1}}
{}

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break, this},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]"
}

% command for typesetting inline code
\renewcommand{\code}[2][language=java]{%
\lstset{%
	language=Java,
	upquote=true,
	basicstyle=\color{emcolor}\codefont\bfseries\normalsize,
	keywordstyle=\color{emcolor}\codefont\bfseries\normalsize,
	stringstyle=\color{emcolor}\codefont\bfseries\normalsize,
	showstringspaces=false,
	showtabs=false
}%
\mbox{\lstinline[#1]!#2!}}


\usepackage[skins]{tcolorbox}

% inline highlighting of code
\newcommand{\hilightchar}[1]{\colorbox{yellow!75}{\makebox[0pt]{\strut{#1}}}}
\newcommand{\hilight}[1]{\setlength{\fboxsep}{1pt}\colorbox{yellow!75}{#1}}

% uses the same spacing as \hilight, but does no highlighting.  Use on the
% original code when using incremental highlighting.
\newcommand{\nohilight}[1]{\setlength{\fboxsep}{1pt}\fboxrule0pt\fbox{#1}}

\newcommand{\error}[1]{\colorbox{red!75}{#1}}

\tcbset{enhanced,boxsep=0pt,top=6pt,bottom=6pt,left=8pt,right=0pt,drop fuzzy shadow}

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

% command for figures - first param is scale, second is file
\newcommand{\fig}[2] {
  \begin{figure}[H]
		 \centering{\includegraphics[scale=#1,draft=false]{#2}}
  \end{figure}
  \vspace{-0.75\baselineskip}
}

% command for figures rotated 90 degrees left - first param is scale.
\newcommand{\rotatedfig}[2] {
  \begin{figure}[H]
	  \centering{\includegraphics[scale=#1,draft=false, angle=90]{#2}}
  \end{figure}
}

% command for figures - first param is scale, second is file
\newcommand{\capfig}[3] {
  \begin{figure}[H]%
	  \centering{\includegraphics[scale=#1,draft=false]{#2}%
		\\ %
		{\footnotesize #3} %
		}
  \end{figure} %
  \vspace{-0.75\baselineskip}
}

% command for figures that fit the page width
\newcommand{\fittedfig}[1] {
  \begin{figure}[H]
    \begin{center}
      \resizebox{\textwidth}{!}{\includegraphics[draft=false]{#1}}
		\vspace{-25pt}
    \end{center}
  \end{figure}
}

% suppress section numbers
\setcounter{secnumdepth}{-2}

% scale factors used by seminar/powersem package to make over/under full slides fit a bit better
\renewcommand{\slideshrink}{1.0}
\renewcommand{\slideskip}{0.25}
\renewcommand{\slidestretch}{1.05}

% increase paragraph spacing a little bit so slides don't look so crowded
\renewcommand{\slideparskip}{1.5ex}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% sections                                                                  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[sf,bf]{titlesec}

\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\titlespacing{\subsubsection}{0pt}{0pt}{0pt}
\titlespacing{\paragraph}{0pt}{0pt}{-0.5\parskip}

\newcommand\mysectionstyle{\huge\sffamily}
\newcommand\mysubsectionstyle{\LARGE\sffamily}
\newcommand\mysubsubsectionstyle{\Large\sffamily}
\newcommand\mysubsubsubsectionstyle{\sffamily\bfseries}

\titleformat{\section}{\mysectionstyle\filcenter}{\theparagraph}{1em}{}
\titleformat{\subsection}{\mysubsubsubsectionstyle}{\theparagraph}{1em}{}
\titleformat{\subsubsection}{\mysubsubsectionstyle}{\theparagraph}{1em}{}
\titleformat{\paragraph}{\mysubsubsubsectionstyle}{\theparagraph}{1em}{}

% repurpose \paragraph as \subsubsubsection (which it sort of is already)
\newcommand{\subsubsubsection}[1]{\paragraph{#1}}

%%%%
% shrinkable sections - shrink to \textwidth if too long
%%%%

%section
\let\oldsection\section
\newsavebox{\secbox}
\newlength{\secboxlength}
\renewcommand{\section}[1]{%
\sbox{\secbox}{\mbox{\mysectionstyle#1}}\settowidth{\secboxlength}{\usebox{\secbox}}%
\oldsection{\ifdim\secboxlength>\textwidth\protect\resizebox{\textwidth}{!}{\usebox{\secbox}}\else{\usebox{\secbox}}\fi}}

%subsection
\let\oldsubsection\subsection
\newsavebox{\subsecbox}
\newlength{\subsecboxlength}
\renewcommand{\subsection}[1]{%
\sbox{\subsecbox}{\mbox{\mysubsectionstyle#1}}\settowidth{\subsecboxlength}{\usebox{\subsecbox}}%
\oldsubsection{\ifdim\subsecboxlength>\textwidth\protect\resizebox{\textwidth}{!}{\usebox{\subsecbox}}\else{\usebox{\subsecbox}}\fi}}

%subsubsection
\let\oldsubsubsection\subsubsection
\newsavebox{\subsubsecbox}
\newlength{\subsubsecboxlength}
\renewcommand{\subsubsection}[1]{%
\sbox{\subsubsecbox}{\mbox{\mysubsubsectionstyle#1}}\settowidth{\subsubsecboxlength}{\usebox{\subsubsecbox}}%
\oldsubsubsection{\ifdim\subsubsecboxlength>\textwidth\protect\resizebox{\textwidth}{!}{\usebox{\subsubsecbox}}\else{\usebox{\subsubsecbox}}\fi}}

%subsubsubsection
\let\oldsubsubsubsection\subsubsubsection
\newsavebox{\subsubsubsecbox}
\newlength{\subsubsubsecboxlength}
\renewcommand{\subsubsubsection}[1]{%
\sbox{\subsubsubsecbox}{\mbox{\mysubsubsubsectionstyle#1}}\settowidth{\subsubsubsecboxlength}{\usebox{\subsubsubsecbox}}%
\oldsubsubsubsection{\ifdim\subsubsubsecboxlength>\textwidth\protect\resizebox{\textwidth}{!}{\usebox{\subsubsubsecbox}}\else{\usebox{\subsubsubsecbox}}\fi}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% miscellaneous stuff                                                       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% suppress built in slide centering (which buggers up incremental uncovering,
% and makes things jump around a lot)
\centerslidesfalse

% options for hyperef
\hypersetup{
  final={true},
  colorlinks={true},
  urlcolor={blue},
  filecolor={blue},
  linkcolor={blue},
  bookmarks={true},
  bookmarksopen={true},
  pdfpagemode={None}
} % title/subject/author attributes are set in lecturedetails.tex

% command for continuing slides - moves the content down a bit
\newcommand{\continued}{\strong{continued...}}

\newcommand{\ra}[0]{$\rightarrow$~}




\newcommand{\point}[2]{\textbf{#1}\\#2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% lists                                                                     %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% fix the extra spacing that itemize/enumerate has when you put have an blank
% line prior to the environment (paralist).
\setlength{\pltopsep}{0.2\baselineskip}
\setlength{\plpartopsep}{-0.2\baselineskip}
\setlength{\plitemsep}{0.2\baselineskip}
\setlength{\plparsep}{0.2\baselineskip}

% rationalise the bullet points
\def\labelitemi{\footnotesize\raisebox{0.175em}{$\bullet$}\normalsize}
\def\labelitemii{\footnotesize\raisebox{0.175em}{$\circ$}\normalsize}
\def\labelitemiii{\footnotesize\raisebox{0.175em}{$\diamond$}\normalsize}
\def\labelitemiv{\footnotesize\raisebox{0.175em}{$\triangleright$}\normalsize}
\def\labelitemv{\footnotesize\raisebox{0.175em}{$\star$}\normalsize}

% easylist configuration
\ListProperties(%
	Hang=true, % hanging indent
	Space=0pt, % additional space between different nest levels
	Space*=0pt, % additional space between same levels
	Hide=1000, % hide all numbering
	Margin=1em, Align=move,
	Margin1=1em, Style1*=\labelitemi\hskip.5em, Space1*=0.2em, %  level 1
	Margin2=2em, Style2*=\labelitemii\hskip .5em, Space2*=0.1em, %  level 2
	Margin3=3em, Style3*=\labelitemiii\hskip .5em, %  level 3
	Margin4=4em, Style4*=\labelitemiv\hskip .5em, %  level 4
	Margin5=5em, Style5*=\labelitemv\hskip .5em % level 5
)

% my attempt at creating a configurable easylist environment for controlling
% spacing

\newenvironment{nest}[1][0pt]%
{%
\ListProperties(%
	Space=#1, % additional space between different nest levels
	Space*=#1, % additional space between same levels
)

\begin{easylist}%
}%
{%
\end{easylist}
% reset easylist spacing
\ListProperties(%
	Space=0pt, % additional space between different nest levels
	Space*=0pt, % additional space between same levels
)
}%

