Делайте что-нибудь на каждой второй странице

Делайте что-нибудь на каждой второй странице

Существует ли способ печатать только основной текст документа на каждом листе?второйстраницу, выполняя при этом какой-то другой код на других страницах? Мне нужно что-то, что работает как в примере ниже:

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

решение1

Посмотрите на пакет everypageи ifthen. everypageпредставляет хук, который вызывается после установки каждой страницы. Поэтому мне нужно вызвать мою \checkthatpageкоманду только для первой страницы вручную, для всех остальных страниц используется хук. Возможно, есть более сложные решения, но я их пока не нашел.

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

решение2

Я бы занялся этой проблемой на более низком уровне: \shipoutПроцедура, которая вызывается TeX, когда страница заполнена и ее нужно отправить. На этом этапе мы можем просто добавить еще одну страницу с предполагаемым содержимым:

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

Связанный контент