2

A document I wrote uses \begin{figure} and \includegraphics to load an image. Later, I \input this document into a master document in the same folder, and the image is included in my output document.

In a separate folder, I want to load this document again. I reference its location with a path that works for other documents without pictures. However, the image it seems cannot be located. Any suggestions to fix this?

4
  • You can declare a path in includegraphics: \includegraphics{/path/to/your/pic} or even better \graphicspath {<dir-list>}, e.g. \graphicspath {{/path1}{/path2}}. Commented Jul 23, 2015 at 1:28
  • @Ruben Did you forget a comma? Commented Jul 23, 2015 at 2:08
  • On a non-Windows system, I think by far the easiest way is to just create a sym link to the image from the working directory for the file. That's my standard solution. If I expect to use something a lot or want it available to projects in distant directories, I put it in a standard location and set \graphicspath or, for coded images mostly, in TEXMFHOME. There are also some sophisticated packages which try to handle this kind of thing in clever ways, but that necessarily introduces a degree of complexity and fragility. YKMTV. (Your Kilometres May Therefore Vary.) Commented Jul 23, 2015 at 2:11
  • @Ruben That solution is the simplest. I looked into the other ways shared in this thread but it was a simple issue of declaring the image path in the sub-document. Commented Jul 27, 2015 at 17:29

1 Answer 1

1

I am not sure whether it is as elegant as \graphicspath, but another idea may be to have a command pointing to the relative path of the document. In the document, you can do

\makeatletter% \ifx\mypath\@empty% \xdef\mypath{.}% \fi% \makeatother% 

right at the document's beginning, which sets the path to . (the current folder) if it has not been defined. In the other document loading your document, you can set

\xdef\mypath{relative_or_absolute_path_to_doc_folder} 

before doing the \input where relative_or_absolute_path_to_doc_folder is replaced with the corresponding value.

Let's say your first document is in folder a/b/c/d and the document loading the first document is in a/x/y, then it should work with relative_or_absolute_path_to_doc_folder being either a/b/c/d or ../../b/c/d.

All \includegraphics{x.pdf} change to \includegraphics{\mypath/x.pdf}.

This approach has the advantage that you can later copy your first document elsewhere and also move the graphics folder along with it (assuming that it is in a subdirectory of the document's folder). You would only need to change the relative path setting of \mypath in the document which loads it. The same holds if you move the second document loading the first one.

I am not sure about what exactly \graphicspath et al. do, but I think there may be some problems if (and I may be wrong here, so people with more knowledge feel free to correct me):

  1. have several sub-folders in your graphics folders with similarly named images inside (?)
  2. define it in the first document as a relative path: I am afraid that it may be interpreted as relative path to the document which loads the first document when the first document is loaded from that document (?)
  3. define it as absolute path, you may need to re-define it when copying the document elsewhere (?)
  4. define it both in the first document and in the document which loads it (what will happen?)

Again, these above concerns may be wrong and usually, \graphicspath is probably a better solution. I think the approach I list may also work and in some situations may be viable as well.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.