Tracking revisions with latexdiff and latexpand

This post details the setup and use of latexdiff and latexpand for tracking revisions in \(\LaTeX\) documents. Revisions are tracked by first flattening \(\LaTeX\) documents (with chapters, a reference section, etc.) into a single .tex file, and then comparing the differences between an old.tex file to a new.tex file. Let me know if you notice a typo or have suggestions in the comments below.

Getting started

Since latexdiff is a Perl script, you will need Perl to run it:

  1. Download and install the Perl programming language. Strawberry Perl works well on Windows. Mac OS X comes with an installation of Perl.

  • You can check if you are running on a 64 or 32 bit processor by navigating to Windows Settings -> System -> About

  1. Download latexdiff from CTAN.
  • Unzip the latexdiff files and copy them to a C:\Strawberry\perl\bin\latexdiff folder.
  1. Download latexpand also from CTAN (if you don’t already have it). latexpand comes with TexLive and MikTex.
  • I prefer to use the TexMaker \(\LaTeX\) editor which comes with MikTex. Hence, I simply checked that I had latexpand with the package manager.

  1. You’re ready to go!

Using latexdiff and latexpand

Now that you have both latexdiff and latexpand use the below steps to track changes to a \(\LaTeX\) document. This process assumes you have the following folder structure on your machine:

  1. Copy the most recent version’s folder (with all of its interior files), and rename it with today’s date.

  1. Rename the new .tex file with today’s date, and delete all other auxiliary files with the old date.

  1. Make changes to the new .tex files (e.g., thesis_7_20_2020.tex, your_bibliography.bib, etc.) and save them.

  2. Update the old and new .tex file names with the appropriate dates in the following code, and run it in the Perl command line (you can copy and paste it all at once).

cd C:\Users\YourName\Documents\Thesis\Thesis_7_19_2020

latexpand --expand-bbl Thesis_7_19_2020.bbl Thesis_7_19_2020.tex > Thesis_7_19_2020_flattened.tex

cd ..\Thesis_7_20_2020

latexpand --expand-bbl Thesis_7_20_2020.bbl Thesis_7_20_2020.tex > Thesis_7_20_2020_flattened.tex

latexdiff ..\Thesis_7_19_2020\Thesis_7_19_2020_flattened.tex Thesis_7_20_2020_flattened.tex > Thesis_7_20_2020_diff.tex
  1. Compile the diff.tex document in your \(\LaTeX\) editor to obtain a latexdiff pdf of your work.

Cheers!

Eric McKinney
Eric McKinney
Artificial Intelligence Engineer

My research interests include computational statistics, bolide detection, and knowledge sharing.