# How to give two \book{}s each its own Preface?

I have a book which contains two books, each having their own preface. Here's the structure:

\book{An exhortation to virtue}

\frontmatter

\chapter{Preface}

...

\mainmatter

\chapter{This is the first chapter of the first book}

...

\chapter{This is the second chapter of the first book}

...

\book{An instruction on virtue}

\frontmatter

\chapter{Preface}

...

\mainmatter

\chapter{This is the first chapter of the second book}

...

\chapter{This is the second chapter of the second book}

...


This structure is based on this answer's advice to create a Preface by using \chapter inside of \frontmatter.

Obviously this structure won't work because it assumes two separate front-matters.

So what's another way to create two prefaces for two books within the same book?

Another goal is that this book should have a single Table of Contents containing both books in their entirety.

• Instead of posting the image (which isn't actually that important to the question) create a small document that shows the structure of what you have already. It doesn't need to be fancy, just enough to show the \book structure you are using. Sep 8 '15 at 0:22
• @AlanMunn Okay I'll edit it right now, thanks for the advice. Sep 8 '15 at 0:26
• @sdegutis No, this is a bit too schematic. Make a complete compilable document showing what you have (without the content). So you want each book to have its own frontmatter part, with e.g. roman numbering. Sep 8 '15 at 0:42
• What are the special characteristics that make certain chapters a "preface"? Lack of chapter number? special formatting in the TOC? page numbers in "roman" rather than "arabic"? other things?
– jon
Sep 8 '15 at 0:52
• @jon All of those, plus chapter numbering starts over at Chapter 1 after each Preface. Sep 8 '15 at 1:01

I'd just use

\counterwithin*{chapter}{book}


Then each time \book is used, chapter will be reset to zero.

• (+1) I hope you will not mind that I changed my answer to integrate this rather than \apptocmd. If you object, you can use my code to create a complete example and I'll delete mine.
– cfr
Sep 8 '15 at 10:17
• @cfr no problem. Just leave it. I'm currently at a tablet so large examples like your is not something I'm going to do on this device Sep 8 '15 at 10:20

Memoir does very nearly the right thing with the code you posted. Originally, I was not sure if it has a way to reset the chapter numbers per book, but I couldn't find it and couldn't think, so used etoolbox to patch the command. However, daleif's answer is much better and can easily be integrated into the code I was using. Other than that, I just changed your dots to Kant and added a table of contents:

\documentclass{memoir}
\counterwithin*{chapter}{book}
\usepackage{kantlipsum}

\begin{document}

\tableofcontents

\book{An exhortation to virtue}

\frontmatter

\chapter{Preface}

\kant[1]

\mainmatter

\chapter{This is the first chapter of the first book}

\kant[1]

\chapter{This is the second chapter of the first book}

\kant[1]

\book{An instruction on virtue}

\frontmatter

\chapter{Preface}

\kant[1]

\mainmatter

\chapter{This is the first chapter of the second book}

\kant[1]

\chapter{This is the second chapter of the second book}

\kant[1]
\end{document}


• Thanks. This technically works, but I can't help but feel it's a bit hacky. I'll wait a day or two to give others a chance to chime in also. Sep 8 '15 at 3:45
• @sdegutis Waiting for other answers is wise. But I don't see why you'd think using Memoir 'a bit hacky'. Or do you mean the use of etoolbox to reset the counter? You should be able to combine this with daleif's answer to avoid that.
– cfr
Sep 8 '15 at 10:10