每隔一页做某事

每隔一页做某事

有没有办法只打印文档中的每一页的主文本第二页面,同时在其他页面上运行其他代码?我想要的是像下面这个例子一样运行的东西:

\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

看一下everypageandifthen包。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}

相关内容