# How to write a TeX conditional to test start of a new page (ConTeXt)

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.

-
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

## 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.

-