0
votes

I have a Latex project that is including multiple PDFs. These PDFs are added in the final document through the includepdf tag when the project is compiled over Overleaf. My question is can Latex automatically generate a ToC from included PDFs, i.e., can it automatically read the \section \subsection tags from the included files and automatically generate it? Or maybe this is only possible if I included the separate project or sources into the final solution and compile that.

Your help is so welcome!

1

1 Answers

1
votes

Including a rendered pdf file in your project would make you limited in accessing details of those documents. You will then only be able to select specific pages or add some content on specific places of those files (e.g. your own page numbers).

Since you have access to those projects, best is to nest those raw tex files under your current project using one (or a combination) of the following methods:

  • Input command: \input{foo.tex}: in this case the input file mustn't be a separate project (no \begindocument and \enddocument in it)
  • Include command: \include{foo.tex}: very similar to input command but a bit limited about nested includes.
  • import package: very similar to input and include commands but allows nested imports and also accepts a different logic for path resolution on its input (i.e. it accepts relative path to the file from where it is called).
  • subfiles package: In this case the subfile can have its own document body and is able to be rendered separately. The subfiles would use the preambles of your main project.
  • standalone package: Similar to subfiles but the main project would use the preambles of your subfiles in this case.

Overleaf nicely allows you to add files from another project which is the best choice when the other file is still being developed in a separate project. In this case, the file remains under control of the other project.

overleaf

For further info, here is a very nice guide on how to write modular documents in latex and here is a brief tutorial on subfiles and standalone.