Python Calculations in Jupyter with Handcalcs
Jupyter notebooks allows LaTeX rendering inside markdown. This way you can write complex math equations within a notebook. While LaTeX is the de facto standard for scientific documents, it hasn’t a very friendly and intuitive syntax. handcalcs is an Open Source library for converting Python calculations into rendered LaTeX: just write the symbolic formula, followed by numeric substitutions and that’s it. After install it (it is available through PyPI), in the simplest case you just need to import the render class and use the %%render magic command to render the content of a cell:
Here another example of equation render and numeric substitution:
It is also possible to render just the symbolic equation:
or any way generate the corresponding LaTeX code:
By default handcalcs renders code vertically, but it is possible to use the %%render params magic to save space by rendering in a single line or show just the result of a calculation:
After starting evaluation of this library, I can confirm that from a user experience standpoint it is definitely better that writing directly in LaTeX syntax within a notebook. All the features listed in the documentation work as expected. Only downside is that, at the moment this post is written, there is not yet full support for all the functions and symbols available in LaTeX (but I am quite sure this library will become more comprehensive in the future). Also, unfortunately the Python code render doesn’t work in Colab: the %%render magic renders a cell into LaTeK content:
Published on Java Code Geeks with permission by Guglielmo Iozzia, partner at our JCG program. See the original article here: Python Calculations in Jupyter with Handcalcs Opinions expressed by Java Code Geeks contributors are their own. |