version 1.74, 2004/03/16 19:47:47
|
version 1.76, 2004/03/22 21:05:15
|
Line 26
|
Line 26
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
# |
# |
# Guy Albertelli |
|
# |
|
# 05/25/2001 H. K. Ng |
|
# 05/31/2001 H. K. Ng |
|
# 12/21/2001 Matthew |
|
# |
|
#init some globals |
#init some globals |
$hidden::RANDOMINIT=0; |
$hidden::RANDOMINIT=0; |
$pi=atan2(1,1)*4; |
$pi=atan2(1,1)*4; |
Line 68 sub caparesponse_check {
|
Line 63 sub caparesponse_check {
|
} else { |
} else { |
$message .="no ws in :$response:\n"; |
$message .="no ws in :$response:\n"; |
} |
} |
|
if ($type eq 'cs' || $type eq 'ci' || $type eq 'mc') { |
|
#for string answers make surec all places spaces occur, there is |
|
#really only 1 space, in both the answer and the response |
|
$answer=~s/ +/ /g; |
|
$response=~s/ +/ /g; |
|
} |
if (length($response) > 500) { return "TOO_LONG: Answer too long"; } |
if (length($response) > 500) { return "TOO_LONG: Answer too long"; } |
|
|
if ($type eq '' ) { |
if ($type eq '' ) { |
Line 485 sub format {
|
Line 485 sub format {
|
return $result; |
return $result; |
} |
} |
|
|
|
sub chemparse { |
|
my ($reaction) = @_; |
|
my @tokens = split(/(\s\+|\->|<=>)/,$reaction); |
|
my $formula = ''; |
|
foreach my $token (@tokens) { |
|
if ($token eq '->' ) { |
|
$formula .= '<m>\ensuremath{\rightarrow}</m> '; |
|
next; |
|
} |
|
if ($token eq '<=>') { |
|
if ($external::target eq 'web' && |
|
&EXT('request.browser.unicode')) { |
|
$formula .= '⇌ '; |
|
} else { |
|
$formula .= &web('<=> ','<m>\ensuremath{\rightleftharpoons}</m> ', |
|
'<=$gt; '); |
|
} |
|
next; |
|
} |
|
$token =~ /^\s*(\d*)(.*)/; |
|
$formula .= $1 if ($1 > 1); # stoichiometric coefficient |
|
|
|
my $molecule = $2; |
|
# subscripts |
|
$molecule =~ s|(?<=[a-zA-Z\[\s])(\d+)|<sub>$1</sub>|g; |
|
# superscripts |
|
$molecule =~ s|\^(\d*[+\-]*)|<sup>$1</sup>|g; |
|
# strip whitespace |
|
$molecule =~ s/\s*//g; |
|
# forced space |
|
$molecule =~ s/_/ /g; |
|
$formula .= $molecule.' '; |
|
} |
|
# get rid of trailing space |
|
$formula =~ s/(\Q${nbsp}\E| )$//; |
|
|
|
return &xmlparse($formula); |
|
} |
|
|
sub prettyprint { |
sub prettyprint { |
my ($value,$fmt,$target)=@_; |
my ($value,$fmt,$target)=@_; |
my $result; |
my $result; |
my $dollarmode; |
my $dollarmode; |
if (!$target) { $target = $external::target; } |
if (!$target) { $target = $external::target; } |
|
if ($fmt =~ /chem/i) { return(&chemparse($value)); } |
if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; } |
if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; } |
if ($fmt) { $value=sprintf('%.'.$fmt,$value); } |
if ($fmt) { $value=sprintf('%.'.$fmt,$value); } |
if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) { |
if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) { |