npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dongivan/formular

v0.1.2

Published

`formular` is a toy libray which presents an interactive context of mathematics expressions.

Downloads

5

Readme

formular

formular is a toy libray which presents an interactive context of mathematics expressions.

What formular could do:

  • Build a mathematics expression step by step.
  • Move the cursor.
  • Undo / redo.
  • Render the expression to Latex / MathML.

What formular could not do:

  • Render a Latex string / MathML node to HTML / SVG.
  • Read from a Latex string or MathML node.
  • Compute the expression.

Demo

See here.

See more details from the source code of the project.

Concept

In this library, the instance of the Formular class is used to input the math symbols and build them to an expression. Each math symbol is parsed to a MathChar instance, and then all the MathChar instances will be used to generate a MathTree instance using shunting yard algorithm. And then the renderers could render the MathTree to text or other formats.

Install

npm install @dongivan/formular --save

Usage

Import & Renderer

Import Formular and the renderer you need (e.g. Latex).

import { Formular, Latex, MathML } from "@dongivan/formular"

Formular instance will hold all status of the expression and rebuild an expression tree whenever the expression changed. And the expression tree could be rendered to specific format by the renderer.

const formular = new Formular();
formular.addTreeChangedListener({ tree } => {
  result = Latex.renderText(tree);
  /* If you use an reactive framework(e.g. Vue), you should also get the result here */
  resultReference.value = MathML.renderText(tree);
})

Then you will get the latex result of the expression after it is changed.

Latex vs MathML

Latex (or LaTeX) is a famous technology especilly when rendering mathematics expression (with Katex or MathJax in broswer). However, it is not a good renderer while rendering an interactive expression. For example, if we want to add some information to the second symbol of expression a+2 (which is the operator +), and the information would show as a tip when the mouse move over the symbol, the Latex could not help us (to take the information).

MathML, on the other hand, is a structured language which could easily take informations with it but only the MathJax could render it.

Cursor

A Formular instance always has one (and only one) cursor, and the new MathChar (like digits, variables or operators) will be inserted at the position of the cursor. The cursor could be moved to left or right, or to specific position / MathChar.

/* Move the cursor to the left 1 step */
formular.moveCursorLeft();
/* Move the cursor to the right 1 step */
formular.moveCursorRight();
/* Move the cursor to the right 5 steps. The cursor will be moved to the left steps if the param is negative. */
formular.moveCursor(5);
/* Move the cursor to position 0 */
formular.moveCursorTo(0);
/* Move the cursor to the position before the `MathChar` with sequence number 1. */
formular.moveCursorBeforeChar(1);

Sequence Number

Each MathChar instance has a sequenceNumber attribute (as id), and MathML renderer will render the instance to a MathML node with data attribute data-formular-char-sn, and then MathJax will render this node to a html element with the same data attribute. However, the Latex renderer will ignore the sequence number.

Insert / Delete MathChar

formular.insertAtCursor('+');
formular.deleteCharBeforeCursor();

Undo / Redo

formular.undo();
formular.redo();

Listeners

const listener: TreeChangedListener = ({ tree }) => { /* do something */ }
formular.addTreeChangedListener(listener);
formular.removeTreeChangedListener(listener);

Check Valid

The expression inputed may not be valid (e.g. 1+ or 2-(5+4 ), you can check it using checkIntegrity.

const isValid = formular.checkIntegrity(true)

If the parameter is set to true, all the invalid symbols will be saved to tree.incompleteChars and the MathML renderer will render them with specific class formular-incomplete.

If the parameter is set false, the method will just return whether the expression is valid or not.

Pure Tree

A pure tree is a MathTree without cursor. It is usefull when you want to render the expression and hidint the cursor.

const tree = formular.getPureTree();
Latex.renderText(tree);

More

Please read ./src/App.vue.

Caution

Remember: this project is just a toy. DO NOT use it in any production.