### Finding if you're on an odd or an even page

Another question discusses the issue of getting `\``marginpar` commands to put their output in the correct margin of two-sided documents. This is an example of the general problem of knowing where a particular bit of text lies: the output routine is asynchronous, and (La)TeX will usually process quite a bit of the "next" page before deciding to output any page. As a result, the `page` counter (known internally in LaTeX as `\``c@page`) is normally only reliable when you're actually in the output routine.

The solution is to use some version of the `\``label` mechanism to determine which side of the page you're on; the value of the page counter that appears in a `\``pageref` command has been inserted in the course of the output routine, and is therefore safe.

However, `\``pageref` itself isn't reliable: one might hope that

    \ifthenelse{\isodd{\pageref{foo}}}{odd}{even}

would do the necessary, but both the babel and hyperref packages have been known to interfere with the output of `\``pageref`; be careful!

The chngpage package needs to provide this functionality for its own use, and therefore provides a command `\``checkoddpage`; this sets a private-use label, and the page reference part of that label is then examined (in a hyperref-safe way) to set a conditional `\``ifcpoddpage` true if the command was issued on an odd page. The memoir class has the same command setting a conditional `\``ifoddpage`. Of course, the `\``label` contributes to LaTeX's "Rerun to get cross-references right" error messages...

`chngpage.sty`
  macros/latex/contrib/misc/chngpage.sty
`memoir.cls`
  macros/latex/contrib/memoir (gzipped tar, browse)

This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=oddpage