Home > best practices > Using latexdiff to Highlight Revisions in a LaTeX Project

Using latexdiff to Highlight Revisions in a LaTeX Project

Typically research papers are put together as LaTeX projects. I was under the impression that it is a challenge to keep a visual track of who made what changes; typically there are more than one authors on the paper and we try to learn from the experienced writers. But then I came across a useful tool, latexdiff, which opened the door for many possibilities.

What latexdiff does is that it highlights, in color, the differences between two LaTeX files. Consider a trivial example below. Latexdiff compares the two LaTeX files (original.tex and revised.tex) and generates a LaTeX file as output (diff.tex), which can then be compiled into pdf to view the output.

latexdiff original.tex revised.tex > diff.tex
pdflatex diff.tex

An example is shown below, where red color highlights the text that was deleted and blue color highlights the text that was added.

latexdiff example output

When collaborating, the LaTeX project includes multiple files that are pulled into the primary LaTeX file. This can be done using the flatten option.

latexdiff --flatten original.tex revised.tex > diff.tex

I’ll leave it to you to explore the documentation for other possibilities.

The tool can also be used along with version control systems (e.g., svn). Below is a crude bash script that pulls an old version from the svn repository and compares it to the version in your working directory.

#!/bin/bash 
# Version: 0.01
# Author:  Umar Kalim

if [ $# -ne 2 ] ; then
  echo "Usage: $0 <svn revision no.> <filename>"
  exit 1
fi

svn_revno=$1
filename=$2

mkdir tmp
echo "exporting svn repo $svn_revno"
svn export --force -r $svn_revno . tmp

echo "generating diff"
latexdiff --flatten tmp/$filename $filename > diff.tex

echo "compiling output with highlights"
pdflatex diff.tex

echo "cleanup"
rm -rf tmp
Advertisements
Categories: best practices Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: