# Path to image located in the cloud for different users or computers

I'm trying to point the location of an image in the cloud (Dropbox) using TeX on Mac OS. The problem is that I require full path name which contains the username (different for both machines). For example the path on machine 1 is: /Users/user_name1/Dropbox/image.pdf and on the machine 2 it's /Users/user_name2/Dropbox/image.pdf. In such case, I would have to change the path whenever I'm changing the machine (user) to be able to compile the document.

Is there any way to shorten the path name so that I can point to the files universally on a different machines?

• You could just extract the user name and insert it into the path. See for instance How to detect and condition based on hostname. Dec 7, 2012 at 18:07
• @PeterGrill Not so functional if you have multiple chapters wrote into separate .tex files Dec 7, 2012 at 18:08
• Not sure I understand. If it can work for one case then with a bit of programming you should be able to adapt it. Perhaps define the root path in the preamble based on the user, and then use that in the multiple chapters. Would need more details as to exactly how you want to use this and why this is a problem. Best way to do that is to compose a fully compilable MWE including \documentclass and the appropriate packages that illustrates this potential issue. Dec 7, 2012 at 18:12
• If your .tex file is in the cloud as well, relative paths should work. Dec 7, 2012 at 18:18
• Ok, sorry @PeterGrill you added the link a second later;) I'm digging it now. It should work... I have simple structure with main.tex specifying \include{1/chapter-1} for all chapters, everything is in the cloud. Dec 7, 2012 at 18:23

\documentclass{scrartcl}
\usepackage{graphicx}

\begin{document}
\includegraphics[width=5cm]{\detokenize{~/Dropbox/image.pdf}}% or
\includegraphics[width=5cm]{\detokenize{$HOME/Dropbox/image.pdf}}% or \includegraphics[width=5cm]{\detokenize{/Users/$USER/Dropbox/image.pdf}}%
\end{document}


As you are running on a UNIX system, the ~ character can be used to refer to the home directory of the current user. Alternatively, one could also use environmental variables, such as $HOME or $USER in the file path (thanks to bloodworks for pointing that out!). However, as ~ and $ have special meaning in LaTeX, we need to apply \detokenize to sanitize the path. • Just to add: you could also use Variables. eg. \includegraphics{/Users/$USER/Dropbox/image.pdf} works just as fine as \includegraphics{\$HOME/Dropbox/image.pdf} Those Variables should be the same at least under any BSD derivative. Dec 7, 2012 at 18:50
• @bloodworks: Do you know if using env vars also works under Windows? Dec 7, 2012 at 18:55
• i dont need detokenize for the dollar sign. That might be some local thing since graphicxuses \input@path which has some dependencies on texsys. Regarding Windows i have to say i know how to shut it down;) Dec 7, 2012 at 19:21
• \detokenize is exactly what I needed, thank you very much @Daniel. Dec 8, 2012 at 13:16