Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Currently using:

\edef\lastpagenumber{\pagenumber}

after starting a new page, then in subsequent text:

\ifnum\pagenumber>\lastpagenumber
  do something
\else
  do something else
\fi

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

share|improve this question
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
show 1 more comment

1 Answer

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

\usepackage{perpage}
\newcounter{mydummy}
\MakePerPage{mydummy}

then right after every

\stepcounter{mydummy}

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.

share|improve this answer
add comment

Your Answer

 
discard

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.