1

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.

  • Your a.tex is identical with your b.tex (I presume a copy/paste error) - even though it is obvious what you mean you might edit your question – frederik Jun 16 '15 at 14:30
1

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

  • So, copied the preamble into a textfile, 'preamble.tex', then did 'latexdiff -p preamble.tex a.tex b.tex > diff.tex. The output is at gist.github.com/anonymous/1e5cda2d1b8f52cbabef . When I try to compile it, I get "! Argument of \@caption has an extra }.". Any thoughts on this? If I manually remove the DIF markup from the caption, the output is acceptable. – Jacob Schaer Jun 16 '15 at 18:48
  • Before you fixed the typo in the question I had performed the test on a pair of files where just the \includegraphics command had changed. It turns out that the changebar needs some aid when used in the caption. Adding \protect in front of the changebar commands fixes this for me. I have edited the answer to reflect this change. I also removed the \cbdelete mark for marking the end of a deleted section, as these symbols appear to accumulate - you might even consider not marking deletions at all and removing the \cbdelete in \DIFdelbegin – frederik Jun 17 '15 at 20:59

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.