包含主 *.tex 文件的超级/子目录中的 *.sty 文件

发布于 2024-11-06 16:32:33 字数 158 浏览 0 评论 0原文

我想通过 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 技术交流群。

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

发布评论

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

评论(5

没︽人懂的悲伤 2024-11-13 16:32:33

您可以通过两种方式将样式文件 (mystyle.sty) 导入到文档中:

  1. 如果它位于您的路径中或与 .tex 文件位于同一文件夹中,只需在序言中包含此行: \usepackage{mystyle}
  2. 如果您将其放在其他文件夹中,则可以使用其完整路径 \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:

  1. If you have it in your path or in the same folder as the .tex file, simply include this line in your preamble: \usepackage{mystyle}
  2. If you have it in a different folder, you can access using its full path as \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.

就此别过 2024-11-13 16:32:33

这可能与您不再相关,但这里有另一种方法可以实现您想要的功能。
像这样设置你的 git 存储库:

mystyle.sty
project/
    makefile
    project.tex

并将 \usepackage{mystyle} 放在 project.tex 的序言中。
当然,手动编译 project.tex 是行不通的,因为 mystyle.styproject.tex 不在同一目录中。

但是,如果 makefile 包含以下内容:

project.pdf: mystyle.sty project.tex
    pdflatex project

mystyle.sty: ../mystyle.sty
    cp ../$@ $@

那么从 project 目录中运行 make 将导致 mystyle.styproject.tex 编译(这次成功)之前将 code> 复制到正确的位置。

这种方式可能看起来有点夸张,但它确实结合了其他方法的最佳功能。

  1. 如果同一存储库中的多个项目需要 mystyle.sty,那么在它们之上放置一个通用的 mystyle.sty 比在每个项目目录中都有一个副本更有意义;所有这些副本都必须保留。
  2. 编译是可移植的,从某种意义上说,如果您给了我 mystyle.styproject.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:

mystyle.sty
project/
    makefile
    project.tex

and put \usepackage{mystyle} in the preamble of project.tex.
Compiling project.tex manually won't work, of course, because mystyle.sty is not in the same directory as project.tex.

However, if makefile contains something along the lines of:

project.pdf: mystyle.sty project.tex
    pdflatex project

mystyle.sty: ../mystyle.sty
    cp ../$@ $@

then running make from within the project directory will cause mystyle.sty to be copied to the correct place before project.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.

  1. If several projects in the same repository require mystyle.sty then having a common mystyle.sty sitting above them all makes more sense than having a copy in each project directory; all these copies would have to be maintained.
  2. The compilation is portable, in the sense that if you gave me your copies of mystyle.sty and project.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}.
想你只要分分秒秒 2024-11-13 16:32:33

您可以按照上面的建议使用 Makefile。另一个选择是 CMake。我没有测试父目录。

如果您有以下文件结构:

    ├── CMakeLists.txt
    ├── cmake
    │   └── UseLATEX.cmake
    ├── img
    │   └── logo.jpg
    ├── lib
    │   └── framed.sty
    └── main.tex
  • 您应该安装 CMake,请参阅 CMake 资源

  • UseLATEX.cmake 可以从此处

  • 然后在CMakeLists.txt

    ╚═$ cat CMakeLists.txt
    cmake_minimum_required(2.6 版)
    设置(PROJECT_NAME_STR myProject)
    项目(${PROJECT_NAME_STR})
    
    设置(CMAKE_MODULE_PATH“$ {CMAKE_CURRENT_SOURCE_DIR} / cmake”)
    包括(使用LATEX)
    
    ADD_LATEX_DOCUMENT(主.tex
                       IMAGE_DIRS 图片
                       默认_PDF
                       MANGLE_TARGET_NAMES)
    
  • main.tex 的一些示例内容(注意图像)

    ╚═$ cat main.tex
    \documentclass{报告}
    
    \开始{文档}
    
    \开始{中心}
      \includegraphics[宽度=300px]{img/logo.jpg}
    \结束{中心}
    
    \结束{文档}
    
  • lib 目录包含 *.sty 文件

  • 您可以现在编译:

    cd /directory/that/has/CMakeLists.txt/
    mkdir 构建
    光盘构建
    ..
    制作
    
  • 然后您可以查看构建目录中的 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:

    ├── CMakeLists.txt
    ├── cmake
    │   └── UseLATEX.cmake
    ├── img
    │   └── logo.jpg
    ├── lib
    │   └── framed.sty
    └── main.tex
  • you should have CMake installed, instructions on CMake resources

  • UseLATEX.cmake can be downloaded from here

  • then inside the CMakeLists.txt

    ╚═$ cat CMakeLists.txt
    cmake_minimum_required (VERSION 2.6)
    set(PROJECT_NAME_STR myProject)
    project(${PROJECT_NAME_STR})
    
    set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    include(UseLATEX)
    
    ADD_LATEX_DOCUMENT(main.tex
                       IMAGE_DIRS img
                       DEFAULT_PDF
                       MANGLE_TARGET_NAMES)
    
  • Some example content for main.tex (note the image)

    ╚═$ cat main.tex
    \documentclass{report}
    
    \begin{document}
    
    \begin{center}
      \includegraphics[width=300px]{img/logo.jpg}
    \end{center}
    
    \end{document}
    
  • The lib directory has the *.sty files

  • You can now compile:

    cd /directory/that/has/CMakeLists.txt/
    mkdir build
    cd build
    cmake ..
    make
    
  • you can then view main.pdf which is in the build directory.

寄居者 2024-11-13 16:32:33

当您使用使用 kpathsea 的 TeX 发行版时,您可以使用 TEXINPUTS 环境变量指定 TeX 在哪里查找文件。该变量需要按以下方式使用。

TEXINPUTS 中的路径由 : 分隔。空路径将包含默认搜索路径,即仅包含冒号。两个连续的斜杠表示搜索该目录及其所有子目录。

因此,例如,要构建一个文件 document.pdf ,该文件使用当前目录、resources 目录的所有子目录和默认目录中的文件,您可以使用以下Makefile。

document.pdf: document.tex
    TEXINPUTS=.:./resources//: pdflatex document.tex

要加快文件名查找速度,您可以使用 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 the resources directory and the default directories, you can use the following Makefile.

document.pdf: document.tex
    TEXINPUTS=.:./resources//: pdflatex document.tex

To speed up the filename lookup, you can build a ls-R database using the mktexlsr command.

For all the details on kpathsea take a look at the manual.

简单爱 2024-11-13 16:32:33

您可以使用 Latexmk 及其工具

第 48 页Utility subroutines 下记录了一个功能 这里在latexmk中,它可以在运行期间更新TEXINPUTS。如果您可以考虑使用 .latexmkrc 文件来配置您的链和选项,您可以将 ensure_path() 添加到该文件:

这是一个示例:

# .latexmkrc
ensure_path('TEXINPUTS', './path/to/something//', '/full/path/to/something/else//')
# [...] Other options goes here.
$pdf_update_method = 3;
$xelatex = 'xelatex -synctex=1 -interaction=nonstopmode -file-line-error %O %S';
$pdf_previewer = 'start "%ProgramFiles%/SumatraPDF/SumatraPDF.exe" %O %S';
$out_dir = 'build/';

注意 // 位于路径末尾,这将帮助 LaTeX 搜索指定目录和所有子目录中的文件。

请注意,虽然这是一个令人惊叹的功能,但您需要妥善保管您的命名方案。如果您在多个位置使用相同的文件名,则在使用 \include{somefile} 导入它们时可能会遇到麻烦。

You can use latexmk and its facilities

There is a feature documented under Utility subroutines on page 48 here in latexmk which can update TEXINPUTS during a run. If you can consider to use the .latexmkrc file to configure your chain and options, you can add ensure_path() to the file:

Here is an example:

# .latexmkrc
ensure_path('TEXINPUTS', './path/to/something//', '/full/path/to/something/else//')
# [...] Other options goes here.
$pdf_update_method = 3;
$xelatex = 'xelatex -synctex=1 -interaction=nonstopmode -file-line-error %O %S';
$pdf_previewer = 'start "%ProgramFiles%/SumatraPDF/SumatraPDF.exe" %O %S';
$out_dir = 'build/';

Notice the // at the end of a path, This will aid LaTeX to search for files in the specified directory and in all subdirectories.

Please note that while this is an amazing feature, you need to take good care of your naming scheme. If you use the same file name several places, you can run into trouble when importing them with, say \include{somefile}.

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