[texhax] Am I on the lastpage?
Schwartz, Steven J
s.schwartz at imperial.ac.uk
Mon May 20 17:13:08 CEST 2013
Hi Ulrike,
Ulrike Fischer wrote on 2013-05-20:
----------------
> Am Sun, 19 May 2013 16:39:26 +0000 schrieb Schwartz, Steven J:
>
>> (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".
>
> \thepage can be wrong in the first paragraph in the text *body* of a
> page but it is always correct when header and footers are added to the
> page (as the headers and always footers has to (and do) show the
> correct page number). So if you are really using fancyhdr and do the
> comparison in the footer it should work -- which means that your code is probably faulty.
I wasn't doing the comparison inside the footer, because I use latex's pagemarks to control the instructions to be placed in the footer, e.g., "This question continues..." if I'm inside a "question environment" or "Next question overleaf". These leftmarks are therefore set by \markboth's in the \begin{question} and \end{question} commands.
Of course, the end of the examination paper is special and it is perfectly reasonably to test for this within the footer. So I have done this and fixed what you correctly describe as my "faulty" code. [At first I tried putting a \markboth command inside the footer, but I soon realised (a) that this wouldn't work and (b) it is easier just to replace the \leftmark in the footer by the actual text.]
Many thanks for the nudge in the right direction,
Steve
--------------------------------------------------------------------
Professor Steven J Schwartz Phone: +44 (0)207 594 7660
Head, Space & Atmospheric Physics Fax: +44 (0)207 594 7772
The Blackett Laboratory Email: s.schwartz at imperial.ac.uk
Imperial College London Office: Huxley 6M67A
London SW7 2AZ, UK Web: www.sp.ph.ic.ac.uk/~sjs
--------------------------------------------------------------------
More information about the texhax
mailing list