The totpages package^{∗}

Wilhelm Müller

Am Wall 139 D-28195 Bremen muewi@acm.org

1999/07/13

Abstract

This package counts the total number of pages shipped out to the dvi file. The counter itself may be shipped out, too, allowing page access by absolute page numbers, or it may be just a regular L^{A}TEX counter.

The value that counter had at the end of the previous L^{A}TEX run may be referenced as \ref{TotPages}, the (L^{A}TEX) page number it appears on as \pageref{TotPages}. This allows sentences like “This document contains 3 pages, the last one being no. 1236.” to be produced automatically.

This package can be used with with the package hyperref, producing a hyperlink to the last page—though this is not of much use as most hypertext readers allow direct access to the last page anyway.

Contents

1 Introduction 1234

2 Using totpages 1235

3 Options 1235 4 Required packages 1235

5 Acknowledgements 1235

1 Introduction

Printing only part of a dvi file can be difficult or impossible if pages in different parts of the document have the same number—e. g. in the frontmatter and the first text pages (iii vs. 3).

TEX provides an easy solution to this problem: whenever a page has been completed by the output routine and is being shipped out to the dvi file, it displayes the values of \count0 to \count9, with trailing zeroes suppressed, (e. g., [1002.0.3]) and writes them to the log and dvi files, cf. [Knuth, p. 119]. So, if you have a dvi driver which allows page selection by other counters than \count0, you will be able to refer to absolute page numbers when you make use of this package.

∗The version number of this file is v1.00, last revised 1999/07/13.

2 Using totpages

TotPages Keeping a count of the absolute page number makes it possible to provide the total number of pages of the document (as opposed to the “number” on the last page provided by the lastpage package, cf. [Goldberg]).

References to the counter itself won’t make much sense since it is updated asynchronously whenever an actual shipout occurs. But by referencing the label TotPages (with \ref{TotPages}) you get the total number of pages the document had at the end of the previous run of L^{A}TEX. If, for some reason, you want to know what page number L^{A}TEX actually (would have) printed, you may use

\pageref{TotPages}.

\theTotPages What is actually printed by \ref{TotPages} is the result of the macro \theTotPages, which normally is simply \arabic{TotPages}, but may be redefined to anything (sensible) somewhere before \end{document}.

If you want to use this package, you should load totpages as the last package in your document because it executes some code at \end{document} and has to be sure that its code is the last code to be executed there.^{1}

You must not use count1to or lastpage together with this package. Package count1to provides additional functionality, but will not co-operate with hyperref, whereas any use of lastpage is covered by totpages. If you try to use one (or both) of these packages together with totpages, you will receive an error message at \begin{document}. I don’t think that something really bad will happen if you ignore it (unless you use count1to together with hyperref), but I won’t guarantee anything.

3 Options

dvi With Option dvi (the default), \count1 is used for the absolute page counter. nodvi This value is put into the dvi file and may be used by the dvi driver.

Option nodvi uses a regular L^{A}TEX counter which will not show up elsewhere. No matter what counter is used, its name will always be TotPages, e. g. if you

want to change its format to roman (why would you want to do this???).

4 Required packages

This package needs the everyshi package [Schröder 2].

5 Acknowledgements

This packages uses ideas inspired by Martin Schröder’s count1to package [Schröder 1], Jeff Goldberg’s lastpage package [Goldberg], and the lastpage support contained in Sebastian Rahtz’s hyperref package [Rahtz].

1See [Goldberg] for a discussion of problems.

References

[Goldberg] Jeff Goldberg. The lastpage-package. CTAN:

tex-archive/macros/latex/contrib/other/lastpage/.

L^{A}TEX 2ε package.

[Knuth] Donald E. Knuth. The TEXBook, volume A of Computers and Typesetting. Addison-Wesley, 1986. Tenth printing, revised, June 1990.

[Rahtz] Sebastian Rahtz. Hypertext marks in L^{A}TEX. CTAN:

tex-archive/macros/latex/contrib/supported/hyperref/.

L^{A}TEX 2ε package.

[Schröder 1] Martin Schröder. The count1to package. CTAN:tex-archive/

macros/latex/contrib/supported/ms/count1to.dtx.

L^{A}TEX 2ε package.

[Schröder 2] Martin Schröder. The everyshi package. CTAN:tex-archive/

macros/latex/contrib/supported/ms/everyshi.dtx.

L^{A}TEX 2ε package.