# How do I generate only the first 10 pages of a document?

I use pdflatex to generate my documents. I want to create a preview of my document and generate only the first 10 pages, but I still want the full table of contents. How do I do that?

-
My comment may not answer your question. Do you know \includeonly which is invoked in the preamble to activate only one inclusion but the whole indexing and cross referencing still work? –  xport Jun 5 '11 at 15:10
Yes, I know about \includeonly but the first 10 pages end in the middle of chapter two, which is where I want to stop. –  Peteris Krumins Jun 5 '11 at 15:20
A simple quick and efficient technique. Insert \end{document}' where you want to break off. Keep life simple. –  Yiannis Lazarides Jun 5 '11 at 15:38
@Yiannis: But how can you know the number of pages exactly? :-) –  xport Jun 5 '11 at 15:45
@xport From the TOC of the first full run! –  Yiannis Lazarides Jun 5 '11 at 17:27

\documentclass[a4paper]{article}
\usepackage[1-10]{pagesel}

\begin{document}
% text
\end{document}


Thanks to Heiko Oberdiek. Remember, though, that references and table of contents will be incomplete. An alternative way is to compile the whole document and load its first ten pages in another one via pdfpages.

-
The problem with pdfpages is that the included PDF loses the links that it has. :( –  Peteris Krumins Jun 5 '11 at 15:23
+1 I just have known this good package. –  xport Jun 5 '11 at 15:28
@Peteris: The solution given above does not use pdfpages. @egreg just added another method by using pdfpages. :-) –  xport Jun 5 '11 at 15:38
@Peteris: there are free pdf manipulation tools that do what you want. –  egreg Jun 5 '11 at 15:42
@Peteris, @egreg -- if a complete run has previously created a full table of contents, it should suffice for the partial run to insert the command \nofiles` in the preamble. then the old toc (and aux files) won't be overwritten. of course, this doesn't work if it's necessary to have intermediate working files for the first ten pages. –  barbara beeton Jun 6 '11 at 12:39