Question

My friend has the following in his computer in a LaTeX document

 \includegraphics[width=13.0cm]{/Users/max/Dropbox/2_user_cases.png}       

I would like to have a variable for the username such that we can collaborate faster.

Pseudo-code about what I wont

 \includegraphics[width=13.0cm]{/Users/`echo $USER`/Dropbox/2_user_cases.png}       

How can you have such an command inside LaTeX?

Was it helpful?

Solution

in the graphicx package, you can define a folder for latex to look for all your images in, like this:

\graphicspath{{images/}}

In this particular configuration, latex looks for a folder in the same directory as your file called "images."

I don't see why you'd want to use a full path just to get image in...

Make a folder, put your .tex source file in there, create a folder for your images.

Stick you work in some sort of revision control system (git, SVN, etc etc.) Commit often, and you're on your way.

OTHER TIPS

I'm not sure you can access envvars from LaTeX. As Rutger Nijlunsing has said, you can try "~/" since it is an alias to "/Users/<username>".

If there are other envvars that you need to access, my suggestion is using Makefile to 'compile' the .tex (or a shell script) calling sed to replace such word.

sed -i "s/max/$USER/" file.tex
latex file.tex
bibtex ...
latex ...

use ~ for your homedirectory (which is probably /Users/$USER):

\includegraphics[width=13.0cm]{~/Dropbox/2_user_cases.png}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top