Show HN: Literate Calc Mode

Show HN: Literate Calc Mode

Literate programming for M-x calc. There’s an announcement weblog
put up

Shows inline outcomes for calculations, helps variables and
updates as you kind (everytime you want). Additionally works in your well-liked markup


Merely bewitch it from MELPA.


(exercise-equipment literate-calc-mode
  :be explicit t)


(straight-exercise-equipment 'literate-calc-mode)


Create particular that you may believe MELPA available.

M-x equipment-install, bewitch out literate-calc-mode.


Acceptable secure literate-calc-mode.el, arrange it aside someplace and cargo it into

There’s each a critical literate-calc-mode and a minor
literate-calc-minor-mode. Probably the most essential mode does some new syntax
highlighting, whereas the minor mode easiest evaluates all calc statements
whereas typing.

The minor mode works reasonably efficiently with org-/markdown mode or different
markup language most important modes.

There are additionally some features that can be referred to as with none mode
being energetic:

M-x literate-calc-eval-lineEvaluates a single line
M-x literate-calc-eval-bufferEvaluates your entire buffer
M-x literate-calc-insert-outcomesEvaluates your entire buffer and inserts outcomes
M-x literate-calc-bound-overlaysRemoves all overlays and clears variables

The train of Objects

You may merely append objects to your values like so:

My weight = 78kg => My weight: 78 kg

Unit conversion (and different complicated features) would perchance moreover be passe by invoking
the matching Algebraic Feature.

= usimplify(1m + 3mm) => 1.003 m

You may additionally train unknown mathematical symbols:

= x*2 + x-3 => Three x - 3
It is a literate calc file.

Traces with out "=" are disregarded.

All outcomes beginning with "=>" are an overlay generated by
literate-calc-mode. That method they're displayed in Emacs, however not
truly inside the buffer/file contents.

We will calculate a price like so:

= 2 + 2 => 4

If there is perhaps any string on the left hand aspect, it turns right into a sure

Pi = 3.14159 => Pi: 3.14159

We will train this variable under the definiton.

Tau = Pi 2 => Tau: 6.28318

Outcomes are calculated the train of Emacs' acquire calc, so that you could be train system
as efficiently.

= spherical(Pi, 2) => 3.14

Later bindings shadow earlier ones:

Pi = 3 => Pi: 3

= Pi => 3

Variable names can consider areas as efficiently:

Month-to-month Expenses = 500 => Month-to-month Expenses: 500

Month-to-month Income = 1000 => Month-to-month Income: 1000

Annual Monetary financial savings = 12 (Month-to-month Income - Month-to-month Expenses) => Annual Monetary financial savings: 6000

All values are recalculated on each replace in a spreadsheet-like

There are some further substances I’m at the moment pondering.

Semantic Highlighting

One among the distinctive inspirations was as quickly as Tydlig, which does an identical
issues, however additionally has semantic highlighting. That method, variables are
highlighted in assorted colors, however repeatedly the similar one for a given
variable, so that you could be discover the set it’s passe at a behold.

I will even choose some code from rainbow-identifiers, which is one among the many
shorter existing implementations spherical, and adapt that to our desires.


At the moment there is perhaps the likelihood to “bake in” outcomes by collectively with them to
the buffer contents. If there is perhaps efficacious want for exporting
calculations with outcomes (so any particular person can learn them), after which possibly
additionally importing them yet another time, there must be additional tooling spherical this.

I’ve additionally been toying with the foundation of integrating with org-babel, so
that you simply consider babel literate-calc blocks which take heed to and
export efficiently.

Within the event you might consider opinions on this, please be overjoyed to beginning an argument or
ship me an piece of email so I’ll decide what the best methodology to boost out this is.


Please enter your comment!
Please enter your name here