Interfaces#
An interface is how you hand code to handcalcs. All three use the same parser and the same renderers; they differ in where the code and its values come from.
Interface |
You write |
Values come from |
Returns |
Best for |
|---|---|---|---|---|
a Jupyter cell |
the notebook namespace |
displays the output |
notebooks |
|
a string or a |
running the code, or a namespace you pass |
the rendered output |
scripts, reports, web apps, tests |
|
a function |
the function’s call |
|
reusable calculations |
In 30 seconds#
import handcalcs
%%render
a = 2
b = 3
c = 2*a + b/3
from handcalcs import HandCalcs
from handcalcs.renderers import LatexRenderer
hc = HandCalcs(renderer=LatexRenderer())
latex = hc("a = 2\nb = 3\nc = 2*a + b/3\n")
from handcalcs import handcalc
from handcalcs.renderers import HTMLRenderer
@handcalc(HTMLRenderer())
def moment(w, L):
M = w * L**2 / 8
return M
value, html = moment(5, 6)
Which one?#
Working in a notebook: use
%%render. Change its output format with%hc_default_renderer.Generating output from a program (a report, a web page, a batch of PDFs): use
HandCalcs. It is the most direct interface and the one the others are built on.Wrapping a calculation you call repeatedly with different inputs: use
@handcalc, which returns the result for your program and the rendered calculation for your report.