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.

I want to create a book type file, where each chapter is separatly compiled. That is I get the whole thing as well as each individual chapters in pdf or dvi or ps format. How do I do that?

share|improve this question
1  
Compiling each chapter separately will produce a PDF file with the same "Chapter 1" heading, are you ok with this? –  Who is crazy first Jul 18 '12 at 7:41
    
Welcome to TeX.SE. I would suggest you have a look at the the standalone package. There are numerous examples on this site. –  Peter Grill Jul 18 '12 at 7:49
2  
Probably the quickest method is to separate the chapters with a PDF utility such as qpdf or pdftk –  egreg Jul 18 '12 at 7:50
    
possible duplicate: tex.stackexchange.com/questions/31334/… –  matth Jul 18 '12 at 9:53
    
It's not quite clear from your question exactly what you want to achieve with regard to page and chapter numbering. Have you looked at the functionality provided by \include and \includeonly, described, for example, on page 18 of The LaTeX Companion (2nd Edition)? –  Brent.Longborough Jul 18 '12 at 9:53

2 Answers 2

One approach would be to have each chapter in a separate file and then use the \include command to fold them all into a big main file. Then you can use \includeonly to compile each chapter individually. If you compile the whole thing first, then when you do \includeonly you'll get the right numbering and crossreferences would work.

To automate things, what you'd want is a script that does \includeonly for each chapter one after the other, and also changes the jobname such that each chapter is compiled to a distinct file.

share|improve this answer

Without using packages, you could use simply the \input commands:

Write each chapter in a separate file (don't compile these files):

In chapter1.tex:

intro to chapter 1
\section{section 1}
section 1 of chapter 1
\section{section 2}
section 2 of chapter 1

In chapter2.tex:

intro to chapter 2
\section{section 1}
section 1 of chapter 2
\section{section 2}
section 2 of chapter 2

Then write your book as:

in book.tex:

\documentclass{book}

\begin{document}

\title{Title}
\maketitle

\tableofcontents

\chapter{Chapter 1 title}
\input{chapter1}

\chapter{Chapter 2 title}
\input{chapter2}

\end{document}

Compile this file to get your full book.

To get the separate chapter as articles, you can compile the following file:

In chapter1Article.tex:

\documentclass{article}

\begin{document}

\title{Title of chapter X}
\maketitle

\input{chapterX}

\end{document}

If you want them as a book with only one chapter, use the following file. To get the right chapter number, use \setcounter.

In chapter1Book.tex:

\documentclass{book}

\begin{document}

\setcounter{chapter}{X-1}

\chapter{title of chapter X}
\input{chapterX}

\end{document}

etc...

share|improve this answer

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.