Make diff of two versions of a LaTeX document in a Git repo
Project description
Git-LaTeX-Diff Original
Make a rendered diff of two versions of a LaTeX document.
License
See License
Changelog
See Changelog
Purpose
latexdiff is a LaTeX tool to create a diff of two LaTeX documents, which shows deletions and additions as red strike-through text and additions as blue underlined text when compiled to PDF. However, latexdiff has some major limitations.
To overcome the limitations, this Python script extends latexdiff in several ways:
- It works with a Git repo such that it compares the current state or a given commit with an earlier commit
- It resolves
\includeand\inputcommands like LaTeX does - It calls
pdflatexto render the final PDF
In addition the \include and \input resolving itself can be called as standalone script.
Caveats
- While
\includeand\inputare resolved from the respective git revisions, other includes like figures are resolved when compiling the diff. This is done in the new revision. So if the old version includes figures that are missing or renamed in the new revision they will be missing in the diff PDF as well. - There is no diff of the bibliography and other generated parts.
- When using uncommitted changes as new version the rendering has to take place in the documents work directory. This may leave temporary files and have other unexpected side effects. However, if everything is committed or dedicated Git revisions are compared all processing is done in temporary directories that are cleaned up.
Installation
Prerequesites
- LaTeX must be installed including the tools
pdflatexlatexdiff
- Python3 is available with at least the version set in
pyproject.toml
Install
The installation itself can be done with pip or pipx:
pip(x) install gitlatexdiff-original
Usage
The package provides the script gitlatexdiff-original.
Options
Call gitlatexdiff-original with option --help to get the current list of command line options and their defaults if optional.
-m,--main: (mandatory) Name of the main LaTeX file whose versions should be compared. It has to reside in the respective Git repository containing the versions to compare. May be given with path ifgitlatexdiff-originalis called from outside the LaTeX project directory.-n,--new-rev: Newer revision to compare with. If not given the current state of the work files is used, which will be the HEAD revision if all files are committed or else the work files themselves.-o,--old-rev: Older revision to compare with. If not given either the revision before--new-revis used or the HEAD revision if--new-revis also not given and there are uncommitted changes.--old-main: Name of the old main LaTeX file which should be compared. Defaults to--main.-d,--diff-name: Name of the final diff file. '.pdf' will be appended if necessary. The log file of the lastpdflatexcall will be stored beside this file.-w,--overwrite: If not givengitlatexdiff-originalrefuses to overwite an existing diff file.--num-rounds: Number of calls topdflatexwhen compiling the diff.
The following options are passed to latexdiff or pdflatex respectively. For technical reasons values have to be given without leading dashes. Dashes are prepended as required by the respective command.
-l,--latexdiff-options: Arbitrary number of options passed tolatexdiffcall. Pass without any value to turn off the default.-p,--pdflatex-options: Arbitrary number of options passed topdflatexcall. Pass without any value to turn off the default.
Tips
If the diff sources cannot be compiled check the log file for problems with \DIF... commands and see which original LaTeX command caused it. Then you may exclude that command from the diff with for example:
-l 'append-textcmd=hint.*,todo' 'exclude-textcmd=title,.*section,chapter'
Here, LaTeX commands \title, \chapter, and all ending in section are excluded, so diffs in these commands are not marked in the output.
Note, that in this case the 'append-textcmd=hint.*,todo' is the default for option -l, which needs to be set explicitely if -l is given.
flattenlatex
flattenlatex is an additional Python script to resolve \include and recursively \input commands in a LaTeX document. gitlatexdiff-original uses it on both versions of the input file.
flattenlatex resolves \include only one level deep and respects \includeonly if present like LaTeX itself does.
Call flattenlatex --help to see its options to set the input and output file. The input file is mandatory, because included files are drawn from its directory. The output file is optional, if omitted, stdout will be used.
Documentation
Documentation is created with MkDocs.
The following commands called from the base directory create the documentation:
mkdocs build: Build static documentation in subfoldersite/. Opensite/index.htmlin a browser to see the docs.mkdocs serve: Start the docs server. See its messages on how to open the provided website.mkdocs --help: Print help message and exit.
If mkdocs is not available or throws errors you may create a virtual environment with uv sync (or poetry sync) and call MkDocs with uv run mkdocs (or poetry run mkdocs).
Contributing
Create issues or a pull requests to point out bugs or improvements.
We have used uv as development and packaging tool so you may use uv sync to create a virtual environment with all required packages and execute the scripts with uv run. Likely poetry will work as well.
A note on the name
This project is called Git-LaTeX-Diff Original or gitlatexdiff-original, because the project name gitlatexdiff is already in use on PyPI for a similar package that was independently developed. It is called original due to the fact that the first publication of this project on GitHub is older.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitlatexdiff_original-0.3.0.tar.gz.
File metadata
- Download URL: gitlatexdiff_original-0.3.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac9aaf7fc5ab3a387699094737b741c0c38b4b86ffb1e408eb6d6935bd07f101
|
|
| MD5 |
7ddc3c1fc93746fce85b90990d51ef0e
|
|
| BLAKE2b-256 |
a576e3441c267985279ef89a54bb31673fe3d429e14bfad2fb956856df09e37b
|
File details
Details for the file gitlatexdiff_original-0.3.0-py3-none-any.whl.
File metadata
- Download URL: gitlatexdiff_original-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7866592b0afe1c5535d939650424b1c0baa944a2eeaf78a671535a2932ae9df
|
|
| MD5 |
0af44ad9140210726f10823e29638104
|
|
| BLAKE2b-256 |
90489ca395ba5449e5133c799449d74dac7fb562f83cf23b9d376f7412136995
|