The last few times I have tried to install git-latexdiff (both on OSX and Ubuntu), I have run into issues.

Eventually, it has turned out that there is a problem with the latexdiff installation. This post aims to walk the user through setting up latexdiff manually - don't worry, it is actually quite easy.

This post is aimed at both OSX and Linux users.

The problem

The excellent program latexdiff seems to come pre-installed with Ubuntu (and maybe OSX). In a terminal, try the following:

latexdiff -V

If you see any kind of error, for example::

Unescaped left brace in regex is deprecated...
Unescaped left brace in regex is deprecated...
Unescaped left brace in regex is deprecated...

Then, there is a problem. However, if you see something like:

This is LATEXDIFF 1.1.1  (Algorithm::Diff 1.15 so, Perl v5.18.2)
    (c) 2004-2015 F J Tilmann
Preamble Internal Type UNDERLINE
Preamble Internal Type SAFE
Preamble Internal Type FLOATSAFE
2 and only 2 non-option arguments required.  Write latexdiff -h to get help

then that is better. But, experience has shown that we actually need to test latexdiff with a minimal example.

Check latexdiff with a minimal example

We can use the files from the previous post. The following lines create a temporary folder, and download those example tex files.

mkdir -p ~/Documents/test_latexdiff
cd ~/Documents/test_latexdiff

Now that you have the files, you can try running the latexdiff command:

latexdiff version1.tex version2.tex > diff.tex

If you don't see any output, and a file diff.tex is created (check with ls), then everything is working. Great!

However, if you see an error message such as the following:

Can't locate Algorithm/ in @INC (you may need to install the Algorithm::Diff module) (@INC contains: /usr/local/Cellar/perl/5.26.1/lib/perl5/site_perl/5.26.1/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.1/lib/perl5/site_perl/5.26.1 /usr/local/Cellar/perl/5.26.1/lib/perl5/5.26.1/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.1/lib/perl5/5.26.1 /usr/local/lib/perl5/site_perl/5.26.1/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.26.1) at /Users/dean/build/latexdiff/latexdiff line 154.
BEGIN failed--compilation aborted at /Users/dean/build/latexdiff/latexdiff line 154.

then this basically means that latexdiff is not managing to connect to the Perl Diff algorithm. Rather than trying to fix the connection, we will manually install latexdiff again. Don't worry, it is very easy.

Manually installing latexdiff

The developer, F. Tilmann, is still actively developing latexdiff. In the latest version on the official CTAN page (June 2017), he recommended that the standalone version of latexdiff be used, because it already contains the Algorithm::Diff Perl package, and so there is no need to worry about linking to Perl on your OS.

Follow the following steps (described in the README, but fortunately expanded upon here:

  1. Go to the latexdiff CTAN page.
  2. Click the Download link in the top-right corner, and save it to ~/Downloads.
  3. If the zip file does not unzip automatically (OSX), then unzip it manually. You should have the folder ~/Downloads/latexdiff.
  4. Move to the build directory:
  5. mkdir -p ~/build && cd ~/build
  6. Copy the latexdiff folder to the ~/builddirectory
  7. cp -r ~/Downloads/latexdiff ~/build
  8. Move into the latexdiff directory:
    cd ~/build/latexdiff
  9. Copy the manual files (extension .1) into the relevant directory. The creator of latexdiff recommends:
  10. cp latexdiff.1 latexrevise.1 latexdiff-vc.1 /usr/local/share/man/man1
  11. You might need to use sudo cp rather than cp, but the folder /usr/local/share/man/man1 should already exist and contain loads of manual files.
  12. (Not sure this is strictly necessary, but worth doing again.) Make sure the latexdiff-so file executable:
    sudo chmod a+x latexdiff-so
  13. Almost there. Now just need to add an alias for latexdiff to our ~/.bash_profile (OSX) or ~/.bashrc (Linux) file:
  14. On OSX:

    echo "# alias for latexdiff. Using standalone version: " >> ~/.bash_profile
    echo "alias latexdiff='~/build/latexdiff/latexdiff-so' " >> ~/.bash_profile

    On Linux:
    echo "# alias for latexdiff. Using standalone version: " >> ~/.bashrc
    echo "alias latexdiff='~/build/latexdiff/latexdiff-so' " >> ~/.bashrc

That should be it.

Check it is now working

First check that your alias is working. In the terminal:

type latexdiff

and you should see:

latexdiff is aliased to `/Users/dean/build/latexdiff/latexdiff-so'

Now move back to your folder for testing latexdiff and try it out again:

cd ~/Documents/test_latexdiff
latexdiff version1.tex version2.tex > diff.tex

If there is no output, and the file diff.tex is created, it is working!