In [16]:
import pytex
import numpy as np
from IPython.core.display import Latex

# make sympy equations pretty
from sympy.interactive import printing
printing.init_printing(use_latex=True)

In [17]:
(pytex.magnitude(4), 
 pytex.magnitude(-.04), 
 pytex.magnitude(-499))


Out[17]:
$$\left ( 0, \quad -2, \quad 2\right )$$

In [18]:
# calculate magnitude to which error will be rounded
(pytex.prec_by_err(0.29), 
 pytex.prec_by_err(0.31), 
 pytex.prec_by_err(100))


Out[18]:
$$\left ( -2, \quad -1, \quad 1\right )$$

In [19]:
(pytex.round_to_mag(-0.24, -1),
 pytex.round_to_mag(0.05, -2, rdg='UP'),
 pytex.round_to_mag(0.01, -1, rdg='DOWN'))


Out[19]:
$$\left ( -0.2, \quad 0.05, \quad 0.0\right )$$

In [20]:
(pytex.repr_float(2.1),
 pytex.repr_float(2.1e-33))


Out[20]:
('2.1', '2.1 \\times 10^{-33}')

In [21]:
Latex('$%s$' % pytex.repr_float(2.1e33))


Out[21]:
$2.1 \times 10^{33}$

In [22]:
(pytex.repr_decimal(1e-23),
 pytex.repr_decimal(1e-23, -4),
 pytex.repr_decimal(1.2345, -2),
 pytex.repr_decimal(1.2345, -2, rdg='UP'))


Out[22]:
('0.000000000000000000000001', '0.0000', '1.23', '1.24')

In [23]:
pytex.repr_error(1.282e-33)


Out[23]:
'1.3 \\times 10^{-33}'

In [24]:
pytex.align_num(321.2, dleft=4, dright=4)


Out[24]:
'\\phantom{+0} 321.2 \\phantom{000}'

In [25]:
aligned_list = pytex.align_num_list([123, 123.132, 2e22, -10, 100e22])
print('\n'.join(aligned_list))
Latex('<br>'.join([r'$%s$' % e for e in aligned_list]))


\phantom{+} 123.0 \phantom{00}\phantom{ \times 10^{22}}
\phantom{+} 123.132\phantom{ \times 10^{22}}
\phantom{+00} 2 \phantom{.000} \times 10^{22}
-\phantom{0} 10.0 \phantom{00}\phantom{ \times 10^{22}}
\phantom{+00} 1 \phantom{.000} \times 10^{24}
Out[25]:
$\phantom{+} 123.0 \phantom{00}\phantom{ \times 10^{22}}$
$\phantom{+} 123.132\phantom{ \times 10^{22}}$
$\phantom{+00} 2 \phantom{.000} \times 10^{22}$
$-\phantom{0} 10.0 \phantom{00}\phantom{ \times 10^{22}}$
$\phantom{+00} 1 \phantom{.000} \times 10^{24}$

In [26]:
Latex(pytex.format_valerr(1231, 1.2))


Out[26]:
$1231.0 \pm 1.2$

In [27]:
Latex(pytex.format_valerr(1231e10, 1.2e10))


Out[27]:
$(12310 \pm 12) \times 10^{9}$

In [28]:
values = (np.random.rand(10)-.5) * 2015
errors = np.random.rand(10) * 10

valerrs = pytex.format_valerr_list(values, errors)
Latex('<br>'.join(valerrs))


Out[28]:
$-917 \phantom{.0} \pm 10 \phantom{.0}$
$\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$
$-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$
$-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$
$\phantom{+} 621.3 \pm \phantom{0} 1.9$
$\phantom{+} 674.0 \pm \phantom{0} 2.9$
$\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$
$-420.0 \pm \phantom{0} 1.6$
$-841 \phantom{.0} \pm 10 \phantom{.0}$
$\phantom{+} 650.0 \pm \phantom{0} 2.2$

In [29]:
Latex(pytex.table_html([valerrs + valerrs, valerrs], fill='-', just='lc', vsep='| |', hsep={0, -1}))


Out[29]:
$-917 \phantom{.0} \pm 10 \phantom{.0}$ $-917 \phantom{.0} \pm 10 \phantom{.0}$
$\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$ $\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$
$-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ $-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$
$-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ $-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$
$\phantom{+} 621.3 \pm \phantom{0} 1.9$ $\phantom{+} 621.3 \pm \phantom{0} 1.9$
$\phantom{+} 674.0 \pm \phantom{0} 2.9$ $\phantom{+} 674.0 \pm \phantom{0} 2.9$
$\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$ $\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$
$-420.0 \pm \phantom{0} 1.6$ $-420.0 \pm \phantom{0} 1.6$
$-841 \phantom{.0} \pm 10 \phantom{.0}$ $-841 \phantom{.0} \pm 10 \phantom{.0}$
$\phantom{+} 650.0 \pm \phantom{0} 2.2$ $\phantom{+} 650.0 \pm \phantom{0} 2.2$
$-917 \phantom{.0} \pm 10 \phantom{.0}$ -
$\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$ -
$-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ -
$-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ -
$\phantom{+} 621.3 \pm \phantom{0} 1.9$ -
$\phantom{+} 674.0 \pm \phantom{0} 2.9$ -
$\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$ -
$-420.0 \pm \phantom{0} 1.6$ -
$-841 \phantom{.0} \pm 10 \phantom{.0}$ -
$\phantom{+} 650.0 \pm \phantom{0} 2.2$ -

In [30]:
print(pytex.table_latex([valerrs, valerrs]))


\begin{table}[H]
\centering
	\begin{tabular}{|c|c|}
	\hline
	$-917 \phantom{.0} \pm 10 \phantom{.0}$ & $-917 \phantom{.0} \pm 10 \phantom{.0}$\\ \hline
	$\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$ & $\phantom{+} 654 \phantom{.0} \pm \phantom{0} 8 \phantom{.0}$\\ 
	$-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ & $-220 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$\\ 
	$-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$ & $-335 \phantom{.0} \pm \phantom{0} 9 \phantom{.0}$\\ 
	$\phantom{+} 621.3 \pm \phantom{0} 1.9$ & $\phantom{+} 621.3 \pm \phantom{0} 1.9$\\ 
	$\phantom{+} 674.0 \pm \phantom{0} 2.9$ & $\phantom{+} 674.0 \pm \phantom{0} 2.9$\\ 
	$\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$ & $\phantom{+} 747 \phantom{.0} \pm 10 \phantom{.0}$\\ 
	$-420.0 \pm \phantom{0} 1.6$ & $-420.0 \pm \phantom{0} 1.6$\\ 
	$-841 \phantom{.0} \pm 10 \phantom{.0}$ & $-841 \phantom{.0} \pm 10 \phantom{.0}$\\ 
	$\phantom{+} 650.0 \pm \phantom{0} 2.2$ & $\phantom{+} 650.0 \pm \phantom{0} 2.2$\\ \hline
	\end{tabular}
\end{table}

In [ ]: