MathML with missing elements and word document corrupted

Good Morning,

I need some assistance in regards to the API and how Aspose handles MathML in word Documents.
I have compiled a minimalistic case where the equation I am trying to write into the Document produces a corrupt word file (the equation is not displayed as it should and the document behaviour is erroneous)

static String mathML = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"\\begin{array}{l}\\displaystyle "
        + "\\sqrt{(\\hat{r'_k)}}\\end{array}\">\n"
        + "    <mtable columnalign=\"left\" rowspacing=\"4pt\" columnspacing=\"1em\">\n"
        + "        <mtr>\n"
        + "            <mtd>\n"
        + "                <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n"
        + "                    <msqrt>\n"
        + "                        <mo stretchy=\"false\">(</mo>\n"
        + "                        <mrow class=\"MJX-TeXAtom-ORD\">\n"
        + "                            <mover>\n"
        + "                                <mrow>\n"
        + "                                    <msubsup>\n"
        + "                                        <mi>r</mi>\n"
        + "                                        <mi>k</mi>\n"
        + "                                        <mo>′</mo>\n"
        + "                                    </msubsup>\n"
        + "                                    <mo stretchy=\"false\">)</mo>\n"
        + "                                </mrow>\n"
        + "                                <mo stretchy=\"false\">^<!-- ^ --></mo>\n"
        + "                            </mover>\n"
        + "                        </mrow>\n"
        + "                    </msqrt>\n"
        + "                </mstyle>\n"
        + "            </mtd>\n"
        + "        </mtr>\n"
        + "    </mtable>\n"
        + "</math>";



public static void main(String[] args)
{
    // For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
    // The path to the documents directory.
    String dataDir = "./";

    // Load the document.
    Document doc = null;
    try
    {
        doc = new Document();
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }

    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.write("hello world");
    try
    {
        builder.insertHtml(mathML);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }

    try
    {
        doc.save(dataDir + "output.docx");
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}

The Square Root is missing from the equation and if you access the document from production, you can see how the document is corrupted when opening/saving/exiting.

For reference, I have attached the expected equation result as a screenshot :

The latex formula is the following: \sqrt{(\hat{r'_k})}

This is the resulting document in production: Aspose Support-v4-20230419_072251.docx (19.5 KB)

@Mmachado
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25305

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Mmachado We have completed analysis of the issue. The problem occurs because Aspose.Words does not generate an anonymous <mrow> box called the msqrt base for <msqrt> element. If modify the document and enclose all content of <msqrt> into a new <mrow> element, Aspose.Words will import it correctly. Please see the following modified MathML:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="\begin{array}{l}\displaystyle \sqrt{(\hat{r'_k)}}\end{array}">
	<mtable columnalign="left" rowspacing="4pt" columnspacing="1em">
		<mtr>
			<mtd>
				<mstyle displaystyle="true" scriptlevel="0">
					<msqrt>
						<mrow>
							<mo stretchy="false">(</mo>
							<mrow class="MJX-TeXAtom-ORD">
								<mover>
									<mrow>
										<msubsup>
											<mi>r</mi>
											<mi>k</mi>
											<mo>′</mo>
										</msubsup>
										<mo stretchy="false">)</mo>
									</mrow>
									<mo stretchy="false">
										^<!-- ^ -->
									</mo>
								</mover>
							</mrow>
						</mrow>
					</msqrt>
				</mstyle>
			</mtd>
		</mtr>
	</mtable>
</math>

You can use this approach while you are waiting for an actual fix.

Hi,
Thanks for the info @alexey.noskov and the workaround. The MathML is generated via third-party, and since we do not have control over its definitions I think it would be best not to add an edge-case to our code base, specially because according to the MathML Specification, it seems that mrow is inferred as an argument for the this type of element (radical - msqrt).

Thanks again and have a great day.

@Mmachado Thank you for additional information. We will keep you updated and let you know once the issue is resolved.

Good Morning,

Any updates on this issue?

@Mmachado Unfortunately, there are no update regarding the issue. It has been postponed and is not yet scheduled for development. Please accept our apologies for your inconvenience.