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.

The following code typesets a 12 page document; text only appears on every other page and there's an empty page between two text pages:

\documentclass{article}
\usepackage{atbegshi}
\usepackage{lipsum}

\makeatletter
\AtBeginShipout{%
  \ifodd\c@page
    \begingroup
      \AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox
      \global\AtBegShi@Discardedtrue
      \mbox{}\thispagestyle{empty}\clearpage
    \endgroup
  \else
  \fi%
}
\makeatother

\begin{document}

\lipsum[1-30]

\end{document}

Now I am trying to number sequentially the pages with text in them; with the code above pages with text are numbered 1,3,5,... but I would like them to be 1,2,3,... I did some attempts but none of them produced the desired result. How can I achieve the consecutive numbering?

The idea is to wrap this into a command that will allow to change the behaviour of the text flow inside a group: when invoked, the command will cause the text to be typeset in every other page but maintaining the consecutive numbering for the pages with text; once the group ends the text and numbering must return to their normal behaviour.

share|improve this question
1  
What is an odd page? The third absolute page would have page number two. –  Heiko Oberdiek Aug 19 '12 at 6:18
2  
I do not recommend explcitly or implicitly calling \shipout inside \AtBeginShipout. An empty page can output by \AtBeginShipoutOriginalShipout\null (absolute page counters have to be corrected manually). \clearpage might even add further float pages. –  Heiko Oberdiek Aug 19 '12 at 6:22
2  
In the shipout routine the page and therefore its page number is known, \label based approaches like \checkoddpage are not needed. –  Heiko Oberdiek Aug 19 '12 at 6:24
    
@HeikoOberdiek thanks for your comments; I quite don't understand the second one... this is the first time I am trying to do something with the shipout mechanism and I am kind of lost. Where am I calling \shipout inside \AtBeginShipout? Why don't you recommend doing so? –  Gonzalo Medina Aug 19 '12 at 13:35
    
The shipout routine is called by the asynchronous output routine, in the middle of shipout the example adds material to the main vertical list and calls \clearpage. Thus it can happen that in the middle of shipping out a page material is added somewhere later and the output routine is called again and might want to ship out a page while shipping out a previous page. A mess already. atbegshi is not reentrant, one of the reasons are possible global assignments of the shipout box. –  Heiko Oberdiek Aug 19 '12 at 14:02
show 1 more comment

1 Answer

up vote 5 down vote accepted

This seems to work for me. The trick is to use a different counter for the number of shipouts instead of the pages.

\documentclass{article}
\usepackage{changepage}
\usepackage{etoolbox}
\usepackage{atbegshi}
\usepackage{lipsum}

\newcounter{mypage}

\makeatletter
\AtBeginShipoutInit{\setcounter{mypage}{0}}
\AtBeginShipout{
  \ifnumodd{\value{mypage}}{
    \AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox
    \addtocounter{page}{-1}
  }{
    \mbox{}\thispagestyle{empty}\clearpage
  }
  \addtocounter{mypage}{1}
}

\makeatother

\begin{document}

First page \pageref{test}
Last page \pageref{test2}

\label{test}
\lipsum[1-30]
\label{test2}

\end{document}
share|improve this answer
add 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.