It's my first question here. Sorry if it doesn't follow the rules.

I have:

I'm writing a manual in the book class with pdflatex (TeX Live under Linux). Each chapter is stored in a separate tex-file (chapter1.tex, chapter2.tex).

Also I'm using minitoc package for creating the table of contents for each part. The commands for generating the main table of contents and the table of contents for each part are stored in separate tex-files too (maintoc.tex, parttoc.tex).

I need:

After compiling the whole document I am using \includeonly for obtaining separate pdf-files (thanks to post). Using hyperref and zref-xr packages I get correct hyperlinks between different pdf's corresponding to different chapters, but links in the main table of contents and in the table of contents for each part are broken.

Minimal working example:








\part{The first and last part}



\chapter{The first chapter}
See chapter~\ref{chap:second}.



\chapter{The second chapter}
See chapter~\ref{chap:first}.

The sequence of commands I use:

  1. pdflatex -jobname=tmp main && mv tmp.pdf main.pdf (x2)
  2. pdflatex -jobname=tmp "\def\tosplit{1}\includeonly{maintoc}\input{main}" && mv tmp.pdf maintoc.pdf
  3. pdflatex -jobname=tmp "\def\tosplit{1}\includeonly{parttoc}\input{main}" && mv tmp.pdf parttoc.pdf
  4. pdflatex -jobname=tmp "\def\tosplit{1}\includeonly{chapter1}\input{main}" && mv tmp.pdf chapter1.pdf
  5. pdflatex -jobname=tmp "\def\tosplit{1}\includeonly{chapter2}\input{main}" && mv tmp.pdf chapter2.pdf

I tried advice from the author Heiko Oberdiek of hyperref and zref packages. Honestly, it is not clear for me, but it works unless you have just two pdf's (TOC and the rest), otherwise it doesn't. It always tries to open just one pdf, but I have many of them.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Looks like a good first question! Let's hope it gets some good answers ;). – cfr Dec 16 '14 at 0:49
  • I take it this is intended for a web site. The easiest way would be to write the table of contents manually after the rest of the book, using \href for cross-file links. You can link to previously named targets in the files if you know their names. Look at the toc file for the last name in \contentsline. – John Kormylo Dec 16 '14 at 2:53
  • Hmmm, you could do it automatically by creating you own \contentsline macro and \input each of the toc files one at a time. – John Kormylo Dec 16 '14 at 2:57
  • @John Kormylo. thank you! Really, it isn't a bad idea to create a table of contents using \href manually (for multi-pdf version). Yes, such TOC will not have page numbers, but they are not so important in the multi-pdf version. More important thing is that manually created hyperlinks will lead to external pdf files (i.e. another parts or chapters stored in separate pdf files). But in one-pdf version (the whole book in one file) I will use just \tableofcontents, which provides page numbers and internal hyperlinks. – Rishat Dec 16 '14 at 14:11
  • If you are creating one PDF using multiple TeX files then just bite the bullet and run the whole thing in one go using \include. You can still test each chapter separately, but you will need to split the preambles from the part to be included. – John Kormylo Dec 16 '14 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.