% content=tex
%
% copyright=pragma-ade readme=readme.pdf licence=cc-by-nc-sa

\usemodule[mag-01]

\setvariables
  [magazine]
  [title={Page Ranges},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   date=Februari 2003,
   number=2]

\startbuffer[abstract]
  Subpage numbers can save you some messing around with page
  references. Here we show some basics. 
\stopbuffer

\starttext \setups [titlepage] \setups [title] % \enablemode[frame]

This is a simple example of using subpage numbers. Subpage
numbers are not automatically kept track of, so you first
need to activate them:

\startbuffer
\setupsubpagenumber
  [way=bychapter,
   state=start]
\stopbuffer

\typebuffer \getbuffer

After activating this mechanism, you can access the numbers
as follows. The numbers are synchronized in during page
building, which means that they are correct when
constructing headers and footers.

\startbuffer
\setupheadertexts
  [\firstsubpage--\lastsubpage]

\setupfootertexts
  [\pagenumber]
\stopbuffer

\typebuffer \getbuffer

There are several ways to access those numbers:

\starttabulate
\NC \type{\firstsubpage} \NC first real pagenumber in range    \NC\NR
\NC \type{\prevsubpage}  \NC previous real pagenumber in range \NC\NR
\NC \type{\nextsubpage}  \NC next real pagenumber in range     \NC\NR
\NC \type{\lastsubpage}  \NC last real pagenumber in range     \NC\NR
\stoptabulate

\startsetups [sub check]

  \vfill

  \setupbodyfont[8pt]

  \startcolor[MyBlue]

  \starttabulate[|l|r|]
  \NC \type{\firstsubpage} \NC \firstsubpage       \NC\NR
  \NC \type{\prevsubpage}  \NC \prevsubpage        \NC\NR
  \NC \type{\nextsubpage}  \NC \nextsubpage        \NC\NR
  \NC \type{\lastsubpage}  \NC \lastsubpage        \NC\NR
  \NC \type{\nofsubpages}  \NC \nofsubpages        \NC\NR
  \TB 
  \NC \type{\lastpage}     \NC \lastpage           \NC\NR
  \TB 
  \NC \type{\subpageno}    \NC \number \subpageno  \NC\NR
  \NC \type{\pageno}       \NC \number \pageno     \NC\NR 
  \NC \type{\realpageno}   \NC \number \realpageno \NC\NR 
  \stoptabulate

  \stopcolor

  \vfill \vfill 

\stopsetups 

We will now generate a bunch of fake chapters to illustrate
this feature.

\setuptexttexts
  [margin]
  [] [\vbox to \textheight{\setups[sub check]}]

\chapter{Tufte} \dorecurse{15}{\input tufte }
\chapter{Zapf}  \dorecurse{10}{\input zapf  }
\chapter{Knuth} \dorecurse{20}{\input knuth } 

\page 

\setuptexttexts
  [margin]
  [] []

\setups [listing] \setups [lastpage] \stoptext
