How to compare two LaTeX files

We can use latexdiff to compare two LaTeX files. This Perl script has an issue with bibliography files, so place this wrapper before TeX Live's latexdiff:

#!/bin/sh
$HOME/opt/texlive/current/bin/x86_64-linux/latexdiff "$@" |
        sed -E 's/\\DIFadd\{(natexlab)\}/\1/g'

To compare two LaTeX files:

latexdiff file1.tex file2.tex > diff.tex

To compare two main files that input other files:

latexdiff --flatten main1.tex main2.tex > diff.tex

To compare a git revision and main.tex:

latexdiff-vc --git --flatten -r REVISION main.tex
# main-diffREVISION.tex is generated

To compare two git revisions of main.tex:

latexdiff-vc --git --flatten -r REVISION1 -r REVISION2 main.tex
# main-diffREVISION1-REVISION2.tex is generated