[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 19 Sep 2006 10:57:14 -0000


foxr		Tue Sep 19 06:57:14 2006 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  - Do table cell alignments using the \multicolumn{1}{|alignspec}{  method.
  - Add a correction for spacing at the end of a \center in a table cell.
   this looks like it fixes all the nasty issues with space after centering.
   See bug 3058.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.336 loncom/xml/londefdef.pm:1.337
--- loncom/xml/londefdef.pm:1.336	Tue Sep  5 17:57:57 2006
+++ loncom/xml/londefdef.pm	Tue Sep 19 06:57:11 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.336 2006/09/05 21:57:57 foxr Exp $
+# $Id: londefdef.pm,v 1.337 2006/09/19 10:57:11 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -561,8 +561,12 @@
 }
 
 # \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}'; }
+
 #-- <center> tag (end tag required)
 sub start_center {
     my ($target,$token,$tagstack) = @_;
@@ -585,6 +589,9 @@
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
 	$currentstring = '\end{center}';  
+	if (&is_inside_of($tagstack, "table")) {
+	    $currentstring .= &center_end_correction();
+	}
     }
     return $currentstring;
 }
@@ -2206,33 +2213,75 @@
 		    }
 		    $output .= '\multicolumn{'.
 			$colspan
-			."}{|p{$spanwidth mm}|}{";
+			."}";
+		    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.=&center_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...
 		#