e

eqalc

@preview

Convert math equations to functions.

v0.1.4
MIT
3 downloads

Package Information

Last Updated
Authors
Tijme
Categories
utilityvisualization

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/eqalc:0.1.4

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/eqalc:0.1.4": *

Version History

0.1.4
317f5b2e7811...
0.1.3
29c3dba74f2a...
0.1.2
dddfffd77dd9...
0.1.1
86fd5049f5d2...
0.1.0
980f9c0c0089...

Eqalc

Convert your Typst math equations to functions in order to graph or plot them.
So you only have to write your equation out ONCE!

MIT License

Installing

Install eqalc by cloning it and then importing like this:

#import "@preview/eqalc:0.1.4": math-to-func, math-to-table

#let f = $g(t)=2t dot sqrt(e^t)+ln(t)+2pi$
#f\
#math-to-table(f, min: 1, max: 5, step: 1)

// `math-to-func` will return a function that can be used to map over values

// You can also use labels:
$ g(t) = 2t dot sqrt(e^t) + ln(t) + 2pi $ <eq>
#context math-to-table(<eq>, min: 1, max: 5, step: 1)

image

Available functions at the moment:

  • math-to-func
  • math-to-table
  • math-to-data

More on these functions in the manual.

How it works

Eqalc parses your equations by recursively going through the math expressions.

// Let's take #f from the example above
#repr(f)
// This will return a tree representation of the equation
equation(
    block: false,
    body: sequence(
        sequence([g], lr(body: sequence([(], [t], [)]))),
        [=],
        [2],
        [t],
        [ ],
        [⋅],
        [ ],
        root(radicand: attach(base: [e], t: [t])),
        [+],
        sequence(
            op(text: [ln], limits: false),
            lr(body: sequence([(], [t], [)])),
            ),
        [+],
        [2],
        [π],
    ),
)

#math-to-str(f)
// This will return the equation as a string
// `2*t*calc.root(calc.pow(calc.e, t), 2)+calc.ln(t)+2*calc.pi`

If the given math expression is an equation, the left hand side will be turned into the name of the function, and the right hand side will be the body of the function.

Only one variable is allowed in the right hand side of the equation.

Documentation

A generated PDF with the documentation can be found here.

Contributing

Any contributions are welcome! Just fork the repository and make a pull request.