Skip to content

Does not work with diffs in minted environments #323

@brasswood

Description

@brasswood

I am trying to get a diff between two versions of my thesis. However, latexdiff isn't working because my thesis uses minted. Here is a minimal example of the problem.

a.tex:

\documentclass{article}
\usepackage{minted}

\begin{document}
\begin{minted}{text}
something_here
\end{minted}
\end{document}

b.tex:

\documentclass{article}
\usepackage{minted}

\begin{document}
\end{document}

Commands:

latexdiff --config "VERBATIMLINEENV=minted" a.tex b.tex > diff.tex
pdflatex -shell-escape diff.tex

Output:

! Missing $ inserted.
<inserted text>
                $
l.50 }
      %DIFDELCMD < \end{minted}
?

This appears to be caused by latexdiff improperly moving the arguments to minted inside of the minted environment:

 \DIFdelbegin %DIFDELCMD < \begin{minted}%%%
%DIFAUXCMD NEXT
\DIFmodbegin
\begin{minted}[alsolanguage=DIFcode]
%DIF < {text}
%DIF < something_here
\end{minted}
\DIFmodend %DIFAUXCMD
%DIFDELCMD < \end{minted}
%DIFDELCMD <  %%%
\DIFdelend

When I move {text} up to the previous line and remove %DIF < from it, it compiles.

I have tried to hack the script to work for me by duplicating regex replaces containing $VERBATIMLINEENV and replacing that with minted. See my branch at https://github.com/brasswood/latexdiff/tree/minted. However, it's not working, and when I run my patched script (without setting VERBATIMLINEENV), I get the following output:

 \DIFdelbegin %DIFDELCMD < \begin{minted}%%%
%DIF < DIFVRB {text}
%DIF < DIFVRB something_here
%DIFDELCMD < \end{minted}
%DIFDELCMD <  %%%
\DIFdelend

which doesn't include a minted environment at all in the output. By putting debug statements in the output, I am able to see that the reversemintedlinecomment subroutine I defined (copied from reverselinecomment) is not called.

I am willing to keep trying to get this to work. I would also appreciate it if someone shared helpful knowledge about the code base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions