1

In some cases, the file produced by latexdiff will contain multiply-defined labels, which may cause compile error. Below is an example:

old.tex

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Two remarks on the marvelous formula. 

\begin{equation}\label{eq:mass_energy}
    E = mc^2
\end{equation}
\end{document}

new.tex

\documentclass{article}
\usepackage{amsmath}
\usepackage{theorem}
\newtheorem{theorem}{Theorem}
\begin{document}

\begin{theorem}\label{thm:mass}
We have 
    \begin{equation}\label{eq:mass_energy}
        E = mc^2
    \end{equation}   
\end{theorem}

Two remarks on the marvelous formula. 
\end{document}

diff.tex

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL old.tex   Sun Dec 20 16:19:03 2020
%DIF ADD new.tex   Sun Dec 20 16:21:10 2020
\usepackage{amsmath}
\usepackage{theorem} %DIF > 
\newtheorem{theorem}{Theorem} %DIF > 
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFmodbegin}{} %DIF PREAMBLE
\providecommand{\DIFmodend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF LISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
  moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
    language=DIFcode, %DIF PREAMBLE
    basicstyle=\ttfamily, %DIF PREAMBLE
    columns=fullflexible, %DIF PREAMBLE
    keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}
\DIFaddbegin 

\begin{theorem}\label{thm:mass}
\DIFadd{We have 
    }\begin{equation}\DIFadd{\label{eq:mass_energy}
        E = mc^2
    }\end{equation}   
\end{theorem}

\DIFaddend Two remarks on the marvelous formula. 
 \DIFdelbegin %DIFDELCMD < 

%DIFDELCMD < %%%
\begin{displaymath}\DIFdel{\label{eq:mass_energy}
    E = mc^2
}\end{displaymath}%DIFAUXCMD
%DIFDELCMD <  %%%
\DIFdelend\end{document}

As you can see, the problem is that \label is included in the scope of \DIFdel. I tried to add the option --exclude-safecmd=label as suggested here, but it doesn't help. How can I avoid this issue?

Update

I am using the command

latexdiff old.tex new.tex > diff.tex

with LATEXDIFF 1.3.1.1 (Algorithm::Diff 1.15 so, Perl v5.30.1).

3
  • diff.tex (I omitted the preambles) that makes it harder to test any answer Dec 20, 2020 at 12:26
  • Consider upvoting and/or accepting the provided answer if it helped. According to your comments, this is apparently the case :) Dec 21, 2020 at 4:12
  • @Manuel Ah thanks for the reminder! I just upvoted the answer. I guess I will wait some more time to see if someone may come up with a better solution :)
    – Ray30
    Dec 21, 2020 at 8:54

1 Answer 1

1

Your diff file is incomplete and if I run latex diff old.tex new.texI get a different format which does not error, so hard to test but I assume that if your preampbe has

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

You could change that to

\providecommand{\DIFdel}[1]{{\def\label##1{}\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE

to disable lables in deleted regions.

3
  • Thanks for your answer! I edited the question to include the preamble and the version of latexdiff I used. A maybe silly question, but is latex diff the same as latexdiff?
    – Ray30
    Dec 21, 2020 at 2:24
  • Also, this workaround does work perfectly. Still, I am curious if it is possible to avoid this altogether by setting some option in latexdiff.
    – Ray30
    Dec 21, 2020 at 2:28
  • @Ray30 possibly, I have no idea, I think this is fist time I used it:-) Dec 23, 2020 at 15:31

You must log in to answer this question.

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