19

I would like to highlight changes between two versions of a LaTeX document.

I have both my versions in git. Is there an easy way of generating a output document where all changes are highlighted. So the highlighting should be in the output and not in the source.

The whole purpose is to indicate for my supervisor which changes I made so that he can review and approve them quickly.

  • 3
    Seems like a duplicate of (part of) this question. – TH. Oct 4 '10 at 8:01
  • 1
    @TH., not really. Showing differences between two versions and version control in general are two different things. At least both can be used without the other. – Martin Scharrer Jun 22 '11 at 13:17
  • @Martin: Both questions are about using version control in conjunction with LaTeX. In particular displaying differences. "Also, it might be nice to get a PDF showing what was added and removed in a given revision." The answers to that question (and comments to the answers) answer this one as well. Although, as this question is 7 months old and has been answered, I'm not sure why you're bothering to disagree with my comment. – TH. Jun 23 '11 at 3:09
  • 1
    related: Using latexdiff with git – Tobias Kienzler Sep 21 '11 at 13:12
12

  Rewritten answer

Because of the regular structure of typical Latex documents, it's feasible to write a diff-like program that looks at the two Latex source files and creates a compilable Latex diff output where additions and deletions are delineated using macros. With the appropriate macro definitions, you can make these appear as appropriate markup (inline, with changebars) in the compiled diff document.

There are two programs I know of on CTAN that do this, both of which are Perl scripts:

  1. latexdiff, which is the more widely used, and has support for automatic revision acceptance and version control;
  2. texdiff, my preference, which is less sophisticated and I find more predictable. texdiff doesn't try to insert Latex code into the preamble, which means you have to do this yourself, but which means it is more convenient for multifile documents, and for when you want to handle the insert/delete markup yourself.
  • 4
    Can you please give reasons why to use it, or a 2 line introduction how to use it? – Peter Smit Oct 4 '10 at 12:58
  • Just to be clear, the current version of my answer is rewritten in light of @PeterSmit´s comment above. – Charles Stewart Jan 9 '15 at 18:38
  • You can try latexdiff online here: 3142.nl/latex-diff – Alessandro Cuttin Nov 18 '16 at 17:02
7

A less automated way with respect to texdiff is changebar. Use in this way:

...some text
\cbstart
the text you modified
\cbend
some text...
\cbdelete %to be put where some text have been deleted

from \cbstart to \cbend a grey bar is displayed near the text. \cbdelete will display a little grey square instead.

  • 1
    Oh, this is great! I have been meaning to look up if there is a package that does exactly this. You pre-empted my asking. – Willie Wong Oct 4 '10 at 17:42
  • 1
    This package does not seem to work with revtex templates. The commands are processed without error but changebars never show up. I then used the changes package instead. Anyway, still like your suggestion. – engineer Nov 16 '16 at 7:16
4

Latexdiff is a nice perl script for this purpose.

1

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 helpfull. Hope it can be useful for you.

Find it here: http://pedromateo.github.io/revdiff-LaTeX/

  • Welcome to TeX.SX! This seems interesting, but you should add some more information besides the link. A small example of code would do. – egreg Apr 28 '16 at 11:02
0

wdiff, like this:

wdiff -w "\fbox{" -x "}" -y "\fbox{\fbox{" -z "}}" ...

  • What does this exactly do? – Peter Smit Oct 4 '10 at 17:19
  • 2
    It puts a box around the words that you deleted, and a double-box around the words you added. But this doesn't work completely well with latex when there are commands involved in the changes, as then the braces may not pair up correctly. See also the documentation for texdiff that Charles mentioned earlier. – Willie Wong Oct 4 '10 at 17:45
  • if you don't like the box and double box, you can always change \fbox in the above command to something like \colorbox and have it put a colored box around it instead. – Mica Oct 4 '10 at 19:50
  • latexdiff and texdiff handle word differences but are TeX-aware. – András Salamon Oct 6 '10 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.