[LON-CAPA-cvs] cvs: loncom /homework imageresponse.pm

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 10 May 2005 11:24:01 -0000


foxr		Tue May 10 07:24:01 2005 EDT

  Modified files:              
    /loncom/homework	imageresponse.pm 
  Log:
  Defect 3928: gnuplot returns the actual latex required to print it.  Checking
     for \graphicspath as first part of return from body of <img> tag and
     allowing it to set the latex rendering... otherwise, use the
     body as a file and generate the appropriate latex.
  
  
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.67 loncom/homework/imageresponse.pm:1.68
--- loncom/homework/imageresponse.pm:1.67	Fri Apr 22 10:03:56 2005
+++ loncom/homework/imageresponse.pm	Tue May 10 07:24:01 2005
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.67 2005/04/22 14:03:56 albertel Exp $
+# $Id: imageresponse.pm,v 1.68 2005/05/10 11:24:01 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -467,10 +467,25 @@
 	$result=&Apache::edit::end_table();
     } elsif ($target eq 'tex') {
 	my $src = &Apache::lonxml::endredirection();
-	my ($path,$file) = &Apache::londefdef::get_eps_image($src);
-	my ($height_param,$width_param)=
-	    &Apache::londefdef::image_size($src,0.3,$parstack,$safeeval);
-	$Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
+
+	#  There may be all sorts of whitespace on fore and aft:
+
+	$src =~ s/\s+$//;
+	$src =~ s/^\s+//;
+
+	#
+	#  Gnuplot e.g. just generates the latex to put inplace.
+	#
+	my $graphinclude;
+	if ($src =~ /^\\graphicspath/) {
+	    $graphinclude = $src;
+	} else {
+	    my ($path,$file) = &Apache::londefdef::get_eps_image($src);
+	    my ($height_param,$width_param)=
+		&Apache::londefdef::image_size($src,0.3,$parstack,$safeeval);
+	    $graphinclude = '\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'}';
+	}
+	$Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent '.$graphinclude;
     } 
     return $result;
 }