I am trying to understand how (relative) paths need to be used with the subfiles
package. In particular, it's not clear how content that I usually would include with \include
, \input
, \includegraphics
, and \bibliography
should be included within subfiles.
- Does it matter whether a subfile uses
\include
or\input
or\import
to add content with a path relative to the subfile directory or does it do the same thing because of internalsubfile
processing? The package documentation notes that\import
is used to address issues with standalone compilation of subfiles not located in the directory of the "main file" containing\usepackage{subfiles}
:
Sometimes it is desirable to put a subfile together with its images
and supplementary files into its own directory. The difficulty now is
that these additional files have to be addressed by different pathes
depending on whether the main file or the subfile is typeset. As of
version 1.3, the subfiles package handles this problem by using the
import package.
-
For each use of
\subfile
in the main file, do I need to first change the\graphicspath
to ensure the graphics path is set to the directory containing that respective subfile? In the example found at the bottom of page 5 of the documentation, no graphics path change is required, although this post suggests that it IS required, causing confusion. -
While I have a project-wide .bib file that each subfile uses to generate citations and bibliography, do I need to somehow specify the path of the .bib file relative to each subfile if I want (a) a single overall bibliography when the main file is compiled and (b) only those entries pertaining to the specific subfile when a given subfile is compiled? This post seems close to answering this but it's unclear exactly how this works.
Best Answer
To alleviate some of the confusion: most posts before 2020 refer to old versions of the
subfiles
package, which required more work. Information in more recent posts is probably more reliable than information in older ones.include vs. input vs. import with subfile package
Yes, it matters, these commands do different things.
\input
tells LaTeX to replace the\input
command by the contents of the file; if this file refers to other files, the path information is interpreted relative to the file containing the\input
command, even if the file is located in another directory.\include
is similar in this respect, but does some additional things.\import
, however, takes care that the input and the graphics paths are modified such that the path given in any\input
,\include
,\includegraphics
,\import
and\subfile
statement in the imported file is interpreted relative to the imported file.\subfile
essentially is an\import
command, but additionally skips the preamble of the imported file. So the idea of\import
and\subfile
is that any path information in the imported/subfiled file is relative to this file, no matter which other document uses the file.graphics paths with subfile package
No, this is something
\import
and\subfile
take care of.how to use a project-wide bibfile
The following example assumes that you use classic BibTeX, and the following project structure:
main.tex:
allrefs.bib:
part1/details.tex:
In the main directory, you can typeset
main.tex
with the commandswhile the subfile can be typeset with
This results in the documents
main.pdf
(left) andpart1/details.pdf
(right).