Mathematics in XHTML Demystified

Some pages hosted on present site are written in slightly extended version of XHTML that admits embedding of the simple mathematical expressions — subscripts, superscripts, fractions, operators and radicals. This XHTML extension, internally refered as M7-Markup is a side-product of XML MAIDEN project and originally it was oriented on XHTML newbies that are not familiar with XML and CSS, so the main goal was to keep markup as simple as possible and to stay very close to W3C XHTML. By design, scope of markup is limited to the simpliest mathematical expression and complex nesting patterns are not supported.
Markup for simple subscripts and superscripts is already present in most versions of XHTML, including XHTML 1.0 Strict, Transitional, Frameset, XHTML 1.1, XHTML 2.0 WD and excluding XHTML Basic. So one can reuse it and exploit elements sub and sup to mark subscripts and superscripts in XHTML. For example markup ax<sup>2</sup> + bx + c = 0 produces equation
ax2 + bx + c = 0
While <sub>13</sub>Al<sup>27</sup> + <sub>2</sub>He<sup>4</sup> = <sub>15</sub>P<sup>30</sup> + <sub>0<sub>n<sup>1</sup> yeilds
13Al27 + 2He4 = 15P30 + 0n1
Subscripts and supscripts only are not sufficient to display math formulae, we also need fractions, operators, radicals, matrices and a lot of other expressions that have no analog in XHTML. But XHTML is extensible language and developers can add new elements/attributes to basic markup. The simplest extension that the man can imagine is to add several attributes to span general purpose container. These attributes may carry math content that can be retreived using either CSS, DOM or XSLT and appropriately formatted. For example simple fractions can be encoded as follows th(x ± y) = <span n="th(x) ± th(y)" d="1 ± th(x)th(y)"/> th(2x) = <span n="2th(x)" d="1 + th²(x)"/> If appropriately formatted with CSS they will look like
th(x ± y) =
th(2x) =
Similar approach can be used to encode operators and radicals. For example integral over x from 0 to 1 can be encoded as B(m , n) = <span c="∫" a="0" b="1"/> x<sup>m − 1</sup>(1 − x)<sup>n − 1</sup>dx being formatted with CSS it produces
B(m , n) = xm − 1(1 − x)n − 1dx
For radicals one can introduce markup r = <span r="x² + y²"/> s = <span r="x³ + y³ + z³" x="3"/> and display it as
r =
s =
This approach can be used to embedd simple math expressions in XHTML. For more complex stuff it is not the best way to go as attributes may carry only simple character data and does not allow you to nest expressions. However it is good point to start from and later one may either switch to more advanced vocabulary or develop his/her own XHTML extension.

Document Type Definitions

DTD for M7-Markup is very simple and just adds several attributes to XHTML span container. <!ATTLIST span a CDATA #IMPLIED b CDATA #IMPLIED c CDATA #IMPLIED d CDATA #IMPLIED n CDATA #IMPLIED r CDATA #IMPLIED x (2|3|4) #IMPLIED> There are four flavours of M7-Markup, namely M7-T, M7-F, M7-S and M7-M that extend XHTML 1.0 Transitional, Frameset, Strict and XHTML 1.1 respectively. For more convenience new attributes defined in M7-T, M7-F DTDs are not prefixed and does not belong to any namespace (default namespace declarations do not apply directly to attribute names). However in more strict M7-S and M7-M DTDs math attributes must be prefixed and prefix should be defined on 'body' element as follows <body xmlns:s="http://www.xml.org/xml/schema/13de5e66"> Appropriate document type declarations are listed below:

M7-T

<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ATTLIST span a CDATA #IMPLIED b CDATA #IMPLIED c CDATA #IMPLIED d CDATA #IMPLIED n CDATA #IMPLIED r CDATA #IMPLIED x (2|3|4) #IMPLIED>]>
This DTD is also available from xml.org registry and can be declared as <!DOCTYPE html SYSTEM "http://www.xml.org/xml/schema/8d703386/m7t.dtd">

M7-F DTD

<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" [ <!ATTLIST span a CDATA #IMPLIED b CDATA #IMPLIED c CDATA #IMPLIED d CDATA #IMPLIED n CDATA #IMPLIED r CDATA #IMPLIED x (2|3|4) #IMPLIED>]>
This DTD is also available from xml.org registry and can be declared as <!DOCTYPE html SYSTEM "http://www.xml.org/xml/schema/13de5e66/m7f.dtd">

M7-S

<!DOCTYPE html SYSTEM "http://www.xml.org/xml/schema/13de5e66/m7s.dtd">

M7-M

<!DOCTYPE html SYSTEM "http://www.xml.org/xml/schema/13de5e66/m7m.dtd">

Note that most of the browsers does not process external DTDs, while those that process basically just waste bandwidth as these DTDs does not contain any useful information apart of character entity declarations, therefore if cases when no character entities are used in document it is recommended to omit document type declarations (i.e. serve document as well formed XML). Note also that there is a bug in W3C markup validator, as a result some of DTDs listed above are not processed propertly by W3C validator.

MIME types

Note that extended XHTML documents must be served using one of the following MIME types application/xhtml+xml, application/xml, text/xml and should never be served as text/html . If your server is configured properly then changing file extension to .xht, .xhtml or .xml should be sufficient.

Error handling rules

Apparantly not all combinations of proposed attributes make sense. For example the following markup is not correct: <span n="1" d="2" r="3" /> Exact error handling rules and other related documentation will be posted later.

Style sheets

Mathematical content carried by extra attributes is retreived and processed using small CSS stylesheet, therefore appropriate processing instruction <?xml-stylesheet type="text/css" href="math.css"?> should be placed before html element (if both style sheet and XHTML are located in the same directory). More style sheets and other documentation will be posted later.

Samples

Here are some sample pages: Sample⁰, Sample¹, Sample², Sample³, Sample⁴, Sample⁵, Sample⁶, Sample⁷, Sample⁸, Sample⁹. More samples will be provided later.

Last modified on 28-04-2005 by George Chavchanidze