none
using MathML in word add ins Project? RRS feed

  • General discussion

  • hi every one,

    I'm going to build my own equation editor like Word Equation. I searched on the web and I read that it used MathML or Tex languages. I'm using C# word add ins Project. I want to add this MathML code

    <math xmlns="http://www.w3.org/1998/Math/MathML" display="block" dir="rtl"> <mmultiscripts><mo>ل</mo> <mn>12</mn><none/> <mprescripts/> <none/><mn>5</mn> </mmultiscripts> </math>

    to insert arabic symbol in my word add ins project... How can I do this..

    pleaaase help.... :)))

    Sunday, September 30, 2012 4:31 PM

All replies

  • Hi ISE Student

    Word is the only Office application (so far) that will let you insert XML into the opened document. This is done using the InsertXML method and the tricky part is that the XML you pass to the method must be in the valid WordOpenXML "flat file" package format.

    If you create an equation in Word, using Word's tools, then select that part of the text and

    1. Alt+F11 (to open the VBA Editor)
    2. Ctrl+ G (to open the Immediate Window)
    3. Type: ?Selection.WordOpenXML
    4. The press ENTER

    Word will display the WordOpenXML for the current selection in that flat file Word Open XML package format. The XML you use wouldn't need all the namespaces and some of the other stuff, but the basic structures for constructing the package and the document parts for the document as well as any connected with using MathML would be required.

    This should, at least, give you a starting point. Theoretically, you could probably simply substitute your MathML for that in the result...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, October 1, 2012 1:29 PM
    Moderator
  • thanx alot for your answer,

    I tried to use InsertXML method but when I run my project the result of InsertXML method not working well. My code is

    wdFunctionR.Application.Selection.InsertXML(

    " <math xmlns=\"http://www.w3.org/1998/Math/MathML\" ><mmultiscripts><mo>ل</mo><mn>12</mn><none/><mprescripts/><none/><mn>5</mn></mmultiscripts></math>", Type

    .Missing);the result will be: mmultiscripts mo ل mo mn 12 mn none mn 5 mn  ..........it reads XML string as a string and not as  a XML code!!! why?? Sorry but this is the first time for me to deal with XML

    Tuesday, October 2, 2012 8:25 AM
  • Follow the steps I listed in my previous reply to understand what the XML needs to look like.

    Inserting valid WordOpenXML into an open document is not a trivial undertaking, and is also not a topic for the VSTO forum as it has nothing to do with the VSTO technology.

    Your best resource for further assistance is probably OpenXMLDeveloper.org

    But if you've never worked with XML before you have a steep learning curve ahead of you.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 2, 2012 5:46 PM
    Moderator
  • thanx again for your help. I follow the steps you've listed but I didn't understand very well the code. anyway my problem is to get the arabic math symbol in my equation editor. for example the sigma symbol in arabic typed reversed the sigma in english. I've drwan the arabic sigma and added it to word as a picture by this code:

     Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
                Word.Range wdFunctionR = Globals.ThisAddIn.Application.Selection.Range;
                Word.Selection selection = Globals.ThisAddIn.Application.Selection;
                //Get the Path of the picture
                string path;
                path = System.IO.Path.GetDirectoryName(
                   System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                string fpath = "\\images\\sigma.gif";
                string sPath = path + fpath;
                if (selection != null && selection.Range != null)
                {
                  myShape = wdFunctionR.Application.Selection.InlineShapes.AddPicture(sPath, Type.Missing, Type.Missing, Type.Missing).ConvertToShape();
                    myShape.WrapFormat.Type = Word.WdWrapType.wdWrapTight;

    but it doesn't work well as the sigma symbol in the word equation. how can I program arabic sigma . I want a hint. how can we program the sigma symbol?

    thanx for your help again :)

    Wednesday, October 3, 2012 6:42 AM
  • It's really too bad that you didn't continue your discussion on this question with the top-level engineer who was brought in to assist you:
    http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/a012ebf1-ccd6-4051-a043-5cbe968bfca0

    You never answered his question, so the thread was marked as "answered".

    FWIW, if you're not able to create what you want using the Word UI, then it cannot be done using either the object model or XML. Both can only reflect what can be done in the UI.

    It appears that Word does let you insert an InlineShape into an OMath object. I can test that in the UI, and I can do it using a macro:

        Dim rng As word.Range
        Dim ils As word.InlineShape
        
        Set rng = ActiveDocument.OMaths(4).Range
        rng.Collapse wdCollapseStart
        rng.MoveStart wdCharacter, 10
        Set ils = ActiveDocument.InlineShapes.AddPicture("C:\Users\Public\BEta15\DisplayProb.png", , , rng)
    You should be able to convert this to C# with a bit of research...

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 3, 2012 7:32 AM
    Moderator
  • sorry. I tried to create a private character using Private Character Editor as it mention in the

    http://windows.microsoft.com/en-us/windows7/Using-special-characters-Character-Map-frequently-asked-questions

     but it doesn't work!!

    I really don't know where is the problem. when I go to character Map to select the private symol that I've created I don't find it.

    I understood that In Equation word the math symbols are all exits with their unicodes. for ex: the sigma symbol has U + 2211

    and simplly I can insert the sigma symbol by

    wdFunctionR.Application.Selection.TypeText(

    " \u2211");

    but the Sub and the Sup of the symbol how can we program it? it appears like a dot rectangle and this rectangle expand with the user typing. I don't think they have unicode because they are expanding, haven't they?

    Sorry for my questions but I'm really want to develop the word equation to be able For Arabic Mathmatical Symbols :(

    Thursday, October 4, 2012 5:59 AM