handcalcs#

Python calculations, written out the way you would write them by hand.

handcalcs turns ordinary Python calculation code into a formatted calculation: the symbolic formula, then the formula with every value substituted in, then the result. Because the substitution step is shown, anyone can check the calculation by hand.

a = 2.5  # Side a, in m
b = 4.0  # Side b, in m
c = sqrt(a**2 + b**2)  # Hypotenuse
Output (MarkdownRenderer)
\[\begin{aligned} a &= 2.5 \quad\text{(Side a, in m)} \\ b &= 4 \quad\text{(Side b, in m)} \\ c &= \sqrt{a^{2} + b^{2}} = \sqrt{2.5^{2} + 4^{2}} = 4.717 \\ &\quad\text{(Hypotenuse)} \end{aligned}\]
$$\begin{aligned} a &= 2.5 \quad\text{(Side a, in m)} \\ b &= 4 \quad\text{(Side b, in m)} \\ c &= \sqrt{a^{2} + b^{2}} = \sqrt{2.5^{2} + 4^{2}} = 4.717 \\ &\quad\text{(Hypotenuse)} \end{aligned}$$

The same parsed calculation can be sent to different renderers: Markdown and LaTeX for Jupyter and documents, HTML for web pages, plain text for terminals and logs, a live Excel worksheet, and a Word document with editable equations. You can restyle the built-in renderers or write your own.

Where do you want to go?#

Get started

Install handcalcs and render your first calculation in Jupyter or a Python script.

Get started
Use a renderer

Markdown, LaTeX, HTML, plain text, Excel or Word: what each produces and when to use it.

Renderers
Pick an interface

The %%render cell magic, the HandCalcs object, or the @handcalc decorator.

Interfaces
Find a recipe

Tested recipes: precision, checks, notation, equation numbers, Word and PDF reports, web apps.

Cookbook
Customize a renderer

Add colors to the HTML output, change Markdown and LaTeX tokens, add symbols.

Customizing a renderer
Build a renderer

How rendering works, the methods you override, and worked examples.

Building a renderer
Work on handcalcs

Set up a development environment, find your way around the source, run the tests.

Developer’s guide

Looking for a specific function, option or # hc: command? See the reference.