version 1.14, 2003/02/03 18:03:53
|
version 1.31, 2004/03/04 15:40:22
|
Line 44 package Apache::lontexconvert;
|
Line 44 package Apache::lontexconvert;
|
use strict; |
use strict; |
use tth; |
use tth; |
use vars qw($errorstring); |
use vars qw($errorstring); |
|
use Apache(); |
use Apache::lonmsg; |
use Apache::lonmsg; |
use Apache::lonxml; |
use Apache::lonxml; |
|
use Apache::lonmenu; |
|
|
# ====================================================================== Header |
# ====================================================================== Header |
|
|
|
sub init_tth { |
|
my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; |
|
if ($ENV{'browser.mathml'}) { |
|
&tth::ttminit(); |
|
if ($ENV{'browser.unicode'}) { |
|
&tth::ttmoptions('-L -u1 '.$options); |
|
} else { |
|
&tth::ttmoptions('-L -u0 '.$options); |
|
} |
|
} else { |
|
&tth::tthinit(); |
|
if ($ENV{'browser.unicode'}) { |
|
&tth::tthoptions('-L -u1 '.$options); |
|
} else { |
|
&tth::tthoptions('-L -u0 '.$options); |
|
} |
|
} |
|
} |
|
|
sub header { |
sub header { |
$errorstring=''; |
$errorstring=''; |
my $time=time; |
my $time=time; |
if ($ENV{'browser.mathml'}) { |
&init_tth(); |
&tth::ttminit(); |
return &Apache::lonxml::xmlbegin(). |
if ($ENV{'browser.unicode'}) { |
&Apache::lonxml::fontsettings(). |
&tth::ttmoptions('-L -u1'); |
"\n<head>\n". |
} else { |
&Apache::lonmenu::registerurl(undef,'tex'). |
&tth::ttmoptions('-L -u0'); |
"\n</head>\n"; |
} |
|
} else { |
|
&tth::tthinit(); |
|
if ($ENV{'browser.unicode'}) { |
|
&tth::tthoptions('-L -u1'); |
|
} else { |
|
&tth::tthoptions('-L -u0'); |
|
} |
|
} |
|
return &Apache::lonxml::xmlbegin(). |
|
&Apache::lonxml::fontsettings(). |
|
"\n<head>\n". |
|
&Apache::lonxml::registerurl(undef,'tex'). |
|
"\n</head>\n"; |
|
} |
} |
|
|
# ================================================================== Conversion |
# ================================================================== Conversion |
|
|
|
$Apache::lontexconvert::messedup=0; |
sub converted { |
sub converted { |
my $texstring=shift; |
my $texstring=shift; |
my $xmlstring='[UNDISPLAYABLE]'; |
my $xmlstring='[UNDISPLAYABLE]'; |
eval(<<'ENDCONV'); |
if ($Apache::lontexconvert::messedup) { |
{ |
return '[TeX Unconverted Due To Previous Errors]'; |
local $SIG{SEGV}=sub { die; }; |
} |
if ($ENV{'browser.mathml'}) { |
eval(<<'ENDCONV'); |
$xmlstring=&tth::ttm($$texstring); |
{ |
$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g; |
local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; }; |
$xmlstring=~s/\<br\>/\<br\/\>/g; |
if ($ENV{'browser.mathml'}) { |
$xmlstring=~s/\<p\>/\<p\>\<\/p\>/g; |
$xmlstring=&tth::ttm($$texstring); |
$errorstring.=&tth::ttmerror(); |
$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g; |
} else { |
$xmlstring=~s/\<br\>/\<br\/\>/g; |
$xmlstring=&tth::tth($$texstring); |
$xmlstring=~s/\<p\>/\<p\>\<\/p\>/g; |
$errorstring.=&tth::ttherror(); |
$errorstring.=&tth::ttmerror(); |
|
} else { |
|
$xmlstring=&tth::tth($$texstring); |
|
$errorstring.=&tth::ttherror(); |
|
$xmlstring=~s-</font(\s*)>-</font>-g; |
|
} |
|
$xmlstring=~s/^\s*//; |
|
$xmlstring=~s/\s*$//; |
} |
} |
} |
|
ENDCONV |
ENDCONV |
return $xmlstring; |
if ($Apache::lontexconvert::messedup || &tth::tthmessedup()) { |
|
&Apache::lonnet::logthis("Trying to kill myself"); |
|
$Apache::lontexconvert::messedup=1; |
|
my $request=Apache->request(); |
|
$request->child_terminate(); |
|
} |
|
return $xmlstring; |
} |
} |
|
|
# ====================================================================== Footer |
# ====================================================================== Footer |
Line 115 sub footer {
|
Line 135 sub footer {
|
|
|
sub to_convert { |
sub to_convert { |
my ($string) = @_; |
my ($string) = @_; |
$string=~s/\<br\s*\/?\>/ /g; |
$string=~s/\<br\s*\/?\>/ /gs; |
|
# $string=~s/\s/ /gs; |
|
$string=&HTML::Entities::decode($string); |
return &converted(\$string); |
return &converted(\$string); |
} |
} |
|
|
|
sub smiley { |
|
my $expression=shift; |
|
if ($ENV{'browser.imagesuppress'} eq 'on') { return $expression; } |
|
my %smileys=('\:\-\)' => 'smiley', |
|
'8\-\)' => 'coolsmile', |
|
'8\-(I|\|)' => 'coolindiff', |
|
':\-(I|\|)' => 'neutral', |
|
'\:\-(o|O|\(\))' => 'shocked', |
|
':\-\(' => 'frowny', |
|
'\;\-\)' => 'wink', |
|
'\:\-P' => 'baeh', |
|
'\:\-(\\\|\\/)' => 'hrrm', |
|
'\:\-D' => 'bigsmile', |
|
'\:\-C' => 'angry', |
|
'\:(\'|\`)\-\(' => 'cry', |
|
'\:\-(X|\#)' => 'lipsrsealed', |
|
'\:\-S' => 'huh'); |
|
my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'}; |
|
foreach (keys %smileys) { |
|
$expression=~s/$_/\<img src="$iconpath\/$smileys{$_}.gif" \/\>/gs; |
|
} |
|
return $expression; |
|
} |
|
|
sub msgtexconverted { |
sub msgtexconverted { |
my $message=shift; |
my $message=shift; |
|
my $email=shift; |
#FIXME this crap needs to go but right now the -L option might be |
$errorstring=''; |
#ignored if this isn;t the first time the tth engine is used |
&init_tth(); |
#thus the \\document class crap, it makes sure we init the LaTeX stuff |
my $outmessage=''; |
if ($ENV{'browser.mathml'}) { |
my $tex=0; |
&tth::ttminit(); |
foreach (split(/(?:\<\;|\<)\/*m\s*(?:\>\;|\>)/i,$message)) { |
&tth::ttmoptions("-L"); |
if ($tex) { |
|
if ($email) { |
|
$outmessage.='</pre><tt>'.&to_convert($_).'</tt><pre>'; $tex=0; |
|
} else { |
|
$outmessage.=&to_convert($_); $tex=0; |
|
} |
|
} else { |
|
$outmessage.=&smiley($_); $tex=1; |
|
} |
|
} |
|
if (wantarray) { |
|
return ($outmessage,$errorstring); |
} else { |
} else { |
&tth::tthinit(); |
return $outmessage.$errorstring; |
&tth::tthoptions("-L"); |
|
} |
} |
$message=~s/(\$\$.+?\$\$)/&to_convert("\\documentclass{article}".$1)/ge; |
|
$message=~s/(\$.+?\$)/&to_convert("\\documentclass{article}".$1)/ge; |
|
$message=~s/(\\\(.+?\\\))/&to_convert("\\documentclass{article}".$1)/ge; |
|
$message=~s/(\\\[.+?\\\])/&to_convert("\\documentclass{article}".$1)/ge; |
|
return $message.$errorstring; |
|
} |
} |
|
|
1; |
1; |