%%
%% This is file `thumb.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% thumb.dtx  (with options: `package')
%% 
%% Copyright (C) 1997 Christian Holm.
%% 
%% This file is NOT the source for thumb, because almost all comments
%% have been stripped from it.  It is NOT the preferred form of thumb
%% for making modifications to it.
%% 
%% Therefore you can NOT redistribute and/or modify THIS file.  You can
%% however redistribute the complete source (thumb.dtx and
%% thumb.ins) and/or modify it under the terms of the GNU General
%% Public License as published by the Free Software Foundation; either
%% version 2, or (at your option) any later version.
%% 
%% The thumb package is distributed in the hope that it will be
%% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%% 
\def\fileversion{v1.0}
\def\filedate{97/12/24}
\ProvidesPackage{thumb}[\filedate\space\fileversion\space thumb
                          package.]
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\newif\ifhave@fancyhdr
\openin\@ne fancyhdr.sty
\ifeof\@ne \else \have@fancyhdrtrue \fi
\closein\@ne \relax
\ifhave@fancyhdr
  \RequirePackage{fancyhdr}
  % Define primitive counters
  \newcount\thumbchap
  \newcount\thumbHskip
  % Define lengths
  \setlength{\unitlength}{1sp}
  \newlength{\thumbheight}
  \newlength{\thumbwidth}
  \newlength{\thumbskip}
  \newlength{\overviewskip}
  % Define counters
  \newcounter{thumbheight}
  \newcounter{thumbwidth}
  \newcounter{lthumbskip}
  \newcounter{rthumbskip}
  \newcounter{overviewskip}
  % the height of the thumbs
  \setlength{\thumbheight}{1cm}
  % the width of the thumbs
  \newdimen\thumbtmp
  \thumbtmp\paperwidth
  \advance\thumbtmp-\textwidth
  \divide\thumbtmp2
  \setlength{\thumbwidth}{\thumbtmp}
  % the skip of the overview titles
  \thumbtmp\textwidth
  \divide\thumbtmp2
  \setlength{\overviewskip}{\thumbtmp}
  % Set counters
  \AtBeginDocument{
    \setcounter{thumbheight}{\thumbheight}
    \setcounter{thumbwidth}{\thumbwidth}
    \setcounter{overviewskip}{\overviewskip}
  }
  \renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                      \thispagestyle{thumbplain}%
                      \global\@topnum\z@
                      \@afterindentfalse
                      \secdef\@chapter\@schapter}
  \def\@chapter[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \refstepcounter{chapter}%
        \typeout{\@chapapp\space\thechapter.}%
        \addcontentsline{toc}{chapter}%
          {\protect\numberline{\thechapter}#1}%
      \else
        \addcontentsline{toc}{chapter}{#1}%
      \fi
    \else
      \addcontentsline{toc}{chapter}{#1}%
    \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
    \relax
    \ifOverview
      \def\ovrout{\noexpand\secname{\@arabic\c@chapter}{#2}{\thepage}}
      \immediate\write\thumbovr{\ovrout}
    \fi
    \advance\thumbchap1
    \ifx\thumbmini\undefined
    \else
      \minitoc
    \fi
  }
  \ifx\prefacename\undefined
    \newcommand{\Prefacename}{Preface}
  \else
    \newcommand{\Prefacename}{\prefacename}
  \fi
  \newif\ifPreface
  \Prefacefalse
  \newcommand{\preface}[1][\Prefacename]{%
    \Prefacetrue
    \cleardoublepage
    \thispagestyle{thumbplain}
    \addcontentsline{toc}{chapter}{#1}%
    \chaptermark{#1}%
    \vspace*{50\p@}%
    \if@twocolumn
      \@topnewpage[{\Huge \bfseries #1}]%
    \else
      {
      \interlinepenalty\@M
      \Huge \bfseries #1
      \par\nobreak
      \vskip 40\p@
      }
      \@afterheading
    \fi
    \relax
    \renewcommand{\Overviewname}{#1}
    \newcount\tempa
    \tempa\thepage
    \newcommand{\Overviewpage}{\the\tempa}
  }
  \DeclareOption{minitoc}{
    \newif\ifhave@minitoc
      \openin\@ne minitoc.sty
      \ifeof\@ne \else \have@minitoctrue \fi
    \closein\@ne \relax
    \ifhave@minitoc
      \def\thumbmini{}
    \else
      \PackageWarning{thumb}{style `minitoc� not avaliable \return
        option `minitoc' will not be used}
    \fi
  }
  \newcommand{\thumbfilledbox}{%
    \thumbtmp\paperwidth
    \advance\thumbtmp-\textwidth
    \divide\thumbtmp2
    \divide\thumbtmp3
    \setlength{\thumbskip}{\thumbtmp}
    \typeout{Expect some overfull hbox'es in the overview page}
    \AtBeginDocument{
       \setcounter{lthumbskip}{\thumbskip}
       \setcounter{rthumbskip}{\thumbskip}
       \addtocounter{lthumbskip}{\value{thumbwidth}}
    }
    \def\rthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \put(\value{rthumbskip},-\the\thumbHskip){
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
    \def\lthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \put(-\value{lthumbskip},-\the\thumbHskip){
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
    \def\ovrthumb{%
      \hspace{\thumbskip}\rule{\thumbwidth}{\thumbheight}
    }
  }
  \newcommand{\thumbbox}{
    \thumbtmp\paperwidth
    \advance\thumbtmp-\textwidth
    \divide\thumbtmp6
    \setlength{\thumbskip}{\thumbtmp}
    \typeout{Expect some overfull hbox'es in the overvew page}
    \AtBeginDocument{
      \setcounter{rthumbskip}{\thumbskip}
      \setcounter{lthumbskip}{\thumbtmp}
      \newcounter{thumbovrwidth}
      \setcounter{thumbovrwidth}{\value{overviewskip}}
      \addtocounter{thumbovrwidth}{\value{overviewskip}}
    }
    \def\rthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \put(\value{rthumbskip},-\the\thumbHskip){
          \framebox(\value{thumbwidth},\value{thumbheight})}
      \end{picture}
    }
    \def\lthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \advance\thumbHskip-\value{thumbheight}
      \begin{picture}(0,0)
        \put(-\value{rthumbskip},-\the\thumbHskip)
          {\line(-1,0){\value{thumbwidth}}}
        \put(-\value{lthumbskip},-\the\thumbHskip){%
          \line(0,-1){\value{thumbheight}}}
        \advance\thumbHskip\value{thumbheight}
        \put(-\value{rthumbskip},-\the\thumbHskip)
          {\line(-1,0){\value{thumbwidth}}}
      \end{picture}
    }
    \def\ovrthumb{%
      \hspace{-\overviewskip}\hspace{-2em}\raisebox{-2ex}{
      \framebox(\value{thumbovrwidth},\value{thumbheight})}
    }
  }
  \newcommand{\thumbfilledoval}{
    \thumbtmp\paperwidth
    \advance\thumbtmp-\textwidth
    \divide\thumbtmp6
    \setlength{\thumbskip}{\thumbtmp}
    \setlength{\thumbheight}{983025sp}
    \typeout{Expect some overfull hbox'es in the overvew page}
    \AtBeginDocument{
      \setcounter{rthumbskip}{\thumbskip}
      \setcounter{lthumbskip}{\thumbtmp}
      \addtocounter{lthumbskip}{\value{thumbwidth}}
    }
    \def\rthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \thicklines
        \put(\value{rthumbskip},-\the\thumbHskip){
          \circle*{983025}}
        \advance\thumbHskip491513
        \put(\value{rthumbskip},-\the\thumbHskip){
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
    \def\lthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \thicklines
        \put(-\value{rthumbskip},-\the\thumbHskip){
          \circle*{983025}}
        \advance\thumbHskip491513
        \put(-\value{lthumbskip},-\the\thumbHskip){
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
    \def\ovrthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \thicklines
        \put(\value{rthumbskip},-\the\thumbHskip){
          \circle*{983025}}
        \advance\thumbHskip491513
        \put(\value{rthumbskip},-\the\thumbHskip){
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
    \def\HOLD{}
  }
  \newcommand{\thumboval}{
    \thumbtmp\paperwidth
    \advance\thumbtmp-\textwidth
    \divide\thumbtmp6
    \multiply\thumbtmp2
    \setlength{\thumbskip}{\thumbtmp}
    \AtBeginDocument{
      \setcounter{rthumbskip}{\thumbskip}
      \newcounter{thumbovrwidth}
      \setcounter{thumbovrwidth}{\value{overviewskip}}
      \addtocounter{thumbovrwidth}{\value{overviewskip}}
    }
    \def\rthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \thicklines
        \put(\value{rthumbskip},-\the\thumbHskip)
          {\oval(\value{thumbwidth},\value{thumbheight})}
        \put(\value{rthumbskip},-\the\thumbHskip)
          {\usebox{\ovalmark}}
      \end{picture}
    }
    \def\lthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \thicklines
        \put(-\value{rthumbskip},-\the\thumbHskip)
          {\oval(\value{thumbwidth},\value{thumbheight})}
        \put(-\value{rthumbskip},-\the\thumbHskip)
         {\usebox{\ovalmark}}
      \end{picture}
    }
    \def\ovrthumb{%
      \hspace{-2em}\oval(\value{thumbovrwidth},\value{thumbheight})
    }
  }
  \DeclareOption{filledbox}{%
    \thumbfilledbox{}
  }
  \DeclareOption{box}{
    \thumbbox{}
  }
  \DeclareOption{filledoval}{
    \thumbfilledoval{}
  }
  \DeclareOption{oval}{
    \thumboval{}
  }
  \DeclareOption*{\PackageWarning{thumb}{Unkown option: `\CurrentOption'}}
  \ExecuteOptions{filledbox}
  \ProcessOptions\relax
  \newcommand{\thumbheaderfont}{\small\sl}
  \newcommand{\Overviewtitlefont}{\sf\LARGE}
  \let\Overviewauthorfont\Overviewtitlefont
  \let\Overviewdatefont\Overviewtitlefont
  \newcommand{\thumbtitlefont}{}
  \newcommand{\thumbauthorfont}{}
  \newcommand{\thumbdatefont}{}
  \newsavebox{\thumbtitle}
  \newsavebox{\thumbauthor}
  \newsavebox{\thumbdate}
  \newsavebox{\Overviewtitle}
  \AtBeginDocument{
    \let\tmptitlefont\thumbtitlefont
    \let\thumbtitlefont\relax
    \let\tmpauthorfont\thumbauthorfont
    \let\thumbauthorfont\relax
    \let\tmpdatefont\thumbdatefont
    \let\thumbdatefont\relax
    \let\tmpand\and
    \let\and\par
    \savebox{\thumbtitle}
      {{\thumbheaderfont\@title}}
    \begin{lrbox}{\Overviewtitle}
      \begin{minipage}[c]{0.4\textwidth}
          \Overviewtitlefont\@title\newline
          \Overviewauthorfont\@author\newline
          \Overviewdatefont\@date\newline
        \end{minipage}
    \end{lrbox}
    \let\thumbtitlefont\tmptitlefont
    \let\thumbauthorfont\tmpauthorfont
    \let\thumbdatefont\tmpdatefont
    \let\and\tmpand
    \markboth{\usebox{\thumbtitle}}{\usebox{\thumbtitle}}
    \renewcommand{\chaptermark}[1]{
      \markboth{{\small #1}}{\usebox{\thumbtitle}}
    }
    \renewcommand{\sectionmark}[1]{
      \markboth{{\small #1}}{\usebox{\thumbtitle}}
    }
    \renewcommand{\subsectionmark}[1]{
      \markboth{{\small #1}}{\usebox{\thumbtitle}}
    }
  }
  \newif\ifAppendix
  \Appendixfalse
  \newcounter{appendix}
  \setcounter{appendix}{0}
  \renewcommand\appendix{\par
    \setcounter{appendix}{\value{chapter}}
    \setcounter{chapter}{0}%
    \setcounter{section}{0}%
    \renewcommand\chaptername{\appendixname}%
    \renewcommand\thechapter{\Alph{chapter}}
    \ifOverview
      \immediate\write\thumbovr{\noexpand\Appendixtrue}
    \fi
  }
  \ifx\thumbmini\undefined
  \else
    \RequirePackage{minitoc}
    \setcounter{tocdepth}{0}
    \def\contentsname{Short Table of Contents}%
    \AtBeginDocument{\dominitoc}
    \renewcommand*\l@figure{\@dottedtocline{-1}{1.5em}{2.3em}}
    \let\l@table\l@figure
  \fi
  \newlength{\thumbspace}
  \settowidth{\thumbspace}{9}
  \newcommand{\thumbsecnum}{
    \ifnum\value{chapter}=0
    \else
      \ifnum\value{section}=0
        \thechapter
      \else
        \ifnum\value{subsection}=0
          \thesection
        \else
          \thesubsection
        \fi
      \fi
    \fi
  }
  \fancypagestyle{thumbnormal}{
    \fancyhf{}
    \renewcommand{\footrulewidth}{\headrulewidth}
    \fancyfoot[LO]{}
    \fancyfoot[CO]{}
    \fancyfoot[RO]{\thepage}
    \fancyfoot[LE]{\thepage}
    \fancyfoot[CE]{}
    \fancyfoot[RE]{}
    \fancyhead[LO]{}
    \fancyhead[CO]{\small\leftmark}
    \fancyhead[RO]{\thumbsecnum\rthumb}
    \fancyhead[LE]{\lthumb\thumbsecnum}
    \fancyhead[CE]{\small\rightmark}
    \fancyhead[RE]{}
  }
  \pagestyle{thumbnormal}
  \fancypagestyle{thumbplain}{%
    \fancyhf{}
    \fancyfoot[C]{\thepage}
    \fancyhead[RO]{\rthumb}
    \fancyhead[LE]{\lthumb}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
  }
  \fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfoot[C]{}
    \fancyhead[R]{}
    \fancyhead[L]{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
  }
  \fancypagestyle{thumboverview}{%
    \fancyhf{}
    \fancyfoot[C]{}
    \fancyfoot[R]{}
    \fancyfoot[L]{}
    \fancyhead[C]{}
    \fancyhead[L]{}
    \fancyhead[R]{\thumboverview}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
  }
  \newcommand{\Overviewname}{Overview}
  \newcommand{\Overviewfont}{\sf\Large}
  \newcommand{\secname}[3]{%
    \put(0,-\value{thumbline}){\ovrthumb}
    \put(-\value{overviewskip},-\value{thumbline}){%
      {\Overviewfont
        \ifnum#1=0
          #2\dotfill\ #3
        \else
          \setcounter{Overviewnumber}{#1}
          \ifAppendix
            \Alph{Overviewnumber}
          \else
            \arabic{Overviewnumber}
          \fi
          \ifnum#1>99
            \hspace{\thumbspace}
          \else
            \ifnum#1>9
              \hspace{2\thumbspace}
            \else
              \hspace{3\thumbspace}
            \fi
          \fi
          #2\dotfill\ #3
        \fi
      }
    }
    \stepcounter{line}
    \addtocounter{thumbline}{\value{thumbhskip}}
  }
  \newcommand{\thumboverview}{%
    \begin{picture}(0,0)
      \IfFileExists{\jobname.ovr}{%
        \noindent
        \input{\jobname.ovr}
      }
      {
        \PackageWarning{thumb}{I couldn't finde \jobname.ovr}
        \AtEndDocument{
          \typeout{``thumbs'' set, please run LaTeX again}
      }
      }
    \end{picture}
  }
  \newcounter{thumbhskip}
  \AtBeginDocument{
    \setcounter{thumbhskip}{\value{thumbheight}}
  }
  \newcounter{Overviewnumber}
  \newcounter{line}
  \newcounter{thumbline}
  \newif\ifOverview
  \Overviewfalse
  \newcommand{\OverviewPage}{%
    \Overviewtrue
    \setcounter{thumbhskip}{0}
    \newwrite\thumbovr
    \cleardoublepage
    \thispagestyle{thumboverview}
    \ifPreface
    \else
      \newcommand{\Overviewpage}{\thepage}
    \fi
    \vfill
    \usebox{\Overviewtitle}
    \vfill
    \AtEndDocument{
      \closeout\thumbovr
      \typeout{(\jobname.ovr)}
    }
    \cleardoublepage
    \immediate\openout\thumbovr=\jobname.ovr
    \newdimen\tempa
    \tempa\textheight
    \ifnum\value{line}>0
      \divide\tempa\value{line}
      \thumbtmp\value{thumbhskip}sp
      \multiply\thumbtmp\value{line}
      \ifdim\thumbtmp>\textheight
         \PackageError{thumb}{The total height of the thumbs is larger
            then the text}{Go on now, but correct the mistake afterwards}
      \fi
    \else
      \divide\tempa10
      \AtEndDocument{
        \typeout{``thumbs'' not set right, please run LaTeX again}
      }
    \fi
    \newcounter{thumbtmp}
    \setcounter{thumbtmp}{\tempa}
    \immediate\write\thumbovr{\noexpand\setcounter{thumbhskip}{\thethumbtmp}}
    \def\ovrout{
      \noexpand\secname{0}{\noexpand\Overviewfont\noexpand\Overviewname}
      {\noexpand\Overviewpage}
    }
    \immediate\write\thumbovr{\ovrout}
  }
\else
  \PackageWarning{thumb}{style `fancyhdr� not avaliable \return
    style `thumb' will not be used}
\fi
\endinput
%%
%% End of file `thumb.sty'.
