独立于操作系统的图像寻址

发布于 2024-08-13 00:02:00 字数 389 浏览 2 评论 0原文

由于我的计算机上同时使用 Windows 和 Ubuntu,我希望能够独立创建文档。我有一个徽标目录,我想在任何地方的任何文档中使用它们。

我用这些命令解决了不同文件寻址的问题:

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

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


\includegraphics{\winlogo logo_bw}

如何提供此功能:

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

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

else{error}

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 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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷路的信 2024-08-20 00:02:00

我也遇到了这个问题,我发现对路径进行硬编码绝对是一个糟糕的主意。此外,一旦您的项目开始增长,保持这些目录同步最终将成为一个问题。

我解决这个问题的方法是将所有内容放入版本控制中(我喜欢 git,你的情况可能会有所不同)。

然后我创建了一个 images 文件夹,因此我的文件夹层次结构如下所示:

Working-Dir
|-- 图片/
|-- myfile.tex
|-- nextfile.tex

然后在我的文档的序言中: \usepackage{graphicx}\graphicspath{{images/}} 告诉乳胶寻找文件夹名为 images,然后在文件夹内查找图形。

然后我在 comp 上完成工作,将完成的工作推回存储库,当我切换计算机时,我只需从存储库中提取内容。这样,无论我在哪台计算机上工作,一切都保持同步。

像对待源代码一样对待tex源极大地提高了我的工作流程和效率。我建议任何处理大量乳胶来源的人采取类似的措施。

编辑

来自:http://en.wikibooks.org/wiki /LaTeX/Importing_Graphics

图形存储

有一种方法可以告诉 LaTeX 去哪里
寻找图像:例如,它可以
如果您存储图像很有用
集中用于许多不同的
文件。答案就在
您提供的命令 \graphicspath
带有一个给出名称的参数
您想要的其他目录路径
当文件使用
\includegraphics 命令,这里是
一些例子:

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

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

<代码>\graphicspath{{./images/}}

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

请看
http://www.ctan.org/tex-存档/宏/latex/required/graphics/grfguide.pdf

正如您可能已经注意到的,在第一个
例如我使用了“安全”(MS-DOS)
Windows MyPictures 文件夹的形式
因为使用它是一个坏主意
包含空格的目录名。
使用绝对路径,\graphicspath
确实会降低你的文件的便携性,
当使用相对路径时(比如
最后一个例子),你不应该有任何
便携性有问题,但请记住
不要在文件名中使用空格。
或者,如果您正在使用
PDFLaTeX,您可以使用该包
grffile 然后你可以
在文件名中使用空格。

第三个选项应该对你有好处——只需为 \graphicspath 指定多个路径我想知道如果你只包含所有路径(一个用于图像,一个用于日志),LaTeX 是否会正常失败在 Linux 上,一个在 Windows 上用于您的徽标)?

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)?

污味仙女 2024-08-20 00:02:00

米卡,再次感谢你,你的建议很有效!

我已经在序言中测试了此代码,在 .sty 文件中它不起作用:

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

其中

/media/DATA/logo/ 是已安装分区上带有徽标的目录的地址在 Linux 中
d:/logo/ 是 windows 中同一目录的地址
img/ 是实际工作目录中当前文档的图像地址

,文档中的此代码:

\includegraphics{logo_zcu_c} from logo dir
来自 img/ 目录的 \includegraphics{hvof}

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`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文