Annotation of loncom/xml/lontexconvert.pm, revision 1.112.2.3
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # TeX Conversion Module
3: #
1.112.2.3! raeburn 4: # $Id: lontexconvert.pm,v 1.112.2.2 2012/05/25 16:42:28 raeburn Exp $
1.4 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
1.1 harris41 39:
40: package Apache::lontexconvert;
41:
42: use strict;
1.33 albertel 43: use tth();
1.1 harris41 44: use vars qw($errorstring);
1.73 albertel 45: #use Apache::lonxml();
1.33 albertel 46: use Apache::lonlocal;
1.65 albertel 47: use Apache::lonnet;
1.75 www 48: use lib '/home/httpd/lib/perl/';
49: use LONCAPA;
1.94 raeburn 50: use URI::Escape;
51: use IO::Socket::INET;
1.1 harris41 52:
1.110 foxr 53:
54: #
55: # Table of substitutions to unicode characters.
56: #
57: my %unicode_translations = (
58: '\rightleftharpoons' => 0x21cc,
1.111 foxr 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:
1.110 foxr 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:
1.1 harris41 115: # ====================================================================== Header
116:
1.29 albertel 117: sub init_tth {
1.65 albertel 118: my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'};
1.74 albertel 119: if ($options =~ /\S/) {
120: $options = ' '.$options;
121: } else {
122: undef($options);
123: }
1.65 albertel 124: if ($env{'browser.mathml'}) {
1.29 albertel 125: &tth::ttminit();
1.65 albertel 126: if ($env{'browser.unicode'}) {
1.74 albertel 127: &tth::ttmoptions('-L -u1'.$options);
1.29 albertel 128: } else {
1.74 albertel 129: &tth::ttmoptions('-L -u0'.$options);
1.29 albertel 130: }
131: } else {
132: &tth::tthinit();
1.65 albertel 133: if ($env{'browser.unicode'}) {
1.74 albertel 134: &tth::tthoptions('-L -u1'.$options);
1.29 albertel 135: } else {
1.74 albertel 136: &tth::tthoptions('-L -u0'.$options);
1.29 albertel 137: }
138: }
139: }
140:
1.1 harris41 141: # ================================================================== Conversion
142:
1.19 albertel 143: $Apache::lontexconvert::messedup=0;
1.36 albertel 144:
1.91 jms 145:
1.36 albertel 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 {
1.37 albertel 151: &Apache::lonnet::logthis("ALRM");
1.36 albertel 152: $xmlstring='['.&mt("TeX unconverted due to errors").']';
153: $Apache::lontexconvert::messedup=1;
154: die &mt("TeX unconverted due to errors");
155: };
1.63 albertel 156: &Apache::lonxml::start_alarm();
1.65 albertel 157: if ($env{'browser.mathml'}) {
1.36 albertel 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: }
1.43 www 168: $xmlstring=~s/^\s*\<br clear\=\"all\"/\<br/s;
1.36 albertel 169: $xmlstring=~s/^\s*//;
170: $xmlstring=~s/\s*$//;
1.110 foxr 171: &Apache::lonxml::end_alarm();
172:
1.85 foxr 173: #
1.110 foxr 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:
1.85 foxr 184:
1.36 albertel 185: return ($xmlstring,$errorstring);
186: }
187:
1.59 albertel 188: sub tth_converted {
1.31 albertel 189: my $texstring=shift;
1.34 www 190: my $xmlstring='['.&mt('UNDISPLAYABLE').']';
1.31 albertel 191: if ($Apache::lontexconvert::messedup) {
1.35 albertel 192: return '['.&mt('TeX unconverted due to previous errors').']';
1.31 albertel 193: }
1.59 albertel 194: $$texstring ='\\documentstyle{article}'.$$texstring;
195:
1.31 albertel 196: eval(<<'ENDCONV');
1.36 albertel 197: ($xmlstring,$errorstring)=&convert_real($texstring)
1.12 www 198: ENDCONV
1.32 albertel 199: if ($@) {
1.35 albertel 200: $errorstring.=&mt("Evaluation Error: ").$@;
1.32 albertel 201: $Apache::lontexconvert::messedup=1;
202: }
1.37 albertel 203: if ($Apache::lontexconvert::messedup || &tth::tthmessedup() ||
204: $errorstring) {
1.31 albertel 205: &Apache::lonnet::logthis("Trying to kill myself");
206: $Apache::lontexconvert::messedup=1;
1.70 albertel 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: }
1.31 albertel 221: }
222: return $xmlstring;
1.1 harris41 223: }
224:
1.62 albertel 225: sub clean_out_math_mode {
226: my ($texstring)=@_;
1.82 albertel 227: $$texstring=~s/(?<!\\)\$//g;
1.62 albertel 228: $$texstring=~s/\\[\)\(\]\[]//g;
229: $$texstring=~s/\\ensuremath//g;
230: return '';
231: }
232:
233: sub displaystyle {
234: my ($texstring)=@_;
1.106 bisitz 235: #has a $$ or \[ or \displaystyle or eqnarray in it, guessinng it's display mode
1.62 albertel 236: if ($$texstring=~/[^\\]\$\$/ ||
1.106 bisitz 237: $$texstring=~/\\\[/ ||
238: $$texstring=~/\\displaystyle/ ||
239: $$texstring=~/eqnarray/
240: ) { return 1; }
1.62 albertel 241: return 0;
242: }
243:
1.112.2.2 raeburn 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:
1.59 albertel 274: sub jsMath_converted {
275: my $texstring=shift;
276: my $tag='span';
1.62 albertel 277: if (&displaystyle($texstring)) { $tag='div'; }
278: &clean_out_math_mode($texstring);
1.67 albertel 279: return &jsMath_header().
280: '<'.$tag.' class="math">'.$$texstring.'</'.$tag.'>';
281: }
282:
283: {
1.76 albertel 284: my @jsMath_sent_header;
1.67 albertel 285: sub jsMath_reset {
1.76 albertel 286: undef(@jsMath_sent_header);
287: }
288: sub jsMath_push {
289: push(@jsMath_sent_header,0);
1.67 albertel 290: }
291: sub jsMath_header {
1.80 albertel 292: if (!@jsMath_sent_header) {
293: &Apache::lonnet::logthis("mismatched calls of jsMath_header and jsMath_process");
294: return '';
295: }
1.76 albertel 296: return '' if $jsMath_sent_header[-1];
297: $jsMath_sent_header[-1]=1;
1.67 albertel 298: return
299: '<script type="text/javascript">
300: function NoFontMessage () {}
1.78 albertel 301: jsMath = {Parser: {prototype: {environments: {\'eqnarray*\' :[\'Array\',null,null,\'rcl\',[5/18,5/18],3,\'D\']}}}};
1.67 albertel 302: </script>'."\n".
1.71 albertel 303: '<script type="text/javascript" src="/adm/jsMath/jsMath.js"></script>'."\n";
1.67 albertel 304: }
305: sub jsMath_process {
1.76 albertel 306: my $state = pop(@jsMath_sent_header);
307: return '' if !$state;
1.81 albertel 308: return "\n".
309: '<script type="text/javascript">jsMath.Process()</script>'."\n";
1.67 albertel 310: }
1.84 albertel 311: sub jsMath_state {
312: my ($level) = @_;
313: return $jsMath_sent_header[$level];
314: }
1.62 albertel 315: }
316:
1.83 albertel 317: sub tex_engine {
318: if (exists($env{'form.texengine'})) {
1.88 raeburn 319: if ($env{'form.texengine'} ne '') {
320: return $env{'form.texengine'};
321: }
1.83 albertel 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:
1.72 albertel 333: sub init_math_support {
1.84 albertel 334: my ($inherit_jsmath) = @_;
1.73 albertel 335: &init_tth();
1.76 albertel 336: &Apache::lontexconvert::jsMath_push();
1.84 albertel 337: if (lc(&tex_engine()) eq 'jsmath' ||
338: ($inherit_jsmath && &jsMath_state(-2))) {
1.72 albertel 339: return &Apache::lontexconvert::jsMath_header();
340: }
1.112.2.2 raeburn 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: }
1.72 albertel 346: return;
347: }
348:
1.92 hauer 349: sub mimetex_valign {
1.94 raeburn 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();
1.108 raeburn 355: $socket = IO::Socket::INET->new(PeerAddr => 'localhost',
1.107 raeburn 356: PeerPort => 'http(80)',
357: Proto => 'tcp');
1.94 raeburn 358: if ($socket) {
1.96 raeburn 359: my $headreq = "HEAD $path HTTP/1.0\r\n\r\n";
1.94 raeburn 360: print $socket $headreq;
361: while (<$socket>) {
362: if (/Vertical\-Align\:\s*?([\-\d]+)/) {
363: $valign = $1;
364: }
365: }
1.105 raeburn 366: $socket->close();
1.92 hauer 367: }
1.94 raeburn 368: &Apache::lonxml::end_alarm();
369: return $valign;
1.92 hauer 370: }
371:
1.62 albertel 372: sub mimetex_converted {
373: my $texstring=shift;
1.97 www 374:
375: # Alt-Argument for screen readers
376: my $alt_string=$$texstring;
377: $alt_string=~s/\"/\'\'/g;
378:
379: # Is this displaystyle?
380:
1.62 albertel 381: my $displaystyle=&displaystyle($texstring);
382:
1.97 www 383: # Remove math environment delimiters
384:
1.62 albertel 385: &clean_out_math_mode($texstring);
386:
387: if ($displaystyle) {
388: $$texstring='\\displaystyle \\Large '.$$texstring;
1.59 albertel 389: }
1.94 raeburn 390: my $esc_texstring = &uri_escape($$texstring);
391: my $valign = &mimetex_valign($esc_texstring);
1.97 www 392: my $result='<img src="/cgi-bin/mimetex.cgi?'.$esc_texstring.'" style="vertical-align:'.$valign.'px" alt="'.$alt_string.'" />';
1.62 albertel 393: if ($displaystyle) {
1.106 bisitz 394: $result='<div style="text-align:center">'.$result.'</div>';
1.62 albertel 395: }
396: return $result;
1.59 albertel 397: }
398:
399: sub converted {
1.67 albertel 400: my ($string,$mode)=@_;
1.83 albertel 401: if ($mode eq '') { $mode = &tex_engine(); }
1.68 albertel 402: if ($mode =~ /tth/i) {
1.67 albertel 403: return &tth_converted($string);
1.68 albertel 404: } elsif ($mode =~ /jsmath/i) {
1.67 albertel 405: return &jsMath_converted($string);
1.112.2.2 raeburn 406: } elsif ($mode =~ /mathjax/i) {
407: return &MathJax_converted($string);
1.68 albertel 408: } elsif ($mode =~ /mimetex/i) {
1.67 albertel 409: return &mimetex_converted($string);
1.98 www 410: } elsif ($mode =~ /raw/i) {
411: return $$string;
1.59 albertel 412: }
1.67 albertel 413: return &tth_converted($string);
1.59 albertel 414: }
415:
1.6 www 416: # ------------------------------------------------------------ Message display
417:
1.9 albertel 418: sub to_convert {
419: my ($string) = @_;
1.102 faziophi 420: &init_tth();
1.22 www 421: $string=~s/\<br\s*\/?\>/ /gs;
1.30 albertel 422: # $string=~s/\s/ /gs;
1.18 albertel 423: $string=&HTML::Entities::decode($string);
1.9 albertel 424: return &converted(\$string);
425: }
426:
1.20 www 427: sub smiley {
1.31 albertel 428: my $expression=shift;
1.99 faziophi 429: my %smileys=(
430: '\:\-*\)' => 'face-smile.png',
1.100 faziophi 431: '8\-\)' => 'face-cool.png',
432: '8\-(I|\|)' => 'face-glasses.png',
1.101 faziophi 433: '\:\-(I|\|)' => 'face-plain.png',
1.99 faziophi 434: '\:\-(o|O|\(\))' => 'face-surprise.png',
1.101 faziophi 435: ':\-\(' => 'face-sad.png',
436: '\;\-\)' => 'face-wink.png',
437: '\:\-(P|p)' => 'face-raspberry.png',
1.100 faziophi 438: '\:\-(\\\|\\/)' => 'face-uncertain.png',
1.101 faziophi 439: '\:\-D' => 'face-smile-big.png',
440: '\:\-(C|\@)' => 'face-angry.png',
1.99 faziophi 441: '\:(\'|\`)\-*\(' => 'face-crying.png',
1.101 faziophi 442: '\:\-(X|x|\#)' => 'face-quiet.png',
443: '\:\-(s|S)' => 'face-uncertain.png',
444: '\:\-\$' => 'face-embarrassed.png',
445: '\:\-\*' => 'face-kiss.png',
1.99 faziophi 446: '\+O\(' => 'face-sick.png',
447: '(\<\;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',
1.101 faziophi 455: '(o|O)\-\)' => 'face-angel.png',
1.99 faziophi 456: );
1.31 albertel 457: my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
1.79 albertel 458: foreach my $smiley (keys(%smileys)) {
1.99 faziophi 459: $expression=~s/$smiley/\<img src="$iconpath\/$smileys{$smiley}" \/\>/gs;
1.31 albertel 460: }
461: return $expression;
1.20 www 462: }
463:
1.6 www 464: sub msgtexconverted {
1.39 raeburn 465: my ($message,$email) = @_;
1.17 albertel 466: $errorstring='';
1.25 www 467: my $outmessage='';
468: my $tex=0;
1.79 albertel 469: foreach my $fragment (split(/(?:\<\;|\<)\/*m\s*(?:\>\;|\>)/i,$message)) {
1.25 www 470: if ($tex) {
1.30 albertel 471: if ($email) {
1.79 albertel 472: $outmessage.='</pre><tt>'.&to_convert($fragment).'</tt><pre>';
473: $tex=0;
1.30 albertel 474: } else {
1.79 albertel 475: $outmessage.=&to_convert($fragment);
476: $tex=0;
1.30 albertel 477: }
1.25 www 478: } else {
1.79 albertel 479: $outmessage.=&smiley($fragment);
480: $tex=1;
1.25 www 481: }
482: }
1.64 albertel 483: $message=$outmessage; $outmessage=''; $tex=0;
1.79 albertel 484: foreach my $fragment (split(/(?:\<\;|\<)\/*algebra\s*(?:\>\;|\>)/i,
485: $message)) {
1.64 albertel 486: if ($tex) {
1.112.2.3! raeburn 487: my $algebra = &algebra($fragment, 'web', undef, undef, undef, 'tth');
1.64 albertel 488: if ($email) {
1.103 faziophi 489: $outmessage.='</pre><tt>'.$algebra.'</tt><pre>';
1.79 albertel 490: $tex=0;
1.64 albertel 491: } else {
1.103 faziophi 492: $outmessage.=$algebra;
1.79 albertel 493: $tex=0;
1.64 albertel 494: }
495: } else {
1.103 faziophi 496: $outmessage.=$fragment;
1.79 albertel 497: $tex=1;
1.64 albertel 498: }
499: }
1.24 albertel 500: if (wantarray) {
1.25 www 501: return ($outmessage,$errorstring);
1.24 albertel 502: } else {
1.25 www 503: return $outmessage.$errorstring;
1.24 albertel 504: }
1.1 harris41 505: }
506:
1.44 albertel 507: sub algebra {
1.49 albertel 508: use AlgParser;
1.103 faziophi 509: my ($string,$target,$style,$parstack,$safeeval,$tth)=@_;
1.44 albertel 510: my $parser = new AlgParserWithImplicitExpand;
1.103 faziophi 511: if ($tth eq 'tth') {&init_tth();}
1.46 albertel 512: $string=&prepare_algebra($string);
1.44 albertel 513: my $ret = $parser->parse($string);
514: my $result='['.&mt('Algebra unconverted due to previous errors').']';
515: if ( ref($ret) ) {
1.50 albertel 516: #$parser->tostring();
1.44 albertel 517: $parser->normalize();
518: my $latex=$parser->tolatex();
1.49 albertel 519: $latex=&postprocess_algebra($latex);
1.58 albertel 520: if ($style eq 'display') {
521: $latex='$$'.$latex.'$$x';
522: } else {
1.61 albertel 523: # style is 'inline'
1.58 albertel 524: $latex='\\ensuremath{'.$latex.'}';
525: }
1.44 albertel 526: if ($target eq 'web' || $target eq 'analyze') {
1.89 droeschl 527: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
528: $result = &converted(\$latex,$display);
529: # $result = &converted(\$latex);
1.44 albertel 530: } else {
531: $result = $latex;
532: }
533: } else {
534: &Apache::lonxml::error($parser->{'htmlerror'});
535: }
536: }
537:
1.46 albertel 538: sub prepare_algebra {
539: my ($string)=@_;
540:
1.50 albertel 541: # makes the decision about what is a minus sign easier supposedly
1.57 albertel 542: $string =~ s/(\<\>|\<\=|\>\=[\=\>\<] *)-/$1 zeroplace -/g;
1.48 albertel 543:
1.46 albertel 544: return $string;
545: }
546:
547: sub postprocess_algebra {
548: my ($string)=@_;
1.48 albertel 549:
1.50 albertel 550: # moodle had these and I don't know why, ignoring them for now
1.51 albertel 551: # $string =~s/\\fun/ /g;
1.47 albertel 552:
1.51 albertel 553: # sqrt(3,4) means the 4 root of 3
1.52 albertel 554: $string =~s/\\sqrt{([^,]+),([^\}]+)}/\\sqrt[$2]{$1}/gs;
555:
1.53 albertel 556: # log(3,4) means the log base 4 of 3
557: $string =~s/\\log\\left\((.+?),(.+?)\\right\)/\\log_{$2}\\left($1\\right)/gs;
558:
1.54 albertel 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:
1.55 albertel 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;
1.51 albertel 567:
1.56 albertel 568: #
569: $string =~s/\\lim\\left\((.+?),(.+?),(.+?)\\right\)/\\lim_{$2\\to $3}$1/gs;
1.46 albertel 570: return $string;
571: }
1.1 harris41 572: 1;
573: __END__
574:
575:
1.91 jms 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:
1.112.2.2 raeburn 616: =item MathJax_converted()
617: - Mimics the jsMath functionality
618:
1.91 jms 619: =item tex_engine()
620:
621:
622: =item init_math_support()
623:
1.105 raeburn 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>
1.91 jms 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()
1.1 harris41 679:
1.91 jms 680: =back
1.1 harris41 681:
1.91 jms 682: =cut
1.1 harris41 683:
684:
685:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>