Metadata-Version: 2.4
Name: texdiff
Version: 0.2.0
Summary: AST-driven semantic diff for LaTeX documents
Author: GoBobr
License: MIT License
        
        Copyright (c) 2026 GoBobr
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/GoBobr/texdiff
Keywords: latex,diff,latexdiff,ast,track-changes
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: Markup :: LaTeX
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pylatexenc>=2.10
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-cov>=4; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.5; extra == "docs"
Requires-Dist: mkdocs-material>=9; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
Requires-Dist: pymdown-extensions>=10; extra == "docs"
Dynamic: license-file

# texdiff

**AST-driven semantic diff for LaTeX documents.**

`texdiff` compares two revisions of a LaTeX document and produces a single
marked-up `diff.tex` that compiles with `pdflatex` — added text in blue,
deleted text struck out — while preserving the original document's styling,
cross-references and custom classes.

## Why

[`latexdiff`](https://www.ctan.org/pkg/latexdiff) is the de-facto standard for
review-marked LaTeX, but it diffs *token soup*: it guesses word boundaries with
regexes and re-injects markup into the merged text, hoping braces still
balance. On real-world documents the result is markup that crosses brace /
environment boundaries, glues old and new table cells together, and corrupts
listings — which is why every serious latexdiff user eventually ends up
maintaining a pile of fragile pre/post-processing scripts around it.

`texdiff` takes the other road: **diff the tree, never the text.**

1. Parse old and new documents into a LaTeX syntax tree
   ([pylatexenc](https://github.com/phfaist/pylatexenc) — a faithful concrete
   syntax tree carrying exact source spans, no macro expansion).
2. Align the trees level by level (document → environments → groups → text
   runs) with difflib-style sequence matching. A change can never leak across
   a node boundary.
3. Walk the merged tree and emit `\DIFadd{...}` / `\DIFdel{...}` markup —
   latexdiff-compatible rendering, valid by construction.

Restructured tables (re-ordered rows, changed column layouts), math,
listings and verbatim environments are handled as atomic or row-aligned
blocks instead of being shredded by a word diff.

Multi-file sources are flattened automatically (`\input`/`\include`
resolved relative to each file, like `latexdiff --flatten`), and the
preamble of the new revision is used verbatim so custom classes and
macros keep working.

## Usage

```sh
texdiff old/main.tex new/main.tex > diff.tex   # \input expansion built in
pdflatex diff.tex                              # done - no pre/postprocessing
texdiff old.tex new.tex -o diff.tex --check    # + fail loudly if it won't compile
texdiff old.tex new.tex --stats                # "611 unchanged, 29 added, ..."
```

```sh
pip install texdiff        # or from a checkout:
pip install -e ".[dev]" && pytest
```

Status: **v0.2.0** — core pipeline plus flattening, row-granular table
alignment, preamble policy, `--check` and a compile-guaranteed corpus in
CI; validated on a 65-page generated longtable-heavy document. See the
[roadmap](https://gobobr.github.io/texdiff/roadmap/) for what is next.

## License

MIT
