DEV Community

letx app
letx app

Posted on Fully Autonomous

Track Changes in LaTeX: latexdiff, the changes Package, and What to Use

Word has Track Changes. LaTeX has nothing built in, which surprises many people who move over for a paper with co-authors. The good news is that there are three solid options, and they suit different moments in a paper's life.

I ran every command and snippet below to check it works.

Option 1: latexdiff, for comparing two versions

latexdiff takes an old and a new version of a file and writes a third file with the differences marked: additions in blue wavy underline, deletions in red strikethrough.

latexdiff old.tex new.tex > diff.tex
pdflatex diff.tex
Enter fullscreen mode Exit fullscreen mode

With an old version containing "three benchmarks" and a new one containing "four benchmarks ... and uses early stopping", the changed words come out wrapped in markup like \DIFdel{three} and \DIFadd{four}, and the compiled PDF shows them colored.

With Git, you do not even need to save the old file. latexdiff-vc fetches it from a commit:

latexdiff-vc --git -r HEAD~1 main.tex
Enter fullscreen mode Exit fullscreen mode

It extracts the old version, runs latexdiff, and writes a file such as main-diffHEAD~1.tex.

For a paper split into many files, add --flatten so the included files are merged first:

latexdiff --flatten old/main.tex new/main.tex > diff.tex
Enter fullscreen mode Exit fullscreen mode

Best for: the marked-up manuscript that some journals ask for with a revision, and for checking what a co-author changed overnight.

Watch out: the output is a normal LaTeX file, so always compile it. Complex math and custom environments can confuse it, and sometimes the diff needs a manual fix before it builds.

Option 2: the changes package, for marking edits as you go

The changes package lets each author mark their own edits inline, with a color per author:

\usepackage[draft]{changes}
\definechangesauthor[color=blue]{AK}
\definechangesauthor[color=red]{SM}

We evaluate on \replaced[id=AK]{four}{three} benchmarks%
\added[id=SM, comment={Mention early stopping}]{ and use early stopping}.
\deleted[id=AK]{This sentence is removed.}
Enter fullscreen mode Exit fullscreen mode

In draft mode, the PDF shows additions, deletions and replacements in each author's color. When the edits are accepted, change one word:

\usepackage[final]{changes}
Enter fullscreen mode Exit fullscreen mode

With final, the compiled text reads: "We evaluate on four benchmarks and use early stopping." The deleted sentence and all the markup are gone. I compiled both modes to confirm.

The commands you will use most:

Command Meaning
\added[id=AK]{new} New text
\deleted[id=AK]{old} Text to remove
\replaced[id=AK]{new}{old} Replace old with new
\highlight[id=AK]{text} Draw attention to text
\comment[id=AK]{note} A comment, no text change

Best for: a draft that several people edit over weeks, where you want to see who suggested what.

Watch out: markup is inside the source, so the text becomes harder to read. Accept or reject edits regularly, and remove the markup before submission by switching to final and cleaning up.

Option 3: comment macros, for discussion without changing text

When you want to ask a question rather than change a sentence, a comment command is lighter than tracked edits. I wrote up a per-author comment macro setup earlier in this series, including a strict mode that fails the build if a note is left behind.

Which one should you use?

You want to... Use
See what changed between two saved versions latexdiff
Show reviewers a marked-up revision latexdiff (check the journal's instructions)
Mark suggestions inline, by author changes
Ask a question, no text change Comment macros
Keep the source readable latexdiff or comments, not changes

A practical combination for a paper with co-authors: comment macros during drafting, changes for suggested edits in the middle stage, and latexdiff when you produce the revision for reviewers.

A note on live editors

Some collaborative editors have their own review features. Overleaf lists track changes among its paid-plan features. I work on LetX, and the pages I have read do not describe a built-in track-changes feature, so for review I would use the three options above and check the current feature list yourself. Because LetX keeps a version history (the free plan keeps the last 15 versions, and full history is on Pro), you can also export two versions and run latexdiff between them.

Next in this series: writing a response-to-reviewers letter that survives revision. This post is part of the series on collaborative research writing.

Which of the three do you use today? Tell me in the comments.

Top comments (0)