--- loncom/xml/londefdef.pm 2006/08/31 18:45:42 1.334 +++ loncom/xml/londefdef.pm 2006/11/06 11:39:02 1.341 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.334 2006/08/31 18:45:42 albertel Exp $ +# $Id: londefdef.pm,v 1.341 2006/11/06 11:39:02 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -561,8 +561,12 @@ sub end_body { } # \begin{center} causes a new paragprah spacing that looks odd inside -# of a table cell -sub center_correction { return '\vspace*{-6 mm}'; } +# of a table cell. Same at the end of a \center but with a slightly +# larger space .. hence center_correction and center_end_correction. +# +sub center_correction { return '\vspace*{-6 mm}'; } +sub center_end_correction { return '\vspace*{-7 mm}'; } + #--
tag (end tag required) sub start_center { my ($target,$token,$tagstack) = @_; @@ -585,6 +589,9 @@ sub end_center { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '\end{center}'; + if (&is_inside_of($tagstack, "table")) { + $currentstring .= ¢er_end_correction(); + } } return $currentstring; } @@ -1214,20 +1221,15 @@ sub start_br { $signal=1; } if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) { - my $colspan = - &Apache::lonxml::get_param('colspan', $parstack, - $safeeval, $i, 0); - if ($colspan) { - $signal = 2; - } + $signal = 1; } } if ($signal eq 1) { $currentstring .= ' \vskip 0 mm '; - } elsif ($signal eq '2') { - # multicol doesn't like blank lines } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') { $currentstring .= '\strut \\\\ \strut '; + } else { # Honor break in simple + $currentstring .= '}} \strut \\\\ \strut \ensuremath{^{'; } } return $currentstring; @@ -1989,7 +1991,13 @@ sub start_table { $Apache::londefdef::table[-1]{'minlen'}=[]; $Apache::londefdef::table[-1]{'content'}=[]; $Apache::londefdef::table[-1]{'align'}=[]; - $currentstring.='\keephidden{NEW TABLE ENTRY}'; + if (&is_inside_of($tagstack, 'sup')) { + $currentstring .= '}} \\\\ \ensuremath{^{ '; + } + if (&is_inside_of($tagstack, 'sub')) { + $currentstring .= '}} \\\\ \ensuremath{_{ '; + } + $currentstring.=' \keephidden{NEW TABLE ENTRY}'; } @@ -2207,35 +2215,81 @@ sub end_table { # if ($colspan > 1) { + my $spanwidth = 0; + for (my $spancol = $jn; $spancol < $jn + $colspan; $spancol++) { + $spanwidth += $fwidth[$spancol]; + } $output .= '\multicolumn{'. $colspan - .'}{|l|}{'; + ."}"; + if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { + $output .= '{|c|}{'; + } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { + $output .= '{|r|}{'; + } + else { + $output .= "{|p{$spanwidth mm}|}{"; + } + } + # Rowspan... if colspan is 1, and there's an alignment we'll need + # to kick in a multicolumn in order to get the alignment spec. + # this must precede the multirow or LaTex gets quite upset. + # Naturally if colspan > 1 we've already done that above ^ + # + my $multirow_aligned = 0; if ($rowspan > 1) { + if ($colspan == 1) { + if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { + $output .= '\multicolumn{1}{|c|}{'; + $multirow_aligned = 1; + } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { + $output .= '\multicolumn{1}{|r|}{'; + $multirow_aligned = 1; + } + } $have_rowspan++; - $output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{'; + $output .= '\multirow{'.$rowspan.'}[0]{*}{'; + # + # If we did not throw in a multicolumn to align, then add + # an extra { + # so we close correctly without having to keep additional state + # around + # + if (!$multirow_aligned) { + $output .= '{'; + } } if (($rowspan eq '^') || ($rowspan eq '_')) { $have_rowspan++; } #-------------------------------------------------------------- - if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { - $output.=¢er_correction().'\begin{center}'; - } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { - $output.=' \hfill \llap{' + + # For right and center alignment of single cells. + # we are going to use a multicolumn with a span of 1 to specify alignment. + # + if ($colspan == 1 && $rowspan == 1) { + if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { + $output .= '\multicolumn{1}{|c|}{'; + } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { + $output .= '\multicolumn{1}{|r|}{'; + } } + $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; - if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { - $output.='\end{center}'; - } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { - $output.='} '; + + if (($colspan == 1 && $rowspan == 1) && + (($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') || + ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r'))) { + $output .= '}'; } + # Close off any open multirow: if ($rowspan > 1) { - $output .= '}'; + $output .= '}}'; } # Close off the colspan... # @@ -2798,6 +2852,7 @@ sub start_img { #if original gif/jpg/png file exist do following: my $origsrc=$src; my ($path,$file) = &get_eps_image($src); + # &Apache::lonnet::logthis("Image source: $src result: $path $file"); $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &Apache::lonxml::debug("path = $path file = $file src = $src"); if (-e $src) { @@ -2811,6 +2866,13 @@ sub start_img { my $size; if ($width_param) { $size.='width='.$width_param.' mm,'; } if ($height_param) { $size.='height='.$height_param.' mm]'; } + # Default size if not able to extract that (e.g. eps image). + + # &Apache::lonnet::logthis("Size = $size"); + if ($size eq "0 mm") { + $size = "50 mm]"; # Default to 1 column width for 2 column. + } + $size='['.$size; $size=~s/,$/]/; $currentstring .= '\graphicspath{{'.$destpath.'}}' @@ -3366,6 +3428,9 @@ sub start_blockquote { if ($target eq 'web' || $target eq 'webgrade') { $currentstring .= $token->[4]; } + if ($target eq 'tex') { + $currentstring .= '\begin{quote}'; + } return $currentstring; } @@ -3375,6 +3440,9 @@ sub end_blockquote { if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; } + if ($target eq 'tex') { + $currentstring = '\end{quote}'; + } return $currentstring; } @@ -4180,6 +4248,7 @@ sub get_eps_image { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &Apache::lonxml::debug("Filelocation gives: $src"); if (! -e $src) { + # &Apache::lonnet::logthis("$src does not exist...repcopying"); &Apache::lonxml::debug("$src does not exist"); if (&Apache::lonnet::repcopy($src) ne 'ok' ) { &Apache::lonxml::debug("Repcopy of $src failed (1)"); @@ -4191,6 +4260,7 @@ sub get_eps_image { &Apache::lonxml::debug("repcopy of $src ... $didrepcopy"); if ( (not -e $src) || ($didrepcopy ne 'ok')) { + # &Apache::lonnet::logthis("queuing $orig_src for dynamic eps gen"); &Apache::lonxml::debug("Failed to find or replicate $src"); #if replication failed try to produce eps file dynamically @@ -4207,8 +4277,24 @@ sub get_eps_image { if ($sext ne "") { # Put the ext. back in to uniquify. $src =~ s/\.eps$/$sext.eps/; } + } } + } else { +# &Apache::lonnet::logthis("$src exists. queueing for copy."); +# &Apache::lonnet::logthis("Got eps already.. queue for copy"); + # If the postscript file has spaces in its name, + # LaTeX will gratuitiously vomit. Therefore + # queue such files for copy with " " replaced by "_". + # printout.pm will know them by their .ps or .eps extensions. + my $newsrc = $orig_src; + $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; + open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat"); +# &Apache::lonnet::logthis("Queueing $newsrc for copy"); + print FILE "$newsrc\n"; + close FILE; + $src=~s|/home/httpd/html/res|/home/httpd/prtspool|; + $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; } my ($path,$file)=($src=~m|(.*)/([^/]*)$|); &Apache::lonxml::debug("get_eps_image returning: $path / $file
");