# Including graphics in modular documents [duplicate]

What is the right way to include graphics when you are creating a modular document?

My directory structure is as follows:

/root
--report.tex
--mystyle.sty
--/tex
----/literature
------literature.tex
--/img
----biological_neuron.eps


My main file is report.tex whose content is as follows:

\documentclass[11pt, a4paper, twoside, openright]{book}

\usepackage{graphicx}
\usepackage{my_style}

\begin{document}

\mainmatter
\include{tex/literature/literature}

\bibliographystyle{plain}
\bibliography{../../../Bibliography/Bibtex/SNN}
\end{document}


The content of file literature.tex is as follows:

\chapter{A review}

\begin{figure}[h]
\includegraphics{../../img/biological_neuron}
\caption{A biological neuron}
\label{Fig:BN}
\end{figure}


Everytime I try to generate a pdf I get an error: File "../../img/biological_neuron" not found. I tried "/img/biological_neuron" instead of "../../img/biological_neuron" but that doesn't work either. One thing that does work is adding \graphicspath{img/} to report.tex. But I don't know if thats the right way to do it. Because even if I do \graphicspath{img/} I have to specify the path for any graphics in an included file as '../../img/biological_neuron' and I think after adding \graphicspath{img/} we should have to just write '/biological_neuron'. I don't know if this is a bug or am I doing something wrong. Please enlighten. Thank you.

-

## marked as duplicate by Peter Jansson, Fran, Martin Schröder, Mico, moeweNov 8 '13 at 19:08

\graphicspath requires it's argument to contain grouped elements. So you should use \graphicspath{{<dir1>}{<dir2>}..}. See section 4.5 Other commands in the graphics package (p 13) of the graphics guide. – Werner Aug 17 '13 at 5:01
Maybe \graphicspath{{../../img/}} will help? Take note to double braces. – Eddy_Em Aug 17 '13 at 5:01
@werner: Your solution works. Thank you. But as an aside is this the right way to include graphics from a central location while creating modular documents or is there a better way to manage your directory structure while creating modular documents. For instance having a different directory of graphics for chapters within each chapter folder. I have no idea of the repercussions of any approach. Can you elaborate? – Shaun Aug 17 '13 at 5:08
@Shaun: It's definitely a good idea. You'll run into problems when you're using similarly-named files across your folder structure though. To that end, you can also define macros for folders. For example, try \def\imgfolder{img/}\includegraphics{\imgfolder myimage}. – Werner Aug 17 '13 at 5:20

One way is to place the images in the same folder, and give the location(s) the \graphicspath{{folder},{folder},...} command.

When using modular documents, especially when the parts are edited by different users idependently, I prefer to use a different method. I usually create an __before.tex and a __after.tex file for each part. Before including any tex files from the folder, I always \input the __before.tex file, and __after.tex file afterwards.

So I have this structure:

/root
--main.tex
--*.tex
--/1_<part1name>
----__before.tex
----__after.tex
----*.tex
--/2_<part2name>
----__before.tex
----__after.tex
----*.tex
--/img
----*.*
----/<part1name> % without numbering
------*.*
----/<part2name>
------*.*
----/misc
------/gen_ba
--------gen_ba.sh
--------gen_ba.cmd
--/* % other folders


I generate these __before.tex and __after.tex files in folders using scripts. In this case, the commands I would put in them is the following:

• \def\imgfolder{img/partxname} in __before.tex
• \def\imgfolder\relax in __after.tex

And I use \includegraphics with the \imgfolder` location included.

-