--- loncom/xml/lonxml.pm	2003/02/07 21:55:57	1.228
+++ loncom/xml/lonxml.pm	2003/02/12 22:04:34	1.230
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.228 2003/02/07 21:55:57 albertel Exp $
+# $Id: lonxml.pm,v 1.230 2003/02/12 22:04:34 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -145,7 +145,7 @@ $Apache::lonxml::registered=0;
 $Apache::lonxml::request='';
 
 # a problem number counter, and check on ether it is used
-$Apache::lonxml::counter=1;
+$Apache::lonxml::counter=4;
 $Apache::lonxml::counter_changed=0;
 
 #internal check on whether to look at style defs
@@ -668,18 +668,24 @@ sub htmlclean {
 }
 
 sub latex_special_symbols {
-    my ($current_token,$stack,$parstack)=@_;
-    $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
+    my ($current_token,$stack,$parstack,$where)=@_;
+    if ($where=='header') {
+      $current_token =~ s/_/ /g;
+      $current_token =~ s/\^/ /g;
+      $current_token =~ s/&/\\&/g;
+    } else {
+     $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;
 }
 
@@ -1500,14 +1506,22 @@ sub get_param_var {
   if ( ! $context ) { $context = -1; }
   my $args ='';
   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
+  &Apache::lonxml::debug("Args are $args param is $param");
   if ($case_insensitive) {
       if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
 	  return undef;
       }
   } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
   my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
-  if ($value =~ /^[\$\@\%]/) {
-    return &Apache::run::run("return $value",$safeeval,1);
+  &Apache::lonxml::debug("first run is $value");
+  if ($value =~ /^[\$\@\%]\w+$/) {
+      &Apache::lonxml::debug("doing second");
+      my @result=&Apache::run::run("return $value",$safeeval,1);
+      if (!defined($result[0])) {
+	  return $value
+      } else {
+	  if (wantarray) { return @result; } else { return $result[0]; }
+      }
   } else {
     return $value;
   }