# How to make page numbering continuous after a second \mainmatter?

I am writing a document with multiple \mainmatters and \backmatters. The structure is basically:

...
\mainmatter
\backmatter
...
\mainmatter
\backmatter
...


Is there a simple way of preventing LaTeX to reset the page counter? Also \backmatter should not reset the counter.

-
Welcome to TeX.SX! What's the purpose of alternating \mainmatter and \backmatter? –  egreg Jun 27 '12 at 14:34
Thank you :) The purpose is, that i have multiple documents, each with its own reference list, which i must summarize in tex using the book class. Since references should be listed in the backmatter multiple backmatters/mainmatter are necessary. –  Julian Jun 28 '12 at 5:27

This depends highly on the document class you're using. Taking the standard book as base, \fontmatter and \mainmatter both reset the page counter. \backmatter on the other hand doesn't:

\newcommand\frontmatter{%
\cleardoublepage
\@mainmatterfalse
\pagenumbering{roman}}
\newcommand\mainmatter{%
\cleardoublepage
\@mainmattertrue
\pagenumbering{arabic}}
\newcommand\backmatter{%
\if@openright
\cleardoublepage
\else
\clearpage
\fi
\@mainmatterfalse}


The important thing that causes the page numbering to be reset when issuing the above commands is \pagenumbering (taken from latex.ltx):

\def\pagenumbering#1{%
\global\c@page \@ne \gdef\thepage{\csname @#1\endcsname
\c@page}}


As mentioned, this sets the page counter to one (\global\c@page \@ne) and redefines the representation \thepage (\gdef\thepage{\csname @#1\endcsname\c@page}). So, with an issue of \pagenumbering{roman} (as is performed by \frontmatter), LaTeX issues something equivalent to

\setcounter{page}{1}
\renewcommand{\thepage}{\arabic{page}}


memoir does something similar. If your question is only "How to prevent LaTeX from resetting the page counter?", then you should not use \frontmatter and friends, or at least void what \pagenumbering is doing. You might just be better off redefining the page counter printing mechanism \thepage as is done above. Or, for convenience of use in order to stick to your current layout, perhaps the following suffices in your preamble (which removes the page counter resetting):

\makeatletter
\def\pagenumbering#1{%
\gdef\thepage{\csname @#1\endcsname \c@page}}
\makeatother


Finally, neither book nor memoir resets the page counter for \backmatter.

-
Wouldn't \def\pagenumbering#1{} be more economic? :) However, redefining \mainmatter seems to be better than changing drastically the meaning of an important command. –  egreg Jun 27 '12 at 19:41
@egreg: If the OP doesn't want to change to a different numbering representation (like roman or arabic), then yes. –  Werner Jun 27 '12 at 19:46

An easy solution to your problem is getting rid of the \pagenumbering command issued by \mainmatter, which is responsible of resetting the page number. So I propose

\makeatletter
\def\mainmatter{%
\cleardoublepage
\@mainmattertrue
\pagenumbering{arabic}
\def\mainmatter{\cleardoublepage\@mainmattertrue}
}
\makeatother


The first call of \mainmatter would do as usual, so the page numbering will be arabic, starting from 1. Then it redefines itself to issue only \cleardoublepage and \@mainmattertrue. The latter restores chapter numbering.

-