--- loncom/interface/lonprintout.pm 2004/08/19 20:02:21 1.328 +++ loncom/interface/lonprintout.pm 2005/02/09 15:56:45 1.359 @@ -1,7 +1,7 @@ -# The LearningOnline Network +# The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.328 2004/08/19 20:02:21 albertel Exp $ +# $Id: lonprintout.pm,v 1.359 2005/02/09 15:56:45 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,13 +41,68 @@ use Apache::lonnavmaps; use Apache::lonratedt; use POSIX qw(strftime); use Apache::lonlocal; -use GDBM_File; - -my %hash; my $LaTeXwidth = 0; +# Compare two students by name. The students are in the form +# returned by the helper: +# user:domain:section:last, first:status +# This is a helper function for the perl sort built-in therefore: +# Implicit Inputs: +# $a - The first element to compare (global) +# $b - The second element to compare (global) +# Returns: +# -1 - $a < $b +# 0 - $a == $b +# +1 - $a > $b +# Note that the initial comparison is done on the last names with the +# first names only used to break the tie. +# +# +sub compare_names { + # First split the names up into the primary fields. + + my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a); + my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b); + + # Now split the last name and first name of each n: + # + + my ($l1,$f1) = split(/,/, $n1); + my ($l2,$f2) = split(/,/, $n2); + + # We don't bother to remove the leading/trailing whitespace from the + # firstname, unless the last names compare identical. + + if($l1 lt $l2) { + return -1; + } + if($l1 gt $l2) { + return 1; + } + + # Break the tie on the first name, but there are leading (possibly trailing + # whitespaces to get rid of first + # + $f1 =~ s/^\s+//; # Remove leading... + $f1 =~ s/\s+$//; # Trailing spaces from first 1... + + $f2 =~ s/^\s+//; + $f2 =~ s/\s+$//; # And the same for first 2... + + if($f1 lt $f2) { + return -1; + } + if($f1 gt $f2) { + return 1; + } + + # Must be the same name. + + return 0; +} + sub latex_header_footer_remove { my $text = shift; $text =~ s/\\end{document}//; @@ -229,7 +284,7 @@ sub character_chart { $result =~ s/&(\#219|Ucirc);/\\^{U}/g; $result =~ s/&(\#220|Uuml);/\\\"{U}/g; $result =~ s/&(\#221|Yacute);/\\\'{Y}/g; - $result =~ s/&(\#223|szlig);/\\ss/g; + $result =~ s/&(\#223|szlig);/{\\ss}/g; $result =~ s/&(\#224|agrave);/\\\`{a}/g; $result =~ s/&(\#225|aacute);/\\\'{a}/g; $result =~ s/&(\#226|acirc);/\\^{a}/g; @@ -377,11 +432,11 @@ sub character_chart { my %page_formats= ('letter' => { 'book' => { - '1' => [ '7.1 in','10.2 in', '-0.57 in','-0.57 in','0 in'], - '2' => ['3.66 in','10.2 in', '-0.57 in','-0.57 in','0 in'] + '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'], + '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'] }, 'album' => { - '1' => [ '8.8 in', '6.8 in','-40 pt in', '-60 pt','0 in'], + '1' => [ '8.8 in', '6.8 in','-40 pt in', '-60 pt','1 cm'], '2' => [ '4.4 in', '6.8 in','-0.5 in', '-1.5 in','3.5 in'] }, }, @@ -519,12 +574,12 @@ sub page_format_transformation { $fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; } if ($layout eq 'album') { - $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1} /; + $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\\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\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/; + $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\\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\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1} \\vskip 5 mm /; + $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{}\\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}/; @@ -554,9 +609,11 @@ sub page_cleanup { sub details_for_menu { - - my $name_of_resourse = &Apache::lonnet::gettitle($ENV{'form.postdata'}); - my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'}); + my ($helper)=@_; + my $postdata=$ENV{'form.postdata'}; + if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; } + my $name_of_resource = &Apache::lonnet::gettitle($postdata); + my $symbolic = &Apache::lonnet::symbread($postdata); my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic); $map=&Apache::lonnet::clutter($map); my $name_of_sequence = &Apache::lonnet::gettitle($map); @@ -569,8 +626,7 @@ sub details_for_menu { $ENV{'request.course.uri'} =~ m|([^/]+)$|; $name_of_map = $1; } - return ($name_of_resourse,$name_of_sequence,$name_of_map); - + return ($name_of_resource,$name_of_sequence,$name_of_map); } @@ -642,25 +698,26 @@ sub IndexCreation { sub print_latex_header { my $mode=shift; my $output='\documentclass[letterpaper]{article}'; - if ($mode eq 'batchmode') { + if (($mode eq 'batchmode') || (!$ENV{'request.role.adv'})) { $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}'; + $output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'."\n". + '\usepackage{longtable}\usepackage{textcomp}\usepackage{makeidx}'."\n". + '\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n". + '\usepackage{picins}\usepackage{calc}'."\n". + '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'."\n". + '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'."\n". + '\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'."\n". + '\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}'."\n". + '\setlength{\abovedisplayshortskip}{-0.04in}'."\n". + '\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'."\n". + '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large'."\n". + '\textbf{Index}} \newline \setlength{\rightmargin}{0in}'."\n". + '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}'."\n". + '\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}'."\n". + '\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}'."\n". + '\setlength{\abovedisplayshortskip}{-0.04in}'."\n". + '\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}\begin{document}'."\n"; return $output; } @@ -690,11 +747,11 @@ sub path_to_problem { sub recalcto_mm { my $textwidth=shift; my $LaTeXwidth; - if ($textwidth=~/(\d+\.?\d*)\s*cm/) { + if ($textwidth=~/(-?\d+\.?\d*)\s*cm/) { $LaTeXwidth = $1*10; - } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) { + } elsif ($textwidth=~/(-?\d+\.?\d*)\s*mm/) { $LaTeXwidth = $1; - } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) { + } elsif ($textwidth=~/(-?\d+\.?\d*)\s*in/) { $LaTeXwidth = $1*25.4; } $LaTeXwidth.=' mm'; @@ -732,6 +789,9 @@ sub output_data { my %parmhash = %$rparmhash; my $bodytag=&Apache::loncommon::bodytag('Preparing Printout'); $r->print(<