# How do I define and use a directory name inside latex for media inclusion?

In Mac OSX, using latex, I have a long class file that includes various macros containing commands of the sort

``````\includegraphics[#5]{/Users/myname/Desktop/book/images/#2.eps}

\includemovie[#4]{/Users/myname/Desktop/book/movies/#2.mpg}
``````

I would like to make this portable to computers with different absolute paths. (For compatibility reasons, I need absolute paths.) Probably the simplest would be to define a `\imagedirectoryname` and a `\moviedirectoryname` and do something like

``````\includegraphics[#5]{\imagedirectoryname/#2.eps}

\includemovie[#4]{\moviedirectoryname/#2.eps}
``````

How exactly do I do this in latex? Thank you in advance for any help! It is for a book that is free to download on the internet.

I am using OSX, latex, MacTeX/texlive 2014, and the dvi -> ps -> pdf typesetting method.

P.S. Yes, I know that movie15 is obsolete, but it works, and the successor package media9 is not compatible with it, as far as I understand.

• You do this by using `\graphicspath{{<pathA>}{<pathB>}{..}{..}}` and then not including the path in your `\includegraphics` command. – Werner Dec 31 '14 at 16:52
• or you can do as you said and simply use `\newcommand\imagedirectoryname{/Users/myname/Desktop/book/images}` but usually best is not to use absolute paths at all, it is almost never needed. – David Carlisle Dec 31 '14 at 16:53
• – Werner Dec 31 '14 at 16:55

You can do one of these:

1. Update `\graphicspath` to point towards the folders that may include graphics. It's syntax for paths `<pathA>`, `<pathB>`, ... is

``````\graphicspath{{<pathA>}{<pathB>}{..}...}
``````
2. Define a macro to hold the path via something like

``````\newcommand{\imagefolder}{/your/image/folder/here}
``````

and then use it in your commands as

``````\includegraphics[..]{\imagefolder/<image>}
``````
3. Of course, (2) could also be hard-coded by changing `\includegraphics` to always use a specific path via something like

``````\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{\oldincludegraphics[#1]{\imagefolder/#2}
``````

You need to know your use-case/environment to be confident that such hard-coding would work though.

• Thanks. I'm working on Ubuntu 14.04LTS and TexLive2015 and solutions 2 works -- after 2h of search & try. (-; – alex Nov 30 '15 at 16:13