% =====================================================================
%
% LaTeX style file for the HOL system manual
%
% =====================================================================

% ---------------------------------------------------------------------
% BOOLEAN FLAG FOR PAPER SIZE.
%
% set:   \Afourtrue    to make paper size A4
%        \Afourfalse   to make paper size 8.5 x 11 inches
% ---------------------------------------------------------------------

\newif\ifAfour
\Afourtrue

% ---------------------------------------------------------------------
% PAPER SIZE  (latex overrides these anyway)
%
% TeX expects 1 inch margins all around.
%    * a4 (european paper) is exactly 297mm high by 210mm wide
%    * 8.5x11 (american paper) is exactly 279.4mm high by 215.9mm wide
%
% 1 inch = 25.4 mm
% ---------------------------------------------------------------------

\ifAfour \hsize=159.2truemm \else \hsize=165.1truemm \fi
\ifAfour \vsize=246.2truemm \else \vsize=228.6truemm \fi

% ---------------------------------------------------------------------
% PAGE LAYOUT  
% ---------------------------------------------------------------------

\textwidth 160truemm
\textheight 225truemm

% ---------------------------------------------------------------------
% POSITION ON PAPER  Adjusted for local conditions (see \Afour above)
% ---------------------------------------------------------------------

% Double sided
\ifAfour \oddsidemargin=6.6truemm \else \oddsidemargin=8.55truemm \fi
\ifAfour \evensidemargin=-7.4truemm \else \evensidemargin=-3.45truemm \fi

% Single Sided 
%\ifAfour \oddsidemargin=6.6truemm \else \oddsidemargin=8.55truemm \fi
%\ifAfour \evensidemargin=6.6truemm \else \evensidemargin=8.55truemm \fi

\ifAfour \topmargin 1truemm \else \topmargin -4truemm \fi

% ---------------------------------------------------------------------
% MATH INDENTATION.  = \tabcolsep + three small verbatim spaces  (!)
% ---------------------------------------------------------------------
\setlength{\mathindent}{\tabcolsep}
\addtolength{\mathindent}{\the\fontdimen2\elvtt}
\addtolength{\mathindent}{\the\fontdimen2\elvtt}
\addtolength{\mathindent}{\the\fontdimen2\elvtt}

% ---------------------------------------------------------------------
% HEAD: spacing to match header macro below.
% ---------------------------------------------------------------------
\headheight 16pt
\headsep 20pt 

% ---------------------------------------------------------------------
% FOOT: page number in 12 point font
% ---------------------------------------------------------------------
\footheight 12pt
\footskip 13mm

% ---------------------------------------------------------------------
% INDENTATION: 4mm indentation
% --------------------------------------------------------------------- 
\parindent 4mm

% ---------------------------------------------------------------------
% FOOTNOTES: footnotes are in 10 point font.
%
% put 12+1-1 points between text and rule
% put 10pt between at start of footnote
% foot note rule is 40mm long
% ---------------------------------------------------------------------
\skip\footins 12pt plus 2pt minus 2pt
\footnotesep 10pt
\def\footnoterule{\kern-3\p@ \hrule width 40mm \kern 2.6\p@}

% ---------------------------------------------------------------------
% FLOATS
% ---------------------------------------------------------------------
\floatsep 12pt plus 2pt minus 2pt
\textfloatsep  20pt plus 2pt minus 4pt
\intextsep 12pt plus 2pt minus 2pt
\@maxsep 20pt

% ---------------------------------------------------------------------
% Make "@" a "letter" for definitions that follow
% ---------------------------------------------------------------------
\makeatletter   

% ---------------------------------------------------------------------
% CHAPTER HEADINGS (deriving from Larry Paulson)
% ---------------------------------------------------------------------

\def\@rulehead#1{\hrule height1pt \vskip 14pt \huge \bf 
   #1 \vskip 14pt\hrule height1pt}

\def\@makechapterhead#1{ { \parindent 0pt 
\ifnum \c@secnumdepth >\m@ne \raggedright\large\bf \@chapapp{} \thechapter\par
 \vskip 8pt \fi \raggedright \@rulehead{#1} \par 
 \nobreak \vskip 50pt } }

\def\@makeschapterhead#1{ { \parindent 0pt {\large\bf\phantom{Chapter}} \par
   \vskip 8pt \raggedright 
 \@rulehead{#1} \par \nobreak \vskip 50pt } }


% ---------------------------------------------------------------------
% PAGE FOOT, on pages that start a new chapter
% ---------------------------------------------------------------------

\def\ps@plain{\let\@mkboth\@gobbletwo
     \def\@oddhead{}\def\@oddfoot{\rm\bf\hfil\thepage
     \hfil}\def\@evenhead{}\let\@evenfoot\@oddfoot}

% ---------------------------------------------------------------------
% PAGE HEADINGS
% ---------------------------------------------------------------------

\def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}\def
  \@evenhead{\vbox{\hbox to \textwidth{\bf\thepage\hfil\bf\leftmark
	}\vskip-\prevdepth\vskip 4.5pt\hrule height0.9pt}}\def
  \@oddhead{\vbox{\hbox to \textwidth{\bf\rightmark\hfil\bf
	\thepage}\vskip-\prevdepth\vskip 4.5pt\hrule height0.9pt}}\def
  \chaptermark##1{\markboth {{\ifnum \c@secnumdepth
>\m@ne
\@chapapp\ \thechapter. \ \fi ##1}}{}}\def\sectionmark##1{\markright
{{\ifnum \c@secnumdepth >\z@
\thesection. \ \fi ##1}}}}

% ---------------------------------------------------------------------
% Table of contents
% ---------------------------------------------------------------------
\def\tableofcontents{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi\chapter*{Contents\@mkboth{Contents}{Contents}}
 \@starttoc{toc}\if@restonecol\twocolumn\fi}

% ---------------------------------------------------------------------
% Part
% ---------------------------------------------------------------------
\def\part{\cleardoublepage \thispagestyle{empty} \if@twocolumn \onecolumn
\@tempswatrue \else \@tempswafalse \fi \hbox{}\vfil \bgroup \centering
\secdef\@part\@spart} 

\def\@endpart{\par\egroup \vfil\newpage \if@twoside \hbox{}
\thispagestyle{empty} 
 \newpage 
 \fi \if@tempswa \twocolumn \fi} 

% ---------------------------------------------------------------------
% REFERENCES
%
% (1) For references in each volume use:
%
%        \begin{thebibliography} ... \end{thebibliography}
%
%     This makes the references a new chapter.
%
% (2) For case study references, also use:
%
%        \begin{thebibliography} ... \end{thebibliography}
%
%     This makes the references in a case study an unumbered section.
%
% NOTE: references in case studies should have different names than
%       those in the body of the tutorial.  (I.e. different \bibitem name).
% ---------------------------------------------------------------------

\def\thebibliography#1{\chapter*{References\@mkboth
 {References}{References}} \addcontentsline{toc}{chapter}{References}
 \list {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}\leftmargin\labelwidth
 \advance\leftmargin\labelsep
 \usecounter{enumi}}
 \def\newblock{\hskip .11em plus .33em minus -.07em}
 \sloppy
 \sfcode`\.=1000\relax}
\let\endthebibliography=\endlist

\ps@headings  %to override previous

% ---------------------------------------------------------------------
% To make the index
% ---------------------------------------------------------------------
\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
\columnseprule \z@
\columnsep 35pt\twocolumn[\@makeschapterhead{Index}]
 \@mkboth{Index}{Index}\thispagestyle{plain}
 \addcontentsline{toc}{chapter}{Index}
 \parindent\z@
 \parskip\z@ plus .3pt\relax\let\item\@idxitem}
\def\@idxitem{\par\hangindent 40pt}
\def\subitem{\par\hangindent 40pt \hspace*{20pt}}
\def\subsubitem{\par\hangindent 40pt \hspace*{30pt}}
\def\endtheindex{\if@restonecol\onecolumn\else\clearpage\fi}

% ---------------------------------------------------------------------
% Other Indexing commands
%
% autoindex is defined for indexing the thing in \DOC{thing}. 
% It translates \_ in thing to \string \_.
% ---------------------------------------------------------------------

\def\makeindex{\if@filesw \newwrite\@indexfile
  \immediate\openout\@indexfile=\jobname.idx
  \def\index{\@bsphack\begingroup
             \def\protect####1{\string####1\space}\@sanitize
             \@wrindex\@indexfile}
  \def\autoindex{\@bsphack\begingroup
             \def\protect####1{\string####1\space}
             \def\_{\string\_}\@sanitize
             \@wrindex\@indexfile}\typeout
  {Writing index file \jobname.idx }\fi}

\def\@wrindex#1#2{\let\thepage\relax
   \xdef\@gtempa{\write#1{\string
      \indexentry{#2}{\thepage}}}\endgroup\@gtempa
   \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}

\def\index{\@bsphack\begingroup \@sanitize\@index}
\def\autoindex{\@bsphack\begingroup \@sanitize\@index}

\def\@index#1{\endgroup\@esphack}

% ---------------------------------------------------------------------
% Enumeration with Roman numerals: one-level enumeration only
% ---------------------------------------------------------------------

\newcount\@myenumdepth \@myenumdepth = 0
\@definecounter{myenumi}

%\newenvironment{myenumerate}{\begin{enumerate}}{\end{enumerate}}
%  \renewcommand{\theenumi}{\roman{enumi}}
%  \renewcommand{\labelenumi}{(\roman{enumi})}}{\end{enumerate}}

\def\myenumerate{\ifnum \@myenumdepth >0 \@toodeep\else
      \advance\@myenumdepth \@ne 
       \list{(\roman{myenumi})}{\usecounter{myenumi}
            \settowidth{\labelwidth}{(iii)}
            \setlength{\leftmargin}{\labelwidth}
            \addtolength{\leftmargin}{\labelsep}
            \addtolength{\leftmargin}{\mathindent}
            \def\makelabel##1{\hss\llap{##1}}}\fi}

\let\endmyenumerate =\endlist


% ---------------------------------------------------------------------
% Enumerate envoronment for proofs in drules.tex
% ---------------------------------------------------------------------

\def\proof{\ifnum \@enumdepth >0 \@toodeep\else
      \advance\@enumdepth \@ne 
      \edef\@enumctr{enum\romannumeral\the\@enumdepth}\list
      {\csname label\@enumctr\endcsname}{\usecounter
        {\@enumctr}\setlength{\itemsep}{0.0mm}
        \setlength{\baselineskip}{13pt}
        \def\makelabel##1{\hss\llap{##1}}}\fi}

\let\endproof =\endlist

% ---------------------------------------------------------------------
% Make "@" an "other" again
% ---------------------------------------------------------------------
\makeatother



% ---------------------------------------------------------------------
% Preliminary settings etc.
% ---------------------------------------------------------------------

\renewcommand{\topfraction}{0.8}	  % 0.8 of the top page can be fig.
\renewcommand{\bottomfraction}{0.8}	  % 0.8 of the bottom page can be fig.
\renewcommand{\textfraction}{0.1}	  % 0.1 of the page must contain text
\setcounter{totalnumber}{4}	 	  % max of 4 figures per page
\setcounter{secnumdepth}{3}		  % number sections down to level 3
\setcounter{tocdepth}{2}		  % toc contains numbers to level 2
\flushbottom				  % text extends right to the bottom
