--- loncom/xml/londefdef.pm 2006/08/31 18:45:42 1.334
+++ loncom/xml/londefdef.pm 2006/09/25 10:11:47 1.338
@@ -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.338 2006/09/25 10:11:47 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;
@@ -2207,35 +2209,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...
#