Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize more possible input schemata of frac #246

Merged
merged 3 commits into from
Dec 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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