%% Curriculum Vitae style file
%% Rob J Hyndman. Last updated 16 August 2011
%% This file may be modified, copied and redistributed without any further permission.
%% However, if you modify it, please add a note indicating it is a modification of the original.
%% The original file is available at http://robjhyndman.com/research/cv.sty

\usepackage{paralist,ragged2e,datetime}
\usepackage{hyperref,fancyhdr,enumitem,color}
\usepackage[a4paper,text={17.5cm,25.5cm},centering]{geometry}
\usepackage[compact,small,sf,bf]{titlesec}
\usepackage{kpfonts,dsfont}

\RaggedRight
\sloppy

% Header and footer
\pagestyle{fancy}
\lhead{\sf Curriculum Vitae: \@name}
\rhead{\sf\thepage}
\cfoot{}

% Date format
\newdateformat{rjh}{\monthname~\THEYEAR}
\rjh

% Header box
\def\name#1{\def\@name{#1}}
\def\info#1{\def\@info{#1}}
\newcommand{\shadebox}[3][.9]{\fcolorbox[gray]{0}{#1}{\parbox{#2}{#3}}}

\def\maketitle{
\thispagestyle{plain}
\vspace*{-1.4cm}
\shadebox[0.9]{17.3cm}{\sf\color[rgb]{.6,0,0}
\hbox to 17cm{\begin{tabular}{p{7.4cm}}
\LARGE\textbf{\@name}\\[0.3cm]
\Large\textbf{Curriculum Vitae}\\[0.6cm]
\normalsize\today
\end{tabular}
\hfill\hbox{\fontsize{9}{12}\sf
\begin{tabular}{@{}rp{7.2cm}@{}}
\@info
\end{tabular}}}
}
\vspace*{0.2cm}}


% Section headings
\titlelabel{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat*{\section}{\color[rgb]{0.6,0,0}\large\sf\bfseries}
\titlespacing{\subsection}{0pt}{1ex}{0.5ex}

% Miscellaneous dimensions
\setlength{\parskip}{0ex}
\setlength{\parindent}{0em}
\setlength{\headheight}{15pt}
\setlength{\tabcolsep}{0.15cm}
\clubpenalty = 10000
\widowpenalty = 10000
\setlist{itemsep=1pt}
\setdescription{labelwidth=1.2cm,leftmargin=1.5cm,labelindent=1.5cm,font=\rm}

% Bibliography formatting

\usepackage[sorting=ynt,bibstyle=authoryear-comp,labelyear=false,defernumbers=true,maxnames=20,firstinits=true,
uniquename=init,dashed=false]{biblatex}

\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat[article]{pages}{#1}
\DeclareFieldFormat[inproceedings]{pages}{\lowercase{pp.}#1}
\DeclareFieldFormat[incollection]{pages}{\lowercase{pp.}#1}
\DeclareFieldFormat[article]{volume}{\textbf{#1}}
\DeclareFieldFormat[article]{number}{(#1)}
\DeclareFieldFormat[article]{title}{\MakeCapital{#1}}
\DeclareFieldFormat[inproceedings]{title}{#1}
\DeclareFieldFormat{shorthandwidth}{#1}

% Don't use "In:" in bibliography. Omit urls from journal articles.
\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \setunit{\labelnamepunct}\newblock
  \MakeSentenceCase{\usebibmacro{title}}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
%  \usebibmacro{in:}%
  \usebibmacro{journal+issuetitle}%
  \newunit\newblock
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}
  \newunit\newblock
  \usebibmacro{eprint}
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

% Remove dot between volume and number in journal articles.
\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}%
  \newunit\newblock
  \usebibmacro{issue}%
  \newunit}


% Bibliography categories
\def\makebibcategory#1#2{\DeclareBibliographyCategory{#1}\defbibheading{#1}{\section*{#2}}}
\makebibcategory{books}{Books}
\makebibcategory{papers}{Refereed research papers}
\makebibcategory{chapters}{Book chapters}
\makebibcategory{conferences}{Papers in conference proceedings}
\makebibcategory{techreports}{Unpublished working papers}
\makebibcategory{bookreviews}{Book reviews}
\makebibcategory{editorials}{Editorials}
\makebibcategory{phd}{PhD thesis}
\makebibcategory{subpapers}{Submitted papers}
\makebibcategory{curpapers}{Current projects}

\setlength{\bibitemsep}{2.65pt}
\setlength{\bibhang}{.8cm}
\renewcommand{\bibfont}{\small}

\renewcommand*{\bibitem}{\addtocounter{papers}{1}\item \mbox{}\hskip-0.85cm\hbox to
0.85cm{\hfill\arabic{papers}.~~}}
\defbibenvironment{bibliography}
{\list{}
  {\setlength{\leftmargin}{\bibhang}%
   \setlength{\itemsep}{\bibitemsep}%
   \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\bibitem}

\newenvironment{publications}{\section{\LARGE Publications}\label{papersstart}\vspace*{0.2cm}\small
\titlespacing{\section}{0pt}{1.5ex}{1ex}\itemsep=0.00cm
}{\label{papersend}\addtocounter{sumpapers}{-1}\refstepcounter{sumpapers}\label{sumpapers}}

\def\printbib#1{\printbibliography[category=#1,heading=#1]\lastref{sumpapers}}

% Counters for keeping track of papers
\newcounter{papers}\setcounter{papers}{0}
\newcounter{sumpapers}\setcounter{sumpapers}{0}
\def\lastref#1{\addtocounter{#1}{\value{papers}}\setcounter{papers}{0}}

% Add all papers in the bib file.
\nocite{*}
