[Tex/LaTex] Path to image located in the cloud for different users or computers

graphicspaths

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?

Best Answer

\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.

Related Question