Haz algo en cada segunda página

Haz algo en cada segunda página

¿Existe una manera de imprimir solo el texto principal del documento en cadasegundopágina mientras ejecuta algún otro código en las otras páginas? Lo que quiero es algo que se ejecute como en el siguiente ejemplo:

\documentclass{memoir}
\usepackage{lipsum}

\begin{document}
\begin{atevenpages}
  The content of this environment is supposed to be printed on even-numbered pages. On the other hand, even-numbered pages are supposed to contain none of the main text.
\end{atevenpages}

This is the main text, which is only to appear on odd-numbered pages.
\lipsum[1-22]
\end{document}

Respuesta1

Eche un vistazo al paquete everypagey ifthen. everypageintroduce un gancho que se llama después de que se haya configurado cada página. Entonces necesito llamar mi \checkthatpagecomando solo para la primera página manualmente, para todas las demás páginas se usa el gancho. Puede que haya soluciones más sofisticadas, pero aún no las he encontrado.

\documentclass{article}
\usepackage{ifthen,everypage}

\newcommand{\checkthatpage}[2]{%
\ifthenelse{\isodd{\value{page}}}%
    {#1}%
    {#2}%
}%

\AddEverypageHook{\checkthatpage{Even}{Odd}}

\begin{document}

Foo

\clearpage

Bar

\end{document}

Respuesta2

Yo abordaría este problema en un nivel inferior: la \shipoutrutina, que TeX invoca cuando una página está llena y es necesario enviarla. En esta etapa, podemos simplemente agregar otra página con el contenido deseado:

\documentclass{memoir}
\usepackage{lipsum}

\usepackage{atbegshi}

\AtBeginShipout{%
  \ifodd\value{page}%
    \EvenPageContent%
    \newpage
  \fi
}

\newcommand{\EvenPageContent}{%
  The content of this environment is supposed to be printed on even-numbered pages. On the other hand, even-numbered pages are supposed to contain none of the main text.
}

\begin{document}

This is the main text, which is only to appear on odd-numbered pages.
\lipsum[1-22]
\end{document}

información relacionada