summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/thumbs/thumbs.sty
blob: e990f8e42879c0d6c011bf8134b954942a426745 (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
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
%%
%% This is file `thumbs.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% thumbs.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: thumbs
%% Version: 2012/01/07 v1.0l
%% 
%% Copyright (C) 2010 - 2012 by
%%     H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>
%% 
%% The usual disclaimer applies:
%% If it doesn't work right that's your problem.
%% (Nevertheless, send an e-mail to the maintainer
%%  when you find an error in this package.)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is H.-Martin Muench.
%% 
%% This work consists of the main source file thumbs.dtx,
%% the README, and the derived files
%%    thumbs.sty, thumbs.pdf, thumbs.ins, thumbs.drv,
%%    thumbs-example.tex, thumbs-example.pdf.
%% 
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{thumbs}[2012/01/07 v1.0l
            Thumb marks and overview page(s) (HMM)]

%% This package allows to create a customizable thumb index,
%% providing a quick and easy reference method for large documents,
%% as well as an overview page.

\IfFileExists{tcilatex.tex}{%
  % Quite probably SWP/SW/SN
  \PackageWarningNoLine{thumbs}{%
   When compiling with SWP 5.50 Build 2960\MessageBreak%
   (copyright MacKichan Software, Inc.),\MessageBreak%
   these additional packages are needed:\MessageBreak%
   \string\usepackage[T1]{fontenc}\MessageBreak%
   \string\usepackage{amsfonts}\MessageBreak%
   \string\usepackage[math]{cellspace}\MessageBreak%
   \string\usepackage{xcolor}\MessageBreak%
   \string\pagecolor{white}\MessageBreak%
   \string\newcommand{\string\QTO}[2]{\string##2}\MessageBreak%
   especially before hyperref and thumbs,\MessageBreak%
   but best right after the \string\documentclass!%
   }%
  }{% Probably not SWP/SW/SN
   \message{^^J *** Compiling with SW(P)? ^^J%
    When compiling with SWP 5.50 Build 2960^^J%
    (copyright MacKichan Software, Inc.),^^J%
    these additional packages are needed:^^J%
    \string\usepackage[T1]{fontenc}^^J%
    \string\usepackage{amsfonts}^^J%
    \string\usepackage[math]{cellspace}^^J%
    \string\usepackage{xcolor}^^J%
    \string\pagecolor{white}^^J%
    \string\newcommand{\string\QTO}[2]{\string##2}^^J%
    especially before hyperref and thumbs,^^J%
    but best right after the \string\documentclass!^^J%
    ^^J%
    }%
   }

\RequirePackage{kvoptions}[2010/12/23]%      v3.10
\RequirePackage{atbegshi}[2011/01/30]%       v1.15
\RequirePackage{xcolor}[2007/01/21]%         v2.11
\RequirePackage{picture}[2009/10/11]%        v1.3
\RequirePackage{alphalph}[2010/04/18]%       v2.3
\RequirePackage{pageslts}[2011/08/08]%       v1.2a
\RequirePackage{pagecolor}[2011/08/08]%      v1.0c
\RequirePackage{rerunfilecheck}[2011/04/15]% v1.7
\RequirePackage{infwarerr}[2010/04/08]%      v1.3
\RequirePackage{atveryend}[2011/04/23]%      v1.7
%% \RequirePackage{atveryend}[2011/06/30]%   v1.8
%% would be needed but is currently (2012/01/07) not available at CTAN yet
%% thumbs may work with earlier versions of LaTeX2e and those packages,
%% but this was not tested. Please consider updating your LaTeX contribution
%% and packages to the most recent version (if they are not already the most
%% recent version).

\@ifl@t@r\fmtversion{2011/06/27}% or possibly even newer
{\@ifpackagelater{atveryend}{2011/06/29}%
 {% 2011/06/30, v1.8, or even more recent: OK
 }{% else: older package version, no \AtVeryVeryEnd
   \PackageWarningNoLine{thumbs}{%
     LaTeX 2011/06/27 has changed \string\enddocument\space and thus broken the\MessageBreak%
     \string\AtVeryVeryEnd\space command/hooking of atveryend package as of\MessageBreak%
     2011/04/23, v1.7. New package version 2011/06/30, v1.8, works with\MessageBreak%
     the new LaTeX format, but some older package version was loaded.\MessageBreak%
     (As of 2012/01/07, the new version is NOT available at CTAN yet.)\MessageBreak%
     For fixing this problem until the update is available,\MessageBreak%
     \string\let\string\AtVeryVeryEnd\string\AtEndAfterFileList\MessageBreak%
     is used now, fingers crossed.%
     }%
   \let\AtVeryVeryEnd\AtEndAfterFileList%
   \RequirePackage{ltxcmds}[2011/04/18]% v1.20, for \ltx@firstofone
   \AtEndAfterFileList{% if there is \AtVeryVeryEnd inside \AtEndAfterFileList
     \let\AtEndAfterFileList\ltx@firstofone%
    }
 }
}{% else: older fmtversion: OK
}

\SetupKeyvalOptions{family=thumbs,prefix=thumbs@}
\DeclareStringOption{linefill}[dots]% \thumbs@linefill
\DeclareStringOption[rule]{thumblink}[rule]
\DeclareStringOption[47pt]{minheight}[47pt]
\DeclareStringOption{height}[auto]
\DeclareStringOption{width}[auto]
\DeclareStringOption{distance}[2mm]
\DeclareStringOption{topthumbmargin}[auto]
\DeclareStringOption{bottomthumbmargin}[auto]
\DeclareBoolOption[true]{ignorehoffset}
\DeclareBoolOption[true]{ignorevoffset}
\DeclareBoolOption{nophantomsection}% false by default, but true if used
\DeclareBoolOption[true]{verbose}
\DeclareComplementaryOption{silent}{verbose}
\DeclareBoolOption{draft}
\DeclareComplementaryOption{final}{draft}
\DeclareBoolOption[false]{hidethumbs}
\DeclareStringOption{pagecolor}

\ProcessKeyvalOptions*

\ifx\thumbs@pagecolor\empty%
  \pagecolor{\thepagecolor}
\else
  \PackageWarningNoLine{thumbs}{Option pagecolor is obsolete.\MessageBreak%
    Instead the pagecolor package is used.\MessageBreak%
    Use \string\pagecolor{...}\space after \string\usepackage[...]{thumbs}\space and\MessageBreak%
    before \string\begin{document}\space to define a background colour\MessageBreak%
    of the pages}
  \pagecolor{\thumbs@pagecolor}
\fi

\ifthumbs@ignorehoffset
  \PackageInfo{thumbs}{%
    Option ignorehoffset NOT =false:\MessageBreak%
    hoffset will be ignored.\MessageBreak%
    To make thumbs regard hoffset use option\MessageBreak%
    ignorehoffset=false}
  \gdef\th@bmshoffset{0pt}
\else
  \PackageInfo{thumbs}{%
    Option ignorehoffset=false:\MessageBreak%
    hoffset will be regarded.\MessageBreak%
    This might move the thumb marks away from the paper edge}
  \gdef\th@bmshoffset{\hoffset}
\fi

\ifthumbs@ignorevoffset
  \PackageInfo{thumbs}{%
    Option ignorevoffset NOT =false:\MessageBreak%
    voffset will be ignored.\MessageBreak%
    To make thumbs regard voffset use option\MessageBreak%
    ignorevoffset=false}
  \gdef\th@bmsvoffset{-\voffset}
\else
  \PackageInfo{thumbs}{%
    Option ignorevoffset=false:\MessageBreak%
    voffset will be regarded.\MessageBreak%
    This might move the thumb mark outside of the printable area}
  \gdef\th@bmsvoffset{\voffset}
\fi

\ifx\thumbs@linefill\empty%
  \gdef\th@mbs@linefill{\hspace*{\fill}}
\else
  \def\th@mbstest{line}%
  \ifx\thumbs@linefill\th@mbstest%
    \gdef\th@mbs@linefill{\hrulefill}
  \else
    \def\th@mbstest{dots}%
    \ifx\thumbs@linefill\th@mbstest%
      \gdef\th@mbs@linefill{\dotfill}
    \else
      \PackageError{thumbs}{Option linefill with invalid value}{%
        Option linefill has value '\thumbs@linefill'.\MessageBreak%
        Valid values are '' (empty), 'line', or 'dots'.\MessageBreak%
        '' (empty) will be used now.\MessageBreak%
        }
       \gdef\th@mbs@linefill{\hspace*{\fill}}
    \fi
  \fi
\fi

\newdimen\th@mbwidthx

\newdimen\th@mbheighty% Thumb height y
\setlength{\th@mbheighty}{\z@}

\newdimen\th@mbposx
\newdimen\th@mbposy
\newdimen\th@mbposyA
\newdimen\th@mbposytop
\newdimen\th@mbposybottom
\newdimen\th@mbwidthxtoc
\newdimen\th@mbsposytocy
\newdimen\th@mbsposytocyy

\newdimen\th@mbsdistance% vertical distance between thumb marks
\ifx\thumbs@distance\empty%
  \setlength{\th@mbsdistance}{1mm}
\else
  \setlength{\th@mbsdistance}{\thumbs@distance}
\fi

\ifthumbs@verbose% \relax
\else
  \PackageInfo{thumbs}{%
    Option verbose=false (or silent=true) found:\MessageBreak%
    You will lose some information}
\fi

\newbox\ThumbsBox

\gdef\th@mbs{0}
\gdef\th@mbsmax{0}
\gdef\th@umbsperpage{0}% will be set via .aux file
\gdef\th@umbsperpagecount{0}

\gdef\th@mbtitle{}
\gdef\th@mbtext{}
\gdef\th@mbtextcolour{\thepagecolor}
\gdef\th@mbbackgroundcolour{\thepagecolor}
\gdef\th@mbcolumn{0}

\gdef\th@mbtextA{}
\gdef\th@mbtextcolourA{\thepagecolor}
\gdef\th@mbbackgroundcolourA{\thepagecolor}

\gdef\th@mbprinting{1}
\gdef\th@mbtoprint{0}
\gdef\th@mbonpage{0}
\gdef\th@mbonpagemax{0}

\gdef\th@mbcolumnnew{0}

\gdef\th@mbs@toc@level{}
\gdef\th@mbs@toc@text{}

\gdef\th@mbmaxwidth{0pt}

\gdef\th@mb@titlelabel{}

\gdef\th@mbstable{0}% number of thumb marks overview tables

\if@filesw% \relax
\else
  \PackageWarningNoLine{thumbs}{No auxiliary files allowed!\MessageBreak%
    It was not allowed to write to files.\MessageBreak%
    A lot of packages do not work without access to files\MessageBreak%
    like the .aux one. The thumbs package needs to write\MessageBreak%
    to the \jobname.tmb file. To exit press\MessageBreak%
    Ctrl+Z\MessageBreak%
    .\MessageBreak%
   }
\fi

\newcommand{\setth@mbheight}{%
  \setlength{\th@mbheighty}{\z@}
  \advance\th@mbheighty+\headheight
  \advance\th@mbheighty+\headsep
  \advance\th@mbheighty+\textheight
  \advance\th@mbheighty+\footskip
  \@tempcnta=\th@mbsmax\relax
  \ifnum\@tempcnta>1
    \divide\th@mbheighty\th@mbsmax
  \fi
  \advance\th@mbheighty-\th@mbsdistance
  \advance\th@mbheighty-\th@mbsdistance
  }

\AtBeginDocument{%
  \ifthumbs@ignorehoffset
    \gdef\th@bmshoffset{0pt}
  \else
    \gdef\th@bmshoffset{\hoffset}
  \fi
  \ifthumbs@ignorevoffset
    \gdef\th@bmsvoffset{-\voffset}
  \else
    \gdef\th@bmsvoffset{\voffset}
  \fi
  \xdef\th@mbpaperwidth{\the\paperwidth}
  \setlength{\@tempdima}{1pt}
  \ifdim \thumbs@minheight < \@tempdima% too small
    \setlength{\thumbs@minheight}{1pt}
  \else
    \ifdim \thumbs@minheight = \@tempdima% small, but ok
    \else
      \ifdim \thumbs@minheight > \@tempdima% ok
      \else
        \PackageError{thumbs}{Option minheight has invalid value}{%
          Please use a number and a length unit (e.g. mm, cm, pt)\MessageBreak%
          and no space between as value for option minheight\MessageBreak%
          and include this value+unit combination in curly brackets\MessageBreak%
          (please see the thumbs-example.tex file).\MessageBreak%
          When pressing return, minheight will now be set to 47pt.\MessageBreak%
         }
        \setlength{\thumbs@minheight}{47pt}
      \fi
    \fi
  \fi
  \setlength{\@tempdima}{\thumbs@minheight}
  \ifx\thumbs@height\empty%
    \setlength{\th@mbheighty}{\@tempdima}
  \else
    \def\th@mbstest{auto}
    \ifx\thumbs@height\th@mbstest%
      \setth@mbheight
      \ifdim \th@mbheighty < \thumbs@minheight
        \PackageWarningNoLine{thumbs}{Thumbs not high enough:\MessageBreak%
          Option height has value 'auto'. For \th@mbsmax\space thumbs per page\MessageBreak%
          this results in a thumb height of \the\th@mbheighty.\MessageBreak%
          This is lower than the minimal thumb height, \thumbs@minheight,\MessageBreak%
          therefore another thumbs column will be opened.\MessageBreak%
          If you do not want this, choose a smaller value\MessageBreak%
          for option 'minheight'%
        }
        \setlength{\th@mbheighty}{\z@}
        \advance\th@mbheighty by \@tempdima% = \thumbs@minheight
     \fi
    \else
      \ifthumbs@verbose
        \edef\thumbsinfo{\the\th@mbheighty}
        \PackageInfo{thumbs}{Now setting thumbs' height to \thumbsinfo .}
      \fi
      \setlength{\th@mbheighty}{\thumbs@height}
    \fi
  \fi
  \newread\@instreamthumb%
  \ifthumbs@verbose
    \message{^^J}
    \@PackageInfoNoLine{thumbs}{************** THUMB dimensions **************}
    \edef\thumbsinfo{\the\th@mbheighty}
    \@PackageInfoNoLine{thumbs}{The height of the thumb marks is \thumbsinfo}
  \fi
  \ifthumbs@draft
    \setlength{\th@mbwidthx}{2pt}
  \else
    \setlength{\th@mbwidthx}{\paperwidth}
    \advance\th@mbwidthx-\textwidth
    \divide\th@mbwidthx4
    \setlength{\@tempdima}{0sp}
    \ifx\thumbs@width\empty%
    \else
      \def\th@mbstest{auto}
      \ifx\thumbs@width\th@mbstest%
      \else
        \def\th@mbstest{autoauto}
        \ifx\thumbs@width\th@mbstest%
          \@ifundefined{th@mbmaxwidtha}{%
            \if@filesw%
              \gdef\th@mbmaxwidtha{0pt}
              \setlength{\th@mbwidthx}{\th@mbmaxwidtha}
              \AtEndAfterFileList{
                \PackageWarningNoLine{thumbs}{%
                  \string\th@mbmaxwidtha\space undefined.\MessageBreak%
                  Rerun to get the thumb marks width right%
                 }
              }
            \else
              \PackageError{thumbs}{%
                You cannot use option autoauto without \jobname.aux file.%
               }
            \fi
          }{%\else
            \setlength{\th@mbwidthx}{\th@mbmaxwidtha}
          }%\fi
        \else
          \ifdim \thumbs@width > \@tempdima% OK
            \setlength{\th@mbwidthx}{\thumbs@width}
          \else
            \PackageError{thumbs}{Thumbs not wide enough}{%
              Option width has value '\thumbs@width'.\MessageBreak%
              This is not a valid dimension larger than zero.\MessageBreak%
              Width will be set automatically.\MessageBreak%
             }
          \fi
        \fi
      \fi
    \fi
  \fi
  \ifthumbs@verbose
    \edef\thumbsinfo{\the\th@mbwidthx}
    \@PackageInfoNoLine{thumbs}{The width of the thumb marks is \thumbsinfo}
    \ifthumbs@draft
      \@PackageInfoNoLine{thumbs}{because thumbs package is in draft mode}
    \fi
  \fi
  % Thumb position x \th@mbposx
  \setlength{\th@mbposx}{\paperwidth}
  \advance\th@mbposx-\th@mbwidthx
  \ifthumbs@ignorehoffset
    \advance\th@mbposx-\hoffset
  \fi
  \advance\th@mbposx+1pt
  % Thumb position y \th@mbposy
  \ifx\thumbs@topthumbmargin\empty%
    \def\thumbs@topthumbmargin{auto}
  \fi
  \def\th@mbstest{auto}
  \ifx\thumbs@topthumbmargin\th@mbstest%
    \setlength{\th@mbposy}{1in}
    \advance\th@mbposy+\th@bmsvoffset
    \advance\th@mbposy+\topmargin
    \advance\th@mbposy-\th@mbsdistance
    \advance\th@mbposy+\th@mbheighty
  \else
    \setlength{\@tempdima}{-1pt}
    \ifdim \thumbs@topthumbmargin > \@tempdima% OK
    \else
      \PackageWarning{thumbs}{Thumbs column starting too high.\MessageBreak%
        Option topthumbmargin has value '\thumbs@topthumbmargin'.\MessageBreak%
        topthumbmargin will be set to -1pt.\MessageBreak%
       }
      \gdef\thumbs@topthumbmargin{-1pt}
    \fi
    \setlength{\th@mbposy}{\thumbs@topthumbmargin}
    \advance\th@mbposy-\th@mbsdistance
    \advance\th@mbposy+\th@mbheighty
  \fi
  \setlength{\th@mbposytop}{\th@mbposy}
  \ifthumbs@verbose%
    \setlength{\@tempdimc}{\th@mbposytop}
    \advance\@tempdimc-\th@mbheighty
    \advance\@tempdimc+\th@mbsdistance
    \edef\thumbsinfo{\the\@tempdimc}
    \@PackageInfoNoLine{thumbs}{The top thumb margin is \thumbsinfo}
  \fi
  % Max. thumb position y \th@mbposybottom
  \ifx\thumbs@bottomthumbmargin\empty%
    \gdef\thumbs@bottomthumbmargin{auto}
  \fi
  \def\th@mbstest{auto}
  \ifx\thumbs@bottomthumbmargin\th@mbstest%
    \setlength{\th@mbposybottom}{1in}
    \ifthumbs@ignorevoffset% \relax
    \else \advance\th@mbposybottom+\th@bmsvoffset
    \fi
    \advance\th@mbposybottom+\topmargin
    \advance\th@mbposybottom-\th@mbsdistance
    \advance\th@mbposybottom+\th@mbheighty
    \advance\th@mbposybottom+\headheight
    \advance\th@mbposybottom+\headsep
    \advance\th@mbposybottom+\textheight
    \advance\th@mbposybottom+\footskip
    \advance\th@mbposybottom-\th@mbsdistance
    \advance\th@mbposybottom-\th@mbheighty
  \else
    \setlength{\@tempdima}{\paperheight}
    \advance\@tempdima by -\thumbs@bottomthumbmargin
    \advance\@tempdima by -\th@mbposytop
    \advance\@tempdima by -\th@mbsdistance
    \advance\@tempdima by -\th@mbheighty
    \advance\@tempdima by -\th@mbsdistance
    \ifdim \@tempdima > 0sp \relax
    \else
      \setlength{\@tempdima}{\paperheight}
      \advance\@tempdima by -\th@mbposytop
      \advance\@tempdima by -\th@mbsdistance
      \advance\@tempdima by -\th@mbheighty
      \advance\@tempdima by -\th@mbsdistance
      \advance\@tempdima by -1pt
      \PackageWarning{thumbs}{Thumbs column ending too high.\MessageBreak%
        Option bottomthumbmargin has value '\thumbs@bottomthumbmargin'.\MessageBreak%
        bottomthumbmargin will be set to '\the\@tempdima'.\MessageBreak%
       }
      \xdef\thumbs@bottomthumbmargin{\the\@tempdima}
    \fi
    \setlength{\@tempdima}{\thumbs@bottomthumbmargin}
    \setlength{\@tempdimc}{-1pt}
    \ifdim \@tempdima < \@tempdimc%
      \PackageWarning{thumbs}{Thumbs column ending too low.\MessageBreak%
        Option bottomthumbmargin has value '\thumbs@bottomthumbmargin'.\MessageBreak%
        bottomthumbmargin will be set to -1pt.\MessageBreak%
       }
      \gdef\thumbs@bottomthumbmargin{-1pt}
    \fi
    \setlength{\th@mbposybottom}{\paperheight}
    \advance\th@mbposybottom-\thumbs@bottomthumbmargin
  \fi
  \ifthumbs@verbose%
    \setlength{\@tempdimc}{\paperheight}
    \advance\@tempdimc by -\th@mbposybottom
    \edef\thumbsinfo{\the\@tempdimc}
    \@PackageInfoNoLine{thumbs}{The bottom thumb margin is \thumbsinfo}
    \@PackageInfoNoLine{thumbs}{**********************************************}
    \message{^^J}
  \fi
  \advance\th@mbposy-\th@mbheighty%         because it will be advanced also for the first thumb
  \setlength{\th@mbposyA}{\th@mbposy}%      \th@mbposyA will change.
  \setlength{\th@mbsposytocyy}{\th@mbposy}% \th@mbsposytocyy shall not be changed.
  }

\newcommand{\th@mb@dvance}{%
  \advance\th@mbposy+\th@mbheighty%
  \advance\th@mbposy+\th@mbsdistance%
  \ifdim\th@mbposy>\th@mbposybottom%
    \advance\th@mbposy-\th@mbheighty%
    \advance\th@mbposy-\th@mbsdistance%
  \else%
    \advance\th@mbposy-\th@mbheighty%
    \advance\th@mbposy-\th@mbsdistance%
    \thumborigaddthumb{}{}{\string\thepagecolor}{\string\thepagecolor}%
    \th@mb@dvance%
  \fi%
  }

\newcommand{\thumbnewcolumn}{%
  \ifx\th@mbtoprint\pagesLTS@one%
    \PackageError{thumbs}{\string\thumbnewcolumn\space after \string\addthumb }{%
      On page \thepage\space (approx.) \string\addthumb\space was used and *afterwards* %
      \string\thumbnewcolumn .\MessageBreak%
      When you want to use \string\thumbnewcolumn , do not use an \string\addthumb\space %
      on the same\MessageBreak%
      page before \string\thumbnewcolumn . Thus, either remove the \string\addthumb , %
      or use a\MessageBreak%
      \string\pagebreak , \string\newpage\space etc. before \string\thumbnewcolumn .\MessageBreak%
      (And remember to use an \string\addthumb\space*after* \string\thumbnewcolumn .)\MessageBreak%
      Your command \string\thumbnewcolumn\space will be ignored now.%
     }%
  \else%
    \PackageWarning{thumbs}{%
      Starting of another column requested by command\MessageBreak%
      \string\thumbnewcolumn.\space Only use this command directly\MessageBreak%
      before an \string\addthumb\space - did you?!\MessageBreak%
     }%
    \gdef\th@mbcolumnnew{1}%
    \th@mb@dvance%
    \gdef\th@mbprinting{0}%
    \gdef\th@mbcolumnnew{2}%
  \fi%
  }

\newcommand{\addtitlethumb}[5]{%
  \xdef\th@mb@titlelabel{#5}%
  \addthumb{#1}{#2}{#3}{#4}%
  \xdef\th@mb@titlelabel{}%
  }

\gdef\th@mbsphantom{1}

\newcommand{\thumbsnophantom}{%
  \gdef\th@mbsphantom{0}%
  }

\newcommand{\addthumb}[4]{%
  \gdef\th@mbprinting{1}%
  \advance\th@mbposy\th@mbheighty%
  \advance\th@mbposy\th@mbsdistance%
  \ifdim\th@mbposy>\th@mbposybottom%
    \PackageInfo{thumbs}{%
      Thumbs column full, starting another column.\MessageBreak%
      }%
    \setlength{\th@mbposy}{\th@mbposytop}%
    \advance\th@mbposy\th@mbsdistance%
    \ifx\th@mbcolumn\pagesLTS@zero%
      \xdef\th@umbsperpagecount{\th@mbs}%
      \gdef\th@mbcolumn{1}%
    \fi%
  \fi%
  \@tempcnta=\th@mbs\relax%
  \advance\@tempcnta by 1%
  \xdef\th@mbs{\the\@tempcnta}%
  \gdef\th@mbtitle{#1}%
  \gdef\th@mbtext{#2}%
  \gdef\th@mbtextcolour{#3}%
  \gdef\th@mbbackgroundcolour{#4}%
  \settowidth{\@tempdima}{\th@mbtext\space}%
  \ifdim\@tempdima>\th@mbmaxwidth%
    \xdef\th@mbmaxwidth{\the\@tempdima}%
  \fi%
  \ifdim\@tempdima>\th@mbwidthx%
    \ifthumbs@draft% \relax
    \else%
      \edef\thumbsinfoa{\the\th@mbwidthx}
      \edef\thumbsinfob{\the\@tempdima}
      \PackageWarning{thumbs}{%
        Thumb mark too small (width: \thumbsinfoa )\MessageBreak%
        or its text too wide (width: \thumbsinfob )\MessageBreak%
       }%
    \fi%
  \fi%
  \@ifundefined{Hy@Warning}{% hyperref not loaded
    }{% hyperref loaded
     \ifthumbs@nophantomsection% \relax
     \else%
       \ifx\th@mbsphantom\pagesLTS@one%
         \phantomsection%
       \else%
         \gdef\th@mbsphantom{1}%
       \fi%
     \fi%
     }%
  \label{thumbs.\th@mbs}%
  \if@filesw%
    \ifx\th@mb@titlelabel\empty%
      \addtocontents{tmb}{\string\thumbcontents{#1}{#2}{#3}{#4}{\thepage}{thumbs.\th@mbs}{\th@mbcolumnnew}}%
    \else%
      \addtocounter{page}{-1}%
      \edef\th@mb@page{\thepage}%
      \addtocontents{tmb}{\string\thumbcontents{#1}{#2}{#3}{#4}{\th@mb@page}{\th@mb@titlelabel}{\th@mbcolumnnew}}%
      \addtocounter{page}{+1}%
    \fi%
 %\else there is a problem, but the according warning message was already given earlier.
  \fi%
  \ifx\th@mbcolumnnew\pagesLTS@one%
  \else%
    \@tempcnta=\th@mbonpage\relax%
    \advance\@tempcnta by 1%
    \xdef\th@mbonpage{\the\@tempcnta}%
  \fi%
  \ifx\th@mbtoprint\pagesLTS@zero%
  \else%
    \ifx\th@mbcolumnnew\pagesLTS@zero%
      \PackageWarning{thumbs}{More than one thumb at one page:\MessageBreak%
        You placed more than one thumb mark (at least \th@mbonpage)\MessageBreak%
        on page \thepage \space (page is approximately).\MessageBreak%
        Maybe insert a page break?\MessageBreak%
       }%
    \fi%
  \fi%
  \ifnum\th@mbonpage=1%
    \ifnum\th@mbonpagemax>0% \relax
    \else \gdef\th@mbonpagemax{1}%
    \fi%
    \gdef\th@mbtextA{#2}%
    \gdef\th@mbtextcolourA{#3}%
    \gdef\th@mbbackgroundcolourA{#4}%
    \setlength{\th@mbposyA}{\th@mbposy}%
  \else%
    \ifx\th@mbcolumnnew\pagesLTS@zero%
      \@tempcnta=1\relax%
      \edef\th@mbonpagetest{\the\@tempcnta}%
      \@whilenum\th@mbonpagetest<\th@mbonpage\do{%
       \advance\@tempcnta by 1%
       \xdef\th@mbonpagetest{\the\@tempcnta}%
       \ifnum\th@mbonpage=\th@mbonpagetest%
         \ifnum\th@mbonpagemax<\th@mbonpage%
           \xdef\th@mbonpagemax{\th@mbonpage}%
         \fi%
         \edef\th@mbtmpdef{\csname th@mbtext\AlphAlph{\the\@tempcnta}\endcsname}%
         \expandafter\gdef\th@mbtmpdef{#2}%
         \edef\th@mbtmpdef{\csname th@mbtextcolour\AlphAlph{\the\@tempcnta}\endcsname}%
         \expandafter\gdef\th@mbtmpdef{#3}%
         \edef\th@mbtmpdef{\csname th@mbbackgroundcolour\AlphAlph{\the\@tempcnta}\endcsname}%
         \expandafter\gdef\th@mbtmpdef{#4}%
       \fi%
      }%
    \else%
      \ifnum\th@mbonpagemax<\th@mbonpage%
        \xdef\th@mbonpagemax{\th@mbonpage}%
      \fi%
    \fi%
  \fi%
  \ifx\th@mbcolumnnew\pagesLTS@two%
    \gdef\th@mbcolumnnew{0}%
  \fi%
  \gdef\th@mbtoprint{1}%
  }

\newcommand{\stopthumb}{\gdef\th@mbprinting{0}}

\newcommand{\continuethumb}{\gdef\th@mbprinting{1}}

\newcommand{\thumbcontents}[7]{%
  \advance\th@mbposy\th@mbheighty%
  \advance\th@mbposy\th@mbsdistance%
  \ifdim\th@mbposy>\th@mbposybottom%
    \setlength{\th@mbposy}{\th@mbposytop}%
    \advance\th@mbposy\th@mbsdistance%
  \fi%
  \def\th@mb@tmp@title{#1}%
  \def\th@mb@tmp@text{#2}%
  \def\th@mb@tmp@textcolour{#3}%
  \def\th@mb@tmp@backgroundcolour{#4}%
  \def\th@mb@tmp@page{#5}%
  \def\th@mb@tmp@label{#6}%
  \def\th@mb@tmp@column{#7}%
  \ifx\th@mb@tmp@column\pagesLTS@two%
    \def\th@mb@tmp@column{0}%
  \fi%
  \setlength{\th@mbwidthxtoc}{\paperwidth}%
  \advance\th@mbwidthxtoc-1in%
  \def\th@mbstest{r}%
  \ifx\th@mbstest\th@mbsprintpage% r
    \advance\th@mbwidthxtoc-\oddsidemargin%
    \setlength{\@tempdimc}{1in}%
    \advance\@tempdimc+\oddsidemargin%
  \else% l
    \advance\th@mbwidthxtoc-\evensidemargin%
    \setlength{\@tempdimc}{\th@bmshoffset}%
    \advance\@tempdimc-\hoffset
  \fi%
  \put(\@tempdimc,-\th@mbposy){%
    \def\th@mbstest{l}%
    \ifx\th@mbstest\th@mbsprintpage% l
      \advance\th@mbwidthxtoc+\evensidemargin%
    \fi%
    \begin{picture}(0,0)%
      \def\th@mbstest{rule}%
      \ifx\thumbs@thumblink\th@mbstest%
        \ifx\th@mb@tmp@column\pagesLTS@zero%
         {\color{\th@mb@tmp@backgroundcolour}\hyperref[\th@mb@tmp@label]{\rule{\th@mbwidthxtoc}{\th@mbheighty}}}%
        \else%
          {\color{\th@mb@tmp@backgroundcolour}\rule{\th@mbwidthxtoc}{\th@mbheighty}}%
        \fi%
      \else%
        {\color{\th@mb@tmp@backgroundcolour}\rule{\th@mbwidthxtoc}{\th@mbheighty}}%
      \fi%
    \end{picture}%
    \ifx\th@mbstest\th@mbsprintpage% l
      \advance\th@mbwidthxtoc-\evensidemargin%
    \fi%
    \ifx\th@mb@tmp@column\pagesLTS@zero%
      \setlength{\th@mbwidthxtoc}{\paperwidth}%
      \advance\th@mbwidthxtoc-1in%
      \advance\th@mbwidthxtoc-\hoffset%
      \ifx\th@mbstest\th@mbsprintpage% l
        \advance\th@mbwidthxtoc-\evensidemargin%
      \else%
        \advance\th@mbwidthxtoc-\oddsidemargin%
      \fi%
      \advance\th@mbwidthxtoc-\th@mbwidthx%
      \advance\th@mbwidthxtoc-20pt%
      \ifdim\th@mbwidthxtoc>\textwidth%
        \setlength{\th@mbwidthxtoc}{\textwidth}%
      \fi%
      \ifx\th@mbstest\th@mbsprintpage% l
        \begin{picture}(0,0)(-6pt,-0.5\th@mbheighty+384930sp)%
          \bgroup%
            \setlength{\parindent}{0pt}%
            \makebox[\th@mbwidthx][l]{{\color{\th@mb@tmp@textcolour}\th@mb@tmp@text}}%
          \egroup%
        \end{picture}%
        \setlength{\@tempdimc}{-1in}%
        \advance\@tempdimc-\evensidemargin%
      \else% r
        \setlength{\@tempdimc}{0pt}%
      \fi%
      \begin{picture}(0,0)(\@tempdimc,-0.5\th@mbheighty+384930sp)%
        \bgroup%
          \setlength{\parindent}{0pt}%
          \vbox%
           {\hsize=\th@mbwidthxtoc {%
              \def\th@mbstest{none}%
              \ifx\thumbs@thumblink\th@mbstest%
                {\color{\th@mb@tmp@textcolour}\noindent \th@mb@tmp@title%
                 \leaders\box \ThumbsBox {\th@mbs@linefill \th@mb@tmp@page}%
                }%
              \else%
                \def\th@mbstest{title}%
                \ifx\thumbs@thumblink\th@mbstest%
                  {\color{\th@mb@tmp@textcolour}\noindent%
                   \hyperref[\th@mb@tmp@label]{\th@mb@tmp@title}%
                   \leaders\box \ThumbsBox {\th@mbs@linefill \th@mb@tmp@page}%
                  }%
                \else%
                  \def\th@mbstest{page}%
                  \ifx\thumbs@thumblink\th@mbstest%
                    {\color{\th@mb@tmp@textcolour}\noindent%
                     \th@mb@tmp@title%
                     \leaders\box \ThumbsBox {\th@mbs@linefill \pageref{\th@mb@tmp@label}}%
                    }%
                  \else%
                    \def\th@mbstest{titleandpage}%
                    \ifx\thumbs@thumblink\th@mbstest%
                      {\color{\th@mb@tmp@textcolour}\noindent%
                       \hyperref[\th@mb@tmp@label]{\th@mb@tmp@title}%
                       \leaders\box \ThumbsBox {\th@mbs@linefill \pageref{\th@mb@tmp@label}}%
                      }%
                    \else%
                      \def\th@mbstest{line}%
                      \ifx\thumbs@thumblink\th@mbstest%
                        {\color{\th@mb@tmp@textcolour}\noindent%
                         \hyperref[\th@mb@tmp@label]{\th@mb@tmp@title%
                         \leaders\box \ThumbsBox {\th@mbs@linefill \th@mb@tmp@page}}%
                        }%
                      \else%
                        \def\th@mbstest{rule}%
                        \ifx\thumbs@thumblink\th@mbstest%
                          {\color{\th@mb@tmp@textcolour}\noindent%
                           \th@mb@tmp@title%
                           \leaders\box \ThumbsBox {\th@mbs@linefill \th@mb@tmp@page}%
                          }%
                        \else%
                          \PackageError{thumbs}{\string\thumbs@thumblink\space invalid}{%
                            \string\thumbs@thumblink\space has an invalid value,\MessageBreak%
                            although it did not have an invalid value before,\MessageBreak%
                            and the thumbs package did not change it.\MessageBreak%
                            Therefore some other package (or the user)\MessageBreak%
                            manipulated it.\MessageBreak%
                            Now setting it to 'none' as last resort.\MessageBreak%
                           }%
                          \gdef\thumbs@thumblink{none}%
                          {\color{\th@mb@tmp@textcolour}\noindent%
                           \th@mb@tmp@title%
                           \leaders\box \ThumbsBox {\th@mbs@linefill \th@mb@tmp@page}%
                          }%
                        \fi%
                      \fi%
                    \fi%
                  \fi%
                \fi%
              \fi%
             }%
           }%
        \egroup%
      \end{picture}%
      \ifx\th@mbstest\th@mbsprintpage% l; relax
      \else%
        \begin{picture}(0,0)(1in+\oddsidemargin-\th@mbxpos+20pt,-0.5\th@mbheighty+384930sp)%
          \bgroup%
            \setlength{\parindent}{0pt}%
            \makebox[\th@mbwidthx][r]{{\color{\th@mb@tmp@textcolour}\th@mb@tmp@text}}%
          \egroup%
        \end{picture}%
      \fi%
    \fi%
    }%
  }

\newcommand{\th@mb@yA}{%
  \advance\th@mbposyA\th@mbheighty%
  \advance\th@mbposyA\th@mbsdistance%
  \ifdim\th@mbposyA>\th@mbposybottom%
    \PackageWarning{thumbs}{You are not only using more than one thumb mark at one\MessageBreak%
      single page, but also thumb marks from different thumb\MessageBreak%
      columns. May I suggest the use of a \string\pagebreak\space or\MessageBreak%
      \string\newpage ?%
     }%
    \setlength{\th@mbposyA}{\th@mbposytop}%
  \fi%
  }

\newcommand{\th@mbprint}[3]{%
  \put(\th@mbxpos,-\th@mbposyA){%
    \begin{picture}(0,0)%
      {\color{#3}\rule{\th@mbwidthx}{\th@mbheighty}}%
    \end{picture}%
    \begin{picture}(0,0)(0,-0.5\th@mbheighty+384930sp)%
      \bgroup%
        \setlength{\parindent}{0pt}%
        \ifodd\c@CurrentPage%
          \if@twoside%
            \makebox[\th@mbwidthx][l]{{\color{#2}\hspace*{1pt}\space #1}}%
          \else%
            \makebox[\th@mbwidthx][r]{{\color{#2}#1\space}}%
          \fi%
        \else%
          \makebox[\th@mbwidthx][r]{{\color{#2}#1\space}}%
        \fi%
      \egroup%
    \end{picture}%
   }%
  }

\AtBeginShipout{%
  \ifx\th@mbcolumnnew\pagesLTS@zero% ok
  \else%
    \PackageError{thumbs}{Missing \string\addthumb\space after \string\thumbnewcolumn }{%
      Command \string\thumbnewcolumn\space was used, but no new thumb placed with \string\addthumb\MessageBreak%
      (at least not at the same page). After \string\thumbnewcolumn\space please always use an\MessageBreak%
      \string\addthumb . Until the next \string\addthumb , there will be no thumb marks on the\MessageBreak%
      pages. Starting a new column of thumb marks and not putting a thumb mark into\MessageBreak%
      that column does not make sense. If you just want to get rid of column marks,\MessageBreak%
      do not abuse \string\thumbnewcolumn\space but use \string\stopthumb .\MessageBreak%
      (This error message will be repeated at all following pages,\MessageBreak%
      \space until \string\addthumb\space is used.)\MessageBreak%
     }%
  \fi%
  \@tempcnta=\value{CurrentPage}\relax%
  \advance\@tempcnta by -1% because CurrentPage is already the one of the next page
  \edef\th@mbstmpwidth{\the\paperwidth}%
  \ifdim\th@mbpaperwidth=\th@mbstmpwidth% OK
  \else%
    \PackageWarningNoLine{thumbs}{%
      Paperwidth has changed. Thumb mark positions become now adapted%
     }%
    \setlength{\th@mbposx}{\paperwidth}%
    \advance\th@mbposx-\th@mbwidthx%
    \ifthumbs@ignorehoffset%
      \advance\th@mbposx-\hoffset%
    \fi%
    \advance\th@mbposx+1pt%
    \xdef\th@mbpaperwidth{\the\paperwidth}%
  \fi%
  \def\th@mbxpos{\th@mbposx}%
  \ifodd\@tempcnta% \relax
  \else%
    \if@twoside%
      \ifthumbs@ignorehoffset%
         \def\th@mbxpos{-1pt-\hoffset}%
      \else%
        \def\th@mbxpos{-1pt}%
      \fi%
    \fi%
  \fi%
  \AtBeginShipoutUpperLeft{%
    \ifx\th@mbprinting\pagesLTS@one%
      \th@mbprint{\th@mbtextA}{\th@mbtextcolourA}{\th@mbbackgroundcolourA}%
      \@tempcnta=1\relax%
      \edef\th@mbonpagetest{\the\@tempcnta}%
      \@whilenum\th@mbonpagetest<\th@mbonpage\do{%
        \advance\@tempcnta by 1%
        \edef\th@mbonpagetest{\the\@tempcnta}%
        \th@mb@yA%
        \def\th@mbtmpdeftext{\csname th@mbtext\AlphAlph{\the\@tempcnta}\endcsname}%
        \def\th@mbtmpdefcolour{\csname th@mbtextcolour\AlphAlph{\the\@tempcnta}\endcsname}%
        \def\th@mbtmpdefbackgroundcolour{\csname th@mbbackgroundcolour\AlphAlph{\the\@tempcnta}\endcsname}%
        \th@mbprint{\th@mbtmpdeftext}{\th@mbtmpdefcolour}{\th@mbtmpdefbackgroundcolour}%
      }%
    \fi%
    \@tempcnta=\th@mbonpage\relax%
    \ifnum\@tempcnta<2% \relax
    \else%
      \gdef\th@mbtextA{\th@mbtext}%
      \gdef\th@mbtextcolourA{\th@mbtextcolour}%
      \gdef\th@mbbackgroundcolourA{\th@mbbackgroundcolour}%
      \gdef\th@mbposyA{\th@mbposy}%
    \fi%
    \gdef\th@mbonpage{0}%
    \gdef\th@mbtoprint{0}%
    }%
  }

\AfterLastShipout{%
  \ifx\th@mbcolumnnew\pagesLTS@zero% ok
  \else
    \PackageWarningNoLine{thumbs}{%
      Still missing \string\addthumb\space after \string\thumbnewcolumn\space after\MessageBreak%
      last ship-out: Command \string\thumbnewcolumn\space was used,\MessageBreak%
      but no new thumb placed with \string\addthumb\space anywhere in the\MessageBreak%
      rest of the document. Starting a new column of thumb\MessageBreak%
      marks and not putting a thumb mark into that column\MessageBreak%
      does not make sense. If you just want to get rid of\MessageBreak%
      thumb marks, do not abuse \string\thumbnewcolumn\space but use\MessageBreak%
      \string\stopthumb %
     }
  \fi
  \ifx\th@mbcolumn\pagesLTS@zero% if there is only one column of thumbs
    \xdef\th@umbsperpagecount{\th@mbs}
    \gdef\th@mbcolumn{1}
  \fi
  \ifx\th@umbsperpagecount\pagesLTS@zero
    \gdef\th@umbsperpagecount{\th@mbs}% \th@mbs was increased with each \addthumb
  \fi
  \ifdim\th@mbmaxwidth>\th@mbwidthx
    \ifthumbs@draft% \relax
    \else
      \def\th@mbstest{autoauto}
      \ifx\thumbs@width\th@mbstest%
        \AtEndAfterFileList{%
          \PackageWarningNoLine{thumbs}{%
            Rerun to get the thumb marks width right%
           }
         }
      \else
        \AtEndAfterFileList{%
          \edef\thumbsinfoa{\th@mbmaxwidth}
          \edef\thumbsinfob{\the\th@mbwidthx}
          \PackageWarningNoLine{thumbs}{%
            Thumb mark too small or its text too wide:\MessageBreak%
            The widest thumb mark text is \thumbsinfoa\space wide,\MessageBreak%
            but the thumb marks are only \space\thumbsinfob\space wide.\MessageBreak%
            Either shorten or scale down the text,\MessageBreak%
            or increase the thumb mark width,\MessageBreak%
            or use option width=autoauto%
           }
         }
      \fi
    \fi
  \fi
  \if@filesw
    \immediate\write\@auxout{\string\gdef\string\th@mbmaxwidtha{\th@mbmaxwidth}}
    \immediate\write\@auxout{\string\gdef\string\th@umbsperpage{\th@umbsperpagecount}}
    \immediate\write\@auxout{\string\gdef\string\th@mbsmax{\th@mbs}}
    \expandafter\newwrite\csname tf@tmb\endcsname
    \RerunFileCheck{\jobname.tmb}{%
      \immediate\closeout \csname tf@tmb\endcsname
      }{Warning: Rerun to get list of thumbs right!%
       }
    \immediate\openout \csname tf@tmb\endcsname = \jobname.tmb\relax
 %\else there is a problem, but the according warning message was already given earlier.
  \fi
  }

\newcommand{\addthumbsoverviewtocontents}[2]{%
  \gdef\th@mbs@toc@level{#1}
  \gdef\th@mbs@toc@text{#2}
  }

\newcommand{\clearotherdoublepage}{%
\clearpage\if@twoside \ifodd\c@page% removed "\else" from \cleardoublepage
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi%
}

\newcommand{\th@mbstablabeling}{%
  \@ifundefined{Hy@Warning}{}{\phantomsection}%
  \let\label\thumbsoriglabel%
  \ifx\th@mbstable\pagesLTS@one%
    \label{TableOfThumbs}%
    \label{TableOfThumbs1}%
  \else%
    \overridelabel{TableOfThumbs}%
    \label{TableOfThumbs\th@mbstable}%
  \fi%
  \let\label\@gobble%
  \ifx\th@mbs@toc@level\empty%\relax
  \else \addcontentsline{toc}{\th@mbs@toc@level}{\th@mbs@toc@text}%
  \fi%
  }

\newcommand{\thumbsoverview}[1]{\thumbsoverviewprint{#1}{r}}

\newcommand{\thumbsoverviewback}[1]{\thumbsoverviewprint{#1}{l}}

\newcommand{\thumbsoverviewverso}[1]{\thumbsoverviewprint{#1}{v}}

\newcommand{\thumbsoverviewdouble}[1]{\thumbsoverviewprint{#1}{d}}

\newcommand{\thumbsoverviewprint}[2]{%
  \edef\th@mbstest{#2}%
  \def\th@mbstestb{r}%
  \ifx\th@mbstest\th@mbstestb% r
    \gdef\th@mbsprintpage{r}%
  \else%
    \def\th@mbstestb{l}%
    \ifx\th@mbstest\th@mbstestb% l
      \gdef\th@mbsprintpage{l}%
    \else%
      \def\th@mbstestb{v}%
      \ifx\th@mbstest\th@mbstestb% v
        \gdef\th@mbsprintpage{v}%
      \else%
        \def\th@mbstestb{d}%
        \ifx\th@mbstest\th@mbstestb% d
          \gdef\th@mbsprintpage{d}%
        \else%
          \PackageError{thumbs}{%
             Invalid second parameter of \string\thumbsoverviewprint %
           }{The second argument of command \string\thumbsoverviewprint\space must be\MessageBreak%
             either 'r' or 'l' or 'v' or 'd', but is 'X2'.\MessageBreak%
             Now 'r' is chosen instead.\MessageBreak%
           }%
          \gdef\th@mbsprintpage{r}%
        \fi%
      \fi%
    \fi%
  \fi%
  \def\th@mbstest{none}%
  \ifx\thumbs@thumblink\th@mbstest% OK
  \else%
    \@ifundefined{Hy@Warning}{% hyperref not loaded
      \PackageError{thumbs}{Option thumblink != none, but hyperref not loaded}{%
        The option thumblink of the thumbs package was not set to 'none',\MessageBreak%
        but to some kind of hyperlinks, without using package hyperref.\MessageBreak%
        Either choose option 'thumblink=none', or load package hyperref.\MessageBreak%
        When pressing return, 'thumblink=none' will be set now.\MessageBreak%
        }%
      \gdef\thumbs@thumblink{none}%
      }{% hyperref loaded
      \def\th@mbstest{title}%
      \ifx\thumbs@thumblink\th@mbstest% OK
      \else%
        \def\th@mbstest{page}%
        \ifx\thumbs@thumblink\th@mbstest% OK
        \else%
          \def\th@mbstest{titleandpage}%
          \ifx\thumbs@thumblink\th@mbstest% OK
          \else%
            \def\th@mbstest{line}%
            \ifx\thumbs@thumblink\th@mbstest% OK
            \else%
              \def\th@mbstest{rule}%
              \ifx\thumbs@thumblink\th@mbstest% OK
              \else%
                \PackageError{thumbs}{Option thumblink with invalid value}{%
                  Option thumblink has value '\thumbs@thumblink'.\MessageBreak%
                  Valid values are 'none', 'title', 'page',\MessageBreak%
                  'titleandpage', 'line', or 'rule'.\MessageBreak%
                  'rule' will be used now.\MessageBreak%
                  }%
                \gdef\thumbs@thumblink{rule}%
              \fi%
            \fi%
          \fi%
        \fi%
      \fi%
    }%
  \fi%
  \edef\th@mbprintingovertoc{\th@mbprinting}%
  \ifnum \th@mbsmax > \pagesLTS@zero%
    \if@twoside%
      \def\th@mbstest{r}%
      \ifx\th@mbstest\th@mbsprintpage%
        \cleardoublepage%
      \else%
        \def\th@mbstest{v}%
        \ifx\th@mbstest\th@mbsprintpage%
          \cleardoublepage%
        \else% l or d
          \clearotherdoublepage%
        \fi%
      \fi%
    \else \clearpage%
    \fi%
    \stopthumb%
    \markboth{\MakeUppercase #1 }{\MakeUppercase #1 }%
  \fi%
  \setlength{\th@mbsposytocy}{\th@mbposy}%
  \setlength{\th@mbposy}{\th@mbsposytocyy}%
  \ifx\th@mbstable\pagesLTS@zero%
    \newcounter{th@mblinea}%
    \newcounter{th@mblineb}%
    \newcounter{FileLine}%
    \newcounter{thumbsstop}%
  \fi%
  \setcounter{th@mblinea}{\th@mbstable}%
  \addtocounter{th@mblinea}{+1}%
  \xdef\th@mbstable{\arabic{th@mblinea}}%
  \setcounter{th@mblinea}{1}%
  \setcounter{th@mblineb}{\th@umbsperpage}%
  \setcounter{FileLine}{1}%
  \setcounter{thumbsstop}{1}%
  \addtocounter{thumbsstop}{\th@mbsmax}%
  \let\thumbsoriglabel\label%
  \let\thumbsorigindex\index%
  \let\thumbsorigglossary\glossary%
  \let\label\@gobble%
  \let\index\@gobble%
  \let\glossary\@gobble%
  \def\th@mbstest{v}% r l r ...
  \ifx\th@mbstest\th@mbsprintpage%
    \def\th@mbsprintpage{l}% because it will be changed to r
    \def\th@mbdoublepage{1}%
  \else%
    \def\th@mbstest{d}% l r l ...
    \ifx\th@mbstest\th@mbsprintpage%
      \def\th@mbsprintpage{r}% because it will be changed to l
      \def\th@mbdoublepage{1}%
    \else%
      \def\th@mbdoublepage{0}%
    \fi%
  \fi%
  \def\th@mb@resetdoublepage{0}%
  \@whilenum\value{FileLine}<\value{thumbsstop}\do%
   {\ifx\th@mbdoublepage\pagesLTS@one%
      \def\th@mbstest{r}%
      \ifx\th@mbsprintpage\th@mbstest%
        \def\th@mbsprintpage{l}%
      \else% \th@mbsprintpage is l
        \def\th@mbsprintpage{r}%
      \fi%
      \clearpage%
      \ifx\th@mb@resetdoublepage\pagesLTS@one%
        \setcounter{th@mblinea}{\theth@mblinea}%
        \setcounter{th@mblineb}{\theth@mblineb}%
        \def\th@mb@resetdoublepage{0}%
      \else%
        \edef\theth@mblinea{\arabic{th@mblinea}}%
        \edef\theth@mblineb{\arabic{th@mblineb}}%
        \def\th@mb@resetdoublepage{1}%
      \fi%
    \else%
      \if@twoside%
        \def\th@mbstest{r}%
        \ifx\th@mbstest\th@mbsprintpage%
          \cleardoublepage%
        \else% l
          \clearotherdoublepage%
        \fi%
      \else \clearpage%
      \fi%
    \fi%
    \ifnum\value{FileLine}=1%
      \ifx\th@mbdoublepage\pagesLTS@one%
        \ifx\th@mb@resetdoublepage\pagesLTS@one%
          \th@mbstablabeling%
        \fi%
      \else
        \th@mbstablabeling%
      \fi%
    \fi%
    \null%
    \th@mbs@verview%
    \pagebreak%
    \ifthumbs@verbose%
      \message{THUMBS: Fileline: \arabic{FileLine}, a: \arabic{th@mblinea}, %
        b: \arabic{th@mblineb}, per page: \th@umbsperpage, max: \th@mbsmax.^^J}%
    \fi%
    \ifx\th@mb@resetdoublepage\pagesLTS@one%
      \setcounter{FileLine}{\theth@mblinea}%
    \fi%
   }%
  \setlength{\th@mbposy}{\th@mbsposytocy}%
  \ifx\th@mbprintingovertoc\pagesLTS@one%
    \continuethumb%
  \fi%
  \let\label\thumbsoriglabel%
  \let\index\thumbsorigindex%
  \let\glossary\thumbsorigglossary%
  \addthumbsoverviewtocontents{}{}%
  }

\newcommand{\th@mbs@verview}{%
  \ifthumbs@verbose%
   \message{^^JPackage thumbs Info: Processing line \arabic{th@mblinea} to \arabic{th@mblineb} of \jobname.tmb.}%
  \fi%
  \setcounter{FileLine}{1}%
  \AtBeginShipoutNext{%
    \AtBeginShipoutUpperLeftForeground{%
      \IfFileExists{\jobname.tmb}{% then
        \openin\@instreamthumb=\jobname.tmb %
          \@whilenum\value{FileLine}<\value{th@mblineb}\do%
           {\ifthumbs@verbose%
              \message{THUMBS: Processing \jobname.tmb line \arabic{FileLine}.}%
            \fi%
            \ifnum \value{FileLine}<\value{th@mblinea}%
              \read\@instreamthumb to \@unused%
              \ifthumbs@verbose%
                \message{Can be skipped.^^J}%
              \fi%
              % NIRVANA: ignore the line by not executing it,
              % i.e. not executing \@unused.
              % % \@unused
            \else%
              \ifnum \value{FileLine}=\value{th@mblinea}%
                \read\@instreamthumb to \@thumbsout% execute the code of this line
                \ifthumbs@verbose%
                  \message{Executing \jobname.tmb line \arabic{FileLine}.^^J}%
                \fi%
                \@thumbsout%
              \else%
                \ifnum \value{FileLine}>\value{th@mblinea}%
                  \read\@instreamthumb to \@thumbsout% execute the code of this line
                  \ifthumbs@verbose%
                    \message{Executing \jobname.tmb line \arabic{FileLine}.^^J}%
                  \fi%
                  \@thumbsout%
                \else% THIS SHOULD NEVER HAPPEN!
                  \PackageError{thumbs}{Unexpected error! (Really!)}{%
                    ! You are in trouble here.\MessageBreak%
                    ! Type\space \space X \string<return\string>\space to quit.\MessageBreak%
                    ! Delete temporary auxiliary files\MessageBreak%
                    ! (like \jobname.aux, \jobname.tmb, \jobname.out)\MessageBreak%
                    ! and retry the compilation.\MessageBreak%
                    ! If the error persists, cross your fingers\MessageBreak%
                    ! and try typing\space \space \string<return\string>\space to proceed.\MessageBreak%
                    ! If that does not work,\MessageBreak%
                    ! you might contact the maintainer of the thumbs package.\MessageBreak%
                    }%
                \fi%
              \fi%
            \fi%
            \stepcounter{FileLine}%
           }%
          \ifnum \value{FileLine}=\value{th@mblineb}
            \ifthumbs@verbose%
              \message{THUMBS: Processing \jobname.tmb line \arabic{FileLine}.}%
            \fi%
            \read\@instreamthumb to \@thumbsout% Execute the code of that line.
            \ifthumbs@verbose%
              \message{Executing \jobname.tmb line \arabic{FileLine}.^^J}%
            \fi%
            \@thumbsout% Well, really execute it here.
            \stepcounter{FileLine}%
          \fi%
        \closein\@instreamthumb%
        \addtocounter{th@mblinea}{\th@umbsperpage}%
        \addtocounter{th@mblineb}{\th@umbsperpage}%
        \@tempcnta=\th@mbsmax\relax%
        \ifnum \value{th@mblineb}>\@tempcnta\relax%
          \setcounter{th@mblineb}{\@tempcnta}%
        \fi%
      }{% else
        \setcounter{FileLine}{\arabic{thumbsstop}}%
        \AtEndAfterFileList{%
          \PackageWarningNoLine{thumbs}{%
            File \jobname.tmb not found.\MessageBreak%
            Rerun to get thumbs overview page(s) right.\MessageBreak%
           }%
         }%
       }%
      }%
    }%
  }

\let\thumborigaddthumb\addthumb%

\ifthumbs@draft
  \setlength{\th@mbwidthx}{2pt}
  \renewcommand{\addthumb}[4]{\thumborigaddthumb{#1}{#2}{black}{gray}}
  \PackageWarningNoLine{thumbs}{thumbs package in draft mode:\MessageBreak%
    Thumb mark width is set to 2pt,\MessageBreak%
    thumb mark text colour to black, and\MessageBreak%
    thumb mark background colour to gray.\MessageBreak%
    Use package option final to get the original values.\MessageBreak%
   }
\fi

\ifthumbs@hidethumbs
  \renewcommand{\addthumb}[4]{\relax}
  \PackageWarningNoLine{thumbs}{thumbs package in hide mode:\MessageBreak%
    Thumb marks are hidden.\MessageBreak%
    Remove package option hide to get thumb marks.\MessageBreak%
   }
  \renewcommand{\thumbnewcolumn}{\relax}
\fi

\endinput
%%
%% End of file `thumbs.sty'.