A GitHub Actions workflow that automatically finds, compiles, and commits all LaTeX documents in your repository whenever you push changes.
- Smart Root Detection: Only compiles root documents (files containing
\documentclass), skipping sub-files and inputs automatically - Full TeXLive Environment: Uses the complete TeXLive Docker container for maximum compatibility
latexmkCompilation: Handles bibliographies (BibTeX/Biber), indexes, and multi-pass references automatically- Auto-Commit: Automatically commits compiled PDFs back to the repository on main/master branches
- Artifact Storage: Uploads all PDFs as a single artifact with 30-day retention
- Concurrency Control: Cancels redundant runs when you push multiple times in quick succession
- Error Resilience: Continues processing other files even if one fails to compile
Create the directory .github/workflows/ in your repository and copy clean_latex_workflow.yml into it, renaming it to latex.yml (or any .yml name you prefer).
This step is crucial for the workflow to function properly.
- Go to your repository on GitHub
- Navigate to Settings → Actions → General
- Scroll down to "Workflow permissions"
- Select "Read and write permissions"
- Click "Save"
Without these permissions, the workflow cannot commit the compiled PDFs back to your repository.
Simply add your .tex files anywhere in your repository. The workflow will automatically find and compile them.
The workflow runs automatically on:
- Push to
mainormasterbranch - Pull requests to
mainormasterbranch
If you push multiple commits in quick succession, the workflow cancels the previous run and starts fresh (concurrency control).
- Discovery: Scans the entire repository for
.texfiles that contain\documentclass(root documents only) - Compilation: Runs
latexmk -pdfon each document — handles bibliographies, indexes, and multiple passes automatically - Artifact Upload: Bundles all compiled PDFs into a single downloadable artifact
- Auto-Commit: On main/master push events, commits PDFs back to their original locations
- Summary: Generates a table report showing compiled vs. failed files
The workflow maintains your repository's directory structure. If you have:
docs/
├── chapter1/
│ └── intro.tex
├── chapter2/
│ └── methodology.tex
└── references.tex
The compiled PDFs will be placed in the same directories:
docs/
├── chapter1/
│ ├── intro.tex
│ └── intro.pdf
├── chapter2/
│ ├── methodology.tex
│ └── methodology.pdf
├── references.tex
└── references.pdf
If your project uses \input{} or \include{} to split the document across multiple .tex files, only the root file (the one with \documentclass) will be compiled. Sub-files without \documentclass are ignored.
- Add a
.texfile to your repository - Push to main/master branch
- The workflow automatically compiles it and commits the PDF
No extra configuration needed — latexmk automatically runs Biber/BibTeX and re-runs pdflatex as many times as needed.
The workflow handles any number of LaTeX documents across any directory structure. Each root document is compiled in sequence.
- Discovers all root
.texfiles (\documentclasspresent) - Compiles each with
latexmk -pdf - Collects all generated PDFs and uploads them as one artifact
- Outputs a summary table to the Actions run page
- Runs only on push to main/master (not on pull requests)
- Downloads the artifact and places each PDF next to its source
.texfile - Commits and pushes only if PDFs actually changed
Edit the branches section in the workflow:
on:
push:
branches: [ main, master, your-branch ]Modify the latexmk command in the compile step:
latexmk -pdf -interaction=nonstopmode -halt-on-error "$base_name.tex"For example, add -xelatex or -lualatex if your document requires a different engine.
Change the retention period in the "Upload all PDFs" step:
retention-days: 30 # Change to desired number of daysEnsure you've enabled "Read and write permissions" in the repository settings as described in the setup section.
Check the workflow logs for specific LaTeX errors. The workflow continues processing other files even if one fails, and the summary table shows which files failed.
PDFs are only committed to main/master branches on push events. On pull requests, they're available as a downloadable artifact.
The workflow uses the full TeXLive distribution. If you encounter package errors, the issue is likely in your LaTeX source rather than missing packages.
- The workflow only runs on your repository's content
- No external LaTeX code is executed
- All compilation happens in isolated Docker containers
- PDFs are committed using GitHub's built-in token with minimal permissions
Feel free to submit issues and enhancement requests. Contributions are welcome!
This workflow configuration is provided as-is. Use it freely in your projects.