summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/thumb/thumb.dtx
blob: 29d5b4d68cd22d5ebcbe0f95f6edd1695270778a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
% \iffalse % thumb.dtx
%<*copyright>
% thumb macros for use with the LaTeX book class.
% $Header: thumb.dtx,v 1.0 97/12/24 14:43:14 sdc Exp $
%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 1997 Christian Holm.
%
% The thumb package is free software; you can redistribute it
% and/or modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2 of
% the License, 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @LaTeX-style-file{
%%    Author     = "Christian Holm",
%%    Version    = "1.0",
%%    Date       = "1997/12/24",
%%    Time       = "14:43:14",
%%    Filename   = "thumb.dtx",
%%    Address    = "Niels Bohr Institute of Physics
%%                  University of Copenhagen
%%                  Denmark",
%%    Email      = "cholm@fys.ku.dk (Internet)",
%%    CodeTable  = "ISO/ASCII",
%%    Keywords   = "LaTeX2e, thumb, minitoc, fancyhdr",
%%    Supported  = "yes",
%%    Abstract   = "LaTeX package for providing support for the
%%                  inclusion of ``thumb'' marks."  
%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<*driver>
\documentclass{ltxdoc}
    \EnableCrossrefs
%    \DisableCrossrefs    % use \DisableCrossrefs if the
                          % index is ready

   \RecordChanges
%   \OnlyDescription
  \CodelineIndex

   \typeout{Expect some Under- and overfull boxes}

\begin{document}
  \DocInput{thumb.dtx}
\end{document}%
%</driver>
%
% \fi
%
%\def\fileversion{v1.0} 
%\def\filedate{97/12/24}
%\def\docdate {97/12/24}
%\def\bs{{\tt\char'134}}
%\newcommand{\Lcs}[1]{{\bs\tt#1}}
%\def\SpecialOptIndex#1{%
%    \index{#1\actualchar{\protect\ttfamily#1}
%           (option)\encapchar usage}%
%    \index{options:\levelchar{\protect\ttfamily#1}\encapchar
%           usage}}
%\def\DescribeOption{\leavevmode
%   \begingroup\MakePrivateLetters\DescribeOpt}
%\def\DescribeOpt#1{\endgroup
%              \marginpar{\raggedleft\PrintDescribeMacro{#1}}%
%              \SpecialOptIndex{#1}\ignorespaces}
%\def\SpecialCountIndex#1{%
%    \index{#1\actualchar{\protect\ttfamily#1}
%           (counter)\encapchar usage}%
%    \index{counters:\levelchar{\protect\ttfamily#1}\encapchar
%           usage}}
%\def\DescribeCount{\leavevmode
%   \begingroup\MakePrivateLetters\DescribeCou}
%\def\DescribeCou#1{\endgroup
%              \marginpar{\raggedleft\PrintDescribeMacro{#1}}%
%              \SpecialCountIndex{#1}\ignorespaces}
%\def\SpecialPageIndex#1{%
%    \index{#1\actualchar{\protect\ttfamily#1}
%           (page style)\encapchar usage}%
%    \index{page styles:\levelchar{\protect\ttfamily#1}\encapchar
%           usage}}
%\def\DescribePage{\leavevmode
%   \begingroup\MakePrivateLetters\DescribePg}
%\def\DescribePg#1{\endgroup
%              \marginpar{\raggedleft\PrintDescribeMacro{#1}}%
%              \SpecialPageIndex{#1}\ignorespaces}
%\def\SpecialBoxIndex#1{%
%    \index{#1\actualchar{\protect\ttfamily#1}
%           (box)\encapchar usage}%
%    \index{box:\levelchar{\protect\ttfamily#1}\encapchar
%           usage}}
%\def\DescribeBox{\leavevmode
%   \begingroup\MakePrivateLetters\DescribeBx}
%\def\DescribeBx#1{\endgroup
%              \marginpar{\raggedleft\PrintDescribeMacro{#1}}%
%              \SpecialPageBox{#1}\ignorespaces}
%
% \DoNotIndex{\@ne,\advance,\begin,\char,\closein,\def,\DeclareOption}
% \DoNotIndex{\divide,\docdate,\else,\end,\fi,\filedate,\fileversion}
% \DoNotIndex{\framebox,\global,\ifdim,\ifeof,\ifnum,\ifx,\let,\loop}
% \DoNotIndex{\makebox,\mbox,\mutliply,\NeedsTeXFormat,\newcommand}
% \DoNotIndex{\newcount,\newdim,\newenvironment,\newif,\newsavebox}
% \DoNotIndex{\noindent,\openin,\PackageWarning,\par,\ProcessOptions}
% \DoNotIndex{\ProvidesPackage,\put,\relax,\repeat,\RequirePackage}
% \DoNotIndex{\rule,\savebox,\space,\tempa,\textsc,\tt,\undefined}
% \DoNotIndex{\usebox}
% \iffalse
% \CheckSum{881}
% \fi
% \changes{v1.0}{97/12/24}{The creation of \textsf{thumb}}
%
% \title{The \textsf{thumb}--Package\thanks{%
%    This file has version number \fileversion{} dated \filedate{}.
%    The documentation was last revised on \docdate.
%       }}
% \author{Christian Holm\thanks{This package id largely based on the
% work of Piet van Oosrum, in the package \textsf{fancyhdr}.}\\
% Niels Bohr Institute of Physics\\
% University of Copenhagen}
%
% \date{\today}
%
% \maketitle
%
% \begin{abstract}
%    This style option contains the definitions that are necessary to
%    make a \textit{thumb} index, providing an easy reference methode
%    for large books, manuals, and reference guides. 
% \end{abstract}
%
% \tableofcontents
%
% \section{Use of this package}
%
% This package puts running thumb marks in the margin, moving downward
% as the chapters increase. Also, it is possible to have an
% ``Overview'' page, contaning the chapter names and a thumb mark
% corrosponding to every chapter, and where it is positioned in the
% chapter. I think this package could be usefull for people writing
% referance guides, where quick look--up is important, or for
% anthologies or the like.
%
% This package is intented for large documents only, and should be
% used with a document class, such as \texttt{book} or \texttt{report},
% \emph{not} \texttt{article}. The reason why this is limited so, is
% because, it doesn't make sense to have thumbmarks in a docuemnt
% smaller then 30 pages.
%
% \subsection{What to do in your document source}
% 
% To use this package, include it in a document with
% \begin{quote}
%   \Lcs{usepackage[}\textsl{options}\texttt{]\{thumb\}}
% \end{quote}
%
% \DescribeOption{minitoc}
% Here \textsl{option}, can be \texttt{minitoc} for miniture table of
% contents at each chapter. This depends on package \textsf{minitoc},
% so you need to have this installed, if you want to use this feature.
%
% \DescribeOption{box}\DescribeOption{filledbox}\DescribeOption{oval}
% \DescribeOption{filledoval}
% Option \texttt{minitoc}, can be combined with \emph{one} of the
% below, or not at all. In any case, of the options below, \emph{only
% one} or less can be used.
%
% These options specify the \textit{style} of the ``thumbs''. They
% are shown in figure~\ref{tab:styles}
% \begin{figure}[htbp]
%   \setlength{\unitlength}{1cm}
%   \begin{picture}(5,10)
%     \put(0,0){\mbox{\texttt{filledbox} (defualt)}}
%     \put(5,0){\rule{3cm}{1cm}}
%     \put(0,2){\mbox{\texttt{box}}}
%     \put(5,2){\framebox(3,1)}
%     \put(0,4){\mbox{\texttt{oval}}}
%     \put(6.5,4.5){\oval(3,1)}
%     \put(0,6){\mbox{\texttt{filledoval}}}
%     \put(5,6){\circle*{0.5}}
%     \put(5,5.77){\rule{3cm}{0.5cm}}
%   \end{picture}
%   \caption{``thumb'' styles}\label{tab:styles}
% \end{figure}
%
% Notice the style \texttt{filledoval} \emph{cannot} be made any
% higher. This is due the the primitive drawning mechanisms of
% \LaTeX{} without extension packages as \textsf{epic} etc..
% 
% The \texttt{box} and \texttt{oval} style, will extend the thumbs on
% the ``overview page'', to reach over the chapter name and
% number. This will effecually ``frame'' the chapter name with the
% thumb.
%
% \subsection{Style Commands}
%
% While the general style of the ``thumbs'' are selected by option to
% the package, it is also possible to say something more via commands.
%
% \DescribeMacro{\Overviewpage} 
%
% First of, there is the ``Overview page''. To trigger this page, put
% \Lcs{Overviewpage} at the begining of your document. I think it
% should come just before the preface and the table of contents, but
% you may disagree.
%
% This page will contain, the thumbs for all the capters. plus their
% names, printed next to there corrosponding thumb mark, and the
% title, author(s) and date of the document, in a seperate cloumn of
% its own.
%
% If you use the overview page, you should proberly run you docuemnt
% through \LaTeX{} \emph{at least} three times. This is because, the
% first time, \LaTeX{} must create a file, the second time, it will
% have to adjust the space between the thumb marks, and thirdly, it
% should type set it all proberly. However, this is not that strange,
% in fact, packages like \textsf{minitoc}, may sometimes require 5
% runs, until the utput comes out right.
%
% The use of the ``Overview page'' does, however put some restrains on
% your formatting, though they are minor, and I think a have made a
% suttable compensation. More on this later.
%
% \subsection{Manipulating the ``thumbs''}
%
% There are two ways in which you can maniplute the thumb marks. It
% should come as no surpise, that these are the height and width of
% the thumbs. All you ghave to do is to set this \textsl{lengths} to
% the value, you desire. By default, they are calculated from the
% paper and text dimensions. 
%
% \DescribeMacro{\thumbwidth}\DescribeMacro{\thumbheight}
% The \textsl{lenghts} you should change are \Lcs{thumbheight} and
% \Lcs{thumbwidth}. The should be cahnge by using the \LaTeX{} command
% \Lcs{setlength\{}\textsl{length}\texttt{\}\{}\textsl{dimension}\texttt{\}} 
% where \textsl{dimension} is a valid \LaTeX{} dimension (a number
% plus a unit). 
%
% \StopEventually{}
% \iffalse
%<*package>
% \fi
%
% \section{Implementation}
% 
% First some package identification:
%    \begin{macrocode}
\def\fileversion{v1.0} 
\def\filedate{97/12/24}
\ProvidesPackage{thumb}[\filedate\space\fileversion\space thumb
                          package.]
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
%    \end{macrocode} 
%
% \subsection{Initialization}
%
% \begin{macro}{\ifhave@fancyhdr}
% Then we check to se if package \textsf{fancyhdr} is avaliable. This
% is done by a new conditional \Lcs{ifhave@fancyhdr}:
%    \begin{macrocode}
\newif\ifhave@fancyhdr
\openin\@ne fancyhdr.sty
\ifeof\@ne \else \have@fancyhdrtrue \fi
\closein\@ne \relax
%    \end{macrocode}
% \end{macro}
% If we found {\tt fancyhdr.sty} we use it.  
% Notice the rest of the package is \emph{conditional}, in the sense,
% that if \textsf{fancyhdr} isn't installed, nothing will be defined.
%     \begin{macrocode}
\ifhave@fancyhdr 
  \RequirePackage{fancyhdr}
%    \end{macrocode}
% \DescribeCount{thumb}
% Initialize the counter \texttt{thumb}, which will be used to measure
% out the distance between the ``thumbs''. 
%    \begin{macrocode}
  % 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}
  }
%    \end{macrocode}
%
% \subsection{The \Lcs{chapter} macro}
%
% \begin{macro}{\chapter}
% The chapter needs to be redefined, so that the ``overview'' page can
% be produced in a nice way. The page style is set to
% \texttt{thumbplain} so that the \texttt{plain} page style can be
% used for page that should contain \emph{no} fancy stuff at all. In
% any other respect, the \Lcs{chapter} works as usual.
%    \begin{macrocode}
  \renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                      \thispagestyle{thumbplain}%
                      \global\@topnum\z@
                      \@afterindentfalse
                      \secdef\@chapter\@schapter}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@chapter}
% However it is only the \emph{un--stared}
% form \Lcs{chapter\{...\}} that needs this modfication. The stared
% form should not create any line in the ``overview'' page, nor should
% it have a ``table of contents'' if the \texttt{minitoc} option is
% used. This have to be done before the options decleration, because
% style \textsf{minitoc} changes the \Lcs{chapter} macro. 
%    \begin{macrocode}
%\let\sv@chapter\@chapter
%\def\@chapter[#1]#2{\sv@chapter[{#1}]{#2}\relax%}
  \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
%    \end{macrocode}
% The above code is taken from \texttt{book.cls}. No changes so far.
%
% Now we put an entry in the \textsl{filename}\texttt{.ovr} file, so
% that the ``overview'' page can input it later. Notice this implies
% \LaTeX{} should be run \emph{at least} twice.
%    \begin{macrocode}
    \ifOverview
      \def\ovrout{\noexpand\secname{\@arabic\c@chapter}{#2}{\thepage}}
      \immediate\write\thumbovr{\ovrout}
    \fi
    \advance\thumbchap1
%    \end{macrocode}
% If the \texttt{minitoc} option is given, a table of contents for
% this chapter is output. Notice this implies \LaTeX{} should be run
% \emph{at least} three times.
%    \begin{macrocode}
    \ifx\thumbmini\undefined
    \else
      \minitoc
    \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\preface}
% This macro is for including a preface (a chapter with no number, but
% a entry in the table of contents and the overview page.
% 
% The macro \Lcs{Prefacename} is set to \Lcs{prefacename} if it is
% defined (as in the \textsf{babel} package), else it is set to
% ``Preface''. This means non--english users should redefine the macro
% \Lcs{prefacename}, \emph{not} \Lcs{Prefacename}.
%    \begin{macrocode}
  \ifx\prefacename\undefined
    \newcommand{\Prefacename}{Preface}
  \else
    \newcommand{\Prefacename}{\prefacename}
  \fi
%    \end{macrocode}
% A new \textsl{if} is defined, so that the overview page may use the
% \Lcs{Prefacename} \emph{only} if a preface is present. This means
% the preface should come before the overview page. 
%    \begin{macrocode}
  \newif\ifPreface
  \Prefacefalse
%    \end{macrocode}
% The command \Lcs{preface} takes an optional argument, so
% non--english users may specify another name for the preface, e.g.\
% ``Vorrede''. A new right--handed page is started, and a line is
% added to the table of contents. 
%    \begin{macrocode}
  \newcommand{\preface}[1][\Prefacename]{%
    \Prefacetrue
    \cleardoublepage
    \thispagestyle{thumbplain}
    \addcontentsline{toc}{chapter}{#1}%
%    \end{macrocode}
% Marks are set, and apropiate
% vertical space is added. Next, we take into account wether the
% document is set in two column or not.
%    \begin{macrocode}
    \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
%    \end{macrocode}
% Some commands for the overview page is defined, etc.
%    \begin{macrocode}
    \renewcommand{\Overviewname}{#1}
    \newcount\tempa
    \tempa\thepage
    \newcommand{\Overviewpage}{\the\tempa}
  }
%    \end{macrocode}    
% \end{macro}
% \subsection{Options}
%
% The options are declared. These are \texttt{minitoc, filledbox, box,
% filledoval,} and \texttt{oval}.
%
%  \begin{macro}{minitoc}
% If option \texttt{minitoc} is set, we check to see if the file
% \texttt{minito.sty} is avaliable. If it is we load it. 
%
% \begin{macro}{\ifhave@minitoc}
% To accomplish this we define a new \Lcs{if}
%    \begin{macrocode}
  \DeclareOption{minitoc}{
    \newif\ifhave@minitoc
      \openin\@ne minitoc.sty
      \ifeof\@ne \else \have@minitoctrue \fi
    \closein\@ne \relax
    \ifhave@minitoc 
      \def\thumbmini{}
%    \end{macrocode}
% Notice if you use some other language then English, you will have
% to redefine the macro \Lcs{contentsname} yourself to something
% apropriate\footnote{For example Danish users should say
% \Lcs{renewcommand\{}\Lcs{contentsname\}\{Kort oversigt\}}.}.
%
% If the option \texttt{minitoc} is not set, then put out a warning.
%    \begin{macrocode}
    \else
      \PackageWarning{thumb}{style `minitoc´ not avaliable \return
        option `minitoc' will not be used}
    \fi
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{The ``thumb'' styles}
% 
% Next the options for the thumbs styles is set. Notice, in every
% option there is a definiton of three different marks
% \Lcs{rthumb}, \Lcs{lthumb} and \Lcs{ovrthumb}. These are used on
% right--, left--handed pages and on the overview page, respectivly. 
%
% First some commands to use wit the options.
%
% Most of the dimensions are defined here also, but often not set
%  until at \Lcs{begin\{document\}}, since various packages such as
% \texttt{a4wide.sty}, may change the size of the paper etc.
%
% \begin{macro}{thumbfilledbox}
%    \begin{macrocode}
  \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}}
    }
%    \end{macrocode}
% From then on, it's is just a question of defing the thumb marks.
% 
% First the thumbmarks for right--handed pages.
%
%    \begin{macrocode}
    \def\rthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \put(\value{rthumbskip},-\the\thumbHskip){    
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
%    \end{macrocode}
% Then the thumbmarks for left--handed pages.
%
%    \begin{macrocode}
    \def\lthumb{%
      \thumbHskip\thumbchap
      \multiply\thumbHskip\value{thumbhskip}
      \begin{picture}(0,0)
        \put(-\value{lthumbskip},-\the\thumbHskip){    
          \rule{\thumbwidth}{\thumbheight}}
      \end{picture}
    }
%    \end{macrocode}
% And finally the thumbmarks for overview page.
%
%    \begin{macrocode}
    \def\ovrthumb{%
      \hspace{\thumbskip}\rule{\thumbwidth}{\thumbheight}
    }
  }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{thumbbox}
% This makes the ``thumbs'' black frames. This is pretty much the same
% as above, expect for \Lcs{lthumb}, which I had to define in a
% roundabout way.
%    \begin{macrocode}
  \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}
    }
%    \end{macrocode}
% The left--handed pages thumbs are a bit tricky. Since \LaTeX{} have
% some problem starting a picture \emph{outside} the page, I had to
% make up the left thumbs, from lines, instead of using the
% \Lcs{framebox} command, which would have been easier, but didn't work!
%
%    \begin{macrocode}
    \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}
    }
%    \end{macrocode}
% The thumbmarks for overview page are actually a bit interresting,
% since it produces a frame around the text put on the overview page
% for each chapter. The thumbs are therefore wider on the overview
% page then in the rest of the document (half the textwidth plus some
% more, aloving it to go beyod the page).
%
%    \begin{macrocode}
    \def\ovrthumb{%
      \hspace{-\overviewskip}\hspace{-2em}\raisebox{-2ex}{
      \framebox(\value{thumbovrwidth},\value{thumbheight})}
    }
  }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{thumbfilledoval}
% This makes the ``thumbs'' filled ovals. Notice, these \emph{can not}
% be higher then ca.\ 0.7cm (ca.\ 0.3 inches), due to \LaTeX{}
% handling of the macro \Lcs{circle}. \Lcs{HOLD} is used to prevent
% redifintion of \Lcs{unitlenght}.
%
% \textbf{Notice:} This style may not come out completly right. That
% is due to some rounding errors, which I didn't try to prevent,
% since I think it is only a minor bug\footnote{OK, so I was lazy
% --- you correct it!}. It is most notaciable on the overview page.
%    \begin{macrocode}
  \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{}
  }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{thumboval}
% This makes the ``thumbs'' non--filled ovals.
%
% These thumbs are a bit interresting, in a \TeX{}nical way. The
% starting point of a \Lcs{framebox}, is the lower left corner, and
% for \Lcs{rule}, is the left edge, and for \Lcs{cirle} it is the
% center. However, for \Lcs{oval}, it is the \emph{middle} of the
% oval, so some extra care must be used to put the thumbs on the
% page, when ovals is used. Again, we use the page dimensions to
% ensure the optimal layout.
%
%    \begin{macrocode}
  \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}
    }
%    \end{macrocode}
% The thumbmarks for overview page are actually a bit interresting,
% since it produces a frame around the text put on the overview page
% for each chapter. This is like the thumbs defined in the
% \texttt{box} style option.
%
%    \begin{macrocode}
    \def\ovrthumb{%
      \hspace{-2em}\oval(\value{thumbovrwidth},\value{thumbheight})
    }
  }
%    \end{macrocode}
% \end{macro}
% Now the actual option declarations.
%    \begin{macrocode}
  \DeclareOption{filledbox}{%
    \thumbfilledbox{}
  }
  \DeclareOption{box}{
    \thumbbox{}
  }
  \DeclareOption{filledoval}{
    \thumbfilledoval{}
  }
  \DeclareOption{oval}{
    \thumboval{}
  }
%    \end{macrocode}
%
% If some strange option is given, then give an error message.
%    \begin{macrocode}
  \DeclareOption*{\PackageWarning{thumb}{Unkown option: `\CurrentOption'}} 
%    \end{macrocode}
% Make the option \texttt{filledbox} default.
%    \begin{macrocode}
  \ExecuteOptions{filledbox}
  \ProcessOptions\relax
%    \end{macrocode}
%
% \subsection{Boxes for headings} 
%
% \begin{macro}{\thumbheader}
% \begin{macro}{\Overviewtitlefont}
% \begin{macro}{\Overviewauthorfont}
% \begin{macro}{\Overviewdatefont}
% First we define some commands, and there defaults, to format the 
% header fonts.
%    \begin{macrocode} 
  \newcommand{\thumbheaderfont}{\small\sl}
  \newcommand{\Overviewtitlefont}{\sf\LARGE}
  \let\Overviewauthorfont\Overviewtitlefont
  \let\Overviewdatefont\Overviewtitlefont
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\thumbtitlefont}
% \begin{macro}{\thumbauthorfont}
% \begin{macro}{\thumbdatefont}
% Then we define a new macro to control the font of the title \emph{on
% the titlepage} and nowhere else. This is done, so that the font in
% the headers may be different from the one on the titlepage. However,
% this must be considered a bug, because it means, you have to use the
% macro \Lcs{thumbtitlefont}, if you wish to change the font of the
% title on the titlepage. Otherwise, you can get strange headers!
% Also, you can only use fontmacroes, that normally change the font
% globally, e.g.\ \Lcs{tt}, \Lcs{rm}, \Lcs{bf}, \Lcs{Huge},
% \Lcs{Large}, and \emph{not} the local counterparts \Lcs{texttt},
% \Lcs{textrm}, \Lcs{textbs} etc.. \Lcs{thumbauthorfont} and
% \Lcs{thumbdatefont} work in the same way as \Lcs{thumbtitlefont}
%    \begin{macrocode}
  \newcommand{\thumbtitlefont}{}
  \newcommand{\thumbauthorfont}{}
  \newcommand{\thumbdatefont}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\thumbtitle}
% \begin{macro}{\thumbauthor}
% \begin{macro}{\thumbdate}
% \begin{macro}{\Overviewtitle}
% The next step is to make some saveboxes, and fill them with the
% title of the document.
%    \begin{macrocode}
  \newsavebox{\thumbtitle}
  \newsavebox{\thumbauthor}
  \newsavebox{\thumbdate}
  \newsavebox{\Overviewtitle}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Then we fill the boxes. this have to be done at the begin of the
% document, since, other styles might change the marks.
%    \begin{macrocode}
  \AtBeginDocument{
    \let\tmptitlefont\thumbtitlefont
    \let\thumbtitlefont\relax
    \let\tmpauthorfont\thumbauthorfont
    \let\thumbauthorfont\relax
    \let\tmpdatefont\thumbdatefont
    \let\thumbdatefont\relax
%    \end{macrocode}
% This is the tricky part. Here we set \Lcs{thumbtitlefont} to be
% void, so that any large font, or otherwise unreasonable font,
% headerwise that is, specified on the titlepage, will not affect the
% header fonts. this is why you \emph{must} use the
% \Lcs{thumbtitlefont} macro to change the bfont on the title font.  
% The \Lcs{thumbtitlefont} is restored to it original use below.
%    \begin{macrocode}
    \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
%    \end{macrocode}
%
% \begin{macro}{\chaptermark}
% \begin{macro}{\sectionmark}
% \begin{macro}{\subsectionmark}
% After having filled the boxes, we make use of them in the
% headers. If you don't like to have the title in the headers, you
% can always redefine the marks, with \Lcs{markboth\{\}\{\}} and
% \Lcs{markright\{\}\{\}}, though it should be done \emph{after} the
% \Lcs{begin\{document\}}.
%    \begin{macrocode}
    \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}}
    }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{The Appendix}
%
% \begin{macro}{\appendix}
% The command \Lcs{appendix} is redefined, so that the thumb
% marks come out running, instead of shifting up at the appendix
% \DescribeCount{appendix}
% \DescribeCount{chapter}
% \DescribeCount{section}
%    \begin{macrocode}
  \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
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The Lists}
%
% If the option \texttt{minitoc} is set, then the tableofcontents,
% should only contain the parts and and chapters (Like a ``Short Table
% of Contents'')
%    \begin{macrocode}
  \ifx\thumbmini\undefined
  \else
    \RequirePackage{minitoc}
    \setcounter{tocdepth}{0}
    \def\contentsname{Short Table of Contents}%
    \AtBeginDocument{\dominitoc}
%    \end{macrocode}
% Also, since \texttt{minitoc} redefines a lot of the behavior of the
% lists, we have to be able to print the ``List of Figures'', and
% ``List of Tables''. Now since \texttt{tocdepth} is set to 0, normally
% the above lists would \emph{not} be printed, but if we redefine the
% macroes \verb+\l@figure+ and \verb+\l@table+, wich \LaTeX{} use to
% control the beaviour of the lists, so that the first number is less
% then 0, then the lists \emph{do} get printed\footnote{This all sound
% so simple, but it tok me a couple of hours to figure it out.}.
%    \begin{macrocode}
    \renewcommand*\l@figure{\@dottedtocline{-1}{1.5em}{2.3em}}
    \let\l@table\l@figure
  \fi
%    \end{macrocode}
%
% \subsection{Page Styles}
%
% \begin{macro}{\thumbsecnum}
% First we create the macro \Lcs{thumbsecnum}, to get nice headers. It
% test if a counter is 0, if it is, then it, and \emph{all} subsequent
% counters in the section number, should not be printed. Notice, if all
% section numbers are 0, nothing is printed \emph{at all}.
%    \begin{macrocode}
  \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
  }
%    \end{macrocode}
% \end{macro}
% The macro \Lcs{thumbspace} is a length, we use when a number was
% supposed to be there, but isn't dor some reason, and so we
% want a empty space. It also used below.
%
% \DescribePage{fancynormal}
% This is he normal page style, that puts the ``thumbs'' on the page,
% and the current section name in the center of the header, and the
% current subsection number on the farmost corner of the header. The
% page number is put in the farmost footer.
%
% The macroes \emph{could} have been made so that the user could
% change them, but instead of doing that, I leave it up to the user,
% to browse the manual of \texttt{fanyhdr} and find out how to do that
%
%    \begin{macrocode}
  \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}
%    \end{macrocode}
%
% \DescribePage{plain}
% This is the page style \LaTeX{} on special pages, such as the first
% of the chapter or part, the tableofcontents, etc. 
%    \begin{macrocode}
  \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}
  }
%    \end{macrocode}
% \DescribePage{fancyoverview}
% This is the page style of the overview page. This page contains a
% ``thumb'' for every chapter of document, plus a line containing the
% chapter number and name. 
%    \begin{macrocode}
  \fancypagestyle{thumboverview}{%
    \fancyhf{}
    \fancyfoot[C]{}
    \fancyfoot[R]{}
    \fancyfoot[L]{}
    \fancyhead[C]{}
    \fancyhead[L]{}
    \fancyhead[R]{\thumboverview}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
  }
%    \end{macrocode}
%
% \subsection{Commands for the Overview page}
%
% \begin{macro}{\Ovreviewname}
% The first macro, is for deciding what the name of 
% ``Overview'' page should be. This can be refined by saying:
%
% \Lcs{renewcommand\{\bs{}Overviewname\}\{}\textsl{name\_of\_page}\texttt{\}} 
% 
%    \begin{macrocode}
  \newcommand{\Overviewname}{Overview}
%    \end{macrocode}
% \end{macro}
%
% Like above, only it sets the font.
%
% \begin{macro}{\Overviewfont}
%    \begin{macrocode}
  \newcommand{\Overviewfont}{\sf\Large}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\secname}
% This is the command that sets the individual lines on the
% ``Overview'' page. Notice how the previous defined \Lcs{ifAppendix}
% is used here, and the names of the chapters are set to align, by
% inspecting the number before.
%
% First, we put in the thumb, then we put in the text, though the
% numbers need special attention.
%    \begin{macrocode}
  \newcommand{\secname}[3]{%
    \put(0,-\value{thumbline}){\ovrthumb}
    \put(-\value{overviewskip},-\value{thumbline}){%
      {\Overviewfont
%    \end{macrocode}
% If the first number is zero, the we don't want the number on the page.
%    \begin{macrocode}
        \ifnum#1=0
          #2\dotfill\ #3
        \else
%    \end{macrocode}
% Else, the counter is put on the page, according to thier meaning. 
%    \begin{macrocode}
          \setcounter{Overviewnumber}{#1}
          \ifAppendix
            \Alph{Overviewnumber}
          \else
            \arabic{Overviewnumber}
          \fi
%    \end{macrocode}
% Then a check to see if space is need in front of the number, so that
% the numbers will come out right adjusted.
%    \begin{macrocode}
          \ifnum#1>99
            \hspace{\thumbspace}
          \else
            \ifnum#1>9
              \hspace{2\thumbspace}
            \else
              \hspace{3\thumbspace}
            \fi
          \fi
%    \end{macrocode}
% Finally, the text and page number is put on the page. 
%    \begin{macrocode}
          #2\dotfill\ #3
        \fi
      }
    }
%    \end{macrocode}
% We need to increment the \texttt{line} counter, so that the next
% line isn't put on top of this line.  
%    \begin{macrocode}
    \stepcounter{line}
    \addtocounter{thumbline}{\value{thumbhskip}}
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\thumboverview}
% This is the command used in the previous defined
% \texttt{thumboverview} page style. It does nothing fancy, expect
% check to see if the file \Lcs{\jobname.ovr} exists. If it does, it
% inputs it. Othewise it outputs a warning.
%
%    \begin{macrocode}
  \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}
  }
%    \end{macrocode}
% \end{macro}
%
% If the Overview page is not used, the \texttt{thumbhskip} counter
% still needs to be set, so we set it in any case. This is not a
% problem, since the overview page \emph{always} comes after
% \Lcs{begin\{document\}}.  
%    \begin{macrocode}
  \newcounter{thumbhskip}
  \AtBeginDocument{
    \setcounter{thumbhskip}{\value{thumbheight}}
  }
%    \end{macrocode}
% \begin{macro}{\OverviewPage}
% This is the macro to be used in the document. It typesets the
% ``Overview'' page where it is given. It is \emph{always} set on a
% right--handed page. This look best, I think (and makes the coding
% easier). Notice, the empty \Lcs{mbox} at the end is
% nessecary. Oterwise \LaTeX{} think you have asked for 3 or 4 empty
% pages, and will reduce these to 1 or zero respectivly. Figure that
% out! Also the file \textsl{jobname}\texttt{.ovr} is opened and ready
% to be written in. At the end of the document, we close it.
%
% First some counters and a new \textsl{if}, so that we may check in
% the \Lcs{chapter} macro, wether we should write to the file
% \Lcs{jobname.ovr}.
%    \begin{macrocode}
  \newcounter{Overviewnumber}
  \newcounter{line}
  \newcounter{thumbline}
  \newif\ifOverview
  \Overviewfalse
%    \end{macrocode}
% Now to the macro it self. First \Lcs{ifOverview} should test
% \textsl{true}, and the counter \texttt{thumbhskip} is reset.
% Then we open the file \Lcs{jobname.ovr} for writting, and start a
% new righthanded page. The page style is what actually does all the
% work. This is defined earlier.
%    \begin{macrocode}
  \newcommand{\OverviewPage}{%
    \Overviewtrue
    \setcounter{thumbhskip}{0}
    \newwrite\thumbovr  
    \cleardoublepage
    \thispagestyle{thumboverview}
    \ifPreface
    \else
      \newcommand{\Overviewpage}{\thepage}
    \fi
%    \end{macrocode}
% Now, we put a small paragraph containg the titlepage stuff, next to
% the overview index. The \Lcs{vfill}'s is to ensure the page will
% appear non--empty, and create appropiate vertical space.
%    \begin{macrocode}
    \vfill  
    \usebox{\Overviewtitle}
    \vfill
%    \end{document}
% The file \Lcs{jobname.ovr} is closed at the end of the document.
%    \begin{macrocode}
    \AtEndDocument{
      \closeout\thumbovr
      \typeout{(\jobname.ovr)}
    }
%    \end{macrocode}
% Then a new right--handed page is started, and we open the file
% \Lcs{jobname.ovr} for writting.
%    \begin{macrocode}
    \cleardoublepage
    \immediate\openout\thumbovr=\jobname.ovr
%    \end{macrocode}
% If the file \Lcs{jobname.ovr} wasn't found, then we do not know the
% number of chapters in the document, so we guess it to be less then
% 10 (I think thats a reasonable number --- you may differ). Also, we
% ask the user to run \LaTeX{} again, so that the thumbs may come
% out right.
%    \begin{macrocode}
    \newdimen\tempa
    \tempa\textheight
    \ifnum\value{line}>0
      \divide\tempa\value{line}
      \thumbtmp\value{thumbhskip}sp
      \multiply\thumbtmp\value{line}
%    \end{macrocode}
% Next we test to see if there are too many thumbs, or if they are to
% high, if so right an error, and prompt.
%    \begin{macrocode}
      \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
%    \end{macrocode}
% Now we that we have the (approximate) value of \texttt{thumbhskip},
% we output it to the file \Lcs{jobname.ovr}.
%    \begin{macrocode}
    \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}
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Ending}
%
% Finally, the errormessage if \texttt{fancyhdr} wasn't found.
%    \begin{macrocode}
\else
  \PackageWarning{thumb}{style `fancyhdr´ not avaliable \return
    style `thumb' will not be used}
\fi
%    \end{macrocode}
% \iffalse
%</package>
% \fi
%
% \Finale
% \PrintIndex 
% \PrintChanges
\endinput