I have the following expression

mi></mrow></mfrac><mo> ( </mo><mrow><mo> - 
</mo><mn>5</mn></mrow><msup><mi>x</mi><mn>3</mn></msup><mo> - 
</mo><mn>5</mn><msup><mi>x</mi><mn>2</mn></msup><mo> - 
</mo><mn>3</mn><mi>x</mi><mo> - </mo><mn>4</mn><mo> ) </mo>


Which when I try to run, returns

Failure[ Message: Please enter a valid expression. Tag: Restriction failure]

But when I try it on Wolfram research's online interpreter, it returns fine. What am I doing wrong? (PS I have also tried ToExpression and HoldMathMLExpression--in Interpreter--and had no more luck)

  • $\begingroup$ Your expression should definitely be in a String... is that just a copy-paste error? $\endgroup$ – b3m2a1 Jul 3 '19 at 21:48

ToExpression tries to get an Expression but what you've posted isn't valid Mathematica syntax. You want to use ImportString with "MathML" as the format. See this for more.

mathExpr = "<math>
  <mo> ( </mo>
  <mrow><mo> - 
  <mo> - 
  <mo> - </mo><mn>3</mn><mi>x</mi><mo> - </mo><mn>4</mn>
ImportString[mathExpr, "MathML"] // RawBoxes

enter image description here

| improve this answer | |
  • $\begingroup$ I was missing the raw boxes when I tried earlier. Thank you! $\endgroup$ – Silas K Grossberndt Jul 4 '19 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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