Skip to main content


Subfiles is a LaTeX package which allows you to split your document in multiple subfiles, instead of one big file. This is more manageable for editing the code and saves on compilation time, as you can compile each part individually.

Say we split a large thesis into one file for each section. Our file structure could look like


For thesis.tex use the following structure



For the subfiles, e.g. section1.tex use

% !TEX root=section1.tex

    \section{Homotopy theory}

Compiling the thesis.tex now behaves as if \subfile{section1.tex} is replaced with the contents of document in section1.tex.

All \usepackage's and other configuration go in the preamble of the main file, i.e. thesis.tex.


Leave the preamble of the subfiles empty. That preamble will be ignored when compiling the main file. Instead, put all \usepackage and other configuration in the main file's preamble.


The magic comment % !TEX root=section1.tex instructs the editor to compile and display the subfile instead of the main file.