-
MathType
-
WirisQuizzes
-
Nubric
-
CalcMe
-
MathPlayer
-
Store FAQ
-
MathFlow
-
BF FAQ
-
Miscellaneous
-
Wiris Integrations
Modified XML encoding for MathML
Reading time: 1minReference describing the modified XML encoding used by MathType to safely store MathML in environments that cannot contain raw XML.
Summary
MathML is an XML-based language. Some platforms and HTML contexts cannot safely store raw XML because reserved XML characters may be filtered, escaped incorrectly, or interpreted as HTML markup.
To avoid these issues, MathType uses a modified XML encoding that replaces the five reserved XML characters with alternative Unicode characters. The original MathML can be restored by reversing these substitutions.
Why a modified encoding is used
MathType stores formulas as MathML. In some environments, however, embedding raw MathML directly is not possible. Typical examples include:
- HTML attributes (such as
data-mathml). - HTML editors that sanitize unknown XML tags.
- Content management systems that remove embedded XML.
- Legacy platforms that treat MathML as invalid HTML.
Using the modified encoding preserves MathML while allowing it to be safely stored within HTML content.
Character mapping
The following substitutions are applied.
| XML character | Replacement character |
|---|---|
< |
« |
> |
» |
& |
§ |
" |
¨ |
' |
` |
To recover the original MathML, replace each encoded character with its corresponding XML character.
Example
Original MathML:
<mi>x</mi>
Stored using the modified encoding:
«mi»x«/mi»
Typical use cases
The modified encoding is commonly found in:
- The
data-mathmlattribute of legacy MathType image formulas. - Exported HTML content.
- Integrations that store MathML inside HTML attributes.
See Migrate MathType image formulas to MathML for a practical migration example.
Decoding
Decoding simply consists of reversing the character substitutions listed above. Any programming language capable of replacing characters or strings can restore the original MathML. For example:
| From | To |
|---|---|
« |
< |
» |
> |
§ |
& |
¨ |
" |
` |
' |
Legacy XSLT example
Earlier versions of the documentation included an XSLT stylesheet that demonstrated how to automatically reverse the modified encoding. The same result can be achieved with any XML or text-processing library that supports the character substitutions shown above.
Notes
- This encoding does not modify the MathML structure or semantics.
- Only the five reserved XML characters are replaced.
- The encoding is fully reversible.
- New integrations working directly with MathML usually do not need to apply this encoding manually.