[Tex/LaTex] Forcing even number of pages in output (LaTeX — pdflatex)

double-sidedlastpagepage-breaking

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)

Best Answer

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).

Related Question