# [texhax] \thepage issues, seems like a bug, but how could it be??

Mon Feb 13 19:49:08 CET 2006

```On Sun, Feb 12, 2006 at 08:03:56PM -0500, Micha Hofri wrote:
> (1)  It sets \theequation which is used both in .aux and to print the
> equation number.  I need that value in the .aux file, to generate
> references, but I want to print only the second part of the string,
> following the period, so I need to get into the macro(?) that prints the
> equation number.

Sorry, I can't help here.

> (2) When latex gets to an equation which causes it to clear page and
> start another, its \theequation has already been set as belonging to the
> previous page, while the .aux file reflects the correct page where it
> was included.  There seems to be fuzziness about the value of \thepage.
> Which seems odd at this stage of developmment

If I understand you correctly, you are wondering how LaTeX
writes the correct page number to the .aux file.  The usual
mechanism for this is as follows.  TeX provides the
primitive command \write which takes as one of its arguments
a text to write.  Now, the trick is, TeX does not expand the
text for the \write at the moment it sees the command.
Instead, TeX creates a so-called whatsit which contains the
_unexpanded_ text, and places the whatsit in the current
list along with boxes.  Only when TeX starts shipping out
the boxes on the page and encounters a whatsit, it expands
the text for the \write and sends the result of expansion to
the file.  This is when the page number is expanded, and
thus the correct page number gets written to the .aux file.

However, for this to work you have to process your document
twice, so the correct page number will be read from the .aux
file the second time.

If you are interested in this kind of things you might want
to read The TeXbook by Donald Knuth.

Hope this helps,