TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

Pages \pageref{pg:first} through \pageref{pg:last}.


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.

share|improve this question
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.