Unit options
The unit options are saved in the unit_kw attribute:
[1]:
from mplunitx import sisetup
si = sisetup()
print(si.unit_kw)
_unit_kw({'per_mode': 'power', 'per_symbol': '/', 'inter_unit_product': '\\,', 'bracket_unit_denominator': True, 'per_symbol_script_correction': '\\!', 'sticky_per': False, 'parse_units': True, 'unit_font_command': '\\mathrm'})
They can be set when creating the sistetup instance:
[2]:
# Default values
si = sisetup(
inter_unit_product=r"\,", per_mode="power", per_symbol="/",
bracket_unit_denominator=True, per_symbol_script_correction=r"\!",
sticky_per=False, parse_units=True, unit_font_command=r"\mathrm"
)
Or temporarily overwritten in the call of si.unit.
The options are demonstrated below.
inter_unit_product
[3]:
print(si.unit("farad.squared;lumen;candela"))
print(si.unit("farad.squared;lumen;candela", inter_unit_product=r"\cdot"))
$\mathrm{F}^{2}\,\mathrm{lm}\,\mathrm{cd}$
$\mathrm{F}^{2}\cdot\mathrm{lm}\cdot\mathrm{cd}$
\(\mathrm{F}^{2}\,\mathrm{lm}\,\mathrm{cd}\)
\(\mathrm{F}^{2}\cdot\mathrm{lm}\cdot\mathrm{cd}\)
per_mode
per_mode = "power"
[4]:
# per_mode = "power"
print(si.unit("joule;per.mole;per.kelvin"))
print(si.unit("metre;per.second.squared"))
$\mathrm{J}\,\mathrm{mol}^{-1}\,\mathrm{K}^{-1}$
$\mathrm{m}\,\mathrm{s}^{-2}$
\(\mathrm{J}\,\mathrm{mol}^{-1}\,\mathrm{K}^{-1}\)
\(\mathrm{m}\,\mathrm{s}^{-2}\)
per_mode = "fraction"
[5]:
# per_mode = "fraction"
print(si.unit("joule;per.mole;per.kelvin", per_mode="fraction"))
print(si.unit("metre;per.second.squared", per_mode="fraction"))
$\frac{\mathrm{J}}{\mathrm{mol}\,\mathrm{K}}$
$\frac{\mathrm{m}}{\mathrm{s}^{2}}$
\(\frac{\mathrm{J}}{\mathrm{mol}\,\mathrm{K}}\)
\(\frac{\mathrm{m}}{\mathrm{s}^{2}}\)
per_mode = "power-positive-first"
[6]:
# per_mode = "power-positive-first"
print(si.unit("ampere;per.mole;second"))
print(si.unit("ampere;per.mole;second", per_mode="power-positive-first"))
$\mathrm{A}\,\mathrm{mol}^{-1}\,\mathrm{s}$
$\mathrm{A}\,\mathrm{s}\,\mathrm{mol}^{-1}$
\(\mathrm{A}\,\mathrm{mol}^{-1}\,\mathrm{s}\)
\(\mathrm{A}\,\mathrm{s}\,\mathrm{mol}^{-1}\)
per_mode = "symbol"
[7]:
# per_mode = "symbol"
print(si.unit("joule;per.mole;per.kelvin", per_mode="symbol"))
print(si.unit("metre;per.second.squared", per_mode="symbol"))
print(si.unit("joule;per.mole;per.kelvin", per_mode="symbol",
per_symbol="\\text{ per }"))
print(si.unit("joule;per.mole;per.kelvin", per_mode="symbol",
bracket_unit_denominator=False))
$\mathrm{J}/(\mathrm{mol}\,\mathrm{K})$
$\mathrm{m}/\mathrm{s}^{2}$
$\mathrm{J}\text{ per }(\mathrm{mol}\,\mathrm{K})$
$\mathrm{J}/\mathrm{mol}\,\mathrm{K}$
\(\mathrm{J}/(\mathrm{mol}\,\mathrm{K})\)
\(\mathrm{m}/\mathrm{s}^{2}\)
\(\mathrm{J}\text{ per }(\mathrm{mol}\,\mathrm{K})\)
\(\mathrm{J}/\mathrm{mol}\,\mathrm{K}\)
per_mode = "single-symbol"
[8]:
# per_mode = "single-symbol"
print(si.unit("metre;per.second", per_mode="single-symbol"))
print(si.unit("joule;per.mole;per.kelvin", per_mode="single-symbol"))
$\mathrm{m}/\mathrm{s}$
$\mathrm{J}\,\mathrm{mol}^{-1}\,\mathrm{K}^{-1}$
\(\mathrm{m}/\mathrm{s}\)
\(\mathrm{J}\,\mathrm{mol}^{-1}\,\mathrm{K}^{-1}\)
per_symbol_script_correction
[9]:
print(si.unit("cm.cubed;per.gram", per_mode="symbol"))
print(si.unit("cm.cubed;per.gram", per_mode="symbol",
per_symbol_script_correction=""))
$\mathrm{cm}^{3}\!/\mathrm{g}$
$\mathrm{cm}^{3}/\mathrm{g}$
\(\mathrm{cm}^{3}\!/\mathrm{g}\)
\(\mathrm{cm}^{3}/\mathrm{g}\)