Units#
handcalcs renders whatever values your code produces, so quantities from a units library work like numbers: the substituted step and the result show the value with its unit. forallpeople (designed alongside handcalcs) and pint are both used this way.
forallpeople#
Load an environment with top_level=True so the unit names (m, kN, …) are
available directly:
import forallpeople as si
si.environment("structural", top_level=True)
Then, in a separate rendered cell:
%%render
L = 6 * m
w = 5 * kN / m
M = w * L**2 / 8
The result is shown as 22.5 kN·m. forallpeople quantities accept format codes, so
# hc: -f works on them.
pint#
import pint
ureg = pint.UnitRegistry()
ureg.formatter.default_format = "~P" # short, pretty unit symbols
%%render
L = 6 * ureg.m
w = 5 * ureg.kN / ureg.m
M = w * L**2 / 8
Tips#
Set up the units in a cell you don’t render, or hide the setup lines with
# hc: -iat the end of each line. The setup code is not part of the calculation.Unit-aware values are formatted by the units library. Whether the format code applies depends on the library’s
__format__support.In LaTeX and Markdown, any other value with a
_repr_latex_(e.g. a worstcase parameter, shown as1 ± 0.1) is rendered with its own LaTeX, bracketed when it has more than one term. The format code does not apply to it.The Excel renderer converts pint and forallpeople quantities into unit columns and SI-scaled formulas.
Next: Gotchas.