A GitHub Action that compiles LaTeX documents to PDF using a complete TeXLive environment.
Tip
For running arbitrary commands in a TeXLive environment, use texlive-action instead.
- π³ Containerized: Run in a Docker container with a full TeXLive installation.
- π TeXLive version flexibility: Support both the latest and historic versions of TeXLive.
- π§ Multi-platform: Support both Alpine and Debian-based Docker images.
- π Multi-document support: Compile multiple LaTeX files in a single workflow.
- π§ Flexible compilation: Support various LaTeX engines (pdfLaTeX, XeLaTeX, LuaLaTeX).
- π¨ Custom fonts: Install additional fonts.
- π¦ System packages: Add extra system packages as needed.
- βοΈ Customizable: Run arbitrary pre/post-compile scripts.
Configure the action by providing these inputs in the with section:
-
root_file(required) The root LaTeX file(s) to compile. Supports glob patterns and multiple files via multi-line input:- uses: xu-cheng/latex-action@v4 with: root_file: | file1.tex file2.tex
-
texlive_versionTeXLive version to use (2020-2025 or 'latest'). Defaults to latest. Cannot be used withdocker_image.- uses: xu-cheng/latex-action@v4 with: root_file: main.tex texlive_version: 2024
-
osBase operating system for the Docker image (alpineordebian). Defaults toalpine.- uses: xu-cheng/latex-action@v4 with: root_file: main.tex os: debian
-
docker_imageCustom Docker image to use (overridestexlive_versionandos). We recommend to use latex-docker images. An example if you want to pin the docker image.- uses: xu-cheng/latex-action@v4 with: root_file: main.tex docker_image: ghcr.io/xu-cheng/texlive-alpine@sha256:<hash>
-
working_directoryWorking directory for the compilation process. -
work_in_root_file_dirChange to each root file's directory before compilation. Useful for multi-document builds where each document has its own directory structure. -
continue_on_errorContinue building remaining documents even if some fail. The action will still report failure if any document fails. -
compilerLaTeX compiler to use. Defaults tolatexmkfor automated compilation. -
argsAdditional arguments passed to the LaTeX compiler. Defaults to-pdf -file-line-error -halt-on-error -interaction=nonstopmode.
-
extra_system_packagesAdditional system packages to install (space-separated). Usesapkfor Alpine orapt-getfor Debian.extra_system_packages: "inkscape ghostscript"
-
extra_fontsExtra font files to install for fontspec (.ttf/.otf). Supports glob patterns and multi-line input:extra_fonts: | ./path/to/custom.ttf ./fonts/*.otf
-
pre_compileBash commands to execute before compilation (e.g., package updates):pre_compile: "tlmgr update --self && tlmgr update --all"
-
post_compileBash commands to execute after compilation (e.g., cleanup tasks):post_compile: "latexmk -c"
Important
The following inputs only work with the default latexmk compiler.
-
latexmk_shell_escapeEnable shell-escape for latexmk (allows external command execution). -
latexmk_use_lualatexUse LuaLaTeX engine with latexmk. -
latexmk_use_xelatexUse XeLaTeX engine with latexmk.
name: Build LaTeX document
on: [push]
jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v4
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
- name: Upload PDF file
uses: actions/upload-artifact@v4
with:
name: PDF
path: main.pdfBy default, this action uses pdfLaTeX. If you want to use XeLaTeX or LuaLaTeX, you can set the latexmk_use_xelatex or latexmk_use_lualatex input respectively. For example:
- uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
latexmk_use_xelatex: true- uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
latexmk_use_lualatex: trueAlternatively, you could create a .latexmkrc file. Refer to the latexmk document for more information.
To enable --shell-escape, set the latexmk_shell_escape input.
- uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
latexmk_shell_escape: trueThe compiled PDF file will be placed in the same directory as the LaTeX source file. You have several options for handling the generated PDF:
-
Upload as artifact - Use
@actions/upload-artifactto make the PDF available in the workflow tab:- uses: actions/upload-artifact@v4 with: name: PDF path: main.pdf
-
Attach to releases - Use
@softprops/action-gh-releaseto attach the PDF to GitHub releases. -
Deploy elsewhere - Use standard tools like
scp,git, orrsyncto upload the PDF to any destination. For example, push to thegh-pagesbranch to serve via GitHub Pages.
Sometimes you may have custom package (.sty) or class (.cls) files in other directories. If you want to add these directories to the LaTeX input search path, you can add them in TEXINPUTS environment variable. For example:
- name: Download custom template
run: |
curl -OL https://example.com/custom_template.zip
unzip custom_template.zip
- uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
env:
TEXINPUTS: ".:./custom_template//:"Note that you should NOT use {{ github.workspace }} or $GITHUB_WORKSPACE in TEXINPUTS. This action runs in a separate Docker container where the workspace directory is mounted. Therefore, the workspace directory inside the Docker container is different from github.workspace.
You can find more information of TEXINPUTS here.
- Check the build log - Examine the GitHub Actions log output for specific error messages
- Test locally - Try building your document locally with the same LaTeX distribution
- Create a minimal example - Narrow down the issue by creating a minimal working example
- Check dependencies - Ensure all required packages and fonts are properly configured
- Get help - Open an issue with a minimal working example if you need assistance
MIT