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

Adding column to a table combined with graphicx fails #212

Open ianhbell opened 3 years ago

ianhbell commented 3 years ago

TL;DR: When graphicx package is included, addition of a column to a table doesn't result in buildable diff. Otherwise, no problem. Sadly I need graphicx to add figures to document.

Original with 2 columns:

\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\begin{document}
    \begin{tabular}{|c|c|}
        \hline
        &  \\
        \hline
        &  \\
        \hline
    \end{tabular}
\end{document}

New with 5 columns:

\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{tabular}{|c|c|c|c|c|}
    \hline
    &  &  &  &  \\
    \hline
    &  &  &  &  \\
    \hline
\end{tabular}
\end{document}

Generated diff:

\documentclass[10pt,a4paper]{article}
%DIF LATEXDIFF DIFFERENCE FILE

\usepackage{graphicx}
%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
\newcommand{\DIFscaledelfig}{0.5}
%DIF HIGHLIGHTGRAPHICS PREAMBLE %DIF PREAMBLE
\RequirePackage{settobox} %DIF PREAMBLE
\RequirePackage{letltxmacro} %DIF PREAMBLE
\newsavebox{\DIFdelgraphicsbox} %DIF PREAMBLE
\newlength{\DIFdelgraphicswidth} %DIF PREAMBLE
\newlength{\DIFdelgraphicsheight} %DIF PREAMBLE
% store original definition of \includegraphics %DIF PREAMBLE
\LetLtxMacro{\DIFOincludegraphics}{\includegraphics} %DIF PREAMBLE
\newcommand{\DIFaddincludegraphics}[2][]{{\color{blue}\fbox{\DIFOincludegraphics[#1]{#2}}}} %DIF PREAMBLE
\newcommand{\DIFdelincludegraphics}[2][]{% %DIF PREAMBLE
\sbox{\DIFdelgraphicsbox}{\DIFOincludegraphics[#1]{#2}}% %DIF PREAMBLE
\settoboxwidth{\DIFdelgraphicswidth}{\DIFdelgraphicsbox} %DIF PREAMBLE
\settoboxtotalheight{\DIFdelgraphicsheight}{\DIFdelgraphicsbox} %DIF PREAMBLE
\scalebox{\DIFscaledelfig}{% %DIF PREAMBLE
\parbox[b]{\DIFdelgraphicswidth}{\usebox{\DIFdelgraphicsbox}\\[-\baselineskip] \rule{\DIFdelgraphicswidth}{0em}}\llap{\resizebox{\DIFdelgraphicswidth}{\DIFdelgraphicsheight}{% %DIF PREAMBLE
\setlength{\unitlength}{\DIFdelgraphicswidth}% %DIF PREAMBLE
\begin{picture}(1,1)% %DIF PREAMBLE
\thicklines\linethickness{2pt} %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,0){\framebox(1,1){}}}% %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,0){\line( 1,1){1}}}% %DIF PREAMBLE
{\color[rgb]{1,0,0}\put(0,1){\line(1,-1){1}}}% %DIF PREAMBLE
\end{picture}% %DIF PREAMBLE
}\hspace*{3pt}}} %DIF PREAMBLE
} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbegin}{\DIFaddbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddend}{\DIFaddend} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbegin}{\DIFdelbegin} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelend}{\DIFdelend} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbegin}{\DIFOaddbegin \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbegin}{\DIFOdelbegin \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelend}{\DIFOaddend \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddbeginFL}{\DIFaddbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOaddendFL}{\DIFaddendFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelbeginFL}{\DIFdelbeginFL} %DIF PREAMBLE
\LetLtxMacro{\DIFOdelendFL}{\DIFdelendFL} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddbeginFL}{\DIFOaddbeginFL \let\includegraphics\DIFaddincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFaddendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelbeginFL}{\DIFOdelbeginFL \let\includegraphics\DIFdelincludegraphics} %DIF PREAMBLE
\DeclareRobustCommand{\DIFdelendFL}{\DIFOaddendFL \let\includegraphics\DIFOincludegraphics} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}
\DIFdelbegin %DIFDELCMD < \begin{tabular}{|c|c|}
%DIFDELCMD <        %%%
\DIFdelend \DIFaddbegin \begin{tabular}{|c|c|c|c|c|}
    \DIFaddend \hline
    &  \DIFaddbegin &  &  &  \DIFaddend \\
    \hline
    \DIFaddbegin &  &  &  \DIFaddend &  \\
    \hline
\end{tabular}
\end{document}

Build log with xelatex.exe -synctex=1 -shell-escape -interaction=nonstopmode "coldiff".tex:

This is XeTeX, Version 3.14159265-2.6-0.999992 (MiKTeX 20.6.29) (preloaded format=xelatex 2020.7.9)  16 SEP 2020 23:15
entering extended mode
**./coldiff.tex
(coldiff.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-06-18>
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\size10.clo"
File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option)
)
\c@part=\count163
\c@section=\count164
\c@subsection=\count165
\c@subsubsection=\count166
\c@paragraph=\count167
\c@subparagraph=\count168
\c@figure=\count169
\c@table=\count170
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen134
)
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\graphicx.st
y"
Package: graphicx 2019/11/30 v1.2a Enhanced LaTeX Graphics (DPC,SPQR)

("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\keyval.sty"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\graphics.st
y"
Package: graphics 2019/11/30 v1.4a Standard LaTeX Graphics (DPC,SPQR)
 ("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-cfg\graphic
s.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: xetex.def on input line 105.

("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-def\xetex.d
ef"
File: xetex.def 2017/06/24 v5.0h Graphics/color driver for xetex
))
\Gin@req@height=\dimen135
\Gin@req@width=\dimen136
) ("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/ulem\ulem.sty"
\UL@box=\box45
\UL@hyphenbox=\box46
\UL@skip=\skip49
\UL@hook=\toks16
\UL@height=\dimen137
\UL@pe=\count171
\UL@pixel=\dimen138
\ULC@box=\box47
Package: ulem 2019/11/18
\ULdepth=\dimen139
) ("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\color.sty
"
Package: color 2019/11/23 v1.2a Standard LaTeX Color (DPC)

("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-cfg\color.c
fg"
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package color Info: Driver file: xetex.def on input line 147.
)
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/oberdiek\settobox.st
y"
Package: settobox 2016/05/16 v1.5 Assign box dimensions to length registers (HO
)
)
("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/letltxmacro\letltxma
cro.sty"
Package: letltxmacro 2019/12/03 v1.6 Let assignment for LaTeX macros (HO)
)
\DIFdelgraphicsbox=\box48
\DIFdelgraphicswidth=\skip50
\DIFdelgraphicsheight=\skip51
LaTeX Info: Redefining \DIFaddbegin on input line 53.
LaTeX Info: Redefining \DIFaddend on input line 54.
LaTeX Info: Redefining \DIFdelbegin on input line 55.
LaTeX Info: Redefining \DIFdelend on input line 56.
LaTeX Info: Redefining \DIFaddbeginFL on input line 61.
LaTeX Info: Redefining \DIFaddendFL on input line 62.
LaTeX Info: Redefining \DIFdelbeginFL on input line 63.
LaTeX Info: Redefining \DIFdelendFL on input line 64.

("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/l3backend\l3backend-
xdvipdfmx.def"
File: l3backend-xdvipdfmx.def 2020-06-29 L3 backend support: xdvipdfmx
\g__graphics_track_int=\count172
\l__pdf_internal_box=\box49
\g__pdf_backend_object_int=\count173
\g__pdf_backend_annotation_int=\count174
) (coldiff.aux)
\openout1 = `coldiff.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 67.
LaTeX Font Info:    Trying to load font information for TS1+cmr on input line 6
7.

("C:\Users\ihb\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\ts1cmr.fd"
File: ts1cmr.fd 2019/12/16 v2.5j Standard LaTeX font definitions
)
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for TU/lmr/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 67.
LaTeX Font Info:    ... okay on input line 67.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 70.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 70.

! Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.71 ^^I^^I\DIFaddend \hline

I expect to see \noalign only after the \cr of
an alignment. Proceed, and I'll ignore this case.

! You can't use `\hrule' here except with leaders.
\hline ->\noalign {\ifnum 0=`}\fi \hrule 
                                         \@height \arrayrulewidth \futurelet...
l.71 ^^I^^I\DIFaddend \hline

To put a horizontal rule in an hbox or an alignment,
you should use \leaders or \hrulefill (see The TeXbook).

! Missing number, treated as zero.
<to be read again> 
                   \futurelet 
l.71 ^^I^^I\DIFaddend \hline

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \futurelet 
l.71 ^^I^^I\DIFaddend \hline

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

[1

] (coldiff.aux) ) 
Here is how much of TeX's memory you used:
 1004 strings out of 414039
 15011 string characters out of 2893178
 253991 words of memory out of 3000000
 18711 multiletter control sequences out of 15000+200000
 532452 words of font info for 26 fonts, out of 3000000 for 9000
 1348 hyphenation exceptions out of 8191
 30i,6n,25p,231b,105s stack positions out of 5000i,500n,10000p,200000b,50000s

Output written on coldiff.pdf (1 page).
ftilmann commented 3 years ago

Thanks for the well-documented report and sorry for my slow reaction. It seems the redefinition of commands that \DIFaddbegin introduces is not possible within the tabular environment, which I was not aware off. There is currently no solution but as a work-around you can use --graphics-markup=none option, with which the example works. The only downside is that new images will not be highlighted with a blue frame anymore but this was more eye candy and probably not that critical. I will leave the issue open, but the ability to fix this is probably beyond me, as it relates to the interaction within the tabular environment. I added a note to the documentation to be aware of this problem

Friedrich2 commented 2 years ago

I neither know the script nor Perl or TeX, but could this page help? (I. e., will the problem be solved by redefining the commands in \DIFaddbegin only locally?) Do I see it correctly that, when using the workaround, it is not marked in the difference file that there is a difference in the table between the compared files?

ftilmann commented 2 years ago

Thank you for the suggestion. Unfortunately the redefinition has to be non-local to work, so the linked hint does not help. The workaround only affects the markup of graphics (images), not the markup in the table. For most purposes it's not a big deal I would think.