Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:10:30+00:00 2026-06-05T14:10:30+00:00

I use MathML to create some data blocks and I need to insert it

  • 0

I use MathML to create some data blocks and I need to insert it throught OpenXML SDK into docx file. I’ve heard it is possible, but I didn’t manage it. Could somebody help me with this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:10:31+00:00Added an answer on June 5, 2026 at 2:10 pm

    As far as I know, the OpenXml SDK does not support presentation MathML out of the box.

    Instead, the OpenXml SDK supports Office MathML.
    So, to insert presentation MathML into a word document we first have
    to transform the presentation MathML into Office MathML.

    Fortunately, Microsoft provides a XSL file (called MML2OMML.xsl) to transform presentation MathML
    into Office MathML. The file MML2OMML.xsl is located under %ProgramFiles%\Microsoft Office\Office12.
    In conjunction with the .Net Framework class
    XslCompiledTransform we are able to transform presentation MathML into Office MathML.

    The next step is to create a OfficeMath object from the transformed MathML.
    The OfficeMath class represents a run containing WordprocessingML which shall be handled as though it was Office Open XML Math.
    For more info please refer to MSDN.

    The presentation MathML does not contain font information. To get a nice result
    we must add font information to the created OfficeMath object.

    In the last step we have to add the OfficeMath object to our word document.
    In the example below I simply search for the first Paragraph in a
    word document called template.docx and add the OfficeMath object to the found paragraph.

    XslCompiledTransform xslTransform = new XslCompiledTransform();
    
    // The MML2OMML.xsl file is located under 
    // %ProgramFiles%\Microsoft Office\Office12\
    xslTransform.Load("MML2OMML.xsl");
    
    // Load the file containing your MathML presentation markup.
    using (XmlReader reader = XmlReader.Create(File.Open("mathML.xml", FileMode.Open)))
    {
      using (MemoryStream ms = new MemoryStream())
      {
        XmlWriterSettings settings = xslTransform.OutputSettings.Clone();
    
        // Configure xml writer to omit xml declaration.
        settings.ConformanceLevel = ConformanceLevel.Fragment;
        settings.OmitXmlDeclaration = true;
    
        XmlWriter xw = XmlWriter.Create(ms, settings);
    
        // Transform our MathML to OfficeMathML
        xslTransform.Transform(reader, xw);
        ms.Seek(0, SeekOrigin.Begin);
    
        StreamReader sr = new StreamReader(ms, Encoding.UTF8);
    
        string officeML = sr.ReadToEnd();
    
        Console.Out.WriteLine(officeML);
    
        // Create a OfficeMath instance from the
        // OfficeMathML xml.
        DocumentFormat.OpenXml.Math.OfficeMath om =
          new DocumentFormat.OpenXml.Math.OfficeMath(officeML);
    
        // Add the OfficeMath instance to our 
        // word template.
        using (WordprocessingDocument wordDoc =
          WordprocessingDocument.Open("template.docx", true))
        {
          DocumentFormat.OpenXml.Wordprocessing.Paragraph par =
            wordDoc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().FirstOrDefault();        
    
          foreach (var currentRun in om.Descendants<DocumentFormat.OpenXml.Math.Run>())
          {
            // Add font information to every run.
            DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties2 =
              new DocumentFormat.OpenXml.Wordprocessing.RunProperties();
    
            RunFonts runFonts2 = new RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" };        
            runProperties2.Append(runFonts2);
    
            currentRun.InsertAt(runProperties2, 0);
          }
    
          par.Append(om);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some mathml markup inside web (html) pages. When I try to use
Use case: we have some project meta-data files which we want tracked, but are
USE AdventureWorks2008R2; GO INSERT INTO myTestSkipField SELECT * FROM OPENROWSET(BULK 'C:\myTestSkipField-c.dat', FORMATFILE='C:\myTestSkipField.fmt' ) AS
Use open syscall to write and create a file ,there's no attributes with the
use C#,want to upload excel file on google doc. bellow syntax use to upload
use strict; use warnings; use Data::Dumper; my %h; my $undef = undef; $h{''}='test2'; $h{$undef}
use LWP::UserAgent; use Data::Dumper; my $ua = new LWP::UserAgent; $ua->agent(AgentName/0.1 . $ua->agent); my $req
There are some sites on the web that render LaTeX into some more readable
use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub {
I'm developing a report in Crystal Reports and need to render some math formulas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.