This is the first in a series of posts describing some of the lesser-known features in the ePub spec. Many of them aren’t implemented by any readers, yet, but can provide some interesting functionality.
The first is “fallbacks.” As ePub developers know, only a small handful of content types are supported by the spec: XHTML, DTBook, SVG, and a few binary image formats. Missing from this list are any kinds of video or audio, as well as other types of XML. This restriction leads to the assumption that ePub books can’t support these features.
In fact, any type of content can be included in an ePub, including both video and audio, as long as “fallback” is included. A fallback is an equivalent representation of that content in one of the supported formats.
Even novice HTML authors are familiar with the fallback concept — the same idea is expressed in the IMG element with “alt” text. Just like the
alt attribute specifies some textual representation of the image, a fallback in ePub expresses the content in a native format for users who can’t view the real thing.
A common request of educational publishers is to be able to include MathML, a type of XML, in mathematics books. MathML is not directly supported in ePub (though it is likely be added in the future). However, it is possible to include a reference to a MathML file in the ePub book, perhaps as an “examples” page, with a fallback to an XHTML equivalent (perhaps one which includes static image examples).
Here’s some sample MathML:
&lt;math&gt; &lt;apply&gt; &lt;minus/&gt; &lt;apply&gt; &lt;times/&gt; &lt;ci&gt;x&lt;/ci&gt; &lt;apply&gt; &lt;plus/&gt; &lt;apply&gt; &lt;divide/&gt; &lt;ci&gt;a&lt;/ci&gt; &lt;ci&gt;b&lt;/ci&gt; &lt;/apply&gt; &lt;ci&gt;c&lt;/ci&gt; &lt;/apply&gt; &lt;/apply&gt; &lt;cn&gt;1&lt;/cn&gt; &lt;/apply&gt; &lt;/math&gt;
In a MathML-capable rendering system this will appear as:
In the OPF you declare the MathML and the fallback as:
&lt;!-- MathML --&gt; &lt;item id=&quot;math&quot; href=&quot;math.xml&quot; fallback=&quot;math-fallback&quot; media-type=&quot;application/mathml+xml&quot;/&gt; &lt;!-- XHTML 1.1 fallback --&gt; &lt;item id=&quot;math-fallback&quot; href=&quot;fallback.html&quot; media-type=&quot;application/xhtml+xml&quot; /&gt; &lt;/manifest&gt; &lt;spine toc=&quot;ncx&quot;&gt; &lt;itemref idref=&quot;math&quot;/&gt; &lt;/spine&gt;
The specification is unclear about how this should be referenced in the NCX file; logically I should be able to point to the main document and let the reading system handle the fallback:
&lt;navPoint id=&quot;navpoint-1&quot; playOrder=&quot;1&quot;&gt; &lt;navLabel&gt; &lt;text&gt;MathML example&lt;/text&gt; &lt;/navLabel&gt; &lt;content src=&quot;math.xml&quot;/&gt; &lt;/navPoint&gt;
…but this doesn’t validate in epubcheck:
ERROR: ../math.epub/OEBPS/toc.ncx(18): hyperlink to non-standard resource ‘OEBPS/math.xml’ of type ‘application/mathml+xml’
I’m not sure if I’m declaring it wrong or if epubcheck should allow this case.
Note that the above will not work in Bookworm, as it doesn’t think it understands MathML (in fact it could render the above in Firefox). Adobe Digital Editions displays nothing at all — it can’t render the MathML, but also doesn’t regress to the fallback.
The above is an example of fallbacks used in Out-of-line XML Islands, but it is also possible to embed external formats as Inline XML islands.