--- loncom/interface/lonprintout.pm 2006/01/27 00:06:52 1.417
+++ loncom/interface/lonprintout.pm 2006/03/01 11:20:37 1.424
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.417 2006/01/27 00:06:52 foxr Exp $
+# $Id: lonprintout.pm,v 1.424 2006/03/01 11:20:37 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 {
@@ -687,7 +699,6 @@ sub page_format_transformation {
my $topmargintoinsert = '';
if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
my $fancypagestatement='';
- &Apache::lonnet::logthis("1: columns = $numberofcolumns");
if ($numberofcolumns eq '2') {
$fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}";
} else {
@@ -752,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') {
@@ -782,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;
}
@@ -907,10 +916,7 @@ sub unsupported {
} else {
$result.=$currentURL;
}
- # TODO: /2 used to be /$number_of_columns which we don'thave
- # access to and therefore now causes latex to fail.
- # need to figure out exactly what we should divide by.
- $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/2][b]{\hrulefill} \end{document}';
+ $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
return $result;
}
@@ -967,12 +973,12 @@ 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");
-}
+#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) = @_;
@@ -1040,7 +1046,6 @@ ENDPART
my %page_breaks = &get_page_breaks($helper);
my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
- &dump_helper_vars($helper);
my ($result,$selectionmade) = ('','');
my $number_of_columns = 1; #used only for pages to determine the width of the cell
my @temporary_array=split /\|/,$format_from_helper;
@@ -1123,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'};
@@ -1199,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') {
@@ -1312,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='';
}
@@ -1333,7 +1347,6 @@ ENDPART
my $courseidinfo = &get_course();
if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
$prevassignment=$assignment;
- &Apache::lonnet::logthis("2: Number of columns: $numberofcolumns");
if ($numberofcolumns eq '1') {
$result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';
} else {
@@ -1426,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_';
@@ -1459,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) {
@@ -1732,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;
@@ -1785,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') {
@@ -1810,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') {
@@ -1830,7 +1848,6 @@ sub print_resources {
if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
if ($current_output=~/\\documentclass/) {
- &Apache::lonnet::logthis("3: Number of columns = $columns_in_format");
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 {
@@ -1840,7 +1857,6 @@ sub print_resources {
} else {
my $blankpages = '';
for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';}
- &Apache::lonnet::logthis("4: Number of columns = $columns_in_format");
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 {
@@ -2153,7 +2169,19 @@ ALL_PROBLEMS
push @{$printChoices}, ["".&mt('Problems')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('selected students')."", 'problems_for_students', 'CHOOSE_STUDENTS'];
push @{$printChoices}, ["".&mt('Problems')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('anonymous students')."", 'problems_for_anon', 'CHOOSE_ANON1'];
}
+
+ # resource_selector will hold a few states that:
+ # - Allow resources to be selected for printing.
+ # - Determine pagination between assignments.
+ # - Determine how many assignments should be bundled into a single PDF.
+ # TODO:
+ # Probably good to do things like separate this up into several vars, each
+ # with one state, and use REGEXPs at inclusion time to set state names
+ # and next states for better mix and match capability
+ #
my $resource_selector=<
+ PRINT_FORMATTING Select resources for the assignment
@@ -2162,6 +2190,9 @@ ALL_PROBLEMS
return $symbFilter;
+
+
+ NUMBER_PER_PDF How should the results be printed? Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)
@@ -2169,20 +2200,24 @@ ALL_PROBLEMS
Add two empty pages/column after each student\'s assignmentAdd three empty pages/column after each student\'s assignment
+
+
+ PAGESIZENumber of assignments printed at the same time: "all"
+
RESOURCE_SELECTOR
&Apache::lonxml::xmlparse($r, 'helper', <
-
+ Select sort orderSort by section then studentSort by students across sections.
- $resource_selector
+ $resource_selector
CHOOSE_STUDENTS
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -2228,7 +2263,7 @@ CHOOSE_STUDENTS
}
&Apache::lonxml::xmlparse($r, 'helper', <
- PAGESIZE
+ SELECT_PROBLEMS