Latex expression \int_{a}^{b} x dx in Mathematica - ToExpression+TexForm error

6

1

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.

Gennaro Arguzzi

Posted 2017-10-27T12:17:00.390

Reputation: 709

Answers

9

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"

Carl Woll

Posted 2017-10-27T12:17:00.390

Reputation: 112 778

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. – Gennaro Arguzzi – 2017-10-27T15:03:15.907

3Use 3-arg form of ToExpression, e.g., ToExpression[texString, TeXForm, Hold] – Carl Woll – 2017-10-27T15:12:26.907