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

Lines ending in underscore in verbatim block cause confusion #305

Closed anka-213 closed 2 weeks ago

anka-213 commented 1 month ago

Diffing this file with itself will the first \begin{verbatim} to be replaced with a \begin{DIFverbatim} and the last \end{verbatim} to be replaced with a \end{DIFverbatim}, but the first \end{verbatim} and the second \begin{verbatim} are left as is, so the middle non-verbatim text gets included in the spurious DIFverbatim block.

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{verbatim}
first _
block _
\end{verbatim}
non verbatim text
\begin{verbatim}
second block
\end{verbatim}

\end{document}

Running latexdiff strange.tex strange.tex | tail -n15 outputs:

\begin{document}

\DIFmodbegin
\begin{DIFverbatim}[alsolanguage=DIFcode]
first _
%block _
\end{verbatim}
non verbatim text
\begin{verbatim}
second block
\end{DIFverbatim}
\DIFmodend

\end{document}

As you can see, despite not actually having a diff, they get wrapped in a DIFverbatim block and each line after a line ending with underscore gets preceded with a % sign, which maybe is related to why the first \end{verbatim} is ignored? I don't really know what is going on.

If I only have one line ending with underscore in the verbatim block, the first \end{verbatim} will get the \end{DIFverbatim} instead of the second.

ftilmann commented 2 weeks ago

Thank you for reporting. As you can see the lastest commit has fixed this bug.