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

hauer hauer@source.lon-capa.org
Thu, 04 Dec 2008 09:51:15 -0000


hauer		Thu Dec  4 09:51:15 2008 EDT

  Modified files:              
    /loncom/xml	lontexconvert.pm 
  Log:
  I have edited the implementation of mimetex to calculate the vertical-align-value for the images, so that the mimetex-gifs are aligned to the surrounding text correctly. I have commented the call, because there is still a hard dependence to a http-connection to the local server. This is a problem (and the timeouts are to high in this solution). We try to get this functionality now working without calling http by doing it local with the mimetex.cgi on the server. I have nevertheless commited this code, so that you can review it. Search for FIXME.
  
  
Index: loncom/xml/lontexconvert.pm
diff -u loncom/xml/lontexconvert.pm:1.91 loncom/xml/lontexconvert.pm:1.92
--- loncom/xml/lontexconvert.pm:1.91	Mon Nov 24 17:17:51 2008
+++ loncom/xml/lontexconvert.pm	Thu Dec  4 09:51:14 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # TeX Conversion Module
 #
-# $Id: lontexconvert.pm,v 1.91 2008/11/24 17:17:51 jms Exp $
+# $Id: lontexconvert.pm,v 1.92 2008/12/04 09:51:14 hauer Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,6 +47,7 @@
 use Apache::lonnet;
 use lib '/home/httpd/lib/perl/';
 use LONCAPA;
+use LWP::UserAgent;
  
 
 # ====================================================================== Header
@@ -241,6 +242,21 @@
     return;
 }
 
+sub mimetex_valign {
+    my ($texstring)=@_;
+    my $ua = LWP::UserAgent->new; #from the perldoc of LWP::UserAgent
+    $ua->timeout(10); 
+    $ua->env_proxy;
+    #header without imagedata saved to response:
+    my $response = $ua->head('http://lcdevhost.localdomain/cgi-bin/mimetex.cgi?'.$texstring);
+    if ($response->is_success) {
+        #get the valign-value:
+        return($response->headers->{'vertical-align'});}
+    else {
+        return(0); #if (error) than continue without valign
+    }
+}
+
 sub mimetex_converted {
     my $texstring=shift;
     my $displaystyle=&displaystyle($texstring);
@@ -250,6 +266,12 @@
     if ($displaystyle) {
 	$$texstring='\\displaystyle \\Large '.$$texstring;
     }
+
+# FIXME
+# this is the line that calls the new function mimetex_valign above:
+#   my $result='<img src="/cgi-bin/mimetex.cgi?'.&escape($$texstring).'" style="vertical-align:'.&mimetex_valign($$texstring).'px" alt="$'.$$texstring.'$" />';
+#
+# this line is the old implementation  without valign of the images:
     my $result='<img src="/cgi-bin/mimetex.cgi?'.&escape($$texstring).'" alt="$'.$$texstring.'$" />';
     if ($displaystyle) {
 	$result='<center>'.$result.'</center>';