[LON-CAPA-cvs] cvs: loncom /xml/algebra AlgParser.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 13 Mar 2006 19:23:50 -0000


albertel		Mon Mar 13 14:23:50 2006 EDT

  Modified files:              
    /loncom/xml/algebra	AlgParser.pm 
  Log:
  - BUG#4695, some paren where incorrectly being removed
  
  
Index: loncom/xml/algebra/AlgParser.pm
diff -u loncom/xml/algebra/AlgParser.pm:1.14 loncom/xml/algebra/AlgParser.pm:1.15
--- loncom/xml/algebra/AlgParser.pm:1.14	Wed Jun  8 22:35:55 2005
+++ loncom/xml/algebra/AlgParser.pm	Mon Mar 13 14:23:46 2006
@@ -482,23 +482,24 @@
 # print STDERR Data::Dumper->Dump([@_]);
   my($self) = shift;
   my($type, @args) = @$self;
+
   local $_;
   $_ = $type;
   /binop1/ && do {
     my ($p1, $p2) = ('','');
-    if ($args[2]->[0] eq 'binop1') {($p1,$p2)=qw{ ( ) };}
+    if ($args[2]->[0] eq 'binop1') {($p1,$p2)=qw{ [ ] };}
     return ($args[1]->tostring() . $args[0] . $p1 .
             $args[2]->tostring() . $p2);
   };
   /unop1/ && do {
     my ($p1, $p2) = ('','');
-    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ ( ) };}
+    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ [ ] };}
     return ($args[0] . $p1 . $args[1]->tostring() . $p2);
   };
   /binop2/ && do {
     my ($p1, $p2, $p3, $p4)=('','','','');
     if ($args[0] =~ /implicit/) {$args[0] = ' ';}
-    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ ( ) };}
+    if ($args[1]->[0] =~ /binop1/) {($p1,$p2)=qw{ [ ] };}
 #    if ($args[2]->[0] =~ /binop[12]/) {($p3,$p4)=qw{ ( ) };}
     if ($args[2]->[0] =~ /binop[12]|unop1/) {($p3,$p4)=qw{ ( ) };}
     return ($p1 . $args[1]->tostring() . $p2 . $args[0] . $p3 .
@@ -518,9 +519,6 @@
   };
   /special|varname|numberE?/ && return $args[0];
   /closep/ && do {
-    my(%close) = %AlgParser::close;
-
-
 
     return ($args[0] . $args[1]->tostring() . $close{$args[0]});
   };
@@ -529,6 +527,7 @@
 sub tolatex {
   my($self) = shift;
   my($type, @args) = @$self;
+
   local $_;
   $_ = $type;
   /binop1/ && do {
@@ -551,17 +550,17 @@
     if ($args[0] eq '/'){
 	return('\frac{'.$lop.'}{'.$rop.'}');
     }
-    elsif ($args[0] eq '*'){
-	return($lop. '\cdot ' .$rop); 
+    my $op = $args[0];
+    if ($args[0] eq '*'){
+	$op = '\cdot ';
     }
-    else{
-	$lop = '\left('.$lop.'\right)' if ($args[1]->[0] =~ /binop1|numberE/);
-	$rop = '\left('.$rop.'\right)' if ($args[2]->[0] =~ /binop[12]|numberE|unop1/);
-	if ($args[0] =~ /implicit/) {
-	    $args[0] = ($lop =~ m/[.0-9]$/ && $rop =~ m/^[-+.0-9]/) ? '\cdot ' : ' ';
-	}
-	return ($lop.$args[0].$rop);
+    $lop = '\left('.$lop.'\right)' if ($args[1]->[0] =~ /binop1|numberE/);
+    $rop = '\left('.$rop.'\right)' if ($args[2]->[0] =~ /binop[12]|numberE|unop1/);
+    if ($args[0] =~ /implicit/) {
+	$op = ($lop =~ m/[.0-9]$/ && $rop =~ m/^[-+.0-9]/) ? '\cdot ' : ' ';
     }
+    return ($lop.$op.$rop);
+
   };
   /binop3/ && do {
     my ($p1, $p2, $p3, $p4)=('','','','');
@@ -626,7 +625,7 @@
   /closep/ && do {
     my($backslash) = '';
     if ($args[0] eq '{') {$backslash = '\\';}
-#This is for editors to match: }
+#This is for editors to match: }     
     return ('\left' . $backslash . $args[0] . $args[1]->tolatex() .
             '\right' . $backslash . $close{$args[0]});
   };