% preamble.tex -- packages to include
%
% Wisconsin dissertation template
% Copyright (c) 2008 William C. Benton.  All rights reserved.
%
% This program can redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.
%
% This program includes other software that is licensed under the
% terms of the LPPL and the Perl Artistic License; see README for details.
%
% You, the user, still hold the copyright to any document you produce
% with this software (like your dissertation).

%% You should use natbib
% \IfFileExists{natbib.sty}{%
% \usepackage{natbib}%
% }{}

%% You probably need appendix, if you want appendices
\IfFileExists{appendix.sty}{%
\usepackage{appendix}%
}{}

%% the spacing in memoir is weird, you'll need to use this
\DisemulatePackage{setspace}
\usepackage[onehalfspacing]{setspace}

%% List setup; the ``hanglist`` environment will allow you to have
%% nicely-typeset enumerated lists (i.e. with the numbers hanging in
%% the margins).  You need at least version 2.1 of enumitem.sty.  If
%% you don't have enumitem installed at all, hanglist will just be an
%% alias for enumerate.
%\IfFileExists{enumitem.sty}{%
%\usepackage[loadonly]{enumitem}[2007/06/30]%
%\newlist{hanglist}{enumerate}{1}% 
%\setlist[hanglist]{label=\arabic*.}%
%\setlist[hanglist,1]{leftmargin=0pt}%
%}{%
%\newenvironment{hanglist}{\begin{enumerate}}{\end{enumerate}}%
%}

%% Comment out any of these that you don't want
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
%\usepackage{theorem}
%\usepackage{hyperref}

\IfFileExists{mathpartir.sty}{%
\usepackage{mathpartir}%
}{}

%%%%% LISTINGS package and setup
\IfFileExists{listings.sty}{%
\usepackage{listings}%
}{}





%% You want microtype.
\IfFileExists{microtype.sty}{%
\usepackage[protrusion=true,expansion=true]{microtype}%
}{}

%\pagestyle{thesisdraft}

% Surround parts of graphics with box
\usepackage{boxedminipage}

%% booktabs (thx to Nate Rosenblum for bringing this beautiful package
%% to my attention)
\IfFileExists{booktabs.sty}{%
\usepackage{booktabs}%
}{}

% This is now the recommended way for checking for PDFLaTeX:
\usepackage{ifpdf}

%% Avoid ugly "Type 3" fonts
\usepackage{lmodern}
\usepackage[LY1]{fontenc}

%% Substitute your favorite serif and sans fonts here....
\IfFileExists{tgpagella.sty}{%
% TeX Gyre pagella, like Palatino
\usepackage{tgpagella}%
}{}

\usepackage[LY1]{eulervm}

\ifpdf
\usepackage[pdftex]{graphicx}
\else
\usepackage{graphicx}
\fi

\usepackage{makeidx}
\makeindex

{\theoremstyle{plain}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{define}[thm]{Definition}
\newtheorem{exmpl}[thm]{Example}
}
{\theoremstyle{remark}
\newtheorem{rmk}[thm]{Remark}
}

\newtheoremstyle{customsty1}
{3pt}%
{3pt}%
{}% --- body font
{}% --- indent amount
{\bfseries}% --- Theorem head font
{:}% --- Punctuation after head
{.5em}% --- space after head
{}% --- theorem head spec (can be left empty, meaning 'normal')

% Define 'newtheorems' that use ``customsty1''
{\theoremstyle{customsty1} 
}


%%% NB: the ``deposit'' chapter- and page- styles should conform to UW
%%% requirements.  If you are producing a pretty version of your
%%% dissertation for web use later, you will certainly want to make
%%% your own chapter and page styles.

\makechapterstyle{deposit}{%
  \renewcommand{\chapterheadstart}{\vspace*{3em}}
  \renewcommand{\printchaptername}{}
  \renewcommand{\chapternamenum}{}
  \renewcommand{\printchapternum}{%
    \vspace{1em}\centering\Huge\scshape{Chapter \thechapter{}}:\\}% trailing h-space to add a space after the chapter number
  \renewcommand{\afterchapternum}{}
  \renewcommand{\printchaptertitle}[1]{%
    \vbox{%
      \centering % Centering the title
      \Huge\scshape
      \parbox[t]{\textwidth}{\centering ##1} % Ensures title wraps within the text width
    }
  }
  \renewcommand{\afterchaptertitle}{%
    \vskip\onelineskip \vspace{1em} \vskip\onelineskip
  }
}

\makepagestyle{deposit}

\makeatletter

\renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter: #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}

\makeevenfoot{deposit}{}{}{}
\makeoddfoot{deposit}{}{}{}
\makeevenhead{deposit}{\thepage}{}{\leftmark}
\makeoddhead{deposit}{\leftmark}{}{\thepage}
\makeatother

%%% set up page numbering for chapter pages to satisfy UW requirements
%%% NB: You will want to delete until the ``SNIP'' mark if you are
%%% making a ``nice'' copy
\copypagestyle{chapter}{plain}
\makeoddfoot{chapter}{}{}{}
\makeevenhead{chapter}{\thepage}{}{}
\makeoddhead{chapter}{}{}{\thepage}
%%% SNIP

% %%% bib nonsense
% \makeatletter
% \newenvironment{wb-bib}[1]{%
%   \chapter*{references}
% \ifnobibintoc\else 
% \phantomsection 
% \addcontentsline{toc}{chapter}{References} 
% \fi 
% \prebibhook
%   \begin{bibitemlist}{#1}}{\end{bibitemlist}\postbibhook}

% \AtBeginDocument{%
%   \@ifpackageloaded{natbib}{% natbib is loaded
%     \addtodef{\endthebibliography}{}{\vskip-\lastskip\postbibhook}
%     \@ifpackagewith{natbib}{sectionbib}{% with sectionbib option
%       \renewcommand{\bibsection}{\@memb@bsec}}%
%       {\renewcommand{\bibsection}{\@memb@bchap}}}%
%   {}
%   \@ifpackagewith{chapterbib}{sectionbib}{%
%     \renewcommand{\sectionbib}[2]{}
%     \renewcommand{\bibsection}{\@memb@bsec}}{}
% }
% \makeatother


% Bibliography stuff
\usepackage{couriers} % will allow a bolder texttt

\usepackage[colorlinks=false, hidelinks]{hyperref} % needed to ensure that back references can be hyper references
%% Get rid of ugly borders around PDF hyperlinks (e.g. for cross-references, bib entries, or URLs)
\hypersetup{pdfborder = 0 0 0}

\usepackage[
    backend=bibtex, 
    citetracker=true, 
    pagetracker=true,
    backref=true, % include location of references in manuscript
    hyperref=true, % back references are also hyperlinks
    backrefstyle=none, % do not compress list
]{biblatex}
\addbibresource{glossary.bib}

\DeclareFieldFormat{labelnumberwidth}{}
\DefineBibliographyStrings{english}{
  backrefpage={See page},
  backrefpages={See pages}
}

% Redefine \cite for bold citation key. handles most regular ones
\DeclareCiteCommand{\cite}
  {\textbf{\thefield{title}}}
  {}
  {}
  {}

  % Redefine \cite for terms that should be in tt in the text and bib citation key
\DeclareCiteCommand{\citett}
  {\textbf{\texttt{\thefield{title}}}}
  {}
  {}
  {}

% for capturing alternative keys... will render the "author" stuff in the main text
\DeclareCiteCommand{\acite}
  {\textbf{\textnormal{\thefield{author}}}} % textnormal removes bolding
  {}
  {}
  {}

% Custom driver for glossary entries
\DeclareBibliographyDriver{unpublished}{%
  \textbf{\texttt{\printfield{title}}}% Print citation key in lstinlin
  \addcolon\space% Add colon and space
  \printfield{note}% Print the note
  \newunitpunct% Clean unit separation
  \usebibmacro{pageref}% Add page numbers where cited
  \finentry% End entry
}

\DeclareBibliographyDriver{misc}{%
  \textbf{\printfield{title}}% Print citation key in bold
  \addcolon\space% Add colon and space
  \printfield{note}% Print the note
  \newunitpunct% Clean unit separation
  \usebibmacro{pageref}% Add page numbers where cited
  \finentry% End entry
}


