Difference between revisions of "Thumb index"

From Wiki
Jump to navigation Jump to search
(Merging the contents of Chapter thumbs with metapost)
m (Add a note to clean up the page)
Line 1: Line 1:
 +
{{todo | this page needs to be cleaned up}}
 +
 
The following code is an example of how to draw a graphic on every page of a document. The graphic (a grey rectangle) appears in a different place for each chapter, and the chapter number appears in the rectangle as well. This is often called a thumb index - your thumb can flip the pages of a book while you watch the contents flash past...
 
The following code is an example of how to draw a graphic on every page of a document. The graphic (a grey rectangle) appears in a different place for each chapter, and the chapter number appears in the rectangle as well. This is often called a thumb index - your thumb can flip the pages of a book while you watch the contents flash past...
  

Revision as of 07:47, 22 January 2010


TODO: this page needs to be cleaned up (See: To-Do List)


The following code is an example of how to draw a graphic on every page of a document. The graphic (a grey rectangle) appears in a different place for each chapter, and the chapter number appears in the rectangle as well. This is often called a thumb index - your thumb can flip the pages of a book while you watch the contents flash past...

% by Hans Hagen, of course :-)

\unprotected \def\rawsectionnumber#1{\countervalue{\??se#1}} % will be in kernel

\setuppagenumbering
   [alternative=doublesided]

\setupcolors
   [state=start]

\setupbackgrounds
   [page]
   [background=thumbs]

\defineoverlay
   [thumbs]
   [\setups{thumbs}]

\def\NOfChapters{4} % i need to make this one available

\startsetups thumbs

     \definemeasure[thumbheight][\dimexpr\paperheight/\NOfChapters\relax]

     \vbox to \paperheight \bgroup
         \vskip \rawsectionnumber{section-2} \measure{thumbheight}
         \vskip -1                           \measure{thumbheight}
         \doifoddpageelse\hfill\donothing
         \framed
             [background=color,
              backgroundcolor=darkgray,
              frame=off,
              foregroundcolor=white,
              height=\measure{thumbheight},width=1cm]
             {\bfa \rawsectionnumber{section-2}}
         \doifoddpageelse\donothing\hfill
         \vss
     \egroup

\stopsetups

\starttext

\chapter{first}  \dorecurse{10}{\input tufte  }
\chapter{second} \dorecurse{10}{\input davis  }
\chapter{third}  \dorecurse{10}{\input zapf   }
\chapter{fourth} \dorecurse{10}{\input bryson }

\stoptext


Another Example

An example (MkIV) for using Metapost to create thumb indices for chapters.

\setuppapersize[A4][A4,oversized]

\setuplayout
  [width=middle,
   % margin=\dimexpr\backspace-\margindistance\relax
   location=middle]

\definecolor[chap_frame][g=1,t=1,a=12]
\definecolor[sect_frame][b=1,t=1,a=12]
\definecolor[textcolor] [r=1,t=1,a=12]

\startuseMPgraphic{chapter thumb}
  path chap_frame, sect_frame ;  pair pos,a,b ;  picture text ;
  
  curr_chap := \somenamedheadnumber{chapter}{current} ; 
  last_chap := \somenamedheadnumber{chapter}{last}    ;
  curr_sect := \somenamedheadnumber{section}{current} ; 
  last_sect := \somenamedheadnumber{section}{last}    ;

  skip   := TextHeight * (curr_chap-1)/last_chap ;
  height := TextHeight/last_chap ;
  sskip  := height*curr_sect/last_sect ;
 
  text   := textext("\ssbfb\textcolor Chapter\enspace\getmarking[chapternumber]");

  StartPage ;
    chap_frame := fullsquare xyscaled(RightMarginWidth,height) ;

    a := ulcorner chap_frame ;
    b := urcorner chap_frame ;

    sect_frame := a--b--(xpart b,ypart b-sskip)--(xpart a,ypart a-sskip)--cycle;

    pos := urcorner Field[Text][RightMarginSeparator] -
           ulcorner chap_frame - (0,skip);

    fill chap_frame shifted pos withcolor \MPcolor{chap_frame};
    unfill sect_frame shifted pos withcolor white ;
    fill sect_frame shifted pos withcolor \MPcolor{sect_frame};
    draw text rotated 90 shifted pos ;
  StopPage ;
\stopuseMPgraphic


\defineoverlay[chapter thumb][\useMPgraphic{chapter thumb}]

\setupbackgrounds[page][background=chapter thumb]


\starttext  \showframe
\dorecurse{6}{\chapter{Test Chapter #1}
  Chapter \somestructureheadnumber[chapter][current] of
  \somestructureheadnumber[chapter][last]
  \dorecurse{9}{\section{Test Section}
    Section \somestructureheadnumber[section][current] of
    \somestructureheadnumber[section][last] \blank
    \input tufte \par \input knuth \par
  }
}
\stoptext