Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/149916

Change subject: Add SVG generation for LaTeXML
......................................................................

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.

Change-Id: If13a8b0825bf12dbfe4920ddb7ad552df9bc095f
---
M MathLaTeXML.php
1 file changed, 32 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/16/149916/1

diff --git a/MathLaTeXML.php b/MathLaTeXML.php
index a93417f..0f6d820 100644
--- a/MathLaTeXML.php
+++ b/MathLaTeXML.php
@@ -145,7 +145,6 @@
                }
        }
 
-
        /**
         * Internal version of @link self::embedMathML
         * @return string
@@ -174,6 +173,38 @@
                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';
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/149916
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If13a8b0825bf12dbfe4920ddb7ad552df9bc095f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to