Generalpossible to compile only chapter

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
mappo
Posts: 25
Joined: Thu Nov 29, 2007 11:19 am

possible to compile only chapter

Post by mappo »

I'm considering converting my one-enormous-main-file system to a structure with a smaller one
that \include:s one-chapter-files.

The problem is that the first command on the first line in these files is \chapter{} and to
preview the document I have to compile the main file.

Here's what I want:
The document is divided into one-chapter-files for easy re-organizing.
The one-chapter-files can be compiled on their own for easy pre-viewing.

Is this possible?
Or is the best solution to exclude \include-lines by %commenting them?

I'm using TeXnicCenter\MikTeX on XP.
If you don't recycle, you're throwing it all away.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10360
Joined: Mon Mar 10, 2008 9:44 pm

possible to compile only chapter

Post by Stefan Kottwitz »

Hi mappo,

you could use \includeonly. Here is a good description: Structuring Large Documents.

Stefan
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

possible to compile only chapter

Post by T3. »

In the preamble of your document put:

Code: Select all

\includeonly{chap1,chap2}
Then only chap1.tex and chap2.tex will be included, other \include commands will be ignored. This works only for \include commands, \input works as usual.

I, personally, tend to split my documents into many, many files (read 100+) some of them generated automatically by some external tools/scripts. So I use \input command a lot and the above method doesn't work for me. Instead, I usually have a main file like this:

Code: Select all

\input{preamble}
\begin{document}
\input{body}% not a corpse ;)
\end{document}
If I want to preview only some fragment, it is enough to substitute \input{body} -> \input{fragment}

Cheers,

Tomek

Edit:
Damn, I have to write faster, Stefan beat me to it :)
User avatar
mappo
Posts: 25
Joined: Thu Nov 29, 2007 11:19 am

Re: possible to compile only chapter

Post by mappo »

Great suggestions! Thank you both!

My thesis writing just got an order of magnitude more efficient.
If you don't recycle, you're throwing it all away.
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

possible to compile only chapter

Post by T3. »

I'm glad we could help :)
My thesis writing just got an order of magnitude more efficient.
Wow, now that's a difference :o

Cheers,

Tomek

PS.
If you're constantly recompiling your documents and you're looking for some ways to speed up that process, there are also other possibilities than exclusion of chapters. It's not uncommon that the actual compilation of your document takes much less than loading of all the packages, so exclusion of chapters doesn't help all that much. In such a case dumping a custom format file from the preamble is a very effective way to cut down on the compilation time.
Post Reply