mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 23:25:02 +00:00
Expose LaTeXML Settings
Make LaTeXML setting configurable with the new global variable $wgDefaultLaTeXMLSetting. PS: This variable can be specified as an array or a string. If specified as an array, the array('a'=>'b','c'=>array('e','f')) would be transformed to the equivalent setting a=b&c=e&c=f ,which is the input format for the LaTeXML daemon. Change-Id: I2869df27cee83b426c6eb2312306fac9d6203ef2
This commit is contained in:
parent
40ba7ff462
commit
12b43489ea
6
Math.php
6
Math.php
|
@ -127,7 +127,11 @@ $wgUseLaTeXML = false;
|
|||
* in seconds.
|
||||
*/
|
||||
$wgLaTeXMLTimeout = 240;
|
||||
|
||||
/**
|
||||
* Setting for the LaTeXML renderer.
|
||||
* See http://dlmf.nist.gov/LaTeXML/manual/commands/latexmlpost.xhtml for details.
|
||||
*/
|
||||
$wgDefaultLaTeXMLSetting = 'format=xhtml&whatsin=math&whatsout=math&pmml&cmml&nodefaultresources&preload=LaTeX.pool&preload=article.cls&preload=amsmath.sty&preload=amsthm.sty&preload=amstext.sty&preload=amssymb.sty&preload=eucal.sty&preload=[dvipsnames]xcolor.sty&preload=url.sty&preload=hyperref.sty&preload=[ids]latexml.sty&preload=texvc';
|
||||
////////// end of config settings.
|
||||
|
||||
$wgDefaultUserOptions['math'] = MW_MATH_PNG;
|
||||
|
|
|
@ -15,18 +15,35 @@ class MathLaTeXML extends MathRenderer {
|
|||
* @var String settings for LaTeXML daemon
|
||||
*/
|
||||
private $LaTeXMLSettings = '';
|
||||
const DEFAULT_LATEXML_SETTING = 'format=xhtml&whatsin=math&whatsout=math&pmml&cmml&nodefaultresources&preload=LaTeX.pool&preload=article.cls&preload=amsmath.sty&preload=amsthm.sty&preload=amstext.sty&preload=amssymb.sty&preload=eucal.sty&preload=[dvipsnames]xcolor.sty&preload=url.sty&preload=hyperref.sty&preload=[ids]latexml.sty&preload=texvc';
|
||||
|
||||
/**
|
||||
* Converts an array with LaTeXML settings to a URL encoded String.
|
||||
* If the argument is a string the input will be returned.
|
||||
* Thus the function has projector properties and can be applied a second time safely.
|
||||
* @param (string|array) $array
|
||||
* @return string
|
||||
*/
|
||||
public function serializeSettings($array){
|
||||
if(!is_array($array)){
|
||||
return $array;
|
||||
} else {
|
||||
//removes the [1] [2]... for the unnamed subarrays since LaTeXML
|
||||
//assigns multiple values to one key e.g.
|
||||
//preload=amsmath.sty&preload=amsthm.sty&preload=amstext.sty
|
||||
return preg_replace('|\%5B\d+\%5D|', '', wfArrayToCgi($array)) ;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the settings for the LaTeXML daemon.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLaTeXMLSettings() {
|
||||
global $wgDefaultLaTeXMLSetting;
|
||||
if ( $this->LaTeXMLSettings ) {
|
||||
return $this->LaTeXMLSettings;
|
||||
} else {
|
||||
return self::DEFAULT_LATEXML_SETTING;
|
||||
return $wgDefaultLaTeXMLSetting;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +53,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
* For a list of possible settings see:
|
||||
* http://dlmf.nist.gov/LaTeXML/manual/commands/latexmlpost.xhtml
|
||||
* An empty value indicates to use the default settings.
|
||||
* @param string $settings
|
||||
* @param string|array $settings
|
||||
*/
|
||||
public function setLaTeXMLSettings( $settings ) {
|
||||
$this->LaTeXMLSettings = $settings;
|
||||
|
@ -158,7 +175,8 @@ class MathLaTeXML extends MathRenderer {
|
|||
*/
|
||||
public function getPostData() {
|
||||
$texcmd = urlencode( $this->tex );
|
||||
return $this->getLaTeXMLSettings() . '&tex=' . $texcmd;
|
||||
$settings = $this->serializeSettings($this->getLaTeXMLSettings());
|
||||
return $settings. '&tex=' . $texcmd;
|
||||
}
|
||||
/**
|
||||
* Does the actual web request to convert TeX to MathML.
|
||||
|
|
|
@ -99,7 +99,26 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
|
|||
$invalidSample = '<notmath />';
|
||||
$this->assertTrue( MathLaTeXML::isValidMathML( $validSample ), 'test if math expression is valid mathml sample' );
|
||||
$this->assertFalse( MathLaTeXML::isValidMathML( $invalidSample ), 'test if math expression is invalid mathml sample' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the serialiazation of the LaTeXML settings
|
||||
* @covers MathLaTeXML::serializeSettings
|
||||
*/
|
||||
public function testSerializeSettings() {
|
||||
$renderer = $this->getMockBuilder( 'MathLaTeXML' )
|
||||
->setMethods( NULL )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sampleSettings = array(
|
||||
'k1'=>'v1',
|
||||
'k2&='=>'v2 + & *üö',
|
||||
'k3' => array(
|
||||
'v3A', 'v3b'
|
||||
));
|
||||
$expected = 'k1=v1&k2%26%3D=v2+%2B+%26+%2A%C3%BC%C3%B6&k3=v3A&k3=v3b';
|
||||
$this->assertEquals( $expected,$renderer->serializeSettings($sampleSettings), 'test serialization of array settings' );
|
||||
$this->assertEquals( $expected,$renderer->serializeSettings($expected), 'test serialization of a string setting' );
|
||||
}
|
||||
/**
|
||||
* Checks the basic functionallity
|
||||
|
|
Loading…
Reference in a new issue