-
Notifications
You must be signed in to change notification settings - Fork 21
Public API
TeXZilla.toMathMLString = function(aTeX, aDisplay, aRTL, aThrowExceptionOnError)
converts the TeX string aTeX into a MathML source and return the corresponding string. The optional boolean aDisplay and aRTL indicates whether the MathML output should be in display mode and in RTL direction respectively. The optional boolean aThrowExceptionOnError indicates whether TeXZilla should throw an exception when parsing fails.
TeXZilla.toMathML = function(aTeX, aDisplay, aRTL, aThrowExceptionOnError)
is the same as TeXZilla.toMathMLString, but returns a MathML DOM element. This
requires to have a DOMParser instance supporting the application/xml
type (see TeXZilla.setDOMParser below).
TeXZilla.toImage = function(aTeX, aRTL, aRoundToPowerOfTwo, aSize, aDocument)
This function first converts the TeX string aTeX into a display MathML element
which is temporarily inserted into a HTML document.
The MathML element is then measured and moved from the HTML document to
a SVG document. This SVG document is in turn serialized as a base64 string
which is finally used as the src
attribute value of an <img>
element.
The function returns that <img>
element.
The optional boolean parameter aRTL
indicates the directionality of the MathML element. The optional boolean
parameter aRoundToPowerOfTwo indicates whether the size of the images
should be rounded to a power of two and is useful
for use in a WebGL context. The optional parameter
aSize indicates the font-size in pixels of the MathML element and defaults
to 64px
. Finally, the optional parameter aDocument indicates the host HTML
document to use for the measuring step and defaults to window.document
.
This requires to have DOMParser and XMLSerializer instances available (see TeXZilla.setDOMParser and TeXZilla.setXMLSerializer below) as well as a DOM Level 1 API to manipulate trees, support for the HTMLImageElement and the window.btoa function. Because of the measuring step, because the size of the MathML element is context dependent, and because of the API required, this function is really likely to only work in the a Web browser context, typically to generate dynamic mathematical formulas in 2D or WebGL canvas.
This requires TeXZilla >= 0.9.7.
TeXZilla.filterString = function(aString, aThrowExceptionOnError)
applies the stream filter to aString and returns the output string. The optional boolean aThrowExceptionOnError indicates whether TeXZilla should throw an exception when parsing fails.
This requires TeXZilla >= 0.9.7.
TeXZilla.filterElement = function(aElement, aThrowExceptionOnError)
applies the stream filter to each text node inside descendant elements of aElement. The optional boolean aThrowExceptionOnError indicates whether TeXZilla should throw an exception when parsing fails.
This requires to have a DOMParser instance available (see
TeXZilla.setDOMParser below) as well as the corresponding DOM Level 1 API
to handle trees.
This requires TeXZilla >= 0.9.7.
TeXZilla.getTeXSource = function(aMathMLElement)
returns the TeX source attached to aMathMLElement via a semantics annotation or null if none is found. aMathMLElement is either a string or a MathML DOM element. This requires to have a DOMParser instance available (see TeXZilla.setDOMParser below) and the corresponding DOM API to handle trees.
TeXZilla.setDOMParser = function(aDOMParser)
sets TeXZilla's DOMParser to the aDOMParser object implementing the
DOMParser interface. Note that
TeXZilla tries to automatically initialize its DOMParser to new DOMParser()
and otherwise create a dummy instance throwing exception when used.
TeXZilla.setXMLSerializer = function(aXMLSerializer)
sets TeXZilla's XMLSerializer to the aXMLSerializer object implementing the
XMLSerializer interface. Note that
TeXZilla tries to automatically initialize its XMLSerializer to new XMLSerializer()
and otherwise create a dummy instance throwing exception when used.
This requires TeXZilla >= 0.9.7.
TeXZilla.setSafeMode = function(aEnable)
enables or disables TeXZilla's safe mode as indicated by the boolean aEnable.
By default safe mode is disabled but if you enable it, MathML features like href
or maction
that are known to be usable for XSS injections will be ignored.
This requires TeXZilla >= 0.9.7.
TeXZilla.setItexIdentifierMode = function(aEnable)
enables or disables
itex identifier
mode as indicated by the boolean aEnable.
By default this is disabled but if you enable it, a sequence of basic latin letters
(a, b, ... z, A, B, C, ..., Z) such as $pin$
will generate a single MathML
token <mi>pin</mi>
. Other letters e.g. Greek or Arabic will still be treated
as individual tokens. This requires TeXZilla >= 0.9.7.