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.

Possible Duplicate:
How to keep the last page number even?

Is there a way of forcing an even number of pages in output ?

What I mean is to make pdflatex document "intelligent" it will add or not, blank page on the end to ensure there is always produced even number of pages.

(Purpose: I produce many of such pdfs and later combine them with external tool together in order to produce on pdf for double-side printing)

share|improve this question

marked as duplicate by lockstep, Marco Daniel, percusse, diabonas, clemens Aug 28 '12 at 18:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers 3

up vote 12 down vote accepted

Issue \clearpage at the end of the document; then check whether the page number is odd and do nothing in this case, otherwise eject an empty page; the following code in the document preamble will do:

\AtEndDocument{\clearpage\ifodd\value{page}\else\null\clearpage\fi}

This works independently of the oneside or twoside option. In the latter case

\AtEndDocument{\cleardoublepage}

is sufficient (as stated by Ulrike).

share|improve this answer
    
Isn't testing for \value{page} unreliable, as shown in the MWE to the linked question? –  lockstep Aug 28 '12 at 16:11
2  
@lockstep If the test is put just after \clearpage it gives the correct result, because the output routine has just been performed. –  egreg Aug 28 '12 at 16:19

This may not be the cleanest way, and probably someone will come with something better:

\documentclass{article}

\usepackage{lipsum}
\usepackage{ifthen}

\begin{document}

\lipsum

\lipsum

\lipsum

\ifthenelse{\isodd{\thepage}}
{\cleardoublepage\mbox{}}
{}

\end{document}

Add/remove \lipsum to see how the number of pages evolves. The document will always have an even number of pages.

Invert {} and {\cleardoublepage\mbox{}} to ensure an odd number of pages.

share|improve this answer
    
What's the advantage above using only \cleardoublepage ? –  Grzegorz Wierzowiecki Aug 28 '12 at 10:16
    
It's dynamic. Using \cleardoublepage will add a new page, whether the number of pages is even or not. This code only adds a new page if the number of pages is odd, ensuring an even number of pages. –  ℝaphink Aug 28 '12 at 10:17
1  
@Raphink No, \cleardoublepage will not add always a new page. It contains the same test you are doing (and it contains a \clearpage before the test to avoid problems with the asynchronous page which your code is missing.) –  Ulrike Fischer Aug 28 '12 at 10:29
    
@Raphink I would love to see your solution improved by Ulrike suggestions, as It's much more flexible to standard \cleardoublepage. On the other hand, you might like to show how to use it for setting up "this page is intentionally blank" : tex.stackexchange.com/questions/69115/… –  Grzegorz Wierzowiecki Aug 28 '12 at 10:30
    
The clean way of doing it is @egreg's (not surprisingly). –  ℝaphink Aug 28 '12 at 10:41

This here gives two pages:

\documentclass{book}
\begin{document}
abc
\cleardoublepage
\end{document}
share|improve this answer
    
Is it book class specific or general solution for any documentclass? –  Grzegorz Wierzowiecki Aug 28 '12 at 10:15
    
It works for any document class. –  ℝaphink Aug 28 '12 at 10:18
    
@UlrikeFischer Raphink suggests \cleardoublepage adds page always. I need to add page only when is it needed. What do you think about it ? –  Grzegorz Wierzowiecki Aug 28 '12 at 10:19
    
@GrzegorzWierzowiecki No, \cleardoublepage works like you want only if twoside mode is active. With oneside (default e.g. in report or article) \cleardoublepage calls only \clearpage. But you can easily define your alwayscleardoublepage without this restriction. The original definition is in latex.ltx. –  Ulrike Fischer Aug 28 '12 at 10:23
1  
@UlrikeFischer Could you provide please an one more example showing how to make it working with article documentclass? I believe it will useful for other readers. –  Grzegorz Wierzowiecki Aug 28 '12 at 10:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.
http://tex.stackexchange.com/questions/69111/forcing-even-number-of-pages-in-output-latex-pdflatex?answertab=oldest
tex.stackexchange.com
crawl=CC-MAIN-2015-18
84611
application/http; msgtype=response
sha1:4F7M2JIQPVTXX7T2QCI7JEOGDSF5Z45R
<urn:uuid:0839a64d-aebe-4dd1-a508-b17ed3f9725c>
2015-05-06T05:28:35Z
104.16.12.13
sha1:HHCKDLOLXI3EZ77DX6Q5TEAM4S6XQT6Y
<urn:uuid:6a8fa161-4d00-4597-a2d5-6739f4051dd3>
http://tex.stackexchange.com/questions/69111/forcing-even-number-of-pages-in-output-latex-pdflatex?answertab=oldest
length
response
<urn:uuid:9414ebb8-699c-47a3-9b7f-e1859d9a0762>
robots: classic
hostname: ip-10-235-10-82.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2015-18
operator: CommonCrawl Admin
description: Wide crawl of the web for April 2015
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf