# Forward referencing no longer works after porting from MikTex to Ubuntu

I know that you need to rerun latex to resolve references -- it doesn't matter how many times I rerun it -- I get the same warning messages.

This sample program:

\documentclass[12pt]{article}
\begin{document}
\label{pg:first}
\newpage
Pages \pageref{pg:first} through \pageref{pg:last}.
\newpage
\label{pg:last}
\end{document}


yields:

Pages 1 through ??.


and the warnings:

LaTeX Warning: Reference pg:last' on page 1 undefined on input line 6.
LaTeX Warning: There were undefined references.


on every run.

A .aux file is generated, but consists only of "/relax". Running under sudo has no effect.

Am I just missing something basic in this example? A more complex one used to work in MikTex.

-
Welcome to TeX.SE! LaTeX needs to "attach" each \label to some object (section, figure, table, footnote, whatever) in order to "know" what to do with it. However, your MWE is so minimal that there's literally nothing for LaTeX to attach the second label to. Try providing some "real" item before issuing the second \label command, and you should be OK. –  Mico Jul 26 '12 at 8:16
I can't explain exactly why, but it seems to happen because there isn't anything on the last page. Add a letter, or even \null after the \newpage, and it works. –  Torbjørn T. Jul 26 '12 at 8:18
Only to avoid the impression that miktex is doing something magic: The simply example doesn't work on miktex either as - like Torbjorn has already mentioned - there isn't anything on the second page. –  Ulrike Fischer Jul 26 '12 at 8:22
Thank you all, the lack of content was the certainly the issue with this example. What I was actually trying to do was have the pg:last label be placed at the close of an environment surrounding various figures (then the label would be associated with a figure). I am computing page counts in counters using pg:last, and these are not coming out properly, where I believe that they were under MikTex. I can get correct behavior by moving the pg:last label to the last figure definition, but it would be better to hide this in an abstraction so that I don't have to keep remembering to move it. –  Steven Ganz Jul 26 '12 at 9:03

labels are shipped out with the rest of a page; it's at that time that the .aux file is written.
with nothing on the second page of your document, there's no shipout ... \label` commands don't count in evaluating the content of a page.