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.