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
Install Latex on Mac
MacTeX-2019 here, and follow the instructions to install.
Diff the tex files using
- Save the different versions of tex files to local computer
pdflatexon 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
- If exernal file such as
SI.texexists, need to run
pdflatexfirst on these files.
$ pdflatex SI.tex $ pdflatex SI.tex
latexdiffhas 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
- To prevent prompt on errors, use the following flag. Also you can type
Qto quit the interactive session.
pdflatex -interaction=nonstopmode diff.tex
Diff tex using
$ 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 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
git latexdiffsometimes could not render the citation correctly, need to switch to
latexdiffdoes 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
- If you use bibtex, it is recommended to include the
.bblfile 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
git latexdiff, try include
.bbl file in git push? Otherwise the citation won’t render.
having external .tex file such as SupportingInformation.tex?
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