latexdiff icon indicating copy to clipboard operation
latexdiff copied to clipboard

error with booktabs

Open ajshephard opened this issue 7 years ago • 8 comments

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}}

ajshephard avatar Aug 14 '17 14:08 ajshephard

+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.

alexpacini avatar Sep 26 '17 12:09 alexpacini

@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.

ftilmann avatar Sep 26 '17 12:09 ftilmann

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).

alexpacini avatar Sep 26 '17 13:09 alexpacini

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?

cgundogan avatar Jun 01 '21 13:06 cgundogan

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?

jdpipe avatar Jun 23 '21 11:06 jdpipe

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?

ftilmann avatar Jun 23 '21 12:06 ftilmann

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.

cgundogan avatar Jun 23 '21 12:06 cgundogan

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?\}

ORippler avatar Feb 01 '22 11:02 ORippler