[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonpreferences.pm /xml londefdef.pm lontexconvert.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 25 Feb 2005 05:54:01 -0000


This is a MIME encoded message

--albertel1109310841
Content-Type: text/plain

albertel		Fri Feb 25 00:54:01 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm lontexconvert.pm 
    /loncom/interface	loncommon.pm lonpreferences.pm 
  Log:
  - adding jsMath as a TeX -> HTML option
  - adding the ability for a user to choose between jsMath and tth
  - setting tth as the default, but I think the default should be based off browser detection, on anything at all modern jsMath is much sexier
  
  
--albertel1109310841
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050225005401.txt"

Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.257 loncom/xml/londefdef.pm:1.258
--- loncom/xml/londefdef.pm:1.257	Fri Feb 18 18:22:43 2005
+++ loncom/xml/londefdef.pm	Fri Feb 25 00:54:01 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.257 2005/02/18 23:22:43 albertel Exp $
+# $Id: londefdef.pm,v 1.258 2005/02/25 05:54:01 albertel Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -84,7 +84,6 @@
     my $currentstring = '';
     my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
     if ($target eq 'web' || $target eq 'analyze') {
-	$inside ='\\documentstyle{article}'.$inside;
 	&Apache::lonxml::debug("M is starting with:$inside:");
 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
 	if ($eval eq 'on') {
Index: loncom/xml/lontexconvert.pm
diff -u loncom/xml/lontexconvert.pm:1.58 loncom/xml/lontexconvert.pm:1.59
--- loncom/xml/lontexconvert.pm:1.58	Thu Feb 24 05:09:32 2005
+++ loncom/xml/lontexconvert.pm	Fri Feb 25 00:54:01 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # TeX Conversion Module
 #
-# $Id: lontexconvert.pm,v 1.58 2005/02/24 10:09:32 albertel Exp $
+# $Id: lontexconvert.pm,v 1.59 2005/02/25 05:54:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -117,12 +117,14 @@
     return ($xmlstring,$errorstring);
 }
 
-sub converted {
+sub tth_converted {
     my $texstring=shift;
     my $xmlstring='['.&mt('UNDISPLAYABLE').']';
     if ($Apache::lontexconvert::messedup) {
 	return '['.&mt('TeX unconverted due to previous errors').']';
     }
+    $$texstring ='\\documentstyle{article}'.$$texstring;
+
     eval(<<'ENDCONV');
     ($xmlstring,$errorstring)=&convert_real($texstring)
 ENDCONV
@@ -140,6 +142,29 @@
     return $xmlstring;
 }
 
+sub jsMath_converted {
+    my $texstring=shift;
+    my $tag='span';
+    if ($$texstring=~/[^\\]\$\$/) {
+	#has a $$ in it, guessinng it's display mode
+	$tag='div';
+    }
+    &Apache::lonnet::logthis($$texstring);
+    $$texstring=~s/(?!\\)\$//g;
+    $$texstring=~s/\\ensuremath//g
+    &Apache::lonnet::logthis($$texstring);
+    return '<'.$tag.' class="math">'.$$texstring.'</'.$tag.'>';
+}
+
+sub converted {
+    if ($ENV{'environment.texengine'} eq 'tth') {
+	return &tth_converted;
+    } elsif ($ENV{'environment.texengine'} eq 'jsMath') {
+	return &jsMath_converted;
+    }
+    return &tth_converted;
+}
+
 # ====================================================================== Footer
 
 sub footer {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.251 loncom/interface/loncommon.pm:1.252
--- loncom/interface/loncommon.pm:1.251	Thu Feb 24 23:56:05 2005
+++ loncom/interface/loncommon.pm	Fri Feb 25 00:54:01 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.251 2005/02/25 04:56:05 albertel Exp $
+# $Id: loncommon.pm,v 1.252 2005/02/25 05:54:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2632,6 +2632,13 @@
 <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"
 style="margin-top: 0px;$addstyle" $addentries>
 END
+    if ($ENV{'environment.texengine'} eq 'jsMath') {
+	$bodytag.='<script type="text/javascript">
+                     function NoFontMessage () {}
+                   </script>'."\n".
+	    '<script src="/adm/jsMath/jsMath.js"></script>'."\n";
+    }
+
     my $upperleft='<img src="http://'.$ENV{'HTTP_HOST'}.':'.
                    $lonhttpdPort.$img.'" alt="'.$function.'" />';
     if ($bodyonly) {
@@ -2776,6 +2783,10 @@
 
 sub endbodytag {
     my $endbodytag='</body>';
+    if ($ENV{'environment.texengine'} eq 'jsMath') {
+	$endbodytag='<script type="text/javascript">jsMath.Process()</script>'.
+	    "\n".$endbodytag;
+    }
     return $endbodytag;
 }
 
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.53 loncom/interface/lonpreferences.pm:1.54
--- loncom/interface/lonpreferences.pm:1.53	Thu Feb 17 03:29:43 2005
+++ loncom/interface/lonpreferences.pm	Fri Feb 25 00:54:01 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.53 2005/02/17 08:29:43 albertel Exp $
+# $Id: lonpreferences.pm,v 1.54 2005/02/25 05:54:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -178,6 +178,88 @@
 }
 
 ################################################################
+#         Tex Engine Change Subroutines                        #
+################################################################
+sub texenginechanger {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+    my %userenv = &Apache::lonnet::get('environment',['texengine']);
+    my $texengine=$userenv{'texengine'};
+
+    my $pref=&mt('Preferred method to display Math');
+    my %mathchoices=('' => 'No Preference',
+		     'tth' => 'TeX to HTML',
+		     #'ttm' => 'TeX to MathML',
+		     'jsMath' => 'jsMath',
+		     #'mimetex' => 'Convert to Images'
+                     );
+    my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine',
+						     %mathchoices);
+    my $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$';
+    my $jsMath_example=&Apache::lontexconvert::jsMath_converted(\$mathexample);
+    $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$';
+    my $tth_example=&Apache::lontexconvert::tth_converted(\$mathexample);
+    my $change=&mt('Change');
+    $r->print(<<ENDLSCREEN);
+<form name="server" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_texengine" />
+<p>$pref: $selectionbox</p>
+<p><input type="submit" value="$change" /></p>
+</form>
+Examples:
+<p> TeX to HTML <br /> $tth_example</p>
+<script type"text/javascript">function NoFontMessage () { }</script>
+<script src="/adm/jsMath/jsMath.js"></script>
+<p>jsMath <br /> 
+
+<script type"text/javascript">
+if (jsMath.nofonts == 1) {
+    document.writeln
+        ('<center><div style="padding: 10; border-style: solid; border-width:3;'
+	 +' border-color: #DD0000; background-color: #FFF8F8; width: 75%; text-align: left">'
+	 +'<small><font color="#AA0000"><b>Warning:</b> '
+	 +'It looks like you don\\\'t have the TeX math fonts installed. '
+	 +'The jsMath example on this page may not look right without them. '
+	 +'The <a href="http://www.math.union.edu/locate/jsMath/" target="_blank"> '
+	 +'jsMath Home Page</a> has information on how to download the '
+	 +'needed fonts.  In the meantime, jsMath will do the best it can '
+	 +'with the fonts you have, but it may not be pretty and some equations '
+	 +'may not be rendered correctly. '
+	 +'</font></small></div></center>');
+}
+</script>
+
+$jsMath_example</p>
+<script type="text/javascript">jsMath.Process()</script>
+ENDLSCREEN
+}
+
+
+sub verify_and_change_texengine {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+# Screenname
+    my $newtexengine  = $ENV{'form.texengine'};
+    $newtexengine=~s/[^\-\w]//g;
+    my $message='';
+    if ($newtexengine) {
+        &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
+        &Apache::lonnet::appenv('environment.texengine' => $newtexengine);
+        $message='Set new preferred math display to '.$newtexengine;
+    } else {
+        &Apache::lonnet::del('environment',['texengine']);
+        &Apache::lonnet::delenv('environment\.texengine');
+        $message='Reset preferred math display.';
+    }
+    $r->print(<<ENDVCSCREEN);
+</p>
+$message
+ENDVCSCREEN
+}
+
+################################################################
 #         Roles Page Preference Change Subroutines         #
 ################################################################
 sub rolesprefchanger {
@@ -1048,6 +1130,22 @@
                       printmenu => 'yes',
                       }));
 
+    push (@Options,({ action   => 'changetexenginepref',
+                      linktext => 'Change How Math Equations Are Displayed',
+                      href     => '/adm/preferences',
+                      subroutine => \&texenginechanger,
+                      breadcrumb =>
+                          { href => '/adm/preferences?action=changetexenginepref',
+                            text => 'Change Math Pref'},
+                      },
+                    { action   => 'verify_and_change_texengine',
+                      subroutine => \&verify_and_change_texengine,
+                      breadcrumb =>
+                          { href => '/adm/preferences?action=changetexenginepref',
+                            text => 'Change Math Preferences'},
+                      printmenu => 'yes',
+                      }));
+
 
     if ($ENV{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle)$/) {
         push (@Options,({ action => 'debugtoggle',
@@ -1126,10 +1224,7 @@
 	$r->print('<br /><a href="'.$ENV{'form.returnurl'}.'"><font size="+1">'.
 		  &mt('Return').'</font></a>');
     }
-    $r->print(<<ENDFOOTER);
-</body>
-</html>
-ENDFOOTER
+    $r->print(&Apache::loncommon::endbodytag().'</html>');
     return OK;
 }
 

--albertel1109310841--