{{todo|Beware, this doesn’t fit the current export files and ePub workflow as of January 2015!}} < [[Epub]]| [[XML]] | [[Export]] | [[ePub|New ePub docs]]>
Creating an ebook with ConTeXt is still tedious and needs a lot of manual work - that will not change, since everyone has other needs, uses different structures etc.
Here I’ll show you my workflow for creating ebooks of my songbooklets (that use [[LilyPond]] via [http[modules://modules.contextgarden.net/t-filter |filter module]] for the notes).
I’m using ConTeXt’s [[Project structure]], separating content in products (for me: single booklets) and components (for me: single songs) with a common stylesheet (environment).
Unfortunately, ConTeXt has a bug in XML creation in this setup.
Beware, you need a current beta version of ConTeXt, since Hans fixed some export related bugs in the last few days! --[[User:Hraban|Hraban]] 27 August 13 September 2014.
== ConTeXt setup ==
<texcode>
\setupexport[ hyphen=yes,
%firstpage={cover.jpg}, % is ignored
title={Songbook},
\settaggedmetadata[
% here you can set as many metadata entries as you like
%firstpage={cover.jpg}, % is ignored
title={Songbook},
name=ebook, % this becomes the name of the output directory
author={Hraban}] \definehighlight[emph][style=italic] % use \emph{something} instead of {\em something}
</texcode>
Make sure to tag all your structural elements with {{cmd|start...}}-{{cmd|stop...}}, e.g. {{cmd|startchapter}}, but even {{cmd|startparagraph}}!
In places where {{cmd|startparagraph}} does not work, such as itemizations, where it causes a blank line after the bullet and before the item text, use {{cmd|bpar}} (and closing {{cmd|epar}}) to tag paragraphs.
Then you can call ConTeXt and its ePub script:
We’ll mostly work with "export.xml" that contains all your content (check that, you’ll miss everything that was not properly tagged).
== Fix export.xml ePub structure == This is the directory structure that we need for our ePub:
If you run the epub script on a single file, you’ll get a well<pre>/songbook.tree/├── META-formed and usable exportINF│ └── container.xml├── OEBPS│ ├── Fonts│ │ └── somefont.otf│ ├── Images│ │ ├── ...│ │ ├── c_farewell-1.png│ │ ├── c_farewell-2.png│ │ ├── c_farewell.png│ │ ├── ...│ │ └── cover.jpg│ ├── Styles│ │ └── style.css│ ├── Text│ │ ├── _intro.html│ │ ├── aut_1.html│ │ ├── ...│ │ └── aut_99. If you use a project structure, the root node {{code|<document>}} is missinghtml│ ├── cover. Just put it in manually (after the comment lines)html│ ├── songbook. You can also move the {{code|<metadata>}} block out of the first structure, but that’s merely a cosmetical erroropf│ └── toc.ncx└── mimetype</pre>
A proper We use mimetype and container.xml unchanged from ConTeXt’s epub script and (re)create everything else.At the end this structure is just zipped with an "epub" file ending. == Unchanged files == For the records: === {{code|mimetype}} === <pre>application/epub+zip</pre> === {{code|exportcontainer.xml}} starts like this:===
<xmlcode>
<<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><!-- input filename : solo --><!-- processing date : Wed Aug 27 13:47:46 2014 --><!-- context <container version : 2014.08="1.21 09:56 --><!-- exporter version : 0.31 --><document language="en" filexmlns="solo" date="Wed Aug 27 13urn:oasis:names:47tc:46 2014" context="2014.08.21 09opendocument:56" version="0.31" xmlns:m=container"http://www.w3.org/1998/Math/MathML">> <metadatarootfiles> <metavariable namerootfile full-path="authorOEBPS/songbook.opf" media-type="application/oebps-package+xml">Hraban</metavariable> </metadatarootfiles><section detail="chapter" location="aut:1"/container>...
</xmlcode>
You don’t need the attributes of the document node, even if we could use the language setting.
== Transform XML to HTML ==
I installed Saxon on my Mac with MacPorts, then instead of just "saxon" you must call {{code|java -jar /opt/local/share/java/saxon9he.jar}}.
This is my === {{code|export2html.xsl}}:===
<xmlcode>
/>
<xsl:variable name="within-paragraph">0</xsl:variable ><!-- statusxsl: are we variable name="within a paragraph? -section">0</xsl:variable ><xsl:variable name="previous-section">0</xsl:variable >
This The [http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm OPF file ] keeps the others together, it lists all resources of the ebook. You will have to adapt the listing of images (since I use only PDFs converted to PNG) and add fonts manually, if you ship any. === {{code|export2opf.xsl}} ===