Ch.2: EPUB

How EPUB and the HTML it is made of came about and how they are built, from Berners-Lee's 1989 proposal to EPUB 3.3. Written from the original documents and specifications.

26 flashcards · Computer Science · by lakesare

Part of Public › PDF vs EPUB: file formats explained · 3 courses

  1. [What an EPUB is] What is an EPUB file?

    A ZIP file of a small website: one XHTML page per chapter, CSS, fonts and images, plus three small files that describe the book. Rename book.epub to book.zip and any ZIP program opens it. The W3C's overview of the format says an EPUB file is essentially just a ZIP file with some information that lets reading apps recognise it.Source: EPUB 3 Overview, §1.1 and §2

  2. [What an EPUB is] What does it mean that the text of an EPUB reflows?

    The reading app breaks the text into lines and pages itself, to fit your screen and the font size you chose. The publisher does not decide the line breaks or page breaks in advance.Source: EPUB 3 Overview, §5.1 and §6.1

  3. [What an EPUB is] Why is a PDF awkward to read on a phone, while an EPUB is not?

    A PDF page has a fixed size and layout, so the phone shows the whole page shrunk; an EPUB is laid out again for the phone's screen. A fixed page is what PDF was made for: John Warnock's 1991 memo that started PDF asked for documents that can be viewed on any display and printed on any printer.Source: Warnock, The Camelot Project (1991), EPUB 3 Overview, §5.1

  4. [What an EPUB is] A web page also reflows when the browser window gets narrower. What does an EPUB reading app do beyond that?

    It cuts the text into pages, and applies the reader's own font size, line spacing and word spacing to the book. The text is laid out again for every change, so it still fits the screen. The W3C overview notes that HTML was designed for such flexible layout, but many web sites today use layouts that are less flexible.Source: EPUB 3 Overview, §5.1 and §9

  5. [What an EPUB is] Is it true that accessibility for blind and visually impaired readers is a side feature of EPUB?

    No: it is a main design goal. The W3C overview says EPUB is designed to maximise accessibility for the visually impaired. Text that adapts to any screen and font size has been a primary design consideration in every version of EPUB.The overview also argues that accessible books are worth more: they work on more devices and are easier to reuse.Source: EPUB 3 Overview, §5.1 and §9

  6. [What an EPUB is] Any text can be read aloud by a speech synthesiser, and an HTML <audio> element can play a recording, but the <audio> element does not know which paragraph is being spoken at which moment.What does an EPUB media overlay add?

    A file that pairs each paragraph (or sentence) of a chapter with a time range in a recorded human narration, so the app highlights the text as it is spoken. The file is SMIL, a W3C format for timing multimedia. Each <par> element pairs a <text src="chapter1.xhtml#p1"/> with an <audio src="…" clipBegin="…" clipEnd="…"/>. The publisher can name a CSS class for the element being spoken.The specification says this gives a continuous listening experience that traditional audio embedding cannot offer…

  7. [What an EPUB is] On a web page, <img src="https://…"> can load a picture from any server.Which files may an EPUB chapter load from the web instead of from inside the ZIP?

    Only audio, video and fonts (plus data a script fetches); images, stylesheets and the chapters themselves must be inside the EPUB. The exceptions exist because audio and video files are large, and fonts are not essential to showing the text.The specification strongly encourages putting everything inside the ZIP anyway, so the whole book works without a connection, and recommends https for anything outside.Source: EPUB 3.3, §3.6 Resource locations

  8. [What's inside an EPUB file] What does a minimal EPUB chapter file look like, and how does it differ from an ordinary .html page?

    An HTML page written as XML (XHTML): the <html> element declares the XHTML namespace with xmlns, and every element must be closed. xmlns="http://www.w3.org/1999/xhtml" says the elements are HTML; xmlns:epub="http://www.idpf.org/2007/ops" allows EPUB's own attributes such as epub:type. The <link rel="stylesheet"> works as on the web; as an empty element it ends with a slash. The first line, <?xml …?>, is the optional XML declaration.Source: EPUB 3.3, §6.1, EPUB 3.3, §1.6

  9. [What's inside an EPUB file] An EPUB chapter (an .xhtml file) has a <p> without its </p>. What happens?

    An error: XHTML must be well-formed XML (every tag closed), so a browser renders only the part before the error. An .html page silently fixes it. The same markup, opened in Chrome once as .html and once as .xhtml. Chrome shows an error box and renders the page only up to the first error (here the end of the file, so all text is still visible).Source: WHATWG HTML, §1.8, EPUB 3.3, §6.1.2

  10. [What's inside an EPUB file] How is the table of contents of an EPUB written?

    As an HTML <nav epub:type="toc"> containing an <ol> of links to the chapters, in its own XHTML file (here nav.xhtml). Nested <ol> lists give sub-sections. The file is marked in the manifest with properties="nav".Surprise: many reading apps build their own contents menu from this <nav> and keep only the text of the links; images, maths and inline styles inside the links are lost.Source: EPUB 3.3, §7.3 and §7.4.2, EPUB 3 Overview, §4.2

  11. [What's inside an EPUB file] On a web site, the order of pages is given only by the links between them.Where does an EPUB's reading order come from?

    From the <spine> in the .opf file: a list of <itemref idref="…"/> elements, one per chapter, in reading order. "Next page" at the end of chapter 1 goes to the next spine item. Links inside chapters still work as on the web. The overview notes that a web site has no standard way to say that a sequence of pages forms one publication.Source: EPUB 3 Overview, §3 and §4.1, EPUB 3.3, §5.7

  12. [What's inside an EPUB file] Can an EPUB chapter run JavaScript, like a web page?

    Yes, but reading apps are not required to run scripts, and may switch them off for security. The overview notes that the browser's same-origin rules do not fit a book downloaded to the reader's device, so scripts in a book raise different security questions. It advises scripts only where essential, with the book still readable without them, e.g. for quizzes or games.Source: EPUB 3 Overview, §5.4

  13. [Fonts and copy protection] Why does the EPUB format make a point of letting a book carry its own font files?

    Reading apps are not required to come with any fonts at all, and the fonts a device has may lack letters of other languages. The book's CSS uses the fonts with @font-face, as on the web, but the font files are inside the ZIP, so the text appears as intended on any reading app.Source: EPUB 3 Overview, §8

  14. [Fonts and copy protection] An EPUB is a ZIP file, so anyone can unzip a font file out of it and install it.What does EPUB offer font sellers who do not want that?

    "Font obfuscation": the first 1040 bytes of the font file are scrambled, using a key made from the book's own identifier. Example: the key is 20 bytes long, and 1040=52×201040 = 52 \times 201040=52×20 , so the key is applied 52 times in a row.Source: EPUB 3.3, §4.4

  15. [Fonts and copy protection] EPUB "font obfuscation" scrambles the start of a font file inside the book, using a key made from the book's identifier.Is font obfuscation encryption?

    No, and the EPUB specification says so itself. It only stops someone from copying the font by plain unzipping. The book's identifier is written inside the book, so anyone who knows the method can rebuild the key. The specification even advises using obfuscation only when no better option exists.Source: EPUB 3.3, §4.4.2

  16. [Where EPUB came from] When did the format that became EPUB start?

    In 1999, as Open eBook 1.0, by the Open eBook Forum (later renamed the International Digital Publishing Forum). Its full name, Open eBook Publication Structure (OEBPS), is still inside every EPUB 3: the book's description file has the type label application/oebps-package+xml.Source: EPUB 3 Overview, §B.1, EPUB 3.3, §I

  17. [Where EPUB came from] Open eBook (1999) was a format for publishers to exchange e-books with each other.What change made it usable for selling e-books to readers?

    Packing the whole book into a single ZIP file, approved in 2006. The overview says a format was needed for delivery to readers, not only for exchange between companies; the single-file container was the answer.Source: EPUB 3 Overview, §B.1

  18. [Where EPUB came from] The name EPUB first appeared in 2007, when version 2.0 of the Open eBook format was renamed EPUB 2.0.

    It was renamed in October 2007 and approved in September 2010. Source: EPUB 3 Overview, §B.1

  19. [Where EPUB came from] What was the main goal of EPUB 3, approved in October 2011?

    To bring EPUB closer to HTML, the language of web pages. With it came audio and video, maths formulas, scripts, vertical writing, better accessibility, and narration synchronised with the text.Source: EPUB 3 Overview, §B.2

  20. [Where EPUB came from] EPUB chapters are written in HTML, the language of web pages, and today they can contain pictures, video and maths.Could the very first version of HTML show pictures?

    No: "HTML Tags" (1991 to 1992), the first description of HTML, had no tag for images. Its tags covered titles, headings, paragraphs, lists, links and addresses. The image tag IMG appears in HTML 2.0, RFC 1866 (1995).Source: HTML Tags, RFC 1866, §5.10

  21. [Where EPUB came from] A book is made according to EPUB 3.3. Which version number is written inside it?

    "3.0" EPUB 3.1, 3.2 and 3.3 are new editions of one format, "EPUB 3", and a book made for EPUB 3.0 should still be valid under EPUB 3.3. So the number inside the book stays 3.0.Source: EPUB 3.3, §5.4, EPUB 3 Overview, §1.3

  22. [Where EPUB came from] Who maintains EPUB today?

    The W3C, the organisation that publishes web standards. EPUB 3.3 (May 2023) was the first EPUB published as a W3C standard. Before that it was the International Digital Publishing Forum (IDPF); its web address still appears in every EPUB 3 book, e.g. http://www.idpf.org/2007/opf.Technically EPUB 3.3 changed almost nothing: every valid EPUB 3.2 book is a valid EPUB 3.3 book. The specification was rewritten to be easier to read.Source: EPUB 3 Overview, §B.6, EPUB 3.3

  23. [EPUB or PDF?] Does an EPUB always reflow?

    No: a fixed-layout EPUB has pages of a fixed size, like a PDF. It is meant for children's books, comics and manga, and magazines. Fixed-layout pages became part of EPUB in version 3.0.1 (2014). Even in a reflowing EPUB, pictures and videos do not reflow.Source: EPUB 3 Overview, §5.1, §6.2 and §B.3

  24. [EPUB or PDF?] Does an EPUB have page numbers?

    Not fixed ones: the reading app makes the pages, so their number depends on the screen and the font size. A book may include a page list: links to the places where the pages of the printed edition begin, so you can find "page 17" of the paper book.In the chapter: <span epub:type="pagebreak" id="page17"/>. In nav.xhtml: <nav epub:type="page-list"><ol><li><a href="chapter2.xhtml#page17">17</a></li>…</ol></nav>Source: EPUB 3.3, §7.4.3

  25. [EPUB or PDF?] When is an EPUB the better choice than a PDF?

    Small screens The text is laid out again for each screen. Example: a novel read on a phone, without zooming and scrolling sideways. Your own reading settings You choose the font size, line spacing and word spacing. Example: a reader with low vision enlarges the text, and it still fits the screen. Listening A book with recorded narration can play it while highlighting the text. Example: a child learning to read follows the highlighted words. Source: EPUB 3 Overview, §5.1, §7 and §9

  26. [EPUB or PDF?] When is a PDF the better choice than an EPUB?

    When every reader must see exactly the same pages, e.g. a document meant to be printed. That is the "view and print anywhere" goal of Warnock's 1991 memo. For comics, picture books and magazines, EPUB also offers fixed-layout pages.Source: Warnock, The Camelot Project (1991), EPUB 3 Overview, §6.2