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
513 stars 72 forks source link

Problem with nested delimiters and subscripts #220

Open ajdunlap opened 3 years ago

ajdunlap commented 3 years ago

I ran latexdiff on the following two files:

$ cat test1.tex 
\documentclass{article}
\begin{document}
\begin{equation}
  \left\Vert     [y] \right\Vert_y
\end{equation}
\end{document}
$ cat test2.tex 
\documentclass{article}
\begin{document}
\begin{equation}
  \left\Vert    [y] \right\Vert_x
\end{equation}
\end{document}

I ran the command as follows and got the following output in the difference file:

$ latexdiff --math-markup=whole test1.tex test2.tex > differences.tex
$ cat differences.tex
\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL test1.tex   Thu Jan 21 10:54:16 2021
%DIF ADD test2.tex   Thu Jan 21 10:54:16 2021
%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
\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
%DIF LISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
  moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\uwave]{\%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}
\DIFdelbegin \begin{displaymath}
  \DIFdel{\left\Vert     }[\DIFdel{y}] \DIFdel{\right\Vert_y
}\end{displaymath}%DIFAUXCMD
\DIFdelend \DIFaddbegin \begin{equation}
  \DIFadd{\left\Vert    }[\DIFadd{y}] \DIFadd{\right\Vert_x
}\end{equation}\DIFaddend 
\end{document}

However, when I ran latex on the difference output, I got an error:

$ pdflatex differences.tex 
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./differences.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-03> xparse <2020-03-03>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texmf-dist/tex/generic/ulem/ulem.sty)
(/usr/share/texmf-dist/tex/latex/graphics/color.sty
(/usr/share/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texmf-dist/tex/latex/graphics-def/pdftex.def))
(/usr/share/texmf-dist/tex/latex/listings/listings.sty
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-dist/tex/latex/listings/lstmisc.sty)
(/usr/share/texmf-dist/tex/latex/listings/listings.cfg))
(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./differences.aux) (/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)
! Extra }, or forgotten \right.
\UL@onmath ...rd {\UL@hrest \mathop {\kern \z@ #1}
                                                  \limits \sb {\UL@leadtype ...
l.45   \DIFdel{\left\Vert     }
                               [\DIFdel{y}] \DIFdel{\right\Vert_y
? X
No pages of output.
Transcript written on differences.log.
ajdunlap commented 3 years ago

This doesn't happen if the inside brackets are replaced by parentheses or by \lbrack/\rbrack, so I suspect the issue is that the [y] is getting parsed as an optional argument.