--- loncom/interface/lonprintout.pm 2003/08/13 19:40:07 1.213 +++ loncom/interface/lonprintout.pm 2003/08/18 18:18:48 1.216 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.213 2003/08/13 19:40:07 albertel Exp $ +# $Id: lonprintout.pm,v 1.216 2003/08/18 18:18:48 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -481,7 +481,7 @@ sub get_course { } sub page_format_transformation { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents) = @_; + my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist) = @_; my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); $assignment=~s/_/ /g; if ($numberofcolumns != 1) { @@ -503,7 +503,11 @@ sub page_format_transformation { $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\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 /; } } - if ($tableofcontents eq 'yes') {$text=~s/(\\begin{document})/$1 \\tableofcontents \\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/1\]\[b\]{\\hrulefill}/;} + 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/; + } return $text; } @@ -578,6 +582,35 @@ sub latex_corrections { } +sub index_table { + my $currentURL = shift; + my $insex_string=''; + $currentURL=~s/\.([^\/+])$/\.$1\.meta/; + $insex_string=&Apache::lonnet::metadata($currentURL,'keywords'); + return $insex_string; +} + + +sub IndexCreation { + my ($texversion,$currentURL)=@_; + my @key_words=split(/,/,&index_table($currentURL)); + my $chunk=''; + my $st=index $texversion,'\addcontentsline{toc}{subsection}{'; + if ($st>0) { + for (my $i=0;$i<3;$i++) {$st=(index $texversion,'}',$st+1);} + $chunk=substr($texversion,0,$st+1); + substr($texversion,0,$st+1)=' '; + } + foreach my $key_word (@key_words) { + if ($key_word=~/\S+/) { + $texversion=~s/\b($key_word)\b/$1 \\index{$key_word} /i; + } + } + if ($st>0) {substr($texversion,0,1)=$chunk;} + return $texversion; +} + + sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; @@ -651,6 +684,9 @@ ENDPART my $answer=&Apache::lonnet::ssi($currentURL,%form); $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { + $texversion=&IndexCreation($texversion,$currentURL); + } $result .= $texversion; if ($currentURL=~m/\.page\s*$/) { ($result,$number_of_columns) = &page_cleanup($result); @@ -714,7 +750,9 @@ ENDPART my $answer=&Apache::lonnet::ssi($urlp,%form); $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } -# $result .= $texversion; + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { + $texversion=&IndexCreation($texversion,$urlp); + } if (($selectionmade == 4) and ($assignment ne $prevassignment) and ($i>=1)) { my ($name,$courseidinfo) = &get_name; my $courseidinfo = &get_course(); @@ -845,6 +883,9 @@ ENDPART } else { $texversion =~ s/\\end{document}//; } + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { + $texversion=&IndexCreation($texversion,$urlp); + } $result .= $texversion; } $flag_latex_header_remove = 'YES'; @@ -853,7 +894,7 @@ ENDPART $result .= '\end{document}'; } #-------------------------------------------------------- corrections for the different page formats - $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'}); + $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'}); $result = &latex_corrections($number_of_columns,$result); #changes page's parameters for the one column output if ($numberofcolumns == 1) { @@ -862,7 +903,10 @@ ENDPART $result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /; $result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /; } - if ($helper->{'VARS'}->{'TABLE_CONTENTS'} eq 'yes') {$selectionmade+=10;} + if ($helper->{'VARS'}->{'TABLE_CONTENTS'} eq 'yes') {$selectionmade*=10;} + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { + if ($selectionmade<10) {$selectionmade*=100;} else {$selectionmade*=10;} + } #-- writing .tex file in prtspool my $temp_file; my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex"; @@ -1159,7 +1203,7 @@ CHOOSE_FROM_SUBDIR if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or ($helper->{VARS}->{'construction'} eq '1')) { $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{MESSAGE_TEXT} = "
Next option is available only for advanced users: "; + $paramHash->{MESSAGE_TEXT} = "
Next four options are available only for advanced users:
"; Apache::lonhelper::message->new(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'ANSWER_TYPE'; @@ -1172,7 +1216,7 @@ CHOOSE_FROM_SUBDIR if ($ENV{'request.role.adv'}) { $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{MESSAGE_TEXT} = "
Another option available only for advanced users: "; + $paramHash->{MESSAGE_TEXT} = "
"; Apache::lonhelper::message->new(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'LATEX_TYPE'; @@ -1189,18 +1233,29 @@ CHOOSE_FROM_SUBDIR Apache::lonhelper::dropdown->new(); } - + if ($ENV{'request.role.adv'}) { $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{MESSAGE_TEXT} = "
Print with Table of Contents: "; + $paramHash->{MESSAGE_TEXT} = "
"; Apache::lonhelper::message->new(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'TABLE_CONTENTS'; $helper->declareVar('TABLE_CONTENTS'); $paramHash->{CHOICES} = [ - ['No', 'no'], - ['Yes', 'yes'] ]; + ['Print without Table of Contents', 'no'], + ['Print with Table of Contents', 'yes'] ]; Apache::lonhelper::dropdown->new(); - + + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{MESSAGE_TEXT} = "
"; + Apache::lonhelper::message->new(); + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{'variable'} = 'TABLE_INDEX'; + $helper->declareVar('TABLE_INDEX'); + $paramHash->{CHOICES} = [ + ['Print without Index', 'no'], + ['Print with Index', 'yes'] ]; + Apache::lonhelper::dropdown->new(); + } Apache::lonprintout::page_format_state->new("FORMAT");