scm-latexdiff: a python script to calculate diffs for TeX files in git or mercurial repositories

When submitting a revision of an article, the editor often requests to include a document which shows what you changed in light of the comments of the reviewers. In Word you can use track changes to get this effect. To get a similar effect in LaTeX there is a tool called latexdiff. However, when using latexdiff in conjunction with a version control system like git, it takes quite a few manual steps to get a pdf with the difference between two versions of a file in the repository. A year or so ago I wrote a python script which takes of this hassle and could be used to create a diff pdf from a git repository.

A while later I switched to mainly using mercurial, so when the time came to create a diff based on a mercurial repo I decided to expand the script. In addition, I refactored the code to make it more clean. This lead to the python command line script scm-latexdiff. Here scm stands for software control management. The usage of scm-latexdiff is:

where:

some example usages:

Note that the NEW:FILE argument is optional, default NEW is ‘HEAD’ when using git, and ‘tip’ when using hg. When referring to a git revision, not the whole sha1 key is needed, you can just provide the first few numbers.

I developed scm-latexdiff for Linux, but it should work on any platform that supports Python, i.e. all. You can the latest version of this script from my bitbucket account:

After cloning the repository, you need to put the files into a directory present in the path. Although I prefer to create a symbolic link.

EDIT 24 Februari 2012:
Together with Ronald van Haren I’ve been updating scm-latexdiff. These updates are:

  • Support for multi-file Latex documents. This requires the latest version of Latexdiff.
  • Cleaner code
  • A python installer using distutils
  • A licence under which the software is released, GPL3
Tagged with: , , , ,
Posted in Python
4 Comments » for scm-latexdiff: a python script to calculate diffs for TeX files in git or mercurial repositories
  1. Ronald van Haren says:

    Hi Paul,

    Maybe you can update your blog post with the latest features we’ve added to scm-latexdiff.

    Cheers,
    Ronald

  2. Will Furnass says:

    A very useful tool, particularly given that it can handle child documents! Thanks for making this available to the masses.

    I was wondering do others have problems with line-wrapping when \DIFend{} or \DIFbegin{} contain \emph{<>}?

    • Paul Hiemstra says:

      Actually it is latexdiff which supports child documents, so kudos to them :). I can’t recall having this problem, but I cannot check right now. You could post a question on the stackexchange site for latex.

Leave a Reply

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

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">