[Tugindia] how to get total no. of pages

Radhakrishnan CV tugindia@tug.org
05 Nov 2002 08:34:32 +0530


>>>>> "Sumit" == Sumit Bhardwaj <bhardwajs@softhome.net> writes:

    Sumit> Hi, I need to put following the footer: Page <current page
    Sumit> no> of <no . of total pages> I don't know how to get the
    Sumit> total no. of pages. Can someone help me?  I think one needs
    Sumit> 2 passes to do this. Is there a 1-pass method to do so?

I don't think last page can be obtained in single pass. In two pass,
surely you can get this. The following code might help:

\def\lastpage{0}
\AtEndDocument{%
  \clearpage
  \addtocounter{page}{-1}
  \immediate\write\@auxout{\string\lastpage{\thepage}}
}

Now, 

  Page \thepage\space of \lastpage

should give you what you want. Anyway, you need two passes in any
LaTeX compilation to fix cross references and bib cites. So there are
no overheads. By the way, pdfscreen.sty uses this mechanism for
getting the current page number and last page number for one of its
navigation buttons. You can have a look if you have problems.

Best.

-- 
Radhakrishnan