--- loncom/xml/lontexconvert.pm 2011/12/06 16:10:53 1.109 +++ loncom/xml/lontexconvert.pm 2012/03/04 14:58:23 1.111 @@ -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.111 2012/03/04 14:58:23 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,68 @@ use LONCAPA; use URI::Escape; use IO::Socket::INET; + +# +# Table of substitutions to unicode characters. +# +my %unicode_translations = ( + '\rightleftharpoons' => 0x21cc, + +# Brackets - unicode is commented out with pure 8-bit ascii ugliness while we need it. + +# '' => 0x23a1, +# '' => 0x23a2, +# '' => 0x23a3, # when unicode catches up with browsers +# '' => 0x23a4, # use these instead of the cheesey brackets below +# '' => 0x23a5, +# '' => 0x23a6 + '' => 0x5b, + '' => 0x5b, # '[' + '' => 0x5b, + '' => 0x5d, # ']' + '' => 0x5d, + '' => 0x5d, + +# Parens..again the unicode is commented out with the 8-bit ascii ugliness +# turned on until browsers catch up with the unicode world. + +# '' => 0x239b, +# '' => 0x239c, +# '' => 0x239d, +# '' => 0x239e, +# '' => 0x239f, +# '' => 0x23a0 + + '' => 0x28, + '' => 0x28, # '(' + '' => 0x28, + + '' => 0x29, + '' => 0x29, # '(' + '' => 0x29 + + +); + +## +# 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 +155,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 +170,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); }