Faça algo em cada segunda página

Faça algo em cada segunda página

Existe uma maneira de imprimir apenas o texto principal do documento em cadasegundopágina enquanto executa algum outro código nas outras páginas? O que eu quero é algo que funcione como no exemplo abaixo:

\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}

Responder1

Dê uma olhada no pacote everypagee ifthen. everypageintroduz um gancho que é chamado após cada página ter sido definida. Então preciso chamar meu \checkthatpagecomando apenas para a primeira página manualmente, para todas as outras páginas o gancho é usado. Pode haver soluções mais sofisticadas, mas ainda não as encontrei.

\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}

Responder2

Eu resolveria esse problema em um nível inferior: a \shipoutrotina, que é invocada pelo TeX quando uma página está cheia e precisa ser enviada. Nesta fase, podemos apenas adicionar outra página com o conteúdo pretendido:

\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}

informação relacionada