I want to compare two different tex files, say old.tex and new.tex, by just yellow highlighting the different places in the new.tex automatically.

I tried two ways but not exactly what I want.

  1. Use package soul and command \hl in new.tex. This is ok but it is a manual process and very time-consuming.
  2. Run latexdiff old.tex new.tex > diff.tex in the PowerShell, and then compile diff.tex in LaTex. This is automatical, but would highlight the diffrent places in both old.tex and new.tex (contain delete and add notations). Besides, it is not yellow highlight.

Really hope someone can help me, thanks very much in advance.

1 Answer 1


Let's suppose you have these two files, respectively old.tex and new.tex:

    This is the old document.

    This an old line.

    We will remove this line.


    This is the new document.

    Esta es una nueva línea.

If you run latexdiff old.tex new.tex > differences.tex you will have a file which once compiled gives you:

enter image description here

Ok, now open the new file. Around the beginning of it, you'll find:

\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE

The two commands that mark the "new" text and the "deleted" text are \DIFadd and \DIFdel. Change them to this:

\providecommand{\DIFadd}[1]{{\protect\hl{#1}}} %highlight
\providecommand{\DIFdel}[1]{}                  %do not show deleted

Then compile it, you'll have:

enter image description here

Notice a couple of things:

  1. I use soulutf8 because of this: French accents in \hl from soul package
  2. latexdiff has a very complex task to do, and it's not 100% reliable or easy to use; but in plain things it works quite well.
  3. I have no idea on how \hl will work on large texts or figure or paragraphs...
  • 1
    Note that If you need to do this repeatedly you can bypass the manual edit by using the --preamble option of latexdiff. Copying all the commands inserted by latexdiff into a separate file, make the change suggested by @Rmano and then include through the --preamble option
    – frederik
    Feb 20, 2021 at 0:09
  • Thank you very much for your help!
    – Doris
    Feb 20, 2021 at 9:26
  • It is skipping after converting pdflatex, please help.
    – HQuser
    Apr 16, 2022 at 13:21
  • @HQuser --- I can't understand your comment, sorry. If you have a problem, please prepare a new question with a complete and simple example (similar to the ones I posted here). Then, if you want, you can add a comment here so that I will see the new question.
    – Rmano
    Apr 16, 2022 at 21:34
  • 1
    soulutf8 was a very handy suggestion, there are a couple cases it throws errors: - when DIFadd{} includes \ref or \textsubscript - in the equation environment I did not mind manually edit them out, it does ok even with a very complex document. Jul 22, 2022 at 14:34

You must log in to answer this question.

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