ftilmann / latexdiff

Compares two latex files and marks up significant differences between them. Releases on www.ctan.org and mirrors
GNU General Public License v3.0
506 stars 72 forks source link

`\protect` weird error #284

Open tdegeus opened 12 months ago

tdegeus commented 12 months ago

I have a compiler error for a code that I have been able to minimise to:

a.tex

\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
    \subfloat{\label{fig:6a}}
    \subfloat{\label{fig:6b}}
    \centering
    \includegraphics[width=\columnwidth]{example-image-a}
    \caption{
        Foo
        \protect\subref{fig:6a}
        Standard deviation of the distribution of the aging rate $B_a \equiv \Delta \mu_a / \ln T_a$ of individual events, normalized by that quantity for $n=1$.
        \protect\subref{fig:6b}
        Bar.
    }
    \label{fig:6}
\end{figure}

\end{document}

b.tex

\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
    \subfloat{\label{fig:6a}}
    \subfloat{\label{fig:6b}}
    \subfloat{\label{fig:6c}}
    \subfloat{\label{fig:6d}}
    \centering
    \includegraphics[width=\columnwidth]{example-image-a}
    \caption{
        \protect\subref{fig:6a}
        Distribution of the aging rate $B_a = \Delta \mu_a / \ln (T_a / T_0)$ for all events on the interface $a=1$ and all $n$.
        \protect\subref{fig:6b}
        Baz.
        \protect\subref{fig:6c}
        For $n=5$, a typical time evolution displaying slow slip of the relative position $R_a(t)-R_a(t_0)$, of the layer $a=2$.
        The total relative displacement $\Delta R$ is categorized as slip events of amplitude $\Delta R_a$, and slow slip.
        The fraction of slow slip is defined by $R_\mathrm{slow} = 1 - \sum \Delta R_a /\Delta R$.
        \protect\subref{fig:6d}
        Foo
    }
    \label{fig:6}
\end{figure}

\end{document}

Command

I run:

latexdiff -t CFONT --exclude-textcmd="chapter,section,subsection,subsubsection,paragraph" a.tex b.tex > diff.tex
latexmk -c diff.tex ; latexmk -pdf diff.tex

which gives the error that

<inserted text>
                \par
l.110     }\DIFaddendFL }

diff.tex

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL a.tex   Fri Jul 21 13:36:59 2023
%DIF ADD b.tex   Fri Jul 21 13:38:29 2023
\usepackage{subfig}
\usepackage{graphicx}
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF CFONT PREAMBLE %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{{\protect\color{blue} \sf #1}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red} \scriptsize #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
\newcommand{\DIFscaledelfig}{0.5}
%DIF HIGHLIGHTGRAPHICS PREAMBLE %DIF PREAMBLE
\RequirePackage{settobox} %DIF PREAMBLE
\RequirePackage{letltxmacro} %DIF PREAMBLE
\newsavebox{\DIFdelgraphicsbox} %DIF PREAMBLE
\newlength{\DIFdelgraphicswidth} %DIF PREAMBLE
\newlength{\DIFdelgraphicsheight} %DIF PREAMBLE
% store original definition of \includegraphics %DIF PREAMBLE
\LetLtxMacro{\DIFOincludegraphics}{\includegraphics} %DIF PREAMBLE
\newcommand{\DIFaddincludegraphics}[2][]{{\color{blue}\fbox{\DIFOincludegraphics[#1]{#2}}}} %DIF PREAMBLE
\newcommand{\DIFdelincludegraphics}[2][]{% %DIF PREAMBLE
\sbox{\DIFdelgraphicsbox}{\DIFOincludegraphics[#1]{#2}}% %DIF PREAMBLE
\settoboxwidth{\DIFdelgraphicswidth}{\DIFdelgraphicsbox} %DIF PREAMBLE
\settoboxtotalheight{\DIFdelgraphicsheight}{\DIFdelgraphicsbox} %DIF PREAMBLE
\scalebox{\DIFscaledelfig}{% %DIF PREAMBLE
\parbox[b]{\DIFdelgraphicswidth}{\usebox{\DIFdelgraphicsbox}\\[-\baselineskip] \rule{\DIFdelgraphicswidth}{0em}}\llap{\resizebox{\DIFdelgraphicswidth}{\DIFdelgraphicsheight}{% %DIF PREAMBLE
\setlength{\unitlength}{\DIFdelgraphicswidth}% %DIF PREAMBLE
\begin{picture}(1,1)% %DIF PREAMBLE
\thicklines\linethickness{2pt} %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,0){\framebox(1,1){}}}% %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,0){\line( 1,1){1}}}% %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,1){\line(1,-1){1}}}% %DIF PREAMBLE
\end{picture}% %DIF PREAMBLE
}\hspace*{3pt}}} %DIF PREAMBLE
} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbegin}{\DIFaddbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddend}{\DIFaddend} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbegin}{\DIFdelbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelend}{\DIFdelend} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbegin}{\DIFOaddbegin \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbegin}{\DIFOdelbegin \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbeginFL}{\DIFaddbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddendFL}{\DIFaddendFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbeginFL}{\DIFdelbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelendFL}{\DIFdelendFL} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbeginFL}{\DIFOaddbeginFL \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbeginFL}{\DIFOdelbeginFL \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
%DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_CFONT %DIF PREAMBLE
  moredelim=[il][\color{red}\scriptsize]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\sffamily]{\%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}

\begin{figure}[htp]
    \subfloat{\label{fig:6a}}
    \subfloat{\label{fig:6b}}
    \DIFaddbeginFL \subfloat{\label{fig:6c}}
    \subfloat{\label{fig:6d}}
    \DIFaddendFL \centering
    \includegraphics[width=\columnwidth]{example-image-a}
    \caption{
        \DIFdelbeginFL \DIFdelFL{Foo
        }\DIFdelendFL \protect\subref{fig:6a}
        \DIFdelbeginFL \DIFdelFL{Standard deviation }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{Distribution }\DIFaddendFL of the \DIFdelbeginFL \DIFdelFL{distribution of the }\DIFdelendFL aging rate \DIFdelbeginFL \DIFdelFL{$B_a \equiv \Delta \mu_a / \ln T_a$ }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{$B_a = \Delta \mu_a / \ln (T_a / T_0)$ for all events on the interface $a=1$ and all $n$.
        }\protect\subref{fig:6b}
        \DIFaddFL{Baz.
        }\protect\subref{fig:6c}
        \DIFaddFL{For $n=5$, a typical time evolution displaying slow slip }\DIFaddendFL of \DIFdelbeginFL \DIFdelFL{individual }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{the relative position $R_a(t)-R_a(t_0)$, of the layer $a=2$.
        The total relative displacement $\Delta R$ is categorized as slip }\DIFaddendFL events \DIFaddbeginFL \DIFaddFL{of amplitude $\Delta R_a$}\DIFaddendFL , \DIFdelbeginFL \DIFdelFL{normalized }\DIFdelendFL \DIFaddbeginFL \DIFaddFL{and slow slip.
        The fraction of slow slip is defined }\DIFaddendFL by \DIFdelbeginFL \DIFdelFL{that quantity for $n=1$}\DIFdelendFL \DIFaddbeginFL \DIFaddFL{$R_\mathrm{slow} = 1 - \sum \Delta R_a /\Delta R$}\DIFaddendFL .
        \protect\DIFdelbeginFL %DIFDELCMD < \subref{fig:6b}
%DIFDELCMD <         %%%
\DIFdelFL{Bar.
    }\DIFdelendFL \DIFaddbeginFL \subref{fig:6d}
        \DIFaddFL{Foo
    }\DIFaddendFL }
    \label{fig:6}
\end{figure}

\end{document}