%% Thumby - LaTeX package for creating thumb indexes.
%
% Version: 0.1
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Requirements:
%
% - memoir document class
%
% - Packages:
%
% - PerlTeX
% - tikz
% - bophook
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Instructions:
%
% Put something like the following in your document (we'll call it "foo.tex"):
%
% \documentclass[twoside]{memoir}
%
% \usepackage{thumby}
%
% \thumbySides{two}
% \thumbyTotalChapters{10}
% \thumbyPageHeight{792}
% \thumbyThumbWidth{42.5}
% \thumbyForeground{white}
% \thumbyBackground{black}
% \thumbyNumberFormat{\Huge\textbf{$chapter_number}}
%
% \thumbySetup
%
% Then, run twice:
%
% perltex --latex=pdflatex foo.tex
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Please change the above to reflect your document and preferences.
% In particular, you should change the \thumbyTotalChapters from 10 to the number
% of chapters in your document, and the \thumbyPageHeight from 792 to the height
% of your document (in points), and \thumbySides to reflect whether your document
% uses one- or two-sided pages.
%
% Note: Units for page height, width, etc, are in points.
%
% Note: Only normal, numbered chapters will have a thumb index.
% For example, the of contents and \frontmatter chapters will not have a thumb index.
%
% Note: When \thumbyNumberFormat contains the literal $chapter_number
% Thumby will substitute the actual chapter number for this literal.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Thumby - LaTeX package for creating thumb indexes.
%
% Copyright (C) 2010 Sergey Goldgaber
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of version 3 of the GNU General Public License
% as published by the Free Software Foundation.
%
% This program 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, see .
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{thumby}[2010/01/14 v0.1 Thumby]
\typeout{}
\typeout{***********************************************}
\typeout{*********** Loading Thumby Package ************}
\typeout{***********************************************}
\typeout{}
% We use the tikz library to draw and position the thumb indexes.
\RequirePackage{tikz}
% We use the perltex package to run perl within LaTeX.
% This is used to do the calculations of the dimensions
% of the thumb boxes and their locations, which are fed
% to tikz.
\RequirePackage{perltex}
%% We use the bophook package to place a thumb box on each page.
\RequirePackage{bophook}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Configuration commands.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\perlnewcommand{\thumbyNumberFormat}[1]{
$thumby_number_format = $_[0] ;
# Slashes have to be doubled, as otherwise perl will interpret them as indicating
# that a special character follows.
$thumby_number_format =~ s{/}{//} ;
return "\\typeout{Thumby number format: $thumby_number_format}" ;
}
% Place a thumb index on each page.
\perlnewcommand{\thumbySides}[1]{
$thumby_sides = $_[0] ;
if ( $thumby_sides eq "one" ) {
$output = <