Using \import correctly
I know of three ways to put one .tex
file into an other:
1. \include{⟨filename⟩}
2. \input{⟨filename⟩}
3. \import{⟨path⟩}{⟨filename⟩}
\include
is only used in the main document, and is the preferred way in large documents. You can not use\include
in documents that has themselves been included with\include
.\include
will always start on a new page. With\includeonly{⟨filename1⟩,⟨filename2⟩,...}
you can tell the main document to only include some documents, for testing purpose. E.g. if you are working onchapter7.tex
in your huge book, and want to see the compiled result, without compiling everything, then just place\includeonly{chapter7}
in the preamble of your main document.⟨filename⟩
needs to be a.tex
file. Type either just the name of the file, a relative path, or a full path, but do not use the.tex
extension.\input
is used in subdocuments, to input e.g. figures. It can also be used directly in the main document for smaller documents. Works exactly as if the contend of the file was written at the point of\input
. Here⟨filename⟩
can have any extension, but if none is written, then.tex
is chosen.\import
needs the\usepackage{import}
, and is only used, when the imported files needs the path to e.g.\input
other files. - see the import manual. Here⟨path⟩
needs to end with a "/".
When using the import
package (which provides the \import
command), you must ensure that the path argument includes the trailing slash /
. So you need to do:
\import{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP/}{GDP}
Note the /
at the end of the path.
Update 2020 As of v6.2 (part of TL 2020) the trailing slash is no longer required.
As others have noted in the comments, it's usually better to use the \include
command for this kind of thing, although the import
package does have some interesting capabilities for relative names within the included documents. See Keep chapter number of chapters inserted with \include for an example.
Note that using relative paths is in general better if you want to compile later on a different system or from a different path:
\import{Kapitel/GDP/}{GDP}
instead of
\import{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP/}{GDP}