Skip to content

Commit

Permalink
Merge pull request #246 from julianuu/master
Browse files Browse the repository at this point in the history
sanitize more possible input schemata of frac
  • Loading branch information
ftilmann authored Dec 12, 2021
2 parents 2b015c5 + 1c9dc55 commit 480d06f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions latexdiff
Original file line number Diff line number Diff line change
Expand Up @@ -2570,15 +2570,15 @@ sub take_comments_and_newline_from_frac() {
# some special magic for common usage of frac, which does not conform to the latexdiff requirements but can be made to fit
# note that this is a rare exception to the general rule that the new tex can be reconstructed from the diff file

# \frac12 -> \frac{1}{2}
s/\\frac(\d)(\w)/\\frac\{$1\}\{$2\}/g;

# \frac1{2b} -> \frac{1}{2b}
s/\\frac(\d)/\\frac\{$1\}/g;

# delete space and comment characters between \frac arguments
# s/\\frac(?:\s*?%[^\n]*?)*?(\{$pat_n\})\s*(\{$pat_n\})/\\frac$1$2/g;
s/\\frac(?:\s|%[^\n]*?)*(\{$pat_n\})(?:\s|%[^\n]*?)*(\{$pat_n\})/\\frac$1$2/g;
# regex that matches space and comment characters
my $space = qr/\s|%[^\n]*?/;
# \frac {abc} -> \frac{abc}
# \frac1 -> \frac{1}
# \frac a -> \frac{a}
# \frac \lambda -> \frac{\lambda}
s/\\frac(?|${space}+\{($pat_n)\}|${space}*(\d)|${space}+(\w)|${space}*(\\[a-zA-Z]+))/\\frac\{$1\}/g;
# same as above for the second argument of frac
s/\\frac(\{$pat_n\})(?|${space}*\{($pat_n)\}|${space}*(\d)|${space}+(\w)|${space}*(\\[a-zA-Z]+))/\\frac$1\{$2\}/g;
}

# preprocess($string, ..)
Expand Down

0 comments on commit 480d06f

Please sign in to comment.