tag (end tag required)
+{
+
+# Since div can be nested, the stack below is used
+# in 'tex' mode to store the ending strings
+# for the div stack.
+
+ my @div_end_stack;
+
sub start_div {
- my ($target,$token) = @_;
+ my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
my $currentstring = &end_p(); # Close enclosing para.
if ($target eq 'web') {
$currentstring .= $token->[4];
}
+ if ($target eq 'tex') {
+ # 4 possible alignments: left, right, center, and -missing-.
+
+ my $endstring = '';
+
+ my $align = lc(&Apache::lonxml::get_param('align', $parstack,
+ $safeeval, undef, 1));
+ if ($align eq 'center') {
+ $currentstring .= '\begin{center}';
+ $endstring = '\end{center}';
+ }
+ elsif ($align eq 'right') {
+ $currentstring .= '\begin{flushright}';
+ $endstring .= '\end{flushright}';
+ } elsif ($align eq 'left') {
+ $currentstring .= '\begin{flushleft}';
+ $endstring = '\end{flushleft}';
+ } else {
+
+ }
+ $currentstring .= "\n"; # For human readability.
+ $endstring = "\n$endstring\n"; # For human readability
+ push(@div_end_stack, $endstring);
+ }
return $currentstring;
}
@@ -1489,9 +1530,14 @@ sub end_div {
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[2];
- }
+ }
+ if ($target eq 'tex') {
+ my $endstring = pop @div_end_stack;
+ $currentstring .= $endstring;
+ }
return $currentstring;
}
+}
#--
tag (end tag required)
sub start_a {
@@ -1911,7 +1957,9 @@ sub start_table {
$Apache::londefdef::table[-1]{'vvinc'} = '';
}
if ($#Apache::londefdef::table==0) {
- $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
+ # Note that \newline seems to destroy the alignment envs.
+ # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
+ $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
}
$Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
$Apache::londefdef::table[-1]{'TeXlen'}=[];
@@ -2134,7 +2182,9 @@ sub end_table {
}
$output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
}
- $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
+ # Note that \newline destroys alignment env's produced by e.g.
+ # $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'};
pop @Apache::londefdef::table;
@@ -2514,7 +2564,11 @@ sub start_img {
$safeeval,
undef,1));
if(!$align) {
- $align = "bottom"; # This is html's default so it's ours too.
+ if (&is_inside_of($tagstack, "table")) {
+ $align = "right"; # Force wraptext use.
+ } else {
+ $align = "bottom"; # This is html's default so it's ours too.
+ }
}
#
&Apache::lonxml::debug("Alignemnt = $align");
@@ -2572,16 +2626,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.'}';
@@ -3920,7 +3975,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 +4012,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/;
+ }
}
}
}
@@ -4033,6 +4099,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;