Universe

An equation runner. You pass an equation through the library, it reads all the variables mentioned in it, inserts their values, returns the equation with its result and saves that result as a variable. Then you can use that variable as an input for the next equation.

Usage

Create the runner providing the initial inputs:

#import "@preview/eqrun:0.1.0": eqrun-builder

#let init = (
  w: 6,
  h: 7,
)
#let eqrun = eqrun-builder(init)

The area of a rectangle with sides $#init.w times #init.h$:

Write an equation and pass it to the runner:

#eqrun($A = w dot h$)

Output of the example block that uses variables from init

Now you can use the new variable in other equations:

Half of the square root of that is:
#eqrun($A^tau_"half sqrt" = sqrt(A) / 2$)

Output of the example block that uses a variable generated by the last equation

And get all the variables out of the runner:

#context [
  #let state = eqrun()
  A: #state.A\
  A triangle: #state.A-half-sqrt-tau
]

Output of the example block that shows how to get variables back from eqrun

You can also change how much it rounds, the default is 2. It can be specified in the eqrun-builder or here:

Changing the precision:
#eqrun($tau = 2.019 / 2$, precision: 4)

Output of the example that shows how to change the precision

Powers and superscript work as you would expect:

This also works:
#eqrun($b^n = 2^sqrt(A div 6)$)

Output of the example that shows how powers and superscript work

Contributing

If you find something that doesn’t work, please open an issue describing how to reproduce the bug.

You can also try running in debug mode to figure out what’s wrong:

#let eqrun = eqrun-builder(init, debug: true)