[Tex/LaTex] Using latexdiff to generate changebars for graphics inside figures

latexdiff

I am trying to utilize latexdiff to highlight the changes between different version of a document. One thing that I have run into is that sometimes graphics in figures change. Obviously, latexdiff can't tell if two images with the same filename are different, so I resorted to just renaming the files. What I've noticed though is that, although latexdiff generates the diff markup inside the figure environment, I don't see any output margin bar next to it.

I tried manipulating the FLOATSAFE/TRADITIONALSAFE/IDENTICAL configuration options – TRADITIONALSAFE had no change, and IDENTICAL just broke the compilation step (not surprising). The following is an MWE:

Given the two tex files:

a.tex

\documentclass[11pt]{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[scale=0.1]{a}
    \caption{Figure A}
    \label{fig:a}
\end{figure}

\end{document}

b.tex

\documentclass[11pt]{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[scale=0.1]{b}
    \caption{Figure B}
    \label{fig:b}
\end{figure}

\end{document}

And using command:

latexdiff -t CHANGEBAR a.tex b.tex >diff.tex

I get:

diff.tex:

\begin{document}

\begin{figure}
    \centering
    \DIFdelbeginFL %DIFDELCMD < \includegraphics[scale=0.1]{a}
%DIFDELCMD <     %%%
\DIFdelendFL \DIFaddbeginFL \includegraphics[scale=0.1]{b}
    \DIFaddendFL \caption{Figure \DIFdelbeginFL \DIFdelFL{A}\DIFdelendFL \DIFaddbeginFL \DIFaddFL{B}\DIFaddendFL }
    \DIFdelbeginFL %DIFDELCMD < \label{fig:a}
%DIFDELCMD < %%%
\DIFdelendFL \DIFaddbeginFL \label{fig:b}
\DIFaddendFL \end{figure}

\end{document}

I'm wondering if anyone has come up with a decent workaround. Ideally, the whole figure would have a changebar – I don't really care if it's the caption or the picture that changed, just that the figure somehow changed.

Best Answer

You can use the changebar package but need to change the \DIFaddbegin/end and \DIFaddbegin/end commands rather than \DIFadd/del as is done by the -t option.

With the following preamble your MWE worked; adjust option of changebar package to your driver.

%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 
\RequirePackage[pdftex]{changebar} %DIF PREAMBLE
\providecommand{\DIFaddbegin}{\protect\cbstart} %DIF PREAMBLE
\providecommand{\DIFaddend}{\protect\cbend} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{\protect\cbdelete} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
%DIF IDENTICAL PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{\DIFaddbegin} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{\DIFaddend} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{\DIFdelbegin} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{\DIFdelend} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

I obtained this by running latexdiff -f IDENTICAL --show-preamble and then editing the middle block by hand. Use --preamble / -p option to read in this preamble. If you like to use the changebars only in figures (really floating environments, also including tables), change the \DIFaddbeginFL etc. commands instead

Related Question