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

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 26 Dec 2005 19:01:26 -0000


foxr		Mon Dec 26 14:01:26 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Make rowspan pretty much work.  There are possible problems with sizing 
  columns.. and I doubt that a cell with both row and colspan will work or
  even that LaTeX can be coerced to do that simply.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.305 loncom/xml/londefdef.pm:1.306
--- loncom/xml/londefdef.pm:1.305	Thu Dec 22 19:12:32 2005
+++ loncom/xml/londefdef.pm	Mon Dec 26 14:01:25 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.305 2005/12/23 00:12:32 foxr Exp $
+# $Id: londefdef.pm,v 1.306 2005/12/26 19:01:25 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -178,6 +178,7 @@
             (!$env{'request.role.adv'})) {$currentstring .='\batchmode';} 
 	$currentstring .= '\newcommand{\keephidden}[1]{}'.
                           '\renewcommand{\deg}{$^{\circ}$}'.
+			  '\usepackage{multirow}'.
                           '\usepackage{longtable}'.
                           '\usepackage{textcomp}'.
                           '\usepackage{makeidx}'.
@@ -2186,6 +2187,7 @@
 	$header_of_table .= '}';
 	#fill the table
 	for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
+	    my $have_rowspan = 0;
 	    for (my $jn=0;$jn<=$#fwidth;$jn++) {
 		#
 		#  Do the appropriate magic if this has a colspan
@@ -2196,6 +2198,18 @@
 			$colspan
 			.'}{|l|}{';
 		}
+		my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
+
+		# Start a rowspan if necessary:
+
+		if ($rowspan > 1) {
+		    $have_rowspan++;
+		    $output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{';
+		}
+		if (($rowspan eq '^') || ($rowspan eq '_')) {
+		    $have_rowspan++;
+		}
+
 		if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
 		    # $output.='\vspace*{-6 mm}\begin{center}';
 		    $output.='\begin{center}';
@@ -2209,6 +2223,11 @@
 		} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
 		    $output.='} ';
 		}
+		# Close off any open multirow:
+		
+		if ($rowspan > 1) {
+		    $output .= '}';
+		}
 		#  Close off the colspan...
 		#
 		if ($colspan > 1)  {
@@ -2217,7 +2236,24 @@
 		}
                 if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
 	    }
-	    $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
+	    #  If have_rowspan > 0, and borders are on, then 
+	    #  we need to do more than put an \hline at the bottom of row.
+	    #  we need to do the appropriate \cline to ensure that
+	    #  the spanned rows don't have \hlines through them.
+
+	    if (($Apache::londefdef::table[-1]{'hinc'} =~ /\\hline/) && $have_rowspan) {
+		$output .= ' \\\\ ';
+		for (my $jn=0; $jn<=$#fwidth;$jn++) {
+		    my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
+		    if (($rowspan <= 1) || ($rowspan eq '_')) {
+			my $column = $jn+1;
+			$output .= '\cline{'.$column.'-'.$column.'} ';
+		    }
+		}
+
+	    } else {
+		$output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
+	    }
 	}
 	# Note that \newline destroys alignment env's produced  by e.g. <div>
 	# $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
@@ -2368,11 +2404,12 @@
     #  The rowspan array of the table indicates which cells are part of a span.
     #  n indicates the start of a span set of n rows.
     #  ^ indicates a cell that continues a span set.
+    #  _ indicates the cell is at the bottom of a span set.
     #  If this and subsequent cells are part of a rowspan, we must
     #  push along the row until we find one that is not.
 
     while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column]) 
-	   && $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] eq '^') {
+	   && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
 	# Part of a span.
 	push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
 	$current_column++;
@@ -2391,6 +2428,9 @@
     $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] = $rowspan;
     for (my $i = 1; $i < $rowspan; $i++) {
 	$Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column] = '^';
+	if ($i == ($rowspan-1)) {
+	    $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column] = '_';
+	}
     }
 
     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);