+ # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
+ $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
if ($#Apache::londefdef::table > 0) {
my $inmemory = $Apache::londefdef::table[-1]{'output'};
+ # Figure out max/and min width by summing us and then
+ # apply that to the current column of the table we nest in
+ # if it's larger than the current width or the current width
+ # is undefined.
+ #
+ my $min_nested_width = 0;
+ my $max_nested_width = 0;
+ for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
+ $min_nested_width += $min_len[$col];
+ $max_nested_width += $max_len[$col];
+
+ }
+ # Fudge in an extra 5 mm for borders etc:
+
+ $min_nested_width += 5;
+ $max_nested_width += 5;
+
+ my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
+ my $outer_row = $Apache::londefdef::table[-2]{'row_number'};
+ if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
+ $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
+ }
+ if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
+ $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
+ }
+
pop @Apache::londefdef::table;
push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
} else {
@@ -2163,6 +2358,10 @@ sub start_tr {
push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
}
push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
+ #
+ # Need to save the number of table columns to preserve the max # columns.
+ #
+ $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
$Apache::londefdef::table[-1]{'counter_columns'} = -1;
push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
@@ -2182,6 +2381,14 @@ sub end_tr {
if ($Apache::londefdef::TD_redirection) {
&end_td_tex($parstack,$parser,$safeeval);
}
+ # Counter columns must be the maximum number of columns seen
+ # in the table so far so:
+ if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
+ $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
+ }
+
+
+
}
return $currentstring;
}
@@ -2236,8 +2443,51 @@ sub start_td_tex {
sub end_td_tex {
my ($parstack,$parser,$safeeval) = @_;
- my $current_row = $Apache::londefdef::table[-1]{'row_number'};
- my $data=&Apache::lonxml::endredirection();
+ my $current_row = $Apache::londefdef::table[-1]{'row_number'};
+ my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
+ my $data = &Apache::lonxml::endredirection();
+
+ # 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] =~ /[\^\_]/)) {
+ # Part of a span.
+ push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
+ $current_column++;
+ }
+ $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
+
+
+ # Get the column and row spans.
+ # Colspan can be done via \multicolumn if I can figure out the data structs.
+
+ my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
+ if (!$colspan) {
+ $colspan = 1;
+ }
+
+ my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
+ if (!$rowspan) {
+ $rowspan = 1;
+ }
+
+
+
+ for (my $c = 0; $c < $colspan; $c++) {
+ $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
+ for (my $i = 1; $i < $rowspan; $i++) {
+ $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
+ if ($i == ($rowspan-1)) {
+ $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
+ }
+ }
+ }
+
my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
if (defined $TeXwidth) {
push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
@@ -2314,11 +2564,43 @@ sub end_td_tex {
push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
}
}
- for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
- $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
- }
+ # Substitute all of the tables nested in this cell in their appropriate places.
+
+
+ my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
+ for (my $in=0; $in<=$nested_count; $in++) {
+ my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
+ $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
+ # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
+ $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
+
+ }
+ # Should be be killing off the 'include' elements as they're used up?
+
push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
- return'';
+
+
+
+
+ # the colspan array will indicate how many columns will be spanned by this
+ # cell..this requires that counter_columns also be adjusted accordingly
+ # so that the next bunch of text goes in the right cell. Note that since
+ # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
+ #
+
+ $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
+ for (my $i = 0; $i < ($colspan -1); $i++) {
+ push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
+ }
+ for (my $r = 0; $r < $rowspan; $r++) {
+ $Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
+ # Put empty text in spanned cols.
+
+ }
+
+
+
+ return '';
}
sub end_td {
@@ -2474,14 +2756,14 @@ sub end_th {
# (Note there seems to also be support for this as a % of page size)
#
sub start_img {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
undef,1);
if (not $src and ($target eq 'web' or $target eq 'tex')) {
- my $inside = &Apache::lonxml::get_all_text("/img",$parser);
+ my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
return '';
}
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
my $scaling = .3;
@@ -2514,7 +2796,7 @@ sub start_img {
$safeeval,
undef,1));
if(!$align) {
- $align = "bottom"; # This is html's default so it's ours too.
+ $align = "bottom"; # This is html's default so it's ours too.
}
#
&Apache::lonxml::debug("Alignemnt = $align");
@@ -2529,11 +2811,17 @@ sub start_img {
$parstack,
$safeeval,
undef,0);
- &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
+ # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
if(!$latex_rendering) {
- $latex_rendering = "parbox";
+ $latex_rendering = "texwrap";
}
- &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
+ # using texwrap inside a table does not work. So, if after all of this,
+ # texwrap is on, we turn it off if we detect we're in a table:
+ #
+ if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
+ $latex_rendering = 'parpic';
+ }
+ # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
#if original gif/jpg/png file exist do following:
my $origsrc=$src;
@@ -2572,16 +2860,17 @@ sub start_img {
} elsif ($align eq "left") {
if ($latex_rendering eq "parpic") {
$currentstring = '\parpic[l]{'.$currentstring.'}';
- } else { # parbox rendering
- $currentstring = "\\strut\\newline\n".
- '\parbox{'.$width_param.'mm}{'.$currentstring.'}';
+ } else { # wrapfig render
+ $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}'
+ .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
}
} elsif ($align eq "right") {
if ($latex_rendering eq "parpic") {
$currentstring = '\parpic[r]{'.$currentstring.'}';
- } else { # parbox rendering.
- $currentstring = '\parbox{'.$width_param.'mm}{\begin{flushright}'
- .$currentstring.'\end{flushright}} \newline'."\n";
+ } else { # wrapfig rendering
+ $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}'
+ .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
+
}
} else { # Bottom is also default.
# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
@@ -2686,12 +2975,10 @@ sub start_applet {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
-
+ &Apache::lonxml::extlink($code);
my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
-
+ &Apache::lonxml::extlink($archive);
my $currentstring = '';
if ($target eq 'web') {
if ($env{'browser.appletsuppress'} ne 'on') {
@@ -2737,7 +3024,7 @@ sub end_applet {
sub start_embed {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
if ($target eq 'web') {
if ($env{'browser.embedsuppress'} ne 'on') {
@@ -2768,13 +3055,15 @@ sub end_embed {
#--
tag (end tag forbidden)
sub start_param {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- if (&Apache::lonxml::get_param
- ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
- }
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+ if (&Apache::lonxml::get_param('name',$parstack,
+ $safeeval,undef,1)=~/^cabbase$/i) {
+ my $value=&Apache::lonxml::get_param('value',$parstack,
+ $safeeval,undef,1);
+ &Apache::lonxml::extlink($value);
+ }
+
+ my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
if ($target eq 'web') {
my %toconvert;
@@ -2806,9 +3095,8 @@ sub end_param {
sub start_allow {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
- $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonnet::clutter($src);
+ &Apache::lonxml::extlink($src);
+
if ($target eq 'tex') { &image_replication($src); }
my $result;
if ($target eq 'edit') {
@@ -2907,6 +3195,7 @@ sub start_pre {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\begin{verbatim}';
+ &Apache::lonxml::disable_LaTeX_substitutions();
}
return $currentstring;
}
@@ -2918,6 +3207,7 @@ sub end_pre {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '\end{verbatim}';
+ &Apache::lonxml::enable_LaTeX_substitutions();
}
return $currentstring;
}
@@ -3402,9 +3692,12 @@ sub end_legend {
#--
tag (end tag forbidden)
sub start_link {
- my ($target,$token) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
+ my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
+ undef,1);
+ &Apache::lonxml::extlink($href);
$currentstring = $token->[4];
}
return $currentstring;
@@ -3920,7 +4213,15 @@ sub image_height {
sub get_eps_image {
my ($src)=@_;
my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
+
+ # In order to prevent the substitution of the alt text, we need to
+ # be sure the orig_src file is on system now so:
+
+ if (! -e $orig_src) {
+ &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
+ }
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
+ my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
&Apache::lonxml::debug("Filelocation gives: $src");
@@ -3949,6 +4250,9 @@ sub get_eps_image {
close FILE;
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
+ if ($sext ne "") { # Put the ext. back in to uniquify.
+ $src =~ s/\.eps$/$sext.eps/;
+ }
}
}
}
@@ -3988,7 +4292,11 @@ sub file_path {
}
return $file,$path;
}
-
+# Converts a measurement in to mm from any of
+# the other valid LaTeX units of measure.
+# If the units of measure are missing from the
+# parameter, it is assumed to be in and returned
+# with mm units of measure
sub recalc {
my $argument = shift;
if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
@@ -4033,6 +4341,26 @@ sub LATEX_length {
}
+# is_inside_of $tagstack $tag
+# This sub returns true if the current state of Xml processing
+# is inside of the tag.
+# Parameters:
+# tagstack - The tagstack from the parser.
+# tag - The tag (without the <>'s.).
+# Sample usage:
+# if (is_inside_of($tagstack "table")) {
+# # I'm in a table....
+# }
+sub is_inside_of {
+ my ($tagstack, $tag) = @_;
+ my @stack = @$tagstack;
+ for (my $i = ($#stack - 1); $i >= 0; $i--) {
+ if ($stack[$i] eq $tag) {
+ return 1;
+ }
+ }
+ return 0;
+}
1;