Skip to content

Commit

Permalink
Fix further unescaped left brace warnings; fixes issue #61
Browse files Browse the repository at this point in the history
  • Loading branch information
ftilmann committed Oct 10, 2016
1 parent cfe445c commit a83d9cb
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions latexdiff
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,15 @@ if ($graphicsmarkup != NONE ) {
# is not compatible with this.
# (A more elegant solution would be to suppress the redefinitions of the \DIFaddbeginFL etc commands, but for this narrow use case
# I currently don't see this as an efficient use of time)
foreach my $cmd ( "DIFaddbegin","DIFaddend","DIFdelbegin","DIFdelend" ) {
@matches=( $latexdiffpreamble =~ m/command{\\DIFaddbeginFL}{($pat_n)}/sg ) ;
# we look at the last one of the list to take into account possible redefinition but almost always matches should have exactly one elemen
if ( $matches[$#matches] =~ m/\\DIFaddbegin/ ) {
die "Cannot combine graphics markup with float styles defining \\DIFaddbeginFL in terms of \\DIFaddbegin. Use --graphics-markup=none option or choose a different float style.";
exit 10;
}
### The foreach loop does not make sense here. I don't know why I put this in - (F Tilmann)
###foreach my $cmd ( "DIFaddbegin","DIFaddend","DIFdelbegin","DIFdelend" ) {
@matches=( $latexdiffpreamble =~ m/command\{\\DIFaddbeginFL}{($pat_n)}/sg ) ;
# we look at the last one of the list to take into account possible redefinition but almost always matches should have exactly one element
if ( $matches[$#matches] =~ m/\\DIFaddbegin/ ) {
die "Cannot combine graphics markup with float styles defining \\DIFaddbeginFL in terms of \\DIFaddbegin. Use --graphics-markup=none option or choose a different float style.";
exit 10;
}
###}
$latexdiffpreamble .= join "\n",("\\newcommand{\\DIFscaledelfig}{$SCALEDELGRAPHICS}",extrapream("HIGHLIGHTGRAPHICS"),"");

# only change required for highlighting both is to declare \includegraphics safe, as preamble already contains commands for deleted environment
Expand Down Expand Up @@ -2048,15 +2049,15 @@ sub marktags {
sub take_comments_and_enter_from_frac() {
###*************take the \n and % between frac and {}***********
###notice all of the substitution are made none global
while( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\frac(([\s]*%[^\n]*?)*[\r\n|\r|\n])+\{(.*?)\\end{\1}/s ) {
while( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\frac(([\s]*%[^\n]*?)*[\r\n|\r|\n])+\{(.*?)\\end\{\1}/s ) {
### if there isn't any % or \n in the pattern $2 then there should be an \\end{...} in $2
if( $2 !~ m/\\end{$1}/s ) {
if( $2 !~ m/\\end\{$1}/s ) {
### take out % and \n from the next match only (none global)
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\frac(([\s]*%[^\n]*?)*[\r\n|\r|\n])+\{(.*?)\\end{\1}/\\begin{$1}$2\\frac{$5\\end{$1}/s;
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\frac(([\s]*%[^\n]*?)*[\r\n|\r|\n])+\{(.*?)\\end\{\1}/\\begin{$1}$2\\frac{$5\\end{$1}/s;
}
else{
###there are no more % and \n in $2, we want to find the next one so we clear the begin-end from the pattern
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end{\1}/MATHBLOCK$1$2MATHBLOCKEND/s;
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end\{\1}/MATHBLOCK$1$2MATHBLOCKEND/s;
}
}
###cleaning up
Expand All @@ -2070,18 +2071,18 @@ sub take_comments_and_enter_from_frac() {
### from now on CURRFRAC is the frac we are looking at
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)\\frac\{(.*?)\\end\{\1\}/\\begin\{$1\}$2CURRFRAC\{$3\\end\{$1\}/s;
while( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)CURRFRAC\{(.*?)\\end\{\1\}/s ) {
if( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)CURRFRAC\{($pat_n)\}([\s]*(%[^\n]*?)*[\r\n|\r|\n])+[\s]*\{(.*?)\\end{\1}/s ) {
if( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)CURRFRAC\{($pat_n)\}([\s]*(%[^\n]*?)*[\r\n|\r|\n])+[\s]*\{(.*?)\\end\{\1}/s ) {
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)CURRFRAC\{($pat_n)\}([\s]*(%[^\n]*?)*[\r\n|\r|\n])+[\s]*\{(.*?)\\end\{\1\}/\\begin\{$1\}$2CURRFRAC\{$3\}\{$6\\end\{$1\}/s;
}
else { # there is no comment or \n between the two brackets {}{}
### change CURRFRAC to FRACSTART so we can change them all back to //frac{ when we finish
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)CURRFRAC\{(.*?)\\end{\1}/\\begin{$1}$2FRACSTART\{$3\\end{$1}/s;
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)CURRFRAC\{(.*?)\\end\{\1}/\\begin{$1}$2FRACSTART\{$3\\end{$1}/s;
}
}
}
else{
###there are no more frac in $2, we want to find the next one so we clear the begin-end from the pattern
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end{\1}/MATHBLOCK$1$2MATHBLOCKEND/s;
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end\{\1}/MATHBLOCK$1$2MATHBLOCKEND/s;
}

}
Expand Down Expand Up @@ -2158,16 +2159,16 @@ sub preprocess {
s/(?<!\\)\\\[/\\begin{SQUAREBRACKET}/sg;
s/\\\]/\\end{SQUAREBRACKET}/sg;
# Convert all picture environmentent (\begin{PICTUREENV} .. \end{PICTUREENV} \PICTUREBLOCKenv
s/\\begin\{($PICTUREENV)}(.*?)\\end{\1}/\\PICTUREBLOCK$1\{$2\}/sg;
s/\\begin\{($PICTUREENV)}(.*?)\\end\{\1}/\\PICTUREBLOCK$1\{$2\}/sg;
# For --block-math-markup option -convert all \begin{MATH} .. \end{MATH}
# into \MATHBLOCKMATH{...} commands, where MATH is any valid math environment
# Also convert all array environments into ARRAYBLOCK environments
if ( $mathmarkup != FINE ) {
s/\\begin\{($ARRENV)}(.*?)\\end{\1}/\\ARRAYBLOCK$1\{$2\}/sg;
s/\\begin\{($ARRENV)}(.*?)\\end\{\1}/\\ARRAYBLOCK$1\{$2\}/sg;

take_comments_and_enter_from_frac();

s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end{\1}/\\MATHBLOCK$1\{$2\}/sg;
s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end\{\1}/\\MATHBLOCK$1\{$2\}/sg;
}
# add final token " STOP"
$_ .= " STOP"
Expand Down Expand Up @@ -2521,8 +2522,8 @@ sub postprocess {
# is not globally minimal but only 'locally' (matching is beginning from the left side of the string)
### print STDERR "DEBUG: before mathmode replacement\n $_ ------------ \n";
if ( $mathmarkup == FINE ) {
1 while s/\\begin\{((?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}((?:.(?!(?:\\end{(?:(?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}|\\begin\{MATHMODE})))*?)\\end{MATHMODE}/\\begin{$1}$2\\end{$1}/s;
1 while s/\\begin\{MATHMODE}((?:.(?!\\end{MATHMODE}))*?)\\end{((?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}/\\begin{$2}$1\\end{$2}/s;
1 while s/\\begin\{((?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}((?:.(?!(?:\\end\{(?:(?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}|\\begin\{MATHMODE})))*?)\\end\{MATHMODE}/\\begin{$1}$2\\end{$1}/s;
1 while s/\\begin\{MATHMODE}((?:.(?!\\end\{MATHMODE}))*?)\\end\{((?:$MATHENV)|(?:$MATHARRENV)|SQUAREBRACKET)}/\\begin{$2}$1\\end{$2}/s;
# convert remaining \begin{MATHMODE} \end{MATHMODE} (and not containing & or \\ )into MATHREPL environments
s/\\begin\{MATHMODE\}((?:(.(?!(?<!\\)\&|\\\\))*)?)\\end\{MATHMODE\}/\\begin{$MATHREPL}$1\\end{$MATHREPL}/sg;
# others into MATHARRREPL
Expand Down

0 comments on commit a83d9cb

Please sign in to comment.