Choosing Between \\include/\\includeonly and \\input with latexmk for Incremental LaTeX Builds
0 reputation · 07 Mar 2025, 06:13 UTC
0 reputation · 07 Mar 2025, 06:13 UTC
When aiming for fast partial rebuilds of a small LaTeX project while keeping cross‑reference numbers and page layout correct, the documented alternative is to convert existing \\input‑based chapters to \\include units and activate them with \\includeonly in the preamble. This approach skips the excluded files during a compile, but each \\include forces a page break via \\clearpage and cannot be nested inside another \\include’d file, and it relies on up‑to‑date .aux files from a prior full run to preserve numbering.
Keeping the original \\input fragments avoids forced page breaks and nesting limits, but then \\includeonly has no effect; one must depend on a build tool such as latexmk to detect changes and rerun only the necessary passes. The trade‑off therefore centers on accepting the structural constraints of \\include for speed versus retaining the flexibility of \\input and relying on dependency tracking for comparable incremental performance.
Is the page‑break overhead of \\include acceptable for the document’s structure? Does the risk of stale .aux files outweigh the rebuild simplicity of keeping \\input? Can latexmk’s dependency tracking deliver similar incremental performance without restructuring the source?
29775 reputation · 07 Mar 2025, 18:07 UTC
If your document’s logical sections (chapters, major subsections) naturally start on a new page, using \\include/\\includeonly with latexmk gives near‑instant rebuilds because unchanged files are skipped entirely. If you need to avoid forced page breaks or want to nest files, keep the original \\input fragments and let latexmk’s dependency tracking handle incremental passes.
latexmk -pdf to generate all .aux files.latexmk -pdf -g (the -g flag tells latexmk not to re‑run make‑style dependencies, relying on the explicit includeonly).latexmk -pdf -g after each edit; latexmk will detect changes via its default scanner and rerun only the necessary passes.Do your chapters or major sections naturally begin on a new page? If yes, the page‑break overhead of \\include is acceptable; if not, staying with \\input avoids unwanted blank pages.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.