Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm working on a mathematics magazine that involves multiple articles from different authors. I would like to give each article a sub-directory in which I can store all the relevant files - .tex, image files, etc. However, when I then \include the article .tex file from the master file, the images won't be linked correctly without editing.

For example, suppose the article is stored in articles/article1/ and includes an image matrix.png. In the article .tex file this would be inserted, normally, through \includegraphics{matrix.png}. However, when we move to including the article in the magazine through the master file, all these instances would have to be changed to \includegraphics{articles/article1/matrix.png}

So, is it possible to change the LaTeX working directory before including the article such that instances of \includegraphics will not have to be changed, but rather that LaTeX will know to search for these files in the article directory? I'm thinking that this would be similar-ish in functionality to HTML's base href command for links.

Or, is there a better way to achieve all this?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

Try

\graphicspath{{articles/article1/}}

before the \include.

share|improve this answer
2  
Also you can have several paths by separating with \graphicspath{{article1}{article2}}. –  zeroth Mar 26 '12 at 10:56
    
This is a perfect solution - thanks! I am designing a custom command to add articles that will take care of headering, titling, reseting the figure counter, etc. - and this fits perfectly into that. –  James Fennell Mar 26 '12 at 18:54
2  
Note: on my installation I had to use \graphicspath{{articles/article1/}} to get this working -- I had to include the trailing / and had to have two braces like @zeroth has, even for only one directory. –  James Fennell Mar 26 '12 at 19:46
1  
Same issue as @JamesFennell here. Would be great if Stephan could fix that in the answer. –  Danilo Bargen Jan 16 '13 at 19:01
    
@DaniloBargen done. Sorry fro not reacting immediately after James' comment. –  Stephan Lehmke Jan 17 '13 at 7:13
add comment

If you want to include more than just graphics, you can also use the environment variable TEXINPUTS and refine it before calling your latex processor:

TEXINPUTS=.:graphics:articles/article1:articles/article2:../../something/somewhere/else:$TEXINPUTS pdflatex main.tex

The last $TEXINPUTS call, although normally empty, is necessary otherwise the normal TeX paths disappear.

This will add all these paths so that \imput{file}, \include{file}, \includegraphics{file} and even \usepackage{file} will also search in these folders to find the appropriate file before giving the file not found error message.

share|improve this answer
1  
A problem with this solution from my perspective is that it would add complication to the process of adding new articles, and could also presumably result in conflicts if different articles have images with the same name. I am designing a special command for adding new articles, and Stephan Lehmke's solution works nicely within this. Still, I can see this being helpful in other situations - thanks! –  James Fennell Mar 26 '12 at 18:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.