latexdiff with git

The program latexdiff is a simple program that can compare the changes of two versions of TeX files and generate a new TeX file with highlights of the changes. The program is shipped with most tex distributions.

There is a lot discussions on how to integrate latexdiff with version control systems like git. If you have your tex documents git-controlled. You want to check the change of two revisions visually (not the standard git-diff for text files but you want see the difference in a pdf file for two tex files). For sophisticated solution integrating with git, you may consider using  git-latexdiff.

A simple solution is to run the command

latexdiff <(git show oldcommit:file.tex) file.tex > diff.tex

and then simply run e.g.

pdflatex -interaction=nonstopmode diff.tex

to see the changes in diff.pdf.

UPDATE: If you run into troubles that some tex environments (e.g. tables) do not diff properly with latexdiff, you could provide a custmized config file. e.g. ld.cfg containing the following information

PICTUREENV=(?:picture|DIFnomarkup|table)[\w\d@]

and run latexdiff as

latexdiff -c ld.cfg <(git show oldcommit:file.tex) file.tex > diff.tex

Comments

4 responses to “latexdiff with git”

  1. Zoltan Csati Avatar
    Zoltan Csati

    I use git under Windows. latexdiff works well, but inside the git prompt I cannot use latexdiff as it returns the error
    Can’t locate Algorithm/Diff.pm in @INC (you may need to install the Algorithm::Diff module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at C:\Programok\MiKTeX 2.9\scripts\latexdiff\latexdiff line 124.
    BEGIN failed–compilation aborted at C:\Programok\MiKTeX 2.9\scripts\latexdiff\latexdiff line 124.

    Why can’t I use latexdiff in git?

    Thank you

    1. I am not a Window user. So I can not answer your question directly. According to the error message “you may need to install the Algorithm::Diff module” I guess you need “http://search.cpan.org/~tyemq/Algorithm-Diff-1.1903/lib/Algorithm/Diff.pm”

    2. Latexdiff is in fact a Perl script, and leverages the Perl package “Algorithm-Diff”

      Thus, to use it, you need Perl support.
      https://www.perl.org/get.html

      If the error messages appear again.

      You should tell BASH terminal to find the Perl scripts correctly, typing the following command in BASH terminal,
      export PATH=”C:\Perl64\bin:$PATH”
      to set the environment variable for current process, or adding the following lines
      # Add PDF Viewer (just an example)
      export PDFVIEWER=”C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe”

      # Add Perl
      export PATH=”C:\Perl64\bin:$PATH”

      into file C:\Program Files\Git\etc\profile.d\env.sh, to set the environment variable permanently.

      I recommend you to use git-latex.
      To compare current version to the version 8 commits back, as simple as,
      git latexdiff HEAD~8

      Regards

      Y

    3. BTW,
      Makesure you have installed.
      It should be shipped with the latest Perl Windows Release

      You can goto Perl package manager to check/install it.
      Active 5.24.0 Build 2400 -> Perl Package manager

      Good luck!

      Y

Leave a Reply

Your email address will not be published. Required fields are marked *