From c2cdaa56611c76c905c2368bee53c7bf8e7f8428 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Sat, 6 Nov 2021 17:31:28 +0200 Subject: [PATCH 1/3] sanitizing more possible input schemata of frac --- latexdiff | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/latexdiff b/latexdiff index a7a27da..7f93773 100755 --- a/latexdiff +++ b/latexdiff @@ -2570,11 +2570,12 @@ 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; + # \frac1 -> \frac{1} + # \frac a -> \frac{a} + # \frac \lambda -> \frac{\lambda} + s/\\frac(?:\s*(\d)|\s+(\w)|\s*(\\[a-zA-Z]+))/\\frac\{$1$2$3\}/g; + # same as above for the second argument of frac + s/\\frac(\{$pat_n\})(?:\s*(\d)|\s+(\w)|\s*(\\[a-zA-Z]+))/\\frac$1\{$2$3$4\}/g; # delete space and comment characters between \frac arguments # s/\\frac(?:\s*?%[^\n]*?)*?(\{$pat_n\})\s*(\{$pat_n\})/\\frac$1$2/g; From f7ee1d57770911270bf87f506ce170fe841c9e90 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Sat, 6 Nov 2021 20:21:35 +0200 Subject: [PATCH 2/3] make frac sanitization work for comments plus newlines too --- latexdiff | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/latexdiff b/latexdiff index 7f93773..01c5684 100755 --- a/latexdiff +++ b/latexdiff @@ -2570,16 +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 + # 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(?:\s*(\d)|\s+(\w)|\s*(\\[a-zA-Z]+))/\\frac\{$1$2$3\}/g; + s/\\frac(?:${space}+\{($pat_n)\}|${space}*(\d)|${space}+(\w)|${space}*(\\[a-zA-Z]+))/\\frac\{$1$2$3$4\}/g; # same as above for the second argument of frac - s/\\frac(\{$pat_n\})(?:\s*(\d)|\s+(\w)|\s*(\\[a-zA-Z]+))/\\frac$1\{$2$3$4\}/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; + s/\\frac(\{$pat_n\})(?:${space}*\{($pat_n)\}|${space}*(\d)|${space}+(\w)|${space}*(\\[a-zA-Z]+))/\\frac$1\{$2$3$4$5\}/g; } # preprocess($string, ..) From 1c9dc55b1d3ee772f73009963ac3b60ac752ff0a Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Mon, 8 Nov 2021 13:35:32 +0200 Subject: [PATCH 3/3] fix uninitialized value warning --- latexdiff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latexdiff b/latexdiff index 01c5684..b365c9c 100755 --- a/latexdiff +++ b/latexdiff @@ -2576,9 +2576,9 @@ sub take_comments_and_newline_from_frac() { # \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$2$3$4\}/g; + 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$3$4$5\}/g; + s/\\frac(\{$pat_n\})(?|${space}*\{($pat_n)\}|${space}*(\d)|${space}+(\w)|${space}*(\\[a-zA-Z]+))/\\frac$1\{$2\}/g; } # preprocess($string, ..)