--- loncom/interface/lonprintout.pm 2009/10/26 09:55:32 1.560.2.7
+++ loncom/interface/lonprintout.pm 2010/11/13 01:57:14 1.568.2.10
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.560.2.7 2009/10/26 09:55:32 foxr Exp $
+# $Id: lonprintout.pm,v 1.568.2.10 2010/11/13 01:57:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -306,11 +306,16 @@ sub set_font_size {
my ($text) = @_;
- $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;
- $text =~ s/\\end{document}/}\\end{document}/;
- return $text;
+ # There appear to be cases where the font directive is empty.. in which
+ # case the first substituion would insert a spurious \ oh happy day.
+ # as this has been the cause of much mystery and hair pulling _sigh_
+ if ($font_size ne '') {
+ $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;
+ }
+ $text =~ s/\\end{document}/}\\end{document}/;
+ return $text;
}
# include_pdf - PDF files are included into the
@@ -494,13 +499,13 @@ sub printf_style_subst {
# %a - Assignment name.
# %c - Course name.
# %n - Student name.
-# %s - The section if it is supplied.
#
sub format_page_header {
- my ($width, $format, $assignment, $course, $student, $section) = @_;
+ my ($width, $format, $assignment, $course, $student) = @_;
-
$width = &recalcto_mm($width); # Get width in mm.
+ my $chars_per_line = int($width/2); # Character/textline.
+
# Default format?
if ($format eq '') {
@@ -514,48 +519,37 @@ sub format_page_header {
# but only truncate the course.
# - Allow the assignment to be 2 lines (wrapped).
#
- my $chars_per_line = $width/2; # Character/textline.
-
-
- my $name_length = int($chars_per_line *3 /4);
- my $sec_length = int($chars_per_line / 5);
-
- $format = "%$name_length".'n';
-
- if ($section) {
- $format .= ' - Sec: '."%$sec_length".'s';
- }
+ my $firstline = "$student $course";
+ if (length($firstline) > $chars_per_line) {
+ my $lastchar = $chars_per_line - length($student) - 1;
+ if ($lastchar > 0) {
+ $course = substr($course, 0, $lastchar);
+ } else { # Nothing left of course:
+ $course = '';
+ }
+ }
+ if (length($assignment) > $chars_per_line) {
+ $assignment = substr($assignment, 0, $chars_per_line);
+ }
- $format .= '\\\\%c \\\\ %a';
-
+ $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
- }
- # An open question is how to handle long user formatted page headers...
- # A possible future is to support e.g. %na so that the user can control
- # the truncation of the elements that can appear in the header.
- #
- $format = &printf_style_subst("a", $format, $assignment);
- $format = &printf_style_subst("c", $format, $course);
- $format = &printf_style_subst("n", $format, $student);
- $format = &printf_style_subst("s", $format, $section);
-
-
- # If the user put %'s in the format string, they must be escaped
- # to \% else LaTeX will think they are comments and terminate
- # the line.. which is bad!!!
-
- # If the user has role author, $course and $assignment are empty so
- # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
- if($format =~ /\\\\\s\\\\\s/) {
- #TODO find sensible caption for page header
- my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');
- $format =~ s/\\\\\s\\\\\s/$testPrintout/;
+ } else {
+ # An open question is how to handle long user formatted page headers...
+ # A possible future is to support e.g. %na so that the user can control
+ # the truncation of the elements that can appear in the header.
+ #
+ $format = &printf_style_subst("a", $format, $assignment);
+ $format = &printf_style_subst("c", $format, $course);
+ $format = &printf_style_subst("n", $format, $student);
+
+ # If the user put %'s in the format string, they must be escaped
+ # to \% else LaTeX will think they are comments and terminate
+ # the line.. which is bad!!!
}
-
return $format;
-
}
#
@@ -1251,8 +1245,6 @@ sub get_course {
my $courseidinfo;
if (defined($env{'request.course.id'})) {
$courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
- my $sec = $env{'request.course.sec'};
-
}
return $courseidinfo;
}
@@ -1263,9 +1255,9 @@ sub page_format_transformation {
if ($selectionmade eq '4') {
if ($choice eq 'all_problems') {
- $assignment='Problems from the Whole Course';
+ $assignment=&mt('Problems from the Whole Course');
} else {
- $assignment='Resources from the Whole Course';
+ $assignment=&mt('Resources from the Whole Course');
}
} else {
$assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
@@ -1275,6 +1267,7 @@ sub page_format_transformation {
my $name = &get_name();
my $courseidinfo = &get_course();
+ if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
my $header_text = $parmhash{'print_header_format'};
$header_text = &format_page_header($textwidth, $header_text, $assignment,
$courseidinfo, $name);
@@ -1295,7 +1288,13 @@ sub page_format_transformation {
$text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /;
}
if ($papersize eq 'a4') {
- $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
+ my $papersize_text;
+ if ($perm{'pav'}) {
+ $papersize_text = '\\special{papersize=210mm,297mm}';
+ } else {
+ $papersize_text = '\special{papersize=210mm,297mm}';
+ }
+ $text =~ s/(\\begin{document})/$1$papersize_text/;
}
}
if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
@@ -1526,7 +1525,9 @@ sub print_page_in_course {
my $title=&Apache::lonnet::gettitle($symb);
$title = &Apache::lonxml::latex_special_symbols($title);
} else {
- $result.=$currentURL;
+ my $esc_currentURL= $currentURL;
+ $esc_currentURL =~ s/_/\\_/g;
+ $result.=$esc_currentURL;
}
$result .= '\\\\';
@@ -1539,9 +1540,9 @@ sub print_page_in_course {
# First is the overall page description. This is then followed by the
# components of the page. Each of which must be printed independently.
-
my $the_page = shift(@page_resources);
+
foreach my $resource (@page_resources) {
my $resource_src = $resource->src(); # Essentially the URL of the resource.
$result .= $resource->title() . '\\\\';
@@ -1556,7 +1557,7 @@ sub print_page_in_course {
}
# these resources go through the XML transformer:
- elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm\xhtml|xhtm)$/) {
+ elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
my $urlp = &Apache::lonnet::clutter($resource_src);
my %form;
my %moreenv;
@@ -1567,7 +1568,7 @@ sub print_page_in_course {
$form{'grade_target'} = 'tex';
$form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
- $form{'pdfFormFiels'} = $pdfFormFields; #
+ $form{'pdfFormFields'} = 'no';
$form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
@@ -1671,8 +1672,9 @@ sub print_page_in_course {
# List of recently generated print files
#
sub recently_generated {
- my $r=shift;
- my $prtspool=$r->dir_config('lonPrtDir');
+ my ($prtspool) = @_;
+ my $output;
+
my $zip_result;
my $pdf_result;
opendir(DIR,$prtspool);
@@ -1705,10 +1707,10 @@ sub recently_generated {
if ($ext eq 'zip') { $zip_result .= $result; }
}
if ($zip_result || $pdf_result) {
- $r->print('