TeX - LaTeX Asked on January 1, 2021
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}
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.
Correct answer by Alan Munn on January 1, 2021
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 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.
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 "/".
Answered by hpekristiansen on January 1, 2021
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}
Answered by BananaIsland on January 1, 2021
You need to put this in your preamble(or second package):
usepackage{import}
. Then you can import as many files as you like.
Here's the full document template:
documentclass[…]{…}
…
usepackage{import}
…
begin{document}
…
import{path}{file.ext}
…
end{document}
path
can be of the form ./folder1/…/
, /folder1/…/
, or an absolute path.
Answered by Someone on January 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP