Handcalcs: Automatically render Latex equations from Python math code
github.com
github.com
I'd love to be able to inline this code into my org documents, and have it display the latex output, but that might be asking for too much magic. (As in, not sure if the magic is worth the incantation.)
I particularly like the idea of feeling reassured that whatever I publish for humans also passed a test-suite.
I agree.
And for writing, the difference is even bigger than for reading. Thus, what we need is the reverse tool, that translates our beautiful formulas into the damned code!
- OCR a handwritten formula (unreliable but the most convenient)
- make the user write serialized code and show it as formula (basically this submission, but also latex etc. - misses the point)
- force the user to design the formula tree with some graphical editor and fill it with values and identifiers later (office suites do this and it's such a pain to constantly switch between keyboard and mouse)
Eg. by hand, you can write down the denominator of a fraction before the numerator. While latex require numerator before denominator.
The problem is that you have to jump which "by hand" is natural (start writing slightly lower) while with keyboard requires switching to mouse and back or remembering shortcuts and modeling the tree structure of your formula in your head to know where the shortcut will jump.
Same with introducing new levels of nesting.
That's why I prefer just writing code for formulas over graphical editors.
But even without all that, a very basic thing that you can do is move around the matching pairs of braces (and brackets, and other paired things) using %
If you do not want to move, but only see where the matching brace is, you can "set showmatch" and it will flash the matching brace when your cursor passes through the other one. This is really helpful for writing nested formulas (although a better strategy is to add a lot of newlines and whitespace so that the structure of your formulas is clear).
Quick note about the site: the animated GIFs are not helpful. A static screenshot would let me see the result and give me time to understand what's going on. As it is, they jump back to an unrendered Jupiter cell almost immediately, and the animation is just typing; not really showing anything useful.
I could also imagine people using this if they aren't that comfortable with LaTeX and want an easier way to write it. They could just write out their formulas with Python, call @handcalc() to get the string output, then post it in their tex documents.
I've been using sage math a lot and the latex generation is really solid. It only renders greek letters correctly if you type them out though, it won't transform unicode greek letters to the correct latex equivalent. Though maybe XeTeX would solve this problem? I'm not sure.
That way of work seems a bit too optimistic to me.
This looks great. Its super useful for when you need to perform calculations and also keep a saved record of it (like structural engineering calcs)