[units] Improve unit display
This commit is contained in:
@@ -43,21 +43,21 @@ def unit_str(unit, base=None, prefix="", format=" [{unit}]"):
|
||||
return ""
|
||||
elif base is not None:
|
||||
coeff = unit.express(base)
|
||||
return unit_str(base, prefix=convert_exp(coeff) + " ")
|
||||
return unit_str(base, prefix=convert_exp(coeff)+" ")
|
||||
elif len(unit.latex) > 0:
|
||||
if "." in unit.latex or "^" in unit.latex:
|
||||
base_str = ".".join(map(parse_exp_unit, unit.name.split(".")))
|
||||
u_str = r"${}{}$".format(prefix, base_str)
|
||||
u_str = r"{}${}$".format(prefix, base_str)
|
||||
else:
|
||||
u_str = r"${}{}$".format(prefix, unit.latex.replace("text", "math"))
|
||||
u_str = r"{}${}$".format(prefix, unit.latex.replace("text", "math"))
|
||||
elif len(unit.name) > 0:
|
||||
base_str = ".".join(map(parse_exp_unit, unit.name.split(".")))
|
||||
u_str = r"${}{}$".format(prefix, base_str)
|
||||
u_str = r"{}${}$".format(prefix, base_str)
|
||||
else:
|
||||
base_str = ".".join(
|
||||
map(parse_exp_unit, unit._decompose_base_units().split("."))
|
||||
)
|
||||
u_str = r"${}{} {}$".format(prefix, unit.coeff, base_str)
|
||||
u_str = r"{}${} {}$".format(prefix, unit.coeff, base_str)
|
||||
return format.format(unit=u_str)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user