独立于操作系统的图像寻址
由于我的计算机上同时使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了这个问题,我发现对路径进行硬编码绝对是一个糟糕的主意。此外,一旦您的项目开始增长,保持这些目录同步最终将成为一个问题。
我解决这个问题的方法是将所有内容放入版本控制中(我喜欢 git,你的情况可能会有所不同)。
然后我创建了一个
images
文件夹,因此我的文件夹层次结构如下所示:Working-Dir
|-- 图片/
|-- myfile.tex
|-- nextfile.tex
然后在我的文档的序言中:
\usepackage{graphicx}
和\graphicspath{{images/}}
告诉乳胶寻找文件夹名为images
,然后在文件夹内查找图形。然后我在 comp 上完成工作,将完成的工作推回存储库,当我切换计算机时,我只需从存储库中提取内容。这样,无论我在哪台计算机上工作,一切都保持同步。
像对待源代码一样对待tex源极大地提高了我的工作流程和效率。我建议任何处理大量乳胶来源的人采取类似的措施。
编辑:
来自:http://en.wikibooks.org/wiki /LaTeX/Importing_Graphics
第三个选项应该对你有好处——只需为
\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 calledimages
, 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
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)?米卡,再次感谢你,你的建议很有效!
我已经在序言中测试了此代码,在
.sty
文件中它不起作用:其中
/media/DATA/logo/
是已安装分区上带有徽标的目录的地址在 Linux 中d:/logo/
是 windows 中同一目录的地址img/
是实际工作目录中当前文档的图像地址,文档中的此代码:
\includegraphics{logo_zcu_c}
fromlogo
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:where
/media/DATA/logo/
is address to directory with logos on mounted partition in Linuxd:/logo/
is address to same directory in windowsimg/
is address of images for current document in actual working directoryand this code in document:
\includegraphics{logo_zcu_c}
fromlogo
dir\includegraphics{hvof}
fromimg/
dir`