2
$\begingroup$

Please help me with the following problem:

TeXForm[2/3]

The Answer is correct:

"\frac{2}{3}"

I don't understand why Mathematica gives me a wrong inverse:

ToExpression["\frac{2}{3}", TeXForm]

The Answer is:

23 a c r
$\endgroup$
3
  • $\begingroup$ You should escape "\" by second "\": ToExpression["\\frac{2}{3}", TeXForm] $\endgroup$
    – ybeltukov
    Feb 27, 2015 at 18:53
  • $\begingroup$ Thank you very much. Now it works fine :) $\endgroup$
    – Darek
    Feb 27, 2015 at 20:41
  • $\begingroup$ I can't find that it is duplicate, so I post it as an answer to avoid unanswered questions. $\endgroup$
    – ybeltukov
    Feb 27, 2015 at 21:02

1 Answer 1

1
$\begingroup$

You should escape "\" by second "\"

ToExpression["\\frac{2}{3}", TeXForm]

To avoid this problem, produce strings explicitly. Copy-pasted text from the TeXForm is designed for an external TeX editor

ToString[2/3, TeXForm]
(* "\\frac{2}{3}" *)
$\endgroup$

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