0

I'm creating a pdf-latex file with a python script such as it is explained in Generating pdf-latex with python script and it works perfectly.

However, I would like to generate a table of contents for my file. The problem is that, using a latex generator as TexWorks for example, you need to compile it twice (in first compiling you generate the .pdf file without toc and .out and .toc files with toc's information, while in second compiling toc's information is added to the pdf.file), but it doesn't work if you run the script twice.

Thanks you in advance.

A. Garzon
  • 1
  • 2

1 Answers1

0

This isn't really feasible, because any script that generates the LaTeX file can't know how the subsequent LaTeX run will paginate the output.

If, for example, you were to adjust the class file or included style files that the generated LaTeX used – or in an extreme case if there were version-skew differences between those class or style files on different machines – then the pagination could end up completely different for the same input in two different runs.

The .toc file generation records which page sections and tables actually end up on, and that's information which is only available when generating the output. Indeed, in not-too-extreme cases, it can need three runs of LaTeX from a standing start, if the presence of a non-empty TOC (on the second run) results in the pagination of the rest of the document changing. Indeed, I recall that it's possible, with a little thought, to devise a LaTeX file which always needs a further run!

Norman Gray
  • 11,978
  • 2
  • 33
  • 56