connorferster / handcalcs

Python library for converting Python calculations into rendered latex.
Apache License 2.0
5.39k stars 418 forks source link

Using handcalcs with pint #203

Open av1dm opened 3 months ago

av1dm commented 3 months ago

Hello,

I wanted to share my default setup for using handcalcs together with pint.

Pint can be a useful alternative to forallpeople, if some "advanced" options are needed. The main reason, I started using pint is to work with fixed prefixes. Here is my default setup to achieve this:

from handcals import render
from pint import UnitRegistry

ureg = UnitRegistry(autoconvert_to_preferred = True)
preferred_units = [
    ureg.mm,
    ureg.kg,
    ureg.s, 
    ureg.K,
    ureg.kN,
    ureg.W,
    ureg.MPa
]

ureg.default_preferred_units = preferred_units

mm  = ureg.mm
kN  = ureg.kN
MPa = ureg.MPa

handcalcs.set_option("preferred_string_formatter", "~L")
connorferster commented 2 months ago

@av1dm Thanks for posting this!