Add SVG generation for LaTeXML
Currently SVGs are generated only in MathML mode but not in LaTeXML mode. Since LaTeXML can benefit from the SVGs as well this change introduces the functionality to generate SVG images from LaTeXML MathML input. Generating SVG images for LaTeXML is an essential part of Math 2.0. It enables to include LaTeXMLs Content MathML and provides fallback images for visitors with MathML disabled browsers. Change-Id: If13a8b0825bf12dbfe4920ddb7ad552df9bc095f
This commit is contained in:
parent
272e6869ed
commit
6cb52f9190
|
@ -145,7 +145,6 @@ class MathLaTeXML extends MathMathML {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal version of @link self::embedMathML
|
||||
* @return string
|
||||
|
@ -174,6 +173,38 @@ class MathLaTeXML extends MathMathML {
|
|||
return Xml::tags( 'span', $attribs, $mml );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the SVG image based on the MathML input
|
||||
* No cache is used.
|
||||
* @return boolean
|
||||
*/
|
||||
public function calulateSvg() {
|
||||
$renderer = new MathMathML( $this->getTex() );
|
||||
$renderer->setMathml( $this->getMathml() );
|
||||
$renderer->setMode( MW_MATH_LATEXML );
|
||||
$renderer->setPurge( true );
|
||||
$res = $renderer->render();
|
||||
if ( $res == true ) {
|
||||
$this->svg = $renderer->getSvg();
|
||||
} else {
|
||||
$lastError = $renderer->getLastError();
|
||||
wfDebugLog( 'Math', 'failed to convert LaTeXML-MathML to SVG:' . $lastError );
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SVG image
|
||||
* Lazy evaluation: If no SVG image exists it's generated on the fly
|
||||
* @return string XML-Document of the rendered SVG
|
||||
*/
|
||||
public function getSvg() {
|
||||
if ( $this->isPurge() || $this->svg == '' ) {
|
||||
$this->calulateSvg();
|
||||
}
|
||||
return $this->svg;
|
||||
}
|
||||
|
||||
protected function getMathTableName() {
|
||||
return 'mathlatexml';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue