是否有一種方法可以只列印文件中的主要文本第二頁面同時在其他頁面上運行其他程式碼?我想要的是像下面的例子一樣運行:
\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}