7
$\begingroup$

I am having trouble entering equations in TeX form. I have actually tried a bunch of different equations and gotten similar errors. For example:

ToExpression["\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt\\pi}2",TeXForm]

enter image description here

$\endgroup$
3
  • $\begingroup$ You need to add a thin space before the dx: ToExpression["\\int_0^\\infty e^{-x^2}\\,dx = \\frac{\\sqrt\\pi}2",TeXForm]. $\endgroup$ Sep 25, 2015 at 4:21
  • $\begingroup$ @SimonRochester When I do that it returns a "ConditionalExpression", a completely wrong interpretation of the TeX string which should be an integral. $\endgroup$ Sep 25, 2015 at 4:40
  • $\begingroup$ Mathematica is doing the integral, with the e interpreted as an arbitrary variable. Change the e to E and Mathematica will verify your equation. $\endgroup$ Sep 25, 2015 at 4:45

1 Answer 1

9
$\begingroup$

You can get your equation in unevaluated form using

ToExpression["\\int_0^\\infty E^{-x^2}\\,dx = \\frac{\\sqrt\\pi}2", TeXForm, HoldForm]

which wraps the expression in HoldForm before evaluation. Note the thin space before dx, which is needed for Mathematica to properly interpret the integral syntax, and the capital E.

ToExpression["{HoldForm}[\\int_0^\\infty E^{-x^2}\\,dx = \\frac{\\sqrt\\pi}2]", TeXForm]

also works to get the held form.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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