Recursive AI

Render PowerPoint equations in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Render native PPTX equations (a14:m / m:oMathPara) to PNG with Office.Convert, keeping fractions stacked.

Terminal
dotnet add package RecursiveAI.OneDocument.Rendering

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument;
 
// fraction.pptx is in the download.
Office.Convert("fraction.pptx", "slide.png");
Console.WriteLine("Wrote slide.png");

Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.

Writes the first visible slide to slide.png and prints:

Text
Wrote slide.png

The result has x above 2, with a horizontal fraction bar. This is a crop of the PNG the program writes:

Rendered equation with x stacked over 2 and a horizontal fraction bar

fraction.pptx contains one slide with a text box and no picture of the equation. Here’s the equation inside that text box’s a:p paragraph in ppt/slides/slide1.xml (namespace declarations are on the slide root):

XML
<mc:AlternateContent>
  <mc:Choice Requires="a14">
    <a14:m>
      <m:oMathPara>
        <m:oMath>
          <m:f>
            <m:num>
              <m:r><m:t>x</m:t></m:r>
            </m:num>
            <m:den>
              <m:r><m:t>2</m:t></m:r>
            </m:den>
          </m:f>
        </m:oMath>
      </m:oMathPara>
    </a14:m>
  </mc:Choice>
  <mc:Fallback>
    <a:r><a:t>Fallback text</a:t></a:r>
  </mc:Fallback>
</mc:AlternateContent>

The renderer draws the equation, not the literal “Fallback text”. If your equation is on a hidden slide, the default export skips that slide.

Variations

Keep the equation in a PDF instead. Replace the conversion and print lines:

C#
Office.Convert("fraction.pptx", "slides.pdf");
Console.WriteLine("Wrote slides.pdf");
Text
Wrote slides.pdf

The default PDF export includes all visible slides. In a tagged PDF, the renderer tags the equation as a Formula with its linear form as alternative text.

The short answer

Use Office.Convert from RecursiveAI.OneDocument.Rendering to render the slide that contains the equation. For native Office Math in a PowerPoint text box, OneDocument reads the math in a14:m and paints it in place. Choose .png for the first visible slide or .pdf for the visible deck. You don’t need to extract the XML and draw the fraction yourself.

What are a14:m and m:oMathPara in PPTX slide XML?

a14:m is the PowerPoint drawing extension that wraps native Office Math inside a slide’s text. In the sample it’s inside mc:Choice, the markup branch for readers that understand that extension. m:oMathPara is a math paragraph; it contains an m:oMath equation. A slide can also have m:oMath directly inside a14:m. In the sample, m:f gives the renderer the fraction structure, with separate m:num and m:den elements. The two m:t strings alone don’t tell you which one goes above the bar.

The presentation rendering docs describe the result as one unbreakable inline box on the baseline at the run’s size and color. That’s how slide text handles it even when the wrapper contains m:oMathPara: the renderer places the whole box in the slide’s text flow without breaking the equation over two lines.

Why do equations disappear or look different in exported slides?

Text extraction and rendering serve different tasks. Office.ExtractText returns a linear representation of native math, such as x/2, for text consumers. It doesn’t return the fraction’s visual layout. In a rendered slide, the math layout lays out glyphs and draws rules such as the fraction bar. The linear form in a tagged PDF is alternative text, not a replacement for what’s drawn. The math layout docs explain when that linear form is used.

If you’re troubleshooting a missing equation, first check whether the slide is part of the export: a .png target only writes the first visible slide. Then check what the slide stores. An equation pasted as a screenshot is a picture, not an a14:m math object. An embedded object follows a different path too: OneDocument draws its saved preview if present, not the object itself. The native math path shown here doesn’t need a preview image and doesn’t draw mc:Fallback instead of the equation.

All onedocument recipes