--- loncom/homework/optionresponse.pm	2003/05/27 13:56:21	1.78
+++ loncom/homework/optionresponse.pm	2003/09/22 20:49:01	1.86
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.78 2003/05/27 13:56:21 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.86 2003/09/22 20:49:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -152,9 +152,11 @@ sub end_foilgroup {
   
   my $result;
   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') {
+    my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
     my $name;
     my @opt;
     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
+    if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
     &Apache::lonxml::debug("Options are $#opt");
     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
     my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
@@ -291,7 +293,7 @@ sub displayfoils {
   my @names = @{ $Apache::response::foilgroup{'names'} };
   my @truelist;
   my @falselist;
-  my $result;
+  my $result;  
   my $name;
   my $displayoptionintex=0;
   my @alphabet = ('A'..'Z');
@@ -301,9 +303,8 @@ sub displayfoils {
   my $break;
   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
   my $status=$Apache::inputtags::status[-1];
-  if (
-      ($target ne 'tex') &&
-      (($solved =~ /^correct/) || ($status eq 'SHOW_ANSWER')) ) {
+  if ( ($target ne 'tex') &&
+       &Apache::response::show_answer() ) {
     foreach $name (@whichopt) {
 	my $text=$Apache::response::foilgroup{$name.'.text'};
 	if ($text!~/^\s*$/) {
@@ -326,7 +327,8 @@ sub displayfoils {
 	    $result.=$text."\n";
       } elsif ($target eq 'tex') {
 	  $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
- 	  $result .='\item \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
+	  if ($max>1) {$result .='\item ';}
+ 	  $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
 	      ":".$Apache::response::foilgroup{$name.'.text'}."\n";
       }
       if ($Apache::lonhomework::type eq 'exam') {
@@ -340,6 +342,7 @@ sub displayfoils {
   } else {
     my $temp=1;
     my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
+    my $internal_counter=$Apache::lonxml::counter;
     foreach $name (@whichopt) {
       my $text=$Apache::response::foilgroup{$name.'.text'};
       if ($text!~/^\s*$/) {
@@ -394,8 +397,8 @@ sub displayfoils {
 		  }
 	      }
 	      if ($Apache::lonhomework::type eq 'exam') {
-		  $result.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut ';
-#		  $Apache::lonxml::counter++;
+		  $result.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut ';
+		  $internal_counter++;
 	      }
 	      $displayoptionintex=1;
 	  } else {
@@ -415,8 +418,8 @@ sub displayfoils {
 		  }
 	      }
 	      if ($Apache::lonhomework::type eq 'exam') {
-		  $result.='\vskip -2 mm \parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut ';
-#		  $Apache::lonxml::counter++;
+		  $result.='\vskip -2 mm \parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut ';
+		  $internal_counter++;
 	      }
 	  }
       }
@@ -433,15 +436,19 @@ sub displayfoils {
 sub optionlist_correction {
 
     my $texoptionlist = shift;
-    $texoptionlist =~ s/<option><\/option>/\\item \[\] Possible answers are:/;
-    $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+)/<m>\$$1\$<\/m>/g;
+    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+)/<m>\$$1\$<\/m>/g;
+    } else {
+	$texoptionlist =~ s/<option><\/option>/\\item \[\] \\vskip -5 mm/;
+    }
     return $texoptionlist;
 }