Skip to content

Commit

Permalink
alignat is now parsed correctly even if they are fractions nearby. Fi…
Browse files Browse the repository at this point in the history
…xes issue #65
  • Loading branch information
ftilmann committed Nov 25, 2016
1 parent 42f1034 commit e39bf4e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
31 changes: 18 additions & 13 deletions latexdiff
Original file line number Diff line number Diff line change
Expand Up @@ -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*********************
}
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions testsuite/alignat-new.tex
Original file line number Diff line number Diff line change
@@ -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}

18 changes: 18 additions & 0 deletions testsuite/alignat-old.tex
Original file line number Diff line number Diff line change
@@ -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}

2 changes: 1 addition & 1 deletion testsuite/verify
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit e39bf4e

Please sign in to comment.