# Copy as LaTex while maintaining SetPrecision?

I am working with large tables of numbers, where the numbers can have as many as 10 decimal points. To make the work more presentable, I use

SetOptions[SelectedNotebook[], PrintPrecision -> 5]


However, I now need to copy these tables into a LaTex file. "Copy as LaTex" prints the tables well but with the full numbers, up to the 10th decimal place. Is there a way to copy these numbers to a set decimal place (i.e. up to only the 5th decimal place)?

Thanks!

• Are the numbers machine numbers or extended precision numbers? If they are extended precision numbers, then it is expected that all digits are displayed. Feb 10, 2021 at 17:28

PrintPrecision is used for display in a notebook, and the conversion to TeX is happening outside the notebook. It may not be possible to use it to control the conversion to TeX. For instance, the box form in a notebook contains the full form of real numbers, even though only usually six digits are displayed.

Setting the Precision of a number will control how many digits are displayed, as the precision of a number is stored in a number and may be accessed when converting it to boxes or TeX. Maybe one of these will work.

TeXForm[tab /. x_Real :> SetPrecision[x, 5]]
TeXForm[Map[SetPrecision[#, 5] &, tab, {2}]]

\left(
$$\begin{array}{ccc} > 0.66667 & 1.0513 & 1.4359 \\ > 0.95238 & 1.3370 & 1.7216 \\ > 1.2381 & 1.6227 & 2.0073 \\ > 1.5238 & 1.9084 & 2.2930 \\ > 1.8095 & 2.1941 & 2.5788 \\ > \end{array}$$
\right)


Alternatively, you can leave off the TeXForm and convert the output cell with "Copy as LaTeX".

• Brain is still sleepy. SetPrecision[tab, 5] will work on a table of real numbers. Feb 10, 2021 at 15:07
• Thank you so much! Option 2 worked perfectly, even with my imaginary numbers. ^-^ Feb 10, 2021 at 19:02
• @PhysicsHobbit For real & complex values, x_Real | x_Complex :> SetPrecision[x, 5] should work. The alternatives do slightly different things. You probably wouldn't want to use SetPrecision on Integer entries and get 1.0000 instead of 1. There might be other fine tuning needed for tables, depending on what kind of entries they have. (This comment is partly for future visitors who might want to adapt one of these approaches.) Feb 10, 2021 at 21:15