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

foxr foxr@source.lon-capa.org
Fri, 27 Aug 2010 09:42:49 -0000


foxr		Fri Aug 27 09:42:49 2010 EDT

  Modified files:              
    /loncom/xml	londefdef.pm lonlatextable.pm lontable.pm 
  Log:
  BZ 6331 - Replace LaTeX::Table usage with lonlatextable which is a simple
  subset that is ok in safe space.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.421 loncom/xml/londefdef.pm:1.422
--- loncom/xml/londefdef.pm:1.421	Mon Aug 16 15:56:08 2010
+++ loncom/xml/londefdef.pm	Fri Aug 27 09:42:48 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.421 2010/08/16 15:56:08 raeburn Exp $
+# $Id: londefdef.pm,v 1.422 2010/08/27 09:42:48 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2193,7 +2193,9 @@
 
 	my $table = pop(@Apache::londefdef::table);
 	my $t     = $table->generate();
+	&Apache::lonnet::logthis("Generating string");
 	$currentstring = $t->generate_string();
+	&Apache::lonnet::logthis("Generated: $currentstring");
 	&enable_para();
 	#--------------------------------------------------------------
 	#  Old table code:
Index: loncom/xml/lonlatextable.pm
diff -u loncom/xml/lonlatextable.pm:1.1 loncom/xml/lonlatextable.pm:1.2
--- loncom/xml/lonlatextable.pm:1.1	Wed Aug 18 12:04:31 2010
+++ loncom/xml/lonlatextable.pm	Fri Aug 27 09:42:48 2010
@@ -1,6 +1,6 @@
 #  Generating TeX tables.
 #
-# $Id: lonlatextable.pm,v 1.1 2010/08/18 12:04:31 foxr Exp $
+# $Id: lonlatextable.pm,v 1.2 2010/08/27 09:42:48 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -140,7 +140,7 @@
 These are treated as LaTeX/TeX commands and, when the table is generated, 
 passed without interpretation.
 
-=item Empty cells
+=item Lines with one cell that is empty.
 
 These produce a horizontal rule that spans the width of the table.
 
@@ -222,7 +222,7 @@
 sub table_header()
 {
     my ($self) = @_;
-    my $result = 'begin{tabular}[';
+    my $result = '\begin{tabular}{';
     my $coldef = $self->{'coldef'};
 
     if ($coldef eq '') {
@@ -252,7 +252,37 @@
 #
 sub table_body()
 {
-    return '';
+    my ($self) = @_;
+    my $result = '';
+    foreach my $row (@{$self->{'data'}}) {
+	#
+	# If a row has only a single cell we need to deal with the two special cases
+	# Pass LaTeX uninterpreted or \hline.
+	#
+	if ((scalar @{$row}) == 1) {
+	    my $cell = $row->[0];
+	    if ($cell eq '') {
+		$result .= '\hline' . "\n";
+	    } elsif (substr($cell, 0, 1) eq "\\") {
+		$result .= $cell . "\n";
+	    } else {
+		# could just be a table with one col...
+
+		$result .= $cell . ' \\\\ ' ."\n";
+	    }
+	} else {
+	    my $line = '';
+	    foreach my $cell (@{$row}) {
+		$line .= $cell . ' & ';
+	    }
+	    #  Replace the last ' & ' with \\ and a line terminator..
+	    #  and append the line to the result.
+
+	    $line =~ s/ & $/ \\\\\n/;
+	    $result .= $line;
+	}
+    }
+    return $result;
 }
 
 #
Index: loncom/xml/lontable.pm
diff -u loncom/xml/lontable.pm:1.11 loncom/xml/lontable.pm:1.12
--- loncom/xml/lontable.pm:1.11	Wed Aug 11 10:57:36 2010
+++ loncom/xml/lontable.pm	Fri Aug 27 09:42:49 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 #  Generating TeX tables.
 #
-# $Id: lontable.pm,v 1.11 2010/08/11 10:57:36 foxr Exp $
+# $Id: lontable.pm,v 1.12 2010/08/27 09:42:49 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -38,7 +38,7 @@
 #
 
 # This module is a support packkage that helps londefdef generate
-# LaTeX tables using the LaTeX::Table package.  A prerequisite is that
+# LaTeX tables using the Apache::lonlatextable package.  A prerequisite is that
 # the print generator must have added the following to the LaTeX 
 #
 #  \usepackage{xtab}
@@ -55,17 +55,17 @@
 
 package Apache::lontable;
 use strict;
-use LaTeX::Table;
+use Apache::lonlatextable;
 use Apache::lonnet;		# for trace logging.
 
-my $tracing = 0;		# Set to 1 to enable log tracing. 2 for local sub tracing.
+my $tracing = 1;		# Set to 1 to enable log tracing. 2 for local sub tracing.
 
 =pod
 
 =head1  lontable Table generation assistant for the LaTeX target
 
 This module contains support software for generating tables in LaTeX output mode 
-In this implementation, we use the LaTeX::Table package to do the actual final formatting.
+In this implementation, we use the Apache::lonlatextable package to do the actual final formatting.
 Each table creates a new object.  Table objects can have global properties configured.
 The main operations on a table object are:
 
@@ -131,8 +131,8 @@
 
 The theme of the table to use.  Defaults to Zurich.  Themes we know about are:
 NYC, NYC2, Zurich, Berlin, Dresden, Houston, Miami, plain, Paris.  Other themes can be added
-to the LaTeX::Table package, and they will become supported automatically, as theme names are
-not error checked.  Any use of a non-existent theme is reported by the LaTeX::Table package
+to the Apache::lonlatextable package, and they will become supported automatically, as theme names are
+not error checked.  Any use of a non-existent theme is reported by the Apache::lonlatextable package
 when the table text is generated.
 
 =item width
@@ -730,10 +730,8 @@
     my $colunits;
 
     if($tracing) {&Apache::lonnet::logthis("generate"); }
-    my $table = LaTeX::Table->new();
-    $table->set_center(0);	# loncapa tables don't float.
-    $table->set_environment(0);
-    $table->set_theme($this->{'theme'});
+    my $table = Apache::lonlatextable->new();
+
 
 
     # Add the caption if supplied.
@@ -847,7 +845,6 @@
 		}
 	    }
 	    if ($inner_border && ($cells->[$cell]->{'rowspan'} == 1)) {
-		&Apache::lonnet::logthis("Pushing underlines $inner_border");
 		my $lastcol = $nextcol -1;
 		push(@underlines, "\\cline{$startcol-$lastcol}");
 	    }
@@ -859,7 +856,6 @@
 	}
 	push(@data, \@row);
 	if ($inner_border) {
-	    &Apache::lonnet::logthis("Pushing underlines with inner_border");
 	    for (my $i =0; $i < scalar(@underlines); $i++) {
 		push(@data, [$underlines[$i]]);
 	    }
@@ -878,7 +874,6 @@
     
     my $coldef = "";
     if ($outer_border || $inner_border) {
-	&Apache::lonnet::logthis("adding | $outer_border : $inner_border");
 	$coldef .= '|';
     }
     for (my $i =0; $i < $column_count; $i++) {
@@ -898,6 +893,7 @@
 
     if ($tracing) { &Apache::lonnet::logthis("Leaving generate"); }
 
+
     return $table;
 
 }