Difference between revisions of "ePub"

From Wiki
Jump to navigation Jump to search
(Work in progress)
 
(section about zipping)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{todo|This page is meant to replace the current pages [[Epub]] and [[Epub_Sample]].}}
+
{{todo|This page is work in progress and an update to the current pages [[Epub]] and [[Epub_Sample]].}}
  
< [[XML]] | [[HTML]] | [[Epub|Old ePub docs]] | [[Epub_Sample|Old ePub Sample]] >
+
< [[XML]] | [[Export]] | [[Epub|Old ePub docs]] | [[Epub_Sample|Old ePub Sample]] >
  
Beware, these ePub/HTML facilities of ConTeXt work only with MkIV since some version in December 2014 and require additional work on your source code!
+
The ePub facilities of ConTeXt are based on its [[Export]] of XML/XHTML. Make sure you get useful export output from your project before you try ePub.
  
= Minimal example =
+
= Documentation about ePub =
  
<texcode>
+
* [https://en.wikipedia.org/wiki/EPUB Wikipedia entry] with some examples
\setupbackend[export=yes]
+
* [http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm Open Packaging Format] (OPF) 2.0.1 specs; contains also information about NCX
 +
* [https://www.iso.org/standard/53255.html ePub3 ISO/IEC TS 30135-1:2014] (Buy specs for 118 CHF?)
 +
* [https://github.com/w3c/epubcheck ePub Check] validator (most validation tools are based on this)
  
\starttext
+
= Minimal ePub =
\input tufte
 
\stoptext
 
</texcode>
 
  
If you compile this, you get ...
+
If you already ran ConTeXt on your project and got the file structure as described in [[Export]], you can run {{code|1=mtxrun --script epub --make minimal}} to get a structure like:
  
= Required structuring =
+
<pre>
 +
minimal.epub
 +
minimal-epub
 +
├── META-INF
 +
│   └── container.xml
 +
├── OEBPS
 +
│   ├── cover.xhtml
 +
│   ├── images
 +
│   ├── minimal-div.xhtml
 +
│   ├── minimal.opf
 +
│   ├── nav.xhtml
 +
│   ├── styles
 +
│   │   ├── minimal-defaults.css
 +
│   │   ├── minimal-images.css
 +
│   │   └── minimal-styles.css
 +
│   └── toc.ncx
 +
└── mimetype
 +
</pre>
  
The export contains usable content only for content that is "well structured" in an XML sense. That means, you need to mark everything, from markup spans over paragraphs and enumeration items to chapters and parts with <tex>start...</tex> <tex>stop...</tex>.
+
* .epub: The epub file is just a zipped version of the directory structure.
 +
* mimetype: contains only "{{code|1=application/epub+zip}}"
 +
* container.xml points to the root file "minimal.opf"
 +
* cover.xhtml is the cover image shown by ePub readers
 +
* -div.xhtml: your content
 +
* .opf: list of all resources, this keeps the "book" together. See also [http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm OPF specs].
 +
* .ncx: table of contents
  
<texcode>
+
= Compressing the structure =
...
 
\startsection[title={A section}]
 
  
\startparagraph
+
The file structure outlined above gets packaged into a ZIP archive with the .epub extension.
  
\startitemize[packed,joinup]
+
* <tt>mimetype</tt> must be the first directory entry of the archive.
\startitem \stopitem
+
* You must not use "extra file attributes", e.g. from macOS (AKA resource forks) or NTFS; use the X parameter of zip.
\startitem \stopitem
+
* You don’t want some other lurking files like macOS’s <tt>.DS_Store</tt> directory information or PDF images; exclude them from recursive packaging.
\startitem \stopitem
 
\startitem \stopitem
 
\stopitemize
 
  
\stopparagraph
+
    EPUB=minimal.epub
 +
    zip -u9X  $EPUB mimetype
 +
    zip -u9X  $EPUB META-INF/container.xml
 +
    zip -u9rX $EPUB OEBPS -x OEBPS/.DS_Store OEBPS/Text/.DS_Store OEBPS/Images/.DS_Store "*/.DS_Store" "OEBPS/Images/*.pdf"
  
\startparagraph
 
\stopparagraph
 
  
\startparagraph
+
= TODO =
\stopparagraph
 
  
\stopsection
+
Write about
...
+
* Cover
</texcode>
+
* ToC
 
+
* Readers
= Minimal useful example =
+
* Styling
 
+
* Images
<texcode>
+
* Better workflow
\setupbackend[export=yes]
 
\setupmainlanguage[en]
 
 
 
\starttext
 
 
 
\startparagraph
 
\input tufte
 
\stopparagraph
 
 
 
\stoptext
 
</texcode>
 

Latest revision as of 09:35, 6 March 2020


TODO: This page is work in progress and an update to the current pages Epub and Epub_Sample. (See: To-Do List)


< XML | Export | Old ePub docs | Old ePub Sample >

The ePub facilities of ConTeXt are based on its Export of XML/XHTML. Make sure you get useful export output from your project before you try ePub.

Documentation about ePub

Minimal ePub

If you already ran ConTeXt on your project and got the file structure as described in Export, you can run mtxrun --script epub --make minimal to get a structure like:

minimal.epub
minimal-epub
├── META-INF
│   └── container.xml
├── OEBPS
│   ├── cover.xhtml
│   ├── images
│   ├── minimal-div.xhtml
│   ├── minimal.opf
│   ├── nav.xhtml
│   ├── styles
│   │   ├── minimal-defaults.css
│   │   ├── minimal-images.css
│   │   └── minimal-styles.css
│   └── toc.ncx
└── mimetype
  • .epub: The epub file is just a zipped version of the directory structure.
  • mimetype: contains only "application/epub+zip"
  • container.xml points to the root file "minimal.opf"
  • cover.xhtml is the cover image shown by ePub readers
  • -div.xhtml: your content
  • .opf: list of all resources, this keeps the "book" together. See also OPF specs.
  • .ncx: table of contents

Compressing the structure

The file structure outlined above gets packaged into a ZIP archive with the .epub extension.

  • mimetype must be the first directory entry of the archive.
  • You must not use "extra file attributes", e.g. from macOS (AKA resource forks) or NTFS; use the X parameter of zip.
  • You don’t want some other lurking files like macOS’s .DS_Store directory information or PDF images; exclude them from recursive packaging.
   EPUB=minimal.epub
   zip -u9X  $EPUB mimetype
   zip -u9X  $EPUB META-INF/container.xml
   zip -u9rX $EPUB OEBPS -x OEBPS/.DS_Store OEBPS/Text/.DS_Store OEBPS/Images/.DS_Store "*/.DS_Store" "OEBPS/Images/*.pdf"


TODO

Write about

  • Cover
  • ToC
  • Readers
  • Styling
  • Images
  • Better workflow