views:

72

answers:

2

Due to using both Windows and Ubuntu on my computer I'd like to be able to create documents independently. I have one directory for logos and I want to use them in any documents everywhere.

The problem with different file adressing I solved with those commands:

\newcommand{\winlogo}{D:/logo/}

\newcommand{\linlogo}{/media/DATA/logo/}



\includegraphics{\winlogo logo_bw}

Please how to provide this feature:

if(parameter==windows){adress:=D:/logo/}

elseif(parameter=linux){adress:=/media/DATA/logo}

else{error}

Thanks for any idea.

+4  A: 

I've run into this problem as well, and I found that hard-coding the paths is an absolutely terrible idea. Also, keeping these directories in sync will eventually be a problem once your projects begin to grow.

The way I solved this was to put everything in version control (I like git, your mileage may vary).

Then I created an images folder, so my folder hierarchy looks like this:

Working-Dir |-- images/ |-- myfile.tex |-- nextfile.tex

Then in the preamble of my documents: \usepackage{graphicx} and \graphicspath{{images/}} which tells latex to look for a folder called images, then look for the graphics inside the folder.

Then I do my work on on comp, push my finished work back the repo, and when I switch computers I just pull from my repo. This way, everything stays in sync, no matter which computer i'm working on.

Treating tex source like source code has greatly improved my work flow and efficiency. I'd suggest similar measures for anyone dealing with a lot of latex source.

EDIT:

From: http://en.wikibooks.org/wiki/LaTeX/Importing%5FGraphics

Graphics storage

There is a way to tell LaTeX where to look for images: for example, it can be useful if you store images centrally for use in many different documents. The answer is in the command \graphicspath which you supply with an argument giving the name of an additional directory path you want searched when a file uses the \includegraphics command, here are some examples:

\graphicspath{{c:\mypict~1\camera}}

\graphicspath{{/var/lib/images/}}

\graphicspath{{./images/}}

\graphicspath{{images_folder/}{other_folder/}{third_folder/}}

please see http://www.ctan.org/tex-archive/macros/latex/required/graphics/grfguide.pdf

As you may have noticed, in the first example I've used the "safe" (MS-DOS) form of the Windows MyPictures folder because it's a bad idea to use directory names containing spaces. Using absolute paths, \graphicspath does make your file less portable, while using relative paths (like the last example), you shouldn't have any problem with portability, but remember not to use spaces in file-names. Alternatively, if you are using PDFLaTeX, you can use the package grffile which will then allow you to use spaces in file names.

The third option should do you well-- just specify multiple paths for the \graphicspath I wonder if LaTeX will fail gracefully if you just include all of your paths in there (one for images, one for your logs on linux, one for your logos on windows)?

Mica
The point is to have in document source command `\includelogo[width=2cm]{\logo name}` without bothering about where the document is and what system is used. Just change one parameter in `main.tex` file (switch between Win and linux) and keep the `.sty` file synchronized with logo directory position...I think the `\graphicsparh` command will redirect all `\incudegraphics`' adresses to `images/` directory so it's not exactly what I want.I'll try your code to shorten usage of other images, thanks.
Crowley
is there any reason why all the images can't go in the same directory?
Mica
As logos are to be same for many documents, images are only for one or two documents.I'm using them in titlepages of papers for seminar works and presentations.Yes they all can be in one directory, or in each workspace. I used to do this, but it was full of mess. This way I hope it would be much better organized and easier to update.
Crowley
Added a little bit more to my answer :P
Mica
Put it in your preamble. I am not sure about the foreword/back slash, Windows sucks with it comes to file paths ;) I would try maybe putting the file path in quotes.
Mica
A: 

Mica, thank you once more, your advice works properly!

I've tested this code in preamble, in .sty file it doesn't work:

\usepackage{graphicx}
\graphicspath{{/media/DATA/logo/}{d:/logo/}{img/}}

where

/media/DATA/logo/ is address to directory with logos on mounted partition in Linux
d:/logo/ is address to same directory in windows
img/ is address of images for current document in actual working directory

and this code in document:

\includegraphics{logo_zcu_c} from logo dir
\includegraphics{hvof} from img/ dir`

Crowley