[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Mon, 29 Sep 2003 20:06:20 -0000


sakharuk		Mon Sep 29 16:06:20 2003 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  For a single resource you can print only answer plus some id info for this resource - name from the sequence/map & path to the problem. Additional cleanup has done - a few new subs were defined to simplify the structure of main output program. 
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.241 loncom/interface/lonprintout.pm:1.242
--- loncom/interface/lonprintout.pm:1.241	Mon Sep 29 09:42:02 2003
+++ loncom/interface/lonprintout.pm	Mon Sep 29 16:06:20 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.241 2003/09/29 13:42:02 www Exp $
+# $Id: lonprintout.pm,v 1.242 2003/09/29 20:06:20 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -611,6 +611,54 @@
     return $texversion;
 }
 
+sub print_latex_header {
+    my $mode=shift;
+    my $output='\documentclass[letterpaper]{article}';
+    if ($mode eq 'batchmode') {
+	$output.='\batchmode';
+    }
+    $output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'.
+	     '\usepackage{longtable}\usepackage{textcomp}\usepackage{makeidx}'.
+	     '\usepackage[dvips]{graphicx}\usepackage{epsfig}\usepackage{calc}'.
+	     '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'.
+	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'.
+	     '\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'.
+	     '\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}'.
+	     '\setlength{\abovedisplayshortskip}{-0.04in}'.
+	     '\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.
+	     '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large'.
+	     '\textbf{Index}} \newline \setlength{\rightmargin}{0in}'.
+	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}'.
+	     '\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}'.
+	     '\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}'.
+	     '\setlength{\abovedisplayshortskip}{-0.04in}'.
+	     '\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}\begin{document}';
+    return $output;	     
+}
+
+sub path_to_problem {
+    my ($urlp,$LaTeXwidth)=@_;
+    my $newurlp = '';
+    $LaTeXwidth=~s/\s*mm\s*$//;
+    my $HowMany = length($urlp)*2;
+    if ($HowMany > $LaTeXwidth) {
+	my @temporrary = split '/',$urlp;
+	my $HowManyNew = 0;
+	for (my $ii=0;$ii<=$#temporrary;$ii++) {
+	    if ($temporrary[$ii] ne '') {
+		$HowManyNew += length($temporrary[$ii])*2;
+		if ($HowManyNew < $LaTeXwidth ) {
+		    $newurlp .=  '/'.$temporrary[$ii];
+		} else {
+		    $HowManyNew = 0;
+		    $newurlp .=  '|\vskip -1 mm \noindent \verb|';
+		    $ii--;
+		}
+	    }
+	}
+    }
+    return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}';
+}
 
 sub output_data {
     my ($r,$helper,$rparmhash) = @_;
@@ -660,31 +708,42 @@
 	}
 	$selectionmade = 1;
 	if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
-	    my %moreenv;
-	    $moreenv{'request.filename'}=$currentURL;
-	    my %form;
-	    $form{'grade_target'}='tex';
-	    $form{'textwidth'}=$LaTeXwidth;	
-	    $form{'problem_split'}=$parmhash{'problem_stream_switch'};
-	    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
 	    my $rndseed=time;
-	    if ($helper->{'VARS'}->{'curseed'}) {
-		$rndseed=$helper->{'VARS'}->{'curseed'};
+	    my $texversion='';
+	    if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
+		my %moreenv;
+		$moreenv{'request.filename'}=$currentURL;
+		my %form;
+		$form{'grade_target'}='tex';
+		$form{'textwidth'}=$LaTeXwidth;	
+		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
+		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
+		if ($helper->{'VARS'}->{'curseed'}) {
+		    $rndseed=$helper->{'VARS'}->{'curseed'};
+		}
+		$form{'rndseed'}=$rndseed;
+		&Apache::lonnet::appenv(%moreenv);
+		&Apache::lonnet::delenv('form.counter');
+		&Apache::lonxml::init_counter();
+		$texversion=&Apache::lonnet::ssi($currentURL,%form);
+		&Apache::lonnet::delenv('form.counter');
+		&Apache::lonnet::delenv('request.filename');
 	    }
-	    $form{'rndseed'}=$rndseed;
-	    &Apache::lonnet::appenv(%moreenv);
-	    &Apache::lonnet::delenv('form.counter');
-	    &Apache::lonxml::init_counter();
-	    my $texversion=&Apache::lonnet::ssi($currentURL,%form);
-	    &Apache::lonnet::delenv('form.counter');
-	    &Apache::lonnet::delenv('request.filename');
-	    if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
+	    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
+	       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
 		my %form;
 		$form{'grade_target'}='answer';
 		$form{'answer_output_mode'}='tex';
 		$form{'rndseed'}=$rndseed;
 		my $answer=&Apache::lonnet::ssi($currentURL,%form);
-		$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+		if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
+		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+		} else {
+		    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
+		    $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';
+		    $texversion.=&path_to_problem ($currentURL,$LaTeXwidth);
+		    $texversion.='\vskip 1 mm '.$answer.'\end{document}';
+		}
 	    }
 	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
 		$texversion=&IndexCreation($texversion,$currentURL);
@@ -723,7 +782,6 @@
 			$form{'answer_output_mode'}='tex';
 			$form{'rndseed'}=$rndseed;
                         if ($urlp=~/\/res\//) {$ENV{'request.state'}='published';}
-			####my $answer=' SSSSSS '.$ENV{'request.state'}.' FFFFFFF ';
 			my $answer=&Apache::lonnet::ssi($urlp,%form);
 			$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
 		    }
@@ -917,25 +975,8 @@
 		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
 		}
                 #this chunck is responsible for printing the path to problem
-		my $newurlp = '';
-		my $HowMany = length($urlp)*2;
-		if ($HowMany > $LaTeXwidth) {
-		    my @temporrary = split '/',$urlp;
-		    my $HowManyNew = 0;
-		    for (my $ii=0;$ii<=$#temporrary;$ii++) {
-			if ($temporrary[$ii] ne '') {
-			    $HowManyNew += length($temporrary[$ii])*2;
-			    if ($HowManyNew < $LaTeXwidth ) {
-				$newurlp .=  '/'.$temporrary[$ii];
-			    } else {
-				$HowManyNew = 0;
-				$newurlp .=  '|\vskip -1 mm \noindent \verb|';
-				$ii--;
-			    }
-			}
-		    }
-		}
-		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
+		my $newurlp=&path_to_problem($urlp,$LaTeXwidth);
+		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/;
 		if ($flag_latex_header_remove ne 'NO') {
 		    $texversion = &latex_header_footer_remove($texversion);
 		} else {
@@ -1321,13 +1362,14 @@
 
     if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or 
 	($helper->{VARS}->{'construction'} eq '1')) {
-	addMessage("<hr width='33%' /><table><tr><td align='right'>Print With Answers:</td><td>");
+	addMessage("<hr width='33%' /><table><tr><td align='right'>Print: </td><td>");
         $paramHash = Apache::lonhelper::getParamHash();
 	$paramHash->{'variable'} = 'ANSWER_TYPE';   
 	$helper->declareVar('ANSWER_TYPE');         
         $paramHash->{CHOICES} = [
-                                   ['No', 'yes'],
-                                   ['Yes', 'no'] ];
+                                   ['Without Answers', 'yes'],
+                                   ['With Answers', 'no'],
+                                   ['Only Answers', 'only'] ];
         Apache::lonhelper::dropdown->new();
 	addMessage("</td></tr>");
 	$startedTable = 1;