[texhax] Am I on the lastpage?

Reinhard Kotucha reinhard.kotucha at web.de
Mon May 20 04:56:10 CEST 2013

On 2013-05-19 at 23:05:06 +0000, Schwartz, Steven J wrote:

 > Reinhard,
 > Thanks for the reply. I think it's a very good reply, but perhaps not to the question I posed. See below:
 > Reinhard Kotucha wrote on 2013-05-19:
 > ----------------
 > > On 2013-05-19 at 16:39:26 +0000, Schwartz, Steven J wrote:
 > > 
 > >> (I tried to send this a week ago but haven't seen it, so perhaps it got
 > >> lost)  > Dear All,  >  > I have a class file that uses fancyhdr and
 > >> latex's leftmarks to
 > > set  > footers depending on the context. It's for exams, so it sets  >
 > > footers to "Turn to next page" or "This question continues ..." or  >
 > > whatever, and on the last page it's supposed to write "End of  >
 > > Examination". To accomplish this last task, I borrowed the logic  >
 > > from the lastpage package. That is, AtEndDocument I write out a  >
 > > label called lastpage, and in my header- building code I use an  >
 > > ifthenelse construction to compare \thepage with  > \pageref{lastpage}.
 > >> 
 > >> This works most of the time, but fails when there is only a small
 > >> paragraph on the last page. This is due to the well-known TeX  >
 > > behaviour which results (see the TeX FAQ) in \thepage being "almost  >
 > > always wrong in the first paragraph of a page".
 > > 
 > >> 
 > >> I have looked briefly at the most recent lastpage package and also
 > >> the documentation for pageslts, but I think both are more concerned
 > >> with accessing information via labels.
 > >> 
 > >> There is a manual workaround by inserting a \pagebreak should this
 > >> happen, but since I distribute this .cls to colleagues who are not
 > >> all TeXies, I'm looking for an automated self-contained  > approach.
 > > And one which doesn't rely on too many external packages  > and such
 > > (which is why my .cls borrowed ideas from lastpage, with  > proper
 > > credit, rather then used the ctan package).
 > >> 
 > >> Anyone have any suggestions?
 > > 
 > > texdoc atveryend
 > I spent some time getting my code to talk to this package, only to
 > realise (I think) that it doesn't solve my problem. It DOES provide
 > a robust way to find out what the number of the last page of the
 > document is, by writing it, e.g., as a \newlabel, to the aux
 > file. But what I need to be able to do somehow is to compare that
 > last page number with the number of the page on which the
 > currently-being-processed text will appear. As \thepage is
 > unreliable, I'm stuck, or perhaps missing something obvious.
 > In short, the title of this thread expresses my problem. I don't
 > want to know what the number of the lastpage is (although I
 > appreciate that atveryend does a better job than lastpage); I want
 > to know if I'm on it.

There is no reliable way to find out where you are before the output
routine is run.  What you can try is to use a \label and examine the
.aux file.  \pageref is reliable, so something similar should work.


Reinhard Kotucha                                      Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                              mailto:reinhard.kotucha at web.de
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.

More information about the texhax mailing list