我在LaTeX大学写下讲座(这对于此目的非常方便),我希望tex
文件能够在pdf
中自动编译。
我的存储库中有几个.tex
文件,如下所示:
.
├── .gitlab-ci.yml
└── lectures
├── math
| ├── differentiation
| | ├── lecture_math_diff.tex
| | ├── chapter_1.tex
| | └── chapter_2.tex
| └── integration
| ├── lecture_math_int.tex
| ├── chapter_1.tex
| └── chapter_2.tex
└── physics
└── mechanics
├── lecture_physics_mech.tex
├── chapter_1.tex
└── chapter_2.tex
所以主文件,例如lecture_math_diff.tex
使用
\include{chapter_1}
\include{chapter_2}
标签,形成整个讲座。
结果,我想在pdf中创建我的构建工件:
├── math
| ├── lecture_math_diff.pdf
| └── lecture_math_int.pdf
└── physics
└── lecture_physics_mech.pdf
这里可以做些什么?我是否必须编写任何sh
脚本来收集所有tex
文件或使用gitlab runners?
答案 0 :(得分:2)
一种方法是使用短脚本(例如python或bash)并运行latexmk
来生成PDF文件。
latexmk
是一个perl脚本,可自动编译乳胶文件。可以找到简短的介绍here
使用python3时,脚本可能类似于以下脚本:
# filename: make_lectures.py
import os
from subprocess import call
# configuration:
keyword_for_main_tex = "lecture"
if __name__ == "__main__":
tex_root_directory = os.getcwd()
for root, _, files in os.walk("."):
for file_name in files:
# check, if file name ends with `tex` and starts with the keyword
if file_name[-3:] == "tex" and file_name[0:len(keyword_for_main_tex)] == keyword_for_main_tex:
os.chdir(root) # go in the direcotry
os.system("latexmk -lualatex "+ file_name) # run latexmk on the mainfile
os.chdir(tex_root_directory) # go back to root directory in case of relative pathes
此脚本假定,仅要编译为PDF的文件以关键字lecture
开头(如问题所示)。但是if
语句(用于检查要构建的文件)也可以扩展为更复杂的比较,以匹配正则表达式。
此处使用命令行标志latexmk
调用-lualatex
,以演示如何整体配置构建过程。 .latexmkrc
文件给出了针对每个单个项目的本地配置可能性,这些文件由latexmk
进行读取和处理。
如果我们将latexmk
作为shell命令调用,则必须确保已将其安装在gitlab运行程序(以及texlive
)上。如果注册了Docker
个容器运行程序(请参见here的完成方式),那么您只需要指定DockerHub中图像的名称,就可以得到示例{{1} }文件如下:
gitlab-ci.yml
免费,将图像更改为您喜欢的任何其他图像(例如compile_latex_to_pdf:
image: philipptempel/docker-ubuntu-tug-texlive:latest
script: python3 make_lectures.py
artifacts:
paths:
- ./*.pdf
expire_in: 1 week
)。请注意,工件提取假定存储库中没有其他PDF文件。
最后一句话:我没有尝试过,但是应该可以在gitlab运行程序上直接安装blang/latex:latest
和texlive
(如果您可以访问它)。
答案 1 :(得分:0)
您可以查看https://github.com/reallyinsane/mathan-latex-maven-plugin。使用Maven或Gradle插件,您还可以在项目中使用“依赖项”。