# Problem when reading a small number as a LaTeX input

I've got a String variable defined as b="4.0 \cdot 10^{-5}", which is clearly written as LaTeX input.

The problem is that when I want to obtain the expression from it using c=ToExpression[b,TeXForm], I get the following output:

4.\[CenterDot]1/100000.

To avoid that problem, I tried first doing b=StringReplace[b," \cdot " -> "*"] but, if I do that, then the output of the other line of code gets senseless:

9.76563*10^(-9)

Is there another way to deal with this problem with \cdot?

• It's a matter of precedence. TeXForm is interpreting the input as (4.0*10)^{-5}. Sep 21, 2021 at 20:31
• Is there another way to deal with this problem with \cdot? it is better to go back to the source to fix the problem there. What sympy expression did you have that generated \cdot as its Latex translation? Sep 21, 2021 at 20:49
• The number was 4e-5 Sep 21, 2021 at 20:51

You should not really use * in Latex. No one does. This is simply bad latex. How did you generate "4.0 * 10^{-5}" as latex to start with?

Try b = "$4.0 \\times 10^{-5}$" which when compiled in Latex, gives $$4.0 \times 10^{-5}$$

Then now b = ToExpression[b, TeXForm] gives 0.00004 But if you want to keep the form without evaluation, then you can use

b = ToExpression[b, TeXForm, HoldForm] • Oh you are right! I already made some changes actually. I will give all the information about how did I get that variable actually. Maybe there is another way to solve the problem in a straightforward way. Sep 21, 2021 at 20:37
• I edited the question. Do you have any suggestion? \times is not working for me. If I replace \cdot by \times, the \t gets understood as a tabulation by Mathematica. Sep 21, 2021 at 20:49
• @edgardeitor Use \\times instead of \times. Sep 21, 2021 at 20:54
• Yes it should be \\times. bad typing on my part. Any latex command in string should be escaped. Sep 21, 2021 at 20:55
• That works perfect! Sep 21, 2021 at 20:55

It's a bug, but ToExpression["4.0 * 10^{-5}"] works fine. So does ToExpression["4.0 \, 10^{-5}", TeXForm]. Here's what's happening:

Trace@ToExpression["4.0 * 10^{-5}", TeXForm]
(* {ToExpression[4.0 * 10^{-5},TeXForm],1/(4. 10)^5,{4. 10,40.},1/40.^5,9.76563*10^-9} *)