0
$\begingroup$

I have a problem where if I multiply two variables a c in Mathematica, then copy as LaTeX (or just use the Mathematica output) to get a c, then put it in ToExpression["a c",TeXForm], I get ac i.e. a new variable called ac not my original a c. But putting in 4 a c for example gives the expected output.

a=...
c=...
test1=a c
a c
test2=ToExpression["a c",TeXForm]
ac
test3=4 a c
4 a c
test4=ToExpression["4 a c",TeXForm]
4 a c

a=1
c=2
N[test1]
2.
N[test2]
ac
N[test3]
8.
N[test4]
8.

Ideally I would like to put a very big expression from Mathematica into Latex, make some edits in Latex to make it more readable, then put it back into Mathematica and put dummy values in to make sure my edits were all mathematically correct. I am also not sure what the . means in the 2. and 8. and would like to know. I am using Mathematica version 12.1 student edition but got the same result on Mathematica 11.3 student version.

I have tried putting in HoldForm and get the same result. I have also tried other pairs of letters and they all give the same result. I haven't tried this on another device yet so maybe it's just my computer. I can't believe that if this is a bug, it hasn't been detected sooner due to how simple this is so can only assume I've done something wrong.

So my question is what is wrong with my code? If nothing is wrong and this is just a quirk/bug of Mathematica then is there another way I can export from LaTeX to Mathematica and preserve correctness?

Any help would be appreciated thanks.

$\endgroup$
3
  • 3
    $\begingroup$ I would like to put a very big expression from Mathematica into Latex, make some edits in Latex to make it more readable, then put it back into Mathematica and put dummy values in to make sure my edits were all mathematically correct. even if this could be made to work, it is not a good way to program. You should just use normal Mathematica code and concentrate on that. Its output cells are pretty clear and easy to read as is. You could always use TraditionalForm if you want for output. At the end, if you want Latex, use TeXForm. Just my 2 cents advice. $\endgroup$
    – Nasser
    Mar 10, 2022 at 17:17
  • $\begingroup$ The mathematica N function attempts to turn an exact integer or rational expression into a machine precision floating point decimal expression. N[2] turns the exact integer 2 into the decimal floating point approximate 2.000000 Try N[113/728] and see that it becomes a decimal number with a . in it. Likewise N[128/4] Mathematica sometimes handles approximate decimal numbers differently from exact integer or rational numbers which have no . $\endgroup$
    – Bill
    Mar 10, 2022 at 17:33
  • $\begingroup$ Thank you to Nasser and Bill; very helpful comments. Still not sure why the LaTeX to Mathematica function would act like this, but I can just bypass this and do the edits in Mathematica as Nasser says then transfer to LateX. $\endgroup$
    – Tom00496
    Mar 11, 2022 at 12:57

0

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.

Browse other questions tagged or ask your own question.