% general page/margin sizes

\setlength{\oddsidemargin}{-.25cm}
\setlength{\evensidemargin}{-.25cm}
\setlength{\topmargin}{-50pt}
\setlength{\headheight}{1.5cm}
\setlength{\textwidth}{16cm}
\setlength{\textheight}{24cm}

% spacing lengths (note that we should define our own itemize environment
% customizing the sizes with the second argument {decls} 
% cf. p112 of the LaTeX book or p59-62 of the Companion book

\setlength{\parindent}{0cm}
\setlength{\parskip}{\baselineskip}
\setlength{\partopsep}{-\baselineskip}
\setlength{\topsep}{0pt}

	% save parskip for destroy+restore (cf. cover, tbl-contents)

\newlength{\saveparskip}
\setlength{\saveparskip}{\parskip}


% To avoid underfull vbox errors due to [twosides]

\raggedbottom


% Fancy headings

\pagestyle{fancy}
\setlength{\headrulewidth}{0.8pt}

\lhead[\thepage]{\rightmark}
\chead{}
\rhead[\leftmark]{\thepage}
\lfoot{}
\cfoot{}
\rfoot{}



% New space for subsubsection numbers in the table of contents

%BEGIN LATEX
\makeatletter
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{3.8em}{3.6em}}
\makeatother
%END LATEX



% Vertical space commands

\newcommand{\BL}{\vspace{\baselineskip}}
\newcommand{\SkipUp}{\vspace{-\multicolsep}}


% Some characters in tt font

\def\bs{\char'134}
\def\lt{\char'074}
\def\gt{\char'076}
\def\lb{\char'173}
\def\rb{\char'175}
\def\us{\char'137}


% Style of a parameter

\def\Param#1{\texttt{\textit{#1}}}



% A reference to a section/page

\newcommand{\RefSP}[1]{(section~\ref{#1}, page~\pageref{#1})}


% Url in LaTeX output

\newcommand{\MyUrl}[2]{\footahref{#1}{#2}}
\newcommand{\MyUrlHtml}[2]{#2}
\newcommand{\MyEMail}[2]{#2\footnote{\texttt{#1}}}


% General environments

\newenvironment{CmdOptions}%
   {\begin{tabular}{p{4.5cm}l}}%
   {\end{tabular}}


\newenvironment{ItemizeThreeCols}%
   {\begin{multicols}{3}\raggedcolumns\begin{itemize}}%
   {\end{itemize}\end{multicols}\SkipUp}

\newenvironment{Indentation}%
   {\begin{list}{}{}%
      \item }%
   {\end{list}}

\newenvironment{Code}%
   {\begin{Indentation}\begin{tt}}%
   {\end{tt}\end{Indentation}}

\newenvironment{CodeTwoCols}[1][4cm]%
   {\begin{Indentation}\begin{tabular}{@{}p{#1}@{}l@{}}}%
   {\end{tabular}\end{Indentation}}

\def\One#1{\multicolumn{2}{@{}l}{\texttt{#1}} \\}
\def\Two#1#2{\texttt{#1} & #2\\}
\def\SkipLine{\multicolumn{2}{@{}l}{} \\}
\def\OneLine#1{\begin{Code}#1\end{Code}}
\newcommand{\OneLineTwoCols}[3][4cm]%
   {\begin{CodeTwoCols}[#1]\Two{#2}{#3}\end{CodeTwoCols}}

% fix for HeVeA info mode (\\ on a single line causes HeVeA to loop)
%
%\renewcommand{\OneLineTwoCols}[3][4cm]%
%   {\begin{CodeTwoCols}[#1]\texttt{#2} & {#3}\end{CodeTwoCols}}

\newlength{\tmplg}
\newcounter{colnbround}
\newenvironment{TabularC}[1]%
   {\setcounter{colnbround}{#1}
    \addtocounter{colnbround}{1}
    \setlength{\tmplg}{\linewidth/#1 - \tabcolsep*2 %
                       - \arrayrulewidth*\value{colnbround}/#1}%
    \par\begin{tabular*}{\linewidth}%
                      {|*{#1}{>{\raggedright\arraybackslash\hspace{0pt}}%
                         p{\the\tmplg}|}}}%
   {\end{tabular*}\par}


% For use in tabular (parameter is column width)

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}



% Image inclusion

\newcommand{\InsertImage}[1]%
   {\BL\begin{center}\includegraphics[scale=0.83]{#1}\end{center}}



% Bips description

\def\SPart#1{\textbf{#1}}
\def\Templates{\SPart{Templates}}
\def\Description{\SPart{Description}}
\def\Errors{\SPart{Errors}}
\def\Portability{\SPart{Portability}}

\newenvironment{TemplatesOneCol}%
   {\Templates\par\begin{Code}}%
   {\end{Code}}


\newenvironment{TemplatesTwoCols}%
   {\Templates\par\begin{multicols}{2}\raggedcolumns\begin{Code}}%
   {\end{Code}\end{multicols}\SkipUp}


\def\PlErrorsNone{\Errors\par None.}

\newenvironment{PlErrors}%
   {\Errors\par\begin{TabularC}{2}\hline}%
   {\end{TabularC}}

\def\ErrCond#1{#1 &}
\def\ErrTerm#1{\texttt{#1} \\ \hline}
\def\ErrTermRm#1{#1 \\ \hline}

% Index

   % new environnement to use \pagestyle{fancy} and \addcontentsline

%BEGIN LATEX
\makeatletter
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \columnseprule \z@
                \columnsep 35\p@
                \twocolumn[\section*{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem%
                \addcontentsline{toc}{section}{\numberline{}\indexname}}
               {\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
%END LATEX

\def\OneUrl#1{\ahrefurl{\texttt{#1}}}

   % One index entry
   % 1=term  2=alphabetic position  3=index term
   % 4=t/d/td (t=texttt, d=def(page nb in textbf))

\newcommand{\IdEntry}[4]%
   {\ifthenelse{\equal{#4}{t}}%
        {\texttt{#1}\index{#2@\texttt{#3}}}%
        {\ifthenelse{\equal{#4}{td}}%
             {\texttt{#1}\index{#2@\texttt{#3}|textbf}}%
             {\ifthenelse{\equal{#4}{d}}%
                  {#1\index{#2@#3|textbf}}%
                  {#1\index{#2@#3}}}}}


   % Generic index entry
   % 1=term  2=index term  3=prefix index term  4=suffix index term
   % 5=t/d/td

\newcommand{\IdxGen}[5]%
   {\ifthenelse{\equal{#2}{!*!}}%
       {\IdEntry{#1}{#1}{#3#1#4}{#5}}%
       {\IdEntry{#1}{#2}{#3#2#4}{#5}}}


   % Any word (roman font)

\newcommand{\IdxD}  [2][!*!] {\IdxGen{#2}{#1}{}{}{d}}
\newcommand{\Idx}   [2][!*!] {\IdxGen{#2}{#1}{}{}{}}

   % Keyword

\newcommand{\IdxKD} [2][!*!] {\IdxGen{#2}{#1}{}{}{td}}
\newcommand{\IdxK}  [2][!*!] {\IdxGen{#2}{#1}{}{}{t}}

   % Directive

\newcommand{\IdxDiD}[2][!*!] {\IdxGen{#2}{#1}{:- }{}{td}}
\newcommand{\IdxDi} [2][!*!] {\IdxGen{#2}{#1}{:- }{}{t}}

   % Control Construct

\newcommand{\IdxCCD}[2][!*!] {\IdxGen{#2}{#1}{}{}{td}}
\newcommand{\IdxCC} [2][!*!] {\IdxGen{#2}{#1}{}{}{t}}

   % Prolog Keyword

\newcommand{\IdxPKD}[2][!*!] {\IdxGen{#2}{#1}{}{}{td}}
\newcommand{\IdxPK} [2][!*!] {\IdxGen{#2}{#1}{}{}{t}}

   % Prolog Built-in

\newcommand{\IdxPBD}[2][!*!] {\IdxGen{#2}{#1}{}{}{td}}
\newcommand{\IdxPB} [2][!*!] {\IdxGen{#2}{#1}{}{}{t}}

   % Prolog Property

\newcommand{\IdxPPD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(property)}}{td}}
\newcommand{\IdxPP} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(property)}}{t}}

   % Prolog Global Variable

\newcommand{\IdxPGD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(global var.)}}{td}}

   % Prolog Option

\newcommand{\IdxPOD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(option)}}{td}}
\newcommand{\IdxPO} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(option)}}{t}}

   % Prolog Mode

\newcommand{\IdxPMD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(mode)}}{td}}

   % Prolog Whence

\newcommand{\IdxPWD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(whence)}}{td}}

   % Prolog File Permission

\newcommand{\IdxPXD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(permission)}}{td}}

   % Prolog Token

\newcommand{\IdxPTD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(token)}}{td}}

   % Prolog Flag

\newcommand{\IdxPFD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(flag)}}{td}}
\newcommand{\IdxPF} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(flag)}}{t}}

   % Debugger Keyword

\newcommand{\IdxDKD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(debug)}}{td}}
\newcommand{\IdxDK} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(debug)}}{t}}

   % Debugger Built-in

\newcommand{\IdxDBD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(debug)}}{td}}
\newcommand{\IdxDB} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(debug)}}{t}}

   % FD Built-in

\newcommand{\IdxFBD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(FD)}}{td}}
\newcommand{\IdxFB} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(FD)}}{t}}

   % FD Option

\newcommand{\IdxFOD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(FD option)}}{td}}

   % FD Keyword

\newcommand{\IdxFKD}[2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(FD)}}{td}}
\newcommand{\IdxFK} [2][!*!] {\IdxGen{#2}{#1}{}{ \textrm{(FD)}}{t}}
