From Python to Paper: Visualizing Calculations with Handcalcs

Python calculations often lack transparency when only showing final results.

Handcalcs addresses this by generating LaTeX output that mimics handwritten calculations. It displays symbolic formulas, numeric substitutions, and results, providing a clear step-by-step breakdown.

This approach makes calculations more intuitive, readable, and easier to verify manually.

Handcalcs can be used in two main ways:

  1. As a cell magic in Jupyter notebooks using %%render:
import handcalcs.render
from handcalcs.decorator import handcalc
%%render
a = 2
b = 3
c = 2*a + b/3
  1. As a decorator for functions:
from math import sqrt

@handcalc(jupyter_display=True)
def my_calc(x: float, y: float, z: float):
    a = 2*x
    b = 3*a/z + sqrt(a+y/2)
    c = a + b
    return c
result = my_calc(2.3, 3.2, 1.2)
result
18.589979919597745

Link to handcalcs.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top