File:  [LON-CAPA] / loncom / xml / lontexconvert.pm
Revision 1.120: download - view: text, annotated - select for diffs
Sat Oct 7 00:50:57 2017 UTC (6 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6867
  - Domain configuration to set default math renderer for <m> tag content.
  - Default renderer for unconfigured domains changed from tth to MathJax.

    1: # The LearningOnline Network with CAPA
    2: # TeX Conversion Module
    3: #
    4: # $Id: lontexconvert.pm,v 1.120 2017/10/07 00:50:57 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:     '&#63726;'             => 0x23a1,
   67:     '&#63727;'             => 0x23a2,
   68:     '&#63728;'             => 0x23a3,
   69:     '&#63737;'             => 0x23a4,
   70:     '&#63738;'             => 0x23a5,
   71:     '&#63739;'             => 0x23a6,
   72: 
   73: #  Parens - unicode for browsers/OS which support it
   74: 
   75:     '&#63723;'              => 0x239b,
   76:     '&#63724;'              => 0x239c,
   77:     '&#63725;'              => 0x239d,
   78:     '&#63734;'              => 0x239e,
   79:     '&#63735;'              => 0x239f,
   80:     '&#63736;'              => 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:     '&#63726;'              => 0x5b,
   89:     '&#63727;'              => 0x5b,    # '['
   90:     '&#63728;'              => 0x5b,
   91:     '&#63737;'              => 0x5d,    # ']'
   92:     '&#63738;'              => 0x5d,
   93:     '&#63739;'              => 0x5d,
   94: 
   95: # Parens - pure 8-bit ascii ugliness for browsers/OS which can't handle unicode
   96: 
   97:     '&#63723;'              => 0x28,
   98:     '&#63724;'              => 0x28,      # '('
   99:     '&#63725;'              => 0x28,
  100:     '&#63734;'              => 0x29,
  101:     '&#63735;'              => 0x29,      # '('
  102:     '&#63736;'              => 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:     $xmlstring=~s/^<br \/><table/<table/;
  182:     &Apache::lonxml::end_alarm();
  183: 
  184:     #
  185:     # Several strings produced by tth require
  186:     # transliteration -> unicode equivalents to render reliably
  187:     # in browsers. %unicode_translations and %unicode_harpoons are tables of
  188:     # string->substitution which we now apply. (%ascii_8bit_translations used
  189:     # instead for Windows XP and mobile devices.
  190: 
  191:     my $use_ascii;
  192:     if ($env{'browser.os'} eq 'win') {
  193:         if (($env{'browser.osversion'}) && ($env{'browser.osversion'} < 6.0)) {
  194:             $use_ascii = 1;
  195:         }
  196:     }
  197:     if ($env{'browser.mobile'}) {
  198:         $use_ascii = 1;
  199:     }
  200: 
  201:     foreach my $pattern (keys(%unicode_translations)) {
  202: 	my $unicode = $unicode_translations{$pattern};
  203: 	if ($use_ascii) {
  204: 	    $unicode = $ascii_8bit_translations{$pattern};
  205: 	}
  206: 	$xmlstring = &unicode_subst($xmlstring, $pattern, $unicode);
  207:     }
  208: 
  209:     foreach my $pattern (keys(%unicode_harpoons)) {
  210:         $xmlstring = &unicode_subst($xmlstring, $pattern, $unicode_harpoons{$pattern});
  211:     }
  212: 
  213:     return ($xmlstring,$errorstring);
  214: }
  215: 
  216: sub tth_converted {
  217:     my $texstring=shift;
  218:     my $xmlstring='['.&mt('UNDISPLAYABLE').']';
  219:     if ($Apache::lontexconvert::messedup) {
  220: 	return '['.&mt('TeX unconverted due to previous errors').']';
  221:     }
  222:     $$texstring ='\\documentstyle{article}'.$$texstring;
  223: 
  224:     eval(<<'ENDCONV');
  225:     ($xmlstring,$errorstring)=&convert_real($texstring)
  226: ENDCONV
  227:     if ($@) {
  228: 	$errorstring.=&mt("Evaluation Error: ").$@;
  229: 	$Apache::lontexconvert::messedup=1;
  230:     }
  231:     if ($Apache::lontexconvert::messedup || &tth::tthmessedup() || 
  232: 	$errorstring) {
  233: 	&Apache::lonnet::logthis("Trying to kill myself");
  234: 	$Apache::lontexconvert::messedup=1;
  235: 	if (ref($Apache::lonxml::request)) {
  236: 	    $Apache::lonxml::request->child_terminate();
  237: 	} else {
  238: 	    my $request;
  239: 	    eval { $request=Apache->request; };
  240: 	    if (!$request) {
  241: 		eval { $request=Apache2::RequestUtil->request; };
  242: 	    }
  243: 	    if ($request) {
  244: 		$request->child_terminate();
  245: 	    } else {
  246: 		&Apache::lonnet::logthis("Unable to find a request to do child_terminate on");
  247: 	    }
  248: 	}
  249:     }
  250:     return $xmlstring;
  251: }
  252: 
  253: sub clean_out_math_mode {
  254:     my ($texstring)=@_;
  255:     $$texstring=~s/(?<!\\)\$//g;
  256:     $$texstring=~s/\\[\)\(\]\[]//g;
  257:     $$texstring=~s/\\ensuremath//g;
  258:     return '';
  259: }
  260: 
  261: sub displaystyle {
  262:     my ($texstring)=@_;
  263:     #has a $$ or \[ or \displaystyle or eqnarray in it, guessinng it's display mode
  264:     if ($$texstring=~/[^\\]\$\$/ ||
  265:         $$texstring=~/\\\[/ ||
  266:         $$texstring=~/\\displaystyle/ ||
  267:         $$texstring=~/eqnarray/
  268:        ) { return 1; }
  269:     return 0;
  270: }
  271: 
  272: sub MathJax_converted {
  273:     my $texstring=shift;
  274:     my $tag='math/tex;';
  275:     if (&displaystyle($texstring)) { $tag='math/tex; mode=display'; }
  276:     &clean_out_math_mode($texstring);
  277:     return &MathJax_header().
  278:       '<script type="'.$tag.'">'.$$texstring.'</script>';
  279: }
  280: 
  281: {
  282:     #Relies heavily on the previous jsMath installation
  283:     my @MathJax_sent_header;
  284:     sub MathJax_reset {
  285:         undef(@MathJax_sent_header);
  286:     }
  287:     sub MathJax_push {
  288:         push(@MathJax_sent_header,0);
  289:     }
  290:     sub MathJax_header {
  291:         if (!@MathJax_sent_header) {
  292:             &Apache::lonnet::logthis("mismatched calls of MathJax_header and MathJax_process");
  293:             return '';
  294:         }
  295:         return '' if $MathJax_sent_header[-1];
  296:         $MathJax_sent_header[-1]=1;
  297:         return
  298:           '<script type="text/javascript" src="/adm/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'."\n";
  299:     }
  300:     #sub MathJax_process {
  301:     #    my $state = pop(@MathJax_sent_header);
  302:     #    return '' if !$state;
  303:     #    return "\n".
  304:     #        '<script type="text/javascript">MathJax.Process()</script>'."\n";
  305:     #}
  306:     #sub MathJax_state {
  307:     #    my ($level) = @_;
  308:     #    return $MathJax_sent_header[$level];
  309:     #}
  310: }
  311: 
  312: sub tex_engine {
  313:     if (exists($env{'form.texengine'})) {
  314: 	if ($env{'form.texengine'} ne '') {
  315:             if (lc($env{'form.texengine'}) eq 'jsmath') {
  316:                 return 'MathJax'; 
  317:             }
  318:             return $env{'form.texengine'};
  319:         }
  320:     }    
  321:     if ($env{'request.course.id'}
  322: 	&& exists($env{'course.'.$env{'request.course.id'}.'.texengine'})) {
  323:         if (lc($env{'course.'.$env{'request.course.id'}.'.texengine'}) eq 'jsmath') {
  324:             return 'MathJax';
  325:         }
  326: 	return $env{'course.'.$env{'request.course.id'}.'.texengine'};
  327:     }
  328:     if (exists($env{'environment.texengine'})) {
  329:         if (lc($env{'environment.texengine'}) eq 'jsmath') {
  330:             return 'MathJax';
  331:         }
  332: 	return $env{'environment.texengine'};
  333:     }
  334:     my $dom = $env{'request.role.domain'} || $env{'user.domain'};
  335:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
  336:     if ($domdefaults{'texengine'} ne '') {
  337:         return $domdefaults{'texengine'};
  338:     }
  339:     return 'MathJax';
  340: }
  341: 
  342: sub init_math_support {
  343:     &init_tth();
  344:     &Apache::lontexconvert::MathJax_push();
  345:     if (lc(&tex_engine()) eq 'mathjax') {
  346:         return &Apache::lontexconvert::MathJax_header();
  347:     }
  348:     return;
  349: }
  350: 
  351: sub mimetex_valign {
  352:     my ($esc_texstring)=@_;
  353:     my $valign = 0;
  354:     my $path = '/cgi-bin/mimetex.cgi?'.$esc_texstring;
  355:     my $socket;
  356:     &Apache::lonxml::start_alarm();
  357:     $socket = IO::Socket::INET->new(PeerAddr => 'localhost',
  358:                                     PeerPort => 'http(80)',
  359:                                     Proto    => 'tcp');
  360:     if ($socket) {
  361:         my $headreq = "HEAD $path HTTP/1.0\r\n\r\n";
  362:         print $socket $headreq;
  363:         while (<$socket>) {
  364:             if (/Vertical\-Align\:\s*?([\-\d]+)/) {
  365:                 $valign = $1;
  366:             }
  367:         }
  368:         $socket->close();
  369:     }
  370:     &Apache::lonxml::end_alarm();
  371:     return $valign;
  372: }
  373: 
  374: sub mimetex_converted {
  375:     my $texstring=shift;
  376: 
  377: # Alt-Argument for screen readers
  378:     my $alt_string=$$texstring;
  379:     $alt_string=~s/\"/\'\'/g;
  380: 
  381: # Is this displaystyle?
  382: 
  383:     my $displaystyle=&displaystyle($texstring);
  384: 
  385: # Remove math environment delimiters
  386: 
  387:     &clean_out_math_mode($texstring);
  388: 
  389:     if ($displaystyle) {
  390: 	$$texstring='\\displaystyle \\Large '.$$texstring;
  391:     }
  392:     my $esc_texstring = &uri_escape($$texstring);
  393:     my $valign = &mimetex_valign($esc_texstring);
  394:     my $result='<img src="/cgi-bin/mimetex.cgi?'.$esc_texstring.'" style="vertical-align:'.$valign.'px" alt="'.$alt_string.'" />';
  395:     if ($displaystyle) {
  396: 	$result='<div style="text-align:center">'.$result.'</div>';
  397:     }
  398:     return $result;
  399: }
  400: 
  401: sub converted {
  402:     my ($string,$mode)=@_;
  403:     if ($mode eq '') { $mode = &tex_engine(); }
  404:     if ($mode =~ /tth/i) {
  405: 	return &tth_converted($string);
  406:     } elsif ($mode =~ /jsmath/i) {
  407:         return &MathJax_converted($string);
  408:     } elsif ($mode =~ /mathjax/i) {
  409: 	return &MathJax_converted($string);
  410:     } elsif ($mode =~ /mimetex/i) {
  411: 	return &mimetex_converted($string);
  412:     } elsif ($mode =~ /raw/i) {
  413:         return $$string;
  414:     }
  415:     return &tth_converted($string);
  416: }
  417: 
  418: # ------------------------------------------------------------ Message display
  419: 
  420: sub to_convert {
  421:     my ($string) = @_;
  422:     &init_tth();
  423:     $string=~s/\<br\s*\/?\>/ /gs;
  424: #    $string=~s/\s/ /gs;
  425:     $string=&HTML::Entities::decode($string);
  426:     return &converted(\$string);
  427: }
  428: 
  429: sub smiley {
  430:     my $expression=shift;
  431:     my %smileys=(
  432:     	 '\:\-*\)' => 'face-smile.png',
  433: 		 '8\-\)'  => 'face-cool.png',
  434: 		 '8\-(I|\|)'   => 'face-glasses.png',
  435: 		 '\:\-(I|\|)'   => 'face-plain.png',
  436: 		 '\:\-(o|O|\(\))' => 'face-surprise.png',
  437: 		 ':\-\('  => 'face-sad.png',
  438: 		 '\;\-\)' => 'face-wink.png',
  439: 		 '\:\-(P|p)'  => 'face-raspberry.png',
  440: 		 '\:\-(\\\|\\/)' => 'face-uncertain.png',
  441: 		 '\:\-D'  => 'face-smile-big.png',
  442: 		 '\:\-(C|\@)'  => 'face-angry.png',
  443: 		 '\:(\'|\`)\-*\(' => 'face-crying.png',
  444: 		 '\:\-(X|x|\#)' => 'face-quiet.png',
  445: 		 '\:\-(s|S)' => 'face-uncertain.png',
  446: 		 '\:\-\$' => 'face-embarrassed.png',
  447: 		 '\:\-\*' => 'face-kiss.png',
  448: 		 '\+O\(' => 'face-sick.png',
  449: 		 '(\&lt\;3|\(heart\))' => 'heart.png',
  450: 		 '\(rose\)' => 'rose.png',
  451: 		 '\(pizza\)' => 'food-pizza.png',
  452: 		 '\(cake\)' => 'food-cake.png',
  453: 		 '\(ninja\)' => 'face-ninja.png',
  454: 		 '\(pirate\)' => 'face-pirate.png',
  455: 		 '\((agree|yes)\)' => 'opinion-agree.png',
  456: 		 '\((disagree|nay)\)' => 'opinion-disagree.png',
  457: 		 '(o|O)\-\)' => 'face-angel.png',
  458: 		 );
  459:     my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
  460:     foreach my $smiley (keys(%smileys)) {
  461: 	$expression=~s/$smiley/\<img src="$iconpath\/$smileys{$smiley}" \/\>/gs; 
  462:     }
  463:     return $expression;
  464: }
  465: 
  466: sub msgtexconverted {
  467:     my ($message,$email) = @_;
  468:     $errorstring='';
  469:     my $outmessage='';
  470:     my $tex=0;
  471:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*m\s*(?:\&gt\;|\>)/i,$message)) {
  472: 	if ($tex) {
  473: 	    if ($email) {
  474: 		$outmessage.='</pre><tt>'.&to_convert($fragment).'</tt><pre>';
  475: 		$tex=0;
  476: 	    } else {
  477: 		$outmessage.=&to_convert($fragment);
  478: 		$tex=0;
  479: 	    }
  480: 	} else {
  481:             $outmessage.=&smiley($fragment);
  482: 	    $tex=1;
  483: 	}
  484:     }
  485:     $message=$outmessage; $outmessage=''; $tex=0;
  486:     foreach my $fragment (split(/(?:\&lt\;|\<)\/*algebra\s*(?:\&gt\;|\>)/i,
  487: 				$message)) {
  488: 	if ($tex) {
  489:         my $algebra = &algebra($fragment, 'web', undef, undef, undef, 'tth');
  490: 	    if ($email) {
  491: 		$outmessage.='</pre><tt>'.$algebra.'</tt><pre>';
  492: 		$tex=0;
  493: 	    } else {
  494: 		$outmessage.=$algebra;
  495: 		$tex=0;
  496: 	    }
  497: 	} else {
  498:         $outmessage.=$fragment;
  499: 	    $tex=1;
  500: 	}
  501:     }
  502:     if (wantarray) {
  503: 	return ($outmessage,$errorstring);
  504:     } else {
  505: 	return $outmessage.$errorstring;
  506:     }
  507: }
  508: 
  509: sub algebra {
  510:     use AlgParser;
  511:     my ($string,$target,$style,$parstack,$safeeval,$tth)=@_;
  512:     my $parser = new AlgParserWithImplicitExpand;
  513:     if ($tth eq 'tth') {&init_tth();}
  514:     $string=&prepare_algebra($string);
  515:     my $ret = $parser->parse($string);
  516:     my $result='['.&mt('Algebra unconverted due to previous errors').']';
  517:     if ( ref($ret) ) {
  518: 	#$parser->tostring();
  519: 	$parser->normalize();
  520: 	my $latex=$parser->tolatex();
  521: 	$latex=&postprocess_algebra($latex);
  522: 	if ($style eq 'display') {
  523: 	    $latex='$$'.$latex.'$$x';
  524: 	} else {
  525: 	    # style is 'inline'
  526: 	    $latex='\\ensuremath{'.$latex.'}';
  527: 	}
  528: 	if ($target eq 'web' || $target eq 'analyze') {
  529:             my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
  530:             $result = &converted(\$latex,$display);
  531: #	    $result = &converted(\$latex);
  532: 	} else {
  533: 	    $result = $latex;
  534: 	}
  535:     } else {
  536: 	&Apache::lonxml::error($parser->{'htmlerror'});
  537:     }
  538: }
  539: 
  540: sub prepare_algebra {
  541:     my ($string)=@_;
  542: 
  543:     # makes the decision about what is a minus sign easier supposedly
  544:     $string =~ s/(\<\>|\<\=|\>\=[\=\>\<] *)-/$1 zeroplace -/g;
  545: 
  546:     return $string;
  547: }
  548: 
  549: sub postprocess_algebra {
  550:     my ($string)=@_;
  551:     
  552:     # moodle had these and I don't know why, ignoring them for now
  553:     # $string =~s/\\fun/ /g;
  554: 
  555:     # sqrt(3,4) means the 4 root of 3
  556:     $string =~s/\\sqrt\{([^,]+),([^\}]+)}/\\sqrt[$2]{$1}/gs;
  557: 
  558:     # log(3,4) means the log base 4 of 3
  559:     $string =~s/\\log\\left\((.+?),(.+?)\\right\)/\\log_{$2}\\left($1\\right)/gs;
  560: 
  561:     # log(3,4) means the log base 4 of 3
  562:     $string =~s/\\((?:sin|cos|tan|sec|csc|cot)(?:h)?)\\left\((.+?),(.+?)\\right\)/\\$1^{$3}\\left($2\\right)/gs;
  563: 
  564:     # int(3,a,b) integral from a to b of 3
  565:     $string =~s/\\int\\left\((.+?),(.+?),(.+?)\\right\)/\\int_{$2}^{$3}\\left($1\\right)/gs;
  566: 
  567:     # int( ... dx) -> ...
  568:     $string =~s/\\int\\left\((.+?)d[a-z]\\right\)/$1/gs;
  569: 
  570:     # 
  571:     $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
  572:     return $string;
  573: }
  574: 
  575: 
  576: 1;
  577: __END__
  578: 
  579: 
  580: =pod
  581: 
  582: =head1 NAME
  583: 
  584: Apache::lontexconvert;
  585: 
  586: =head1 SYNOPSIS
  587: 
  588: Access to tth/ttm
  589: 
  590: This is part of the LearningOnline Network with CAPA project
  591: described at http://www.lon-capa.org.
  592: 
  593: 
  594: =head1 SUBROUTINES
  595: 
  596: =over
  597: 
  598: =item init_tth()
  599: 
  600: Header
  601: 
  602: =item convert_real()
  603: 
  604:  we need this routine because &converted can get called from inside
  605:  of the safespace (through &xmlparse('<m>stuff</m>') which doesn't
  606:  allow the opcode for alarm, so we need to compile this before we get
  607:  into the safe space since opcode checks only occur at compile time
  608: 
  609: =item tth_converted()
  610: 
  611: 
  612: =item clean_out_math_mode()
  613: 
  614: 
  615: =item displaystyle()
  616: 
  617: 
  618: =item MathJax_converted()
  619: 
  620: =item tex_engine()
  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>