latexdiff
latexdiff copied to clipboard
latexdiff doesn't show changes in `\section` when wrapped in`\hypertarget`
I use Pandoc to create nice-looking LaTeX PDF output from easy-to-use Markdown input files. I find this works well, because I get the beauty of LaTeX with the simplicity of Markdown.
One thing I've been wanting to do for a while is highlight the differences between two version of a Markdown file - which is where latexdiff
comes in. Usually I would just create a PDF directly from Pandoc (which takes care of calling the LaTeX engine as needed), but it's also possible to generate the intermediate LaTeX source and then call latexdiff
on that. Changes in the body text works fine - but the way that Pandoc creates section headings in the LaTeX code causes latexdiff
to not mark up the changes in headings (and sub-headings etc.).
For completeness, I've uploaded a series of examples to show completely what I mean:
- This is the "old" input Markdown file: test_document-old.md
- This is the "new" input Markdown file: test_document-new.md
- This is the produced "old" LaTeX file: test_document-old.latex
- This is the produced "new" LaTeX file: test_document-new.latex
- Finally, this is the diff from latexdiff: test_document-new_changes.latex
One section of note, which highlights the issue in the changes.latex file produced by latexdiff
:
This is \DIFdelbegin \DIFdel{another }\DIFdelend \DIFaddbegin \DIFadd{not a }\DIFaddend sub-heading\DIFdelbegin \DIFdel{.
}%DIFDELCMD <
%DIFDELCMD < \hypertarget{heading-2}{%
%DIFDELCMD < \section{Heading 2}%DIFDELCMD < \label{heading-2}%%%
}
%DIFDELCMD <
%DIFDELCMD < %%%
\DIFdel{I thought I wanted some things in this section, but I decided to remove
them instead}\DIFdelend .
In this section, I removed the heading "Heading 2", and the text that goes along with it. But, there is no mark up to show "Heading 2" has been removed, only the body text has \DIFdel
around it. As you would expect, this means there is no red struck-out section in the PDF either, and it makes it quite hard to see that changes have been made at all, see the image below:
I found that if I manually remove the \hypertarget
calls which are wrapped around the \section
pieces from Pandoc in the LaTeX source before doing the latexdiff
call, things to behave much better, e.g. I get this:
%DIFDELCMD < %%%
\section{\DIFdel{Heading 2}}%DIFAUXCMD
\addtocounter{section}{-1}%DIFAUXCMD
%DIFDELCMD < %DIFDELCMD < \label{heading-2}%%%
%DIFDELCMD <
which produces the PDF as expected.
Is there something that I can do to get latexdiff
to play nicely with \hypertarget
? Is this a bug, or is it just not compatible with this kind of use case?
Latexdiff generally will not analyse text that is two levels down in an argument, i.e. arguments of commands, which are in themselves arguments of a command (as is the case here), so on that level it is a feature request. Implementing this would require expanding arguments of text commands recursively. Possible, but not trivial. I tested with your input files, and actually I get error messages when running through latexdiff, though it still produces the pdf - this is definitely a bug.
Latexdiff generally will not analyse text that is two levels down in an argument
Fair enough - to that end, since I came across this in developing a little system of my own, I have worked around the non-ideal output from Pandoc by simply removing the \hypertarget
sections (code here for anyone interested)
I tested with your input files, and actually I get error messages when running through latexdiff, though it still produces the pdf - this is definitely a bug.
I saw these too - to be honest, I was just ignoring them since I was used to seeing a lot of output from xelatex
and tend to ignore it as long as it makes the PDF, so applied that mentality here too. The PDF behaves as expected, so it's not a big deal.
The compile errors are fixed with commit f7814b7. I will not tackle your main issue anytime soon but will leave the issue open, so that people are directed to the link to your workaround.
@seanlano How are you able to even get any output at all? When I run latexdiff output like the above through xelatex, I get ! Too many }'s.
errors at places like:
\DIFdelbegin %DIFDELCMD < \hypertarget{foo-installation}{%
%DIFDELCMD < \section{Foo Installation}%DIFDELCMD < \label{foo-installation}%%%
}
%DIFDELCMD < %%%
\DIFdelend \DIFaddbegin \hypertarget{bar-installation}{%
\section{Bar Installation}\label{bar-installation}}
\DIFaddend
@AlecBenzer This is supposed to have been fixed with commit f7814b7 as mentioned above. Have you upgraded already to version 1.3.0 that contains this fix? If you have, I would much appreciate if you could post a complete MWE, i.e. old and new files and resulting diff.