0
$\begingroup$

My code for parsing MathML to be readable in Mathematica:

ToExpression @ ImportString @ ExportString[#, "XML"]& /@ Cases[
  xml, XMLElement["math", _, _],∞
] 

The MathML contents:

<math xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
          <ci> MM_e</ci>
          <ci> mem </ci>
          <ci> k </ci>
          <ci> sp_3 </ci>
          <ci> sp_1 </ci>
          <ci> Km </ci>
          </apply>
      </math>

I am getting this error when extracting MathML from a XML file. :

ToExpression::esntx: Could not parse FormBox[TagBox[RowBox[{MM_e,RowBox[{(,RowBox[{<<9>>}],)}]}],MathMLContentTag,AutoDelete->True],TraditionalForm] as input.

The math should display like this:

MM_e(mem,k,sp_3,sp_1,Km)

But it only displays somewhat correctly when I copy MathML content to Mathematica which then asks

"Do you want to paste the typeset expression?"

MM_e(mem,k,3 sp_,1 sp_,Km)

Although when using DisplayForm there are no errors but with other math content, it does not simplify unless I use Shift+Enter on the output.

DisplayForm @ ImportString @ ExportString[#, "XML"] & /@ Cases[ 
  xml, XMLElement["math", _, _], ∞
]

How can I fix this error without using DisplayForm?

$\endgroup$
4
  • $\begingroup$ There is no expression behind this so keeping it in boxes makes more sense. Why isn't DisplayForm ok? You can replace it with RawBoxes but that does not change much. $\endgroup$
    – Kuba
    Jan 16, 2018 at 23:14
  • $\begingroup$ DisplayForm does not simplify unless I use Shift+Enter on the output. RawBoxes gives me other errors with other examples. $\endgroup$ Jan 17, 2018 at 0:04
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Jan 17, 2018 at 0:34
  • $\begingroup$ What do you mean by simplify of MM_e(mem,k,3 sp_,1 sp_,Km) which is not a valid Mathematica syntax? $\endgroup$
    – Kuba
    Jan 17, 2018 at 17:27

1 Answer 1

0
$\begingroup$

The problem was with the underscore symbol. I fixed it by changing it to another symbol [LetterSpace] and Math displays perfectly.

$\endgroup$

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.