Annotation of loncom/xml/lontexconvert.pm, revision 1.108

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # TeX Conversion Module
                      3: #
1.108   ! raeburn     4: # $Id: lontexconvert.pm,v 1.107 2011/05/27 18:34:07 raeburn Exp $
1.4       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
                     29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
                     30: # binary executable programs or libraries distributed by the 
                     31: # Michigan State University (the "Licensee"), but any binaries so 
                     32: # distributed are hereby licensed only for use in the context
                     33: # of a program or computational system for which the Licensee is the 
                     34: # primary author or distributor, and which performs substantial 
                     35: # additional tasks beyond the translation of (La)TeX into HTML.
                     36: # The C source of the Code may not be distributed by the Licensee
                     37: # to any other parties under any circumstances.
                     38: #
1.1       harris41   39: 
                     40: package Apache::lontexconvert;
                     41: 
                     42: use strict;
1.33      albertel   43: use tth();
1.1       harris41   44: use vars qw($errorstring);
1.73      albertel   45: #use Apache::lonxml();
1.33      albertel   46: use Apache::lonlocal;
1.65      albertel   47: use Apache::lonnet;
1.75      www        48: use lib '/home/httpd/lib/perl/';
                     49: use LONCAPA;
1.94      raeburn    50: use URI::Escape;
                     51: use IO::Socket::INET;
1.1       harris41   52: 
                     53: # ====================================================================== Header
                     54: 
1.29      albertel   55: sub init_tth {
1.65      albertel   56:     my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'};
1.74      albertel   57:     if ($options =~ /\S/) {
                     58: 	$options = ' '.$options;
                     59:     } else {
                     60: 	undef($options);
                     61:     }
1.65      albertel   62:     if ($env{'browser.mathml'}) {
1.29      albertel   63: 	&tth::ttminit();
1.65      albertel   64: 	if ($env{'browser.unicode'}) {
1.74      albertel   65: 	    &tth::ttmoptions('-L -u1'.$options);
1.29      albertel   66: 	} else {
1.74      albertel   67: 	    &tth::ttmoptions('-L -u0'.$options);
1.29      albertel   68: 	}
                     69:     } else {
                     70: 	&tth::tthinit();
1.65      albertel   71: 	if ($env{'browser.unicode'}) {
1.74      albertel   72: 	    &tth::tthoptions('-L -u1'.$options);
1.29      albertel   73: 	} else {
1.74      albertel   74: 	    &tth::tthoptions('-L -u0'.$options);
1.29      albertel   75: 	}
                     76:     }
                     77: }
                     78: 
1.1       harris41   79: # ================================================================== Conversion
                     80: 
1.19      albertel   81: $Apache::lontexconvert::messedup=0;
1.36      albertel   82: 
1.91      jms        83: 
1.36      albertel   84: sub convert_real {
                     85:     my ($texstring)=@_;
                     86:     my ($xmlstring,$errorstring);
                     87:     local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; };
                     88:     local $SIG{ALRM}=sub { 
1.37      albertel   89: 	&Apache::lonnet::logthis("ALRM");
1.36      albertel   90: 	$xmlstring='['.&mt("TeX unconverted due to errors").']';
                     91: 	$Apache::lontexconvert::messedup=1;
                     92: 	die &mt("TeX unconverted due to errors");
                     93:     };
1.63      albertel   94:     &Apache::lonxml::start_alarm();
1.65      albertel   95:     if ($env{'browser.mathml'}) {
1.36      albertel   96: 	$xmlstring=&tth::ttm($$texstring);
                     97: 	$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
                     98: 	$xmlstring=~s/\<br\>/\<br\/\>/g;
                     99: 	$xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
                    100: 	$errorstring.=&tth::ttmerror();
                    101:     } else {
                    102: 	$xmlstring=&tth::tth($$texstring);
                    103: 	$errorstring.=&tth::ttherror();
                    104: 	$xmlstring=~s-</font(\s*)>-</font>-g;
                    105:     }
1.43      www       106:     $xmlstring=~s/^\s*\<br clear\=\"all\"/\<br/s;
1.36      albertel  107:     $xmlstring=~s/^\s*//;
                    108:     $xmlstring=~s/\s*$//;
1.85      foxr      109:     #
                    110:     # \rightleftharpoons is not converted by tth but maps
                    111:     # reasonably well to &#8660;.  If we get many more of these,
                    112:     # we're going to need to have a translation sub.
                    113:     #
1.87      foxr      114:     my $lrharpoon = pack("U", 0x21cc);
                    115:     $xmlstring=~s/\\rightleftharpoons/$lrharpoon/g;
1.85      foxr      116: 
1.63      albertel  117:     &Apache::lonxml::end_alarm();
1.36      albertel  118:     return ($xmlstring,$errorstring);
                    119: }
                    120: 
1.59      albertel  121: sub tth_converted {
1.31      albertel  122:     my $texstring=shift;
1.34      www       123:     my $xmlstring='['.&mt('UNDISPLAYABLE').']';
1.31      albertel  124:     if ($Apache::lontexconvert::messedup) {
1.35      albertel  125: 	return '['.&mt('TeX unconverted due to previous errors').']';
1.31      albertel  126:     }
1.59      albertel  127:     $$texstring ='\\documentstyle{article}'.$$texstring;
                    128: 
1.31      albertel  129:     eval(<<'ENDCONV');
1.36      albertel  130:     ($xmlstring,$errorstring)=&convert_real($texstring)
1.12      www       131: ENDCONV
1.32      albertel  132:     if ($@) {
1.35      albertel  133: 	$errorstring.=&mt("Evaluation Error: ").$@;
1.32      albertel  134: 	$Apache::lontexconvert::messedup=1;
                    135:     }
1.37      albertel  136:     if ($Apache::lontexconvert::messedup || &tth::tthmessedup() || 
                    137: 	$errorstring) {
1.31      albertel  138: 	&Apache::lonnet::logthis("Trying to kill myself");
                    139: 	$Apache::lontexconvert::messedup=1;
1.70      albertel  140: 	if (ref($Apache::lonxml::request)) {
                    141: 	    $Apache::lonxml::request->child_terminate();
                    142: 	} else {
                    143: 	    my $request;
                    144: 	    eval { $request=Apache->request; };
                    145: 	    if (!$request) {
                    146: 		eval { $request=Apache2::RequestUtil->request; };
                    147: 	    }
                    148: 	    if ($request) {
                    149: 		$request->child_terminate();
                    150: 	    } else {
                    151: 		&Apache::lonnet::logthis("Unable to find a request to do child_terminate on");
                    152: 	    }
                    153: 	}
1.31      albertel  154:     }
                    155:     return $xmlstring;
1.1       harris41  156: }
                    157: 
1.62      albertel  158: sub clean_out_math_mode {
                    159:     my ($texstring)=@_;
1.82      albertel  160:     $$texstring=~s/(?<!\\)\$//g;
1.62      albertel  161:     $$texstring=~s/\\[\)\(\]\[]//g;
                    162:     $$texstring=~s/\\ensuremath//g;
                    163:     return '';
                    164: }
                    165: 
                    166: sub displaystyle {
                    167:     my ($texstring)=@_;
1.106     bisitz    168:     #has a $$ or \[ or \displaystyle or eqnarray in it, guessinng it's display mode
1.62      albertel  169:     if ($$texstring=~/[^\\]\$\$/ ||
1.106     bisitz    170:         $$texstring=~/\\\[/ ||
                    171:         $$texstring=~/\\displaystyle/ ||
                    172:         $$texstring=~/eqnarray/
                    173:        ) { return 1; }
1.62      albertel  174:     return 0;
                    175: }
                    176: 
1.59      albertel  177: sub jsMath_converted {
                    178:     my $texstring=shift;
                    179:     my $tag='span';
1.62      albertel  180:     if (&displaystyle($texstring)) { $tag='div'; }
                    181:     &clean_out_math_mode($texstring);
1.67      albertel  182:     return &jsMath_header().
                    183: 	'<'.$tag.' class="math">'.$$texstring.'</'.$tag.'>';
                    184: }
                    185: 
                    186: {
1.76      albertel  187:     my @jsMath_sent_header;
1.67      albertel  188:     sub jsMath_reset {
1.76      albertel  189: 	undef(@jsMath_sent_header);
                    190:     }
                    191:     sub jsMath_push {
                    192: 	push(@jsMath_sent_header,0);
1.67      albertel  193:     }
                    194:     sub jsMath_header {
1.80      albertel  195: 	if (!@jsMath_sent_header) {
                    196: 	    &Apache::lonnet::logthis("mismatched calls of jsMath_header and jsMath_process");
                    197: 	    return '';
                    198: 	}
1.76      albertel  199: 	return '' if $jsMath_sent_header[-1];
                    200: 	$jsMath_sent_header[-1]=1;
1.67      albertel  201: 	return
                    202:             '<script type="text/javascript">
                    203:                      function NoFontMessage () {}
1.78      albertel  204:                      jsMath = {Parser: {prototype: {environments: {\'eqnarray*\' :[\'Array\',null,null,\'rcl\',[5/18,5/18],3,\'D\']}}}};
1.67      albertel  205:                    </script>'."\n".
1.71      albertel  206: 	    '<script type="text/javascript" src="/adm/jsMath/jsMath.js"></script>'."\n";
1.67      albertel  207:     }
                    208:     sub jsMath_process {
1.76      albertel  209: 	my $state = pop(@jsMath_sent_header);
                    210: 	return '' if !$state;
1.81      albertel  211: 	return "\n".
                    212: 	    '<script type="text/javascript">jsMath.Process()</script>'."\n";
1.67      albertel  213:     }
1.84      albertel  214:     sub jsMath_state {
                    215: 	my ($level) = @_;
                    216: 	return $jsMath_sent_header[$level];
                    217:     }
1.62      albertel  218: }
                    219: 
1.83      albertel  220: sub tex_engine {
                    221:     if (exists($env{'form.texengine'})) {
1.88      raeburn   222: 	if ($env{'form.texengine'} ne '') {
                    223:             return $env{'form.texengine'};
                    224:         }
1.83      albertel  225:     }    
                    226:     if ($env{'request.course.id'}
                    227: 	&& exists($env{'course.'.$env{'request.course.id'}.'.texengine'})) {
                    228: 	return $env{'course.'.$env{'request.course.id'}.'.texengine'};
                    229:     }
                    230:     if (exists($env{'environment.texengine'})) {
                    231: 	return $env{'environment.texengine'};
                    232:     }
                    233:     return 'tth';
                    234: }
                    235: 
1.72      albertel  236: sub init_math_support {
1.84      albertel  237:     my ($inherit_jsmath) = @_;
1.73      albertel  238:     &init_tth();
1.76      albertel  239:     &Apache::lontexconvert::jsMath_push();
1.84      albertel  240:     if (lc(&tex_engine()) eq 'jsmath' ||
                    241: 	($inherit_jsmath && &jsMath_state(-2))) {
1.72      albertel  242: 	return &Apache::lontexconvert::jsMath_header();
                    243:     }
                    244:     return;
                    245: }
                    246: 
1.92      hauer     247: sub mimetex_valign {
1.94      raeburn   248:     my ($esc_texstring)=@_;
                    249:     my $valign = 0;
                    250:     my $path = '/cgi-bin/mimetex.cgi?'.$esc_texstring;
                    251:     my $socket;
                    252:     &Apache::lonxml::start_alarm();
1.108   ! raeburn   253:     $socket = IO::Socket::INET->new(PeerAddr => 'localhost',
1.107     raeburn   254:                                     PeerPort => 'http(80)',
                    255:                                     Proto    => 'tcp');
1.94      raeburn   256:     if ($socket) {
1.96      raeburn   257:         my $headreq = "HEAD $path HTTP/1.0\r\n\r\n";
1.94      raeburn   258:         print $socket $headreq;
                    259:         while (<$socket>) {
                    260:             if (/Vertical\-Align\:\s*?([\-\d]+)/) {
                    261:                 $valign = $1;
                    262:             }
                    263:         }
1.105     raeburn   264:         $socket->close();
1.92      hauer     265:     }
1.94      raeburn   266:     &Apache::lonxml::end_alarm();
                    267:     return $valign;
1.92      hauer     268: }
                    269: 
1.62      albertel  270: sub mimetex_converted {
                    271:     my $texstring=shift;
1.97      www       272: 
                    273: # Alt-Argument for screen readers
                    274:     my $alt_string=$$texstring;
                    275:     $alt_string=~s/\"/\'\'/g;
                    276: 
                    277: # Is this displaystyle?
                    278: 
1.62      albertel  279:     my $displaystyle=&displaystyle($texstring);
                    280: 
1.97      www       281: # Remove math environment delimiters
                    282: 
1.62      albertel  283:     &clean_out_math_mode($texstring);
                    284: 
                    285:     if ($displaystyle) {
                    286: 	$$texstring='\\displaystyle \\Large '.$$texstring;
1.59      albertel  287:     }
1.94      raeburn   288:     my $esc_texstring = &uri_escape($$texstring);
                    289:     my $valign = &mimetex_valign($esc_texstring);
1.97      www       290:     my $result='<img src="/cgi-bin/mimetex.cgi?'.$esc_texstring.'" style="vertical-align:'.$valign.'px" alt="'.$alt_string.'" />';
1.62      albertel  291:     if ($displaystyle) {
1.106     bisitz    292: 	$result='<div style="text-align:center">'.$result.'</div>';
1.62      albertel  293:     }
                    294:     return $result;
1.59      albertel  295: }
                    296: 
                    297: sub converted {
1.67      albertel  298:     my ($string,$mode)=@_;
1.83      albertel  299:     if ($mode eq '') { $mode = &tex_engine(); }
1.68      albertel  300:     if ($mode =~ /tth/i) {
1.67      albertel  301: 	return &tth_converted($string);
1.68      albertel  302:     } elsif ($mode =~ /jsmath/i) {
1.67      albertel  303: 	return &jsMath_converted($string);
1.68      albertel  304:     } elsif ($mode =~ /mimetex/i) {
1.67      albertel  305: 	return &mimetex_converted($string);
1.98      www       306:     } elsif ($mode =~ /raw/i) {
                    307:         return $$string;
1.59      albertel  308:     }
1.67      albertel  309:     return &tth_converted($string);
1.59      albertel  310: }
                    311: 
1.6       www       312: # ------------------------------------------------------------ Message display
                    313: 
1.9       albertel  314: sub to_convert {
                    315:     my ($string) = @_;
1.102     faziophi  316:     &init_tth();
1.22      www       317:     $string=~s/\<br\s*\/?\>/ /gs;
1.30      albertel  318: #    $string=~s/\s/ /gs;
1.18      albertel  319:     $string=&HTML::Entities::decode($string);
1.9       albertel  320:     return &converted(\$string);
                    321: }
                    322: 
1.20      www       323: sub smiley {
1.31      albertel  324:     my $expression=shift;
1.99      faziophi  325:     my %smileys=(
                    326:     	 '\:\-*\)' => 'face-smile.png',
1.100     faziophi  327: 		 '8\-\)'  => 'face-cool.png',
                    328: 		 '8\-(I|\|)'   => 'face-glasses.png',
1.101     faziophi  329: 		 '\:\-(I|\|)'   => 'face-plain.png',
1.99      faziophi  330: 		 '\:\-(o|O|\(\))' => 'face-surprise.png',
1.101     faziophi  331: 		 ':\-\('  => 'face-sad.png',
                    332: 		 '\;\-\)' => 'face-wink.png',
                    333: 		 '\:\-(P|p)'  => 'face-raspberry.png',
1.100     faziophi  334: 		 '\:\-(\\\|\\/)' => 'face-uncertain.png',
1.101     faziophi  335: 		 '\:\-D'  => 'face-smile-big.png',
                    336: 		 '\:\-(C|\@)'  => 'face-angry.png',
1.99      faziophi  337: 		 '\:(\'|\`)\-*\(' => 'face-crying.png',
1.101     faziophi  338: 		 '\:\-(X|x|\#)' => 'face-quiet.png',
                    339: 		 '\:\-(s|S)' => 'face-uncertain.png',
                    340: 		 '\:\-\$' => 'face-embarrassed.png',
                    341: 		 '\:\-\*' => 'face-kiss.png',
1.99      faziophi  342: 		 '\+O\(' => 'face-sick.png',
                    343: 		 '(\&lt\;3|\(heart\))' => 'heart.png',
                    344: 		 '\(rose\)' => 'rose.png',
                    345: 		 '\(pizza\)' => 'food-pizza.png',
                    346: 		 '\(cake\)' => 'food-cake.png',
                    347: 		 '\(ninja\)' => 'face-ninja.png',
                    348: 		 '\(pirate\)' => 'face-pirate.png',
                    349: 		 '\((agree|yes)\)' => 'opinion-agree.png',
                    350: 		 '\((disagree|nay)\)' => 'opinion-disagree.png',
1.101     faziophi  351: 		 '(o|O)\-\)' => 'face-angel.png',
1.99      faziophi  352: 		 );
1.31      albertel  353:     my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
1.79      albertel  354:     foreach my $smiley (keys(%smileys)) {
1.99      faziophi  355: 	$expression=~s/$smiley/\<img src="$iconpath\/$smileys{$smiley}" \/\>/gs; 
1.31      albertel  356:     }
                    357:     return $expression;
1.20      www       358: }
                    359: 
1.6       www       360: sub msgtexconverted {
1.39      raeburn   361:     my ($message,$email) = @_;
1.17      albertel  362:     $errorstring='';
1.25      www       363:     my $outmessage='';
                    364:     my $tex=0;
1.79      albertel  365:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*m\s*(?:\&gt\;|\>)/i,$message)) {
1.25      www       366: 	if ($tex) {
1.30      albertel  367: 	    if ($email) {
1.79      albertel  368: 		$outmessage.='</pre><tt>'.&to_convert($fragment).'</tt><pre>';
                    369: 		$tex=0;
1.30      albertel  370: 	    } else {
1.79      albertel  371: 		$outmessage.=&to_convert($fragment);
                    372: 		$tex=0;
1.30      albertel  373: 	    }
1.25      www       374: 	} else {
1.79      albertel  375:             $outmessage.=&smiley($fragment);
                    376: 	    $tex=1;
1.25      www       377: 	}
                    378:     }
1.64      albertel  379:     $message=$outmessage; $outmessage=''; $tex=0;
1.79      albertel  380:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*algebra\s*(?:\&gt\;|\>)/i,
                    381: 				$message)) {
1.64      albertel  382: 	if ($tex) {
1.103     faziophi  383:         my $algebra = &algebra($fragment, 'web', undef, undef, undef, undef, 'tth');
1.64      albertel  384: 	    if ($email) {
1.103     faziophi  385: 		$outmessage.='</pre><tt>'.$algebra.'</tt><pre>';
1.79      albertel  386: 		$tex=0;
1.64      albertel  387: 	    } else {
1.103     faziophi  388: 		$outmessage.=$algebra;
1.79      albertel  389: 		$tex=0;
1.64      albertel  390: 	    }
                    391: 	} else {
1.103     faziophi  392:         $outmessage.=$fragment;
1.79      albertel  393: 	    $tex=1;
1.64      albertel  394: 	}
                    395:     }
1.24      albertel  396:     if (wantarray) {
1.25      www       397: 	return ($outmessage,$errorstring);
1.24      albertel  398:     } else {
1.25      www       399: 	return $outmessage.$errorstring;
1.24      albertel  400:     }
1.1       harris41  401: }
                    402: 
1.44      albertel  403: sub algebra {
1.49      albertel  404:     use AlgParser;
1.103     faziophi  405:     my ($string,$target,$style,$parstack,$safeeval,$tth)=@_;
1.44      albertel  406:     my $parser = new AlgParserWithImplicitExpand;
1.103     faziophi  407:     if ($tth eq 'tth') {&init_tth();}
1.46      albertel  408:     $string=&prepare_algebra($string);
1.44      albertel  409:     my $ret = $parser->parse($string);
                    410:     my $result='['.&mt('Algebra unconverted due to previous errors').']';
                    411:     if ( ref($ret) ) {
1.50      albertel  412: 	#$parser->tostring();
1.44      albertel  413: 	$parser->normalize();
                    414: 	my $latex=$parser->tolatex();
1.49      albertel  415: 	$latex=&postprocess_algebra($latex);
1.58      albertel  416: 	if ($style eq 'display') {
                    417: 	    $latex='$$'.$latex.'$$x';
                    418: 	} else {
1.61      albertel  419: 	    # style is 'inline'
1.58      albertel  420: 	    $latex='\\ensuremath{'.$latex.'}';
                    421: 	}
1.44      albertel  422: 	if ($target eq 'web' || $target eq 'analyze') {
1.89      droeschl  423:             my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
                    424:             $result = &converted(\$latex,$display);
                    425: #	    $result = &converted(\$latex);
1.44      albertel  426: 	} else {
                    427: 	    $result = $latex;
                    428: 	}
                    429:     } else {
                    430: 	&Apache::lonxml::error($parser->{'htmlerror'});
                    431:     }
                    432: }
                    433: 
1.46      albertel  434: sub prepare_algebra {
                    435:     my ($string)=@_;
                    436: 
1.50      albertel  437:     # makes the decision about what is a minus sign easier supposedly
1.57      albertel  438:     $string =~ s/(\<\>|\<\=|\>\=[\=\>\<] *)-/$1 zeroplace -/g;
1.48      albertel  439: 
1.46      albertel  440:     return $string;
                    441: }
                    442: 
                    443: sub postprocess_algebra {
                    444:     my ($string)=@_;
1.48      albertel  445:     
1.50      albertel  446:     # moodle had these and I don't know why, ignoring them for now
1.51      albertel  447:     # $string =~s/\\fun/ /g;
1.47      albertel  448: 
1.51      albertel  449:     # sqrt(3,4) means the 4 root of 3
1.52      albertel  450:     $string =~s/\\sqrt{([^,]+),([^\}]+)}/\\sqrt[$2]{$1}/gs;
                    451: 
1.53      albertel  452:     # log(3,4) means the log base 4 of 3
                    453:     $string =~s/\\log\\left\((.+?),(.+?)\\right\)/\\log_{$2}\\left($1\\right)/gs;
                    454: 
1.54      albertel  455:     # log(3,4) means the log base 4 of 3
                    456:     $string =~s/\\((?:sin|cos|tan|sec|csc|cot)(?:h)?)\\left\((.+?),(.+?)\\right\)/\\$1^{$3}\\left($2\\right)/gs;
                    457: 
1.55      albertel  458:     # int(3,a,b) integral from a to b of 3
                    459:     $string =~s/\\int\\left\((.+?),(.+?),(.+?)\\right\)/\\int_{$2}^{$3}\\left($1\\right)/gs;
                    460: 
                    461:     # int( ... dx) -> ...
                    462:     $string =~s/\\int\\left\((.+?)d[a-z]\\right\)/$1/gs;
1.51      albertel  463: 
1.56      albertel  464:     # 
                    465:     $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
1.46      albertel  466:     return $string;
                    467: }
1.1       harris41  468: 1;
                    469: __END__
                    470: 
                    471: 
1.91      jms       472: =pod
                    473: 
                    474: =head1 NAME
                    475: 
                    476: Apache::lontexconvert;
                    477: 
                    478: =head1 SYNOPSIS
                    479: 
                    480: Access to tth/ttm
                    481: 
                    482: This is part of the LearningOnline Network with CAPA project
                    483: described at http://www.lon-capa.org.
                    484: 
                    485: 
                    486: =head1 SUBROUTINES
                    487: 
                    488: =over
                    489: 
                    490: =item init_tth()
                    491: 
                    492: Header
                    493: 
                    494: =item convert_real()
                    495: 
                    496:  we need this routine because &converted can get called from inside
                    497:  of the safespace (through &xmlparse('<m>stuff</m>') which doesn't
                    498:  allow the opcode for alarm, so we need to compile this before we get
                    499:  into the safe space since opcode checks only occur at compile time
                    500: 
                    501: =item tth_converted()
                    502: 
                    503: 
                    504: =item clean_out_math_mode()
                    505: 
                    506: 
                    507: =item displaystyle()
                    508: 
                    509: 
                    510: =item jsMath_converted()
                    511: 
                    512: 
                    513: =item tex_engine()
                    514: 
                    515: 
                    516: =item init_math_support()
                    517: 
1.105     raeburn   518: =item mimetex_valign()
                    519: 
                    520:  Makes a HEAD call to /cgi-bin/mimetex.cgi via IO:: to retrieve the 
                    521:  vertical alignment, before the subsequent call to mimetex_converted()
                    522:  which generates the <img> tag and the corresponding image.
                    523: 
                    524:  Input: 1.  $esc_texstring (escaped TeX to be rendered by mimetex).
                    525:  Output: 1. $valign - number of pixels: positive or negative integer 
                    526:             which will be included in <img> tag for mimetex image to
                    527:             support vertical alignment of image within a line of text.
                    528: 
                    529:  If a server is running SSL, and Apache rewrite rules are in place 
                    530:  to rewrite requests for http to https, modification will most likely 
                    531:  be needed for pass through for HEAD requests for /cgi-bin/mimetex.cgi. 
                    532: 
                    533:  Example rewrite rules which rewrite all http traffic to https, 
                    534:  except HEAD requests for /cgi-bin/mimetex.cgi are:
                    535: 
                    536:  <IfModule mod_rewrite.c>
                    537:      RewriteEngine On
                    538:      RewriteLogLevel 0
                    539: 
                    540:      RewriteCond %{HTTPS} off
                    541:      RewriteCond %{HTTP:Host} (.*)
                    542:      RewriteCond %{REQUEST_METHOD} !HEAD 
                    543:      RewriteRule ^/(.*) https://%1/$1 [R=301,L]
                    544: 
                    545:      RewriteCond %{HTTPS} off
                    546:      RewriteCond %{HTTP:Host} (.*)
                    547:      RewriteCond %{REQUEST_METHOD} HEAD
                    548:      RewriteCond %{REQUEST_URI} !^/cgi-bin/mimetex.cgi
                    549:      RewriteRule ^/(.*) https://%1/$1 [R=301,L]
                    550:  </IfModule>
1.91      jms       551: 
                    552: =item mimetex_converted()
                    553: 
                    554: 
                    555: =item converted()
                    556: 
                    557: 
                    558: =item to_convert()
                    559: 
                    560: message display
                    561: 
                    562: =item smiley()
                    563: 
                    564: ???
                    565: 
                    566: =item msgtexconverted()
                    567: 
                    568: =item algebra()
                    569: 
                    570: =item prepare_algebra()
                    571: 
                    572: =item postprocess_algebra()
1.1       harris41  573: 
1.91      jms       574: =back
1.1       harris41  575: 
1.91      jms       576: =cut
1.1       harris41  577: 
                    578: 
                    579: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>