包含主 *.tex 文件的超级/子目录中的 *.sty 文件
我想通过 git 与许多其他人分享乳胶文档。 因此,我们决定将每个人的 Latex 安装中不存在的所有特殊 sty 文件放入资源目录中。如果这个目录是超级目录,那就太酷了。实际工作目录的 我究竟如何导入这些样式文件?
重要的是,即使这些远程样式的依赖关系也可以通过其他远程样式来解决。
I want to share a latex document via git with many other people.
Therefore we decided to put all the special sty files, that are not present in everyones latex-installation, into a resources directory. It would be cool, if this dir would be a superdir. of the actual working directory
How exactly can I import those style files?
It is important that even the dependencies of those remote styles are resolved with other remote styles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过两种方式将样式文件 (
mystyle.sty
) 导入到文档中:.tex
文件位于同一文件夹中,只需在序言中包含此行:\usepackage{mystyle}
\usepackage{/path/to/folder/ 进行访问也就是说
,如果您不确定样式文件是否在每个人的安装中,只需将其包含在同一目录中,并确保执行
git add mystyle.sty
并跟踪它与您的其他文件一起保存(尽管很可能不会对其进行任何更改)。不需要父目录。但如果您坚持使用不同的目录,请参阅上面的选项 2。如果它位于子目录中会比位于父目录中更好,因为您仍然可以将该文件称为
\usepackage{subdir/mystyle}
并确保您正在调用样式文件。但是,如果您转义到父目录,您永远不知道其他用户是否有一个不属于您的包的类似名称的文件夹,这可能会导致错误。You can import a style file (
mystyle.sty
) into your document in two ways:.tex
file, simply include this line in your preamble:\usepackage{mystyle}
\usepackage{/path/to/folder/mystyle}
That said, if you're not sure if the style file is in everyone's installation, simply include it in the same directory and make sure you do
git add mystyle.sty
and track it along with the rest of your files (although most likely there won't be any changes to it). There is no need for a parent directory. But if you insist on a different directory, see option 2 above.It would be better if it were in a subdirectory than in a parent directory, as you can still call the file as
\usepackage{subdir/mystyle}
and be certain that you are invoking your style file. However, if you escape out to the parent directory, you never know if the other users have a similarly named folder that is not part of your package, which can result in errors.这可能与您不再相关,但这里有另一种方法可以实现您想要的功能。
像这样设置你的 git 存储库:
并将
\usepackage{mystyle}
放在project.tex
的序言中。当然,手动编译
project.tex
是行不通的,因为mystyle.sty
与project.tex
不在同一目录中。但是,如果
makefile
包含以下内容:那么从
project
目录中运行make
将导致mystyle.styproject.tex
编译(这次成功)之前将 code> 复制到正确的位置。这种方式可能看起来有点夸张,但它确实结合了其他方法的最佳功能。
mystyle.sty
,那么在它们之上放置一个通用的mystyle.sty
比在每个项目目录中都有一个副本更有意义;所有这些副本都必须保留。mystyle.sty
和project.tex
的副本,那么我(至少在理论上)将能够编译手动,无需修改您给我的文件。例如,我不必将
\usepackage{/your/path/mystyle}
替换为\usepackage{/my/path/mystyle}
。This probably isn't relevant to you any more, but here is another way to do what you want.
Set up your git repository like this:
and put
\usepackage{mystyle}
in the preamble ofproject.tex
.Compiling
project.tex
manually won't work, of course, becausemystyle.sty
is not in the same directory asproject.tex
.However, if
makefile
contains something along the lines of:then running
make
from within theproject
directory will causemystyle.sty
to be copied to the correct place beforeproject.tex
is (this time successfully) compiled.This way might seem a little bit over the top, but it does combine the best features of other methods.
mystyle.sty
then having a commonmystyle.sty
sitting above them all makes more sense than having a copy in each project directory; all these copies would have to be maintained.mystyle.sty
andproject.tex
then I would (in theory at least) be able to compile manually without needing to modify the files you gave me.For example, I would not have to replace
\usepackage{/your/path/mystyle}
with\usepackage{/my/path/mystyle}
.您可以按照上面的建议使用 Makefile。另一个选择是 CMake。我没有测试父目录。
如果您有以下文件结构:
您应该安装 CMake,请参阅 CMake 资源
UseLATEX.cmake 可以从此处
然后在CMakeLists.txt
main.tex 的一些示例内容(注意图像)
lib 目录包含 *.sty 文件
您可以现在编译:
然后您可以查看构建目录中的 main.pdf。
You can use Makefiles as suggested above. Another option is CMake. I didn't test for parent directories.
If you have the following file structure:
you should have CMake installed, instructions on CMake resources
UseLATEX.cmake can be downloaded from here
then inside the CMakeLists.txt
Some example content for main.tex (note the image)
The lib directory has the *.sty files
You can now compile:
you can then view main.pdf which is in the build directory.
当您使用使用 kpathsea 的 TeX 发行版时,您可以使用
TEXINPUTS
环境变量指定 TeX 在哪里查找文件。该变量需要按以下方式使用。TEXINPUTS
中的路径由:
分隔。空路径将包含默认搜索路径,即仅包含冒号。两个连续的斜杠表示搜索该目录及其所有子目录。因此,例如,要构建一个文件
document.pdf
,该文件使用当前目录、resources
目录的所有子目录和默认目录中的文件,您可以使用以下Makefile。要加快文件名查找速度,您可以使用
mktexlsr
命令构建ls-R
数据库。有关 kpathsea 的所有详细信息,请参阅手册。
When you use TeX distribution that uses kpathsea, you can use the
TEXINPUTS
environment variable to specify where TeX is looking for files. The variable needs to be used in the following way.The paths in
TEXINPUTS
are separated by:
. An empty path will include the default search paths, i.e., just the colon. Two consecutive slashes means that the directory and all sub-directories are searched.Thus, e.g., to build a file
document.pdf
which uses files in the current directory, all sub-directories of theresources
directory and the default directories, you can use the following Makefile.To speed up the filename lookup, you can build a
ls-R
database using themktexlsr
command.For all the details on kpathsea take a look at the manual.
您可以使用 Latexmk 及其工具
第 48 页的
Utility subroutines
下记录了一个功能 这里在latexmk中,它可以在运行期间更新TEXINPUTS
。如果您可以考虑使用 .latexmkrc 文件来配置您的链和选项,您可以将ensure_path()
添加到该文件:这是一个示例:
注意
//
位于路径末尾,这将帮助 LaTeX 搜索指定目录和所有子目录中的文件。You can use latexmk and its facilities
There is a feature documented under
Utility subroutines
on page 48 here in latexmk which can updateTEXINPUTS
during a run. If you can consider to use the .latexmkrc file to configure your chain and options, you can addensure_path()
to the file:Here is an example:
Notice the
//
at the end of a path, This will aid LaTeX to search for files in the specified directory and in all subdirectories.