[Tugindia] Total number of pages

CV Radhakrishnan cvr at river-valley.org
Sun Oct 3 05:03:19 CEST 2004


On Sun, October 3, 2004 6:54 am, Sridhar M.A. said:

> I am typesetting a book in LaTeX and things are going on nicely. I
> have a small problem.
>
> The book has a frontmatter section in which about 10-12 pages are
> numbered in Roman and
> the rest in Arabic. Using \pageref, I am able to indicate on the
> copyright page the total number of pages as ix+242 (e.g.). Is there a
> simple way to get the total number of pages in a
> document (irrespective of whether the page counter is reset midway or
> not)?

Here is one way of doing it:

 \usepackage{everyshi}
 \makeatletter
 \let\totalpages\relax
 \newcounter{mypage}
 \EveryShipout{\stepcounter{mypage}}
 \AtEndDocument{\clearpage
    \immediate\write\@auxout{%
     \string\gdef\string\totalpages{\themypage}}}
 \makeatother

In second pass \totalpages will give you the total number of leaves
irrespective of any front/backmatter or increment/decrement of page
counter.

-- 
Radhakrishnan




More information about the tugindia mailing list