I have run into a problem with the markup that latexdiff adds around \cite commands. The MWE below, which is supposed to have been generated by latexdiff, doesn't compile because LaTeX doesn't recognise the closing brace for \DIFdel:

ERROR: Extra }, or forgotten \endgroup.

The culprit is \hspace{0pt}: commenting this out prevents this error.

I have solved my immediate problem by manually deleting the string \hspace{0pt} from the difference file wherever it occurs, but obviously I'd rather not do this every time.

I have two questions: (1) why does LaTeX find a problem with the braces here in the first place, since they look matched to my human eyes (and to emacs!)? And (2) is there a way to prevent latexdiff from generating code that fails to compile in this way?

MWE for LaTeX (note that I've deleted most of the latexdiff preamble)



\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFdeltex}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE

\DIFdelbegin \DIFdel{Some text\mbox{%DIFAUXCMD
, and some more text.}


MWE for latexdiff




Some text \cite{reference}, and some more text.






latexdiff old.tex new.tex > diff.tex

  • 1
    I think the problem is not really the \hspace command, but rather an incompatibility of the packages/code added by latexdiff with the current LaTeX version. LaTeX underwent some internal changes recently. If you add \RequirePackage[2015/01/01]{latexrelease} as first line of diff.tex, then the file works as it is. – gernot Dec 9 '20 at 14:48
  • 1
    It seems to be the ulem package. Removing \sout makes the file compilable. – gernot Dec 9 '20 at 14:54
  • 1
    Many thanks @gernot; if you add that as an answer I'll happily accept it! In the actual document, I couldn't roll back because I need more recent features in amsmath, but your discovery that ulem is the thing to avoid means that I can just call latexdiff with -t CFONT (to avoid styles using ulem) and all is well. – Ant Dec 9 '20 at 16:34
  • 1
    Done. Keep me updated (e.g. in the comment section here or below the answer) about your experience with the workaround. Maybe we are on the wrong track and the error is caused by something else. – gernot Dec 9 '20 at 17:06
  • 1
    I had simillar issues as well. I think it is pretty neatly fixable by using lua-ul package. – Tomáš Kruliš Dec 10 '20 at 8:45

This year (2020) LaTeX underwent some internal changes that introduce incompatibilities with some packages. It seems that ulem.sty is one of them, with the current version ulem 2019/11/18 pre-dating the changes in the LaTeX format.

The differences file produced by latexdiff loads ulem.sty and uses the command \sout (strike out), which leads to the error.

\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\providecommand{\DIFdeltex}[1]{{\protect\color{red}\sout{#1}}} %DIF PREAMBLE

As a workaround, until the incomaptibility gets fixed, run latexdiff with the option -t CFONT, which avoids the use of \sout (proposed by @Ant in the comments).

Alternatively, add


as the first line in the differences file. This will set back the LaTeX format to a state that is compatible.

  • Somehow removing "\hspace{0pt}" generated by latexdiff fixed this issue for me, before I found this great answer. – Parham Jan 10 at 10:34
  • I will hang this answer over my desk....many thanks! – Kassem Feb 4 at 4:30
  • In my document \RequirePackage[2019/11/18]{latexrelease} caused LaTeX to hang. – Anonymous Physicist Feb 22 at 3:16
  • @AnonymousPhysicist Well, this is a non-normal behavior of latexrelease. If you care, post a question or file a bug report at https://github.com/latex3/latex2e/issues – gernot Feb 22 at 11:49

Germot already provided a good answer. However, it was not entirely satisfactory. The -t CFONT option changes the formatting (it only uses colour, removing strike-out and underlining). And while setting the latexrelease version to 2019/11/18 worked fine with OP's MWE, it failed in a more complex document.

So I sought to get rid of the real culprit, the \hspace{0pt}.

Since v1.0.1, latexdiff encloses citation (and a few other things such as siunitx commands) in \mbox commands in order to circumvent incompatibilities with ulem styling (the \sout and \uwave used by default). However, this implies that line breaks no longer work within citations. This was fixed in v1.2.1 by adding the \hspace{0pt} after the \mbox. The changelog states that “change should not cause adverse behaviour otherwise”. Well, now it does!

My temporary fix was to edit the latexdiff source (texmf-dist/scripts/latexdiff/latexdiff.pl), and replace the \hspace{0pt} with a \hskip0pt. The resulting PDF is identical to the one obtained with older versions.

tl; dr:

Find latexdiff.pl in your texlive installation directory¹, and replace line 2734²:

push(@$retval,"\\mbox{$AUXCMD\n\\" . $1 . $2 . $3 ."}\\hspace{0pt}$AUXCMD\n" );


push(@$retval,"\\mbox{$AUXCMD\n\\" . $1 . $2 . $3 ."}\\hskip0pt$AUXCMD\n" );

¹ E.g. /usr/share/texmf-dist/scripts/latexdiff/latexdiff.pl.
² Assuming you have latexdiff v1.3.1.1.

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.