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?


2 Answers 2




before the \include.

  • 3
    Also you can have several paths by separating with \graphicspath{{article1}{article2}}.
    – nickpapior
    Mar 26, 2012 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. Mar 26, 2012 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. Mar 26, 2012 at 19:46
  • 1
    Same issue as @JamesFennell here. Would be great if Stephan could fix that in the answer. Jan 16, 2013 at 19:01
  • @DaniloBargen done. Sorry fro not reacting immediately after James' comment. Jan 17, 2013 at 7:13

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.

  • 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! Mar 26, 2012 at 18:53
  • 2
    Is it possible to do same thing from preamble in main.tex?
    – Crowley
    May 14, 2015 at 9:33
  • @JamesFennell: In my opinion, files should be included not based on working directory. Includes should be relative to the original file that executes the include. It seems TeX people do not like this because some systems do not have the concept of "directory". Well, this is no excuse in my opinion... but... :-( Apr 2, 2019 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .