3

This is follow up question to If Then Else for odd page/even page.

Why doesn't this simple conditional code work in the tufte-book class? It shows me Even on every page! while it works fine in the book class.

\documentclass{tufte-book}
\usepackage{ifthen}
\newcounter{mycount}

\begin{document}
\noindent\whiledo{\themycount<130}{%
  \label{mylabel\themycount}%
  \ifthenelse{\isodd{\pageref{mylabel\themycount}}}%
    {Odd\\}%
    {Even\\}%
  \stepcounter{mycount}%
}
\end{document}

2 Answers2

2

This is better, but not perfect -- the first check on a page is always wrong!

The reason the OP does not work is that \pageref is not expandable, i.e. its output cannot be used for \ifthenelse or any other \if.... conditional that should check the number, so the output branches always to the false branch, i.e. Even.

\getpagerefnumber from refcount package is expandable, however.

\documentclass{tufte-book}
\usepackage{ifthen}
\newcounter{mycount}
\usepackage{refcount}

\begin{document}
\noindent\whiledo{\themycount<130}{%
  \refstepcounter{mycount}%
  \label{mylabel\number\value{mycount}}%
  \ifodd\getpagerefnumber{mylabel\number\value{mycount}}
  Odd

  \else

  Even
  \fi
}
\end{document}
2
\documentclass{tufte-book}
\usepackage{ifoddpage}
\newcounter{mycount}

\begin{document}
\parindent=0pt
\loop
  \mbox{\checkoddpage
  \ifoddpage Odd \else Even \fi}\\
  \ifnum\themycount<130 \stepcounter{mycount}%
\repeat
\end{document}
  • Did you try it? The first line on page 2 says “Odd”, the first line on page 3 says ”Even”. One can fix the issue with \mbox{\checkoddpage\ifoddpage Odd\else Even\fi}\\ – egreg Jun 02 '16 at 18:04
  • yes that's true, there must be something on the page. A \null would also work, but creates an empty line –  Jun 02 '16 at 18:11
  • Yes, it's a problem of timing when the whatsit enters the vertical list. However the example is quite artificial. – egreg Jun 02 '16 at 18:12