16

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?

doncherry
  • 54,637
  • 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? – Display Name Jun 05 '11 at 15:10
  • A simple quick and efficient technique. Insert `\end{document}' where you want to break off. Keep life simple. – yannisl Jun 05 '11 at 15:38
  • @Yiannis: But how can you know the number of pages exactly? :-) – Display Name Jun 05 '11 at 15:45
  • 1
    @xport From the TOC of the first full run! – yannisl Jun 05 '11 at 17:27
  • @Yiannis: I think egreg's solution is quicker because we do need to do compilation twice just for the purpose to lookup the TOC. :-) – Display Name Jun 05 '11 at 17:31
  • @xport \everypar{\ifnum\thepage>10 \stop\fi} will load faster!? – yannisl Jun 05 '11 at 17:51
  • @xport and it is a one liner! – yannisl Jun 05 '11 at 17:53
  • @Yiannis: Why don't you post it as the answer? – Display Name Jun 05 '11 at 17:55
  • @xport Because I think egreg's solution is better for someone, just starting with LaTeX. Also I am not sure if Peteris wanted ten physical pages or to break at page 10 to check if his sections are typesetting properly. – yannisl Jun 05 '11 at 18:10
  • @Yiannis: Do you have idea "how to generate only n characters/lines of a document?" – Display Name Jun 05 '11 at 18:16
  • @xport I am not sure if it can be done easily with TeX. Look at the microtype package, I am sure one can hook into one of the macros there, count chars using a counter and stop the document when you reach the limit, same for linenumbers probably only via lineno package. Post as a question and see what others come up with. – yannisl Jun 05 '11 at 18:47
  • @Peteris I thought so, just `\end{document}' at a nice place and be done! No need to complexify life! – yannisl Jun 06 '11 at 10:53

1 Answers1

21
\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.

egreg
  • 1,121,712
  • 1
    @Peteris: The solution given above does not use pdfpages. @egreg just added another method by using pdfpages. :-) – Display Name Jun 05 '11 at 15:38
  • 1
    @Peteris: there are free pdf manipulation tools that do what you want. – egreg Jun 05 '11 at 15:42
  • @Peteris: I think it is the final solution. – Display Name Jun 05 '11 at 17:35
  • 2
    @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 06 '11 at 12:39