[Tex/LaTex] Does LaTeX have to reprocess included files that haven’t changed

compilinginclude

I have included several .tex files (they do not contain the header code like documentclass, begin and end document, etc). When I include the file using \include everything works. But if I recompile the code I still takes a while even though most of the includes(or even all) have not changed.

My basic method to deal with this is to comment out the includes I do not want compiled but I see no reason why they can't be "precompiled" and reused each time unless the .tex file changed.

Best Answer

TeX works in a linear fashion with an input file, and while there are methods to split up in input (ultimately based on the \input primitive), these are for the author's convenience only. TeX still processes all of the input in a linear manner: once a file is \input it is as though the material was all in one big file.

At the same time, it is possible for changes in one part of a document to affect another (for example, altering the set up of the running headers or page numbering). So it is not possible to simply say 'I can skip this input'. Writing the output is also a linear process: there is no direct link between individual .tex files and parts of the .dvi or .pdf in a way that would allow TeX to take 'old' pages and 'recycle' them.

The LaTeX \include mechanism does have features to help with larger documents. Using \includeonly it is possible to compile only part of a document, while retaining cross-references and so on. This however works by entirely skipping the files which are not included, so you do not get the complete version of your document.

There are also methods to precompile the preamble of a document into a custom format, and then only retypeset the document body. See for example mylatexformat.