开发者

Operating system independent image addressing

Due to using both Windows and Ubuntu on my computer I'd like to be able to create开发者_如何学C documents independently. I have one directory for logos and I want to use them in any documents everywhere.

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

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

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


\includegraphics{\winlogo logo_bw}

How to provide this feature:

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

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

else{error}


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_Graphics

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, 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`

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜