import __main__
import numpy as np

def export(varname, precision=None, scale=None, siunit=None):
    x = getattr(__main__, varname)
    if scale is not None:
        x *= scale
    if precision is None:
        x = '%d' % (x,)
    else:
        if precision < 0:
            x = np.round(x, precision)
            precision = 0
        x = ('%%.%df' % (precision,)) % (x,)
    if siunit is None:
        value = x
    else:
        value = r'\SI{%s}{%s}' % (x, siunit)
    print(r'\newcommand{\%s}{%s}' % (varname,value,))
