--- loncom/homework/default_homework.lcpm 2004/06/09 21:16:43 1.87 +++ loncom/homework/default_homework.lcpm 2004/10/11 16:31:34 1.90 @@ -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.87 2004/06/09 21:16:43 albertel Exp $ +# $Id: default_homework.lcpm,v 1.90 2004/10/11 16:31:34 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,7 +41,7 @@ sub caparesponse_check { my $type=$LONCAPA::CAPAresponse_args{'type'}; my $tol=$LONCAPA::CAPAresponse_args{'tol'}; my $sig=$LONCAPA::CAPAresponse_args{'sig'}; - my $ans_fmt=$LONCAPA::CAPAresponse_args{'ans_fmt'}; + my $ans_fmt=$LONCAPA::CAPAresponse_args{'format'}; my $unit=$LONCAPA::CAPAresponse_args{'unit'}; my $calc=$LONCAPA::CAPAresponse_args{'calc'}; my $samples=$LONCAPA::CAPAresponse_args{'samples'}; @@ -70,6 +70,12 @@ sub caparesponse_check { $response=~s/ +/ /g; } if ($type eq 'float') { $response=~s/,//g; } + if ($type eq 'float' && $ans_fmt=~/\$/) { + if ($response!~/^\$/) { return "NO_UNIT: Missing \$ "; } + $response=~s/\$//g; + } + $ans_fmt=~s/\W//g; + if (length($response) > 500) { return "TOO_LONG: Answer too long"; } if ($type eq '' ) { @@ -508,8 +514,8 @@ sub chemparse { } next; } - $token =~ /^\s*(\d*)(.*)/; - $formula .= $1 if ($1 > 1); # stoichiometric coefficient + $token =~ /^\s*(\d*(?:&frac\d\d)?)(.*)/; + $formula .= $1 if ($1 ne '1'); # stoichiometric coefficient my $molecule = $2; # subscripts