# pdfdiff

Produces a PDF from two LaTeX sources with all changes visually marked — insertions in dark green, deletions in red strikethrough by default. Both colours are configurable.

Wraps [`latexdiff`](https://ctan.org/pkg/latexdiff) and handles the full build pipeline: bibliography generation, multi-file projects, and arXiv-style embedded `.bbl` files.

## Usage

```
pdfdiff [OPTIONS] <original> <modified>
```

Each source can be:

| Form | Example |
|------|---------|
| Git branch name | `main` |
| `.tex` file path | `paper/main.tex` |
| Project directory | `paper/` |

For directories and branches, the file containing `\documentclass` is used as the root automatically.  
`diff.tex` and `diff.pdf` are written to `./diff/` by default, or to the directory specified with `--output`.

### Disclaimer
**Never use your active project directory as the output path.** The modified source is copied into the output directory during the build — any existing files there can be overwritten.

### Options

| Flag | Default | Description |
|------|---------|-------------|
| `--output <DIR>` | `./diff/` | Directory to write `diff.tex` and `diff.pdf` |
| `--no-cleanup` | — | Keep intermediate build files in the output directory |
| `--add-color <COLOUR>` | `green!50!black` | Colour for inserted text |
| `--del-color <COLOUR>` | `red` | Colour for deleted text |

Colours accept any [`xcolor`](https://ctan.org/pkg/xcolor) expression: named colours (`blue`, `orange`), DVIPSNames (`NavyBlue`, `ForestGreen`), or mixed expressions (`red!70!black`, `blue!50!white`).

### Examples

```sh
# Compare two git branches, output to ./diff/
pdfdiff main feature-branch

# Compare two directories
pdfdiff paper-v1/ paper-v2/

# Compare specific .tex files
pdfdiff old/main.tex new/main.tex

# Write output to a custom directory
pdfdiff main feature-branch --output out/

# Keep all intermediate build files
pdfdiff main feature-branch --no-cleanup

# Custom colours
pdfdiff --add-color blue --del-color orange old.tex new.tex
```

## Requirements

Works on Linux and macOS. Windows 10+ should be supported as long as the dependencies are installed.

Required:

- [`latexdiff`](https://ctan.org/pkg/latexdiff) — usually part of TeX Live / MiKTeX
- `pdflatex`
- `git` (for branch inputs)

Optional but recommended:

- `latexpand` — enables `--flatten` so `\input`/`\include` directives are inlined; ships with TeX Live
- `bibtex` / `biber` — required if the project has a bibliography

## Installation
Either download the latest release, or if you have `cargo` installed you can run:

```sh
cargo install pdfdiff
```

## How it works

1. Each source is resolved to a root `.tex` file (extracting git branches via `git archive` into a temp directory as needed).
2. The modified project is copied into the output directory so all relative asset paths work.
3. The modified source is pre-built (`pdflatex` + bibliography tool) to generate `.bbl` and other artifacts before the diff is compiled.
4. `latexdiff` produces `diff.tex` with change markup.
5. Colour overrides are injected just before `\begin{document}`: insertions are coloured, deletions get a strikethrough — `\sout` in text mode, `\bcancel` in math mode (since `\sout` does not work inside equation environments).
6. `diff.tex` is compiled twice with `pdflatex` to resolve cross-references.

### arXiv projects

Projects that embed `\input{main.bbl}` instead of a live `\bibliography{}` call are handled automatically: a minimal `.aux` stub is written and `bibtex` is run to synthesise the missing `.bbl` before compilation.
