Skip to content

Commit

Permalink
modify patch for multiline CUSTOMDIFCMD, fixes issue ftilmann#204
Browse files Browse the repository at this point in the history
  • Loading branch information
ftilmann committed Jul 3, 2020
1 parent 4b12356 commit 75fb55d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
18 changes: 13 additions & 5 deletions latexdiff
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
### - --flatten option only expands first including command per line if there is more than one
### - move --show-xxx options so that they are also capable of showing preamble (and commands) after all modificationsbased on source file packages
### - change meaning of --packages option such that this packages are used in addition of automatically detected packages (possibly introduce option --only-packages that overrides automatic choices completely

# Version 1.3.2
# - extend CUSTOMDIFCMD related postprocessing to deal properly with multiline commands, or a sequence of several commands in the same line (see github issue #204)
#
# Version 1.3.1.1
# - remove spurious \n to fix error: Unknown regexp modifier "/n" at .../latexdiff line 1974, near "=~ " (see github issue #201)
#
Expand Down Expand Up @@ -212,7 +214,7 @@ my ($algodiffversion)=split(/ /,$Algorithm::Diff::VERSION);


my ($versionstring)=<<EOF ;
This is LATEXDIFF 1.3.1.1 (Algorithm::Diff $Algorithm::Diff::VERSION, Perl $^V)
This is LATEXDIFF 1.3.2a (Algorithm::Diff $Algorithm::Diff::VERSION, Perl $^V)
(c) 2004-2020 F J Tilmann
EOF

Expand Down Expand Up @@ -1558,7 +1560,8 @@ sub add_safe_commands {
print STDERR "DEBUG Checking new command: maybe_to_test, should_be_safe: $1 $2\n" if $debug;
my $success = 0;
# skip custom diff commands
next if ($maybe_to_test =~ m/^${CUSTOMDIFCMD}$/);
next if ($maybe_to_test =~ m/^(?:ADD|DEL)?${CUSTOMDIFCMD}$/);
###print STDERR "DEBUG: really test it. \n";
# test if all latex commands inside it are safe
$success = 1;
if ($should_be_safe =~ m/\\\\/) {
Expand Down Expand Up @@ -3025,7 +3028,12 @@ sub postprocess {
# Mark deleted verbose commands
$delblock =~ s/(${DELCMDOPEN}\\DIF((?:verb\*?|lstinline(?:\[$brat_n\])?)\{([-\d]*?)\}\s*).*)$/%\n\\DIFDIFdel$2${AUXCMD}\n$1/gm;
if ( $CUSTOMDIFCMD ) {
$delblock =~ s/(${DELCMDOPEN}.*)\\($CUSTOMDIFCMD)((?:\[${brat_n}\])*?(?:\s*\{${pat_n}\})*)/"$1${DELCMDCLOSE}\\DEL$2". stripdelcmdopen($3) ." ${DELCMDOPEN}"/egms;
###$delblock =~ s/(${DELCMDOPEN}.*)\\($CUSTOMDIFCMD)((?:\[${brat_n}\])*?(?:\s*\{${pat_n}\})*)/"$1${DELCMDCLOSE}\\DEL$2". stripdelcmdopen($3) ." ${DELCMDOPEN}"/egms;
###$delblock =~ s/(${DELCMDOPEN}.*)\\($CUSTOMDIFCMD)/$1${DELCMDCLOSE}\\DEL$2/gm;
# ($1 ? "${DELCMDOPEN}$1${DELCMDCLOSE}":"") : only add the DELCMDOPEN / DELCMDCLOSE pair if there are actually any commands in between, otherwise this is redundant
$delblock =~ s/${DELCMDOPEN}(.*?)\\($CUSTOMDIFCMD)((?:\[${brat_n}\])*?(?:\s*\{${pat_n}\})*)/($1 ? "${DELCMDOPEN}$1${DELCMDCLOSE}":"") ."\\DEL$2". stripdelcmdopen($3)/egs;
# if there is a sequence of several commands in the same row only the first will be converted due to the need to be connected to the DELCMDOPEN. To mop these up, just add the DEL to the front of any remaining cmd's in the deleted block
$delblock =~ s/\\($CUSTOMDIFCMD)/\\DEL$1/g; # this will also convert comments but I guess it does not matter much
}
# splice in modified delblock
Expand Down Expand Up @@ -3072,7 +3080,7 @@ sub postprocess {
$addblock =~ s/\\DIFverb/\\DIFDIFaddverb/g;
$addblock =~ s/\\DIFlstinline/\\DIFDIFaddlstinline/g;
if( $CUSTOMDIFCMD ) {
$addblock =~ s/\\($CUSTOMDIFCMD)/\\ADD$1/g;
$addblock =~ s/\\($CUSTOMDIFCMD)/\\ADD$1/g; # this will also convert comments but I guess it does not matter much
}
# markup the optional arguments of \item
$addblock =~ s/(\\$ITEMCMD$extraspace(?:<$abrat0>)?$extraspace)\[($brat_n)\]/
Expand Down
5 changes: 5 additions & 0 deletions testsuite/customdiffcmdtest-new.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
\newcommand{\donothing}[1]{#1}
\newcommand{\ADDdonothing}[1]{{\color{blue}\donothing{#1}}}
\newcommand{\DELdonothing}[1]{{\color{red}\donothing{#1}}}
\newcommand{\cmd}[1]{#1}
\newcommand{\ADDcmd}[1]{\textcolor{blue}{#1}}
\newcommand{\DELcmd}[1]{\textcolor{red}{#1}}

\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
Expand All @@ -12,5 +15,7 @@
\newcommand{\DELmypar}{\paragraph{\DIFdel{MYPAR}}}
\newcommand{\ADDmypar}{\paragraph{\DIFadd{MYPAR}}}
\begin{document}
\cmd{Test1}
\cmd{Test5}
\end{document}

10 changes: 10 additions & 0 deletions testsuite/customdiffcmdtest-old.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
\newcommand{\donothing}[1]{#1}
\newcommand{\ADDdonothing}[1]{{\color{blue}\donothing{#1}}}
\newcommand{\DELdonothing}[1]{{\color{red}\donothing{#1}}}
\newcommand{\cmd}[1]{#1}
\newcommand{\ADDcmd}[1]{\textcolor{blue}{#1}}
\newcommand{\DELcmd}[1]{\textcolor{red}{#1}}

\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
Expand All @@ -22,5 +25,12 @@

}


\cmd{Test1}
\cmd{Test2}\cmd{Test3}
\cmd{Test4}



\end{document}

2 changes: 1 addition & 1 deletion testsuite/verify
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set testroots=( test rapine_et_al island_obs2004 texdiffsample gershwin12 "gersh
delequ latin9 pollack move-equation nomarkup subscript doubledollar intertext \
DIFDELCMDBUG eqnarray eqnarray2 subscriptm delequ2 schneider gennady umesh underwood endfloat endfloat2 outerrise \
delequ3 delequ4 "simplefrac --allow-spaces" "master --flatten" "subfile --flatten" titlediffTest2 exampleDiff bornd2 \
"rolla --math-markup=2" mini "complex-maths --math-markup=1" margalit circonflex mwe-comment "apacite-test --flatten" quoteddollarunderscore units complicated-math move-equation2 lists "figures --graphics-markup=both" alignat "safecmd --append-safecmd=remark" verbatim verbatim2-is143 embedded-math-array "verbatim-input --flatten" anchordemo 'customdiffcmdtest --add-to-config "CUSTOMDIFCMD=blindtext;mypar;donothing"' description frac_w_space_comments \
"rolla --math-markup=2" mini "complex-maths --math-markup=1" margalit circonflex mwe-comment "apacite-test --flatten" quoteddollarunderscore units complicated-math move-equation2 lists "figures --graphics-markup=both" alignat "safecmd --append-safecmd=remark" verbatim verbatim2-is143 embedded-math-array "verbatim-input --flatten" anchordemo 'customdiffcmdtest --add-to-config "CUSTOMDIFCMD=blindtext;mypar;donothing;cmd"' description frac_w_space_comments \
"href-in-bibliography --append-safecmd=path" revtex-bibliography \
)

Expand Down

0 comments on commit 75fb55d

Please sign in to comment.