# [Tex/LaTex] Can latexdiff be used for mathematics documents

latexdiffmath-mode

I've been pulling my hair out trying to get latexdiff to work with a mathematics document. It produces output that latex can't compile if one of the files is this:

\documentclass{amsart}
\begin{document}
$$\label{eq:Psi-action} 2=1+1$$
\end{document}


and the other is this:

\documentclass{amsart}
\begin{document}
yo
\end{document}


But I think it chokes on other things as well. Am I doing something wrong? Is anyone able to use latexdiff for mathematics documents more than a few lines long? If anyone is able to use it by making some easy changes to their LaTeX code, are there general guidelines about what kind of LaTeX code to avoid?

Update 1: It appears that latexdiff doesn't like things like \big(. You can sort of get around this by changing every \big( to a \left(.

Update 2: Here is another pair of files that breaks it:

\documentclass{amsart}
\begin{document}
\begin{equation*}
X_{[1],n}
\end{equation*}
\end{document}


and

\documentclass{amsart}
\begin{document}
\begin{equation*}
[1]X_{n}
\end{equation*}
\end{document}


I had only a few such examples and was able to get around them by just commenting out the offending code, but it would be nice to know if there are any rules of thumb to avoid having to worry about it in the first place, like Andrew's helpful comment about Perl and line breaks.

#### Best Answer

I can get the example that you gave to compile by moving the \label{eq:Psi-action} on to a line by itself:

\documentclass{amsart}
\begin{document}
$$\label{eq:Psi-action} 2=1+1$$
\end{document}


Without that, what seemed to be happening was that it was recognising the as the end of a mathematics environment that was in one file but not the other, so it marked it up as \end{MATHMODE}. But for some reason it didn't spot the beginning of that environment so there was no corresponding \begin{MATHMODE}. Putting the \label on the new line seems to be enough to make it recognise the once again.

Whilst doing a pretty fair job, latexdiff doesn't interpret TeX documents in the same way that TeX does. In particular, since latexdiff is a perl program, I imagine it works on a line-by-line basis, so new-lines are more important to latexdiff than to TeX. So if there are other things that are causing it to complain, try adding more new-lines to separate things so that latexdiff recognises them as separate.

And, of course, if it gets stuck on something else, ask again!