--- loncom/interface/lonprintout.pm 2010/04/19 10:29:40 1.575 +++ loncom/interface/lonprintout.pm 2010/05/11 11:10:19 1.575.2.2 @@ -2,7 +2,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.575 2010/04/19 10:29:40 foxr Exp $ +# $Id: lonprintout.pm,v 1.575.2.2 2010/05/11 11:10:19 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,23 +59,38 @@ my $resources_printed; # Global variables that describe errors in ssi calls detected by ssi_with_retries. # -my $ssi_error; # True if there was an ssi error. -my $ssi_last_error_resource; # The resource URI that could not be fetched. -my $ssi_last_error; # The error text from the server. (e.g. 500 Server timed out). +my $ssi_error; # True if there was an ssi error. +my $ssi_last_error_resource; # The resource URI that could not be fetched. +my $ssi_last_error + ; # The error text from the server. (e.g. 500 Server timed out). # # Our ssi max retry count. # -my $ssi_retry_count = 5; # Some arbitrary value. - +my $ssi_retry_count = 5; # Some arbitrary value. # Font size: -my $font_size = 'normalsize'; # Default is normalsize... +my $font_size = 'normalsize'; # Default is normalsize... + +# +# Useful filters that will be filled in by printHelper. +# These are put here to support modularizing helpers into +# less of a helper soup than it was originally: +# These can't be filled in here as there's some conditionalization +# involved. +# + +my $isProblem; +my $isProblemOrMap; +my $isNotMap; +my $isMap; +my $symbFilter; #---------------------------- Helper helpers. ------------------------- + # Returns the text needd for a student chooser. # that text must still be parsed by the helper xml parser. # Parameters: @@ -84,12 +99,8 @@ my $font_size = 'normalsize'; # Default # variable - Name of variable to hold students. # next_state - State after chooser. - sub generate_student_chooser { - my ($this_state, - $sort_choice, - $variable, - $next_state) = @_; + my ( $this_state, $sort_choice, $variable, $next_state ) = @_; my $result = < Select sorting order of printout @@ -108,7 +119,7 @@ sub generate_student_chooser { CHOOSE_STUDENTS - return $result; + return $result; } # Generate the text needed for a resource chooser given the top level of @@ -129,21 +140,17 @@ CHOOSE_STUDENTS # filter - How to filter the resources. # value_func - function. # choice_func - If not empty generates a with this function. -# start_new_option +# start_new_option # - Fragment appended after valuefunc. # # sub generate_resource_chooser { - my ($this_state, - $prompt_text, - $resource_options, - $variable, - $next_state, - $top_url, - $filter, - $choice_func, - $value_func, - $start_new_option) = @_; + my ( + $this_state, $prompt_text, $resource_options, + $variable, $next_state, $top_url, + $filter, $choice_func, $value_func, + $start_new_option + ) = @_; my $result = < @@ -152,11 +159,11 @@ sub generate_resource_chooser { $next_state return $filter; CHOOSE_RESOURCES - if ($choice_func ne '') { - $result .= "return $choice_func;"; + if ( $choice_func ne '' ) { + $result .= "return $choice_func;"; } - if ($top_url ne '') { - $result .= "$top_url"; + if ( $top_url ne '' ) { + $result .= "$top_url"; } $result .= <return $value_func; @@ -167,6 +174,7 @@ CHOOSE_RESOURCES return $result; } + # # Generate the helper XML for a code choice helper dialog: # @@ -182,12 +190,9 @@ CHOOSE_RESOURCES # The Xml of the code chooser. # sub generate_code_selector { - my ($helper, - $state, - $next_state, - $bubble_types, - $code_selections, - $saved_codes) = @_; # Unpack the parameters. + my ( $helper, $state, $next_state, $bubble_types, $code_selections, + $saved_codes ) + = @_; # Unpack the parameters. my $result = < @@ -246,11 +251,46 @@ sub generate_code_selector { CHOOSE_ANON1 - return $result; + return $result; } -#----------------------------------------------------------------------- +# Returns the XML for the states associated with choosing incomplete problems +# for selected students: +# Paramterss: +# helper - reference to the helper. +# map - Map within which to generate the selector. +# base_state - The first/base state of the helper subsegment. +# +# +# +# States we will use: +# $base_state - Selects resources. +# $base_state.WHO - Selects the people to display. +# $base_state.FORMAT - Selects the final print format etc. +# + +sub generate_incomplete_states { + my ($helper, $map, $base_state) = @_; + my $result = ''; + $result .= &generate_resource_chooser( + $base_state, + 'Select Problem(s) to print.', + "multichoice='1' addstatus='1'", + 'RESOURCES', + $base_state.'WHO', + '', + '$res->is_incomplete()' + ); + $result .= &generate_student_chooser( + $base_state.'WHO', + 'student_sort', + 'STUDENTS', + $base_state.'FORMAT'); + return $result; +} + +#----------------------------------------------------------------------- # Fetch the contents of a resource, uninterpreted. # This is used here to fetch a latex file to be included @@ -263,34 +303,35 @@ CHOOSE_ANON1 sub fetch_raw_resource { my ($url) = @_; - my $filename = &Apache::lonnet::filelocation("", $url); - my $contents = &Apache::lonnet::getfile($filename); + my $filename = &Apache::lonnet::filelocation( "", $url ); + my $contents = &Apache::lonnet::getfile($filename); - if ($contents == -1) { - return "File open failed for $filename"; # This will bomb the print. + if ( $contents == -1 ) { + return "File open failed for $filename"; # This will bomb the print. } return $contents; - } -# Fetch the annotations associated with a URL and +# Fetch the annotations associated with a URL and # put a centered 'annotations:' title. # This is all suppressed if the annotations are empty. # sub annotate { my ($symb) = @_; - my $annotation_text = &Apache::loncommon::get_annotation($symb, 1); - + my $annotation_text = &Apache::loncommon::get_annotation( $symb, 1 ); my $result = ""; - if (length($annotation_text) > 0) { - $result .= '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ '; - $result .= "\n"; - $result .= &Apache::lonxml::latex_special_symbols($annotation_text,""); # Escape latex. - $result .= "\n\n"; + if ( length($annotation_text) > 0 ) { + $result .= + '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ '; + $result .= "\n"; + $result .= + &Apache::lonxml::latex_special_symbols( $annotation_text, "" ) + ; # Escape latex. + $result .= "\n\n"; } return $result; } @@ -310,17 +351,16 @@ sub set_font_size { # 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 '') { + 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}/; return $text; - } -# include_pdf - PDF files are included into the +# include_pdf - PDF files are included into the # output as follows: # - The PDF, if necessary, is replicated. # - The PDF is added to the list of files to convert to postscript (along with the images). @@ -329,7 +369,7 @@ sub set_font_size { # # Parameters: # pdf_uri - URI of the PDF file to include. -# +# # Returns: # The LaTeX to include. # @@ -343,50 +383,49 @@ sub include_pdf { # Where is the file? If not local we'll need to repcopy it:' - my $file = &Apache::lonnet::filelocation('', $pdf_uri); - if (! -e $file) { - &Apache::lonnet::repcopy($file); - $file = &Apache::lonnet::filelocation('',$pdf_uri); + my $file = &Apache::lonnet::filelocation( '', $pdf_uri ); + if ( !-e $file ) { + &Apache::lonnet::repcopy($file); + $file = &Apache::lonnet::filelocation( '', $pdf_uri ); } - # The file isn ow replicated locally.. or it did not exist in the first place - # (unlikely). If it did exist, add the pdf to the set of files/images that - # need tob e converted for this print job: + # The file isn ow replicated locally.. or it did not exist in the first place + # (unlikely). If it did exist, add the pdf to the set of files/images that + # need tob e converted for this print job: $file =~ s|(.*)/res/|/home/httpd/html/res/|; - open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat"); + open( FILE, +">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat" + ); print FILE ("$file\n"); - close (FILE); + close(FILE); # Construct the special to put out. To do this we need to get the # resulting filename after conversion. The file will have the same name # but will be in the user's spool directory with converted images. my $dirname = "/home/httpd/prtspool/$env{'user.name'}/"; - my ( $base, $path, $ext) = &fileparse($file, '.pdf'); + my ( $base, $path, $ext ) = &fileparse( $file, '.pdf' ); + # my $destname = $dirname.'/'.$base.'.eps'; # Not really an eps but easier in printout.pl $base =~ s/ /\_/g; - my $output = &print_latex_header(); - $output .= '\special{ps: _begin_job_ (' - .$base.'.pdf.eps'. - ')run _end_job_}'; + $output .= + '\special{ps: _begin_job_ (' . $base . '.pdf.eps' . ')run _end_job_}'; return $output; - } - # # ssi_with_retries- Does the server side include of a resource. # if the ssi call returns an error we'll retry it up to # the number of times requested by the caller. # If we still have a proble, no text is appended to the # output and we set some global variables. -# to indicate to the caller an SSI error occurred. +# to indicate to the caller an SSI error occurred. # All of this is supposed to deal with the issues described # in LonCAPA BZ 5631 see: # http://bugs.lon-capa.org/show_bug.cgi?id=5631 @@ -396,7 +435,7 @@ sub include_pdf { # resource - The resource to include. This is passed directly, without # interpretation to lonnet::ssi. # form - The form hash parameters that guide the interpretation of the resource -# +# # retries - Number of retries allowed before giving up completely. # Returns: # On success, returns the rendered resource identified by the resource parameter. @@ -412,20 +451,20 @@ sub include_pdf { # in the event of an error. # sub ssi_with_retries { - my ($resource, $retries, %form) = @_; + my ( $resource, $retries, %form ) = @_; my $target = $form{'grade_target'}; my $aom = $form{'answer_output_mode'}; - - - my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form); - if (!$response->is_success) { - $ssi_error = 1; - $ssi_last_error_resource = $resource; - $ssi_last_error = $response->code . " " . $response->message; - $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error"); + my ( $content, $response ) = + &Apache::loncommon::ssi_with_retries( $resource, $retries, %form ); + if ( !$response->is_success ) { + $ssi_error = 1; + $ssi_last_error_resource = $resource; + $ssi_last_error = $response->code . " " . $response->message; + $content = '\section*{!!! An error occurred !!!}'; + &Apache::lonnet::logthis( + "Error in SSI resource: $resource Error: $ssi_last_error"); } return $content; @@ -433,15 +472,25 @@ sub ssi_with_retries { } sub get_student_view_with_retries { - my ($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv)=@_; - - my ($content, $response) = &Apache::loncommon::get_student_view_with_retries($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv); - if (!$response->is_success) { - $ssi_error = 1; - $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain; - $ssi_last_error = $response->code . " " . $response->message; - $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain"); + my ( + $curresline, $retries, $username, $userdomain, + $courseid, $target, $moreenv + ) = @_; + + my ( $content, $response ) = + &Apache::loncommon::get_student_view_with_retries( + $curresline, $retries, $username, $userdomain, + $courseid, $target, $moreenv + ); + if ( !$response->is_success ) { + $ssi_error = 1; + $ssi_last_error_resource = + $curresline . ' for user ' . $username . ':' . $userdomain; + $ssi_last_error = $response->code . " " . $response->message; + $content = '\section*{!!! An error occurred !!!}'; + &Apache::lonnet::logthis( +"Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain" + ); } return $content; @@ -449,41 +498,41 @@ sub get_student_view_with_retries { # # printf_style_subst item format_string repl -# +# # Does printf style substitution for a format string that # can have %[n]item in it.. wherever, %[n]item occurs, # rep is substituted in format_string. Note that # [n] is an optional integer length. If provided, -# repl is truncated to at most [n] characters prior to +# repl is truncated to at most [n] characters prior to # substitution. # sub printf_style_subst { - my ($item, $format_string, $repl) = @_; + my ( $item, $format_string, $repl ) = @_; my $result = ""; - while ($format_string =~ /(%)(\d*)\Q$item\E/g ) { - my $fmt = $1; - my $size = $2; - my $subst = $repl; - if ($size ne "") { - $subst = substr($subst, 0, $size); - - # Here's a nice edge case.. supose the end of the - # substring is a \. In that case may have just - # chopped off a TeX escape... in that case, we append - # " " for the trailing character, and let the field - # spill over a bit (sigh). - # We don't just chop off the last character in order to deal - # with one last pathology, and that would be if substr had - # trimmed us to e.g. \\\ - - - if ($subst =~ /\\$/) { - $subst .= " "; - } - } - my $item_pos = pos($format_string); - $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst; - $format_string = substr($format_string, pos($format_string)); + while ( $format_string =~ /(%)(\d*)\Q$item\E/g ) { + my $fmt = $1; + my $size = $2; + my $subst = $repl; + if ( $size ne "" ) { + $subst = substr( $subst, 0, $size ); + + # Here's a nice edge case.. supose the end of the + # substring is a \. In that case may have just + # chopped off a TeX escape... in that case, we append + # " " for the trailing character, and let the field + # spill over a bit (sigh). + # We don't just chop off the last character in order to deal + # with one last pathology, and that would be if substr had + # trimmed us to e.g. \\\ + + if ( $subst =~ /\\$/ ) { + $subst .= " "; + } + } + my $item_pos = pos($format_string); + $result .= + substr( $format_string, 0, $item_pos - length($size) - 2 ) . $subst; + $format_string = substr( $format_string, pos($format_string) ); } # Put the residual format string into the result: @@ -493,9 +542,8 @@ sub printf_style_subst { return $result; } - -# Format a header according to a format. -# +# Format a header according to a format. +# # Substitutions: # %a - Assignment name. @@ -504,63 +552,62 @@ sub printf_style_subst { # %s - The section if it is supplied. # sub format_page_header { - my ($width, $format, $assignment, $course, $student, $section) = @_; - + my ( $width, $format, $assignment, $course, $student, $section ) = @_; - - $width = &recalcto_mm($width); # Get width in mm. - my $chars_per_line = int($width/1.6); # Character/textline. + $width = &recalcto_mm($width); # Get width in mm. + my $chars_per_line = int( $width / 1.6 ); # Character/textline. # Default format? - if ($format eq '') { - # For the default format, we may need to truncate - # elements.. To do this we need to get the page width. - # we assume that each character is about 2mm in width. - # (correct for the header text size??). We ignore - # any formatting (e.g. boldfacing in this). - # - # - Allow the student/course to be one line. - # but only truncate the course. - # - Allow the assignment to be 2 lines (wrapped). - # - - + if ( $format eq '' ) { - my $name_length = int($chars_per_line *3 /4); - my $sec_length = int($chars_per_line / 5); + # For the default format, we may need to truncate + # elements.. To do this we need to get the page width. + # we assume that each character is about 2mm in width. + # (correct for the header text size??). We ignore + # any formatting (e.g. boldfacing in this). + # + # - Allow the student/course to be one line. + # but only truncate the course. + # - Allow the assignment to be 2 lines (wrapped). + # - $format = "%$name_length".'n'; + my $name_length = int( $chars_per_line * 3 / 4 ); + my $sec_length = int( $chars_per_line / 5 ); - if ($section) { - $format .= ' - Sec: '."%$sec_length".'s'; - } + $format = "%$name_length" . 'n'; - $format .= '\\\\%c \\\\ %a'; - + if ($section) { + $format .= ' - Sec: ' . "%$sec_length" . 's'; + } + + $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); - - + $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/) { + if ( $format =~ /\\\\\s\\\\\s/ ) { + #TODO find sensible caption for page header - my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout '); + my $testPrintout = + '\\\\' . &mt('Construction Space') . ' \\\\' . &mt('Test-Printout '); $format =~ s/\\\\\s\\\\\s/$testPrintout/; } + # # We're going to trust LaTeX to break lines appropriately, but # we'll truncate anything that's more than 3 lines worth of @@ -569,14 +616,13 @@ sub format_page_header { # header or rather that those control sequences won't get broken # by the stuff below. # - my $total_length = 3*$chars_per_line; - if (length($format) > $total_length) { - $format = substr($format, 0, $total_length); + my $total_length = 3 * $chars_per_line; + if ( length($format) > $total_length ) { + $format = substr( $format, 0, $total_length ); } - return $format; - + } # @@ -584,29 +630,31 @@ sub format_page_header { # sub num_to_letters { my ($num) = @_; - my @nums= split('',$num); - my @num_to_let=('A'..'Z'); + my @nums = split( '', $num ); + my @num_to_let = ( 'A' .. 'Z' ); my $word; - foreach my $digit (@nums) { $word.=$num_to_let[$digit]; } + foreach my $digit (@nums) { $word .= $num_to_let[$digit]; } return $word; } + # Convert a letter code to numeric. # sub letters_to_num { my ($letters) = @_; - my @letters = split('', uc($letters)); - my %substitution; + my @letters = split( '', uc($letters) ); + my %substitution; my $digit = 0; - foreach my $letter ('A'..'J') { - $substitution{$letter} = $digit; - $digit++; + foreach my $letter ( 'A' .. 'J' ) { + $substitution{$letter} = $digit; + $digit++; } + # The substitution is done as below to preserve leading # zeroes which are needed to keep the code size exact # - my $result =""; + my $result = ""; foreach my $letter (@letters) { - $result.=$substitution{$letter}; + $result .= $substitution{$letter}; } return $result; } @@ -620,20 +668,24 @@ sub letters_to_num { # num_digits - Number of digits required. # sub is_valid_numeric_code { - my ($value, $num_digits) = @_; + my ( $value, $num_digits ) = @_; + # Remove leading/trailing whitespace; $value =~ s/^\s*//g; $value =~ s/\s*$//g; - + # All digits? - if ($value !~ /^[0-9]+$/) { - return "Numeric code $value has invalid characters - must only be digits"; - } - if (length($value) != $num_digits) { - return "Numeric code $value incorrect number of digits (correct = $num_digits)"; + if ( $value !~ /^[0-9]+$/ ) { + return + "Numeric code $value has invalid characters - must only be digits"; + } + if ( length($value) != $num_digits ) { + return +"Numeric code $value incorrect number of digits (correct = $num_digits)"; } return undef; } + # Determines if a code is a valid alhpa code. Alpha codes # are ciphers that map [A-J,a-j] -> 0..9 0..9. # They also have a correct digit count. @@ -644,26 +696,27 @@ sub is_valid_numeric_code { # leading and trailing whitespace are ignored. # sub is_valid_alpha_code { - my ($value, $num_letters) = @_; - - # strip leading and trailing spaces. + my ( $value, $num_letters ) = @_; + + # strip leading and trailing spaces. $value =~ s/^\s*//g; $value =~ s/\s*$//g; # All alphas in the right range? - if ($value !~ /^[A-J,a-j]+$/) { - return "Invalid letter code $value must only contain A-J"; + if ( $value !~ /^[A-J,a-j]+$/ ) { + return "Invalid letter code $value must only contain A-J"; } - if (length($value) != $num_letters) { - return "Letter code $value has incorrect number of letters (correct = $num_letters)"; + if ( length($value) != $num_letters ) { + return +"Letter code $value has incorrect number of letters (correct = $num_letters)"; } return undef; } # Determine if a code entered by the user in a helper is valid. # valid depends on the code type and the type of code selected. -# The type of code selected can either be numeric or +# The type of code selected can either be numeric or # Alphabetic. If alphabetic, the code, in fact is a simple # substitution cipher for the actual numeric code: 0->A, 1->B ... # We'll be nice and be case insensitive for alpha codes. @@ -676,23 +729,24 @@ sub is_valid_alpha_code { # other - An error message indicating what's wrong. # sub is_code_valid { - my ($code_value, $code_option) = @_; - my ($code_type, $code_length) = ('letter', 6); # defaults. + my ( $code_value, $code_option ) = @_; + my ( $code_type, $code_length ) = ( 'letter', 6 ); # defaults. my @lines = &Apache::grades::get_scantronformat_file(); foreach my $line (@lines) { - my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; - if($name eq $code_option) { - $code_length = $length; - if($type eq 'number') { - $code_type = 'number'; - } - } + my ( $name, $type, $length ) = ( split( /:/, $line ) )[ 0, 2, 4 ]; + if ( $name eq $code_option ) { + $code_length = $length; + if ( $type eq 'number' ) { + $code_type = 'number'; + } + } } my $valid; - if ($code_type eq 'number') { - return &is_valid_numeric_code($code_value, $code_length); - } else { - return &is_valid_alpha_code($code_value, $code_length); + if ( $code_type eq 'number' ) { + return &is_valid_numeric_code( $code_value, $code_length ); + } + else { + return &is_valid_alpha_code( $code_value, $code_length ); } } @@ -713,43 +767,44 @@ sub is_code_valid { # # 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); + 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); + 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 lt $l2 ) { + return -1; } - if($l1 gt $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 + # whitespaces to get rid of first # - $f1 =~ s/^\s+//; # Remove leading... - $f1 =~ s/\s+$//; # Trailing spaces from first 1... - + $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... + $f2 =~ s/\s+$//; # And the same for first 2... - if($f1 lt $f2) { - return -1; + if ( $f1 lt $f2 ) { + return -1; } - if($f1 gt $f2) { - return 1; + if ( $f1 gt $f2 ) { + return 1; } - + # Must be the same name. return 0; @@ -761,18 +816,20 @@ sub latex_header_footer_remove { $text =~ s/\\documentclass([^&]*)\\begin{document}//; return $text; } + # -# If necessary, encapsulate text inside +# 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}'; + if ( !( $env{'form.problem.split'} =~ /yes/i ) ) { + $text = '\begin{minipage}{\textwidth}' . $text . '\end{minipage}'; } return $text; } + # # The NUMBER_TO_PRINT and SPLIT_PDFS # variables interact, this sub looks at these two parameters @@ -786,31 +843,37 @@ sub adjust_number_to_print { my $helper = shift; my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'}; - - if ($split_pdf eq 'all') { - $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all'; - } elsif ($split_pdf eq 'oneper') { - $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1; - } elsif ($split_pdf eq 'sections') { - $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section'; - } elsif ($split_pdf eq 'usenumber') { - # Unmodified. - } else { - # Error!!!! - - croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print"; + if ( $split_pdf eq 'all' ) { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all'; } -} + elsif ( $split_pdf eq 'oneper' ) { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1; + } + elsif ( $split_pdf eq 'sections' ) { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section'; + } + elsif ( $split_pdf eq 'usenumber' ) { + + # Unmodified. + } + else { + + # Error!!!! + croak + "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print"; + + } +} sub character_chart { my $result = shift; - return &Apache::entities::replace_entities($result); + return &Apache::entities::replace_entities($result); } sub old_character_chart { - my $result = shift; + my $result = shift; $result =~ s/&\#0?0?(7|9);//g; $result =~ s/&\#0?(10|13);//g; $result =~ s/&\#0?32;/ /g; @@ -818,8 +881,8 @@ sub old_character_chart { $result =~ s/&(\#0?34|quot);/\"/g; $result =~ s/&\#0?35;/\\\#/g; $result =~ s/&\#0?36;/\\\$/g; - $result =~ s/&\#0?37;/\\%/g; - $result =~ s/&(\#0?38|amp);/\\&/g; + $result =~ s/&\#0?37;/\\%/g; + $result =~ s/&(\#0?38|amp);/\\&/g; $result =~ s/&\#(0?39|146);/\'/g; $result =~ s/&\#0?40;/(/g; $result =~ s/&\#0?41;/)/g; @@ -926,7 +989,7 @@ sub old_character_chart { $result =~ s/&(\#160|nbsp);/~/g; $result =~ s/&(\#161|iexcl);/!\`/g; $result =~ s/&(\#162|cent);/\\textcent /g; - $result =~ s/&(\#163|pound);/\\pounds /g; + $result =~ s/&(\#163|pound);/\\pounds /g; $result =~ s/&(\#164|curren);/\\textcurrency /g; $result =~ s/&(\#165|yen);/\\textyen /g; $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g; @@ -952,32 +1015,32 @@ sub old_character_chart { $result =~ s/&(\#188|frac14);/\\textonequarter /g; $result =~ s/&(\#189|frac12);/\\textonehalf /g; $result =~ s/&(\#190|frac34);/\\textthreequarters /g; - $result =~ s/&(\#191|iquest);/?\`/g; - $result =~ s/&(\#192|Agrave);/\\\`{A}/g; - $result =~ s/&(\#193|Aacute);/\\\'{A}/g; + $result =~ s/&(\#191|iquest);/?\`/g; + $result =~ s/&(\#192|Agrave);/\\\`{A}/g; + $result =~ s/&(\#193|Aacute);/\\\'{A}/g; $result =~ s/&(\#194|Acirc);/\\^{A}/g; $result =~ s/&(\#195|Atilde);/\\~{A}/g; - $result =~ s/&(\#196|Auml);/\\\"{A}/g; + $result =~ s/&(\#196|Auml);/\\\"{A}/g; $result =~ s/&(\#197|Aring);/{\\AA}/g; $result =~ s/&(\#198|AElig);/{\\AE}/g; $result =~ s/&(\#199|Ccedil);/\\c{c}/g; - $result =~ s/&(\#200|Egrave);/\\\`{E}/g; - $result =~ s/&(\#201|Eacute);/\\\'{E}/g; + $result =~ s/&(\#200|Egrave);/\\\`{E}/g; + $result =~ s/&(\#201|Eacute);/\\\'{E}/g; $result =~ s/&(\#202|Ecirc);/\\^{E}/g; $result =~ s/&(\#203|Euml);/\\\"{E}/g; $result =~ s/&(\#204|Igrave);/\\\`{I}/g; - $result =~ s/&(\#205|Iacute);/\\\'{I}/g; + $result =~ s/&(\#205|Iacute);/\\\'{I}/g; $result =~ s/&(\#206|Icirc);/\\^{I}/g; - $result =~ s/&(\#207|Iuml);/\\\"{I}/g; + $result =~ s/&(\#207|Iuml);/\\\"{I}/g; $result =~ s/&(\#209|Ntilde);/\\~{N}/g; $result =~ s/&(\#210|Ograve);/\\\`{O}/g; $result =~ s/&(\#211|Oacute);/\\\'{O}/g; $result =~ s/&(\#212|Ocirc);/\\^{O}/g; $result =~ s/&(\#213|Otilde);/\\~{O}/g; - $result =~ s/&(\#214|Ouml);/\\\"{O}/g; + $result =~ s/&(\#214|Ouml);/\\\"{O}/g; $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g; $result =~ s/&(\#216|Oslash);/{\\O}/g; - $result =~ s/&(\#217|Ugrave);/\\\`{U}/g; + $result =~ s/&(\#217|Ugrave);/\\\`{U}/g; $result =~ s/&(\#218|Uacute);/\\\'{U}/g; $result =~ s/&(\#219|Ucirc);/\\^{U}/g; $result =~ s/&(\#220|Uuml);/\\\"{U}/g; @@ -1008,7 +1071,7 @@ sub old_character_chart { $result =~ s/&(\#246|ouml);/\\\"{o}/g; $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g; $result =~ s/&(\#248|oslash);/{\\o}/g; - $result =~ s/&(\#249|ugrave);/\\\`{u}/g; + $result =~ s/&(\#249|ugrave);/\\\`{u}/g; $result =~ s/&(\#250|uacute);/\\\'{u}/g; $result =~ s/&(\#251|ucirc);/\\^{u}/g; $result =~ s/&(\#252|uuml);/\\\"{u}/g; @@ -1016,7 +1079,8 @@ sub old_character_chart { $result =~ s/&(\#255|yuml);/\\\"{y}/g; $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g; $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g; -#Greek Alphabet + + #Greek Alphabet $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g; $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g; $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g; @@ -1067,7 +1131,8 @@ sub old_character_chart { $result =~ s/&(Chi|\#935);/X/g; $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g; $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g; -#Arrows (extended HTML 4.01) + + #Arrows (extended HTML 4.01) $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g; $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g; $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g; @@ -1078,7 +1143,8 @@ sub old_character_chart { $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g; $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g; $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g; -#Mathematical Operators (extended HTML 4.01) + + #Mathematical Operators (extended HTML 4.01) $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g; $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g; $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g; @@ -1117,14 +1183,17 @@ sub old_character_chart { $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g; $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g; $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g; -#Geometric Shapes (extended HTML 4.01) + + #Geometric Shapes (extended HTML 4.01) $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g; -#Miscellaneous Symbols (extended HTML 4.01) + + #Miscellaneous Symbols (extended HTML 4.01) $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g; $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g; $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g; $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g; -# Chemically useful 'things' contributed by Hon Kie (bug 4652). + + # Chemically useful 'things' contributed by Hon Kie (bug 4652). $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g; $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g; @@ -1145,372 +1214,411 @@ sub old_character_chart { $result =~ s/&(ldquo|#8220);/\`\`/g; $result =~ s/&(rdquo|#8221);/\'\'/g; - - return $result; } - - #width, height, oddsidemargin, evensidemargin, topmargin -my %page_formats= - ('letter' => { - 'book' => { - '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'], - '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'] - }, - 'album' => { - '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','0.394 in'], - '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in'] - }, - }, - 'legal' => { - 'book' => { - '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'], - '2' => ['3.66 in','13 in','-0.57 in','-0.57 in','-0.5 in'] - }, - 'album' => { - '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'], - '2' => ['6.0 in','7.1 in','-1 in','-1 in','5 in'] - }, - }, - 'tabloid' => { - 'book' => { - '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'], - '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in'] - }, - 'album' => { - '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'], - '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in'] - }, - }, - 'executive' => { - 'book' => { - '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'], - '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in'] - }, - 'album' => { - '1' => [], - '2' => [] - }, - }, - 'a2' => { - 'book' => { - '1' => [], - '2' => [] - }, - 'album' => { - '1' => [], - '2' => [] - }, - }, - 'a3' => { - 'book' => { - '1' => [], - '2' => [] - }, - 'album' => { - '1' => [], - '2' => [] - }, - }, - 'a4' => { - 'book' => { - '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'], - '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'] - }, - 'album' => { - '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'], - '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','0 cm'] - }, - }, - 'a5' => { - 'book' => { - '1' => [], - '2' => [] - }, - 'album' => { - '1' => [], - '2' => [] - }, - }, - 'a6' => { - 'book' => { - '1' => [], - '2' => [] - }, - 'album' => { - '1' => [], - '2' => [] - }, - }, - ); +#width, height, oddsidemargin, evensidemargin, topmargin +my %page_formats = ( + 'letter' => { + 'book' => { + '1' => [ '7.1 in', '9.8 in', '-0.57 in', '-0.57 in', '0.275 in' ], + '2' => [ '3.66 in', '9.8 in', '-0.57 in', '-0.57 in', '0.275 in' ] + }, + 'album' => { + '1' => [ '8.8 in', '6.8 in', '-0.55 in', '-0.55 in', '0.394 in' ], + '2' => [ '4.8 in', '6.8 in', '-0.5 in', '-1.0 in', '3.5 in' ] + }, + }, + 'legal' => { + 'book' => { + '1' => [ '7.1 in', '13 in',, '-0.57 in', '-0.57 in', '-0.5 in' ], + '2' => [ '3.66 in', '13 in', '-0.57 in', '-0.57 in', '-0.5 in' ] + }, + 'album' => { + '1' => [ '12 in', '7.1 in',, '-0.57 in', '-0.57 in', '-0.5 in' ], + '2' => [ '6.0 in', '7.1 in', '-1 in', '-1 in', '5 in' ] + }, + }, + 'tabloid' => { + 'book' => { + '1' => [ '9.8 in', '16 in', '-0.57 in', '-0.57 in', '-0.5 in' ], + '2' => [ '4.9 in', '16 in', '-0.57 in', '-0.57 in', '-0.5 in' ] + }, + 'album' => { + '1' => [ '16 in', '9.8 in', '-0.57 in', '-0.57 in', '-0.5 in' ], + '2' => [ '16 in', '4.9 in', '-0.57 in', '-0.57 in', '-0.5 in' ] + }, + }, + 'executive' => { + 'book' => { + '1' => [ '6.8 in', '9 in', '-0.57 in', '-0.57 in', '1.2 in' ], + '2' => [ '3.1 in', '9 in', '-0.57 in', '-0.57 in', '1.2 in' ] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a2' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a3' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a4' => { + 'book' => { + '1' => + [ '17.6 cm', '27.2 cm', '-1.397 cm', '-2.11 cm', '-1.27 cm' ], + '2' => [ '9.1 cm', '27.2 cm', '-1.397 cm', '-2.11 cm', '-1.27 cm' ] + }, + 'album' => { + '1' => [ '21.59 cm', '19.558 cm', '-1.397cm', '-2.11 cm', '0 cm' ], + '2' => [ '9.91 cm', '19.558 cm', '-1.397 cm', '-2.11 cm', '0 cm' ] + }, + }, + 'a5' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a6' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, +); sub page_format { + # #Supported paper format: "Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", # "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]", # "A2 [420x594 mm]", "A3 [297x420 mm]", # "A4 [210x297 mm]", "A5 [148x210 mm]", # "A6 [105x148 mm]" -# - my ($papersize,$layout,$numberofcolumns) = @_; - return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}}; +# + my ( $papersize, $layout, $numberofcolumns ) = @_; + return @{ $page_formats{$papersize}->{$layout}->{$numberofcolumns} }; } - sub get_name { - my ($uname,$udom)=@_; - if (!defined($uname)) { $uname=$env{'user.name'}; } - if (!defined($udom)) { $udom=$env{'user.domain'}; } - my $plainname=&Apache::loncommon::plainname($uname,$udom); - if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; } - $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); + my ( $uname, $udom ) = @_; + if ( !defined($uname) ) { $uname = $env{'user.name'}; } + if ( !defined($udom) ) { $udom = $env{'user.domain'}; } + my $plainname = &Apache::loncommon::plainname( $uname, $udom ); + if ( $plainname =~ /^\s*$/ ) { $plainname = $uname . '@' . $udom; } + $plainname = &Apache::lonxml::latex_special_symbols( $plainname, 'header' ); return $plainname; } 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'}; - + 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; } sub page_format_transformation { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; - my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); - - if ($selectionmade eq '4') { - if ($choice eq 'all_problems') { - $assignment=&mt('Problems from the Whole Course'); - } else { - $assignment=&mt('Resources from the Whole Course'); - } - } else { - $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); + my ( + $papersize, $layout, $numberofcolumns, + $choice, $text, $assignment, + $tableofcontents, $indexlist, $selectionmade + ) = @_; + my ( $textwidth, $textheight, $oddoffset, $evenoffset, $topmargin ); + + if ( $selectionmade eq '4' ) { + if ( $choice eq 'all_problems' ) { + $assignment = &mt('Problems from the Whole Course'); + } + else { + $assignment = &mt('Resources from the Whole Course'); + } } - ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); - + else { + $assignment = + &Apache::lonxml::latex_special_symbols( $assignment, 'header' ); + } + ( $textwidth, $textheight, $oddoffset, $evenoffset, $topmargin ) = + &page_format( $papersize, $layout, $numberofcolumns, $topmargin ); - my $name = &get_name(); + my $name = &get_name(); my $courseidinfo = &get_course(); my $header_text = $parmhash{'print_header_format'}; - $header_text = &format_page_header($textwidth, $header_text, $assignment, - $courseidinfo, $name); + $header_text = + &format_page_header( $textwidth, $header_text, $assignment, $courseidinfo, + $name ); my $topmargintoinsert = ''; - if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';} - my $fancypagestatement=''; - if ($numberofcolumns eq '2') { - $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}"; - } else { - $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 /; - } 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/; - } 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 /; - } - if ($papersize eq 'a4') { - 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 ( $topmargin ne '0' ) { + $topmargintoinsert = '\setlength{\topmargin}{' . $topmargin . '}'; + } + my $fancypagestatement = ''; + if ( $numberofcolumns eq '2' ) { + $fancypagestatement = "\\fancyhead{}\\fancyhead[LO]{$header_text}"; + } + else { + $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 /; + } + 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/; + } + 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 /; + } + if ( $papersize eq 'a4' ) { + 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 /; } - 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/; + if ( $indexlist eq 'yes' ) { + $text =~ s/(\\begin{document})/\\makeindex $1/; + $text =~ s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/; } return $text; } - sub page_cleanup { - my $result = shift; - + my $result = shift; + $result =~ m/\\end{document}(\d*)$/; my $number_of_columns = $1; - my $insert = '{'; - for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; } + 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; + return $result, $number_of_columns; } - sub details_for_menu { - my ($helper)=@_; - my $postdata=$env{'form.postdata'}; - if (!$postdata) { $postdata=$helper->{VARS}{'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); - return if ( $symbolic eq ''); + my $symbolic = &Apache::lonnet::symbread($postdata); + return if ( $symbolic eq '' ); - my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic); - $map=&Apache::lonnet::clutter($map); + my ( $map, $id, $resource ) = &Apache::lonnet::decode_symb($symbolic); + $map = &Apache::lonnet::clutter($map); my $name_of_sequence = &Apache::lonnet::gettitle($map); - if ($name_of_sequence =~ /^\s*$/) { - $map =~ m|([^/]+)$|; - $name_of_sequence = $1; - } - my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'}); - if ($name_of_map =~ /^\s*$/) { - $env{'request.course.uri'} =~ m|([^/]+)$|; - $name_of_map = $1; + if ( $name_of_sequence =~ /^\s*$/ ) { + $map =~ m|([^/]+)$|; + $name_of_sequence = $1; + } + my $name_of_map = &Apache::lonnet::gettitle( $env{'request.course.uri'} ); + if ( $name_of_map =~ /^\s*$/ ) { + $env{'request.course.uri'} =~ m|([^/]+)$|; + $name_of_map = $1; } - return ($name_of_resource,$name_of_sequence,$name_of_map); + return ( $name_of_resource, $name_of_sequence, $name_of_map ); } sub copyright_line { - return '\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 } '; + return +'\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 } '; } -my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n"; +my $end_of_student = "\n" . '\special{ps:ENDOFSTUDENTSTAMP}' . "\n"; sub latex_corrections { - my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; + my ( $number_of_columns, $result, $selectionmade, $answer_mode ) = @_; + # $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/; - } else { - $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; + if ( $selectionmade eq '1' || $answer_mode eq 'only' ) { + $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/\$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\\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,'',$first_comment); - substr($result,$first_comment,$end_comment-$first_comment+3) = ''; - $first_comment = index($result,'', $first_comment ); + substr( $result, $first_comment, $end_comment - $first_comment + 3 ) = + ''; + $first_comment = index( $result, '