--- loncom/xml/lonlatextable.pm 2010/08/18 12:04:31 1.1 +++ loncom/xml/lonlatextable.pm 2010/08/27 09:42:48 1.2 @@ -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 @@ array element is a table row. However: 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 generate_string { 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_header() # 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; } #