This module loads scripts from the MathLive library (from https://cortexjs.io/mathlive/), and then creates from it several different tools useful in the Lurch application.
First, it creates the MathItem class, which can be added to Dialog instances as an input component containing an equation editor. (Note that I say "equation editor" here because that is common parlance, but of course one can use it for many types of mathematical expressions, not just equations.)
Second, it creates a function for converting among various math notation formats. See getConverter() for details.
Classes
Members
inputFormats
An array of names of all the input formats known by the converter defined in getConverter().
Source
outputFormats
An array of names of all the output formats known by the converter defined in getConverter().
Source
stylesheetstring
We store here the URL to the MathLive CSS stylesheet, so that we can define it in only one location and others can reference it from here.
Type
-
string
Source
Methods
getConverter() → {Promise}
A converter is a function with the following signature:
convert( data, 'input format', 'output format' )
.
For example, to convert some $\LaTeX$ code to putdown, you might do the
following.
getConverter().then( convert => {
const putdown = convert( someLaTeXString, 'latex', 'putdown' )
console.log( putdown )
} )
Thre are five formats that this function knows about. Two are output-only
formats: 'html'
and 'putdown'
. You cannot convert from these formats
into any other format. The other three are storage formats: 'latex'
,
'mathjson'
, and 'asciimath'
. The formats are case-insensitive, so you
can write 'LaTeX'
or 'MathJSON'
instead if you like. All of the three
storage formats can be converted into one another, and into any of the
output formats. So the only constraint is that the output format cannot be
'html'
or 'putdown'
.
The reason that this function is asynchronous is because some of those conversion functions can be run only once MathLive has been loaded, and so this function ensures that has happened before returning to you a converter instance. That way, the instance you receive is guaranteed to work immediately, and all of its methods can be synchronous. Note that many of the conversion functions are built into MathLive, and I'm simply making them available here and connecting them in all the transitive ways the user might need them.
Returns
-
Promise
a promise that resolves to a function that behaves as above