]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AsciiMath.php
new MathML plugin and lib
[SourceForge/phpwiki.git] / lib / plugin / AsciiMath.php
1 <?php // -*-php-*-
2 rcs_id('$Id: AsciiMath.php,v 1.1 2005-01-29 21:50:38 rurban Exp $');
3 /*
4 Copyright 2005 $ThePhpWikiProgrammingTeam
5
6 This file is part of PhpWiki.
7
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23 require_once("lib/ASCIIMathPHP/ASCIIMathPHP.class.php");
24
25 /** 
26  * Render ASCII math as MathML
27  * Requires ENABLE_XHTML_XML = true
28  * See http://www.jcphysics.com/ASCIIMath/
29  * Syntax: http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.xml
30  * Example: "int_-1^1 sqrt(1-x^2)dx = pi/2"
31  * => <math xmlns="http://www.w3.org/1998/Math/MathML">
32         <mrow><msubsup><mo>&#8747;</mo><mn>-1</mn><mn>1</mn></msubsup></mrow>
33         <msqrt><mrow><mn>1</mn><mo>-</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></msqrt>
34         <mi>d</mi>
35         <mi>x</mi>
36         <mo>=</mo>
37         <mfrac><mi>&#960;</mi><mo>2</mo></mfrac>
38       </math>
39  */
40 class WikiPlugin_AsciiMath
41 extends WikiPlugin
42 {
43     function getName() {
44         return _("AsciiMath");
45     }
46
47     function getDescription() {
48         return _("Render ASCII Math as MathML");
49     }
50
51     function getVersion() {
52         return preg_replace("/[Revision: $]/", '',
53                             "\$Revision: 1.1 $");
54     }
55
56     function getDefaultArguments() {
57         return array();
58     }
59     function handle_plugin_args_cruft(&$argstr, &$args) {
60         $this->source = $argstr;
61     }
62
63     function run($dbi, $argstr, &$request, $basepage) {
64         $args = $this->getArgs($argstr, $request);
65         if (empty($this->source))
66             return '';
67
68         include_once("lib/ASCIIMathPHP/ASCIIMathPHP.cfg.php");
69         $ascii_math = new ASCIIMathPHP($symbol_arr, $this->source);
70         $ascii_math->genMathML();
71         return HTML::Raw($ascii_math->getMathML());
72     }
73 };
74
75 // $Log: not supported by cvs2svn $
76
77 // Local Variables:
78 // mode: php
79 // tab-width: 8
80 // c-basic-offset: 4
81 // c-hanging-comment-ender-p: nil
82 // indent-tabs-mode: nil
83 // End:
84 ?>