Secrets of ePub: Out-of-line XML islands and fallbacks
by Liza Daly
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:
<math>
<apply>
<minus/>
<apply>
<times/>
<ci>x</ci>
<apply>
<plus/>
<apply>
<divide/>
<ci>a</ci>
<ci>b</ci>
</apply>
<ci>c</ci>
</apply>
</apply>
<cn>1</cn>
</apply>
</math>
In a MathML-capable rendering system this will appear as:
In the OPF you declare the MathML and the fallback as:
<!-- MathML -->
<item id="math"
href="math.xml"
fallback="math-fallback"
media-type="application/mathml+xml"/>
<!-- XHTML 1.1 fallback -->
<item id="math-fallback"
href="fallback.html"
media-type="application/xhtml+xml" />
</manifest>
<spine toc="ncx">
<itemref idref="math"/>
</spine>
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:
<navPoint id="navpoint-1" playOrder="1">
<navLabel>
<text>MathML example</text>
</navLabel>
<content src="math.xml"/>
</navPoint>
…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.
Comments
We clearly need more information in the specs about the relationship between DTBook’s NCX and EPUB.
I assume that items in the NCX should behave like items in the spine and use the fallback attribute, but I don’t remember reading about it in the specs.
epubcheck is most likely looking for “OPS Core Document” formats in this case: either XHTML or DTBook.
This is clearly epubcheck error. I remember that we discussed how links are supposed to work with fallbacks at one of the IDPF telecons and the consesnus was that this is the only sane interepretation. Can you create and issue for epubcheck and attach your sample file?
Will do, Peter. Thanks.
Added as issue 50 in epubcheck.
I’m very glad you mentioned MathML in ePub. This is something we at Design Science are very interested in. By the way, readers of this post may also be interested in the “Ebooks for Math and Science” group we have over at LinkedIn: http://www.linkedin.com/groups?gid=1945452.
Paul Topping,
Design Science, Inc.
Thank you for one of the few geeky blogs on ePub! Like Paul I am all in favour of MathML instead of dumb “islands”, and hope that eBook readers will start to render it directly. We are working on an eBook reader for iPhone that uses TeX for rendering. It’s looking good. :-)
Oh, is there an RSS feed for this blog?
Kaveh: Yes, there’s a feed.
Most browsers will provide a method to auto-identify a feed (in Firefox there will be an icon next to your URL bar), but I also added a “Subscribe” link at the top.
[...] item is a standard OPS document; the second is the Flash movie itself. Notice that we declared a fallback to another item. That item needs to be a supported type, like an [...]
[...] are two methods to include “foreign” media types in ePub. The first is out-of-line items which have separate fallback items, either out-of-line XML in another vocabulary, or a [...]