# Awkward output of TeXForm

When I try to format a number that has a big exponent with TeXForm the following happens:

In[1]:= TeXForm[1.543*10^-10 ]

Out[1]//TeXForm=
\text{1.543$\grave{ }$*${}^{\wedge}$-10}


But I would like to get something like 1.543 \cdot 10^{-10}. Is there any workaround for this?

-
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign –  ssch Nov 14 '12 at 14:58

Here is another approach that addresses some issues you may (or may not) encounter: With the built-in formats like ScientificForm, there is an aesthetic problem:

TeXForm[ScientificForm[1.*10^-10]]


1.\times 10^{-10}

Notice that trailing decimal points are printed after machine-precision numbers even when there's no digits to the right.

Also, you wanted a centered dot to represent the multiplication. Both of these issues can be addressed with the following wrapper function:

tF[x_?MachineNumberQ] :=
TeXForm@NumberForm[x,
NumberFormat -> (DisplayForm@
RowBox[Join[{StringTrim[#1, RegularExpression["\\.$"]]}, If[#3 =!= "", {"\[CenterDot]", SuperscriptBox[#2, #3]}, {}]]] &)]  An example is: tF[1.34 10^-10]  1.34\cdot 10^{-10} A slightly different way to implement this would be to declare this as a Format that only kicks in during TeXForm output: Format[tN[x_?MachineNumberQ], TeXForm] := NumberForm[x, NumberFormat -> (DisplayForm@ RowBox[Join[{StringTrim[#1, RegularExpression["\\.$"]]},
If[#3 =!= "", {"\[CenterDot]",
SuperscriptBox[#2, #3]}, {}]]] &)]

Format[tN[x_]] := x


With this, you could wrap any expression you want with the tN function, and it will display as if tN weren't there. But if you apply TeXForm, the output is changed:

tN[1. 10^-10]


$1. \times 10^{-10}$

TeXForm[%]


1\cdot 10^{-10}

The centered dot and the removed decimal point can be seen only in the last line where TeXForm was applied.

It depends on the application whether you would want to use a wrapper with a Format like tN, or a simple conversion function like tF.

The formatting in these wrapper functions relies on NumberForm, and I basically borrowed the function trimPoint from my answer here.

-
One might also consider using MantissaExponent[] for such manipulations... –  Ｊ. Ｍ. Nov 15 '12 at 0:23
That's the same thing that NumberFormat does. Here the main point is that you want the flexibility provided by NumberForm to introduce, e.g., the \cdot multiplication symbol. –  Jens Nov 15 '12 at 3:49
You could use ScientificForm[] for starters:
TeXForm[ScientificForm[1.543*10^-10]]