From 04ce4a02c7149cf0c6148e49744fa0a0c9c09c33 Mon Sep 17 00:00:00 2001 From: "physikerwelt (Moritz Schubotz)" Date: Tue, 10 Jun 2014 13:18:26 +0200 Subject: [PATCH] Add options to the math tag * id: Allows to name equations and deep link to equations * forcemathmode: Allows to override the user defined rendering mode. This feature is useful for help pages and discussions about rendering. * type: support for MathML and asciimath input required for MediaWiki instances that want to incorporate MathML sources like for instance pubmed Change-Id: I615c7f1a5762e9e662937b70953fb873309d4c07 --- Math.php | 3 +++ MathRenderer.php | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Math.php b/Math.php index b97f6a79b..cb1633aba 100644 --- a/Math.php +++ b/Math.php @@ -191,6 +191,9 @@ $wgMathDisableTexFilter = false; /** Stores debug information in the database and provides more detailed debug output */ $wgMathDebug = false; + +/** @var boolean $wgMathEnableExperimentalInputFormats enables experimental MathML and AsciiMath input format support */ +$wgMathEnableExperimentalInputFormats = false; ////////// end of config settings. $wgExtensionFunctions[] = 'MathHooks::setup'; diff --git a/MathRenderer.php b/MathRenderer.php index dd64ad4ed..d25e0c9ce 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -117,7 +117,7 @@ abstract class MathRenderer { * @return MathRenderer appropriate renderer for mode */ public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) { - global $wgDefaultUserOptions, $wgMathValidModes; + global $wgDefaultUserOptions, $wgMathValidModes, $wgMathEnableExperimentalInputFormats; $mathStyle = null; if ( isset( $params['display'] ) ) { $layoutMode = $params['display']; @@ -139,9 +139,23 @@ abstract class MathRenderer { $tex = '{\textstyle ' . $tex . '}'; } } + $id = null; + if ( isset( $params['id'] ) ) { + $id = $params['id']; + } + if ( isset( $params['forcemathmode'] ) ) { + $mode = $params['forcemathmode']; + } if ( !in_array( $mode, $wgMathValidModes ) ) { $mode = $wgDefaultUserOptions['math']; } + if ( $wgMathEnableExperimentalInputFormats === true && $mode == MW_MATH_MATHML && isset( $params['type'] ) ) { + // Support of MathML input (experimental) + // Currently support for mode MW_MATH_MATHML only + if( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) { + unset( $params['type'] ); + } + } switch ( $mode ) { case MW_MATH_MATHJAX: case MW_MATH_SOURCE: