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.
- 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
- Download latexdiff from CTAN.
- Unzip the latexdiff files and copy them to a C:\Strawberry\perl\bin\latexdiff folder.
- 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.
- 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:
- Copy the most recent version’s folder (with all of its interior files), and rename it with today’s date.
- Rename the new .tex file with today’s date, and delete all other auxiliary files with the old date.
Make changes to the new .tex files (e.g., thesis_7_20_2020.tex, your_bibliography.bib, etc.) and save them.
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
- Compile the diff.tex document in your \(\LaTeX\) editor to obtain a latexdiff pdf of your work.