Keecas: Python package for symbolic math with units in Jupyter/Quarto notebooks #13684
kompre
started this conversation in
Show and Tell
Replies: 1 comment
-
|
This is really cool! I feel like this kind of expressive DSL stuff is very common in R because of its Non-Standard Evaluation, but much less common in Python. Love to see it! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I'd like to share Keecas, a Python package I built for symbolic and units-aware calculations in Jupyter notebooks, specifically designed to work in a Quarto environment.
Background
As a structural engineer writing calculation reports, I wanted executable notebooks that generate publication-quality PDFs with proper equation numbering and cross-references. Quarto solved the document rendering problem beautifully, but I still had too much boilerplate in the Python code itself. Keecas eliminates that.
What It Does
Keecas provides a thin layer over SymPy + Pint that uses dicts as equation containers. Keys represent left-hand side symbols, values represent right-hand side expressions. This maps naturally to how equations are written and reduces repetitive code.
Key features for Quarto users:
amsmathLaTeX generation with\label{}for equation numbering\eqref{}and\ref{}Example
A typical Python cell would look like this:
show_eqnreturns anIPython.display.Latexobject, that will be rendered by the Jupyter engine.Generated LaTeX:
Since
show_eqnreturns aLatexobject, the command\label{}must be used, and therefore to reference equations\eqref{}or\ref{}must be used as well. I couldn't find a workaround to use@eq-syntax, but at least a user can copy-paste the interpolated labels, or use an inline helper function:Quarto Workflow
As a personal preference I develop calculation reports as
ipynbfor the vertical input-cell/output layout. Since VS Code's KaTeX doesn't support\label{}, I use Quarto's#| eval: falseto set config options that will run only during the development phase, but not during rendering withquarto render.#| eval: falsecellsThis approach require either to pass
--executeflag toquarto render, or to convertipynbtoqmdbefore final render. (I prefer the latter approach, and convert the ipynb with apre-renderstep in_quarto.yml.)Try It
If you have
uvinstalled, try a quick session:A jupyterlab session will open a temporary file using the quickstart template.
Use Cases
Examples
Links
Feedback Welcome
I've been using this professionally for over a year in structural engineering, but would love feedback from the broader Quarto community. Questions, suggestions, and contributions are all welcome!
Beta Was this translation helpful? Give feedback.
All reactions