%%================================================================================
\usepackage[latin1]{inputenc}
\usepackage{fancyhdr,clock,hyperref,ifthen,color,graphicx}
\usepackage[text={7in,9.5in},centering]{geometry}
\usepackage{pdfsync}


\newboolean{JMenglish}\setboolean{JMenglish}{true}
\DeclareOption{german}{\setboolean{JMenglish}{false}}
\newboolean{JMMAC}\setboolean{JMMAC}{false}
\DeclareOption{MAC}{\setboolean{JMMAC}{true}}
\newboolean{HTML}\setboolean{HTML}{false}
\DeclareOption{HTML}{\setboolean{HTML}{true}}
\ProcessOptions


\ifthenelse{\boolean{JMMAC}}%
  {\newcommand{\BIBROOT}{/Users/Jan/JM/TeX/BiB}}
  {\newcommand{\BIBROOT}{c:/JM/TeX/BiB}}

%-- bibliography stuff --------------------------------------------------------
\usepackage[]{multibib}
\newcites{books}{Books}
\newcites{submitted}{Submitted}
\newcites{journals}{Journals}
\newcites{peerProceedings}{Journals}
\newcites{proceedings}{Journals}
\newcites{patents}{Journals}
\newcites{software}{Journals}
\newcommand{\Nocitebooks}[1]{\addtocounter{bibNr}{1}\nocitebooks{#1}}
\newcommand{\Nocitesubmitted}[1]{\addtocounter{bibNr}{1}\nocitesubmitted{#1}}
\newcommand{\Nocitejournals}[1]{\addtocounter{bibNr}{1}\nocitejournals{#1}}
\newcommand{\NocitepeerProceedings}[1]{\addtocounter{bibNr}{1}\nocitepeerProceedings{#1}}
\newcommand{\Nociteproceedings}[1]{\addtocounter{bibNr}{1}\nociteproceedings{#1}}
\newcommand{\Nocitepatents}[1]{\addtocounter{bibNr}{1}\nocitepatents{#1}}
\newcommand{\Nocitesoftware}[1]{\addtocounter{bibNr}{1}\nocitesoftware{#1}}
                        

\ifthenelse{\boolean{HTML}}{%
  \newcommand{\bookStyle}{\bibliographystylebooks{JMunsrt}}%
  \newcommand{\journalStyle}{\bibliographystylejournals{JMunsrt}}%
  \newcommand{\peerProceedingsStyle}{\bibliographystylepeerProceedings{JMunsrt}}%
  \newcommand{\proceedingsStyle}{\bibliographystyleproceedings{JMunsrt}}%
  \newcommand{\patentsStyle}{\bibliographystylepatents{JMunsrt}}%
  \newcommand{\softwareStyle}{\bibliographystylesoftware{JMunsrt}}%
 }{%
  \newcommand{\bookStyle}{\bibliographystylebooks{unsrt}}%
  \newcommand{\journalStyle}{\bibliographystylejournals{unsrt}}%
  \newcommand{\peerProceedingsStyle}{\bibliographystylepeerProceedings{unsrt}}%
  \newcommand{\proceedingsStyle}{\bibliographystyleproceedings{unsrt}}%
  \newcommand{\patentsStyle}{\bibliographystylepatents{unsrt}}%
  \newcommand{\softwareStyle}{\bibliographystylesoftware{unsrt}}%
}


\setlength{\parindent}{0mm}

\definecolor{lightblue}{rgb}{0.8,0.8,1}

\hypersetup{backref,%
  pdftitle={Publications of Jan Modersitzki},colorlinks=true,%
            linkcolor=blue,filecolor=blue,urlcolor=blue}

%-- the hyperref stuff ---------------------------------------------------------
\newcommand{\JM}{\href{http://www.cas.mcmaster.ca/~modersit}{Jan Modersitzki}}
\newcommand{\theabsref}[1]{\href{http://www.cas.mcmaster.ca/~modersit/Pubs/#1.html}{abstract}}
\newcommand{\thebibref}[1]{\href{http://www.cas.mcmaster.ca/~modersit/Pubs/#1.bib}{bib}}
\newcommand{\thepapref}[2]{\href{http://www.cas.mcmaster.ca/~modersit/Pubs/#2}{#1}}
\newcommand{\theFileName}{\url{http://www.cas.mcmaster.ca/~modersit/Pubs/TeX/PublicationsJanModersitzki.pdf}}

\newcommand{\theBook}{\vbox to0mm{%
  \hbox to\hsize{\hss\href{http://www.cas.mcmaster.ca/~modersit/Pubs/NM4IR.html}%
    {\includegraphics[width=3cm]{NM4IR-FP}}}\vss}}

\newcommand{\theBooks}{\vbox to0mm{\hbox to\hsize{\hss%
	  \mbox{\includegraphics[height=4cm]{../images/NM4IR}\hskip5mm
	        \includegraphics[height=4cm]{../images/FAIRtex}}}%
	\vss}}

%------------------------------------------------------------------------------


\newcounter{theBib}
\setcounter{theBib}{0}
\newcounter{bibNr}
\setcounter{bibNr}{0}

\newcommand{\Nocite}{\addtocounter{bibNr}{1}\nocite}

\makeatletter
\newcommand{\saveBibs}[1]{%
  %#1:\arabic{bibNr}%
  \immediate\write\@mainaux{\string\newlabel{#1}%
    {{\arabic{bibNr}}{\arabic{page}}{\arabic{subsection}}}}%
  \setcounter{bibNr}{0}}
% \renewcommand{\saveBibs}[1]{%
%   %#1:\arabic{bibNr}%
%   \immediate\write\@mainaux{\string\newcommand{\string\the#1}{{\arabic{bibNr}}}}
%   \setcounter{bibNr}{0}}
% %
\renewcommand{\saveBibs}[1]{%
  \newcounter{#1}
  \setcounter{#1}{\arabic{bibNr}}
  \setcounter{bibNr}{0}}


\renewenvironment{thebibliography}[1]
   {%\section*{\refname\@mkboth{\uppercase{\refname}}{\uppercase{\refname}}}
    \list{\@biblabel{\addtocounter{theBib}{1}\@arabic\c@theBib}}%
         {\settowidth\labelwidth{\@biblabel{#1}}%
          \leftmargin\labelwidth
          \advance\leftmargin\labelsep
          \setlength{\itemsep}{2mm}
          \setlength{\parsep}{0pt}
          \@openbib@code
          \usecounter{enumiv}%
%            \let\p@enumiv\@empty
          \renewcommand\theenumiv{\@arabic\c@theBib}}%
    \sloppy\fontsize{10}{12}\rm
    \clubpenalty4000
    \@clubpenalty \clubpenalty
    \widowpenalty4000%
    \sfcode`\.\@m}
   {\def\@noitemerr
     {\@latex@warning{Empty `thebibliography' environment}}%
    \endlist}

\makeatother

%
\newcounter{setbar}
\newcommand{\dobar}{\ifthenelse{\value{setbar}>0}{$|$}{}}

\newcommand{\JMnote}[4][paper]{\newline
  \setcounter{setbar}{0}[%
  \ifthenelse{\equal{#2}{}}{}{\theabsref{#2}\setcounter{setbar}{1}}%
  \ifthenelse{\equal{#3}{}}{}{\dobar\thebibref{#3}\setcounter{setbar}{1}}%
  \ifthenelse{\equal{#4}{}}{}{\dobar\thepapref{#1}{#4}}%
]}%
\newcommand{\JMbook}[3][Book]{\newline[\thebibref{#2}$|$\href{#3}{#1}]}%
%------------------------------------------------------------------------------

%-- other commands  -----------------------------------------------------------
\newcommand{\EG}[2]{\ifthenelse{\boolean{JMenglish}}{#1}{#2}}

%\lhead{\JM}
%\chead{Publications}
%\rhead{\today}
%\lfoot{{\tiny \copyright\ \JM}}
%\rfoot{{\tiny[{\tt \jobname.tex}, \today, \texttime}}
\pagestyle{fancy}

%\renewcommand{\sectionmark}[1]{\markboth{\thesection.\ \textsc{#1}{}}}
\renewcommand{\headrulewidth}{0mm}
\renewcommand{\footrulewidth}{0mm}
\setlength{\headheight}{8mm}
\fancyhead{}
\fancyhead{\colorbox{lightblue}{\vbox to0.7\headheight{\vss\hbox to\textwidth{%
  {\uppercase{\bf Publications -- Jan Modersitzki}}\hss\leftmark}\vss}}}
\fancyfoot{\colorbox{lightblue}{\vbox to5mm{\vss
  \hbox to\textwidth{\today\hss\bf\arabic{page}}\vss}}}

\newcommand{\block}[3][]{\pagebreak[3]\vskip3mm%
  %\ifthenelse{\equal{#1}{}}{}{\addcontentsline{toc}{#1}{#2}}
  \hbox to0mm{\colorbox{lightblue}{\hbox{\begin{minipage}{\textwidth}
  \textbf{#2}\end{minipage}}}\hss}\vskip3pt\noindent\ignorespaces}

\renewcommand{\block}[3][]{{\protect\section{#2}}}
%------------------------------------------------------------------------------
%\newcommand{\EOP}[1]{\vfill#1\par\vskip20mm}
