3 * Copyright 2005 $ThePhpWikiProgrammingTeam
4 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
6 * This file is part of PhpWiki.
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.
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.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 if (phpversion() >= '5') {
24 require_once("lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php");
26 require_once("lib/ASCIIMathPHP/ASCIIMathPHP.class.php");
30 * Render ASCII math as MathML
31 * Requires ENABLE_XHTML_XML = true
32 * See http://www.jcphysics.com/ASCIIMath/
33 * Syntax: http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.xml
34 * Example: "int_-1^1 sqrt(1-x^2)dx = pi/2"
35 * => <math xmlns="http://www.w3.org/1998/Math/MathML">
36 <mrow><msubsup><mo>∫</mo><mn>-1</mn><mn>1</mn></msubsup></mrow>
37 <msqrt><mrow><mn>1</mn><mo>-</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></msqrt>
41 <mfrac><mi>π</mi><mo>2</mo></mfrac>
44 class WikiPlugin_AsciiMath
48 return _("AsciiMath");
51 function getDescription() {
52 return _("Render ASCII Math as MathML");
55 function getDefaultArguments() {
58 function handle_plugin_args_cruft(&$argstr, &$args) {
59 $this->source = $argstr;
62 function run($dbi, $argstr, &$request, $basepage) {
63 $args = $this->getArgs($argstr, $request);
64 if (empty($this->source)) {
65 return HTML::div(array('class' => "error"), "Please provide a formula to AsciiMath plugin");
68 if (phpversion() >= '5') {
69 include("lib/ASCIIMathPHP/ASCIIMathPHP-2.0.cfg.php");
71 include("lib/ASCIIMathPHP/ASCIIMathPHP.cfg.php");
73 $ascii_math = new ASCIIMathPHP($symbol_arr, $this->source);
74 $ascii_math->genMathML();
75 return HTML::raw($ascii_math->getMathML());
83 // c-hanging-comment-ender-p: nil
84 // indent-tabs-mode: nil