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


and run latexdiff as

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

By Feng Li

Dr. Feng Li is an Associate Professor of Statistics in the School of Statistics and Mathematics at Central University of Finance and Economics in Beijing, China. Feng obtained his Ph.D. degree in Statistics from Stockholm University, Sweden in 2013. His research interests include Bayesian computation, econometrics and forecasting, and distributed learning. His recent research output appeared in statistics and forecasting journals such as the International Journal of Forecasting and Statistical Analysis and Data Mining, AI journals such as Expert Systems with Applications, and medical journals such as BMJ Open.


  1. 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/ 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 “”

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

      Thus, to use it, you need Perl support.

      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\, 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



    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!


Leave a comment

Your email address will not be published.