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.

I'm trying to create a somewhat specially formatted document, with some text on the recto (right side) and a graphic on the verso (left side). This is for a brochure of sorts. See below:

---------    ---------
|       |    |       |
| text  |    |  fig  |  
|       |    |       |
|   n   |    |  n+1  |
--------     ---------

My idea is to compile two separate documents -- one will have the text, and the other the graphics, and these are easy to create. With some pdftk wizardry, I can easily mix the pages together in the order they should appear, together with some additional front and back matter.

Now, I want to have page numbers on each page, and for this, they need to be incremented by two for each document. I guess I could try to do this manually, but I was kinda hoping there could be a better way to do it.

All kinds of ideas welcome. I'm using LaTeX, but ConTeXt solutions will be interesting to see as well. If you think of another way to do the whole thing, feel free to give it a go.

Bonus points for specifying arbitrary page increment.

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

This idea popped into my mind: Using \afterpage to simply increase the page counter after every page. Note the recursive call. This allows for arbitrary, but fixed page increments. Variable page increments would need some form of \increasethispagenumber{<n>} macro in the text which sets the increment. I think you get the idea.

\documentclass{article}

\usepackage{afterpage}

\def\incpage{\addtocounter{page}{1}\afterpage{\incpage}}

\begin{document}

\afterpage{\incpage}

A
\newpage
B
\newpage
C
\newpage
D
\newpage
E
\newpage
F
\end{document}

Works fine in my simple test.

share|improve this answer
    
I'm not very well versed in TeX, but why the \afterpage argument doesn't expand forever, given that is makes a recursive call? (The solution works beautifully, BTW). –  Martin Tapankov Feb 18 '11 at 10:09
    
@MartinTapankov: Because the \afterpage content is not expanded directly but only after the page. The then resulting new \afterpage counts for the next page, not the current one. –  Martin Scharrer Feb 18 '11 at 10:15
    
@MartinScharrer: Ahh, I see. Thanks for the explanation. –  Martin Tapankov Feb 18 '11 at 10:19
1  
@Martin: the behaviour of \afterpage is very interesting! Thanks. –  Bruno Le Floch Feb 19 '11 at 21:41
    
@Bruno: It's often used to flush floats: \afterpage{\clearpage}, but comes in handy for other things to –  Martin Scharrer Feb 19 '11 at 21:44
show 4 more comments

Beside changing the page counter you can also simply change the output and leave the counter as is:

\documentclass[a4paper,10pt]{scrartcl}
\renewcommand\thepage{\number\numexpr 2*\the\value{page}\relax}
\begin{document}


a\newpage b\newpage c\newpage d\newpage
\end{document}
share|improve this answer
    
That works too; one needs to only fiddle with the formula instead of using \setcounter{page}{n} or similar for the starting offset. This is quite flexible as well. Thanks! –  Martin Tapankov Feb 18 '11 at 10:40
add comment

A slightly less obvious way of doing this (and probably less robust than Martin's) is to use etoolbox to patch the macro that actually outputs the page number.

\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@outputpage{\stepcounter{page}}{\stepcounter{page}\stepcounter{page}}{}{}
\makeatother
\begin{document}
\section{A}\label{sec:A}\pageref{sec:A}\newpage
\section{B}\label{sec:B}\pageref{sec:B}\newpage
\section{C}\label{sec:C}\pageref{sec:C}\newpage
\section{D}\label{sec:D}\pageref{sec:D}
\end{document}

Here, the single \stepcounter{page} is replaced by two of them.

share|improve this answer
    
Hmm, the etoolbox manual says \patchcmd is robust; where do you think there might be issues with this particular use? (or do you mean "robust" as in "reliable", not in the TeX sense). –  Martin Tapankov Feb 18 '11 at 12:48
    
@Martin: I meant reliable. If the output routine is replaced before the \patchcmd, then this might fail silently (although that is easy to check by adding an error message to the last argument). If it is replaced after the \patchcmd, then it will have had no effect. –  TH. Feb 18 '11 at 13:12
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.