--- loncom/xml/lontexconvert.pm 2011/12/06 16:10:53 1.109 +++ loncom/xml/lontexconvert.pm 2012/02/28 10:38:14 1.110 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # TeX Conversion Module # -# $Id: lontexconvert.pm,v 1.109 2011/12/06 16:10:53 dseaton Exp $ +# $Id: lontexconvert.pm,v 1.110 2012/02/28 10:38:14 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,39 @@ use LONCAPA; use URI::Escape; use IO::Socket::INET; + +# +# Table of substitutions to unicode characters. +# +my %unicode_translations = ( + '\rightleftharpoons' => 0x21cc, + '' => 0x23a1, + '' => 0x23a2, + '' => 0x23a3, + '' => 0x23a4, + '' => 0x23a5, + '' => 0x23a6 +); + +## +# Utility to convert elements of a string to unicode: +# +# @param input - Input string +# @param pattern - Pattern to convert +# @param unicode - Unicode to substitute for pattern. +# +# @return string - resulting string. +# +sub unicode_subst { + my ($input, $pattern, $unicode) = @_; + + my $char = pack('U', $unicode); + + $input =~ s/$pattern/$char/g; + + return $input; +} + # ====================================================================== Header sub init_tth { @@ -93,12 +126,14 @@ 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; @@ -106,15 +141,20 @@ 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: + + foreach my $pattern (keys(%unicode_translations)) { + my $unicode = $unicode_translations{$pattern}; + $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode); + } + - &Apache::lonxml::end_alarm(); return ($xmlstring,$errorstring); }