Compares two LaTeX files and generates a color-coded diff document.
Key Features:
- Visual Diff Generation: Creates a LaTeX document highlighting differences
- Color-Coded Output:
- 🔴 Red: Content removed from first file
- 🔵 Blue: Content added in second file
- ⚫ Black: Unchanged content
- Two Diff Modes:
- Line-level diff: Shows entire lines as added/removed
- Inline diff: Shows word-level changes within similar lines
- LaTeX-Aware: Uses
lstlistingenvironment to preserve LaTeX formatting - Compilable Output: Generates valid LaTeX document ready to compile
Usage:
from latex_diff_parser import LatexDiffParser
# Create line-level diff
parser = LatexDiffParser('old_version.tex', 'new_version.tex', 'diff_output.tex')
parser.create_diff_document()
# Create inline word-level diff
from latex_diff_parser import LatexInlineDiffParser
inline_parser = LatexInlineDiffParser('old.tex', 'new.tex', 'inline_diff.tex')
inline_parser.create_diff_document()
# Compile the diff document
# pdflatex diff_output.texDiff Modes:
-
LatexDiffParser: Line-by-line comparison
- Shows complete lines as added or removed
- Uses
\textcolor{red}and\textcolor{blue}for changes - Best for significant structural changes
-
LatexInlineDiffParser: Word-level comparison
- Shows changes within lines
- Uses
\odiff{}(red strikethrough) for deletions - Uses
\ndiff{}(green) for additions - Better for minor edits and fine-grained changes
Output:
- Generates a standalone LaTeX document with:
- Required packages (
xcolor,listings,soul,ulem) - Color legend explaining the diff markers
- Formatted diff content
- Compilation instructions
- Required packages (
# Install with pipx (isolated environment, system-wide commands)
pipx install git+https://github.com/iheitlager/latex-tools.git
# The commands are now available globally
latex-processor --help
doi-validator --help
latex-diff --help# Install directly from GitHub (latest version)
python3 -m pip install git+https://github.com/iheitlager/latex-tools.git
# Or install from a specific release
python3 -m pip install https://github.com/iheitlager/latex-tools/releases/latest/download/latex_tools-0.2.0-py3-none-any.whl# Clone the repository
git clone https://github.com/iheitlager/latex-tools.git
cd latex-tools
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
# Or using uv (recommended)
uv syncFor more installation options, see INSTALL.md
- Python 3.11+
- Standard library only (no external dependencies required)
Copyright (c) 2025 - Ilja Heitlager
SPDX-License-Identifier: Apache-2.0
python latex_processor.py thesis.tex -o thesis_single.tex --verbosepython doi_validator.py references.bib --verbosepython latex_processor.py paper.tex --bibtex -o paper_refs.bibfrom latex_diff_parser import LatexInlineDiffParser
parser = LatexInlineDiffParser('draft_v1.tex', 'draft_v2.tex', 'changes.tex')
parser.create_diff_document()python latex_processor.py document.tex -o output.tex --verbose
# Check output for warnings about:
# - Duplicate labels
# - Undefined references
# - Unused labels
# - Missing captions