At work, we use Subversion (yes, I know) for version control of the LaTeX sources of the papers we write. One of the nice things about version control is the possibility of viewing diffs, which is really useful when collaborating on text. However, LaTeX sources often have very long lines, which makes it hard to spot differences in the usual line-based diff. For viewing word-based differences, there is wdiff instead. To use colors for marking added and removed words, Prof. Iain Murray has published a cwdiff shell script in 2011.

I have adapted that shell script a bit. First, tput setf didn’t work on my system, so I replaced it with tput setaf. Next, the script now marks additions and removals only with colors. Third, I played around with the color choices a bit until they looked good in my solarized color scheme. Finally, the script compares the files given in $6 and $7, which allows using it directly as svns diff-cmd.

The complete shell script is below:

diffnew=$(tput setaf 7)$(tput bold)
diffold=$(tput setaf 1)$(tput bold)
reset=$(tput op)$(tput sgr0)

wdiff \
    --start-delete "${diffold}" \
    --end-delete "${reset}" \
    --start-insert "${diffnew}" \
    --end-insert "${reset}" \
    -n "$6" "$7" \
    | grep -C2 '\[' \
    | less

I recommend that you read the well-documented original script for more background.