4 * Copyright 2005 $ThePhpWikiProgrammingTeam
5 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
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.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 if (phpversion() >= '5') {
25 require_once("lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php");
27 require_once("lib/ASCIIMathPHP/ASCIIMathPHP.class.php");
31 * Render ASCII math as MathML
32 * Requires ENABLE_XHTML_XML = true
33 * See http://www.jcphysics.com/ASCIIMath/
34 * Syntax: http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.xml
35 * Example: "int_-1^1 sqrt(1-x^2)dx = pi/2"
36 * => <math xmlns="http://www.w3.org/1998/Math/MathML">
37 <mrow><msubsup><mo>∫</mo><mn>-1</mn><mn>1</mn></msubsup></mrow>
38 <msqrt><mrow><mn>1</mn><mo>-</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></msqrt>
42 <mfrac><mi>π</mi><mo>2</mo></mfrac>
45 class WikiPlugin_AsciiMath
49 return _("AsciiMath");
52 function getDescription() {
53 return _("Render ASCII Math as MathML");
56 function getVersion() {
57 return preg_replace("/[Revision: $]/", '',
61 function getDefaultArguments() {
64 function handle_plugin_args_cruft(&$argstr, &$args) {
65 $this->source = $argstr;
68 function run($dbi, $argstr, &$request, $basepage) {
69 $args = $this->getArgs($argstr, $request);
70 if (empty($this->source)) {
71 return HTML::div(array('class' => "error"), "Please provide a formula to AsciiMath plugin");
74 if (phpversion() >= '5') {
75 include("lib/ASCIIMathPHP/ASCIIMathPHP-2.0.cfg.php");
77 include("lib/ASCIIMathPHP/ASCIIMathPHP.cfg.php");
79 $ascii_math = new ASCIIMathPHP($symbol_arr, $this->source);
80 $ascii_math->genMathML();
81 return HTML::raw($ascii_math->getMathML());
89 // c-hanging-comment-ender-p: nil
90 // indent-tabs-mode: nil