%% $Id$

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{scaladoc}[2003/08/27 v0.1 Scala style customization]
\RequirePackage{fourier}
\RequirePackage[scaled=0.8]{luximono}
\RequirePackage{helvet}
\RequirePackage{color}
\RequirePackage{colortbl}

% produce an acceptable typing area
\RequirePackage{a4}
\setlength{\textheight}{22.5cm}

% support for generating PDF files
\newif\ifpdf
    \ifx\pdfoutput\undefined
    \pdffalse
\else
    \pdftrue
    \pdfoutput=1
\fi

% produce nice captions
\RequirePackage[hang,small,bf]{caption2}

% include titlesec
\RequirePackage[clearempty]{titlesec}
\newcommand{\mytitlerule}{\titlerule[.5pt]}
\newcommand{\mychaptername}{Chapter}
\newcommand{\setupBookStyle}{%
        \titleformat{name=\part}%
                [block]%
                {\thispagestyle{empty}\centering\scshape\huge}%
                {\Roman{part}}%
                {1ex}%
                {}%
                [\vspace*{0.5\textheight}]%
        \titleformat{name=\chapter}%
                [display]%
                {\sffamily\bfseries\huge}%
                {\textnormal{\sffamily\LARGE\mychaptername{} \thechapter}}%
                {0pt}%
                {\vspace*{2.5mm}}%
                [\vspace*{8mm}]%
        \titleformat{name=\chapter,numberless}%
                [display]%
                {\vspace*{-30mm}\sffamily\bfseries\huge}%
                {}%
                {0pt}%
                {}%
                [\vspace*{2mm}]%
}
\@ifundefined{part}{}{\setupBookStyle}
\titleformat{name=\section}
   {\sffamily\bfseries\large}
   {\thesection}
   {1em}
   {}
\titlespacing{\section}{0pt}{*4}{*2}
\titleformat{name=\subsection}
   {\sffamily\bfseries\normalsize}
   {\thesubsection}
   {0.666em}
   {}
\titlespacing{\subsection}{0pt}{*2}{*1}
\titleformat{name=\subsubsection}
   {\sffamily\bfseries\normalsize}
   {\thesubsubsection}
   {0.55em}
   {}
\titleformat{name=\paragraph}
   [runin]
   {\rmfamily\normalsize\bfseries}
   {}
   {opt}
   {}
   [.\ ]
\titleformat{name=\subparagraph}
   [runin]
   {\itshape}
   {}
   {0pt}
   {}
   [.\ ]
\addtocounter{secnumdepth}{1}

% produce nice footers
\RequirePackage[bottom,multiple,stable]{footmisc} % flushmargin,norule removed

% produce nice headings
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{\fancyhf{}%
   \renewcommand{\headrulewidth}{0pt}%
   \renewcommand{\footrulewidth}{0pt}}
\@ifundefined{chaptermark}{}{%
  \renewcommand{\chaptermark}[1]{\markboth{#1}{}}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ \ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\sffamily\footnotesize\thepage}
\fancyhead[RE]{\sffamily\footnotesize\leftmark}
\fancyhead[LO]{\sffamily\footnotesize\rightmark}
\renewcommand{\headrulewidth}{0.5pt}

% tweak list environments to customize the spacing between items
\RequirePackage{tweaklist}
\renewcommand{\enumhooki}{\addtolength{\itemsep}{-0.32\baselineskip}}
\renewcommand{\enumhookii}{\addtolength{\itemsep}{-0.13\baselineskip}}
\renewcommand{\enumhookiii}{\addtolength{\itemsep}{-0.1\baselineskip}}
\renewcommand{\enumhookiv}{\addtolength{\itemsep}{-0.08\baselineskip}}
\renewcommand{\itemhooki}{\addtolength{\itemsep}{-0.32\baselineskip}}
\renewcommand{\itemhookii}{\addtolength{\itemsep}{-0.13\baselineskip}}
\renewcommand{\itemhookiii}{\addtolength{\itemsep}{-0.1\baselineskip}}
\renewcommand{\itemhookiv}{\addtolength{\itemsep}{-0.08\baselineskip}}

%% set latex/pdflatex specific stuff
\ifpdf
    \RequirePackage[pdftex,
                hyperindex,
                plainpages=false,
                breaklinks,
                colorlinks,
                citecolor=black,
                filecolor=black,
                linkcolor=black,
                pagecolor=black,
                urlcolor=blue]{hyperref}
    \RequirePackage[pdftex]{graphicx}
    \DeclareGraphicsExtensions{.jpg,.pdf}
    \pdfcatalog {
        /PageMode (/UseNone)
    }
    \RequirePackage{thumbpdf}
\else
    \RequirePackage[ps2pdf]{hyperref}
    \RequirePackage{graphicx}
    \DeclareGraphicsExtensions{.eps,.jpg}
\fi

\RequirePackage{listings}

% scala language description
\lstdefinelanguage{Scala}{
    morekeywords={%
        abstract,case,catch,class,def,do,else,extends,false,final,finally,%
        for,if,import,let,module,new,null,object,override,package,private,%
        protected,qualified,return,sealed,super,this,trait,true,try,type,%
        val,var,while,with,yield},%
    sensitive,%
    morecomment=[l]//,%
    morecomment=[s]{/*}{*/},%
}[keywords,comments]%

% activate the language and predefine settings
\lstset{
    language=Scala,%
    xleftmargin=4mm,%
    aboveskip=3mm,%
    belowskip=3mm,%
    fontadjust=true,%
    columns=[c]fixed,%
    keepspaces=true,%
    basewidth={0.58em, 0.53em},%
    tabsize=2,%
    basicstyle=\renewcommand{\baselinestretch}{0.95}\ttfamily,%
    commentstyle=\itshape,%
    keywordstyle=\bfseries,%
    mathescape=true,%
    escapechar=�,%
    captionpos=b,%
    framerule=0.3pt,%
    firstnumber=0,%
    numbersep=1.5mm,%
    numberstyle=\tiny,%
}

\lstdefinestyle{floating}{%
    xleftmargin=10pt,%
    xrightmargin=5pt,%
    aboveskip=4mm,%
    belowskip=4mm,%
    fontadjust=true,%
    columns=[c]flexible,%
    keepspaces=true,%
    basewidth={0.5em, 0.425em},%
    tabsize=2,%
    basicstyle=\renewcommand{\baselinestretch}{0.95}\ttfamily,%
    commentstyle=\rm,%
    keywordstyle=\bfseries,%
    mathescape=true,%
    captionpos=b,%
    framerule=0.3pt,%
    firstnumber=0,%
    numbersep=1.5mm,%
    numberstyle=\tiny,%
    float=tbp,%
    frame=tblr,%
    framesep=5pt,%
    framexleftmargin=3pt,%
    abovecaptionskip=\smallskipamount,%
    belowcaptionskip=\smallskipamount,%
} % to define: caption, label

\newcommand{\code}[1]{%
    \lstinline[%keywordstyle=,%
               flexiblecolumns=true,%
               basicstyle=\ttfamily]�#1�}




\newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}}

\newcommand{\docauthor}{Author}
\newcommand{\doctitle}{Title}
\newcommand{\docsubtitle}{DRAFT}
\newcommand{\docdate}{\today}
\newcommand{\makedoctitle}{%
  \begin{titlepage}%
  \begin{center}%
  \begin{tabular}{p{0.6\textwidth}>{\columncolor[gray]{.82}[\tabcolsep]}p{0.327\textwidth}}%
  \rowcolor[gray]{.82}\ & \  \\%
  \  & \  \\[35mm]%
  \hspace*{4mm}{\sffamily\LARGE\bfseries\parbox{0.55\textwidth}{\doctitle}} & \  \\[42mm]%
  \  & {\sffamily\normalsize \docsubtitle} \\[.5ex]%
  \  & {\sffamily\normalsize \docdate} \\[16mm]%
  \  & {\sffamily\normalsize\bfseries\parbox{0.31\textwidth}{\docauthor}} \\%
  \rowcolor[gray]{.82} \  & \  \\%
  \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{%
    \small\sc Programming Methods Laboratory}\\[-.2ex]%
  \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{%
    \small\sc EPFL}\\[-.2ex]%
  \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{%
    \small\sc Switzerland}\\[-.6ex]%
  \rowcolor[gray]{.82} \  & \  %
  \end{tabular}%
  \end{center}%
  \end{titlepage}}

\endinput
