In the line of this post, I am looking for a way to compile a large document (~400 pages with 10 chapters) into a single pdf file and one additional pdf file per chapter.

Currently, I use pdftk to manually split the large pdf file after its pdflatex compilation. However, this is tedious in the sense that the page split may vary (addition in chapter 1 will shift page numbers of following chapters...).

Is there a way to compile a latex file between two labels for instance ? Ideally I would like to keep hyperlinks active in the final sub-pdf files (which is the advantage of pdftk...).

The only thing I can think of is the use of \ifnum in order to consider specific parts of the document but this will necessarily break all hyperlinks.

  • 1
    Effectively you need multiple runs. You could do that with a shell script or something similar and say, your chapters are numbered with file-0.tex, file-1.tex, etc. you could give it a jobname like 0 and it would use the jobname for doing an \includeonly.
    – TeXnician
    Jun 9, 2017 at 12:12
  • @TeXnician I see but I believe this would break the hyperlinks between chapters which is a problem.
    – Alain
    Jun 9, 2017 at 12:21
  • How do you imagine hyperlinks between chapters that aren't in the PDF? What should they show?
    – TeXnician
    Jun 9, 2017 at 14:12
  • Well let's say I have a link from chapter 2 to chapter 9 ",see chap. 9". If I make distinct compilations, my link will show up as ",see chap. ??". This is what I would like to avoid.
    – Alain
    Jun 9, 2017 at 14:51
  • @JohnKormylo That's what I thought too as I suggested it.
    – TeXnician
    Jun 10, 2017 at 16:24


Browse other questions tagged .