Declared in module PyLaTeX
def LaTeXGenerateUnit(value, *data, **kw) def __format_digit_string(value, thousand_sep, reverse=0) def __str_reverse(val) def formatFloat(val, *data, **kw) def formatInt(val, *data, **kw) def generateUnitList(value, *data, **kw) string __author__ = 'Berthold H\366llmann, bhoel@starship.python.net' string __file__ = '../PyLaTeX/UnitPrint.pyc' tuple __unit_print = (None, '%s', '\\unit[%s]{%s}', '\\unitfrac[%s]{%s}{%s}') string __version__ = '1.6' string decimal_point = ',' instance digit_group = re.RegexObject instance string fact_sep = '' string group_off = '' string group_on = '' string pow_char = '' string thousand_sep = '' alias p = PhysicalQuantities.PhysicalQuantity (type class)
formatInt, formatFloat,
generateUnitList, and LaTeXGenerateUnit. Therfor it uses the
values thousand_sep and decimal_point. thousand_sep is
determinded at startup using locale.localeconv()["thousands_sep"],
decimal_point is taken from locale.localeconv()["decimal_point"].
If locale is not avaible, thousand_sep is set to "" and
decimal_point is set to ".". The regular expression digit_group is
used to split into the chunks divided by thousand_sep. digit_group
usually generates a chunk length of three digits using
re.compile(r"([0-9]{3,3}?)").formatInt
thousand_sep after each 3
digits beginning at the right side.
formatFloat
decimal_point. Insert thousand_sep after each 3 digits
beginning at the right side for the part before the
decimal point and beginning at the left side for the part
after the decimal point.
generateUnitList
PhysicalQuantities into a list of one up to three
elements. First element is the value of the instance.
Second element is the nominator of the instances unit if
it exists. If no nominator exists but a deniminator does
exist this will be a 1. The third element is the
denominator of the instances unit if it exists.
LaTeXGenerateUnit
generateUnitList to be typesetted with LaTeX and Axel
Reichert's units.sty. It chooses the apropriate command
to use, which is none, \unit, or \unitfrac.
>>> import PhysicalQuantities
>>> p = PhysicalQuantities.PhysicalQuantity
>>> import UnitPrint
>>> from UnitPrint import *
>>> print "got: ->%s<-" % formatInt(1)
got: ->1<-
>>> print "got: ->%s<-" % formatInt(12)
got: ->12<-
>>> print "got: ->%s<-" % formatInt(123)
got: ->123<-
>>> print "got: ->%s<-" % formatInt(1234)
got: ->1234<-
>>> print "got: ->%s<-" % formatInt(12345)
got: ->12345<-
>>> print "got: ->%s<-" % formatInt(123456)
got: ->123456<-
>>> print "got: ->%s<-" % formatInt(1234567)
got: ->1234567<-
>>> print "got: ->%s<-" % formatInt(12345678)
got: ->12345678<-
>>> print "got: ->%s<-" % formatInt(123456789)
got: ->123456789<-
>>> UnitPrint.thousand_sep = r"\,"
>>> print "got: ->%s<-" % formatInt(1234567890)
got: ->1\,234\,567\,890<-
>>> UnitPrint.thousand_sep = r""
>>> print "got: ->%s<-" % formatInt(1234567890,
... {'thousand_sep': '-'})
got: ->1-234-567-890<-
>>> print "got: ->%s<-" % formatInt(1.)
got: ->1<-
>>> print "got: ->%s<-" % formatInt(12.)
got: ->12<-
>>> print "got: ->%s<-" % formatInt(123.)
got: ->123<-
>>> print "got: ->%s<-" % formatInt(1234.)
got: ->1234<-
>>> print "got: ->%s<-" % formatInt(12345.)
got: ->12345<-
>>> print "got: ->%s<-" % formatInt(123456.)
got: ->123456<-
>>> print "got: ->%s<-" % formatInt(1234567.)
got: ->1234567<-
>>> print "got: ->%s<-" % formatInt(12345678.)
got: ->12345678<-
>>> print "got: ->%s<-" % formatInt(123456789.)
got: ->123456789<-
>>> print "got: ->%s<-" % formatInt(1234567890.)
got: ->1234567890<-
>>> value = 1234.567891234
>>> print "got: ->%s<-" % formatFloat(value, 1)
got: ->1234.6<-
>>> print "got: ->%s<-" % formatFloat(value, format=2)
got: ->1234.57<-
>>> print "got: ->%s<-" % formatFloat(value, 3)
got: ->1234.568<-
>>> print "got: ->%s<-" % formatFloat(value, 4)
got: ->1234.5679<-
>>> print "got: ->%s<-" % formatFloat(value, 5)
got: ->1234.56789<-
>>> print "got: ->%s<-" % formatFloat(value, 6)
got: ->1234.567891<-
>>> UnitPrint.thousand_sep = r"\,"
>>> print "got: ->%s<-" % UnitPrint.formatFloat(value, 7)
got: ->1\,234.567\,891\,2<-
>>> print "got: ->%s<-" % formatFloat(value, 7)
got: ->1\,234.567\,891\,2<-
>>> print "got: ->%s<-" % formatFloat(value, 8,
... {'thousand_sep': -,
... decimal_point: '#'})
got: ->1-234#567-891-23<-
>>> print generateUnitList(1)
('1.0',)
>>> print generateUnitList(p("1 m/m"))
('1.0',)
>>> print generateUnitList(1, formatInt)
('1',)
>>> print generateUnitList(1, formatFloat)
('1.000',)
>>> print generateUnitList(p("1m"))
('1.0', 'm')
>>> print generateUnitList(p("1m/s"))
('1.0', m, 's')
>>> print generateUnitList(p("1kg*m/s**2"))
('1.0', kgm, 's2')
>>> print generateUnitList(1/p("1kg*m/s**2"))
('1.0', s2, 'mkg')
>>> print generateUnitList(p(1, "1/kg/m/s**2"))
('1.0', 1, 'kgms2')
>>> print generateUnitList(p("1m"), formatInt)
('1', 'm')
>>> print generateUnitList(p("1m"), formatFloat, 2)
('1.00', 'm')
>>> print generateUnitList(p("1m"), formatFloat, 3)
('1.000', 'm')
>>> print generateUnitList(p("12345.678901m"), formatFloat, 5)
('12\\,345.678\\,90', 'm')
>>> print generateUnitList(p("1m/s"), formatInt)
('1', m, 's')
>>> print generateUnitList(p("1kg*m/s**2"), formatInt)
('1', kgm, 's2')
>>> print generateUnitList(1/p("1kg*m/s**2"), formatInt)
('1', s2, 'mkg')
>>> print generateUnitList(p(1, "1/kg/m/s**2"), formatInt)
('1', 1, 'kgms2')
>>> print LaTeXGenerateUnit(1)
{1.0}
>>> print LaTeXGenerateUnit(1, formatInt)
{1}
>>> print LaTeXGenerateUnit(1, formatFloat)
{1.000}
>>> print LaTeXGenerateUnit(p("1m"))
\unit[{1.0}]{{m}}
>>> print LaTeXGenerateUnit(p("1m/s"))
\unitfrac[{1.0}]{{m}}{{s}}
>>> print LaTeXGenerateUnit(p("1kg*m/s**2"))
\unitfrac[{1.0}]{{kg}\,{m}}{{s}^{2}}
>>> print LaTeXGenerateUnit(1/p("1kg*m/s**2"))
\unitfrac[{1.0}]{{s}^{2}}{{m}\,{kg}}
>>> print LaTeXGenerateUnit(p(1, "1/kg/m/s**2"))
\unitfrac[{1.0}]{{1}}{{kg}\,{m}\,{s}^{2}}
>>> print LaTeXGenerateUnit(p("1m"), formatInt)
\unit[{1}]{{m}}
>>> print LaTeXGenerateUnit(p("1m"), formatFloat, 2)
\unit[{1.00}]{{m}}
>>> print LaTeXGenerateUnit(p("1m"), formatFloat, 3)
\unit[{1.000}]{{m}}
>>> print LaTeXGenerateUnit(p("12345.6789012m"), formatFloat, 5)
\unit[{12\,345.678\,90}]{{m}}
>>> print LaTeXGenerateUnit(p("1m/s"), formatInt)
\unitfrac[{1}]{{m}}{{s}}
>>> print LaTeXGenerateUnit(p("1kg*m/s**2"), formatInt)
\unitfrac[{1}]{{kg}\,{m}}{{s}^{2}}
>>> print LaTeXGenerateUnit(1/p("1kg*m/s**2"), formatInt)
\unitfrac[{1}]{{s}^{2}}{{m}\,{kg}}
>>> print LaTeXGenerateUnit(p(1, "1/kg/m/s**2"), formatInt)
\unitfrac[{1}]{{1}}{{kg}\,{m}\,{s}^{2}}
>>>
PhysicalQuantity and return a string ready to print
the value and unit using LaTeX and Axel Reichert's units.sty. The function
has one argument:func
float.
val reverted.
thousand_sep each three digits in
both parts and insert decimal_point. The possible arguments are:format
sep
formatFloat uses the values:
thousand_sep
thousand_sep
decimal_point
decimal_point.
thousand_sep each three digits. The function has
one argumnt:sep
formatInt only uses
thousand_sep as the string to insert each three digits. Default is
thousand_sep
PhysicalQuantity instance. The returned tuple has the length 1, 2, or 3.
Avaible options are:func
float.
args
func, default is {}.
format
fact_sep
fact_sep.
group_on
group_on.
group_off
group_off.
pow_char
pow_char.