[LON-CAPA-cvs] cvs: loncom /homework optionresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 19 Feb 2004 19:06:35 -0000


albertel		Thu Feb 19 14:06:35 2004 EDT

  Modified files:              
    /loncom/homework	optionresponse.pm 
  Log:
  - options with > < in them didn't print correct in exam mode
  - removed dead tex print posisbility from showanswer mode
  - option list in tex homwork mode uses latex_special_symbols now
  - removed redundant code from exam/homeworkj print mode
  - <drawoptionlist> didn't work properly in exam mode web and tex
  - some small amounts of retabination
  
  
  
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.100 loncom/homework/optionresponse.pm:1.101
--- loncom/homework/optionresponse.pm:1.100	Fri Feb 13 16:01:11 2004
+++ loncom/homework/optionresponse.pm	Thu Feb 19 14:06:35 2004
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.100 2004/02/13 21:01:11 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.101 2004/02/19 19:06:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -289,7 +289,7 @@
   my @falselist;
   my $result;  
   my $name;
-  my $displayoptionintex=0;
+  my $displayoptionintex=1;
   my @alphabet = ('A'..'Z');
   my @whichopt = &whichfoils($max,$randomize);
   my $part=$Apache::inputtags::part;
@@ -303,13 +303,7 @@
 	my $text=$Apache::response::foilgroup{$name.'.text'};
 	my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
 	my $lastopt=$lastresponse{$name};
-	if ($text!~/^\s*$/) {
-	    if ($target eq 'tex') {
-		$break='\vskip 0 mm ';
-	    } elsif ($target eq 'web') {
-		$break='<br />';
-	    }
-	}
+	if ($text!~/^\s*$/) { $break='<br />'; }
 	$result.=$break;
 	if ($target eq 'web') {
 	    my $value=$Apache::response::foilgroup{$name.'.value'};
@@ -323,18 +317,9 @@
 		$text='&#149;'.$text;
 	    }
 	    $result.=$text."\n";
-      } elsif ($target eq 'tex') {
-	  $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
-	  if ($max>1) {$result .='\item ';}
- 	  $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
-	      ":".$Apache::response::foilgroup{$name.'.text'}."\n";
       }
       if ($Apache::lonhomework::type eq 'exam') {
-	if ($target ne 'tex') {
 	  $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
-        } else {
-	  $result.=&bubbles(\@alphabet,\@opt);
-        }
       }
       $temp++;
     }
@@ -363,66 +348,55 @@
       }
       if ($target ne 'tex') {
 	  if ($Apache::lonhomework::type ne 'exam') {
-	    $optionlist='<select name="HWVAL_'.
-	      $Apache::inputtags::response['-1'].':'.$temp.'">'.
+	      $optionlist='<select name="HWVAL_'.
+		  $Apache::inputtags::response['-1'].':'.$temp.'">'.
 		  $optionlist."</select>\n";
+	  } else {
+	      $optionlist='<u>'.('&nbsp;'x10).'</u>';
 	  }
-	  my $text=$Apache::response::foilgroup{$name.'.text'};
-	  if (!($text=~s|<drawoptionlist\s*/>|$optionlist|) && $Apache::lonhomework::type ne 'exam') {
-	      $text=$optionlist.$text;
+	  if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
+	      if ($Apache::lonhomework::type ne 'exam') {
+		  $text='&#149;'.$text;
+	      }
 	  } else {
-	      $text='&#149;'.$text;
+	      if ($Apache::lonhomework::type ne 'exam') {
+		  $text=$optionlist.$text;
+	      }
 	  }
 	  $result.=$break.$text."\n";
 	  if ($Apache::lonhomework::type eq 'exam') {
-	    $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
+	      $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
 	  }
 	  $temp++;
       } else {
-          my $texoptionlist = &optionlist_correction($optionlist);
-	  if ($displayoptionintex == 0) {
-	      if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';} #if exam we do not need to show optionlist
-	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
-		if ($Apache::lonhomework::type eq 'exam') {
-	          $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\vskip 2 mm/;
-	        }
-	        if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {
-	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
-	        }
-		$result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
-	      } else {
-		  if ($Apache::lonhomework::type eq 'exam') {
-		      $result.= $texoptionlist.'  '.$Apache::response::foilgroup{$name.'.text'};
-		  } else {
-		      $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
-		  }
-	      }
+	  my $texoptionlist='';
+	  if ($displayoptionintex &&
+	      $Apache::lonhomework::type ne 'exam') {
+	      $texoptionlist = &optionlist_correction(@opt);
+	  }
+	  if ($text=~/<drawoptionlist\s*\/>/) {
+	      $text=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
+	  }
+
+	  if ($text=~m/\\item /) {
 	      if ($Apache::lonhomework::type eq 'exam') {
-		  $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';
-		  $internal_counter++;
+	          $text=~s/\\item/\\vskip 2 mm/;
 	      }
-	      $displayoptionintex=1;
+	      $result.= $texoptionlist.$text;
 	  } else {
-	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
-		  if ($Apache::lonhomework::type eq 'exam') {
-		      $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
-		  }
-	        if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {
-	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
-	        }
-		$result.= $Apache::response::foilgroup{$name.'.text'};
-	      } else {
-		  if ($Apache::lonhomework::type eq 'exam') {
-		      $result.= '  '.$Apache::response::foilgroup{$name.'.text'};
-		  } else {
-		      $result.= '\item '.$Apache::response::foilgroup{$name.'.text'};
-		  }
-	      }
 	      if ($Apache::lonhomework::type eq 'exam') {
-		  $result.='\vskip -1 mm \noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';
-		  $internal_counter++;
+		  $result.= $texoptionlist.'  '.$text;
+	      } else {
+		  $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
 	      }
 	  }
+	  if ($Apache::lonhomework::type eq 'exam') {
+	      $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
+		  $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
+		  '\end{enumerate} \vskip -8 mm \strut ';
+	      $internal_counter++;
+	  }
+	  $displayoptionintex=0;
       }
     }
   }
@@ -435,27 +409,24 @@
 
 
 sub optionlist_correction {
-
-    my $texoptionlist = shift;
-    if ($texoptionlist=~/<option selected/ or $texoptionlist=~/<option>[^<]+<\/option>/) {
-	$texoptionlist =~ s/<option><\/option>/\\item \[\] Choices: /;
-	$texoptionlist =~ s/<option>/\{\\bf /g;
-	$texoptionlist =~ s/<option selected="on">/\{\\bf /g;
-	$texoptionlist =~ s/<\/option>/\},/g;
-	$texoptionlist =~ s/,$/\./g;
-	$texoptionlist =~ s/>/\$>\$/g;
-	$texoptionlist =~ s/</\$<\$/g;
-	$texoptionlist =~ s/=/\$=\$/g;
-	$texoptionlist =~ s/\^(\d+)/\$^{$1}\$/g;
+    my @options = @_;
+    my $texoptionlist='\\item [] Choices: ';
+    if (scalar(@options) > 0) {
+	foreach my $option (@options) {
+	    $texoptionlist.='{\bf '.
+		&Apache::lonxml::latex_special_symbols($option).
+		'},';
+	}
+	chop($texoptionlist);
+	$texoptionlist.='.';
     } else {
-	$texoptionlist =~ s/<option><\/option>/\\item \[\] \\vskip -5 mm/;
+	$texoptionlist='\\item [] \\vskip -5 mm';
     }
     return $texoptionlist;
 }
 
 
 sub webbubbles {
-
     my ($ropt,$ralphabet,$temp,$lastopt)=@_;
     my @opt=@$ropt; 
     my @alphabet=@$ralphabet;
@@ -478,7 +449,6 @@
 
 
 sub bubbles {
-
     my ($ralphabit,$ropt) = @_;
     my @alphabet = @$ralphabit;
     my @opt = @$ropt;
@@ -495,6 +465,7 @@
     }
     for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
 	my $leftmargin;
+	$opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
 	if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
 	$current_length += (length($opt[$ind])+length($alphabet[$ind])+3)*2;
 	if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {