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
518 stars 73 forks source link

Limits of symbolic sums/products in display-style math #301

Open simon-pfahler opened 4 months ago

simon-pfahler commented 4 months ago

When a limit of a \sum or a \product is changed in display-style math, latexdiff shows the limits as if they were set in an inline-math environment.

Example:

old.tex

\documentclass{article}

\begin{document}
\begin{equation}
    \sum_{n=0}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}
\end{equation}
\end{document}

new.tex

\documentclass{article}

\begin{document}
\begin{equation}
    \sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}
\end{equation}
\end{document}

The resulting diff.tex obtained from running latexdiff old.tex new.tex > diff.tex is:

diff.tex

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL old.tex   Fri May 17 08:37:47 2024
%DIF ADD new.tex   Fri May 17 08:38:43 2024
%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 COLORLISTINGS 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}
\begin{equation}
    \sum\DIFdelbegin \DIFdel{_{n=0}}\DIFdelend \DIFaddbegin \DIFadd{_{n=1}}\DIFaddend ^\infty \frac{1}{n^2}=\frac{\pi^2}{6}
\end{equation}
\end{document}

The \DIF part includes the _{n=0}, instead of just the 0, therefore the subscripts are not directly behind the sum anymore and get displayed in another way.

ftilmann commented 1 month ago

Thanks for the report. According to my assessment, this is difficult to fix without causing problems in other situations in a general way. As marked-up versions are usually for internal use only, I would say minor cosmetic imperfections like this are not a priority.

If somebody wants to have a go I think in postprocessing looking for the pattern \(sum|product) \DIF(add\del)begin) \DIF(add/del){\(SUPER/SUB)SCRIPT|_|^...} and then moving the markup inside the argument of _ or ^ would be the way to go about this.