File:  [LON-CAPA] / loncom / xml / lontexconvert.pm
Revision 1.112.2.4: download - view: text, annotated - select for diffs
Wed Jun 18 06:48:47 2014 UTC (9 years, 10 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_1, version_2_11_0
- For 2.11
  - Backport 1.114, 1.115, 1.116

    1: # The LearningOnline Network with CAPA
    2: # TeX Conversion Module
    3: #
    4: # $Id: lontexconvert.pm,v 1.112.2.4 2014/06/18 06:48:47 raeburn Exp $
    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: #
   39: 
   40: package Apache::lontexconvert;
   41: 
   42: use strict;
   43: use tth();
   44: use vars qw($errorstring);
   45: #use Apache::lonxml();
   46: use Apache::lonlocal;
   47: use Apache::lonnet;
   48: use lib '/home/httpd/lib/perl/';
   49: use LONCAPA;
   50: use URI::Escape;
   51: use IO::Socket::INET;
   52: 
   53: 
   54: #
   55: # Table of substitutions to unicode characters.
   56: #
   57: 
   58: my %unicode_harpoons = (
   59:                         '\rightleftharpoons'  => 0x21cc,
   60:                       );
   61: 
   62: my %unicode_translations = (
   63: 
   64: # Brackets - unicode for browsers/OS which support it.
   65: 
   66:     ''             => 0x23a1,
   67:     ''             => 0x23a2,
   68:     ''             => 0x23a3,
   69:     ''             => 0x23a4,
   70:     ''             => 0x23a5,
   71:     ''             => 0x23a6,
   72: 
   73: #  Parens - unicode for browsers/OS which support it
   74: 
   75:     ''              => 0x239b,
   76:     ''              => 0x239c,
   77:     ''              => 0x239d,
   78:     ''              => 0x239e,
   79:     ''              => 0x239f,
   80:     ''              => 0x23a0,
   81: 
   82: );
   83: 
   84: my %ascii_8bit_translations = (
   85: 
   86: # Brackets - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
   87: 
   88:     ''              => 0x5b,
   89:     ''              => 0x5b,    # '['
   90:     ''              => 0x5b,
   91:     ''              => 0x5d,    # ']'
   92:     ''              => 0x5d,
   93:     ''              => 0x5d,
   94: 
   95: # Parens - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
   96: 
   97:     ''              => 0x28,
   98:     ''              => 0x28,      # '('
   99:     ''              => 0x28,
  100:     ''              => 0x29,
  101:     ''              => 0x29,      # '('
  102:     ''              => 0x29,
  103: 
  104: );
  105: 
  106: ##
  107: # Utility to convert elements of a string to unicode:
  108: #
  109: # @param input - Input string
  110: # @param pattern - Pattern to convert
  111: # @param unicode - Unicode to substitute for pattern.
  112: #
  113: # @return string - resulting string.
  114: # 
  115: sub unicode_subst {
  116:     my ($input, $pattern, $unicode) = @_;
  117:     
  118:     my $char = pack('U', $unicode);
  119: 
  120:     $input =~ s/$pattern/$char/g;
  121: 
  122:     return $input;
  123: }
  124: 
  125: # ====================================================================== Header
  126: 
  127: sub init_tth {
  128:     my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'};
  129:     if ($options =~ /\S/) {
  130: 	$options = ' '.$options;
  131:     } else {
  132: 	undef($options);
  133:     }
  134:     if ($env{'browser.mathml'}) {
  135: 	&tth::ttminit();
  136: 	if ($env{'browser.unicode'}) {
  137: 	    &tth::ttmoptions('-L -u1'.$options);
  138: 	} else {
  139: 	    &tth::ttmoptions('-L -u0'.$options);
  140: 	}
  141:     } else {
  142: 	&tth::tthinit();
  143: 	if ($env{'browser.unicode'}) {
  144: 	    &tth::tthoptions('-L -u1'.$options);
  145: 	} else {
  146: 	    &tth::tthoptions('-L -u0'.$options);
  147: 	}
  148:     }
  149: }
  150: 
  151: # ================================================================== Conversion
  152: 
  153: $Apache::lontexconvert::messedup=0;
  154: 
  155: 
  156: sub convert_real {
  157:     my ($texstring)=@_;
  158:     my ($xmlstring,$errorstring);
  159:     local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; };
  160:     local $SIG{ALRM}=sub { 
  161: 	&Apache::lonnet::logthis("ALRM");
  162: 	$xmlstring='['.&mt("TeX unconverted due to errors").']';
  163: 	$Apache::lontexconvert::messedup=1;
  164: 	die &mt("TeX unconverted due to errors");
  165:     };
  166:     &Apache::lonxml::start_alarm();
  167:     if ($env{'browser.mathml'}) {
  168: 	$xmlstring=&tth::ttm($$texstring);
  169: 	$xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
  170: 	$xmlstring=~s/\<br\>/\<br\/\>/g;
  171: 	$xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
  172: 	$errorstring.=&tth::ttmerror();
  173:     } else {
  174: 	$xmlstring=&tth::tth($$texstring);
  175: 	$errorstring.=&tth::ttherror();
  176: 	$xmlstring=~s-</font(\s*)>-</font>-g;
  177:     }
  178:     $xmlstring=~s/^\s*\<br clear\=\"all\"/\<br/s;
  179:     $xmlstring=~s/^\s*//;
  180:     $xmlstring=~s/\s*$//;
  181:     &Apache::lonxml::end_alarm();
  182: 
  183:     #
  184:     # Several strings produced by tth require
  185:     # transliteration -> unicode equivalents to render reliably
  186:     # in browsers. %unicode_translations and %unicode_harpoons are tables of
  187:     # string->substitution which we now apply. (%ascii_8bit_translations used
  188:     # instead for Windows XP and mobile devices.
  189: 
  190:     my $use_ascii;
  191:     if ($env{'browser.os'} eq 'win') {
  192:         if (($env{'browser.osversion'}) && ($env{'browser.osversion'} < 6.0)) {
  193:             $use_ascii = 1;
  194:         }
  195:     }
  196:     if ($env{'browser.mobile'}) {
  197:         $use_ascii = 1;
  198:     }
  199: 
  200:     foreach my $pattern (keys(%unicode_translations)) {
  201: 	my $unicode = $unicode_translations{$pattern};
  202: 	if ($use_ascii) {
  203: 	    $unicode = $ascii_8bit_translations{$pattern};
  204: 	}
  205: 	$xmlstring = &unicode_subst($xmlstring, $pattern, $unicode);
  206:     }
  207: 
  208:     foreach my $pattern (keys(%unicode_harpoons)) {
  209:         $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode_harpoons{$pattern});
  210:     }
  211: 
  212:     return ($xmlstring,$errorstring);
  213: }
  214: 
  215: sub tth_converted {
  216:     my $texstring=shift;
  217:     my $xmlstring='['.&mt('UNDISPLAYABLE').']';
  218:     if ($Apache::lontexconvert::messedup) {
  219: 	return '['.&mt('TeX unconverted due to previous errors').']';
  220:     }
  221:     $$texstring ='\\documentstyle{article}'.$$texstring;
  222: 
  223:     eval(<<'ENDCONV');
  224:     ($xmlstring,$errorstring)=&convert_real($texstring)
  225: ENDCONV
  226:     if ($@) {
  227: 	$errorstring.=&mt("Evaluation Error: ").$@;
  228: 	$Apache::lontexconvert::messedup=1;
  229:     }
  230:     if ($Apache::lontexconvert::messedup || &tth::tthmessedup() || 
  231: 	$errorstring) {
  232: 	&Apache::lonnet::logthis("Trying to kill myself");
  233: 	$Apache::lontexconvert::messedup=1;
  234: 	if (ref($Apache::lonxml::request)) {
  235: 	    $Apache::lonxml::request->child_terminate();
  236: 	} else {
  237: 	    my $request;
  238: 	    eval { $request=Apache->request; };
  239: 	    if (!$request) {
  240: 		eval { $request=Apache2::RequestUtil->request; };
  241: 	    }
  242: 	    if ($request) {
  243: 		$request->child_terminate();
  244: 	    } else {
  245: 		&Apache::lonnet::logthis("Unable to find a request to do child_terminate on");
  246: 	    }
  247: 	}
  248:     }
  249:     return $xmlstring;
  250: }
  251: 
  252: sub clean_out_math_mode {
  253:     my ($texstring)=@_;
  254:     $$texstring=~s/(?<!\\)\$//g;
  255:     $$texstring=~s/\\[\)\(\]\[]//g;
  256:     $$texstring=~s/\\ensuremath//g;
  257:     return '';
  258: }
  259: 
  260: sub displaystyle {
  261:     my ($texstring)=@_;
  262:     #has a $$ or \[ or \displaystyle or eqnarray in it, guessinng it's display mode
  263:     if ($$texstring=~/[^\\]\$\$/ ||
  264:         $$texstring=~/\\\[/ ||
  265:         $$texstring=~/\\displaystyle/ ||
  266:         $$texstring=~/eqnarray/
  267:        ) { return 1; }
  268:     return 0;
  269: }
  270: 
  271: sub MathJax_converted {
  272:     my $texstring=shift;
  273:     my $tag='math/tex;';
  274:     if (&displaystyle($texstring)) { $tag='math/tex; mode=display'; }
  275:     &clean_out_math_mode($texstring);
  276:     return &MathJax_header().
  277:       '<script type="'.$tag.'">'.$$texstring.'</script>';
  278: }
  279: 
  280: {
  281:     #Relies heavily on the previous jsMath installation
  282:     my @MathJax_sent_header;
  283:     sub MathJax_reset {
  284:         undef(@MathJax_sent_header);
  285:     }
  286:     sub MathJax_push {
  287:         push(@MathJax_sent_header,0);
  288:     }
  289:     sub MathJax_header {
  290:         if (!@MathJax_sent_header) {
  291:             &Apache::lonnet::logthis("mismatched calls of MathJax_header and MathJax_process");
  292:             return '';
  293:         }
  294:         return '' if $MathJax_sent_header[-1];
  295:         $MathJax_sent_header[-1]=1;
  296:         return
  297:           '<script type="text/javascript" src="/adm/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'."\n";
  298:     }
  299: }
  300: 
  301: 
  302: sub jsMath_converted {
  303:     my $texstring=shift;
  304:     my $tag='span';
  305:     if (&displaystyle($texstring)) { $tag='div'; }
  306:     &clean_out_math_mode($texstring);
  307:     return &jsMath_header().
  308: 	'<'.$tag.' class="math">'.$$texstring.'</'.$tag.'>';
  309: }
  310: 
  311: {
  312:     my @jsMath_sent_header;
  313:     sub jsMath_reset {
  314: 	undef(@jsMath_sent_header);
  315:     }
  316:     sub jsMath_push {
  317: 	push(@jsMath_sent_header,0);
  318:     }
  319:     sub jsMath_header {
  320: 	if (!@jsMath_sent_header) {
  321: 	    &Apache::lonnet::logthis("mismatched calls of jsMath_header and jsMath_process");
  322: 	    return '';
  323: 	}
  324: 	return '' if $jsMath_sent_header[-1];
  325: 	$jsMath_sent_header[-1]=1;
  326: 	return
  327:             '<script type="text/javascript">
  328:                      function NoFontMessage () {}
  329:                      jsMath = {Parser: {prototype: {environments: {\'eqnarray*\' :[\'Array\',null,null,\'rcl\',[5/18,5/18],3,\'D\']}}}};
  330:                    </script>'."\n".
  331: 	    '<script type="text/javascript" src="/adm/jsMath/jsMath.js"></script>'."\n";
  332:     }
  333:     sub jsMath_process {
  334: 	my $state = pop(@jsMath_sent_header);
  335: 	return '' if !$state;
  336: 	return "\n".
  337: 	    '<script type="text/javascript">jsMath.Process()</script>'."\n";
  338:     }
  339:     sub jsMath_state {
  340: 	my ($level) = @_;
  341: 	return $jsMath_sent_header[$level];
  342:     }
  343: }
  344: 
  345: sub tex_engine {
  346:     if (exists($env{'form.texengine'})) {
  347: 	if ($env{'form.texengine'} ne '') {
  348:             return $env{'form.texengine'};
  349:         }
  350:     }    
  351:     if ($env{'request.course.id'}
  352: 	&& exists($env{'course.'.$env{'request.course.id'}.'.texengine'})) {
  353: 	return $env{'course.'.$env{'request.course.id'}.'.texengine'};
  354:     }
  355:     if (exists($env{'environment.texengine'})) {
  356: 	return $env{'environment.texengine'};
  357:     }
  358:     return 'tth';
  359: }
  360: 
  361: sub init_math_support {
  362:     my ($inherit_jsmath) = @_;
  363:     &init_tth();
  364:     &Apache::lontexconvert::jsMath_push();
  365:     if (lc(&tex_engine()) eq 'jsmath' ||
  366: 	($inherit_jsmath && &jsMath_state(-2))) {
  367: 	return &Apache::lontexconvert::jsMath_header();
  368:     }
  369:     &Apache::lontexconvert::MathJax_push();
  370:     if (lc(&tex_engine()) eq 'mathjax') { # ||
  371:         #($inherit_jsmath && &jsMath_state(-2))) {
  372:         return &Apache::lontexconvert::MathJax_header();
  373:     }
  374:     return;
  375: }
  376: 
  377: sub mimetex_valign {
  378:     my ($esc_texstring)=@_;
  379:     my $valign = 0;
  380:     my $path = '/cgi-bin/mimetex.cgi?'.$esc_texstring;
  381:     my $socket;
  382:     &Apache::lonxml::start_alarm();
  383:     $socket = IO::Socket::INET->new(PeerAddr => 'localhost',
  384:                                     PeerPort => 'http(80)',
  385:                                     Proto    => 'tcp');
  386:     if ($socket) {
  387:         my $headreq = "HEAD $path HTTP/1.0\r\n\r\n";
  388:         print $socket $headreq;
  389:         while (<$socket>) {
  390:             if (/Vertical\-Align\:\s*?([\-\d]+)/) {
  391:                 $valign = $1;
  392:             }
  393:         }
  394:         $socket->close();
  395:     }
  396:     &Apache::lonxml::end_alarm();
  397:     return $valign;
  398: }
  399: 
  400: sub mimetex_converted {
  401:     my $texstring=shift;
  402: 
  403: # Alt-Argument for screen readers
  404:     my $alt_string=$$texstring;
  405:     $alt_string=~s/\"/\'\'/g;
  406: 
  407: # Is this displaystyle?
  408: 
  409:     my $displaystyle=&displaystyle($texstring);
  410: 
  411: # Remove math environment delimiters
  412: 
  413:     &clean_out_math_mode($texstring);
  414: 
  415:     if ($displaystyle) {
  416: 	$$texstring='\\displaystyle \\Large '.$$texstring;
  417:     }
  418:     my $esc_texstring = &uri_escape($$texstring);
  419:     my $valign = &mimetex_valign($esc_texstring);
  420:     my $result='<img src="/cgi-bin/mimetex.cgi?'.$esc_texstring.'" style="vertical-align:'.$valign.'px" alt="'.$alt_string.'" />';
  421:     if ($displaystyle) {
  422: 	$result='<div style="text-align:center">'.$result.'</div>';
  423:     }
  424:     return $result;
  425: }
  426: 
  427: sub converted {
  428:     my ($string,$mode)=@_;
  429:     if ($mode eq '') { $mode = &tex_engine(); }
  430:     if ($mode =~ /tth/i) {
  431: 	return &tth_converted($string);
  432:     } elsif ($mode =~ /jsmath/i) {
  433: 	return &jsMath_converted($string);
  434:     } elsif ($mode =~ /mathjax/i) {
  435:         return &MathJax_converted($string);
  436:     } elsif ($mode =~ /mimetex/i) {
  437: 	return &mimetex_converted($string);
  438:     } elsif ($mode =~ /raw/i) {
  439:         return $$string;
  440:     }
  441:     return &tth_converted($string);
  442: }
  443: 
  444: # ------------------------------------------------------------ Message display
  445: 
  446: sub to_convert {
  447:     my ($string) = @_;
  448:     &init_tth();
  449:     $string=~s/\<br\s*\/?\>/ /gs;
  450: #    $string=~s/\s/ /gs;
  451:     $string=&HTML::Entities::decode($string);
  452:     return &converted(\$string);
  453: }
  454: 
  455: sub smiley {
  456:     my $expression=shift;
  457:     my %smileys=(
  458:     	 '\:\-*\)' => 'face-smile.png',
  459: 		 '8\-\)'  => 'face-cool.png',
  460: 		 '8\-(I|\|)'   => 'face-glasses.png',
  461: 		 '\:\-(I|\|)'   => 'face-plain.png',
  462: 		 '\:\-(o|O|\(\))' => 'face-surprise.png',
  463: 		 ':\-\('  => 'face-sad.png',
  464: 		 '\;\-\)' => 'face-wink.png',
  465: 		 '\:\-(P|p)'  => 'face-raspberry.png',
  466: 		 '\:\-(\\\|\\/)' => 'face-uncertain.png',
  467: 		 '\:\-D'  => 'face-smile-big.png',
  468: 		 '\:\-(C|\@)'  => 'face-angry.png',
  469: 		 '\:(\'|\`)\-*\(' => 'face-crying.png',
  470: 		 '\:\-(X|x|\#)' => 'face-quiet.png',
  471: 		 '\:\-(s|S)' => 'face-uncertain.png',
  472: 		 '\:\-\$' => 'face-embarrassed.png',
  473: 		 '\:\-\*' => 'face-kiss.png',
  474: 		 '\+O\(' => 'face-sick.png',
  475: 		 '(\&lt\;3|\(heart\))' => 'heart.png',
  476: 		 '\(rose\)' => 'rose.png',
  477: 		 '\(pizza\)' => 'food-pizza.png',
  478: 		 '\(cake\)' => 'food-cake.png',
  479: 		 '\(ninja\)' => 'face-ninja.png',
  480: 		 '\(pirate\)' => 'face-pirate.png',
  481: 		 '\((agree|yes)\)' => 'opinion-agree.png',
  482: 		 '\((disagree|nay)\)' => 'opinion-disagree.png',
  483: 		 '(o|O)\-\)' => 'face-angel.png',
  484: 		 );
  485:     my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
  486:     foreach my $smiley (keys(%smileys)) {
  487: 	$expression=~s/$smiley/\<img src="$iconpath\/$smileys{$smiley}" \/\>/gs; 
  488:     }
  489:     return $expression;
  490: }
  491: 
  492: sub msgtexconverted {
  493:     my ($message,$email) = @_;
  494:     $errorstring='';
  495:     my $outmessage='';
  496:     my $tex=0;
  497:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*m\s*(?:\&gt\;|\>)/i,$message)) {
  498: 	if ($tex) {
  499: 	    if ($email) {
  500: 		$outmessage.='</pre><tt>'.&to_convert($fragment).'</tt><pre>';
  501: 		$tex=0;
  502: 	    } else {
  503: 		$outmessage.=&to_convert($fragment);
  504: 		$tex=0;
  505: 	    }
  506: 	} else {
  507:             $outmessage.=&smiley($fragment);
  508: 	    $tex=1;
  509: 	}
  510:     }
  511:     $message=$outmessage; $outmessage=''; $tex=0;
  512:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*algebra\s*(?:\&gt\;|\>)/i,
  513: 				$message)) {
  514: 	if ($tex) {
  515:         my $algebra = &algebra($fragment, 'web', undef, undef, undef, 'tth');
  516: 	    if ($email) {
  517: 		$outmessage.='</pre><tt>'.$algebra.'</tt><pre>';
  518: 		$tex=0;
  519: 	    } else {
  520: 		$outmessage.=$algebra;
  521: 		$tex=0;
  522: 	    }
  523: 	} else {
  524:         $outmessage.=$fragment;
  525: 	    $tex=1;
  526: 	}
  527:     }
  528:     if (wantarray) {
  529: 	return ($outmessage,$errorstring);
  530:     } else {
  531: 	return $outmessage.$errorstring;
  532:     }
  533: }
  534: 
  535: sub algebra {
  536:     use AlgParser;
  537:     my ($string,$target,$style,$parstack,$safeeval,$tth)=@_;
  538:     my $parser = new AlgParserWithImplicitExpand;
  539:     if ($tth eq 'tth') {&init_tth();}
  540:     $string=&prepare_algebra($string);
  541:     my $ret = $parser->parse($string);
  542:     my $result='['.&mt('Algebra unconverted due to previous errors').']';
  543:     if ( ref($ret) ) {
  544: 	#$parser->tostring();
  545: 	$parser->normalize();
  546: 	my $latex=$parser->tolatex();
  547: 	$latex=&postprocess_algebra($latex);
  548: 	if ($style eq 'display') {
  549: 	    $latex='$$'.$latex.'$$x';
  550: 	} else {
  551: 	    # style is 'inline'
  552: 	    $latex='\\ensuremath{'.$latex.'}';
  553: 	}
  554: 	if ($target eq 'web' || $target eq 'analyze') {
  555:             my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
  556:             $result = &converted(\$latex,$display);
  557: #	    $result = &converted(\$latex);
  558: 	} else {
  559: 	    $result = $latex;
  560: 	}
  561:     } else {
  562: 	&Apache::lonxml::error($parser->{'htmlerror'});
  563:     }
  564: }
  565: 
  566: sub prepare_algebra {
  567:     my ($string)=@_;
  568: 
  569:     # makes the decision about what is a minus sign easier supposedly
  570:     $string =~ s/(\<\>|\<\=|\>\=[\=\>\<] *)-/$1 zeroplace -/g;
  571: 
  572:     return $string;
  573: }
  574: 
  575: sub postprocess_algebra {
  576:     my ($string)=@_;
  577:     
  578:     # moodle had these and I don't know why, ignoring them for now
  579:     # $string =~s/\\fun/ /g;
  580: 
  581:     # sqrt(3,4) means the 4 root of 3
  582:     $string =~s/\\sqrt{([^,]+),([^\}]+)}/\\sqrt[$2]{$1}/gs;
  583: 
  584:     # log(3,4) means the log base 4 of 3
  585:     $string =~s/\\log\\left\((.+?),(.+?)\\right\)/\\log_{$2}\\left($1\\right)/gs;
  586: 
  587:     # log(3,4) means the log base 4 of 3
  588:     $string =~s/\\((?:sin|cos|tan|sec|csc|cot)(?:h)?)\\left\((.+?),(.+?)\\right\)/\\$1^{$3}\\left($2\\right)/gs;
  589: 
  590:     # int(3,a,b) integral from a to b of 3
  591:     $string =~s/\\int\\left\((.+?),(.+?),(.+?)\\right\)/\\int_{$2}^{$3}\\left($1\\right)/gs;
  592: 
  593:     # int( ... dx) -> ...
  594:     $string =~s/\\int\\left\((.+?)d[a-z]\\right\)/$1/gs;
  595: 
  596:     # 
  597:     $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
  598:     return $string;
  599: }
  600: 
  601: 
  602: 1;
  603: __END__
  604: 
  605: 
  606: =pod
  607: 
  608: =head1 NAME
  609: 
  610: Apache::lontexconvert;
  611: 
  612: =head1 SYNOPSIS
  613: 
  614: Access to tth/ttm
  615: 
  616: This is part of the LearningOnline Network with CAPA project
  617: described at http://www.lon-capa.org.
  618: 
  619: 
  620: =head1 SUBROUTINES
  621: 
  622: =over
  623: 
  624: =item init_tth()
  625: 
  626: Header
  627: 
  628: =item convert_real()
  629: 
  630:  we need this routine because &converted can get called from inside
  631:  of the safespace (through &xmlparse('<m>stuff</m>') which doesn't
  632:  allow the opcode for alarm, so we need to compile this before we get
  633:  into the safe space since opcode checks only occur at compile time
  634: 
  635: =item tth_converted()
  636: 
  637: 
  638: =item clean_out_math_mode()
  639: 
  640: 
  641: =item displaystyle()
  642: 
  643: 
  644: =item jsMath_converted()
  645: 
  646: =item MathJax_converted()
  647:         - Mimics the jsMath functionality
  648: 
  649: =item tex_engine()
  650: 
  651: 
  652: =item init_math_support()
  653: 
  654: =item mimetex_valign()
  655: 
  656:  Makes a HEAD call to /cgi-bin/mimetex.cgi via IO:: to retrieve the 
  657:  vertical alignment, before the subsequent call to mimetex_converted()
  658:  which generates the <img> tag and the corresponding image.
  659: 
  660:  Input: 1.  $esc_texstring (escaped TeX to be rendered by mimetex).
  661:  Output: 1. $valign - number of pixels: positive or negative integer 
  662:             which will be included in <img> tag for mimetex image to
  663:             support vertical alignment of image within a line of text.
  664: 
  665:  If a server is running SSL, and Apache rewrite rules are in place 
  666:  to rewrite requests for http to https, modification will most likely 
  667:  be needed for pass through for HEAD requests for /cgi-bin/mimetex.cgi. 
  668: 
  669:  Example rewrite rules which rewrite all http traffic to https, 
  670:  except HEAD requests for /cgi-bin/mimetex.cgi are:
  671: 
  672:  <IfModule mod_rewrite.c>
  673:      RewriteEngine On
  674:      RewriteLogLevel 0
  675: 
  676:      RewriteCond %{HTTPS} off
  677:      RewriteCond %{HTTP:Host} (.*)
  678:      RewriteCond %{REQUEST_METHOD} !HEAD 
  679:      RewriteRule ^/(.*) https://%1/$1 [R=301,L]
  680: 
  681:      RewriteCond %{HTTPS} off
  682:      RewriteCond %{HTTP:Host} (.*)
  683:      RewriteCond %{REQUEST_METHOD} HEAD
  684:      RewriteCond %{REQUEST_URI} !^/cgi-bin/mimetex.cgi
  685:      RewriteRule ^/(.*) https://%1/$1 [R=301,L]
  686:  </IfModule>
  687: 
  688: =item mimetex_converted()
  689: 
  690: 
  691: =item converted()
  692: 
  693: 
  694: =item to_convert()
  695: 
  696: message display
  697: 
  698: =item smiley()
  699: 
  700: ???
  701: 
  702: =item msgtexconverted()
  703: 
  704: =item algebra()
  705: 
  706: =item prepare_algebra()
  707: 
  708: =item postprocess_algebra()
  709: 
  710: =back
  711: 
  712: =cut
  713: 
  714: 
  715: 

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