data
attributes to each math element This math will have a data-mathml
attribute
containing the MathML representation of the expression, and a
data-original
attribute holding the original TeX format
of the expression. The results are shown below the typeset
expression. The semantic-enrichment and speech attributes are
removed for easier viewing. Note that <
,
>
and &
are encoded as entities
within the attribute values when the tag is serialized, but
node.getAttribute('data-mathml')
would give a string
where the entities would be replaced by their usual characters.
This example shows how to automatically generate a
data-mathml
attribute on the HTML output for each math
expression that contains the serialized MathML version of the
expression. It also adds a data-original
attribute that
gives the original form of the expression (i.e., the original TeX or
MathML markup). These attributes could be picked up by other tools
that may need access to the mathematics after it has been converted to
HTML or SVG tags, for example.
The process uses the startup.ready()
function to do
the normal startup, then attaches a post-filter to the output jax that
looks up the original format of the math, sets that
data-original
attribute to that, and uses the
startup.toMML()
function to set the
data-mathml
attribute to the serialized MathML for the
expression using the internal MathML representation generated by
MathJax. Some attributes are removed to simplify the structure.
Finally, we wait for the initial typesetting to comple using the
MathJax.startup.promise
, and when it dos, we transfer the
mjx-container
node to the output area, removing some
attributes and showing each attribute on a separate line for
clarity.