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

strict-content-mathml-editor

v1.0.3

Published

WYSIWYG editor for MathML expressions

Downloads

2

Readme

Strict Content MathML Editor

This editor helps to create Strict Content MathML 3.0 expressions.

Demo

Visit https://ifte-eda.github.io/strict-content-mathml-editor/ for a simple demo page that displays the generated Strict Content MathML code.

Screenshot

Screenshot of the Strict Content MathML Editor

Features

  • Support of custom symbols, e.g. type Umax and get the single symbol Umax instead of the product Umax in the formula editor
  • Support of SI prefixes and units
  • Support of piecewise-defined expressions
  • Automatic detection of integers, real numbers and rational numbers

Installation

npm install strict-content-mathml-editor

Usage

The editor component is provided by Guppy which is licensed under the MIT License.

This package provides the function guppy_xml_to_mathml to convert Guppy's internal XML format to Strict Content MathML.

For a simple demo web page with the formula editor and a text field displaying the resulting MathML code, the following files index.html and mathml-editor.js are required.

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="node_modules/guppy-js/guppy-default-osk.min.css">
    <script type="text/javascript" src="node_modules/guppy-js/guppy.min.js"></script>
    <script type="text/javascript" src="node_modules/guppy-js/guppy_osk.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vkiryukhin/vkBeautify@master/vkbeautify.js"></script>
    <script type="text/javascript" src="node_modules/strict-content-mathml-editor/guppy-xml-to-mathml.js"></script>
    <script type="text/javascript" src="mathml-editor.js"></script>
</head>

<body>
    <h2>Editor</h2>
    <div id="guppy1"></div>

    <h2>Result</h2>
    <div class="label">Strict Content MathML3: </div>
    <textarea type="text" id="output_mathml" class="output" rows="30" cols="100"></textarea>
</body>
</html>

mathml_editor.js

window.onload = function(){
    // ID of the editor's div
    var editor_id = "guppy1";
    // output textarea
    var output_mathml = document.getElementById("output_mathml");

    // update output textarea when editor content changes
    var update_output = function(e) {
        try {
            var engine = e.target.engine;
            var doc = engine.doc;
            var content = (new XMLSerializer()).serializeToString(guppy_xml_to_mathml(engine, doc));
            content = vkbeautify.xml(content, 4);
            output_mathml.value = content;
        }
        catch(e) {
            output_mathml.value = "Failed to parse input: " + e.message;
        }
    }

    // tab completion after backslash prints all candidates in the output textarea
    var completion = function(e) {
        output_mathml.value = e.candidates.join(", ");
    }

    Guppy.init({
        "osk":new GuppyOSK(),
        "path":"node_modules/guppy-js",
        "symbols":["node_modules/guppy-js/sym/symbols.json","node_modules/strict-content-mathml-editor/strict-content-mathml-symbols.json"],
        "events": {
            "ready": update_output,
            "change": update_output,
            "completion": completion
        },
        "settings":{
            "empty_content": "{\\text{Click to start typing math!}}"
        },
    });

    var g1 = new Guppy(editor_id);
}

Custom Symbols

You can define custom mathematical/physical symbols for later use in the formula.

Example: By defining a custom symbol, you can type Umax in the formula editor and get the single symbol Umax instead of the product Umax. In this case, the resulting MathML is <ci>Umax</ci>.

Guppy.add_global_symbol("Umax", {
    "output": {
        "latex": "U_\\text{max}",
        "asciimath": "Umax"
    },
    "attrs": {
        "group": "custom",
        "type": "Umax"
    }
});

Supported Content Dictionaries

In Strict Content MathML3, all mathematical concepts are grouped in content dictionaries. Currently, this formula editor supports the following content dictionaries and concepts:

arith1

  • abs
  • divide
  • minus
  • plus
  • power
  • product
  • root
  • sum
  • times
  • unary_minus

calculus1

  • defint
  • diff
  • int

directives1

  • evaluate

integer1

  • factorial

linalg2

  • matrix
  • matrixrow
  • vector

logic1

  • and
  • false
  • nand
  • nor
  • not
  • or
  • true
  • xnor
  • xor

norm1

  • Euclidean_norm

nums1

  • infinity

piece1

  • piece
  • piecewise
  • otherwise

prog1

  • assignment
  • block
  • call_arguments
  • def_arguments
  • for
  • global_var
  • if
  • function_block
  • function_call
  • function_definition
  • local_var
  • procedure_block
  • procedure_call
  • procedure_definition
  • return
  • while

relation1

  • eq
  • lt
  • gt
  • neq
  • leq
  • geq

rounding1

  • ceiling
  • floor

transc1

  • arccos
  • arcsin
  • arctan
  • cos
  • cosh
  • cot
  • csc
  • ln
  • log
  • sec
  • sin
  • sinh
  • tan
  • tanh

units_siprefix1

  • yocto
  • zepto
  • atto
  • femto
  • pico
  • nano
  • micro
  • milli
  • centi
  • deci
  • deka
  • hecto
  • kilo
  • mega
  • giga
  • tera
  • peta
  • exa
  • zetta
  • yotta

units_time1

  • calendar_month
  • calendar_year

SI_BaseUnits1

  • ampere
  • candela
  • kelvin
  • kilogram
  • metre
  • mole
  • second

SI_NamedDerivedUnits1

  • becquerel
  • coulomb
  • degree celsius
  • farad
  • gram
  • gray
  • henry
  • hertz
  • joule
  • katal
  • lumen
  • lux
  • newton
  • ohm
  • pascal
  • radian
  • siemens
  • sievert
  • steradian
  • tesla
  • volt
  • watt
  • weber

SIUsed_OffSystemUnits1

  • bel
  • day
  • hour
  • litre
  • minute
  • neper
  • tonne
  • degree of arc
  • minute of arc
  • second of arc