[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 21 Feb 2002 04:10:31 -0000


albertel		Wed Feb 20 23:10:31 2002 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  - improved tex conversion of <img src="" />, handles .gif and .jpg files, with an already existing .eps file
     - also improved reference generation for tags with relative references
  
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.41 loncom/xml/londefdef.pm:1.42
--- loncom/xml/londefdef.pm:1.41	Fri Jan 18 11:33:54 2002
+++ loncom/xml/londefdef.pm	Wed Feb 20 23:10:31 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.41 2002/01/18 16:33:54 sakharuk Exp $
+# $Id: londefdef.pm,v 1.42 2002/02/21 04:10:31 albertel Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -1331,17 +1331,35 @@
             $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
                                         $token->[2]->{'src'};
             my $currentstring = '';
-            if ($target eq 'web') {
+	    if ($target eq 'web') {
               $currentstring = $token->[4];     
 	    } elsif ($target eq 'tex') {
-                my $durty = $token->[2]->{'src'};
-                $durty =~ s!(^.*)/(.*)$!$1/!;
-                my $durtytwo = $2;
-                my $num = index($durtytwo,'gif',0);
-		substr($durtytwo,$num,3) = 'eps';
-		$currentstring = '\graphicspath{{/home/httpd/html'.$durty.'}}\fbox{\includegraphics{'.$durtytwo.'}}';
-	    } 
-	   return $currentstring;
+	      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval);
+	      my $file;
+	      my $path;
+              if ($src =~ m!(.*)/([^/]*)$!) {
+		$file = $2;
+		$path = $1;
+		if ($path=~m:^/:) {
+		  $path = '/home/httpd/html'.$path;
+		} elsif ($path =~ /^\./) {
+		  $path = $Apache::lonxml::pwd[-1].'/'.$path;
+		} else {
+		  #else it is a full url don't print
+		  $path = undef;
+		}
+	      } else {
+		$path = $Apache::lonxml::pwd[-1];
+		$file = $src;
+	      }
+	      $file=~s/(\.gif|\.jpg)^/\.eps/;
+	      if ($path) {
+		$currentstring = '\graphicspath{{'.$path.'}}\fbox{\includegraphics{'.$file.'}}';
+	      } else {
+		$currentstring = 'See the image at \tt{'.$src.'}';
+	      }
+	    }
+	    return $currentstring;
 	}
         sub end_img {
 	    my ($target,$token) = @_;