version 1.58, 2005/02/24 10:09:32
|
version 1.64, 2005/03/01 03:21:05
|
Line 98 sub convert_real {
|
Line 98 sub convert_real {
|
$Apache::lontexconvert::messedup=1; |
$Apache::lontexconvert::messedup=1; |
die &mt("TeX unconverted due to errors"); |
die &mt("TeX unconverted due to errors"); |
}; |
}; |
alarm($Apache::lonnet::perlvar{'lonScriptTimeout'}); |
&Apache::lonxml::start_alarm(); |
if ($ENV{'browser.mathml'}) { |
if ($ENV{'browser.mathml'}) { |
$xmlstring=&tth::ttm($$texstring); |
$xmlstring=&tth::ttm($$texstring); |
$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g; |
$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g; |
Line 113 sub convert_real {
|
Line 113 sub convert_real {
|
$xmlstring=~s/^\s*\<br clear\=\"all\"/\<br/s; |
$xmlstring=~s/^\s*\<br clear\=\"all\"/\<br/s; |
$xmlstring=~s/^\s*//; |
$xmlstring=~s/^\s*//; |
$xmlstring=~s/\s*$//; |
$xmlstring=~s/\s*$//; |
alarm(0); |
&Apache::lonxml::end_alarm(); |
return ($xmlstring,$errorstring); |
return ($xmlstring,$errorstring); |
} |
} |
|
|
sub converted { |
sub tth_converted { |
my $texstring=shift; |
my $texstring=shift; |
my $xmlstring='['.&mt('UNDISPLAYABLE').']'; |
my $xmlstring='['.&mt('UNDISPLAYABLE').']'; |
if ($Apache::lontexconvert::messedup) { |
if ($Apache::lontexconvert::messedup) { |
return '['.&mt('TeX unconverted due to previous errors').']'; |
return '['.&mt('TeX unconverted due to previous errors').']'; |
} |
} |
|
$$texstring ='\\documentstyle{article}'.$$texstring; |
|
|
eval(<<'ENDCONV'); |
eval(<<'ENDCONV'); |
($xmlstring,$errorstring)=&convert_real($texstring) |
($xmlstring,$errorstring)=&convert_real($texstring) |
ENDCONV |
ENDCONV |
Line 140 ENDCONV
|
Line 142 ENDCONV
|
return $xmlstring; |
return $xmlstring; |
} |
} |
|
|
|
sub clean_out_math_mode { |
|
my ($texstring)=@_; |
|
$$texstring=~s/(?!\\)\$//g; |
|
$$texstring=~s/\\[\)\(\]\[]//g; |
|
$$texstring=~s/\\ensuremath//g; |
|
return ''; |
|
} |
|
|
|
sub displaystyle { |
|
my ($texstring)=@_; |
|
#has a $$ or \[ or \displaystyle in it, guessinng it's display mode |
|
if ($$texstring=~/[^\\]\$\$/ || |
|
$$texstring=~/\\\[/ || |
|
$$texstring=~/\\displaystyle/) { return 1; } |
|
return 0; |
|
} |
|
|
|
sub jsMath_converted { |
|
my $texstring=shift; |
|
my $tag='span'; |
|
if (&displaystyle($texstring)) { $tag='div'; } |
|
&clean_out_math_mode($texstring); |
|
return '<'.$tag.' class="math">'.$$texstring.'</'.$tag.'>'; |
|
} |
|
|
|
sub mimetex_converted { |
|
my $texstring=shift; |
|
my $displaystyle=&displaystyle($texstring); |
|
|
|
&clean_out_math_mode($texstring); |
|
|
|
if ($displaystyle) { |
|
$$texstring='\\displaystyle \\Large '.$$texstring; |
|
} |
|
my $result='<img src="/cgi-bin/mimetex.cgi?'.&Apache::lonnet::escape($$texstring).'" />'; |
|
if ($displaystyle) { |
|
$result='<center>'.$result.'</center>'; |
|
} |
|
return $result; |
|
} |
|
|
|
sub converted { |
|
if ($ENV{'environment.texengine'} eq 'tth') { |
|
return &tth_converted; |
|
} elsif ($ENV{'environment.texengine'} eq 'jsMath') { |
|
return &jsMath_converted; |
|
} elsif ($ENV{'environment.texengine'} eq 'mimetex') { |
|
return &mimetex_converted; |
|
} |
|
return &tth_converted; |
|
} |
|
|
# ====================================================================== Footer |
# ====================================================================== Footer |
|
|
sub footer { |
sub footer { |
Line 205 sub msgtexconverted {
|
Line 259 sub msgtexconverted {
|
$outmessage.=&smiley($_); $tex=1; |
$outmessage.=&smiley($_); $tex=1; |
} |
} |
} |
} |
|
$message=$outmessage; $outmessage=''; $tex=0; |
|
foreach (split(/(?:\<\;|\<)\/*algebra\s*(?:\>\;|\>)/i,$message)) { |
|
if ($tex) { |
|
if ($email) { |
|
$outmessage.='</pre><tt>'.&algebra($_,'web').'</tt><pre>'; $tex=0; |
|
} else { |
|
$outmessage.=&algebra($_,'web'); $tex=0; |
|
} |
|
} else { |
|
$outmessage.=$_; $tex=1; |
|
} |
|
} |
if (wantarray) { |
if (wantarray) { |
return ($outmessage,$errorstring); |
return ($outmessage,$errorstring); |
} else { |
} else { |
Line 228 sub algebra {
|
Line 294 sub algebra {
|
if ($style eq 'display') { |
if ($style eq 'display') { |
$latex='$$'.$latex.'$$x'; |
$latex='$$'.$latex.'$$x'; |
} else { |
} else { |
|
# style is 'inline' |
$latex='\\ensuremath{'.$latex.'}'; |
$latex='\\ensuremath{'.$latex.'}'; |
} |
} |
if ($target eq 'web' || $target eq 'analyze') { |
if ($target eq 'web' || $target eq 'analyze') { |
Line 279 sub postprocess_algebra {
|
Line 346 sub postprocess_algebra {
|
|
|
# |
# |
$string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs; |
$string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs; |
&Apache::lonnet::logthis($string); |
|
return $string; |
return $string; |
} |
} |
1; |
1; |