--- loncom/homework/default_homework.lcpm 2011/05/22 03:04:51 1.155 +++ loncom/homework/default_homework.lcpm 2011/06/07 22:07:09 1.156 @@ -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.155 2011/05/22 03:04:51 www Exp $ +# $Id: default_homework.lcpm,v 1.156 2011/06/07 22:07:09 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -309,12 +309,19 @@ sub caparesponse_check_list { &LONCAPA_INTERNAL_DEBUG("Initial final response :$responses->[0][-1]:"); my $unit; + my ($allowalgebra)=(¶meter_setting('allowalgebra',¤tpart())=~/^(yes|1|on)$/i); if ($type eq 'float' || $type eq '') { #for numerical problems split off the unit -# if ( $responses->[0][-1]=~ /(.*[^\s])\s+([^\s]+)/ ) { - if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/ ) { - $responses->[0][-1]=$1; - $unit=&capa_formula_fix($2); + my $part1; + my $part2; + if ($allowalgebra) { + ($part1,$part2)=($responses->[0][-1]=~ /^(.*[^\s])\s+([^\s]+)$/); + } else { + ($part1,$part2)=($responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/); + } + if ($part1 && $part2) { + $responses->[0][-1]=$part1; + $unit=&capa_formula_fix($part2); &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:"); } } @@ -344,6 +351,10 @@ sub caparesponse_check_list { if (($element==0) && ($unit!~/\w/) && ($answerunit=~/\w/)) { $appendunit=$answerunit; } +# Do the math for the student if allowed + if ($allowalgebra) { + $element=&cas('maxima',$element); + } if ($appendunit ne '') { $element .= " $appendunit"; }