\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{romana5}[2004/11/20 0.1]

\newif\ifpasrecueil
\pasrecueiltrue

\newif\iffrench
\frenchfalse

\newif\ifchaptitle
\chaptitletrue

\newif\if@romantoc
\@romantocfalse

\newif\iftoc
\tocfalse

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions

\LoadClass[a5paper,twoside,10pt,draft]{book}
\RequirePackage{fancyhdr}
\RequirePackage[
  includehead,headheight=15pt,headsep=10pt,
  nofoot,
  top=1cm,bottom=1.3cm,
  textwidth=10cm,
  left=2.0cm, twosideshift=.5cm
]{geometry}
\advance\tolerance by \tolerance
\emergencystretch=1em
\hfuzz=1pt

\RequirePackage[latin9]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{lmodern}
\RequirePackage{xspace}
%\RequirePackage{longtable}
\RequirePackage{graphicx}

\def\french{
\RequirePackage[frenchb]{babel}
\initiate@active@char{«}
\def«{\og\ignorespaces}%
\def»{{\fg}}%
\renewcommand\contentsname{Sommaire}
}


\def\roman@setcommand#1{\textsl{Set a #1 with \textbackslash{}#1}}

\def\roman@title       {\roman@setcommand{title}}
\def\roman@head@title  {\roman@title}
\let\roman@subtitle=\relax
\let\roman@supertitle=\relax
\def\roman@head@supertitle {\roman@supertitle}
\def\roman@author      {\roman@setcommand{author}}
\def\roman@head@author {\roman@author}
\def\roman@date        {\roman@setcommand{date}}
\let\roman@foreword=\relax
\let\roman@dedication=\relax

\newcommand\supertitle[1]{\gdef\roman@supertitle{#1}}
\newcommand\headsupertitle[1]{\gdef\roman@head@supertitle{#1}}
\renewcommand\title[1]{\gdef\roman@title{#1}}
\newcommand\headtitle[1]{\gdef\roman@head@title{#1}}
\newcommand\subtitle[1]{\gdef\roman@subtitle{#1}}
\renewcommand\author[1]{\gdef\roman@author{#1}}
\newcommand\headauthor[1]{\gdef\roman@head@author{#1}}
\renewcommand\date[1]{\gdef\roman@date{#1}}
\newcommand\foreword[2]{\gdef\roman@forewordname{#1}
                        \gdef\roman@foreword{#2}}
\newcommand\dedication[1]{\gdef\roman@dedication{#1}}

\def\romantoc{\renewcommand\thechapter{\@Roman\c@chapter}\@romantoctrue}
\def\recueil{\pasrecueilfalse}
\def\withtoc{\toctrue}
\def\nochaptertitle{\chaptitlefalse}

\def\el{$\ldots$}
\newcommand{\subscript}[1]{$_{#1}$}

\def\final{\setlength\overfullrule{0pt}}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[CE]{\roman@head@author}
\fancyhead[CO]{\MakeUppercase{\roman@head@supertitle\ \roman@head@title}}
\fancyhead[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else%
\hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \if@romantoc%
    \setlength\@tempdima{5em}%
    \else
    \setlength\@tempdima{1.5em}%
    \fi%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

\renewcommand\part{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{plain}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}

\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\bfseries \partname\nobreakspace\thepart
     %  \par
     %  \vskip 20\p@
     %\fi
     \Huge \bfseries #2\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \Huge \bfseries #1\par}%
    \@endpart}

\newcommand\notchapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{empty}%
                    \vspace*{4cm}

                    }

\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{empty}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}

\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \ifpasrecueil
                          \ifchaptitle
                           \addcontentsline{toc}{chapter}%
                                     {\protect\numberline{\thechapter}#1}%
                           \else
                           \addcontentsline{toc}{chapter}
                               {\@chapapp\space \thechapter}%
                           \fi
                         \else
                           \addcontentsline{toc}{chapter}{#1}%
                         \fi
                       \else
                         \ifchaptitle
                         \addcontentsline{toc}{chapter}{#1}%
                         \else
                         \addcontentsline{toc}{chapter}
                             {\MakeUppercase{\@chapapp}\space \thechapter}%
                         \fi
                       \fi
                    \else
                       \ifchaptitle
                       \addcontentsline{toc}{chapter}{#1}%
                       \else
                       \addcontentsline{toc}{chapter}
                           {\MakeUppercase{\@chapapp}\space \thechapter}%
                       \fi
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}


\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \ifpasrecueil
        \if@mainmatter
          \begin{center}
          \Large\bfseries --- \MakeUppercase{\@chapapp}\space \thechapter\ ---
          \end{center}
          \par\nobreak
          \vskip 20\p@
        \fi
      \fi
    \fi
    \ifchaptitle
    \interlinepenalty\@M
    \begin{center}
    \Large \bfseries #1\par\nobreak
    \end{center}
    \vskip 40\p@
    \else
    \vskip 20\p@
    \fi
  }}

\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \centerline{\Large \bfseries  \MakeUppercase{#1}}\par\nobreak
    \vskip 40\p@
  }}

\def\maketitle{
\begin{titlepage}
\begin{center}
\sffamily
\if\roman@supertitle\relax
\vspace*{5cm}

\else
\vspace*{4.4cm}
\textbf{\Large \roman@supertitle}
\medskip

\fi
\textbf{\LARGE \roman@title}
\if\roman@subtitle\relax\else
\medskip

\textbf{\Large \roman@subtitle}
\fi
\vspace{2cm}

\textbf{\large \MakeUppercase\roman@author}
\vspace{7cm}

\roman@date

\end{center}
\end{titlepage}
}

\newcommand\makeforeword{
\chapter*{\roman@forewordname}

\roman@foreword
}

\newcommand\pic[1]{
  \noindent\includegraphics[width=0.99\textwidth,keepaspectratio]{#1}
  \bigskip

}

\newcommand\picv[1]{
  \noindent\includegraphics[angle=90,width=0.99\textwidth,totalheight=.99\textheight,keepaspectratio]{#1}
  \bigskip

}

\AtBeginDocument{\maketitle

\iftoc
\tableofcontents
\fi

\if\roman@foreword\relax\else
\makeforeword
\fi

\if\roman@dedication\relax\else
\cleardoublepage

\thispagestyle{empty}
\vspace*{2cm}

\noindent\textit{\roman@dedication}
\cleardoublepage

\fi
}
