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
516 stars 73 forks source link

error with booktabs #111

Open ajshephard opened 7 years ago

ajshephard commented 7 years ago

Hi, Using the booktabs package we may create a table with commands such as


\begin{tabular}{cccc}
\toprule
\multicolumn{2}{c}{I}&\multicolumn{2}{c}{II}\\
\cmidrule(lr){1-2}\cmidrule(lr){3-4}
A & B  & C & D\\
\midrule
1 & 2 & 3 & 4\\
5 & 6 & 7 & 8\\
\bottomrule
\end{tabular}

If this table appears in the revision, then the markup added will result in compilation errors as the \cmidrule command becomes marked up as \cmidrule\DIFadd{(lr)}{\DIFadd{1-2}}\cmidrule\DIFadd{(lr)}{\DIFadd{3-4}}

alexpacini commented 6 years ago

+1. Beside the \cmidrule issue, given by the round parentheses, when adding a table which was not present before, I also get an issue with the \multicolumn whose text field is not recognised and breaks the columns.

ftilmann commented 6 years ago

@alexpacini your support for prioritising \cmidrule issue is noted. However, can you open a separate issue for the \multicolumn issue and include an example demonstrating the effect.

alexpacini commented 6 years ago

The issue is more subtle that I thought and I have problems making a MWE. Unfortunately I am not allowed to post the complete manuscript and by isolating the table the tex is compiling normally. Hence I am not sure if to open a new issue (or maybe send to you the two versions of the manuscript).

cgundogan commented 3 years ago

I guess there is no viable solution to handle \cmidrule in a latex diff nowadays, is there? I am using latexdiff frequently and always de-scramble lines with \cmidrule by hand to get it through pdflatex. I also tried to automatize this process with sed, since manual changes get overwritten by subsequent diff attempts .. Is anyone aware of other approaches?

jdpipe commented 3 years ago

I see that latexdiff provides an argument --exclude-safecmd... I tried to write a regex to exclude this whole \cmdrule(lr){2-4} thing, but it doesn't seem to work. Anyone have a suggestion?

ftilmann commented 3 years ago

The regex `--exclude-safecmd' only can match the command string not the command including its arguments. I think the only way to do this currently is processing outside latexdiff. I see that there is a lot of interest in this issue. To tackle this, it would be helpful to get a (failing) MWE, and I encourage everyone following this issue to post one. @cgundogan could you post your sed script here?

cgundogan commented 3 years ago

I see that there is a lot of interest in this issue.

I would much appreciate this feature. I tried to look into the source file, but only to discover that I'd need quite some time to get accustomed to perl (:

I generally use something along the line of the following gist to remove any DIF from \cmidrule:

function filter () {
    sed -i 's/cmidrule\\DIFaddFL{\((.*)\)}{\\DIFaddFL{\(.*\)}}/cmidrule\1{\2}/g' $1
}

latexdiff-vc --force -t UNDERLINE --git --flatten -r ${SUBMISSION} main.tex
filter main-diff${SUBMISSION}.tex
pdflatex -interaction=nonstopmode main-diff${SUBMISSION}.tex

I'll try to provide a MWE later in the evening.

ORippler commented 2 years ago

I took the time to provide a brief MWE.

Calling latexdiff old.tex new.tex > diff.tex results in a broken diff.tex with \DIFaddbeginFL \cmidrule\DIFaddFL{(lr)}{\DIFaddFL{1-3}} being the cause (should be \cmidrule(lr)\DIFaddFL{1-3}).

Version of latexdiff was

This is LATEXDIFF 1.3.2 (Algorithm::Diff 1.15 so, Perl v5.32.1)
  (c) 2004-2021 F J Tilmann

However, note that the filter provided by @cgundogan does not cover all edge-cases, here are some more I have excerpted from a manuscript of mine.

\cmidrule( \DIFaddbeginFL \DIFaddFL{lr)}\DIFaddendFL { \DIFaddbeginFL \DIFaddFL{2-3}\DIFaddendFL }
\DIFaddbeginFL \cmidrule\DIFaddFL{(l}\DIFaddendFL ){ \DIFaddbeginFL \DIFaddFL{4-7}\DIFaddendFL }
\cmidrule(lr){ \DIFaddbeginFL \DIFaddFL{4-9}\DIFaddendFL }
\cmidrule(l){ \DIFaddbeginFL \DIFaddFL{10-15}\DIFaddendFL }

Is there a way to exclude cmidrule alltogether from markups/latexdiff. How could one best achieve this ? A potential first regex would be cmidrule(\(?l?r?\)?)\{\d\d?\d?-\d?\d?\d?\}