TransWikia.com

Converting $LaTeX$ expression in Mathematica -- strange result

Mathematica Asked on April 4, 2021

I tried to convert a $LaTeX$ expression in Mathematica, but it shows me a strange result (it shows a strange word: "ghit").

ToExpression["frac{s + k_{12} + k_{02}}
 {V_1 left[ s^2 + s left(  k_{12} + k_{02} + k_{21} + k_{01} r
ight)  + left(  k_{21} , k_{02} + k_{01} , k_{12} + k_{01} , 
k_{02} right) right] }", TeXForm]

enter image description here

Thank you for your help.

One Answer

Backslashes, i.e. , must be escaped in Mathematica strings.

This is incorrect syntax:

"xyz"

The correct syntax is

"xyz"

Unfortunately, Mathematica tries to be "user-friendly" and when using the notebook interface, it accepts "xyz" without complaint. (If using the terminal, it at least shows a warning.) This creates the false impression that it's fine to do this. It's not. Sequences like r (which you used), b, f, n, etc. have special meanings. New escape sequences may also be added in the future, breaking code like "xyz".

Thus: always, always escape backslashes in strings!.

str = "frac{s + k_{12} + k_{02}}{V_1 left[ s^2 + s left(  k_{12} + k_{02} + k_{21} + k_{01} right)  + left(  k_{21} , k_{02} + k_{01} , k_{12} + k_{01} , k_{02} right) right] }";

ToExpression[str, TeXForm]

enter image description here

Correct answer by Szabolcs on April 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP