264

I am writing a scientific paper with my collaborator. We have submitted a version to a journal and now we got a review from them, so we need to fix a few things. In Microsoft Word there is the option to "track changes", which displays the deleted text as crossed out and the new text bolded (if I remember the details correctly). Is there a way to achieve a similar result in LaTeX?

I was thinking to create a new file for the revised version and then write a script which would basically compare the two files and make the differences either bold or crossed out before sending it to latex. Is there a tool that already does it?

6
  • 17
    Well, there are always solutions. The key question is: do you need a solution which operates on PDF level? Or would you be satisfied with a diff-based solution (i.e. comparison of the .tex source files)? You could simply create a mercurial or git repo and commit your files - and get the history on source level for free. A solution which highlights changes in the PDF is much more difficult. What are your requirements? Aug 1, 2012 at 12:26
  • 2
    Mendeley (mendeley.com/features/read-and-annotate) allows communal pdf markup. You'd still have to write the changes to the LaTeX source, though. Aug 1, 2012 at 12:30
  • 2
    The changebar latex package has \begin{changebar}...\end{changebar} as well as a cross environment version \cbstart...\cbend. Also the framed latex package has \begin{leftbar}...\end{leftbar}. Aug 1, 2012 at 13:16
  • 2
    See also this question, this question, and this question
    – Scott H.
    Aug 1, 2012 at 20:16
  • 3
    latexdiff is one of a solution for your requirement...
    – MadyYuvi
    Oct 20, 2018 at 7:36

13 Answers 13

190
+500

You can process your TeX files with the Perl program latexdiff that is included with most LaTeX distributions.

From the manual:

Briefly, latexdiff is a utility program to aid in the management of revisions of latex documents. It compares two valid latex files, here called old.tex and new.tex, finds significant differences between them (i.e., ignoring the number of white spaces and position of line breaks), and adds special commands to highlight the differences.

3
  • That looks really useful. Now I just need to script it into my document build process, which has the added complexity that most of my project's documentation is actually written in Markdown and translated to LaTeX by pandoc. So the script would have to retrieve a past revision, translate it to LaTeX, translate the present revision to LaTeX, then run latexdiff. While it will be fussy to do, it is probably easier than using a diff of the Markdown source text to drive markup of the generated LaTeX.
    – RBerteig
    Aug 2, 2012 at 0:33
  • 6
    I found using latexdiff in combination with svn a killer solution. See also my earlier realted question (and answer) on this topic: tex.stackexchange.com/q/61405/2090 Aug 4, 2012 at 17:36
  • 7
    latexdiff is very complete and comes with many options: for instance, use the "--flatten" option if your document is divided into separate files (using \input or \include commands)
    – meduz
    Aug 8, 2012 at 12:36
180

I have used the changes package in the past and I find it very useful. It has a key=value system so most of the things are customizable. You can define different authors and the changes are tracked depending on the id; here is a simple example (mostly from the manual).

\documentclass{article}

\usepackage{changes}
\usepackage{lipsum}% <- For dummy text
\definechangesauthor[name={Per cusse}, color=orange]{per}
\setremarkmarkup{(#2)}


\begin{document}
\lipsum[1-7]

This is \added[id=per,remark={we need this}]{new} text.
This is \added[id=per,remark={has to be in it}]{new} text.
This is \deleted[id=per,remark=obsolete]{unnecessary}text.
This is \replaced[id=per]{nice}{bad} text.

This is \added[remark={we need this}]{new} text.
This is \added[remark={has to be in it}]{new} text.
This is \deleted[remark=obsolete]{unnecessary}text.
This is \replaced{nice}{bad} text.


\listofchanges
\end{document}

enter image description here

And the nice thing is that if you supply the final option to the package declaration that is \usepackage[final]{changes} it clears the traces of changes made by the authors and respecting the last changes. See the replaced and deleted text for an example.

enter image description here

19
  • 4
    This is unrelated to downvotes. I just want to understand how the changes package works. The Changes package gives you a way to manually annotate an existing document with changed, deleted, etc. Each individual changed part of the document needs to be manually identified and then manually annotated (by further changing the document)? Aug 1, 2012 at 18:55
  • 6
    @TrevorBoydSmith This is more suited to more than one authors, not necessarily heavy coders, such as me and my supervisor. For example, writing an article is a painful and kind of a unilateral process. My supervisor always wants to see what I did changed without reading the whole thing again etc. And he doesn't want to compile the whole thing etc. each time. So manually I plug in some changes and we discuss afterwards. I would really recommend the die-hard daily coders stay away from such stop and smell the flowers type of solution. But it's kind of indispensable for us.
    – percusse
    Aug 1, 2012 at 20:10
  • 5
    @percusse, I can definitely see it happening where there is a student writing a paper with an adviser. The student has lots of time and the advisor has very little time. The student can spend lots of time marking his document to show the changes... and then maximize the productivity with the adviser. (but definitely it looks like it would take a lot of work) Aug 2, 2012 at 12:38
  • 1
    @TrevorBoydSmith Not really actually! You embed these commands into macros so per comment, you type three letters and 2 brace pairs. I won't consider it as a lot. Besides the final version just cleans it which is perfect for me.
    – percusse
    Aug 2, 2012 at 22:02
  • 4
    @percusse, this is awesome! But what does \setremarkmarkup{(#2)} do? I get on error on that line (Undefined control sequence), but works nicely if I just remove that line.
    – Egalth
    Nov 15, 2018 at 13:39
58

Latex documents are plain text. Therefore you can handle tracking changes for Latex documents using the same robust methods that millions of software developers have been using for decades!

Short description of how software developers track changes in their source code:

  • keep the source in version control (git, svn, or whatever)
  • use differencing software to see what changes are made in between each revision (diff, vimdiff, Beyond Compare)

Here is a screenshot of what a diff program looks like (in this case this is a stock photo from Beyond Compare's website):

Beyond Compare Screenshot

(I actually don't use Beyond Compare. I prefer plain diff with vim which colorizes the diff.)

So whenever a change is made the change is saved in version control. And your version control keeps track of all changes. Allowing you to do things like: compare the two most recent versions, or compare the most recent with 5 versions back... or compare arbitrary version to arbitrary version. You have all the versions stored in version control!

11
  • 4
    @gt6989b, Yep I already saw the answer that talks about latexdiff (and I upvoted it). I decided to answer because latexdiff only allows you to diff between two versions... but does not help you keep track of the different versions. My answer focuses on both using diff AND keeping track of different versions. Aug 1, 2012 at 14:33
  • 5
    The problem with plain diff on latex files are the newlines. There are two ways people store tex files. Either having a single paragraph as a single line, or using a fixed line width. With the first changing a single character in a paragraph leads to marking the whole paragraph as changed in the diff which is useless. In the second mode some editors (e.g., vim paragraph autoformat) would potentially mark multiple (sometimes all) lines in the paragraph as changed as well. Diff-ing tex documents is not a trivial issue. And that was only about plain text, no tables or equations.
    – walkmanyi
    Aug 1, 2012 at 15:02
  • 2
    @walkmanyi Most diff programs have an option for ignoring white space. For GNU diff, you can use diff -w -B.
    – Aditya
    Aug 1, 2012 at 15:15
  • 4
    @Aditya: simply ignoring whitespace is not sufficient, because it still respects newlines: rewrapped text would still show up as multiple changed lines even if only on one line a word had been added. Better to use wdiff or a similar tool here. Aug 1, 2012 at 19:02
  • 2
    This solution has the advantage that changes to latex comments and non-text things like tikz code show up nicely in the diff. It also allows you to diff between arbitrary revisions (e.g., what have I changed in the last month?)
    – Neil G
    Aug 1, 2012 at 22:11
12

For completeness sake, Adobe Acrobat Professional offers an excellent tool to compare PDFs. That tool has been heavily revised for v9 and now works extremely well for all sorts of text, including tables, font changes etc.

Some advantages over latexdiff:

  • Can track changes in the bibliography
  • Changed text is "overlayed", not crossed out or underlined, allowing for a cleaner document.
  • All changes are stored as comments that can be exported.

Downside:

3
  • 2
    latexdiff tracks changes in the bibliography as long as you include it in your text (that is by including your bbl file if you use bibtex).
    – meduz
    Aug 8, 2012 at 12:34
  • 9
    diffpdf is a rather good open source alternative. Jun 10, 2013 at 7:31
  • Acrobat fails on larger, more complex PDFs (e.g., 49 page LaTeX generated PDF with images), in my experience. Dec 13, 2018 at 23:48
6

You can simply create two commands for marking added and deleted text and display them as you wish. LyX features a change tracking mechanism, which is implemented in the source like this:

\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}

\providecolor{added}{rgb}{0,0,1}
\providecolor{deleted}{rgb}{1,0,0}
%% Change tracking with ulem
\newcommand{\added}[1]{{\color{added}{}#1}}
\newcommand{\deleted}[1]{{\color{deleted}\sout{#1}}}

Whatever you mark with \added{...} will be displayed in blue and \deleted{...} in red and strikenthrough. If such a functionality would be just enough for you, in the final compilation of your document simply redefine \added to plain text passing and \deleted to be omitted. I.e., the following snippet should do:

\newcommand{\added}[1]{#1}
\newcommand{\deleted}[1]{}

Note, these are commands, so you cannot use that for too long text snippets. If your changes are more like blocks of text, take a look at the versions package at CTAN.

5

If you need to mark the changes in the \LaTeX source, the package http://trackchanges.sourceforge.net/TrackChanges is very helpful. It comes with a couple of python programs for globally accepting or rejecting changes as well.

1
  • 2
    Please explain the package. Link answers are discouraged on stackexchange sites. Oct 29, 2015 at 7:47
3

I created revdiff to build diff versions of my papers before sending them to reviewers. They have told me several times that the result was really helpful. Hope it can be useful for you.

Find it here

2

Most answers focus on one part of the question which is how to compare two versions of a document. The other part being how to keep track of changes in the document.

As it has been underlined by other answers, .tex files are actually plain text files containing the latex markup language. It can be handled using classical software development tools.

So for comparison of versions you can use diff tools.

And for keeping track of multiple versions you can use a Revision control software. I would recommend git or mercurial. Those software typically embed diff tools to check differences between various revisions of the document. The main advantage over a simple copy paste of the .tex file is that you can keep track of the whole history of the document: what changes you made 2 weeks ago ?

It is also great for multiple author writing as revision control software can keep track of who made what change as well as merge changes of automagically !

2

For the sake of completeness, the accepted answer to an even older, similar question on Stack Overflow mentions the package todonotes, which offers "MS Word-style" commenting, and more, for those reviewers who are comfortable enough to edit the actual LaTeX code. Haven't used it myself, but it looks pretty solid. The documentation is updated as of July 2018, and provides nice examples.

1
  • 3
    Downvoting without comment is not helpful.
    – Egalth
    Sep 27, 2019 at 17:51
1

If you use pdflatex, there is an Acrobat (Professional) function to compare two PDFs. For a high-level overview on the major differences, it works surprisingly well IMHO.

1

Maybe this is not a direct answer to your question, but I still suggest you try my package debate. It helps you organize a discussion between reviewers inside your document:

\documentclass{article}
\usepackage{debate}
\begin{document}
I think apples are tastier
  \debate[jeff]{I don't think it's true!}
  \debate[anna]{It is indeed true!}
than pears!
\end{document}

When you are ready to make them all invisible, just use \usepackage[hide]{debate}

1

You can also use the trackchanges package (link), which is very straightforward to use. The only thing to do is adding the trackchanges.sty file in the root of the LaTeX project and start adding your changes:

...
\usepackage[margins]{trackchanges}
...

\addeditor{sampleEditor}

My text \add[sampleEditor]{new text}.
My text \remove[sampleEditor]{removed text}.

0

I think unfortunately there is no way to work with an advisor that knows latex but that likes MS Word track-changes option so much that you need to pass him directly the pure latex .tex file and he works with word on it...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .