# Using \import correctly

I've got a main-file which includes the preamble. I then use \import to put together all chapters of my final document. When saving the main-file in another directory than the chapter-files I get the message:

! LaTeX Error: File GDP.tex' not found.


Isn't the idea of \import to import files from different directories? Is there maybe something wrong with my code?

...
\begin{document}

\maketitle
\tableofcontents

\import{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP}{Methodology}
\import{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP}{GDP}

\end{document}

-
I think you might be looking for \input{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP/Methodology}. That is, \input rather than \import. – Werner Feb 14 '12 at 0:56
What package are you using that provides an \import command? Usually files are included with \include (or sometimes \input). – Alan Munn Feb 14 '12 at 0:58
Is Methodology.tex found? Is both files placed in /Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP? If you are not using \input(or like) in the files, then you should just use \include in your main file. – Hans-Peter E. Kristiansen Feb 14 '12 at 1:01
@Werner: When it is in the main file, \include is preferred over \input. – Hans-Peter E. Kristiansen Feb 14 '12 at 1:02
@Brent.Longborough: Yes - I should probably have written "I prefer ...". But I also believe that \include suits the purpose best here. – Hans-Peter E. Kristiansen Feb 14 '12 at 21:00

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.

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.

-
There we go! :) Man thanks Alan Munn again! – John Feb 14 '12 at 1:44

I know of three ways to put one .tex file into an other:

1. \include{⟨filename⟩}
2. \input{⟨filename⟩}
3. \import{⟨path⟩}{⟨filename⟩}

1. \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 on chapter7.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.

2. \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.

3. \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 "/".

-
I tried it with \include but since the argument cannot be a path the include-approach does not fit to my problem. But thank you for the detailed information! :) – John Feb 14 '12 at 1:46
@John: ⟨filename⟩ can be both a filename(name), a relative path(dir/name) or a full path(/dir/name) – Hans-Peter E. Kristiansen Feb 14 '12 at 1:52
Okay, I did not know that, sorry. I'll keep that in mind but for the moment \import works. Thanks. :) – John Feb 14 '12 at 1:55
@John: You are welcome - plz up-vote. One approach is if it is working, don't touch it, but I like Do it right from the start better. – Hans-Peter E. Kristiansen Feb 14 '12 at 2:21
Great summary of the various approaches. Thanks! Upvoted. – SSilk Apr 17 '13 at 20:01

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}


\import{/Users/john/Documents/Uni/Studienarbeit/Latex/Kapitel/GDP/}{GDP}
`