## Use latexdiff to compare different versions of LaTeX tex files to visually mark differences

This post introduces how to use latexdiff to compare two versions of latex *.tex files, in order to visually mark changes to tex files.

(One colleague asked me about the usage of latexdiff, so I think it is a good time to write it up into a blog post to share with those who need some help with this.)

latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.

Use latexdiff to mark differences and create a new LaTeX document with markup differences between two latex files.

• ### Linux (Ubuntu) users

latexdiff can be found in Ubuntu repository and detailed description of usage can be found here.

In your terminal, issue the commands below to install latexdiff.

```sudo apt-get update
sudo apt-get install latexdiff
```
```# open your terminal, and cd to the tex files you need to compare
# issue the following command
latexdiff original_version.tex revised_version.tex > diff.tex```

Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.

• ### Mac OS X users

latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.
Mac OS X includes an installation of Perl and no additional setup is required. latexdiff can be found in any CTAN repository
(If you are using MacTex on your mac,  latexdiff is already installed in MacTex under /usr/texbin/latexdiff. No need to install it separately. To use latexdiff in commend line, see below)
After you setting perl and latexdiff, just open your terminal, and cd to the path where you put you two versions of latex tex files, and then issue the command. (If the two tex files are located in different location, you can just give the relative path to that location for each version of tex file.)

`\$ latexdiff original_version.tex revised_version.tex > diff.tex`
will compare original_version.tex to revised_version.tex and create a new file diff.tex showing the differences.
Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.
• ### Online latexdiff

when you get the diff.tex on the online latexdiff, you can paste into a new tex file and then you can run it and you will see the pdf which shows the differences.
• ### Multiple tex files for each version

If each version of your text files contains multiple (sub) tex files or if you want to use latexdiff with Git, check the Reference lists for potential solutions.

### References

LATEXDIFF: SUPERB DIFF TOOL FOR LATEX (pdf) — talks about solutions to multiple files, but this can only deal with sub-files on the same level, not nested cases.

Two LaTeX gems: ShareLaTeX and latexdiff (pdf)

Using Latexdiff For Marking Changes To Tex Documents (pdf)

Multiple-file LaTeX diff (pdf— this one is very good. – use python code to merge multiple tex files to one big tex file for each version and then use latexdiff to make comparision.

Latexdiff with subfiles (pdf) — this one talks about solutions to multiple tex files.

Using latexdiff with git (pdf) – Git Latexdiff  — this is about using git together with latexdiff

Git and latexdiff: compare versions of LaTeX documents (pdf) — this is also about using git together with latexdiff