latex_differ.py creates a side-by-side PDF diff between two LaTeX sources. Each input can be a full project folder, a single .tex file, or a .zip archive. The script wraps latexdiff/latexmk, injects custom banners for floats, and restores key table tokens so that changes inside table, figure, algorithm, and similar environments are highlighted in place (cell-level edits, figure swaps, etc.).
- Works on full LaTeX projects with nested folders: both input directories are copied intact to a temporary workspace so relative paths/graphics continue to resolve.
- Auto-detects the main
.texfile (or accept--main) and callslatexdiff --flattenso multi-file projects are merged. - Structural highlighter adds
Updated Figure/Table/Algorithmbanners and keeps table separators, ensuring float changes are called out where they actually render. - Normal, deleted, and added text is rendered using the standard
latexdiffblue/red markup while tables still compile cleanly thanks to selective reinsertion of%DIFcommands. - Uses
latexmk(fallback topdflatex) and copies the resultingdiff.pdfto your chosen output path, with a locked-file fallback if the viewer keeps the file open.
- Python 3.10+
- TeX Live (or another TeX distribution) providing
latexdiff,latexmk, andpdflatex - A shell environment that can run the above binaries on
PATH
python latex_differ.py path/to/old path/to/new -o diff.pdfEach path/to/... may be:
- a directory containing a LaTeX project,
- a single
.texfile (the script copies it into an isolated workspace), - or a
.ziparchive (automatically extracted before diffing).
| Flag | Description |
|---|---|
--main path/to/main.tex |
Relative path to the main file if auto-detect fails. |
--latexdiff-arg "..." |
Pass-through options to latexdiff (repeatable). |
--no-default-latexdiff-args |
Disable the built-in safety exclusions. |
--engine {auto,latexmk,pdflatex} |
Force a specific LaTeX build tool. |
--keep-temp |
Leave the temporary workspace on disk for debugging. |
--verbose |
Show all commands executed. |
Diff two directories (explicit main file + verbose logging):
python latex_differ.py ./old ./new --main access.tex -o trustworthiness_diff.pdf --verboseDiff two zipped projects:
python latex_differ.py old_version.zip new_version.zip -o diff.pdfDiff two standalone .tex files:
python latex_differ.py paper_v1.tex paper_v2.texdiff.pdf(ordiff.locked.<timestamp>.pdfif the target is in use) written to the working directory.- Temporary workspace printed when
--keep-tempis set, useful if you want to inspectdiff.texor run LaTeX manually.
- Inputs are copied/extracted into a temporary workspace before diffing, so originals remain untouched. Large assets (figures, images, data) are duplicated temporarily—ensure sufficient disk space.
- The script automatically runs
latexmk(or falls back topdflatex+bibtex) on each staged project so that.bblfiles exist and newly added references appear in the diff. - This tool and its documentation were built with assistance from OpenAI Codex.