Add Math Equations to PowerPoint Presentations in .NET
Overview
PowerPoint stores equations as Office Math Markup Language (OMML). With Aspose.Slides for .NET, you can create the same kind of math content programmatically: fractions, radicals, functions, limits, N-ary operators, matrices, arrays, and formatted math blocks.
In PowerPoint, users normally add equations from Insert > Equation:

The result is editable math text on the slide:

Aspose.Slides builds that math text through three main objects:
- A math shape, created with AddMathShape, is the shape that contains the equation.
- MathPortion stores math content inside the shape text frame.
- MathParagraph contains one or more MathBlock objects.
Most examples below use MathematicalText and the fluent methods from IMathElement to keep the code short and readable.
For MathML export scenarios, see Export Math Equations from Presentations in .NET.
Create an Equation
This example uses AddMathShape to create a math shape and adds the Pythagorean theorem:

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 120);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var equation = new MathematicalText("c")
.SetSuperscript("2")
.Join("=")
.Join(new MathematicalText("a").SetSuperscript("2"))
.Join("+")
.Join(new MathematicalText("b").SetSuperscript("2"));
mathParagraph.Add(equation);
presentation.Save("pythagorean-theorem.pptx", SaveFormat.Pptx);
Note
AddMathShape creates a shape that already contains a math paragraph. Access the first MathPortion, get its MathParagraph, and add math blocks or math elements to it.Combine Math Blocks
When parts of an equation are built independently as IMathBlock objects, use JoinBlock to combine them. The example builds c² = in the left block and a² + b² in the right block. SetSuperscript creates editable mathematical superscripts for all three powers.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddMathShape(20, 20, 600, 100);
var mathParagraph = ((IMathPortion)shape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var leftBlock = new MathBlock();
leftBlock.Add(new MathematicalText("c").SetSuperscript("2"));
leftBlock.Add(new MathematicalText("="));
var rightBlock = new MathBlock();
rightBlock.Add(new MathematicalText("a").SetSuperscript("2"));
rightBlock.Add(new MathematicalText("+"));
rightBlock.Add(new MathematicalText("b").SetSuperscript("2"));
var combinedBlock = leftBlock.JoinBlock(rightBlock);
mathParagraph.Add(combinedBlock);
presentation.Save("equation.pptx", SaveFormat.Pptx);
JoinBlock returns leftBlock itself, now containing both parts in order, and leaves rightBlock empty. Add the combined block to the IMathParagraph only once. After reopening equation.pptx, the paragraph contains one block representing c² = a² + b², with all three powers preserved as mathematical superscripts.
Calling Add as leftBlock.Add(rightBlock) instead attempts to nest one block directly inside another and throws InvalidOperationException.
Add Fractions
Use Divide to create a fraction. You can choose a fraction style with MathFractionTypes.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var fraction = new MathematicalText("1")
.Divide("x", MathFractionTypes.Skewed);
mathParagraph.Add(new MathBlock(fraction));
presentation.Save("fraction.pptx", SaveFormat.Pptx);
For a stacked fraction, use MathFractionTypes.Bar:
using Aspose.Slides.MathText;
var stackedFraction = new MathematicalText("x + 1").Divide("y - 1", MathFractionTypes.Bar);
Add Radicals
Use Radical to create a square root, cube root, or other root. The current element becomes the base, and the argument becomes the degree.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var radical = new MathematicalText("x")
.Radical("n");
mathParagraph.Add(new MathBlock(radical));
presentation.Save("radical.pptx", SaveFormat.Pptx);
Show or Hide the Degree of a Square Root
A square root can display an explicit 2 or use the conventional √x notation. The HideDegree property of IMathRadical controls which form appears. Both forms retain the degree 2 and the radicand x in the editable equation.

The example saves the same square root twice. In visible-degree.pptx the 2 is visible. In hidden-degree.pptx it is hidden.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var radical = new MathematicalText("x").Radical("2");
var shape = slide.Shapes.AddMathShape(20, 20, 200, 100);
var portion = (IMathPortion)shape.TextFrame.Paragraphs[0].Portions[0];
portion.MathParagraph.Add(new MathBlock(radical));
radical.HideDegree = false;
presentation.Save("visible-degree.pptx", SaveFormat.Pptx);
radical.HideDegree = true;
presentation.Save("hidden-degree.pptx", SaveFormat.Pptx);
Add Functions and Limits
Use AsArgumentOfFunction or Function for functions such as sin(x), log(x), or custom function names. For limits, put lim in a MathLimit or use SetLowerLimit.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var limit = new MathematicalText("lim")
.SetLowerLimit("x→∞")
.Function("x");
mathParagraph.Add(new MathBlock(limit));
presentation.Save("functions-and-limits.pptx", SaveFormat.Pptx);
For a custom function name, make the function name the current element and call Function with its argument:
using Aspose.Slides.MathText;
var customFunction = new MathematicalText("f").Function("x + 1");
Add N-ary Operators and Integrals
Use Nary for summations, unions, intersections, and other large operators. Use Integral for integrals. Both methods let you set lower and upper limits.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 120);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var summationBase = new MathematicalText("x")
.SetSuperscript("k")
.Join(new MathematicalText("a").SetSuperscript("n-k"));
var summation = summationBase.Nary(MathNaryOperatorTypes.Summation, "k=0", "n");
mathParagraph.Add(new MathBlock(summation));
presentation.Save("nary-operators.pptx", SaveFormat.Pptx);
N-ary operators are for large operators with optional limits. Simple operators such as +, -, and = are usually added as MathematicalText and joined into the expression.
For an integral, use Integral:
using Aspose.Slides.MathText;
var integralBase = new MathematicalText("x").Join(new MathematicalText("dx").ToBox());
var integral = integralBase.Integral(MathIntegralTypes.Simple, "0", "1");
Add Matrices
Use MathMatrix for rows and columns. Matrices do not include brackets by default, so enclose the matrix when you need parentheses, brackets, or braces.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 120);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var matrix = new MathMatrix(2, 3);
matrix[0, 0] = new MathematicalText("1");
matrix[0, 1] = new MathematicalText("x");
matrix[1, 0] = new MathematicalText("x");
matrix[1, 1] = new MathematicalText("2");
matrix[1, 2] = new MathematicalText("y");
mathParagraph.Add(new MathBlock(matrix));
presentation.Save("matrix.pptx", SaveFormat.Pptx);
Edit an Existing Matrix
Suppose a linear algebra lesson starts with the coefficient matrix in matrix.pptx, saved by the preceding example. For the next exercise, keep the first equation, replace the second with two new equations, and revise the set of variables. Open the existing matrix through IMathMatrix to keep the coefficients that still apply.

Row and column indices start at zero and refer to the matrix as it stands at each call. Inserting a row before index 1 moves the original second row to index 2. Inserting after index 2 then appends a row. Deleting row 2 removes the original second equation and moves the appended row up one position. Columns shift in the same way.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation("matrix.pptx");
var shape = (IAutoShape)presentation.Slides[0].Shapes[0];
var portion = (IMathPortion)shape.TextFrame.Paragraphs[0].Portions[0];
var matrix = (IMathMatrix)portion.MathParagraph[0][0];
matrix.InsertRowBefore(1);
matrix.InsertRowAfter(2);
matrix.DeleteRow(2);
matrix.InsertColumnBefore(1);
matrix.InsertColumnAfter(3);
matrix.DeleteColumn(3);
// New cells are initially null. Set the nonzero coefficients first.
matrix[1, 0] = new MathematicalText("12");
matrix[1, 1] = new MathematicalText("1");
matrix[2, 2] = new MathematicalText("10");
matrix[2, 3] = new MathematicalText("1");
for (var row = 0; row < matrix.RowCount; row++)
{
for (var column = 0; column < matrix.ColumnCount; column++)
{
matrix[row, column] ??= new MathematicalText("0");
}
}
matrix.SetColumnAlignment(0, MathHorizontalAlignment.Left);
matrix.SetColumnsAlignment(1, 3, MathHorizontalAlignment.Right);
presentation.Save("updated-matrix.pptx", SaveFormat.Pptx);
SetColumnAlignment aligns the first column to the left. SetColumnsAlignment aligns three consecutive columns to the right, starting at index 1. In updated-matrix.pptx, the matrix has three equations and four variables. The original first-row coefficients 1 and x now appear in the first and third columns.

Add Equation Arrays
Use ToMathArray when you need aligned equations or a vertical stack of expressions.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 140);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var equationArray = new MathematicalText("x")
.Join("y")
.ToMathArray();
mathParagraph.Add(new MathBlock(equationArray));
presentation.Save("equation-array.pptx", SaveFormat.Pptx);
Align an Array with Surrounding Elements
IMathArray.BaseJustification controls the vertical alignment of an array relative to the mathematical elements beside it. The example below compares alignment with the first row, the center of the array, and the last row.
The following example creates three identical arrays, each with three rows and the neighboring elements A= and =B. All mathematical text uses Cambria Math at 24 points. Only the array alignment changes.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(780, 200, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];
var alignments = new[] { MathVerticalAlignment.Top, MathVerticalAlignment.Center, MathVerticalAlignment.Bottom };
for (int i = 0; i < alignments.Length; i++)
{
var label = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20 + i * 260, 10, 240, 30);
label.FillFormat.FillType = FillType.NoFill;
label.LineFormat.FillFormat.FillType = FillType.NoFill;
label.TextFrame.Text = alignments[i].ToString();
var labelFormat = label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
labelFormat.FontHeight = 16;
labelFormat.FillFormat.FillType = FillType.Solid;
labelFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Black;
var mathShape = slide.Shapes.AddMathShape(20 + i * 260, 60, 240, 130);
mathShape.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
var mathParagraph = ((IMathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
mathParagraph.Justification = MathJustification.LeftJustified;
var rows = new IMathElement[] { CreateText("x+y=3"), CreateText("x-y=1"), CreateText("x=2") };
var equationArray = new MathArray(rows);
equationArray.BaseJustification = alignments[i];
var equation = new MathBlock(CreateText("A=")).Join(equationArray).Join(CreateText("=B"));
mathParagraph.Add(equation);
}
presentation.Save("equation-array-alignment.pptx", SaveFormat.Pptx);
MathematicalText CreateText(string value)
{
var text = new MathematicalText(value);
text.Format.FontHeight = 24;
text.Format.LatinFont = new FontData("Cambria Math");
return text;
}
The following comparison shows the saved presentation in PowerPoint. Notice the position of A= and =B beside each array.

Configure Row Spacing
RowSpacingRule selects the spacing rule for rows within the array. RowSpacing supplies a numeric value for an explicit spacing rule and is ignored by the preset rules.
For exact spacing, the value is measured in points. For proportional spacing, it is measured in half-lines: the value 3 in the example specifies 1.5 lines. Set both properties when specifying an explicit value; changing the numeric value alone does not select a spacing rule.
The example below saves five presentations with the same equations, alignment, and font settings. The first three use presets; the last two show explicit values.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
var settings = new (MathRowSpacingRule Rule, uint Spacing)[]
{
(MathRowSpacingRule.SingleLineGap, 0),
(MathRowSpacingRule.OneAndAHalfLineGap, 0),
(MathRowSpacingRule.TwoLineGap, 0),
(MathRowSpacingRule.Exactly, 20),
(MathRowSpacingRule.Multiple, 3)
};
foreach (var setting in settings)
{
var fileName = $"equation-array-{setting.Rule}.pptx";
using (var presentation = new Presentation())
{
var mathShape = presentation.Slides[0].Shapes.AddMathShape(20, 20, 600, 300);
var paragraph = mathShape.TextFrame.Paragraphs[0];
paragraph.ParagraphFormat.SpaceBefore = 0;
paragraph.ParagraphFormat.SpaceAfter = 0;
var mathParagraph = ((IMathPortion)paragraph.Portions[0]).MathParagraph;
mathParagraph.Justification = MathJustification.LeftJustified;
var rows = new IMathElement[] { CreateText("x+y=3"), CreateText("x-y=1"), CreateText("x=2") };
var equationArray = new MathArray(rows);
equationArray.BaseJustification = MathVerticalAlignment.Center;
equationArray.RowSpacingRule = setting.Rule;
equationArray.RowSpacing = setting.Spacing;
var equation = new MathBlock(CreateText("A=")).Join(equationArray).Join(CreateText("=B"));
mathParagraph.Add(equation);
presentation.Save(fileName, SaveFormat.Pptx);
}
}
MathematicalText CreateText(string value)
{
var text = new MathematicalText(value);
text.Format.FontHeight = 24;
text.Format.LatinFont = new FontData("Cambria Math");
return text;
}
Array row spacing is separate from paragraph spacing. SpaceBefore and SpaceAfter add space around the containing paragraph, not between array rows. Likewise, IMathParagraph.Justification positions the whole math paragraph horizontally; it does not replace the array’s vertical alignment setting.
Add Trigonometric Functions
Use AsArgumentOfFunction when the argument is the current element and the function name is known.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var cosine = new MathematicalText("2x")
.AsArgumentOfFunction(MathFunctionsOfOneArgument.Cos);
mathParagraph.Add(new MathBlock(cosine));
presentation.Save("trigonometric-function.pptx", SaveFormat.Pptx);
Add Subscripts and Superscripts
Use the subscript and superscript helpers for indexes and powers. When the indexes must appear on the left side of the base, use SetSubSuperscriptOnTheLeft.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var scripts = new MathematicalText("Y")
.SetSubSuperscriptOnTheLeft("1", "n");
mathParagraph.Add(new MathBlock(scripts));
presentation.Save("subscript-superscript.pptx", SaveFormat.Pptx);
Align Right Subscripts and Superscripts
When both scripts belong to the same base, use MathRightSubSuperscriptElement. Its AlignScripts property controls their horizontal positions: false (the default) lets them follow the contour of the base, while true aligns the scripts horizontally with each other.
This example places two copies of the same editable expression side by side. Both use mathematical italic f (U+1D453), a lower script of 1, an upper script of 2, and Cambria Math at 72 points. The sloping base makes the difference visible in PowerPoint. Install Cambria Math before running the example.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(900, 250, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];
var format = new PortionFormat
{
FontHeight = 72,
LatinFont = new FontData("Cambria Math")
};
for (var i = 0; i < 2; i++)
{
var left = 40 + i * 440;
var shape = slide.Shapes.AddMathShape(left, 75, 380, 150);
var baseText = new MathematicalText("\U0001D453", format);
var subscript = new MathematicalText("1", format);
var superscript = new MathematicalText("2", format);
var scripts = new MathRightSubSuperscriptElement(baseText, subscript, superscript);
scripts.AlignScripts = i == 1;
var portion = (MathPortion)shape.TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FontHeight = format.FontHeight;
portion.PortionFormat.LatinFont = format.LatinFont;
portion.MathParagraph.Add(new MathBlock(scripts));
}
presentation.Save("aligned-scripts.pptx", SaveFormat.Pptx);

On the left, the lower script starts farther left than the upper script, following the base contour. On the right, the two scripts align horizontally with each other.
Add Delimiters
Use Enclose to put an expression inside delimiters. You can also set a separator character for delimiter expressions that contain several elements.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var delimiter = new MathematicalText("x")
.Join("y")
.Join("z")
.Enclose('<', '>');
delimiter.SeparatorCharacter = '|';
mathParagraph.Add(new MathBlock(delimiter));
presentation.Save("delimiters.pptx", SaveFormat.Pptx);
Size and Align Delimiters
Set GrowToMatchOperandHeight to true to let the parentheses grow around a tall operand, or to false to keep them at their normal size. DelimiterShape takes one of two MathDelimiterShape values. Centered centers the parentheses on the math axis, which runs through the middle of the equals sign. Match aligns them with the enclosed content. Both settings affect only the delimiters. The expression inside stays the same.
The example places a fraction in the exponent of x so the expression extends farther above the baseline than below it. All four equations use the same parentheses and font settings.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
void AddExpression(float left, float top, bool grow, MathDelimiterShape shape)
{
var fraction = new MathematicalText("a + b").Divide("c + d");
var power = new MathematicalText("x").SetSuperscript(fraction);
var delimiter = power.Enclose('(', ')');
delimiter.GrowToMatchOperandHeight = grow;
delimiter.DelimiterShape = shape;
var mathShape = slide.Shapes.AddMathShape(left, top, 300, 100);
var portion = (MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FontHeight = 32;
var equation = new MathematicalText("y = ").Join(delimiter);
portion.MathParagraph.Add(equation);
}
AddExpression(20, 20, true, MathDelimiterShape.Centered);
AddExpression(350, 20, true, MathDelimiterShape.Match);
AddExpression(20, 140, false, MathDelimiterShape.Centered);
AddExpression(350, 140, false, MathDelimiterShape.Match);
presentation.Save("delimiter-sizing.pptx", SaveFormat.Pptx);
In PowerPoint, compare the rows to see the effect of growth. In the top row, the parentheses grow to enclose the exponent and look alike for both shapes. In the bottom row, growth is off. The smaller parentheses on the left (Centered) align with the equals sign, while those on the right (Match) sit higher around the expression.

Add a Border Box
Call ToBorderBox on a fraction to frame the entire expression. The returned IMathBorderBox shows all four sides by default. Use HideTop, HideBottom, HideLeft, and HideRight to remove individual sides.
The example places six copies of the same fraction on one slide. To show cancellation, hide all four sides and set StrikethroughBottomLeftToTopRight for a rising diagonal (↗) or StrikethroughTopLeftToBottomRight for a falling diagonal (↘). You can also use StrikethroughHorizontal or StrikethroughVertical with any combination of visible sides.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(540, 220, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];
IMathBorderBox AddFraction(float x, float y, bool hideBorder = false)
{
var fraction = new MathematicalText("x+1").Divide("y+2");
var box = fraction.ToBorderBox();
box.HideTop = box.HideBottom = box.HideLeft = box.HideRight = hideBorder;
var shape = slide.Shapes.AddMathShape(x, y, 160, 90);
var portion = (MathPortion)shape.TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FontHeight = 28;
portion.MathParagraph.Add(new MathBlock(box));
return box;
}
AddFraction(10, 10);
var partial = AddFraction(190, 10);
partial.HideTop = true;
partial.HideRight = true;
AddFraction(370, 10, hideBorder: true).StrikethroughBottomLeftToTopRight = true;
AddFraction(10, 120, hideBorder: true).StrikethroughTopLeftToBottomRight = true;
AddFraction(190, 120, hideBorder: true).StrikethroughHorizontal = true;
AddFraction(370, 120).StrikethroughVertical = true;
presentation.Save("border-box.pptx", SaveFormat.Pptx);

On this fraction, the horizontal strike overlaps the fraction bar. The vertical strike crosses both the numerator and the denominator while the surrounding border stays visible. These lines decorate the whole expression. Ordinary text strikethrough applies to characters in a text run. After reopening the presentation in PowerPoint, you can still edit the numerator and denominator independently.
Control Visibility and Layout with Phantom Elements
Wrap an expression in MathPhantom to control its visibility and the space it contributes to an equation independently. The IMathPhantom properties control the following:
| Property | Effect |
|---|---|
| Show | Set to false to hide the expression. Its dimensions still contribute to layout unless the corresponding properties below are true. |
| ZeroWidth | Treat the expression’s horizontal width as zero, allowing neighboring elements to move closer together. |
| ZeroAsc | Treat its ascent, the height above the baseline, as zero. This can reduce the space reserved above neighboring elements. |
| ZeroDesc | Treat its descent, the depth below the baseline, as zero. This can move a fraction bar or other content below the expression closer to its neighbors. |
The baseline is the reference line on which ordinary mathematical letters sit. Hiding content does not remove its dimensions, and treating a dimension as zero does not delete the expression. The underlying expression remains available through Base. Set Show back to true to display it again; the dimension settings remain unchanged.
The example below creates five side-by-side variants: a visible fraction, a hidden fraction that reserves space, and three hidden fractions with one dimension treated as zero. Each variant uses the same surrounding expression and Cambria Math at 24 points. All equation shapes have the same top position, marked by the gray guide. Placing the phantom in the numerator of an outer fraction makes the vertical layout changes easier to see.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
presentation.SlideSize.SetSize(1000, 180, SlideSizeScaleType.DoNotScale);
var slide = presentation.Slides[0];
var labels = new[] { "Visible", "Hidden: reserves space", "Hidden: ZeroWidth", "Hidden: ZeroAsc", "Hidden: ZeroDesc" };
var guide = slide.Shapes.AddAutoShape(ShapeType.Line, 10, 60, 980, 0);
guide.LineFormat.FillFormat.FillType = FillType.Solid;
guide.LineFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.LightGray;
for (var i = 0; i < labels.Length; i++)
{
var left = 10 + i * 200;
var label = slide.Shapes.AddAutoShape(ShapeType.Rectangle, left, 10, 190, 30);
label.FillFormat.FillType = FillType.NoFill;
label.LineFormat.FillFormat.FillType = FillType.NoFill;
label.TextFrame.Text = labels[i];
var labelFormat = label.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
labelFormat.FontHeight = 14;
labelFormat.FillFormat.FillType = FillType.Solid;
labelFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Black;
var fraction = new MathFraction(CreateText("a+b"), CreateText("c+d"));
var phantom = new MathPhantom(fraction);
phantom.Show = i == 0;
phantom.ZeroWidth = i == 2;
phantom.ZeroAsc = i == 3;
phantom.ZeroDesc = i == 4;
var numerator = new MathBlock(CreateText("x+")).Join(phantom).Join(CreateText("+y"));
var equation = new MathFraction(numerator, CreateText("z"));
var shape = slide.Shapes.AddMathShape(left, 60, 190, 100);
shape.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
var mathParagraph = ((IMathPortion)shape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
mathParagraph.Add(new MathBlock(equation));
}
presentation.Save("math-phantom.pptx", SaveFormat.Pptx);
MathematicalText CreateText(string value)
{
var text = new MathematicalText(value);
text.Format.FontHeight = 24;
text.Format.LatinFont = new FontData("Cambria Math");
return text;
}

Group Terms
Use Group to place a grouping character above or below an expression. Add a limit to label the grouped terms.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 120);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var grouped = new MathematicalText("x + y")
.Group('\u23DF', MathTopBotPositions.Bottom, MathTopBotPositions.Top)
.SetLowerLimit("any text");
mathParagraph.Add(new MathBlock(grouped));
presentation.Save("grouped-terms.pptx", SaveFormat.Pptx);
Format Math Elements
Use formatting helpers only where they clarify the formula. For example, Overbar places a bar above a math element.

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var mathShape = slide.Shapes.AddMathShape(20, 20, 700, 100);
var mathParagraph = ((MathPortion)mathShape.TextFrame.Paragraphs[0].Portions[0]).MathParagraph;
var overbar = new MathematicalText("ABC").Overbar();
mathParagraph.Add(new MathBlock(overbar));
presentation.Save("overbar.pptx", SaveFormat.Pptx);
Format Text in an Existing Equation
To format text throughout an existing equation, traverse each math block’s element tree. IMathElement.GetChildren returns only the immediate children, so call it recursively to reach text inside fractions, scripts, radicals, and other nested structures. Check the current element as well as its children to include the starting element when it is MathematicalText.
This example assumes that a presentation contains an equation such as z = xᵢ / ∛y, with a fraction containing a subscript in its numerator and a radical in its denominator. Processing only the block’s top-level elements would miss the text inside the fraction. The example finds mathematical portions in slide text frames, accesses their blocks through IMathPortion.MathParagraph, and sets FontHeight to 28 points through each text element’s Format property.
using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.MathText;
using var presentation = new Presentation("input.pptx");
foreach (var slide in presentation.Slides)
{
foreach (var shape in slide.Shapes)
{
if (shape is not IAutoShape autoShape || autoShape.TextFrame == null)
continue;
foreach (var paragraph in autoShape.TextFrame.Paragraphs)
{
foreach (var portion in paragraph.Portions)
{
if (portion is IMathPortion mathPortion)
{
foreach (var block in mathPortion.MathParagraph)
FormatMathText(block);
}
}
}
}
}
presentation.Save("formatted-equations.pptx", SaveFormat.Pptx);
void FormatMathText(IMathElement element)
{
if (element is MathematicalText text)
text.Format.FontHeight = 28;
foreach (var child in element.GetChildren())
FormatMathText(child);
}
The saved presentation contains the updated text formatting at every level of each processed equation, while preserving its text content and mathematical structure.
Quick Reference
| Task | Main API |
|---|---|
| Create math text | MathematicalText |
| Combine elements | IMathElement.Join |
| Create fractions | IMathElement.Divide |
| Add superscript or subscript | SetSuperscript, SetSubscript |
| Add functions | Function, AsArgumentOfFunction |
| Add radicals | IMathElement.Radical |
| Add limits | SetLowerLimit, SetUpperLimit |
| Add left-side scripts | SetSubSuperscriptOnTheLeft |
| Add summations and integrals | Nary, Integral |
| Add matrices | MathMatrix |
| Add equation arrays | ToMathArray |
| Add delimiters | Enclose |
| Add bars and borders | Overbar, ToBorderBox |
| Group terms | Group |
FAQ
Can I edit an existing PowerPoint equation?
Yes. Open the presentation, find the shape that contains a MathPortion, get its MathParagraph, and update the math blocks in that paragraph.
Are equations saved as editable PowerPoint math?
Yes. When you save to PPTX, Aspose.Slides writes the equation as editable Office math content.
Can I export equations to LaTeX?
Yes. Get the equation’s IMathParagraph from its MathPortion, and call IMathParagraph.ToLatex to export it directly. For a complete example, see Export Math Equations from Presentations in .NET.