
I recently began working on an e-book of my own and quickly realized that this space has a lot of room for innovation and reform. First off, I had a hard time even figuring out how the EPUB format works and what it takes to create it. Hopefully this will clear some things up for you.
How does epub format work?
An ePub document is really a collection of XHTML files, stylesheets and images which are all contained together in ZIP format. It is basically like a little self contained website. This format tells the e-reader how to display the book to the user.
Here’s an example of an EPUB .xhtml file skeleton:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>Pride and Prejudice</title>
<link rel="stylesheet" href="css/main.css" type="text/css" />
</head>
<body>
...
</body>
</html>Each .xhtml file represents a chapter of the book. You can embed images, styles, etc in the document just like you would a standard XHTML document. If you’re familiar at all with HTML this won’t come as too much of a shock. If you’re not familiar with HTML then you’re in luck! There are some tools out there which help you organize your ebook visually. Be forewarned, however, they are not easy to use.
Sigil – This is a multi-platform EPUB editor that is very simple and very small. The overall user experience (as with many ebook editors) is pretty bad though. It took me an hour or so to figure out how to use it but it works well overall. The main thing I liked about Sigil is that it gives you pretty deep control over the styling and organization of the ebook. You’ll need to understand HTML and CSS at least a little bit though since you must use it for styling.
epubbud – While the user experience may be pretty rough, epubbud is one of the only websites I could find that actually had decent EPUB editing functionality. The main issue I ran into here was that their text editor would constantly mess up my formatting. It made it nearly impossible to format the book the way that I wanted to.
Calibre – I used Calibre for about an hour and then gave up. It definitely works and comes pretty highly recommended but I just didn’t have luck with it, maybe you will though!
Table of contents
The table of contents for an EPUB book is stored in a .ncx file. This file must conform to a specific format and must reference chapter files exactly.
Here’s an example of a .ncx skeleton file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx version="2005-1" xml:lang="en" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>
<!-- The following four metadata items are required for all NCX documents,
including those conforming to the relaxed constraints of OPS 2.0 -->
<meta name="dtb:uid" content="123456789X"/> <!-- same as in .opf -->
<meta name="dtb:depth" content="1"/> <!-- 1 or higher -->
<meta name="dtb:totalPageCount" content="0"/> <!-- must be 0 -->
<meta name="dtb:maxPageNumber" content="0"/> <!-- must be 0 -->
</head>
<docTitle>
<text>Pride and Prejudice</text>
</docTitle>
<docAuthor>
<text>Austen, Jane</text>
</docAuthor>
<navMap>
<navPoint class="chapter" id="chapter1" playOrder="1">
<navLabel><text>Chapter 1</text></navLabel>
<content src="chapter1.xhtml"/>
</navPoint>
</navMap>
</ncx>Defining components of your ebook
The .opf file defines the different components of an ebook like metadata, file manifest and linear reading order. There are a lot of important sections to a .opf document.
Here’s a sample skeleton to help you understand how it works:
<?xml version="1.0"?>
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>Pride and Prejudice</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="BookId" opf:scheme="ISBN">123456789X</dc:identifier>
<dc:creator opf:file-as="Austen, Jane" opf:role="aut">Jane Austen</dc:creator>
</metadata>
<manifest>
<item id="chapter1" href="chapter1.xhtml" media-type="application/xhtml+xml"/>
<item id="stylesheet" href="style.css" media-type="text/css"/>
<item id="ch1-pic" href="ch1-pic.png" media-type="image/png"/>
<item id="myfont" href="css/myfont.otf" media-type="application/x-font-opentype"/>
<item id="ncx" href="book.ncx" media-type="application/x-dtbncx+xml"/>
</manifest>
<spine toc="ncx">
<itemref idref="chapter1" />
</spine>
<guide>
<reference type="loi" title="List Of Illustrations" href="appendix.html#figures" />
</guide>
</package>Writing it yourself
There is always the option of writing an ebook yourself, though I don’t necessarily recommend it. Before you decide to go down this road I would encourage you to checkout some of the EPUB management apps mentioned above. If you do end up creating your own files manually, Calibre has a nice conversion feature to get your files into the proper EPUB format. I haven’t used it personally so I’m not sure how well it actually work.
The EPUB specification is actually pretty descriptive and well written so I’d certainly recommend checking that out if you are looking to write your own EPUB book manually.
Please let me know if you have any questions or other issues in the comments section below and I will try to help you out as best as I can. Thanks for reading!
Tweet



