From 035b8e742e2dbc92fbe4cc3d7ba491f8176ca2d1 Mon Sep 17 00:00:00 2001 From: Frederik Tilmann Date: Thu, 29 Dec 2016 15:37:36 +0100 Subject: [PATCH] avoid check for file when adding known commands to safecmd, textcmd etc list. Might fix issue #70 --- latexdiff | 154 ++++++++++++++++++++---------------- testsuite/endfloat2-old.tex | 2 +- testsuite/safecmd-new.tex | 8 ++ testsuite/safecmd-old.tex | 5 ++ testsuite/verify | 2 +- 5 files changed, 100 insertions(+), 71 deletions(-) create mode 100644 testsuite/safecmd-new.tex create mode 100644 testsuite/safecmd-old.tex diff --git a/latexdiff b/latexdiff index 860fd46..6e6fca1 100755 --- a/latexdiff +++ b/latexdiff @@ -32,6 +32,7 @@ # # Version 1.2.1a # - bug fix: deleted figures when endfloat package was activated +# - bug fix: alignat environment now always processed correctly (fix issues #65) # # Version 1.2.0: # - highlight new and deleted figures @@ -845,7 +846,7 @@ if ($graphicsmarkup != NONE ) { # only change required for highlighting both is to declare \includegraphics safe, as preamble already contains commands for deleted environment if ( $graphicsmarkup == BOTH ) { - init_regex_arr_ext(\@SAFECMDLIST,'includegraphics'); + init_regex_arr_list(\@SAFECMDLIST,'includegraphics'); } } @@ -921,11 +922,11 @@ if (defined $packages{"siunitx"} ) { # this is done to get around an incompatibility between the ulem and siunitx package print STDERR "siunitx package detected.\n" if $verbose ; my $mboxcmds='SI,ang,numlist,numrange,SIlist,SIrange'; - init_regex_arr_ext(\@SAFECMDLIST,'num,si'); + init_regex_arr_list(\@SAFECMDLIST,'num,si'); if ( $enablecitmark || ( $ulem && ! $disablecitmark )) { - init_regex_arr_ext(\@MBOXCMDLIST,$mboxcmds); + init_regex_arr_list(\@MBOXCMDLIST,$mboxcmds); } else { - init_regex_arr_ext(\@SAFECMDLIST,$mboxcmds); + init_regex_arr_list(\@SAFECMDLIST,$mboxcmds); } } @@ -935,9 +936,9 @@ if (defined $packages{"cleveref"} ) { print STDERR "cleveref package detected.\n" if $verbose ; my $mboxcmds='[Cc]ref(?:range)?\*?,labelcref,(?:lc)?name[cC]refs?' ; if ( $enablecitmark || ( $ulem && ! $disablecitmark )) { - init_regex_arr_ext(\@MBOXCMDLIST,$mboxcmds); + init_regex_arr_list(\@MBOXCMDLIST,$mboxcmds); } else { - init_regex_arr_ext(\@SAFECMDLIST,$mboxcmds); + init_regex_arr_list(\@SAFECMDLIST,$mboxcmds); } } @@ -946,17 +947,17 @@ if (defined $packages{"glossaries"} ) { # this is done to get around an incompatibility between ulem and glossaries package print STDERR "glossaries package detected.\n" if $verbose ; my $mboxcmds='[gG][lL][sS](?:|pl|disp|link|first|firstplural|desc|user[iv][iv]?[iv]?),[aA][cC][rR](?:long|longpl|full|fullpl),[aA][cC][lfp]?[lfp]?'; - init_regex_arr_ext(\@SAFECMDLIST,'[gG][lL][sS](?:(?:entry)?(?:text|plural|name|symbol)|displaynumberlist|entryfirst|entryfirstplural|entrydesc|entrydescplural|entrysymbolplural|entryuser[iv][iv]?[iv]?|entrynumberlist|entrydisplaynumberlist|entrylong|entrylongpl|entryshort|entryshortpl|entryfull|entryfullpl),[gG]lossentry(?:name|desc|symbol),[aA][cC][rR](?:short|shortpl),[aA]csp?'); + init_regex_arr_list(\@SAFECMDLIST,'[gG][lL][sS](?:(?:entry)?(?:text|plural|name|symbol)|displaynumberlist|entryfirst|entryfirstplural|entrydesc|entrydescplural|entrysymbolplural|entryuser[iv][iv]?[iv]?|entrynumberlist|entrydisplaynumberlist|entrylong|entrylongpl|entryshort|entryshortpl|entryfull|entryfullpl),[gG]lossentry(?:name|desc|symbol),[aA][cC][rR](?:short|shortpl),[aA]csp?'); if ( $enablecitmark || ( $ulem && ! $disablecitmark )) { - init_regex_arr_ext(\@MBOXCMDLIST,$mboxcmds); + init_regex_arr_list(\@MBOXCMDLIST,$mboxcmds); } else { - init_regex_arr_ext(\@SAFECMDLIST,$mboxcmds); + init_regex_arr_list(\@SAFECMDLIST,$mboxcmds); } } if (defined $packages{"chemformula"} or defined $packages{"chemmacros"} ) { print STDERR "chemformula package detected.\n" if $verbose ; - init_regex_arr_ext(\@SAFECMDLIST,'ch'); + init_regex_arr_list(\@SAFECMDLIST,'ch'); push(@UNSAFEMATHCMD,'ch'); # The next command would be needed to allow highlighting the interior of \ch commands in math environments # but the redefinitions in chemformula are too deep to make this viable @@ -965,7 +966,7 @@ if (defined $packages{"chemformula"} or defined $packages{"chemmacros"} ) { if (defined $packages{"mhchem"} ) { print STDERR "mhchem package detected.\n" if $verbose ; - init_regex_arr_ext(\@SAFECMDLIST,'ce'); + init_regex_arr_list(\@SAFECMDLIST,'ce'); push(@UNSAFEMATHCMD,'ce','cee'); # The next command would be needed to allow highlighting the interior of \cee commands in math environments # but the redefinitions in chemformula are too deep to make this viable @@ -1020,7 +1021,7 @@ if (defined $packages{"amsmath"} or defined $packages{"amsart"} or defined $pac # add commands in MBOXCMDLIST to SAFECMDLIST foreach $mboxcmd ( @MBOXCMDLIST ) { - init_regex_arr_ext(\@SAFECMDLIST, $mboxcmd); + init_regex_arr_list(\@SAFECMDLIST, $mboxcmd); } # check if \label is in SAFECMDLIST, and if yes replace "label" in $LABELCMD by something that never matches (we hope!) @@ -1180,53 +1181,45 @@ sub list_packages { # scans the argument for \newcommand and \DeclareMathOperator, # and adds the created commands which are clearly safe to @SAFECMDLIST sub add_safe_commands { -### my (@preamble)=@_; my ($preamble)=@_; - my $added_command = 1; + # get rid of comments $preamble=~s/(?) { - chomp; - next if /^\s*#/ || /^\s*%/ || /^\s*$/ ; - push (@$arr,qr/^$_$/); - } - close(FILE); + if ( -f $arg ) { + init_regex_arr_file($arr,$arg); + } else { + init_regex_arr_list($arr,$arg); } - else { - # assume it is a comma-separated list of reg-ex -### print STDERR "DEBUG init_regex_arr_ext arg >$arg<\n"; - foreach $regex (split(qr/(?) { + chomp; + next if /^\s*#/ || /^\s*%/ || /^\s*$/ ; + push (@$arr,qr/^$_$/); } + close(FILE); } +# init_regex_arr_list(\@array,$arg) +# appends array with regular expressions. +# read from comma separated list of regular expressions ($arg) +sub init_regex_arr_list { + my ($arr,$arg)=@_; + my $regex; + ### print STDERR "DEBUG init_regex_arr_list arg >$arg<\n" if $debug; + foreach $regex (split(qr/(?