--- loncom/xml/londefdef.pm 2005/07/11 10:27:58 1.280
+++ loncom/xml/londefdef.pm 2005/10/10 09:13:19 1.288
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.280 2005/07/11 10:27:58 foxr Exp $
+# $Id: londefdef.pm,v 1.288 2005/10/10 09:13:19 foxr Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -47,7 +47,7 @@ use Image::Magick;
use Apache::lonmenu();
use Apache::lonmeta();
use Apache::Constants qw(:common);
-
+use File::Basename;
BEGIN {
@@ -55,6 +55,7 @@ BEGIN {
}
+
sub initialize_londefdef {
$Apache::londefdef::TD_redirection=0;
@Apache::londefdef::table = ();
@@ -166,6 +167,7 @@ sub start_html {
'\usepackage{textcomp}'.
'\usepackage{makeidx}'.
'\usepackage[dvips]{graphicx}'.
+ '\usepackage{wrapfig}'.
'\usepackage{picins}'.
'\usepackage{epsfig}'.
'\usepackage{calc}'.
@@ -540,6 +542,10 @@ sub start_body {
$currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
}
$currentstring.='>';
+ &Apache::lontexconvert::jsMath_reset();
+ if ($env{'environment.texengine'} eq 'jsMath') {
+ $currentstring.=&Apache::lontexconvert::jsMath_header();
+ }
if ($env{'request.state'} ne 'published') {
if ($env{'environment.remote'} eq 'off') {
$currentstring.=
@@ -1201,6 +1207,9 @@ sub start_br {
} elsif ($target eq 'tex') {
my @tempo=@$tagstack;
my $signal=0;
+ # Not going to factor this to is_inside_of since that would require
+ # multiple stack traversals.
+ #
for (my $i=$#tempo;$i>=0;$i--) {
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
@@ -1948,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'}=[];
@@ -2171,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;
@@ -2551,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");
@@ -2568,7 +2585,7 @@ sub start_img {
undef,0);
&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");
@@ -2609,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.'}';
@@ -3957,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");
@@ -3986,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/;
+ }
}
}
}
@@ -4070,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;