mpacts.core.units. formatting

Format units for mpacts.core.units.

copyright:2016 by Pint Authors, see AUTHORS for more details.
license:BSD, see LICENSE for more details.

In order to be able to use this module import it like this:

import mpacts.core.units.formatting
#or assign it to a shorter name
import mpacts.core.units.formatting as for
mpacts.core.units.formatting._join(fmt, iterable)

Join an iterable with the format specified in fmt.

The format can be specified in two ways: - PEP3101 format with two replacement fields (eg. ‘{0} * {1}’) - The concatenating string (eg. ‘ * ‘)

mpacts.core.units.formatting._parse_spec(spec)
mpacts.core.units.formatting._pretty_fmt_exponent(num)

Format an number into a pretty printed exponent.

mpacts.core.units.formatting.format_unit(unit, spec, **kwspec)
mpacts.core.units.formatting.formatter(items, as_ratio=True, single_denominator=False, product_fmt=u' * ', division_fmt=u' / ', power_fmt=u'{0} ** {1}', parentheses_fmt=u'({0})', exp_call=<function <lambda>>, locale=None, babel_length=u'long', babel_plural_form=u'one')

Format a list of (name, exponent) pairs.

Parameters:
  • items – a list of (name, exponent) pairs.
  • as_ratio – True to display as ratio, False as negative powers.
  • single_denominator – all with terms with negative exponents are collected together.
  • product_fmt – the format used for multiplication.
  • division_fmt – the format used for division.
  • power_fmt – the format used for exponentiation.
  • parentheses_fmt – the format used for parenthesis.
  • locale – the locale object as defined in babel.
  • babel_length – the length of the translated unit, as defined in babel cldr.
  • babel_plural_form – the plural form, calculated as defined in babel.
Returns:

the formula as a string.

mpacts.core.units.formatting.matrix_to_latex(matrix, fmtfun=<function <lambda>>)
mpacts.core.units.formatting.ndarray_to_latex(ndarr, fmtfun=<function <lambda>>, dim=())
mpacts.core.units.formatting.ndarray_to_latex_parts(ndarr, fmtfun=<function <lambda>>, dim=())
mpacts.core.units.formatting.remove_custom_flags(spec)
mpacts.core.units.formatting.siunitx_format_unit(units)

Returns LaTeX code for the unit that can be put into an siunitx command.

mpacts.core.units.formatting.vector_to_latex(vec, fmtfun=<function <lambda>>)