Top Related Projects
A web-based collaborative LaTeX editor
Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
Quick Overview
The xu-cheng/latex-action
is a GitHub Action that allows you to compile LaTeX documents directly within your GitHub workflows. It provides a convenient way to automate the process of building and publishing LaTeX-based projects, such as academic papers, reports, or presentations.
Pros
- Automated LaTeX Compilation: The action simplifies the process of compiling LaTeX documents, allowing you to integrate it seamlessly into your GitHub workflow.
- Cross-platform Compatibility: The action supports multiple operating systems, including Linux, macOS, and Windows, making it versatile for different development environments.
- Customizable Configurations: The action provides various configuration options, enabling you to tailor the compilation process to your specific needs, such as using custom LaTeX packages or compiling multiple files.
- Artifact Handling: The action can automatically upload the compiled PDF or other output files as GitHub Actions artifacts, making them easily accessible for download or further processing.
Cons
- Limited Debugging: While the action provides some error reporting, the debugging experience for complex LaTeX projects may be limited, requiring users to investigate issues manually.
- Dependency Management: The action relies on a pre-built Docker image, which may not always include the latest versions of LaTeX packages or dependencies. Users may need to maintain their own custom Docker images to ensure compatibility with their project requirements.
- Lack of Advanced Features: The action is focused on the core functionality of compiling LaTeX documents, and it may not provide advanced features like continuous integration, deployment, or integration with other tools.
- Potential Overhead: The use of a Docker-based approach may introduce some overhead compared to a native LaTeX installation, which could impact the overall performance of the GitHub workflow.
Getting Started
To use the xu-cheng/latex-action
in your GitHub workflow, you can add the following configuration to your .github/workflows/main.yml
file:
name: LaTeX Compilation
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v2
with:
root_file: main.tex
compiler: pdflatex
args: -pdf -interaction=nonstopmode -halt-on-error
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: PDF
path: main.pdf
This configuration will:
- Checkout the repository.
- Compile the
main.tex
file using thepdflatex
compiler with the specified arguments. - Upload the generated
main.pdf
file as a GitHub Actions artifact.
You can customize the configuration further by modifying the root_file
, compiler
, and args
inputs to match your specific project requirements.
Competitor Comparisons
A web-based collaborative LaTeX editor
Pros of Overleaf
- Full-featured online LaTeX editor with real-time collaboration
- Extensive template library and integrated version control
- Web-based platform accessible from any device with a browser
Cons of Overleaf
- Requires internet connection for use
- Limited customization compared to local LaTeX environments
- Potential privacy concerns with cloud-based document storage
Code Comparison
Overleaf (server-side rendering):
app.get('/project/:project_id/output/:output_file', function(req, res, next) {
const project_id = req.params.project_id
const file_path = `${Settings.path.compilesDir}/${project_id}/output/${req.params.output_file}`
res.sendFile(file_path)
})
latex-action (GitHub Action workflow):
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v2
with:
root_file: main.tex
args: -pdf -file-line-error -halt-on-error -interaction=nonstopmode
The code snippets highlight the different approaches: Overleaf focuses on server-side rendering and file serving, while latex-action is designed for CI/CD workflows in GitHub Actions.
Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
Pros of LaTeX-Workshop
- Integrated development environment (IDE) for LaTeX in Visual Studio Code
- Real-time preview and compilation of LaTeX documents
- Extensive language support with syntax highlighting and autocompletion
Cons of LaTeX-Workshop
- Limited to Visual Studio Code environment
- May require additional setup for specific LaTeX distributions
- Potential performance issues with large documents or complex projects
Code Comparison
LaTeX-Workshop (settings.json):
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
}
]
latex-action (workflow.yml):
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v2
with:
root_file: main.tex
latexmk_use_xelatex: true
The LaTeX-Workshop code snippet shows configuration for the LaTeX compilation tool within VS Code, while the latex-action code demonstrates its usage in a GitHub Actions workflow for automated compilation.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
latex-action
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.
Features
- ð³ 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.
Inputs
Configure the action by providing these inputs in the with
section:
Required Inputs
-
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
Environment Configuration
-
texlive_version
TeXLive 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
-
os
Base operating system for the Docker image (alpine
ordebian
). Defaults toalpine
.- uses: xu-cheng/latex-action@v4 with: root_file: main.tex os: debian
-
docker_image
Custom Docker image to use (overridestexlive_version
andos
). 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>
Compilation Settings
-
working_directory
Working directory for the compilation process. -
work_in_root_file_dir
Change to each root file's directory before compilation. Useful for multi-document builds where each document has its own directory structure. -
continue_on_error
Continue building remaining documents even if some fail. The action will still report failure if any document fails. -
compiler
LaTeX compiler to use. Defaults tolatexmk
for automated compilation. -
args
Additional arguments passed to the LaTeX compiler. Defaults to-pdf -file-line-error -halt-on-error -interaction=nonstopmode
.
Dependencies
-
extra_system_packages
Additional system packages to install (space-separated). Usesapk
for Alpine orapt-get
for Debian.extra_system_packages: "inkscape ghostscript"
-
extra_fonts
Extra font files to install for fontspec (.ttf/.otf). Supports glob patterns and multi-line input:extra_fonts: | ./path/to/custom.ttf ./fonts/*.otf
Scripts
-
pre_compile
Bash commands to execute before compilation (e.g., package updates):pre_compile: "tlmgr update --self && tlmgr update --all"
-
post_compile
Bash commands to execute after compilation (e.g., cleanup tasks):post_compile: "latexmk -c"
LaTeX Engine Options
[!IMPORTANT] The following inputs only work with the default
latexmk
compiler.
-
latexmk_shell_escape
Enable shell-escape for latexmk (allows external command execution). -
latexmk_use_lualatex
Use LuaLaTeX engine with latexmk. -
latexmk_use_xelatex
Use XeLaTeX engine with latexmk.
Example
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.pdf
FAQs
How to use XeLaTeX or LuaLaTeX instead of pdfLaTeX?
By 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: true
Alternatively, you could create a .latexmkrc
file. Refer to the latexmk
document for more information.
How to enable --shell-escape
?
To enable --shell-escape
, set the latexmk_shell_escape
input.
- uses: xu-cheng/latex-action@v4
with:
root_file: main.tex
latexmk_shell_escape: true
Where is the PDF file? How to upload it?
The 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-artifact
to 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-release
to attach the PDF to GitHub releases. -
Deploy elsewhere - Use standard tools like
scp
,git
, orrsync
to upload the PDF to any destination. For example, push to thegh-pages
branch to serve via GitHub Pages.
How to add additional paths to the LaTeX input search path?
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.
It fails to build the document, how to solve it?
- 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
License
MIT
Top Related Projects
A web-based collaborative LaTeX editor
Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot