{{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.
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).
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 ==
'''This error is fixed in ConTeXt of 27 August 2014.'''
If you run the epub script on a single file, you’ll get a well-formed and usable export.xml. If you use a project structure, the root node {{code|<document>}} is missing. Just put it in manually (after the comment lines). You can also move the {{code|<metadata>}} block out of the first structure, but that’s merely a cosmetical error.
<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.
Now test it with your reader or editor (e.g. Calibre). (Apple iBooks or Adobe Digital Editions don’t work, .) == Shell script == Of course I don’t know whydo all these steps above manually. Here’s my little shell script. === {{code|epub.sh}} === <pre>#!/bin/bash# call as "./epub.sh productname" # ConTeXt is not in my usual path (setuptex needs too long to be called with every shell);# probably your installation is at a different locationif [ "$TEXROOT" == "" ]; then source ~/Library/texmf/tex/setuptex ~/Library/texmf/texfi # all my products are named like "prd_something.tex"PRD=$1if [ ! -e prd_${PRD}.tex ]; then echo "Product ${PRD} not found!" exit 1fi # all XSL files are in this WORKDIRWORKDIR=epub-workflow # my ConTeXt wrapper "makeit.sh" script creates PDFs with a dateISODATE=`date +"%Y-%m-%d"`PRDPDF=${PRD}_${ISODATE}.pdf # LilyPond is run in this TEMPDIR and creates its note images thereTEMPDIR=lilytemp EPUBPREFIX=epub_TREE=${PRD}.treeOEBPS=${TREE}/OEBPSSAXON="java -jar /opt/local/share/java/saxon9he.jar"# http://saxonica.com/documentation/html/using-xsl/commandline.html if [ ! -f export.xml ]; then echo "File export.xml not found! Trying to run ConTeXt..." # you should replace this call with your own ./makeit.sh ${PRD} exit 2fi if [ ! -f $PRDPDF ]; then echo Product $PRDPDF not found! echo Please run "makeit.sh $PRD" exit 3fi if [ ! -d $OEBPS ]; then echo Directory $OEBPS missing! echo Creating new ePub ... mtxrun --script epub --make ${PRD}fi if [ -d $OEBPS ]; then echo "Creating directories (might exist) ..." mkdir $OEBPS/Styles mkdir $OEBPS/Images mkdir $OEBPS/Fonts mkdir $OEBPS/Text echo Creating HTML ... $SAXON -o:$OEBPS/Text/_intro.html -s:export.xml -xsl:$WORKDIR/export2html.xsl echo Creating OPF ... $SAXON -o:$OEBPS/${PRD}.opf -s:export.xml -xsl:$WORKDIR/export2opf.xsl echo Creating ToC NCX ... $SAXON -o:$OEBPS/toc.ncx -s:export.xml -xsl:$WORKDIR/export2ncx.xsl echo Creating Cover ... $SAXON -o:$OEBPS/cover.html -s:export.xml -xsl:$WORKDIR/export2cover.xsl echo Creating cover image from first page of PDF ... convert -density 196 $PRDPDF'[0]' +repage $OEBPS/Images/cover.jpg echo Copying files ... cp style.css $OEBPS/Styles/ # This copies only fonts from your project directory; adapt. cp *.?tf $OEBPS/Fonts/ echo Converting images from PDF to PNG ... cd $TEMPDIR for IMG in prd_${PRD}-temp-lilypond-*.pdf; do NEWIMG=../$OEBPS/Images/${IMG#prd_${PRD}-temp-lilypond-} NEWIMG=${NEWIMG%.pdf}.png if [ ! -f $NEWIMG ]; then convert -density 196 $IMG'[0]' -trim +repage ${NEWIMG} fi done cd .. # delete old epub rm $TREE/${PRD}.epub rm ${EPUBPREFIX}${PRD}.epub echo Creating ePub ${EPUBPREFIX}${PRD}.epub ... cd $TREE zip -uqr ../${EPUBPREFIX}${PRD}.epub * cd ..fiecho Ready.</pre>