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.

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.

share|improve this question

marked as duplicate by Werner, lockstep, Adam Liter, Peter Jansson, Jubobs Apr 15 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.

1  
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 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 at 17:04
    
Related:tex.stackexchange.com/questions/6143/… –  cgnieder Apr 15 at 17:06

2 Answers 2

up vote 5 down vote accepted

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

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