Skip to content

Jollywatt/typst-parsely

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

142 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parsely

Parse equations with Typst.

Package manual (PDF)

Parsely provides tools to parse Typst equations into structured syntax trees using user-specified grammars.

Supports prefix/infix/postfix operators, precedence, associativity and recursive pattern matching allowing complex mathematical expressions to be parsed.

Usage examples

Self-contained usage examples can be found in the manual:

  • drawing expression trees from equations (using CeTZ)
  • performing engineering calculations with units (using Pariman)
  • turning equations into functions for plotting (using Lilaq)

Minimal example

#import "@preview/parsely:0.1.1"

From the equation $A x + b$ obtain the abstract syntax tree

(head: "add", args: ((head: "mul", args: ($A$, $x$)), $b$))

using the main function parsely.parse(eqn, grammar) where the grammar

#let grammar = (
  add: (infix: $+$, prec: 1, assoc: true),
  mul: (infix: $$, prec: 2, assoc: true),
)

defines the syntax of the operators that form the nodes in the tree.

Change log

v0.1.1

  • Add operator guards and rewrite rules.
  • Improve documentation.
  • Fix usage examples.
  • Improve the default parsely.common.arithmetic grammar.

v0.1.0

  • Initial concept.

About

Parse equations with Typst and manipulate or evaluate them.

Resources

License

Stars

11 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors