-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebook-wtfs.xhtml
51 lines (51 loc) · 14.6 KB
/
ebook-wtfs.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Things You Should Know About Ebook Specs And Readers</title>
<meta name="author" content="Magnus Achim Deininger" />
<meta name="description" content="A summary of the weird things I came across writing the XHTML to ebook transcoders in use on this site." />
<meta name="date" content="2013-05-24T19:48:00Z" />
<meta name="mtime" content="2013-05-24T19:48:00Z" />
<meta name="category" content="Linear Algebra" />
<meta name="category" content="Articles" />
<meta name="unix:name" content="ebook-wtfs" />
</head>
<body>
<h1>Introduction</h1>
<p>So, <a href="/site-news:transcripts">now that this blog is available in several ebook formats</a>, I figured it'd be a good idea to sum up some of the problems I noticed while writing those scripts to transcode things on this blog to ebooks. You know, just 'cause they suck and you should know about them before you try to do yer own.</p>
<p>And before I start, I'd like to point out one thing that people probably aren't aware of: EPUB files are actually a ZIP archive of a collection of a bunch of XML files, which in turn use profiles very close to what's on the web right now. Now <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211">Amazon's kindlegen</a>, which produces MobiPocket .mobi files, which in turn are essentially Kindle ebooks without DRM, and despite Kindles being unable to read EPUBs, will work best if you feed it the raw, uncompressed contents of those EPUB files. I think that already set the theme for this bit. Right, let's get busy then.</p>
<img src="/jpeg/bad-ebook-file-extension" alt="not the most helpful of error messages"/>
<h1>Ebook Readers Actually Care About File Names</h1>
<p>That screenshot up there is the result of trying to open an ebook with a content document inside it with the file name extension "frob" instead of "xhtml" on a 4th Generation Kindle.</p>
<p>Now, some of you may not be aware of this, but filenames are actually bollocks. They carry no inherent meaning. This is why on UNIX systems there are tools like <em>file</em>, which will tell you what kind of content is in a given file. But on Windows, there's this weird trend of assigning a special meaning to the last couple letters after the last dot ('.') in this file name. The idea is that these couple letters will help the operating system, and applications running on it, in figuring out what kind of file it's dealing this. Except this is completely bogus.</p>
<p>On Kindles, you actually give <em>kindlegen</em> the manifest of an EPUB ebook so it can work its magic. This manifest contains all files you're going to use, <em>along with a MIME type that precisely specifies what type of file the Kindle will be dealing with</em>. There is <em>no</em> reason whatsoever to get file names involved in any way! It makes no sense at all. Seriously, none. And the error message you get on a Kindle is really kind of useless, too. Both for the author of the ebook and the reader - because, why would either of them assume you care about the file name of a file you somehow mangled into an opaque archive. Someone pass a memo to those project leads, please!</p>
<p>By the way, for anyone curious about this, or those curious about whether this is solved in later firmware releases for your Kindle, here's <a href="/mobi/good-ebook.mobi">the working Kindle file</a> and <a href="/mobi/bad-ebook.mobi">the one that doesn't</a>. I really only changed the file name, which you can see if you unzip <a href="/epub/good-ebook.epub">this working EPUB version</a> and <a href="/epub/bad-ebook.epub">this EPUB with the contents of the broken one</a>. Colons in filenames seem to cause similar problems with most EPUB readers, weird as that is (ZIP will handle colons just fine, so will UNIX file systems).</p>
<h1>Terrible SVG Support</h1>
<p>Two things: any non-XML files are a pain to work with in an XML pipeline - SVGs are XML-based image files - and the SVG specs are <em>old</em>. They came out in 2001 to be precise, so in computer terms they're the equivalent of ancient Roman Aqueducts. Yet for some reason, SVG image support in modern products is still a kind of an afterthought, and it shows. The EPUB standards authors were nice enough to include support for these files in the EPUB standards, which is great in principle, yet they included content negotiation mechanisms so that SVG support is still technically optional. This in turn means that the content authors are forced to include alternatives for their SVG content in case the ebook reader author couldn't be arsed to support this format.</p>
<p>Then there are those special ebook readers that might read SVGs fine as separate files, but they can't handle it if you include the SVG's source directly in the XHTML source of your EPUB. Now that's just really weird.</p>
<p>Fortunately, support in fourth generation Kindles is decent, except that you can't use SVGs as cover images - beats me why that is, and why kindlegen won't just transform the SVG to a format the Kindle can handle.</p>
<p>All in all, support is pretty half-assed, and I don't get why. SVGs are great: they scale well because it's a vector image format, the text is present as actual, searchable, highlightable text and in a pinch you can include encoded versions of JPEGs and PNGs if you really must have raster images. You'd think publishers would jump at the idea of using those files. I can see how on a device with limited processing power you'd not want to decode the files every time you encounter them, but given that at least Kindles are able to do so they could just store temporary renders of it if that really were a problem.</p>
<h1>The Navigation Document Structure Is Bollocks</h1>
<p><a href="http://www.idpf.org/epub/30/spec/epub30-contentdocs.html#sec-xhtml-nav">Here's the spec if you're interested</a>. I'm picking on this one in particular because the semantic issues are the most apparent. There's similar issues in the other profiles. This applies to both EPUB and Kindle ebooks.</p>
<p>If you look at the specification, you'll see that in the introduction this specification defines that navigation documents are used to create tables of contents for your ebook. That's good. It then goes on to define that navigation documents must be proper XHTML content documents - only that their definition of an XHTML content document is really an HTML 5 document in XHTML notation, <a href="http://www.idpf.org/epub/30/spec/epub30-contentdocs.html#sec-xhtml-conf-content">as specified here</a>, <a href="http://www.w3.org/TR/html5/the-xhtml-syntax.html#the-xhtml-syntax">and here</a>. This is why they can then use the <em>nav</em> element, which is not really part of XHTML in any sense of the way, but rather an element introduced in HTML 5. Using the XHTML MIME type, namespace and doctype as in the examples is then, of course, quite misleading.</p>
<p>And then there's the example for that navigation document. It's really stripped down - just the <em>nav</em> element and exemplary content. Looks like it could be the whole file, except you really need all the other XHTML boilerplate. Then the example is using an <em>h2</em> heading: this is bad if it's the only assumed content on the page. Hell, chances are you have a document dedicated to just the main table of contents, meaning you'll have only one heading in there and that should be an <em>h1</em>.</p>
<p>This wouldn't be such a big deal if I didn't know for a fact that content authors have some real issues with using the right heading for whatever it is they want to get across. Just have a look at <a href="http://www.gutenberg.org/">a few random ebooks at Project Gutenberg</a>, and you'll see most of them don't have much of a problem starting their document with <em>h2</em> and <em>h3</em> - sometimes using higher level headings later, or even using the heading levels for visual effects.</p>
<p>And then comes the coup de grâce: the standard forces you to use an <em>ol</em>, <em>li</em>, <em>a</em> construct - that's <em>ordered list</em>, <em>list item</em> and <em>regular hyperlinks</em>, and a good guideline in principle. Except <em>sub-headings have to be enclosed in <em>span</em>-elements instead of one of the dedicated HTML heading elements</em>! Are you kidding me? <em>span</em>s are meaningless, blind, inline markup elements, whose only point is that they can be used to define textual styling without conveying any semantic meaning - but these are clearly sub headings, which is an important semantic aspect that a screen reader would want to know about. Who the hell wrote this!? Use a goddamn heading, you only have like, five levels of nesting left!</p>
<p>Hello~? Semantic markup plzkthx?</p>
<h1>Nonexistent MathML Support</h1>
<p>I write a lot about maths, and as anyone who does this can tell you, mathematical texts require a lot of funky formulas. You can emulate a lot of the typical mathematical layout with tables and various CSS formatting options, but getting this stuff to look nice is a huge pain in the bum. This is why all real scientists typically use LaTeX as opposed to, say, Word for writing documents: all the maths looks ugly in Word. Very. Ugly.</p>
<p>And this is exactly where MathML comes in. Like SVG, this is a fairly old format, only that this one allows you to mark up mathematical formulas instead of vector graphics. Like SVG it's supported in EPUB - kind of. Like SVG it's part of the new HTML 5 standard. Like SVG most decent, modern browsers support it. Like SVG it's XML-based, so it works great in your XML pipeline. Unlike SVG, your Kindle won't know what to do with MathML, so you end up with a lot of gibberish. That means you have to jump through quite a few hoops to get formulas to appear nicely in your ebooks: I ended up using a set of XSLT stylesheets that translate MathML to SVG, and then running inkscape over the output to turn the text into SVG line art. Which sucks. And you lose the structured data that was used to create those formulas, meaning they can never reflow and they look out of place in pure text paragraphs.</p>
<p>Check the makefile that comes with <a href="source-code">this site's source code</a> if you're curious as to just how ugly that scripting ended up.</p>
<h1>Who Came Up With This XML+ZIP Trend?</h1>
<p>This has to stop. Seriously, what's up with that? First office programmes and now EPUB. Here's why this is bad: it's a pain to work with, and it doesn't make sense in the first place. EPUB is basically a set of subprofiles for XHTML, a manifest and a useless sentinel file that contains the MIME type of the archive. As a set of files, this allows the content author to structure the content documents - individual XHTML files, e.g. one for each chapter; you could also create directories for each chapter or group image files you'll be using together in some way. You then ZIP up the whole thing and you get one file to distribute.</p>
<p>Having a single file to lug around is a good thing, I'm not denying that. But choosing ZIP for the job just blows. First, let's not forget that XHTML, SVG, MathML and most other content are really nothing more than XML files. Working with several files in an XML pipeline is a chore; it's much nicer if you have one big XML file with all the content. You could still structure it whatever way you want if you so desired and if your XML container format supported it - and I can't be the only one thinking that way, because the folks over at Microsoft apparently got the message for their XML office file formats. You actually have a choice as to whether you want to save those as a ZIP file with XML documents inside or whether you'd instead prefer to save them in a single, large XML file.</p>
<p>Working with ZIP files in an XML pipeline is even worse than working with a bunch of small XML files. If you only have one huge XML file, you can just run XSLTs over it for processing. If you have a ZIP file with lots of small files in it, you need to create a script to unzip it, do your processing and then ZIP it back together.</p>
<p>Also, why'd it have to be ZIP, anyway? At least you could use something simple like CPIO or TAR. Those come in fully text-based variants, too, so you have a slight chance of processing them with XSLT.</p>
<p>Oh, you'd like it not just hierarchically structured but also compressed? How about taking a page from the same UNIX book that tells you all about TAR and CPIO: keep it plain and simple and in one, big file, then just run gzip or bzip2 or lzma over it. There, now it's one small, compressed file. Just like you wanted. And it's pretty easy to determine what's in it, too: just uncompress the first 4k or so and parse the XML. No need to force content generators to include an uncompressed file entry with the MIME type as the first file in the archive. Not that most readers gave much about MIME types to begin with. <em>cough</em></p>
<h1>Why Is There No DocBook Support?</h1>
<p>Okay this isn't specific to DocBook, really, but rather: if the lot of ye tried to so hard to stick to established web tech and you sort of established that it'd be great if it were limited to semantic markup only, so that the users get to decide things like the font size and colour and there's no forced line breaks and page sizes like with PDFs but rather reflowing layouts, why would you base it on XHTML+CSS and then come up with a plethora of subprofiles for it? EPUB people, this means you! Well, the Kindle folks too, in a way.</p>
<p>Here's my angle: DocBook has been around for decades. It enforces semantic markup <em>and</em> the latest version is XML-based. Before that it was SGML, which is like a superset of HTML. Why would you even think of creating yet another set of subprofiles to XHTML to try and limit it to a feature set that is essentially DocBook, but as a crossbreed with HTML 5? And then you go and force poor semantics with some of those profiles, like the Navigation Documents.</p>
<p>But if you really needed it to be web-based, at the very least you could've used, like, Atom or another syndication format as the basis for EPUB. Because, you know, it's older than EPUB - 2005 vs 2007 - and already solves the problems you've been trying to solve. That'd even have solved the thing about needing a packaging format to conveniently wrap up your content in. That's what a syndication format is for: just use Atom and embed XHTML content files. That also makes it great to work with in an XML pipeline - although Atom would allow you to keep the files separate if you really wanted that. And you don't need a separate navigation document either, because that's implicit with the feed layout.</p>
<p>Or, of course, you could've used a dedicated markup format for books. Like DocBook! This article is also available as a DocBook 5 file, by the way. <em>wink</em></p>
</body>
</html>