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