Track Changes With Latex

3 minute read

Published:

Track Changes with Latex

Overleaf has become a popular online latex editor for researchers. One of the advanges of Overleaf is that it can track all the changes like Word. It can also integrate with Git so that you can version control using Github. However, the drawback of using latex is that there is no convienient way to generate a tracked-changes version, especially for manuscript that contains images and references.

Here, I will show a workaround to export tracked-changes version uisng latexdiff and git-latexdiff.

Install Latex on Mac

Download MacTeX-2019 here, and follow the instructions to install.

Diff the tex files using latexdiff

  • Save the different versions of tex files to local computer
  • Using latexdiff and pdflatex on the command line
# generate diff version
latexdiff old.tex new.tex > diff.tex
# convert to pdf
pdflatex diff.tex
# generate .bbl file
bibtex diff # no file extension name
# rerun pdflatex twice to render figure ref and bibliography correctly
pdflatex diff.tex
pdflatex diff.tex 

Note:

  1. If exernal file such as SI.tex exists, need to run pdflatex first on these files.
$ pdflatex SI.tex
$ pdflatex SI.tex
  1. latexdiff has options for the visual markup styles such as UNDERLINE, CTRADITIONAL, TRADITIONAL, CFONT, FONTSTRIKE, CHANGEBAR. (see documentation and example)
latexdiff -t CTRADITIONAL old.tex new.tex > diff.tex
  1. To prevent prompt on errors, use the following flag. Also you can type Q to quit the interactive session.
pdflatex -interaction=nonstopmode diff.tex

Diff tex using git-latexdiff(recommended for Git)

Note source code on Gitlab, and this quick tutorial

install git-latexdiff

$ git clone https://gitlab.com/git-latexdiff/git-latexdiff.git
$ sudo make install

# if installation failed, do manual installation to move `git-latexdiff` into one of the PATH folder
$ cp git-latexdiff /usr/local/bin/.

diff command

# diff the changes in the previous commit 
git latexdiff --main manuscript.tex HEAD~1
# diff changes 2 commits back
git latexdiff --main manuscript.tex HEAD~2
# or use commit-hash
git latexdiff --main manuscript.tex c0b1428d8dc81dbe12bf28b17e83382df31c4200 HEAD

caveats

  • git latexdiff sometimes could not render the citation correctly, need to switch to latexdiff
  • latexdiff does not recognise the changes in figure if figure name is the same. Also it does not show the old vs new figure even if you have changed the name of the figure. It will just show the new figure in the diff.tex.
  • If you use bibtex, it is recommended to include the .bbl file in the version management.

bibliograph is not rendered correctly?

In this case, make sure you are using .bbl file instead of .bib file. To generate .bbl file, do the following:

# run pdflatex to generate .aux and .pdf file
$ pdflatex manuscript # e.g, manuscript is the main .tex file
$ bibtex manuscript # Do not add ".bib" extension
$ pdflatex manuscript #
$ pdflatex manuscript # yes, run twice to get the bib reference correctly rendered

For git latexdiff, try include .bbl file in git push? Otherwise the citation won’t render.

having external .tex file such as SupportingInformation.tex?

using pdflatex twice to make sure figures can be referenced correctly.

$ pdflatex SupportingInformation
$ pdflatex SupportingInformation

# make sure to run pdflatex on main tex again
$ pdflatex manuscript