--- loncom/xml/lontexconvert.pm 2012/02/28 10:38:14 1.110 +++ loncom/xml/lontexconvert.pm 2016/01/22 22:31:51 1.117 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # TeX Conversion Module # -# $Id: lontexconvert.pm,v 1.110 2012/02/28 10:38:14 foxr Exp $ +# $Id: lontexconvert.pm,v 1.117 2016/01/22 22:31:51 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,14 +54,53 @@ use IO::Socket::INET; # # Table of substitutions to unicode characters. # + +my %unicode_harpoons = ( + '\rightleftharpoons' => 0x21cc, + ); + my %unicode_translations = ( - '\rightleftharpoons' => 0x21cc, + +# Brackets - unicode for browsers/OS which support it. + '' => 0x23a1, '' => 0x23a2, '' => 0x23a3, '' => 0x23a4, '' => 0x23a5, - '' => 0x23a6 + '' => 0x23a6, + +# Parens - unicode for browsers/OS which support it + + '' => 0x239b, + '' => 0x239c, + '' => 0x239d, + '' => 0x239e, + '' => 0x239f, + '' => 0x23a0, + +); + +my %ascii_8bit_translations = ( + +# Brackets - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode + + '' => 0x5b, + '' => 0x5b, # '[' + '' => 0x5b, + '' => 0x5d, # ']' + '' => 0x5d, + '' => 0x5d, + +# Parens - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode + + '' => 0x28, + '' => 0x28, # '(' + '' => 0x28, + '' => 0x29, + '' => 0x29, # '(' + '' => 0x29, + ); ## @@ -126,14 +165,12 @@ sub convert_real { }; &Apache::lonxml::start_alarm(); if ($env{'browser.mathml'}) { - &Apache::lonnet::logthis("mathml"); $xmlstring=&tth::ttm($$texstring); $xmlstring=~s/\/\/g; $xmlstring=~s/\/\/g; $xmlstring=~s/\/\\<\/p\>/g; $errorstring.=&tth::ttmerror(); } else { - &Apache::lonnet::logthis("tth"); $xmlstring=&tth::tth($$texstring); $errorstring.=&tth::ttherror(); $xmlstring=~s---g; @@ -141,19 +178,37 @@ sub convert_real { $xmlstring=~s/^\s*\
unicode equivalents to render reliably - # in browsers. %unicode_translations is a table of - # string->substitution which we now apply: + # in browsers. %unicode_translations and %unicode_harpoons are tables of + # string->substitution which we now apply. (%ascii_8bit_translations used + # instead for Windows XP and mobile devices. + + my $use_ascii; + if ($env{'browser.os'} eq 'win') { + if (($env{'browser.osversion'}) && ($env{'browser.osversion'} < 6.0)) { + $use_ascii = 1; + } + } + if ($env{'browser.mobile'}) { + $use_ascii = 1; + } foreach my $pattern (keys(%unicode_translations)) { my $unicode = $unicode_translations{$pattern}; + if ($use_ascii) { + $unicode = $ascii_8bit_translations{$pattern}; + } $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode); } + foreach my $pattern (keys(%unicode_harpoons)) { + $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode_harpoons{$pattern}); + } return ($xmlstring,$errorstring); } @@ -468,7 +523,7 @@ sub msgtexconverted { foreach my $fragment (split(/(?:\<\;|\<)\/*algebra\s*(?:\>\;|\>)/i, $message)) { if ($tex) { - my $algebra = &algebra($fragment, 'web', undef, undef, undef, undef, 'tth'); + my $algebra = &algebra($fragment, 'web', undef, undef, undef, 'tth'); if ($email) { $outmessage.=''.$algebra.'
';
 		$tex=0;
@@ -553,6 +608,8 @@ sub postprocess_algebra {
     $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
     return $string;
 }
+
+
 1;
 __END__