Wiris

Documentation / MathType

  • Demos
  • Visit our website
  • Downloads
  • Contact us
  • MathType

    • WirisQuizzes

      • Nubric

        • CalcMe

          • MathPlayer

            • Store FAQ

              • MathFlow

                • BF FAQ

                  • Miscellaneous

                    • Wiris Integrations

                      • Home
                      • MathType
                      • Technical documentation
                      • MathType for HTML editors
                      • Reference

                      Modified XML encoding for MathML

                      Reading time: 1min

                      This article describes how MathType modifies XML characters in MathML when formulas need to be stored in contexts where raw XML cannot be used safely, such as HTML attributes or platforms that filter unrecognized XML tags.

                      Requirements/Prerequisites:

                      • MathType HTML integration.
                      • Access to the encoded MathML source.
                      • Basic familiarity with XML and MathML.

                      Concepts:
                      MathML is XML-based. In some environments, raw XML characters may be filtered, parsed incorrectly, or removed. To prevent this, MathType may replace reserved XML characters with alternative characters.

                      Reference details

                      MathType imports and exports MathML, which sometimes cannot be placed directly inside HTML files. For example, the Moodle platform filters some HTML tags (APPLET, OBJECT, EMBED, etc.) and all unrecognized XML tags, and so it removes any MathML formula. This also occurs when the MathML appears inside an HTML attribute (for example, the SRC attribute of an IMG tag) and the browser, wrongly, tries to parse it.

                      In these situations, the 5 reserved characters of XML are replaced by other characters, as shown in the following table:

                      Original XML character Replacing character
                      < (#3C) « (#AB)
                      > (#3E) » (#BB)
                      & (#26) § (#A7)
                      " (#22) ¨ (#A8)
                      ' (#27) ` (#60)

                      Then, recovering the MathML from the modified version is as simple as undoing the replacement. The following XSLT example reverses the character replacements and restores the original XML characters.

                      <?xml version="1.0" encoding="UTF-8"?>
                      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                       <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
                       <!-- template for text -->
                       <xsl:template match="child::text()">
                       <!-- « (#AB), » (#BB), § (#A7), ¨ (#A8), ` (#B4) -->
                       <xsl:variable name="text" select="translate(.,'&#xAB;&#xBB;&#xA7;&#xA8;','&lt;&gt;&amp;&quot;')"/>
                       <!-- ` (#B4) -->
                       <xsl:value-of disable-output-escaping="yes" select='translate($text,"&#xB4;","&apos;")'/>
                       </xsl:template>
                       <!-- template for other nodes (including attributes) -->
                       <xsl:template match="@*|*">
                       <xsl:copy>
                       <xsl:apply-templates select="@*|node()"/>
                       </xsl:copy>
                       </xsl:template>
                      </xsl:stylesheet>

                      Was this article helpful?

                      Give feedback about this article

                      Related Articles

                      • MathML makes elementary math accessible
                      • MathType MTEF v.5 (MathType 4.0 and later)
                      • Content MathML
                      • API services

                      Modified XML encoding for MathML

                      Reference details

                      Empowering STEM education

                      MathType

                      • Office Tools
                      • LMS
                      • XML
                      • HTML

                      WirisQuizzes

                      Nubric

                      Integrations

                      Solutions

                      • Education
                      • Publishing houses – platforms and interactive
                      • Publishing houses – Print and digital
                      • Technical writers

                      Pricing

                      Downloads

                      Blog

                      • Success stories

                      About us

                      • Careers
                      • Partnership

                      Contact Us

                      Contact Sales

                      European union (European Regional Development Fund) and 1EdTech (TrustEd Apps Certified)
                      • Cookie Policy
                      • Terms of Use
                      • Privacy Policy / GDPR
                      • Student Data Privacy
                      • Compliance
                      • Cookie Settings

                      © Wiris 2026

                      Expand