6
$\begingroup$

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.

$\endgroup$
9
$\begingroup$

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"

$\endgroup$
  • $\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$ – Gennaro Arguzzi Oct 27 '17 at 15:03
  • 3
    $\begingroup$ Use 3-arg form of ToExpression, e.g., ToExpression[texString, TeXForm, Hold] $\endgroup$ – Carl Woll Oct 27 '17 at 15:12

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.