Wei Zhang's Blog

01 Oct 2021

Latexdiff: display differences between two versions of a tex document

latexdiff is a tool to display the differences between two tex files. Suppose the old version and the new version of a draft are in draft-old.tex and draft-new.tex, respectively. The following command generates a tex file, called draft-diff.tex, which includes information on the difference between these two versions.

  latexdiff --config "PICTUREENV=(?:displaymath|equation|aligned|align)[\w\d*@]*" \
    --type=CFONT draft-old.tex draft-new.tex > draft-diff.tex

The tex file draft-diff.tex can then be compiled into a pdf file that highlights the differences. To automate the process, we can put the following commands in a makefile.

  draft-diff.pdf : draft-diff.tex
		xelatex $<
		bibtex draft-diff.aux
		xelatex $<
		xelatex $<

  draft-diff.tex : draft-old.tex draft-new.tex
		latexdiff --config "PICTUREENV=(?:displaymath|equation|aligned|align)[\w\d*@]*" \
		  --type=CFONT draft-old.tex draft-new.tex > draft-diff.tex

An example output:

image

Tags