4

I'm building a set of 6 PDF books in LaTeX, and I'd like the page numbers to monotonically increase throughout the series. For example, Book 1's last page number is 341, so Book 2's first page number should be 342. Each book has its own set of .tex files which compiles into its own PDF.

How can I ensure the page numbers increase across these separate .tex files?

Perhaps I could use the xr package (example) to reference the preceding book's \pageref{LastPage} (example)?

0
3

Since the page numbering restarts at \mainmatter, you need to keep the main matter in separate files from the \frontmatter (and avoid \backmatter). Your master file uses \includeonly to select which book to print. Here the first book is in test5.tex and the second is in test6.tex.

There was a slight problem in that the first book ended on an odd page, so the extra page before the chapter wound up in the second book.

\documentclass{book}
\makeatletter
\newcommand{\skipextrapage}{\if@twoside
  \ifodd\value{page}\else\stepcounter{page}\fi
\fi}
\makeatother

\includeonly{test6}% select one at a time
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\include{test5}
\skipextrapage
\include{test6}
\end{document}

where test5.tex contains

\chapter{First Chapter Book1}
First book starts on \thepage

and test6.tex contains

\chapter{First Chapter Book 2}
Second book starts on \thepage

So how do you want the chapters numbered and the table of contents divided (easiest would be to make each book a part and possibly redefine \partname)?

toc

2
  • This is a nice solution. Is there a way to generate both books with one command? It seems that the main tex file can either be configured to produce one book or the other. Dec 16 '16 at 13:34
  • Only one PDF per LaTeX run (externalize counts as an extra run). Dec 16 '16 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.