File:  [LON-CAPA] / loncom / xml / lontexconvert.pm
Revision 1.111: download - view: text, annotated - select for diffs
Sun Mar 4 14:58:23 2012 UTC (12 years, 3 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
BZ 5873 - Ugly ascii substitutions for large grouping characters that just
don't work uniformly in moder browsers.  The unicode substitutions are present
but commented out as well in the conversion table.

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

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