connorferster / handcalcs

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

Skip subsitution step with forallpeople integration #183

Open cslotboom opened 11 months ago

cslotboom commented 11 months ago

Hey, I'd like to skip unit substitution when there is a lone unit with forallpeople. Right now handcalcs will write out all the calculations steps if you write something like 200*si.mm. This is especially noticeable for unit-less equations.

It would look much cleaner if something like 200*si.mm is rendered as 200 mm, without the distribution, similar to how unitless quantities are just rendered.

An alternatively, if there was a way to flag lines to be skipped so they don't render, that would also be great! If I could declare blim but not render it, that would also be a solution to clean up these equations.

See examples below.

image

@handcalc('long', precision = 1)
def summarizeMoment(F_b, b, d, L, k_net, k_L = 1):
    phi = 0.9

    S_eff = b*d**2 / 6
    blim = 130*si.mm
    k_Zbg = min((((130*si.mm)/b)**0.1)*((610/d)**0.1)*((9100/L)**0.1), 1.3)
    k_eff = min(k_Zbg, k_L)

    Mr = (phi*F_b*S_eff*k_eff*k_net).to('Nm')
connorferster commented 11 months ago

Heyo!

Put any calculation in parentheses to prevent the substitution step from rendering.

cslotboom commented 11 months ago

Hey, okay perfect! Good to note and it did help my use case. Do you think it is feasible to have a tag that will suppress certain lines, or would that be quite tricky? Even with the substitution suppressed, there is a lot of real estate being taken up by extra definitions. I often find myself doing gymnastics (like defining variables in other places) to save room and have cleaner substitutions.

image

That or the ability to suppress the substitution for definitions in multi-line expressions, such as below where 130*si.mm is used. This seems like a much harder task however.

It might seem like a small thing, but the extra substitution step might be confusing for a layperson who is trying to read a calculation.

image

@handcalc('long', precision = 2)
def summarizeMoment(F_b, b, d, L, k_net, k_L = 1):
    phi = 0.9
    d_lim = (610*si.mm)
    L_lim = (9100*si.mm)

    S_eff = b*d**2 / 6
    k_Zbg = min(((((130*si.mm)/b)*(d_lim/d)*(L_lim/L))**0.1), 1.3)
    k_eff = min(k_Zbg, k_L)

    M_r = (phi*F_b*S_eff*k_eff*k_net).to('Nm')