[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm
albertel
lon-capa-cvs@mail.lon-capa.org
Wed, 18 Feb 2004 22:49:33 -0000
albertel Wed Feb 18 17:49:33 2004 EDT
Modified files:
/loncom/homework default_homework.lcpm
Log:
- allow one to coerce pretty print to always do tex or web conversion
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.68 loncom/homework/default_homework.lcpm:1.69
--- loncom/homework/default_homework.lcpm:1.68 Thu Oct 23 09:56:07 2003
+++ loncom/homework/default_homework.lcpm Wed Feb 18 17:49:32 2004
@@ -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.68 2003/10/23 13:56:07 ng Exp $
+# $Id: default_homework.lcpm,v 1.69 2004/02/18 22:49:32 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -498,9 +498,10 @@
}
sub prettyprint {
- my ($value,$fmt)=@_;
+ my ($value,$fmt,$target)=@_;
my $result;
my $dollarmode;
+ if (!$target) { $target = $external::target; }
if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
if ($fmt) { $value=sprintf('%.'.$fmt,$value); }
if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) {
@@ -512,9 +513,9 @@
$exponent=~s/^-0*/-/;
if ($exponent eq '-') { undef($exponent); }
if ($exponent) {
- if ($external::target eq 'web') {
+ if ($target eq 'web') {
$result=$frac.'×10<sup>'.$exponent.'</sup>';
- } elsif ($external::target eq 'tex') {
+ } elsif ($target eq 'tex') {
$result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
} else {
$result=$value;
@@ -524,13 +525,14 @@
}
} else {
$result=$value;
- if ($dollarmode) { $result=&dollarformat($result); }
+ if ($dollarmode) { $result=&dollarformat($result,$target); }
}
return $result;
}
sub dollarformat {
- my ($number) = @_;
+ my ($number,$target) = @_;
+ if (!$target) { $target = $external::target; }
if ($number =~ /\./) {
while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*$)/) {
$number = $1.','.$2.$3;
@@ -540,7 +542,7 @@
$number = $1.','.$2.$3;
}
}
- if ($external::target eq 'tex') {
+ if ($target eq 'tex') {
$number='\$'.$number; #' stupid emacs
} else {
$number='$'.$number; #' stupid emacs