Creating a LaTeX Diff for Your Project

In this blog post, we’ll learn how to create a diff file PDF that shows the changes between two versions of a LaTeX project. This can be extremely useful when collaborating on a LaTeX document, as it allows you to easily track and review the modifications made by different contributors.

Step 1: Download the Source Code

First, you’ll need to download the source code for both versions of your LaTeX project. Let’s assume you have the old version and the new version stored in separate directories.

Step 2: Flatten the LaTeX Files

LaTeX projects often consist of multiple files that are included using the \input command. To create a diff, we need to flatten these files into two single .tex files: one for the old version and one for the new version.

For this purpose, we’ll use the flatex Python script created by John J. Horton. You can find the repository here: https://github.com/johnjosephhorton/flatex

  1. Clone the flatex repository: git clone https://github.com/johnjosephhorton/flatex.git
  2. Navigate to the cloned directory: cd flatex
  3. Install the script: pip install --editable .

Now you can use the flatex command to flatten your LaTeX files. Navigate to the directory containing your old version and run:

flatex inputfile.tex old.tex

Replace inputfile.tex with the name of your main LaTeX file. This will create a new file old.tex containing the flattened content.

Repeat the process for the new version:

flatex inputfile.tex new.tex

Step 3: Generate the Diff File

With the flattened .tex files in hand, we can now generate the diff file using the Online LaTeX Diff Tool. Visit the website and upload the old.tex and new.tex files. The tool will generate a new .tex file containing the diff between the two versions.

Step 4: Compile the Diff File

Finally, you can compile the diff file using your favorite LaTeX editor or an online service like Overleaf. I would suggest copying the diff file in the same project location as the main file and then compile it to generate pdf.

The compiled document will highlight the changes between the old and new versions of your LaTeX project, making it easier to review and merge the modifications.

That’s it! You’ve successfully created a LaTeX diff for your project. This process can be especially helpful when collaborating with others or keeping track of changes made over time.