3
$\begingroup$

I do not see how to remove <annotation encoding='Mathematica' from generated MathML. Afaict it is not needed for a one way conversion and it often doubles the size of generated MathML.

How to do this quickly?

Shouldn't "Annotations"->{} option handle this?

(mathml = ExportString[Column@List@f[x], "MathML", "Annotations" -> {}]) // AbsoluteTiming // Column
0.0025588
<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <semantics>
  ....
  <annotation encoding='Mathematica'>TagBox[...</annotation>  (*THIS is a waste of space for me*)
 </semantics>
</math>

I can mathml->XMLElement->DeleteCase->ExportString but then the procedure takes +500% of time for something that could've been just dropped before.

mathml // 
  ImportString[#, "XMLElement"] & // 
  DeleteCases[#, XMLElement["annotation", ___], \[Infinity]] & // 
  ExportString[#, "XML"] & // 
  AbsoluteTiming // Column
0.0108532
<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <semantics>
  ...
 </semantics>
</math>
$\endgroup$
3
  • $\begingroup$ Back to working on M2MD? $\endgroup$
    – Szabolcs
    Commented Jul 21, 2020 at 6:59
  • $\begingroup$ @Szabolcs yes a little but this question originated completely independently. :) $\endgroup$
    – Kuba
    Commented Jul 21, 2020 at 7:01
  • $\begingroup$ There are the Presentation and Content options. Naively, I would have thought that this falls under "content" and therefore should not be generated at all with "Content"->False (the default). I might be mistaken. but this is definitely not something to be displayed ... $\endgroup$
    – Szabolcs
    Commented Jul 21, 2020 at 7:08

1 Answer 1

3
$\begingroup$

Trace reveals that XML`MathML`BoxesToSymbolicMathML is used under the hood and it has an "IncludeMarkupAnnotations" option which seems to do the job:

ExportString[Column@List@f[x], "MathML",  "IncludeMarkupAnnotations" -> False]
<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <mtable>
  <mtr>
   <mtd>
    <mrow>
     <mi>f</mi>
     <mo>&#8289;</mo>
     <mo>(</mo>
     <mi>x</mi>
     <mo>)</mo>
    </mrow>
   </mtd>
  </mtr>
 </mtable>
</math>
$\endgroup$
2
  • 2
    $\begingroup$ This option is documented in XML/tutorial/MathML. (I find it by searching IncludeMarkupAnnotations in the document, strangely the page is not linked to ref/format/MathML. ) $\endgroup$
    – xzczd
    Commented Jul 21, 2020 at 7:34
  • $\begingroup$ @xzczd thanks. {format}+F1 is my goto when I convert something so I expected it there. $\endgroup$
    – Kuba
    Commented Jul 21, 2020 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.