% inspired by http://robjhyndman.com/research/cv.sty

\usepackage{datetime,fancyhdr,xcolor,enumitem}
\usepackage[a4paper,text={17.5cm,25.5cm},centering]{geometry}
\usepackage[compact,small,bf]{titlesec}

% fonts
\usepackage[charter]{mathdesign}
\usepackage{inconsolata}

% colors
\definecolor{theblue}{rgb}{0.086,0.173,0.514}
\definecolor{thered}{rgb}{0.6,0.0,0.0}

% fancy pdf
\usepackage[colorlinks,urlcolor=theblue,linkcolor=theblue,citecolor=theblue]{hyperref}

% mailto command
\DeclareRobustCommand\mailto[1]{\href{mailto:#1}{\nolinkurl{#1}}}

% header and footer
\pagestyle{fancy}
\lhead{\fontsize{9}{12}\sf Curriculum Vitae: \@name}
\rhead{\fontsize{9}{12}\sf\thepage}
\cfoot{}

% date format
\newdateformat{df}{\monthname~\THEYEAR}
\df

% header
\def\name#1{\def\@name{#1}}
\def\address#1{\def\@address{#1}}
\def\info#1{\def\@info{#1}}
\def\maketitle{
  % add pdf metadata
  \hypersetup{pdftitle=\@name\ Curriculum Vitae,pdfauthor=\@name}
  \thispagestyle{empty}
  \vspace*{-1.4cm}
  \noindent
  {\color{thered}\Large\textbf{Curriculum Vitae}\\[0.5em]}%
  {\LARGE\textbf{\@name}\\[0.5em]}%
  \setlength{\tabcolsep}{0pt}
  \begin{tabular*}{0.55\textwidth}{l}
    \@address
  \end{tabular*}
  \setlength{\tabcolsep}{0.25em}
  \begin{tabular}{rl}
    \@info
  \end{tabular}
  \vspace*{1em}
}

% section headings
\titlelabel{}
\titlespacing*{\section}{0pt}{2ex}{1ex}
\titleformat*{\section}{\color{thered}\large\bfseries}
\titlespacing*{\subsection}{0pt}{1ex}{0.5ex}

% miscellaneous dimensions
\setlength{\parskip}{0pt}
\setlength{\headheight}{15pt}
\setlength{\tabcolsep}{0.15cm}

% listings
\setlist{itemsep=0.5\itemsep}
\setdescription{leftmargin=2em,style=nextline}

\newenvironment{dottedlist}
  {\vspace{0.5ex}\list{}{\leftmargin=2em\rightmargin=2em}\item[]
    \def\and{{\footnotesize\textbullet\space}}}
  {\endlist\vspace*{-1ex}}

% bibliography formatting
\usepackage[backend=biber,bibstyle=authortitle,sorting=none]{biblatex}

% biblatex version in texlive 2010 does not contain this definition
\defbibheading{none}{}{}{}

\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{pages}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\DeclareFieldFormat{year}{\textbf{#1}}
\DeclareFieldFormat[article]{title}{\textit{#1}}

\DeclareFieldFormat{doi}{%
  \texttt{DOI}\addcolon\space
  \ifhyperref
    {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\addspace}%
  \iffieldundef{series}
    {}
    {\newunit
     \printfield{series}%
     \setunit{\addspace}}%
  \printfield{volume}%
  %\setunit*{\adddot}%
  %\printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}%
  \setunit{\addspace}%
  %\usebibmacro{issue+date}%
  %\setunit{\addcolon\space}%
  \usebibmacro{issue}%
  \newunit}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  %\usebibmacro{in:}%
  \usebibmacro{journal+issuetitle}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \usebibmacro{note+pages}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \setunit{\addcomma\space}%
  \printfield{year}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \setunit{\adddot\space}%
  \printfield{url}
  \usebibmacro{finentry}}

\renewcommand*{\bibitem}{\item}
\defbibenvironment{bibliography}{\begin{enumerate}}{\end{enumerate}}{\bibitem}

% add all papers in the bib file.
\nocite{*}
