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
529 stars 75 forks source link

align environment changed to eqnarray #149

Closed vtraag closed 6 years ago

vtraag commented 6 years ago

When the amsmath package gets loaded through a documentclass (or another package possibly?), changes in align environments are changed to eqnarray environments when diffed.

old.tex:

\documentclass[amsmath]{revtex4-1}
\begin{document}
\begin{align}
  a &= b & x &= y   
\end{align}
\end{document}

new.tex:

\documentclass[amsmath]{revtex4-1}
\begin{document}
\begin{equation}
  x \sim y
\end{equation}
\end{document}

Generated diff of the align environment:

\DIFdelbegin \begin{eqnarray*}
  \DIFdel{a }&\DIFdel{= b }& \DIFdel{x }&\DIFdel{= y    
}\end{eqnarray*}

In this case, it is only a minor problem, and compiling diff.tex only produces LaTeX Error: Too many columns in eqnarray environment.

In the actual context of a full article, the reported errors become more severe, and more difficult to track down.

Workaround

A workaround is easy: load the amsmath explicitly in new.tex. I just wanted to document this here, since it took me quite some time to come up with this workaround.

Perhaps this can be solved in latexdiff in some way, but I can imagine it would be rather difficult to detect whether amsmath may have been loaded through some third package or documentclass. Nonetheless, the error of a missing align environment may be somewhat easier to recognize and correct for if necessary.

ftilmann commented 6 years ago

Another workaround: You can explicitly hint to latexdiff that amsmath package is loaded by using option --packages=amsmath. However, this overrides automatic detection completely (probably a behaviour that ought to be changed).

ftilmann commented 6 years ago

Having said this, I just committed a modification to the automatic package scanning subroutine that now also treats options to \documentclass as potential package names, so the code you provided should now work without the workaround (commit 3e56ad7 )