From e39bf4e6b7e4520df3a1de20c02fdca2bd144638 Mon Sep 17 00:00:00 2001 From: Frederik Tilmann Date: Fri, 25 Nov 2016 15:29:26 +0100 Subject: [PATCH] alignat is now parsed correctly even if they are fractions nearby. Fixes issue #65 --- latexdiff | 31 ++++++++++++++++++------------- testsuite/alignat-new.tex | 18 ++++++++++++++++++ testsuite/alignat-old.tex | 18 ++++++++++++++++++ testsuite/verify | 2 +- 4 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 testsuite/alignat-new.tex create mode 100644 testsuite/alignat-old.tex diff --git a/latexdiff b/latexdiff index 761b959..860fd46 100755 --- a/latexdiff +++ b/latexdiff @@ -2047,47 +2047,49 @@ sub marktags { #used in preprocess sub take_comments_and_enter_from_frac() { - ###*************take the \n and % between frac and {}*********** - ###notice all of the substitution are made none global + #*************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 ) { - ### if there isn't any % or \n in the pattern $2 then there should be an \\end{...} in $2 + # if there isn't any % or \n in the pattern $2 then there should be an \\end{...} in $2 + ### print STDERR "Match the following in take_comments and_enter_from_frac(1):\n****$&****\n" if $debug; if( $2 !~ m/\\end\{$1}/s ) { - ### take out % and \n from the next match only (none global) + # 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; } 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; + #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\{$2\}MATHBLOCKEND/s; } } ###cleaning up - while( s/MATHBLOCK($MATHENV|$MATHARRENV|SQUAREBRACKET)(.*?)MATHBLOCKEND/\\begin{$1}$2\\end{$1}/s ){} + while( s/MATHBLOCK($MATHENV|$MATHARRENV|SQUAREBRACKET)\{(.*?)\}MATHBLOCKEND/\\begin{$1}$2\\end{$1}/s ){} ###*************take the \n and % between frac and {}*********** ###**********take the \n and % between {} and {} of the frac*************** while( m/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)\\frac\{(.*?)\\end\{\1\}/s ) { - ### if there isn't any more //frac before the first //end in the pattern $2 then there should be an \\end{...} in $2 + # if there isn't any more //frac before the first //end in the pattern $2 then there should be an \\end{...} in $2 + ###print STDERR "Match the following in take_comments and_enter_from_frac(2):\n****$&****\n" if $debug; if( $2 !~ m/\\end\{$1\}/s ) { - ### from now on CURRFRAC is the frac we are looking at + # 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 ) { 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 + # 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; } } } 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\{$2\}MATHBLOCKEND/s; } } ###cleaning up - while( s/MATHBLOCK($MATHENV|$MATHARRENV|SQUAREBRACKET)(.*?)MATHBLOCKEND/\\begin{$1}$2\\end{$1}/s ){} + while( s/MATHBLOCK($MATHENV|$MATHARRENV|SQUAREBRACKET)\{(.*?)\}MATHBLOCKEND/\\begin{$1}$2\\end{$1}/s ){} s/FRACSTART/\\frac/g; ###***************take the \n and % between {} and {} of the frac********************* } @@ -2165,10 +2167,13 @@ sub preprocess { # Also convert all array environments into ARRAYBLOCK environments if ( $mathmarkup != FINE ) { s/\\begin\{($ARRENV)}(.*?)\\end\{\1}/\\ARRAYBLOCK$1\{$2\}/sg; + print STDERR "vvvvvvvvvvvvvvvvvv\n$_\nvvvvvvvvvvvvvvvv\n" if $debug; take_comments_and_enter_from_frac(); - s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)}(.*?)\\end\{\1}/\\MATHBLOCK$1\{$2\}/sg; + print STDERR "^^^^^^^^^^^^^^^^^^\n$_\n^^^^^^^^^^^^^^^^^\n" if $debug; + + s/\\begin\{($MATHENV|$MATHARRENV|SQUAREBRACKET)\}(.*?)\\end\{\1\}/\\MATHBLOCK$1\{$2\}/sg; } # add final token " STOP" $_ .= " STOP" diff --git a/testsuite/alignat-new.tex b/testsuite/alignat-new.tex new file mode 100644 index 0000000..8962b09 --- /dev/null +++ b/testsuite/alignat-new.tex @@ -0,0 +1,18 @@ +\documentclass{article} +\usepackage{amsmath} + +\begin{document} + +\begin{alignat}{2} + ... +\end{alignat} + +\begin{equation}\label{eq:elas:C} +\end{equation} + +\begin{equation} + \mu = \frac{E }{2(1+\nu) } +\end{equation} + +\end{document} + diff --git a/testsuite/alignat-old.tex b/testsuite/alignat-old.tex new file mode 100644 index 0000000..fbd893e --- /dev/null +++ b/testsuite/alignat-old.tex @@ -0,0 +1,18 @@ +\documentclass{article} +\usepackage{amsmath} + +\begin{document} + +\begin{alignat}{2} + ... +\end{alignat} + +\begin{equation}\label{eq:elas:C} +\end{equation} + +\begin{equation}\label{eq:elas:lam-mu} + \lambda = \frac{E \nu}{ (1+\nu)(1-2\nu)} \qquad +\end{equation} + +\end{document} + diff --git a/testsuite/verify b/testsuite/verify index 893108a..cc2dffb 100755 --- a/testsuite/verify +++ b/testsuite/verify @@ -20,7 +20,7 @@ set testroots=( test rapine_et_al island_obs2004 texdiffsample gershwin12 "gersh delequ latin9 pollack move-equation nomarkup subscript doubledollar \ DIFDELCMDBUG eqnarray subscriptm delequ2 schneider gennady umesh underwood endfloat endfloat2 outerrise \ delequ3 delequ4 "simplefrac --allow-spaces" "master --flatten" titlediffTest2 exampleDiff bornd2 \ -"rolla --math-markup=2" mini "complex-maths --math-markup=1" margalit circonflex mwe-comment "apacite-test --flatten" quoteddollarunderscore units complicated-math move-equation2 lists "figures --graphics-markup=both"\ +"rolla --math-markup=2" mini "complex-maths --math-markup=1" margalit circonflex mwe-comment "apacite-test --flatten" quoteddollarunderscore units complicated-math move-equation2 lists "figures --graphics-markup=both" alignat \ ) #set testroots= ( test subscript )