Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does there exist a way to only print the main text in the document on every second page while running some other code on the other pages? What I want is something that runs like in the below example:

\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}
share|improve this question
    
this question asks for much the same result; unfortunately, it doesn't have an answer. an approach to parallel texts across a two-page spread is given in this question. –  barbara beeton Mar 17 at 19:22
    
Have a look at tex.stackexchange.com/questions/6143/…, I guess it answers your question –  Uwe Ziegenhagen Mar 17 at 19:29
    
@UweZiegenhagen, I may very well be wrong, but I don't see any obvious way to apply that to this problem. I need the same code to be executed at every even page, not just once if the page is even. –  Gaussler Mar 17 at 19:34
    
@barbarabeeton, there may very well be a solution there, but I'm afraid I don't understand much of the code in your second link. :-( –  Gaussler Mar 17 at 19:35
add comment

2 Answers 2

up vote 6 down vote accepted

Have a look at the everypage and ifthen package. everypage introduces a hook which is called after each page has been set. So I need to call my \checkthatpage command only for the first page manually, for all other pages the hook is used. There may be more sophisticated solutions, but I haven't found them, yet.

\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}
share|improve this answer
    
Sounds very promising indeed! I'll try it out and return shortly. :-) –  Gaussler Mar 17 at 19:57
    
For some reason, it stops working after the second page. Try adding some more \clearpages and notice the result. "Even" and "Odd" are completely missing. –  Gaussler Mar 17 at 20:25
    
Strange, I'll have a closer look tomorrow. –  Uwe Ziegenhagen Mar 17 at 20:27
1  
Perhaps you meant everypage? –  Gaussler Mar 17 at 20:30
2  
I would use \value{page} instead of \thepage, as the latter may return roman numbers or other kinds of fancy formatting. See what-is-the-proper-method-of-accessing-a-counter –  Daniel Mar 18 at 8:08
show 5 more comments

I would tackle this problem at a lower level: The \shipout routine, which is invoked by TeX when a page is full and needs to be shipped out. At this stage, we can just add another page with the intended content:

\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}
share|improve this answer
    
Well, thinking a bit more about it, that is basically the same approach as suggested by Uwe. It is just based on other packages. –  Daniel Mar 17 at 23:19
    
Yes, for most purposes, it works exactly the same way. But actually, this approach made some things work better in my concrete document. :-) –  Gaussler Mar 18 at 9:35
    
So thanks for the answer, it may be the one I end up using. :-) –  Gaussler Mar 18 at 10:11
    
I don't really understand the purpose of the code \AtBeginShipoutOriginalShipout \box\AtBeginShipoutBox. It rendered a warning in my document, and when I commented it out, everything still worked. I looked into the documentation of atbegshi, but did not get many answers there. What does that code do? –  Gaussler Mar 19 at 7:44
    
@Gaussler: You are absolutely right, it is not necessary! The purpose was to ship out the current page (provided in \AtBeginShipoutBox) before inserting the \EvenPageContent, so that the latter does not make it accidentally onto an odd page. However, that was a logical mistake: When the shipout handler is invoked, LaTeX has already finished the construction of the odd page, so new content goes to the next page anyway. I have simplified the code. –  Daniel Mar 19 at 8:58
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.