# Why do \pagenumbering and \setpagecounter break \cleardoublepage?

It had taken me a few hours to hunt down a bug with my Thesis when I discovered \cleardoublepage does not have the correct behaviour for twosided documents. It should force a page following the command to begin on an odd page so that when printed for book binding, the inner margin is on the left hand side.

I have sort of identified the cause. In the following MWE, two lines make \cleardoublepage fail if either of the line is set in the state in the following code.

To remedy this, firstly one must have the first page with an odd number, and secondly one must also remove the \pagenumbering{roman} line.

\documentclass[a4paper,10pt,twoside,english]{book}
\usepackage{lipsum}

\begin{document}
\setcounter{page}{0} %Title page must start from an odd number for \cleardoublepage later to work!?
\centering\Huge Testing \texttt{\textbackslash cleardoublepage}
\clearpage\pagenumbering{roman} %The roman numbering here breaks \cleardoublepage too
\normalsize\lipsum[2-7]\clearpage
\cleardoublepage
\chapter{I need to begin on an odd page}
\end{document}


In my Thesis, I would like my title page label to be p.0, then next page starts from roman i, ii, iii... then switch to arabic. I am having no luck getting the chapters to appear as odd pages. I can sort of guess the reason, by switching pagenumbering number system and page number counter arbitrarily, one may turn a even page label to an odd and vice versa. However, I see no merit in \cleardoublepage checking the oddness of the page label, but not the actual page number (number of pages as appears in the output, page label p. ii may actually be the third page, for example). Any way to fix this?

-
LaTeX (by default) does not have any record of the logical page number (ie the number of pages shipped out) it only knows the value of the page counter, \cleardoublepage just does \clearpage then if the current page is even it does a white line then another \clearpage so that the page counter is then odd. –  David Carlisle Jan 24 '13 at 17:40
This example works as expected, in my opinion. That is, "what David said." –  Werner Jan 24 '13 at 17:41
If you use the openright option to the book class \chapter will issue \cleardoublepage itself at the right point. –  David Carlisle Jan 24 '13 at 17:42
@DavidCarlisle Indeed, plus openright is the default behavior with book. –  lockstep Jan 24 '13 at 17:43
Since it appears that you're using the book document class, why not use commands such as \frontmatter and \mainmatter -- i.e., logical markup instructions -- and let LaTeX do all the work that really belongs "behind the scenes," such as using roman page numbering in the front matter (such as half title page, title page, dedication page, table of contents, foreword) and arabic page numbering in the main matter, issuing \cleardoublepage instructions as needed, etc.? The title page, at least in traditional book setups, shouldn't get an explicit page number anyway. –  Mico Jan 24 '13 at 17:46

Your problem is essentially due to setting the page number to 0 on the first physical page which means that the parity of all pages are out. Essentially none of the \clear(double)page commands in your example are having any effect as the page numbering and chapter commands are already issuing those commands.

\documentclass[a4paper,10pt,twoside,english]{book}
\usepackage{lipsum}

\begin{document}

\begin{titlepage}
\centering\Huge Testing \texttt{\string\cleardoublepage}
\end{titlepage}

\frontmatter

\lipsum[2-7]

\chapter{I need to begin on an odd page}
\end{document}


Keeps the parity of the physical page and printed page

1  -    Title
2  2    blank before front matter (you could use a thispagestyle if 2 not needed
3  i    front matter
4  ii
5  iii  first chapter

-
Thanks, I guess the trick to make sure the first content page reads p.i is to either trick \cleardoublepage by changing the page counter and back or insert a blank page –  Mobius Pizza Jan 25 '13 at 10:07
The code above already makes the first page with content i the blank page is inserted by the cleardouplepage executed by \frontmatter. cleardoublepage uses the current page style for its blank page so thenmber 2 appears, if you don't want number use \pagestyle{empty}. I am not sure what you think is a "trick" The above markup just directly mirrors the document structure, it was setting page counter by hand that was causing the problem. –  David Carlisle Jan 25 '13 at 10:16