跳到内容

Author: ShareLaTeX team (February 2013)

Note: This article was originally published on the ShareLateX blog in February 2013 and describes locally installing and using a Perl script called latexdiff. It is reproduced here for the benefit of readers who may be interested to use latexdiff on their own local computing device.

Lately, we have been working on TeX projects that involve a few collaborators. It can be hard to keep track of all the changes the contributors make because it's easy to miss a few changed words in text-heavy document. We were hoping to find a feature in TeX similar to "Track changes" found in Microsoft Word. latexdiff was the solution to our problems.

latexdiff is an invaluable utility that makes it easy to markup and view changes made to the document. It definitely reduced my burden of having to read through two files simultaneously where it would be easy to overlook subtle changes like word substitutions and changing numbers or signs in an equation.

Acquiring latexdiff

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

If you are a Windows user you will have to go through the following setup to get latexdiff working on your machine:

  1. install Perl: download from here;
  2. download latexdiff from CTAN;
  3. unzip the latexdiff files and copy them to the Perl > bin folder (default installation in C: drive);
  4. enjoy latexdiff!

Mac OS X includes an installation of Perl and no additional setup is required. latexdiff can be found in any CTAN repository in TeX Live Utility.

Usage

To compare two documents simply run latexdiff in the command line like so:

latexdiff draft.tex revision.tex > diff.tex

where draft.tex and revision.tex are original and changed versions of your document, and diff.tex is where the markup is stored. The above command provides latexdiff with the two comparison files and the filename for the resulting marked .tex file. If the two input files you provide are valid .tex files, the resulting diff.tex will also be a .tex file. This marked file can now be compiled with your choice of TeX compiler (pdfLaTeX etc.).

Out of the box, any removed words are crossed out with a single line and colored red, whereas any added words are underlined with a squiggle and colored blue. When equations are changed, additions are marked with a blue font and removals are marked with a red.

Example output

We compared two documents with default latexdiff settings, and were very impressed with the results:

Default-format-latexdiff.png

Unlike Microsoft Word, where the changes are simply highlighted and the notes are off to the side, all changes are clearly marked where they happen!

For those of you who do not want a cluttered document with lots of strikethrough text, the CTRADITIONAL option is way to go. Simply specify the option to latexdiff:

latexdiff -t CTRADITIONAL draft.tex revision.tex > diff.tex

All the deleted text appear as footnotes and added text appear in blue.

Changes-in-footer-latexdiff.png

latexdiff options

You can include various to suit your needs for a visual markup style. Some options, taken from the documentation, include:

  • UNDERLINE—added text is wavy-underlined and blue, discarded text is struck out and red;
  • CTRADITIONAL—added text is blue and set in sans-serif, and a red footnote is created for each discarded piece of text;
  • TRADITIONAL—like CTRADITIONAL but without the use of colour;
  • CFONT—added text is blue and set in sans-serif, and discarded text is red and very small size;
  • FONTSTRIKE—added text is set in sans-serif, discarded text small and struck out;
  • CHANGEBAR—added text is blue, and discarded text is red. Additionally, the changed text is marked with a bar in the margin.

For more information on latexdiff check out the official documentation.

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX