--- loncom/interface/lonprintout.pm 2015/03/11 04:15:47 1.627.2.14 +++ loncom/interface/lonprintout.pm 2017/01/29 16:02:29 1.653 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.627.2.14 2015/03/11 04:15:47 raeburn Exp $ +# $Id: lonprintout.pm,v 1.653 2017/01/29 16:02:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -578,7 +578,6 @@ sub printable { # date for printing checks printstartdate param first, then, if not set, # opendate param, then, if not set, contentopen param. - sub get_print_dates { my $res = shift; my $partsref = $res->parts(); @@ -701,12 +700,12 @@ sub incomplete { } } # -# When printing for students, the resoures and order of the +# When printing for students, the resources and order of the # resources may need to be altered if there are folders with # random selectiopn or random ordering (or both) enabled. # This sub computes the set of resources to print for a student # modified both by random ordering and selection and filtered -# to only those that are in the original set selcted to be printed. +# to only those that are in the original set selected to be printed. # # Parameters: # $map - The URL of the folder being printed. @@ -717,6 +716,9 @@ sub incomplete { # $who - Student/domain for whome the sequence will be generated. # $code - CODE being printed when printing Problems/Resources # from folder for CODEd assignments +# $nohidemap - If true, parameter in map for hiddenresource will be +# ignored. The user calling the routine should have +# both the pav and vgr privileges if this is set to true). # # Implicit inputs: # $ @@ -738,12 +740,12 @@ sub master_seq_to_person_seq { my @output_seq; my $unhidden; - if ($perm{'pav'} && $perm{'vgr'} && $nohidemap) { + if ($nohidemap) { $unhidden = &Apache::lonnet::clutter($map); } my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, - $code,$unhidden); + $code, $unhidden); my ($start,$finish); if ($map) { @@ -763,13 +765,13 @@ sub master_seq_to_person_seq { # Iterate on the resource..select the items that are randomly selected # and that are in the seq_has. Presumably the iterator will take care # of the random ordering part of the deal. + # my $curres; while ($curres = $iterator->next()) { # # Only process resources..that are not removed by randomout... # and are selected for printint as well. # - if (ref($curres) && ! $curres->randomout()) { my $currsymb = $curres->symb(); if (exists($seq_hash{$currsymb})) { @@ -843,9 +845,9 @@ sub set_font_size { if ($font_size ne '') { - $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/; + $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/; } - $text =~ s/\\end{document}/}\\end{document}/; + $text =~ s/\\end\{document}/}\\end{document}/; return $text; @@ -922,13 +924,13 @@ sub include_pdf { sub collect_languages { my $doc = shift; my %languages; - while ($doc =~ /\\selectlanguage{(\w+)}/mg) { + while ($doc =~ /\\selectlanguage\{(\w+)}/mg) { $languages{$1} = 1; # allows us to request each language exactly once. } my @lang_list = (keys(%languages)); # List of unique languages if (scalar @lang_list) { my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n"; - $doc =~ s/\\begin{document}/$babel_header\\begin{document}/; + $doc =~ s/\\begin\{document}/$babel_header\\begin{document}/; } return $doc; } @@ -1056,12 +1058,12 @@ sub printf_style_subst { # %s - The section if it is supplied. # sub format_page_header { - my ($width, $format, $assignment, $course, $student) = @_; + my ($width, $format, $assignment, $course, $student, $section) = @_; $width = &recalcto_mm($width); # Get width in mm. - my $chars_per_line = int($width/2); # Character/textline. + my $chars_per_line = int($width/1.6); # Character/textline. # Default format? @@ -1077,38 +1079,34 @@ sub format_page_header { # - Allow the assignment to be 2 lines (wrapped). # - 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 = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; + my $name_length = int($chars_per_line *3 /4); + my $sec_length = int($chars_per_line / 5); - } 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!!! + $format = "%$name_length".'n'; - } + if ($section) { + $format .= ' - Sec: '."%$sec_length".'s'; + } - return $format; + $format .= '\\\\%c \\\\ %a'; + + } + # 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 @@ -1236,7 +1234,6 @@ sub is_code_valid { my ($code_type, $code_length) = ('letter', 6); # defaults. my @lines = &Apache::grades::get_scantronformat_file(); foreach my $line (@lines) { - next if (($line =~ /^\#/) || ($line eq '')); my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; if($name eq $code_option) { $code_length = $length; @@ -1330,8 +1327,8 @@ sub compare_names { sub latex_header_footer_remove { my $text = shift; - $text =~ s/\\end{document}//; - $text =~ s/\\documentclass([^&]*)\\begin{document}//; + $text =~ s/\\end\{document}//; + $text =~ s/\\documentclass([^&]*)\\begin\{document}//; return $text; } # @@ -1845,6 +1842,8 @@ 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; } @@ -1867,7 +1866,6 @@ 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); @@ -1880,12 +1878,12 @@ sub page_format_transformation { $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } if ($layout eq 'album') { - $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; + $text =~ s/\\begin\{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; } elsif ($layout eq 'book') { if ($choice ne 'All class print') { - $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\n\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\n\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\usepackage{booktabs}\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; + $text =~ s/\\begin\{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\n\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\n\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\usepackage{booktabs}\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; } else { - $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 /; + $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') { my $papersize_text; @@ -1894,13 +1892,13 @@ sub page_format_transformation { } else { $papersize_text = '\special{papersize=210mm,297mm}'; } - $text =~ s/(\\begin{document})/$1$papersize_text/; + $text =~ s/(\\begin\{document})/$1$papersize_text/; } } if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;} if ($indexlist eq 'yes') { - $text=~s/(\\begin{document})/\\makeindex $1/; - $text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/; + $text=~s/(\\begin\{document})/\\makeindex $1/; + $text=~s/(\\end\{document})/\\strut\\\\\\strut\\printindex $1/; } return $text; } @@ -1909,12 +1907,12 @@ sub page_format_transformation { sub page_cleanup { my $result = shift; - $result =~ m/\\end{document}(\d*)$/; + $result =~ m/\\end\{document}(\d*)$/; my $number_of_columns = $1; my $insert = '{'; for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; } $insert .= '}'; - $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; + $result =~ s/(\\begin\{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g; return $result,$number_of_columns; } @@ -1950,16 +1948,16 @@ my $end_of_student = "\n".'\special{ps:E sub latex_corrections { my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; -# $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; +# $result =~ s/\\includegraphics\{/\\includegraphics\[width=\\minipagewidth\]{/g; my $copyright = ©right_line(); if ($selectionmade eq '1' || $answer_mode eq 'only') { - $result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; + $result =~ s/(\\end\{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; } else { - $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; + $result =~ s/(\\end\{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; } $result =~ s/\$number_of_columns/$number_of_columns/g; - $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g; - $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g; + $result =~ s/(\\end\{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g; + $result =~ s/(\\end\{longtable}\s*)\\strut\\newline/$1/g; #-- LaTeX corrections my $first_comment = index($result,'