Currently using:


after starting a new page, then in subsequent text:

  do something
  do something else

But sometimes \pagenumber does not seem to increment, even though a new page has started.

  • 2
    You can not test in that way (which format is this? latex and plain do not define \pagenumber) teX typesets complete paragraphs (including expanding all macros before considering page breaks. Page numbers are not reliably known until the output routine. (search for questions about that for more info) – David Carlisle Apr 19 '12 at 13:35
  • You need to set a label at both positions and then test if their page numbers are different. This needs two compiler runs. See my answer to Test if a paragraph has a page break in it?, which might even be a duplicate. – Martin Scharrer Apr 19 '12 at 13:40
  • You could also have a look at the source code of the varioref package which uses some code like you want. – Martin Scharrer Apr 19 '12 at 13:44
  • The format is ConTeXt, which apparently defines the \pagenumber macro. Apologies if the post is a duplicate, though the referenced post is for LaTeX. Not sure how to use LaTeX packages in ConTeXt. – Ray LeClair Apr 19 '12 at 14:00
  • What exactly do you want to achieve with this code? – Aditya Apr 19 '12 at 17:43

Check out the perpage package. If you create a dummy counter


then right after every


the macro \theperpage will expand to the current page number at the point in the text where the counter has been stepped. Not necessarily right away: you might get a warning "references may have changed", requiring you to rerun LaTeX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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