I tried to convert a Latex expression to Mathematica in this way:

ToExpression["\\int_{a}^{b}{x dx}", TeXForm]

Mathematica gives me an error. How can I get the correct expression in Mathematica?

Thank very much for your time.


1 Answer 1


Mathematica is expecting a space between the integrand and the $dx$. So, the following works:

ToExpression["\\int_{a}^{b} x \\, dx", TeXForm]

-(a^2/2) + b^2/2

You could see what kind of TeXForm should work by doing the reverse:

ToString[ Unevaluated[Integrate[x, {x, a, b}]], TeXForm ]

"\int_a^b x \, dx"

  • $\begingroup$ Hello @CarlWoll. Is it also possible to get the unevaluated expression? I tried with ToExpression[Unevaluated["\\int_{a}^{b} x \\, dx"], TeXForm], but my statement is blatantly wrong. $\endgroup$ Oct 27, 2017 at 15:03
  • 3
    $\begingroup$ Use 3-arg form of ToExpression, e.g., ToExpression[texString, TeXForm, Hold] $\endgroup$
    – Carl Woll
    Oct 27, 2017 at 15:12

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.