18

Okay, I've puzzled over this for a while and I can't work it out.

I have a document with several chapters, using the memoir class. I've separated each chapter into separate files, and I'm including them using \input.

I did this because at times I may want to produce a file with just chapter 2, or just chapter 3 and not the others. But when I do this, the chapters get renumbered.

How can I make my file customizable, so if I want to, I can make a pdf with just Chapter 2, or just Chapter 3, and no 1?

2 Answers 2

21

You should use \include instead of \input, and then in the preamble say with \includeonly which of the included files you want in your pdf file, like this:

\documentclass{memoir}
\includeonly{chapter1,chapter3}
\begin{document}
\include{chapter1}
\include{chapter2}
\include{chapter3}
\end{document}

The first run(s) of pdflatex should be done without the \includeonly in order to get all the references right.

5

On the off-chance that you prefer to \input your chapters rather than \include-ing them, then the solution involves nothing more than redefining the chapter number prior to selectively input-ing your chapters. If that's the path you want to take then here's all you need to do:

\documentclass{memoir}
\usepackage{calc}  % for the arithmetic below

\newcommand*\chapternumber[1]{%
  \setcounter{chapter}{#1 - 1}%
}

\begin{document}
  \mainmatter
%  \chapternumber{1}\input{chapter1}
  \chapternumber{2}\input{chapter2}
\end{document}

I'll leave it to you to work out why the arithmetical adjustment is warranted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .