1

I recently encountered some problem using latexdiff when the tex file contains matched half brackets like \left(\. or \.\right). For example, I have two files, one is test-old.tex,

\documentclass{article}
\begin{document}
this is the old one, with

\begin{equation}
  \label{eq:1}
  \left(
    full~bracket
  \right)
\end{equation}
\end{document}

the other is test-new.tex,

\documentclass{article}
\begin{document}
this is the new one, with
\begin{equation}
  \label{eq:1}
  \left(
    half~bracket
  \right.
\end{equation}
\end{document}

I use the command latexdiff test-old.tex test-new.tex > test-diff.tex to generate the compared file test-diff.tex as follows,

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL test-old.tex   Wed Feb  3 21:05:52 2016
%DIF ADD test-new.tex   Wed Feb  3 21:05:58 2016
%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
%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 END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}
this is the \DIFdelbegin \DIFdel{old }\DIFdelend \DIFaddbegin \DIFadd{new }\DIFaddend one, with
\DIFdelbegin %DIFDELCMD < 

%DIFDELCMD < %%%
\DIFdelend \begin{equation}
  \label{eq:1}
  \left(
    \DIFdelbegin \DIFdel{full}\DIFdelend \DIFaddbegin \DIFadd{half}\DIFaddend ~bracket
  \DIFdelbegin %DIFDELCMD < \right)
%DIFDELCMD < %%%
\DIFdelend \DIFaddbegin \right\DIFadd{.
}\DIFaddend \end{equation}
\end{document}

which does not compile to pdf, mainly due to the third line from bottom

\DIFdelend \DIFaddbegin \right\DIFadd{.

where \right is separated from ., hence the matching is ruined.

How does this happen? Is there a proper way to avoid this? Thanks!

P.S.

My latexdiff --version produces

This is LATEXDIFF 1.0.2  (Algorithm::Diff 1.15 so, Perl v5.18.2)

which I know is not the latest, but I did not find any related information on this (possible) bug.


At this stage, I have tried two methods to at least make test-diff.tex compile. One is to modify the file, delete the related part in the generated file(or add a dot manually after \right); but this not only adds debugging effort, I have to do it every time after comparison. The other way is to define a new macro for the half brackets(or parentheses), and use the new macro instead in the files to be compared.

1

It is a simple bug in the script, forgetting to add . as a possible bracket. You can correct it by replacing the line starting my $cmdleftright= by

  my $cmdleftright='\\\\(?:left|right|[Bb]igg?[lrm]?|middle)\s*(?:[<>()\[\]|\.]|\\\\(?:[|{}]|\w+))';

The change being to add \. in the group [<>...].

You should report this as a bug to the maintainer.

  • 1
    You are amazing! I guess I cannot test this myself (as I know nothing of perl etc), but I'll try to report the bug as you suggested. – davyjones Feb 3 '16 at 14:23
  • Another thing I notice is that, if the formulas are inline (between $$), then everything is ok. Why this different standard? – davyjones Feb 4 '16 at 5:34
  • but not ok if I try \(\) or \[\] – davyjones Feb 4 '16 at 5:49
  • @davyjones Those are math environment delimiters, not brackets, so they should not be covered by this. – Andrew Swann Feb 4 '16 at 12:28

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.