[Tex/LaTex] How to compile/update parts of the document only, while still producing a complete document

compilinginclude

Context: When I write a large document, I write each chapter in a different file. All these subfiles are then included (using \include{<subfile name>}) in a main file to constitute my document.

When I work on a specific chapter, I use the \includeonly command to only compile this specific chapter (and thus speed-up the compilation).

\documentclass{scrbook}
    \includeonly{%here, chap2 only will be compiled
%       chap1,
        chap2,
%       chap3
    }
\begin{document}
    \include{chap1}
    \include{chap2}
    \include{chap3}
\end{document}

Problem: As made obvious by its name, the \includeonly command only includes listed subfiles in the compiled document. This makes that in my case, the document produced contains only one chapter.

However, I'd like to have all chapters included in the document produced.

Question: How to make LaTeX update only one chapter (shorter compiling time) while still producing a .pdf that contains every chapter (full document)?


Note: I want the "\updateonly" command to be versatile, i.e. to easily change the chapter(s) to be updated (or even recompile everything). I would also like to keep auxiliary data untouched (macro definition, cited references, hyperlinks [those from not updated chapters pointing on elements of the updated chapter might obviously be broken, though], acronyms, etc.)

Best Answer

Just think that adding a page in a chapter changes all page numbers... adding a figure may change table of figures and extend it to a new page... a citation may change the order of all citations... So, you can not do what you ask for. LaTeX supposed to be clever typesetting system because it uses every letter to decide what to do with rhe whole document.