[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Wed, 04 Sep 2002 06:55:27 -0000
albertel Wed Sep 4 02:55:27 2002 EDT
Modified files:
/loncom/xml lonxml.pm
/loncom/homework/caparesponse caparesponse.pm
Log:
- I think this addresses a whole heck of alot of tex characters in a web page
while still protecting the special HTML characters,
- I think it also now properly handles alot more possible answers properly
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.191 loncom/xml/lonxml.pm:1.192
--- loncom/xml/lonxml.pm:1.191 Wed Sep 4 00:55:13 2002
+++ loncom/xml/lonxml.pm Wed Sep 4 02:55:27 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.191 2002/09/04 04:55:13 albertel Exp $
+# $Id: lonxml.pm,v 1.192 2002/09/04 06:55:27 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -541,19 +541,17 @@
sub latex_special_symbols {
my ($current_token,$stack,$parstack)=@_;
- my @temp_array = @$stack;
- if ($temp_array[-1] ne 'tt') {
- if ($current_token=~m/\^/) {$current_token=~s/\^/\\verb|\^|/g;}
- } else {
- if ($current_token=~m/\^/) {$current_token=~s/\^/}\\verb|\^|{/g;}
- }
- if ($current_token=~m/>/) {$current_token=~s/>/\$>\$/g;} #more
- if ($current_token=~m/</) {$current_token=~s/</\$<\$/g;} #less
- if ($current_token=~m/\d%/) {$current_token =~ s/%/\\%/g;} #percent after digit
- if ($current_token=~m/\s%/) {$current_token =~ s/%/\\%/g;} #persent after space
-
-
-# $current_token = ' start='.$current_token.'=finish ';
+ $current_token=~s/\\/\\char92 /g;
+ $current_token=~s/\^/\\char94 /g;
+ $current_token=~s/\~/\\char126 /g;
+ $current_token=~s/(&[^a-z#])/\\$1/g;
+ $current_token=~s/([^&]\#)/\\$1/g;
+ $current_token=~s/(\$|_|{|})/\\$1/g;
+ $current_token=~s/\\char92 /\\texttt{\\char92}/g;
+ $current_token=~s/>/\$>\$/g; #more
+ $current_token=~s/</\$<\$/g; #less
+ if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit
+ if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space
return $current_token;
}
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.56 loncom/homework/caparesponse/caparesponse.pm:1.57
--- loncom/homework/caparesponse/caparesponse.pm:1.56 Wed Sep 4 00:57:13 2002
+++ loncom/homework/caparesponse/caparesponse.pm Wed Sep 4 02:55:27 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.56 2002/09/04 04:57:13 albertel Exp $
+# $Id: caparesponse.pm,v 1.57 2002/09/04 06:55:27 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -169,7 +169,7 @@
if ($target eq 'web') {
$result="<br />The computer got ";
} elsif ($target eq 'tex') {
- $result='\vskip 0 mm The computer got ';
+ $result='\vskip 0 mm The computer got \\texttt{';
}
for (my $i=0; $i <= $#answers; $i++) {
my $answer=$answers[$i];
@@ -179,20 +179,23 @@
} else {
$format=$formats[0];
}
+ my $formatted;
if ((defined($format)) && ($format ne '')) {
&Apache::lonxml::debug("formatting with :$format: answer :$answer:");
- $result.=sprintf('%.'.$format,$answer).',';
+ $formatted=sprintf('%.'.$format,$answer).',';
} else {
&Apache::lonxml::debug("no format answer :$answer:");
- $result.="$answer,";
+ $formatted="$answer,";
}
+ if ($target eq 'tex') {$formatted=&Apache::lonxml::latex_special_symbols($formatted);}
+ $result.=$formatted;
}
chop $result;
if ($target eq 'web') {
$result.=" $unit.<br />";
} elsif ($target eq 'tex') {
- $result.="$unit. \\vskip 0 mm ";
- $result=&Apache::lonxml::latex_special_symbols($result,$tagstack,$parstack);
+ $result.=&Apache::lonxml::latex_special_symbols($unit);
+ $result.="}. \\vskip 0 mm ";
}
}
} elsif ($target eq 'edit') {