--- loncom/xml/londefdef.pm 2005/07/11 10:27:58 1.280
+++ loncom/xml/londefdef.pm 2005/11/03 21:58:11 1.292
@@ -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.292 2005/11/03 21:58:11 albertel 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;
@@ -2518,7 +2531,7 @@ sub start_img {
my $inside = &Apache::lonxml::get_all_text("/img",$parser);
return '';
}
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
my $scaling = .3;
@@ -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.'}';
@@ -2723,12 +2741,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') {
@@ -2774,7 +2790,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') {
@@ -2805,13 +2821,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;
@@ -2843,9 +2861,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') {
@@ -3439,9 +3456,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;
@@ -3957,7 +3977,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 +4014,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 +4101,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;