version 1.9, 2009/01/26 09:39:19
|
version 1.13, 2010/09/28 22:55:41
|
Line 38
|
Line 38
|
# |
# |
|
|
# This module is a support packkage that helps londefdef generate |
# 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 |
# the print generator must have added the following to the LaTeX |
# |
# |
# \usepackage{xtab} |
# \usepackage{xtab} |
Line 55
|
Line 55
|
|
|
package Apache::lontable; |
package Apache::lontable; |
use strict; |
use strict; |
# use LaTeX::Table; |
use Apache::lonlatextable; |
use Apache::lonnet; # for trace logging. |
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 |
=pod |
|
|
=head1 lontable Table generation assistant for the LaTeX target |
=head1 lontable Table generation assistant for the LaTeX target |
|
|
This module contains support software for generating tables in LaTeX output mode |
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. |
Each table creates a new object. Table objects can have global properties configured. |
The main operations on a table object are: |
The main operations on a table object are: |
|
|
Line 131 The table caption text.
|
Line 131 The table caption text.
|
|
|
The theme of the table to use. Defaults to Zurich. Themes we know about are: |
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 |
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 |
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 LaTeX::Table package |
not error checked. Any use of a non-existent theme is reported by the Apache::lonlatextable package |
when the table text is generated. |
when the table text is generated. |
|
|
=item width |
=item width |
Line 265 sub new {
|
Line 265 sub new {
|
outer_border => 0, |
outer_border => 0, |
inner_border => 0, |
inner_border => 0, |
caption => "", |
caption => "", |
theme => "Zurich", |
theme => "plain", |
column_count => 0, |
column_count => 0, |
row_open => 0, |
row_open => 0, |
rows => [], |
rows => [], |
Line 730 sub generate {
|
Line 730 sub generate {
|
my $colunits; |
my $colunits; |
|
|
if($tracing) {&Apache::lonnet::logthis("generate"); } |
if($tracing) {&Apache::lonnet::logthis("generate"); } |
my $table = LaTeX::Table->new(); |
my $table = Apache::lonlatextable->new(); |
$table->set_center(0); # loncapa tables don't float. |
|
$table->set_environment(0); |
|
|
|
|
|
# Add the caption if supplied. |
# Add the caption if supplied. |
Line 761 sub generate {
|
Line 760 sub generate {
|
my $outer_border = $this->{'outer_border'}; |
my $outer_border = $this->{'outer_border'}; |
my $column_count = $this->{'column_count'}; |
my $column_count = $this->{'column_count'}; |
|
|
|
# Add a top line if the outer or inner border is enabled: |
|
|
|
if ($outer_border || $inner_border) { |
|
push(@data, ["\\cline{1-$column_count}"]); |
|
|
|
} |
|
|
for (my $row = 0; $row < $row_count; $row++) { |
for (my $row = 0; $row < $row_count; $row++) { |
my @row; |
my @row; |
my $cells = $rows->[$row]->{'cells'}; |
my $cells = $rows->[$row]->{'cells'}; |
Line 770 sub generate {
|
Line 776 sub generate {
|
my @underlines; # Array of \cline cells if cellborder on. |
my @underlines; # Array of \cline cells if cellborder on. |
|
|
|
|
|
|
for (my $cell = 0; $cell < $cell_count; $cell++) { |
for (my $cell = 0; $cell < $cell_count; $cell++) { |
my $contents = $cells->[$cell]->{'contents'}; |
my $contents = $cells->[$cell]->{'contents'}; |
|
|
Line 792 sub generate {
|
Line 799 sub generate {
|
|
|
if ($halign eq 'right') { |
if ($halign eq 'right') { |
$col_align = 'r'; |
$col_align = 'r'; |
$embeddedAlignStart = '\begin{flushright} '; |
$embeddedAlignStart = '\raggedleft'; |
$embeddedAlignEnd = ' \end{flushright}'; |
|
} |
} |
if ($halign eq 'center') { |
if ($halign eq 'center') { |
$col_align = 'c'; |
$col_align = 'c'; |
Line 855 sub generate {
|
Line 861 sub generate {
|
} |
} |
|
|
} |
} |
|
# |
|
# Add bottom border if necessary: if the inner border was on, the loops above |
|
# will have done a bottom line under the last cell. |
|
# |
|
if ($outer_border && !$inner_border) { |
|
push(@data, ["\\cline{1-$column_count}"]); |
|
|
|
} |
$table->set_data(\@data); |
$table->set_data(\@data); |
|
|
my $coldef = ""; |
my $coldef = ""; |
Line 878 sub generate {
|
Line 892 sub generate {
|
|
|
if ($tracing) { &Apache::lonnet::logthis("Leaving generate"); } |
if ($tracing) { &Apache::lonnet::logthis("Leaving generate"); } |
|
|
|
|
return $table; |
return $table; |
|
|
} |
} |