--- loncom/interface/lonprintout.pm 2006/01/26 19:54:15 1.408.2.2
+++ loncom/interface/lonprintout.pm 2006/02/24 22:37:45 1.423
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.408.2.2 2006/01/26 19:54:15 albertel Exp $
+# $Id: lonprintout.pm,v 1.423 2006/02/24 22:37:45 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -226,6 +226,18 @@ sub latex_header_footer_remove {
$text =~ s/\\documentclass([^&]*)\\begin{document}//;
return $text;
}
+#
+# If necessary, encapsulate text inside
+# a minipage env.
+# necessity is determined by the problem_split param.
+#
+sub encapsulate_minipage {
+ my ($text) = @_;
+ if (!(env{'form.problem.split'} =~ /yes/i)) {
+ $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}';
+ }
+ return $text;
+}
sub character_chart {
@@ -751,7 +763,6 @@ sub details_for_menu {
sub latex_corrections {
my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_;
-
# $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
$result =~ s/\$number_of_columns/$number_of_columns/g;
if ($selectionmade eq '1' || $answer_mode eq 'only') {
@@ -781,7 +792,6 @@ sub latex_corrections {
}
$result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
$result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
-
return $result;
}
@@ -816,11 +826,12 @@ sub IndexCreation {
sub print_latex_header {
my $mode=shift;
- my $output='\documentclass[letterpaper]{article}';
+ my $output='\documentclass[letterpaper,twoside]{article}';
if (($mode eq 'batchmode') || (!$perm{'pav'})) {
$output.='\batchmode';
}
$output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'."\n".
+ '\usepackage{multirow}'."\n".
'\usepackage{longtable}\usepackage{textcomp}\usepackage{makeidx}'."\n".
'\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n".
'\usepackage{wrapfig}'.
@@ -962,15 +973,20 @@ sub recently_generated {
# A reference to a page break hash.
#
#
+#use Data::Dumper;
+#sub dump_helper_vars {
+# my ($helper) = @_;
+# my $helpervars = Dumper($helper->{'VARS'});
+# &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
+#}
sub get_page_breaks {
my ($helper) = @_;
my %page_breaks;
-
+
foreach my $break (split /\|\|\|/, $helper->{'VARS'}->{'FINISHPAGE'}) {
$page_breaks{$break} = 1;
}
-
return %page_breaks;
}
@@ -1112,6 +1128,9 @@ ENDPART
&Apache::lonnet::delenv('form.counter');
&Apache::lonnet::delenv('request.filename');
}
+ # current document with answers.. no need to encap in minipage
+ # since there's only one answer.
+
if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
@@ -1188,10 +1207,14 @@ ENDPART
if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
} else {
+ # If necessary, encapsulate answer in minipage:
+
$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($urlp,$LaTeXwidth);
- $texversion.='\vskip 1 mm '.$answer.'\end{document}';
+ my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';
+ $body.=&path_to_problem($urlp,$LaTeXwidth);
+ $body.='\vskip 1 mm '.$answer.'\end{document}';
+ $body = &encapsulate_minipage($body);
+ $texversion.=$body;
}
}
if ($flag_latex_header_remove ne 'NO') {
@@ -1252,6 +1275,7 @@ ENDPART
&Apache::lonnet::delenv('form.counter');
&Apache::lonxml::init_counter();
&Apache::lonxml::store_counter();
+ my $pbreakresources = keys %page_breaks;
for (my $i=0;$i<=$#master_seq;$i++) {
# Note due to document structure, not allowed to put \newpage
@@ -1300,9 +1324,11 @@ ENDPART
} else {
if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
$texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
- $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($master_seq[$i]).'}\vskip 0 mm ';
- $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
- $texversion.='\vskip 1 mm '.$answer;
+ my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($master_seq[$i]).'}\vskip 0 mm ';
+ $body .= &path_to_problem ($urlp,$LaTeXwidth);
+ $body .='\vskip 1 mm '.$answer;
+ $body = &encapsulate_minipage($body);
+ $texversion .= $body;
} else {
$texversion='';
}
@@ -1321,7 +1347,11 @@ ENDPART
my $courseidinfo = &get_course();
if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
$prevassignment=$assignment;
- $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';
+ if ($numberofcolumns eq '1') {
+ $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';
+ } else {
+ $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';
+ }
}
$result .= $texversion;
$flag_latex_header_remove = 'YES';
@@ -1409,8 +1439,7 @@ ENDPART
$person,$type,
\%moreenv,\@master_seq,
$flag_latex_header_remove,
- $LaTeXwidth,
- $number_of_columns);
+ $LaTeXwidth);
$resources_printed .= ":";
$print_array[$i].=$output;
$student_names[$i].=$person.':'.$fullname.'_END_';
@@ -1442,6 +1471,7 @@ ENDPART
}
my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
$moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
+ $moreenv{'instructor_comments'}='hide';
my $seed=time+($$<<16)+($$);
my @allcodes;
if ($old_name) {
@@ -1715,7 +1745,7 @@ sub get_CODE {
sub print_resources {
my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header,
- $LaTeXwidth,$number_of_columns)=@_;
+ $LaTeXwidth)=@_;
my $current_output = '';
my $printed = '';
my ($username,$userdomain,$usersection) = split /:/,$person;
@@ -1732,6 +1762,8 @@ sub print_resources {
&Apache::lonxml::init_counter();
&Apache::lonxml::store_counter();
my %page_breaks = &get_page_breaks($helper);
+ my @format_array = split(/\|/,$helper->{'VARS'}->{'FORMAT'});
+ my $columns_in_format = $format_array[1];
foreach my $curresline (@{$master_seq}) {
if (defined $page_breaks{$curresline}) {
@@ -1766,10 +1798,14 @@ sub print_resources {
if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
$rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
} else {
- $rendered=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
- $rendered.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm ';
- $rendered.=&path_to_problem($res_url,$LaTeXwidth);
- $rendered.='\vskip 1 mm '.$ansrendered;
+
+
+ my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
+ my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm ';
+ $body .=&path_to_problem($res_url,$LaTeXwidth);
+ $body .='\vskip 1 mm '.$ansrendered;
+ $body = &encapsulate_minipage($body);
+ $rendered = $header.$body;
}
}
if ($remove_latex_header eq 'YES') {
@@ -1791,7 +1827,8 @@ sub print_resources {
} else {
$rendered =~ s/\\end{document}//;
}
- $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/'.$number_of_columns.'][b]{\hrulefill}\strut \vskip 0 mm \strut ';
+ $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
+
} else {
my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'},$curresline);
if ($remove_latex_header ne 'NO') {
@@ -1811,11 +1848,20 @@ sub print_resources {
if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
if ($current_output=~/\\documentclass/) {
- $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;
+ if ($columns_in_format == 1) {
+ $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;
+ } else {
+ $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;
+
+ }
} else {
my $blankpages = '';
for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';}
- $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;
+ if ($columns_in_format == 1) {
+ $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;
+ } else {
+ $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;
+ }
}
return ($current_output,$fullname, $printed);
@@ -1827,34 +1873,17 @@ sub handler {
&init_perm();
-# my $loaderror=&Apache::lonnet::overloaderror($r);
-# if ($loaderror) { return $loaderror; }
-# $loaderror=
-# &Apache::lonnet::overloaderror($r,
-# $env{'course.'.$env{'request.course.id'}.'.home'});
-# if ($loaderror) { return $loaderror; }
+
my $helper = printHelper($r);
if (!ref($helper)) {
return $helper;
}
-# my $key;
-# foreach $key (keys %{$helper->{'VARS'}}) {
-# $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-
');
-# }
-# foreach $key (keys %env) {
-# $r->print(' '.$key.'->'.$env{$key}.'<-
');
-# }
-# return OK;
my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
-# my $key;
-# foreach $key (keys %parmhash) {
-# $r->print(' '.$key.'->'.$parmhash{$key}.'<-
');
-# }
-#
+
# If a figure conversion queue file exists for this user.domain
@@ -1878,7 +1907,7 @@ sub addMessage {
Apache::lonhelper::message->new();
}
-use Data::Dumper;
+
sub init_perm {
undef(%perm);
@@ -1940,7 +1969,7 @@ sub printHelper {
# But we only do this in the initial state so that they are allowed to change.
#
- $helper->{VARS}->{FINISHPAGE} = '';
+ # $helper->{VARS}->{FINISHPAGE} = '';
&Apache::loncommon::restore_course_settings('print',
{'pagebreaks' => 'scalar',
@@ -1959,7 +1988,7 @@ sub printHelper {
}
}
-
+
# This will persistently load in the data we want from the
# very first screen.
@@ -1977,6 +2006,7 @@ sub printHelper {
if ($env{'form.url'}) {
$helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
}
+
}
if ($env{'form.symb'}) {
@@ -2063,9 +2093,7 @@ sub printHelper {
$helper->declareVar('SEQUENCE');
- # Useful for debugging: Dump the help vars
-# $r->print(Dumper($helper->{VARS}));
-# $r->print($map);
+
# If we're in a sequence...
if (($helper->{'VARS'}->{'construction'} ne '1') &&
@@ -2546,6 +2574,7 @@ RNDSEED
$helper->process();
+
# MANUAL BAILOUT CONDITION:
# If we're in the "final" state, bailout and return to handler
if ($helper->{STATE} eq 'FINAL') {