[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /html/res/adm/pages/reactionresponse reaction_editor.html

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 29 Mar 2005 17:57:52 -0000


albertel		Tue Mar 29 12:57:52 2005 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm 
    /loncom/html/res/adm/pages/reactionresponse	reaction_editor.html 
  Log:
  - BUG#4035, buy Guy Ash.
     1. Rational coefficients are now supported (e.g. Na + 1/2Cl2 -> NaCl )
     2. Hydrates are now supported (e.g. CuSO4.5H2O )
  
  
  
  
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.95 loncom/homework/default_homework.lcpm:1.96
--- loncom/homework/default_homework.lcpm:1.95	Mon Mar 28 14:20:54 2005
+++ loncom/homework/default_homework.lcpm	Tue Mar 29 12:57:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.95 2005/03/28 19:20:54 albertel Exp $
+# $Id: default_homework.lcpm,v 1.96 2005/03/29 17:57:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -529,13 +529,17 @@
 
 sub chemparse {
     my ($reaction) = @_;
-    my @tokens = split(/(\s\+|\->|<=>)/,$reaction);
+    my @tokens = split(/(\s\+|\->|<=>|<\-|\.)/,$reaction);
     my $formula = '';
     foreach my $token (@tokens) {
 	if ($token eq '->' ) {
 	    $formula .= '<m>\ensuremath{\rightarrow}</m> ';
 	    next;
 	}
+	if ($token eq '<-' ) {
+	    $formula .= '<m>\ensuremath{\leftarrow}</m> ';
+	    next;
+	}  
 	if ($token eq '<=>') {
 	    if ($external::target eq 'web' &&
 		&EXT('request.browser.unicode')) {
@@ -546,7 +550,12 @@
 	    }
 	    next;
 	}
-	$token =~ /^\s*(\d*(?:&frac\d\d)?)(.*)/;
+	if ($token eq '.') {
+	  $formula =~ s/(\&nbsp\;| )$//;
+	  $formula .= '&middot;';
+	  next;
+	}
+	$token =~ /^\s*([\d|\/]*(?:&frac\d\d)?)(.*)/;
         $formula .= $1 if ($1 ne '1');  # stoichiometric coefficient
 	
 	my $molecule = $2;
@@ -558,6 +567,7 @@
 	$molecule =~ s/\s*//g;
 	# forced space
 	$molecule =~ s/_/ /g;
+	$molecule =~ s/-/&minus;/g;
 	$formula .= $molecule.'&nbsp;';
     }
     # get rid of trailing space
Index: loncom/html/res/adm/pages/reactionresponse/reaction_editor.html
diff -u loncom/html/res/adm/pages/reactionresponse/reaction_editor.html:1.8 loncom/html/res/adm/pages/reactionresponse/reaction_editor.html:1.9
--- loncom/html/res/adm/pages/reactionresponse/reaction_editor.html:1.8	Tue Jul 13 11:36:25 2004
+++ loncom/html/res/adm/pages/reactionresponse/reaction_editor.html	Tue Mar 29 12:57:52 2005
@@ -1,7 +1,7 @@
 <!-- Chemical reaction editor developed by Guy Ashkenazi, guy@fh.huji.ac.il-->
 
 <!--
- $Id: reaction_editor.html,v 1.8 2004/07/13 15:36:25 albertel Exp $
+ $Id: reaction_editor.html,v 1.9 2005/03/29 17:57:52 albertel Exp $
 
  Copyright Michigan State University Board of Trustees
 
@@ -135,8 +135,7 @@
     reaction += html_component(reactants[i]);
     reaction += " + ";
   }
-  if (i < reactants.length)
-    reaction += html_component(reactants[i]);
+  reaction += html_component(reactants[i]);
 
   if (products.length > 0) {
     reaction += " "+rightarrow+" ";
@@ -144,8 +143,7 @@
       reaction += html_component(products[i]);
       reaction += " + ";
     }
-    if (i < products.length)
-      reaction += html_component(products[i]);
+    reaction += html_component(products[i]);
   }
 
   return reaction;
@@ -156,9 +154,13 @@
   var i = 0;
   level = 0;
 
+  var hydrate = string.split('.');
+  if (hydrate.length > 1) 
+    return html_component(hydrate[0]) + "&middot;" + html_component(hydrate[1]);
+      
   for (;string.substring(i,i+1) == ' ';i++)
     ;
-  for (;isDigit(string.substring(i,i+1));i++)
+  for (;isDigit(string.substring(i,i+1)) || string.substring(i,i+1) == '/'; i++) // stoichiometric coefficient
     reactant += string.substring(i,i+1);
   for (;i < string.length;i++)
     reactant +=  html_char(string.substring(i,i+1));
@@ -183,10 +185,14 @@
   if (level == 1) { // superscript
     if (isDigit(chr))
       return chr.sup();
-    if (chr == '+' || chr == '-') {
+    if (chr == '+') {
       level = 0;
       return chr.sup();
     }
+    if (chr == '-') {
+      level = 0;
+      return "<sup>&minus;</sup>";
+    } 
     if (chr == ' ') {
       level = 0;
       return "";