Because ConTeXt is good at manipulating XML, it would seem likely that it is also good at handling EPUB, since this is essentially a zipped collection of HTML and CSS files. I am wondering if there exists a good ConTeXt-based system for converting EPUBs to PDFs? ConTeXt Garden contains some information about EPUB, but this is restricted to ConTeXt-EPUB conversion.

Such a script would have the potential of producing better results than most of the other (IMO) mediocre EPUB to PDF conversion scripts currently available.

  • it is quite easy to open ePUB file and parse HTML files using Lua, the hard thing is CSS support, as it can change the appearance a lot. it is better to use headless browser such as SlimerJS to convert DOM to LaTeX. Yes, no such tool exists at the moment :(
    – michal.h21
    Jul 10, 2015 at 21:14
  • Can ConTeXt handle CSS?
    – Gaussler
    Jul 10, 2015 at 21:15
  • 3
    maybe yes, but I don't know about CSS parser for Lua and then you would have to reimplement DOM in Lua. This seems like huge task (basically create a new web browser in pure Lua)
    – michal.h21
    Jul 10, 2015 at 21:20
  • I'm not so sure it does not have native support. I haven't tested the EPUB output yet, but I would assume it also outputs CSS. In other words, ConTeXt "knows" something about CSS.
    – Gaussler
    Jul 11, 2015 at 6:28
  • @michal.h21 It would not need support for JavaScript, which (I think) is a major obstacle when making a web browser.
    – Gaussler
    Jul 11, 2015 at 6:29

1 Answer 1


ConTeXt is not up to the task of typesetting EPUB. However, there exist third-party solutions to convert an EPUB file to ConTeXt, e.g. pandoc. It is a command line tool written in Haskell which can translate between multiple markup file formats. To convert from EPUB to ConTeXt use

pandoc -f epub -t context -o output.tex input.epub

(add the -s flag if you want to obtain a default preamble as well).

If you are keen to give it a go, there are test file in the pandoc repository which you could run first: https://github.com/jgm/pandoc/tree/master/test/epub

Here is an excerpt of the first few lines (without the preamble). Doesn't look too bad.

  {\tfd EPUBTEST 0101 - Styling Tests}
  {\tfa Ori Idan\crlf Matt Garrish\crlf Marisa DeMeglio\crlf Toshiaki Koike\crlf Vincent Gros\crlf Markus Gylling}

\section{EPUB 3 Styling Test Document: 0101}

\subsection{Status of this Document}

This publication is currently considered {[}UNDER DEVELOPMENT{]} by the

This publication is part of version X.X of the EPUB 3.0 Compliance Test
Suite released on TBD.

Before using this publication to evaluate reading systems, testers are
strongly encouraged to verify that they have the latest release by
checking the current release version and date of the test suite at

This publication is one of several that currently comprise the EPUB 3
conformance test suite for reflowable content. The complete test suite
includes all of the following publications:


\subsection{About this Document}

This document focuses on human-evaluated binary (pass/fail) tests in a
reflowable context. Tests for fixed-layout content and other individual
tests that require a dedicated epub file are available in additional
sibling documents; refer to the
suite wiki]\from[url2]
(\type{https://github.com/mgylling/epub-testsuite/wiki/Overview}) for
additional information.


The following conventions are used throughout the document:

\startdescription{1. Locating a test}

  Tests for {\em required} Reading System functionality are preceded by
  the label: {[}REQUIRED{]}

  Tests for {\em optional} Reading System functionality are preceded by
  the label: {[}OPTIONAL{]}

\startdescription{2. Performing the test}
  Each test includes a description of its purpose followed by the actual
  {\bf test statement, which can always be evaluated to true or false}.
  These statements typically have the form: "If {[}some condition{]},
  the test passes".

\startdescription{3. Scoring in the results form}
  @@@TODO provide info on where to get the results form

This is the compiled output of the formatting.epub example:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.