Handcalcs
Introduction
This is a package for generating LaTeX maths and designed to improve documentation for your calculations. This package was designed to work in both jupyter and pluto.
This package supplies macros to generate \LaTeX
formatted strings from mathmatical formulas. This package takes inspiration from handcalcs.py which is a python package that works best in jupyter notebooks. The goal is to get the functionalities of that package and bring them to Julia. The current version of Handcalcs.jl is working for typical algebraic formulas. Future plans are to integrate the package with Unitful.jl, be able to render the algebraic expressions within a function, and many other things. This package is an extension of Latexify.jl. The @latexdefine
macro is similar to the main @handcalcs
macro, but instead of only a symbolic rendering it also renders the numeric substitution.
Basic Demo
Basic example:
Single line expression
using Handcalcs
a = 3
b = 4
@handcalcs c = sqrt(a^2 + b^2)
or
@handcalcs begin c = sqrt(a^2 + b^2) end
You may want to do the latter in Pluto. This will supress the assignment callout in the top left of the output cell.
This generates a LaTeXString (from LaTeXStrings.jl) which, when printed looks like:
$c = \sqrt{a^{2} + b^{2}} = \sqrt{3^{2} + 4^{2}} = 5.0$
And when this LaTeXString is displayed in an environment which supports the tex/latex MIME type (Jupyter and Pluto notebooks, Jupyterlab and Hydrogen for Atom) it will automatically render as:
Multi line expression
You can add comments to the side of the expression by adding a string beside the expression. Note: the variables being assigned in the expressions are evaluated (see docs for more details). See example below.
a = 2
b = 5
@handcalcs begin
c = a + b; "eq 1";
d = a - c
end
$\begin{align}
c &= a + b = 2 + 5 = 7\text{ }(\text{eq 1})
\\d &= a - c = 2 - 7 = -5
\end{align}$"
Installation
This package is registered in the Julia registry, so to install it you can just run:
Pkg.add("Handcalcs")
Further information
For further information see the docs