Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 17 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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