tags:

views:

110

answers:

3

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?

+1  A: 

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

\includegraphics[width=13.0cm]{~/Dropbox/2_user_cases.png}
Rutger Nijlunsing
The tilde is definitely the best way for a home directory. What if it's not? The best I can come up with is to have the LaTeX document include another, which is generated from environment variables, and sets LaTeX ones properly. This could then be automated with a Makefile, which has a rule stating that the LaTeX output depends on the generated file. The rule for the generated file would call some user-created script... bit kludgy but it'd work.
Jefromi
I cannot use ~ for some unknown reason. - Dropbox may be the cause of the problem.
Masi
Do you have permission to view the other ones file?
Rutger Nijlunsing
I have permissions. Please, see Mica's answer for the solution to my question.
Masi
+2  A: 

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 ...
Otavio
+2  A: 

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.

Mica
Thank you for your answer! I love your way of answering. You noted the source of the problem in the PATH which I did not know before.
Masi
you bet. I am a technical writer... and I am in LaTeX all day, almost 8 hours a day. :P
Mica