--- loncom/xml/londefdef.pm 2003/08/20 15:27:52 1.163 +++ loncom/xml/londefdef.pm 2003/09/25 16:09:14 1.173 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.163 2003/08/20 15:27:52 sakharuk Exp $ +# $Id: londefdef.pm,v 1.173 2003/09/25 16:09:14 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -323,7 +323,7 @@ sub start_title { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{' + $currentstring .= '\keephidden{Title of the document: ' } if ($target eq 'meta') { $currentstring=''; @@ -398,7 +398,7 @@ sub start_meta { } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -407,8 +407,11 @@ sub end_meta { $currentstring = $token->[4]; } } elsif ($target eq 'tex') { - $currentstring=&Apache::lonxml::endredirection(); - $currentstring=''; + my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ((not defined $content) && (not defined $name)) { + &Apache::lonxml::endredirection(); + } } return $currentstring; } @@ -463,6 +466,10 @@ sub start_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { + if ($Apache::lonhomework::parsing_a_problem) { + &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); + return ''; + } if (!$Apache::lonxml::registered) { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; @@ -534,7 +541,7 @@ sub end_body { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = '\end{document}'; + $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } @@ -1418,7 +1425,7 @@ sub start_a { } sub end_a { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1428,7 +1435,7 @@ sub end_a { #-- <li> tag sub start_li { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1647,29 +1654,37 @@ sub end_dl { return $currentstring; } -#-- <dt> tag +#-- <dt> tag (end tag optional) sub start_dt { - my ($target,$token) = @_; - my $currentstring = ''; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring=''; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\item['; + &Apache::lonxml::startredirection();; } return $currentstring; } sub end_dt { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - $currentstring = ']'; + my $data=&item_cleanup; + $currentstring.='\item['.$data.']'; } return $currentstring; } +sub item_cleanup { + my $item=&Apache::lonxml::endredirection();; + $item=~s/\\begin{center}//g; + $item=~s/\\end{center}//g; + return $item; +} + #-- <dd> tag sub start_dd { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; @@ -1677,10 +1692,9 @@ sub start_dd { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - if ($$tagstack[-2] eq 'dl') { - $currentstring = ' \item [] '; - } elsif ($$tagstack[-2] eq 'dt') { - $currentstring = ']'; + if ($$tagstack[-2] eq 'dt') { + my $data=&item_cleanup; + $currentstring.='\item['.$data.']'; } } return $currentstring; @@ -1792,7 +1806,7 @@ sub end_table { $needed=$#length_row_final-$needed+1; for (my $jn=0;$jn<=$#length_row_final;$jn++) { if ($length_row_final[$jn]==0) { - if ($length_raw_row[$jn]<$available_length/3) { + if ($length_raw_row[$jn]<$available_length) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1828,7 +1842,7 @@ sub end_table { return $currentstring; } -#-- <tr> tag +#-- <tr> tag (end tag optional) sub start_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1865,7 +1879,7 @@ sub end_tr { return $currentstring; } -#-- <td> tag +#-- <td> tag (end tag optional) sub start_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1924,9 +1938,24 @@ sub end_td_tex { $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; $Apache::londefdef::table[-1]{'length'} .= '0,'; } else { - $data=~s/^\s+(\S.*)/$1/; + $data=~s/^\s+(\S.*)/$1/; $data=~s/(.*\S)\s+$/$1/; - my $current_length=2*length($data); + $data=~s/(\s)+/$1/; + my $current_length=0; + if ($data=~/\\vskip/) { + my $newdata=$data; + $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; + my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); + foreach my $elementdata (@newdata) { + $elementdata=~s/^\s+(\S.*)/$1/; + $elementdata=~s/(.*\S)\s+$/$1/; + $elementdata=~s/(\s)+/$1/; + my $lengthnewdata=1.8*length($elementdata); + if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} + } + } else { + $current_length=1.8*length($data); + } $Apache::londefdef::table[-1]{'length'} .= $current_length.','; $Apache::londefdef::table[-1]{'TeXlength'} .= '0,'; } @@ -1950,7 +1979,7 @@ sub end_td { return $currentstring; } -#-- <th> tag +#-- <th> tag (end tag optional) sub start_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -3104,7 +3133,7 @@ sub end_tbody { return $currentstring; } -#-- <tfoot> tag +#-- <tfoot> tag (end tag optional) sub start_tfoot { my ($target,$token) = @_; my $currentstring = ''; @@ -3123,7 +3152,7 @@ sub end_tfoot { return $currentstring; } -#-- <thead> tag +#-- <thead> tag (end tag optional) sub start_thead { my ($target,$token) = @_; my $currentstring = '';