Export Math Equations from Presentations in .NET
Introduction
Aspose.Slides for .NET allows you to export math equations from presentations. For example, you may need to extract the mathematical equations on slides (from a specific presentation) and use them in another program or platform.
Save Math Equations as MathML
While humans easily write the code for some equation formats like LaTeX, they struggle to write the code for MathML because the latter is meant to be generated automatically by apps. Programs read and parse MathML easily because its code is in XML, so MathML is commonly used as an output and printing format in many fields.
This sample code shows you how to export a math equation from a presentation to MathML:
using (Presentation pres = new Presentation())
{
var autoShape = pres.Slides[0].Shapes.AddMathShape(0, 0, 500, 50);
var mathParagraph = ((MathPortion)autoShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
mathParagraph.Add(new MathematicalText("a").SetSuperscript("2").Join("+").Join(new MathematicalText("b").SetSuperscript("2")).Join("=").Join(new MathematicalText("c").SetSuperscript("2")));
using (Stream stream = new FileStream("mathml.xml", FileMode.Create))
mathParagraph.WriteAsMathMl(stream);
}
FAQ
What exactly is exported to MathML—a paragraph or an individual formula block?
You can export either an entire math paragraph (MathParagraph) or an individual block (MathBlock) to MathML. Both types provide a method to write to MathML.
How can I tell that an object on a slide is a math formula rather than regular text or an image?
A formula lives in a MathPortion and has a MathParagraph. Images and regular text portions without a MathParagraph are not exportable formulas.
Where does the MathML come from in a presentation—is it PowerPoint-specific or a standard?
The export targets standard MathML (XML). Aspose uses Presentation MathML—the presentation subset of the standard—which is widely used across applications and the web.
Is exporting formulas inside tables, SmartArt, groups, etc., supported?
Yes, if those objects contain text portions with a MathParagraph (i.e., genuine PowerPoint formulas), they are exported. If a formula is embedded as an image, it is not.
Does exporting to MathML modify the original presentation?
No. Writing MathML is a serialization of the formula’s content; it does not modify the presentation file.