# Detect whether I'm on a left- or right-hand page? [duplicate]

This question already has an answer here:

How do I detect whether I'm on a left- or right-hand page?

I would like to define a custom command with a conditional statement that executes a certain command if it's on a left-hand page and another if it's on a right-hand page.

The command would be executed in the page body.

-

## marked as duplicate by Werner, lockstep, Adam Liter, Peter Jansson, JubobsApr 15 '14 at 17:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

It would be good to know whether this command should be executed as part of the page body, or as part of a page style. –  Werner Apr 15 '14 at 16:59
It would be great to a have a code in your post. Please try \ifodd\thepage A\else B\fi. –  Malipivo Apr 15 '14 at 17:04
–  clemens Apr 15 '14 at 17:06

## 2 Answers

Try:

\documentclass[a4paper]{book}
\begin{document}
~\newpage
\ifodd\thepage I am an odd page\else I am an even page \fi
~\newpage
\ifodd\thepage I am an odd page\else I am an even page \fi
\end{document}


EDIT: If you are using roman page numbering this will work:

\documentclass[a4paper]{book}
\begin{document}
\pagenumbering{roman}
~\newpage
\makeatletter\ifodd\c@page I am an odd page\else I am an even page \fi\makeatother
~\newpage
\makeatletter\ifodd\c@page I am an odd page\else I am an even page \fi\makeatother
\end{document}

-
As a means of showing why this doesn't work in general, add \pagenumbering{roman} on the first page. –  Werner Apr 15 '14 at 17:04
Perfect! I didn't know about \ifodd or \thepage. Thanks! –  Geremia Apr 15 '14 at 17:07
@Werner didn't think about this, thanks. I have edited my answer accordingly. –  Lupino Apr 15 '14 at 17:08

In ConTeXt, the standard way to define such custom commands is:

\signalrightpage % Synchronize page state
\doifrightpageelse{...if on right page...}{...if on left page...}

-