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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 09 Jun 2005 02:35:56 -0000


albertel		Wed Jun  8 22:35:56 2005 EDT

  Modified files:              
    /loncom/xml/algebra	AlgParser.pm 
  Log:
  - grabbing another fix from WeBWorK (rev 1.6+ 1.7 plus my own cleanup)
  
  
Index: loncom/xml/algebra/AlgParser.pm
diff -u loncom/xml/algebra/AlgParser.pm:1.13 loncom/xml/algebra/AlgParser.pm:1.14
--- loncom/xml/algebra/AlgParser.pm:1.13	Wed Jun  8 22:17:12 2005
+++ loncom/xml/algebra/AlgParser.pm	Wed Jun  8 22:35:55 2005
@@ -547,34 +547,20 @@
     return ($args[0] . $p1 . $args[1]->tolatex() . $p2);
   };
   /binop2/ && do {
-    my ($p1, $p2, $p3, $p4) = ('','','','');
-    if ($args[0] =~ /implicit/) {
-      if ( (($args[1]->head eq qq(number)) &&
-            ($args[2]->head eq qq(number))) ||
-           (($args[1]->head eq qq(binop2)) &&
-            ($args[1]->[2]->head eq qq(number))) ) {
-        $args[0] = '\\,';
-      } else {
-        $args[0] = ' ';
-      }
-    }
-    if ($args[1]->[0] =~ /binop1|numberE/)
-      {($p1,$p2)=qw{ \left( \right) };}
- #   if ($args[2]->[0] =~ /binop[12]|numberE/)
-	if ($args[2]->[0] =~ /binop[12]|numberE|unop1/)
-      {($p3,$p4)=qw{ \left( \right) };}
+    my ($lop,$rop) = ($args[1]->tolatex,$args[2]->tolatex);
     if ($args[0] eq '/'){
-#	return('\frac{' . $p1 . $args[1]->tolatex() . $p2 . '}'.
-#               '{' . $p3 . $args[2]->tolatex() . $p4 . '}' );
-	return('\frac{' . $args[1]->tolatex() . '}'.
-               '{' . $args[2]->tolatex() . '}' ); 
+	return('\frac{'.$lop.'}{'.$rop.'}');
     }
     elsif ($args[0] eq '*'){
-	return($args[1]->tolatex() . '\cdot ' . $args[2]->tolatex() ); 
+	return($lop. '\cdot ' .$rop); 
     }
     else{
-    return ($p1 . $args[1]->tolatex() . $p2 . $args[0] . $p3 .
-            $args[2]->tolatex() . $p4);
+	$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);
     }
   };
   /binop3/ && do {