File:  [LON-CAPA] / loncom / xml / lontexconvert.pm
Revision 1.112.2.2: download - view: text, annotated - select for diffs
Fri May 25 16:42:28 2012 UTC (12 years ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_0_RC1
- For 2.11.
  - Reinstate 1.109 (reverse changes in 1.112.2.1). MathJax now in 2.11.

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

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