2ページごとに何かする

2ページごとに何かする

文書のメインテキストのみを毎回印刷する方法はありますか?2番他のページで他のコードを実行しながら、ページを移動できますか? 私が欲しいのは、以下の例のように実行されるものです:

\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およびパッケージをご覧くださいiftheneverypage各ページが設定された後に呼び出されるフックが導入されています。したがって、\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}

関連情報