One approach would be to use a short script (e.g python or bash) and to run latexmk
to generate the PDF files.
latexmk
is a perl script, which compiles latex files automatically. A short introduction can be found here
With python3 the script could look like the following one:
# 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.endswith("tex") and file_name.startswith(keyword_for_main_tex):
os.chdir(root) # go in the directory
call(['latexmk', '-lualatex', file_name]) # run latexmk on the main file
os.chdir(tex_root_directory) # go back to root directory in case of relative paths
This script assumes, that only files to be compiled to PDF start with the keyword lecture
(as in the question). But the if
statement, which checks for files to build, could also be extended to more elaborate comparison as matching regular expressions.
latexmk
is called with the command line flag -lualatex
here to demonstrate how to configure the build process gloally. A local configuration possibility (for each single project) is given with .latexmkrc
files, which are read and processed by latexmk
.
If we call latexmk
as shell command, we have to make sure, that it is installed on our gitlab runner (and also texlive
). If Docker
container runners are registered (see here how it is done), then you just need to specify the name of an image from DockerHub, which leads to the example gitlab-ci.yml
file below:
compile_latex_to_pdf:
image: philipptempel/docker-ubuntu-tug-texlive:latest
script: python3 make_lectures.py
artifacts:
paths:
- ./*.pdf
expire_in: 1 week
Fell free, to change the image to any other image you like (e.g. blang/latex:latest
). Note, that the artifacts extraction assumes, that no other PDF files are in the repository.
A final remark: I did not try it, but it should also be possible to install texlive
and latexmk
directly on the gitlab runner (if you have access to it).