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

TeX STOPPED with continuous $$ #187

Closed zxdawn closed 4 years ago

zxdawn commented 4 years ago

Here's the simple examples:

v1.tex

\documentclass{article}

\begin{document}

t$_\textrm{window}$$^3$
V$_\textrm{strat}$$^4$

\end{document}

v2.tex

\documentclass{article}

\begin{document}

t$_\textrm{window}$$^3$
V$_\textrm{strat}$$^5$

\end{document}

latexdiff.exe v1.tex v2.tex > diff.tex

diff.tex

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL v1.tex   Sun Feb  2 19:05:46 2020
%DIF ADD v2.tex   Sun Feb  2 19:05:51 2020

%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}

t$_\textrm{window}$$^3$
V\DIFdelbegin \DIFdel{$_\textrm{strat}}^4$
$$\DIFdelend \DIFaddbegin \DIFadd{$_\textrm{strat}}^5$
}\DIFaddend 

\end{document}

Error

! Improper \spacefactor.
...def \UL@spfactor {\the \spacefactor
}
l.30 V\DIFdelbegin \DIFdel{$_\textrm{strat}}
^4$
?
ftilmann commented 4 years ago

For sure it gets confused by the $$, which can also be used to designate a displayed equation $$ ... $$ (which strictly speaking is TeX rather than LaTeX, but is common enough that latexdiff allows for that). The sort of non-local understanding needed to distinguish the two meanings would not be that easy to implement (for sure it's possible but nothing that can be done in an hour or two, at least not by me). I could introduce an option that suppresses the display math interpretation of $$ but I am a bit reluctant to have an overabundance of rarely used functions. In your examples, is there any reason why you did not simply write:

t$_\textrm{window}^3$

If spacing is an issue, you can use the negative space command (I have forgotten what this was, maybe \!) If you absolutely must have the exponent in a different inline math environments, I assume adding a comment between the two parts would hint at latexdiff to treat the $$ as two singles.

t$_\textrm{window}$%
$^3$

Of course, this is less human-readable, but then my first variant is more easily understood than your version. For now I will close this, as it's probably a very marginal use case, but feel free to reopen if you strongly disagree.

zxdawn commented 4 years ago

@ftilmann Thanks! I use the % to deal with this problem now.

BTW, this is the "complicated" case I met (the red rectangle) in the table: image