The lastpage package^{∗}

Jeff Goldberg

                    goldberg@nytud.hu

1994/07/20

Abstract

This package puts the label LastPage into the .aux file, allowing the user to use references to the last page of a document. This might be particularly useful in places like headers or footers.

1 Introduction

For various draft forms it is desirable to have a page reference to the last page so that page footers, for example, could contain something like “page N of K’, where N is the current page and K is the last page.

This package defines a label, LastPage, which the user can refer to using the \pageref command.

2 The user interface

Just load it with by placing

 \usepackage{lastpage}

in the preamble of your L^{A}TEX 2ε source file.

LastPage Once that is loaded, you will be able to make reference anywhere in your text to the label LastPage. In particular you can either use the fancyheadings package, or your own redefinitions of the page headings and footings to get a reference to the last page, as in the example below.

 \makeatletter
 \renewcommand{\@evenfoot}%
    {\normalsize\slshape DRAFT \today\hfil
     \upshape page {\thepage} of \pageref{LastPage}}
 \renewcommand{\@oddfoot}{\@evenfoot}
 \makeatother

∗This file has version number v0.1b, last revised 1994/06/25, documentation dated 1994/07/20.

to get footers like “DRAFT April 26, 1995 page 5 of 23” into your document. Or for text like,

   Hey, you don't write a \pageref{LastPage}~page letter every day,
   you know.

to get

Hey, you don’t write a 12 page letter every day, you know.

3 A few warnings

This package uses the L^{A}TEX 2ε directive of \AtEndDocument. If you use other packages that do the same and actually put material at the end, then it is important to load lastpage after such other packages if you want the true last page. That is if a package xyzzy uses \AtEndDocument to put out two pages of material at the end of the document, then to get the last page to be the page number of the second of those pages you need to load lastpage after xyzzy makes its call to \AtEndDocument

3.1 Interaction with endfloat

Version 2.0 (and earlier) of endfloat actually redefine the \enddocument, and so interfere drastically with the L^{A}TEX 2ε commands which make use of \AtEndDocument. A newer version of endfloat exists in modern documentation form, which should be available from the same source where you received this file.

If you want your LastPage to label the last page of these end floats, you need to load lastpage after loading endfloat. If, on the other hand, you want LastPage to refer to the last page, exclusive of the the floats at the end, then load in the reverse order. For each of these, you will still need the modified version of endfloat.

Other L^{A}TEX209 packages also seem to like to redefine \enddocument. In addition to the old endfloat, harvard comes to mind. All of these will need to be modified swiftly. (How did these ever work together before? I can’t believe that nobody wanted harvard bibliography style and floats at the end before!)

3.2 General ordering and wish list

I believe that the output of a L^{A}TEX 2ε run should be independent of the order in which package are loaded. It would be possible to set this up, but it would take coordiniation of all package writers who use \AtEndDocument. The actual call to \AtEndDocument would not occur during package loading, but some new command, like \ExecuteAtEndDocument would be called by the user after all such packages are loaded, with tags for each thing in the packages, so something like

   \usepackage{lastpage}
   \usepackage{endfloat,xyzzy}
   \ExecuteAtEndDocument{endfloat, xyzzy, lastpage}

and the order of End Document material would be the endfloat material, followed by xyzzy, and finally by lastpage.

It is often the case that the same formats for which one must put tables and figure at the end, are the ones in which endnotes are also required. If one wants to use lastpage here as well, then it is easy to get to three separate uses of \AtEndDocument (assuming one uses that for the endnotes as well). Clearly it is not safe for any package writer or user to assume that no material will follow what they put into and \AtEndDocument. This, in addition to the ordering, is a good reason to develop safe practices for use of this very powerful tool.

I will have to wait until someone else develops such a system, but I will gladly modify lastpage to comply with it. Until then I will include a message which begins with AED in every usage of \AtEndDocument, and try to minimize any side effects my usage may have.

3.3 Ignorance is bliss

The author of this package is not only new to L^{A}TEX 2ε, but also to L^{A}TEX209. If I have duplicated something that already exists, forgive me. I have always wanted this in Plain TEX, but never had the robust cross referencing that L^{A}TEX provides. Now that I have made the big switch, I jumped at the chance to get this done.

Index

The italic numbers denote the pages where the corresponding entry is described, numbers underlined point to the definition, all others indicate the places where it is used.

A

LastPage . . . . . . . . 1