The subfiles docs explains that it handles path issues when main files and subfiles are in different directories and subfiles contain paths relative to their own directories using the \import package. It appears that this means subfiles uses \import when adding the content of files passed to \subfile. For example, \subfile{ch/ch1.tex} is roughly equivalent to modifying the preamble of ch1.tex then calling \import{ch/ch1.tex}. What is not clear is how to correctly nest imports, i.e. import within imported subfiles.

Below I provide an example project/directory structure and two example files assuming that main.tex should import ch1.tex and ch1.tex should import fig.png and text.txt.

 +-- main.tex
 +-- chapters
     +-- ch1.tex
     +-- content
         +-- text1.txt
         +-- fig1.png
%% main.tex

    \subfile{chapters/ch1.tex} % \imports ch1.tex
%% ch1.tex
    \import{content}{text.txt}        % adds some text - note use of \import
    \includegraphics{content/fig.png} % adds a figure

When I compile the files above, they produce the desired output. However, as \import is used in the \subfile{chapters/ch1.tex} call in main.tex but then is also used within ch1.tex in the \import{content}{text.txt} call. The import docs indicates \subimport should be used for the latter. As \subimportrequires a path relative to the currently imported file, the call should be\subimport{content/}{text1.txt}`.

Should importing within subfiles always use subimport? If so, I am confused as to why swapping \import with \subimport produces the same results when they should presumably point to different directories as in the examples in the import docs.

  • Because standalone compilation is great. Commented Mar 4, 2023 at 11:34
  • @socialscientist You could typeset parts of a document by commenting/uncommenting \input statements. I.e., you typeset each time the main document, but change which \input statements are active. This is robust and compatible with all packages. subfiles has to do modify the \end command, which is potentially harmful.
    – gernot
    Commented Mar 4, 2023 at 11:58

1 Answer 1


You can use \input directly.

│  main.tex
    │  ch1.tex







enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .