4
$\begingroup$

I have a matrix

M = {{-2.78787*10^-6, 0, 0}, {0, 0.00074904, 0}, {0, 0, -0.119373}};

which I'm converting into ScientificForm, with 3 digits precision

ScientificForm[M, 3]
(* {{-2.79*10^(-6),0,0}, {0,7.49*10^(-4),0}, {0,0,-1.19*10^(-1)}} *)

I would like to copy this exact form as a $\LaTeX$ code. Unfortunately, copying as $\LaTeX$ yields

$$ \left( \begin{array}{ccc} -\text{2.7878728277032345$\grave{ }$*${}^{\wedge}$-6} & 0 & 0 \\ 0 & 0.00074904 & 0 \\ 0 & 0 & -0.119373 \\ \end{array} \right)$$

instead of the nice ScientificForm.

$\endgroup$
4
$\begingroup$

Use TeXForm instead of "Copy as LaTeX"

TeXForm[ScientificForm[M, 3]]
(* \left(
\begin{array}{ccc}
 -2.79\times 10^{-6} & 0 & 0 \\
 0 & 7.49\times 10^{-4} & 0 \\
 0 & 0 & -1.19\times 10^{-1} \\
\end{array}
\right) *)

which, when rendered in LaTeX, gives

$$ \left( \begin{array}{ccc} -2.79\times 10^{-6} & 0 & 0 \\ 0 & 7.49\times 10^{-4} & 0 \\ 0 & 0 & -1.19\times 10^{-1} \\ \end{array} \right) $$

One problem you may have is if you had your zeros defined numerically, in which case you get ugly trailing decimal places,

M = {{-2.78787*10^-6, 0.0, 0.0}, {0.0, 0.00074904, 0.0}, {0.0, 
     0.0, -0.119373}};
TeXForm[ScientificForm[M, 3]]

$$\left( \begin{array}{ccc} -2.79\times 10^{-6} & 0. & 0. \\ 0. & 7.49\times 10^{-4} & 0. \\ 0. & 0. & -1.19\times 10^{-1} \\ \end{array} \right)$$

A simple application of Chop works in that case: TeXForm[ScientificForm[Chop@M, 3]]. If you have numbers like 1.0 that you would prefer to be 1 then you need to follow Jens's answer here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.