% Classe xreport - Version 1.1
% Thomas Claveirole Octobre 2001
%  thomas.claveirole@epita.fr

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{xreport}[2001/10/23 v1.1 Extented PReport class]

%% Options need the color package
\RequirePackage{color}

%% The French option:
\newif\iffrench\frenchfalse
\DeclareOption{french}{\frenchtrue}
\DeclareOption{francais}{\ExecuteOptions{french}}

\newif\ifpdf
\ifx\pdfoutput\undefined
  \pdffalse
\else
  \pdftrue
\fi

%% The grayscale option
\DeclareOption{grayscale}{%
    \definecolor{titlecolor}{gray}{0}
    \definecolor{subtitlecolor}{gray}{0}
    \definecolor{chapterheadcolor}{gray}{0.4}
    \definecolor{chaptercolor}{gray}{0.3}
    \definecolor{seccolor}{gray}{0}
    \definecolor{subsubseccolor}{gray}{0.4}
    \definecolor{subseccolor}{gray}{0.4}
    \definecolor{desc}{gray}{0}
    \definecolor{puce}{gray}{0}
    \definecolor{partnamecolor}{gray}{0.3}
    \definecolor{partcolor}{gray}{0.4}
}

%% The rgbcolor option
\DeclareOption{rgbcolor}{%
    \definecolor{titlecolor}{rgb}{0,0.5,1} 
    \definecolor{subtitlecolor}{rgb}{0,0.5,1}
    \definecolor{chapterheadcolor}{rgb}{0,0.7,0}
    \definecolor{chaptercolor}{rgb}{0,0.5,1}
    \definecolor{seccolor}{rgb}{0,0.3,0.7}
    \definecolor{subseccolor}{rgb}{0,0.1,0.4}
    \definecolor{subsubseccolor}{rgb}{0,0,0.1}
    \definecolor{desc}{rgb}{0.4,0,0}
    \definecolor{puce}{rgb}{0.4,0,0}
    \definecolor{partnamecolor}{rgb}{0,0.5,0}
    \definecolor{partcolor}{rgb}{0,0.7,0}
}
\ExecuteOptions{rgbcolor}

\ProcessOptions\relax

%% Usefull packages
\RequirePackage[latin1]{inputenc}

%% Some graphics stuff:
\RequirePackage{palatino}
\ifpdf
  \RequirePackage[pdftex]{graphicx}
  \graphicspath{{images/}}
  \RequirePackage{thumbpdf}
\else
  \RequirePackage{graphicx}
  \graphicspath{{images/}}
\fi

\LoadClass[a4paper,11pt]{report}

\iffrench
  %% Prevent babel from overriding the itemization sybols ...
  \def\bbl@frenchitemize{}
  \def\bbl@nonfrenchitemize{}
  \RequirePackage[french]{babel}
  \selectlanguage{french}
\else
  \RequirePackage[english]{babel}
  \selectlanguage{english}
\fi

%% The \keywords command
\def\@keywords{%
  \ClassError{Foilx}{No keywords given}{%
    You must call \protect\keywords\space in the preamble
    of your document\MessageBreak
    to provide a set of keywords.}}
\newcommand\keywords[1]{\gdef\@keywords{#1}}
\@onlypreamble\keywords

%% The \subtitle command
\def\@subtitle{}
\newcommand\subtitle[1]{\gdef\@subtitle{#1}}
\@onlypreamble\subtitle

%% horizontal margins
\setlength{\hoffset}{-1in}
\setlength{\oddsidemargin}{3cm}
\setlength{\evensidemargin}{3cm}
\setlength{\textwidth}{15cm}
\setlength{\marginparsep}{0cm}
\setlength{\marginparwidth}{0cm}

%% vertical margins
\setlength{\voffset}{-1in}
\setlength{\topmargin}{2cm}
\setlength{\headheight}{20mm}
\setlength{\headsep}{10mm}
\setlength{\textheight}{20cm}
\setlength{\footskip}{2cm}

%% headers and foot
\RequirePackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\headwidth}{\textwidth}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\let\footnoterule\relax

\fancyhead{}
\fancyhead[LO,LE]{\includegraphics{logo-Headers}}
\fancyhead[RO,RE]{{\small \rightmark}}

\renewcommand{\baselinestretch}{1.1}


%% Customize title page
\let\and\relax
\renewcommand{\maketitle}%
{
    \def\and{%
	\end{tabular}%
	\hskip 1em \@plus.17fil%
	\begin{tabular}[t]{c}}%
    \begin{titlepage}
	\begin{center}
	    \vspace*{3cm}
	    {\sf \Huge \color{titlecolor} \@title \par}
	    \addvspace{1cm}
	    {\sf \Large \color{subtitlecolor} \@subtitle \par}
	    \addvspace{1.5cm}
	    {\large \@date \par}
	    \vfill
	    \ifpdf{
	      \IfFileExists{pdf/titre.png}{%
		\includegraphics[height=1.5cm]{titre}\par\addvspace{0.5cm}
	      }{
		\ClassWarning{preport}{pdf/titre.png not found.}
		\addvspace{2cm}
	      }
	    }\else{
  	      \IfFileExists{ps/titre.eps}{%
	        \includegraphics[height=1.5cm]{titre}\par\addvspace{0.5cm}
	      }{%
		\ClassWarning{preport}{ps/titre.eps not found.}
		\addvspace{2cm}
	      }
	    }\fi
	    \vfill
	    \rule{\textwidth}{1pt}
	    {\sc \large \begin{tabular}[t]{c}
		\@author
	    \end{tabular}}
	    \rule[6pt]{\textwidth}{1pt} \par
	\end{center}
	\@thanks
    \end{titlepage}
    \setcounter{footnote}{0}%
    \global\let\thanks\relax
    \global\let\maketitle\relax
    \global\let\@thanks\@empty
    \global\let\@author\@empty
    \global\let\@date\@empty
    \global\let\@title\@empty
    \global\let\title\relax
    \global\let\author\relax
    \global\let\date\relax
    \global\let\and\relax
}

%% Customize sections
\renewcommand\section{\@startsection{section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex \@minus 1ex}%
                                   {\normalfont\LARGE\sffamily
				   \color{seccolor}}}
\let\presection=\section
\def\section#1{%
  \vspace{4ex}\nopagebreak[4]%
  \presection{#1}\nopagebreak[4]%
  \vspace{-4ex}\nopagebreak[4]%
  {\nopagebreak[4]\color{seccolor}\noindent\rule{\textwidth}{0.25pt}}%
  \vspace{1ex}\nopagebreak[4]%
}

%\newcommand\sectionstar[1]{\presection*{#1}\vspace{-3ex}
%    \noindent\rule{\textwidth}{1pt}\vspace{1ex}}

%% Customize subsections
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex \@minus 1ex}%
                                     {\normalfont\Large\sffamily
				     \color{subseccolor}}}
\let\presubsection=\subsection
\def\subsection#1{%
  \vspace{2ex}
  \presubsection{#1}\nopagebreak[4]%
  \vspace{-4ex}\nopagebreak[4]%
  {\color{subseccolor}\noindent\rule{\textwidth}{0.25pt}}\nopagebreak[4]%
  \vspace{1ex}\nopagebreak[4]%
}


%% Customize subsubsections
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex \@minus 1ex}%
                                     {\normalfont\large\sffamily
				     \color{subsubseccolor}}}

%% Customize paragraphs
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em \@minus 1ex}%
                                    {\normalfont\normalsize\sffamily}}

%% Customize subparagraphs
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em \@minus 1ex}%
                                      {\normalfont\normalsize\sffamily}}
%% Customize chapters
\def\@makechapterhead#1{%
  \makebox[0pt]{\raisebox{-1.5cm}[0pt][0pt]{\hspace{21cm}\includegraphics[scale=0.4]{logo-Main}}}%
  \vspace*{20\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        %\huge\it\sffamily\color{chapterheadcolor} \@chapapp\space \thechapter
        \par\nobreak
        \vskip 5\p@
    \fi
    \interlinepenalty\@M
    \Huge\upshape\sffamily\color{chaptercolor} #1\nobreak
    \vskip 40\p@
  }}%
\def\@makeschapterhead#1{%
  \vspace*{20\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge\upshape\sffamily\color{chaptercolor}  #1\nobreak
    \vskip 40\p@
  }}%


%% Customize parts.
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\sffamily \color{partnamecolor}\partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \sffamily \color{partcolor}#2\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \Huge \sffamily #1\par}%
    \@endpart}

%% Paragraphs spacing
\setlength{\parskip}{1ex}
\let\oldtoc\tableofcontents
\renewcommand\tableofcontents{\setlength{\parskip}{0pt}
    \oldtoc\setlength{\parskip}{1ex}}

%% We use minitoc
\RequirePackage{minitoc}
\doparttoc
\renewcommand{\ptifont}{\Huge\upshape\sffamily\color{chaptercolor}}

%% The \conclusion and \introduction commands
\def\@conclusion{Conclusion}
\newcommand{\conclusion}%
	   {\chapter*{\@conclusion}\addstarredchapter{\@conclusion}}


\def\@introduction{Introduction}
\newcommand{\introduction}%
	   {\chapter*{\@introduction}
	     \pagenumbering{arabic}
	     \addstarredchapter{\@introduction}}

%% We want a special page numbering before introduction
\pagenumbering{roman}

\def\@glossaire{Glossaire}
\newcommand{\glossaire}%
	   {\chapter*{\@glossaire}
	     \addstarredchapter{\@glossaire}}

\def\@merci{Remerciements}
\newcommand{\merci}%
  {\chapter*{\@merci}\addcontentsline{toc}{chapter}{\@merci}}

%% Customize descriptions
\newlength{\descl}
\setlength{\descl}{1cm}
\renewenvironment{description}[1][\descl]{%
    \begin{list}{}{%
	\let\makelabel\descriptionlabel
	\leftmargin #1
	\labelwidth\leftmargin
	\labelsep 2mm
    }}
    {\end{list}}
\renewcommand\descriptionlabel[1]{\hspace{\labelsep}\color{desc}
    \normalfont\bfseries #1}

%% Customize itemizations
\renewcommand{\labelitemi}{\textcolor{puce}{$\bullet$}}

\RequirePackage[colorlinks,linkcolor=chaptercolor,bookmarks,bookmarksnumbered]{hyperref}

\setlength{\parsep}{\parskip}
\setlength{\itemsep}{0ex}

%% \renewenvironment{itemize}{\begin{list}{.}{0ex}}{\end{list}}

\AtBeginDocument{%
  %% \maketitle removes this command, so we've got to save it.
  \let\@@title\@title
  \hypersetup{%
    pdftitle={\@@title},
    pdfauthor={\@author},
    pdfsubject={\@date},
    pdfkeywords={\@keywords}}}



