Skip to main content

The PreTeXt Guide

Section 31.1 Prerequisites

There are a handful of prerequisites to build an EPUB version of a book.
  • You must use either the PreTeXt-CLI or the pretext/pretext script, since creating an EPUB file is a multi-stage process; building with xsltproc is not supported.
  • You must have node and npm must be installed. See Section F.1 for more on node and npm.
  • You must use a publication file (referred to below as publication.ptx) with
    source/directories/@generated
    and
    source/directories/@external
    so that images can be located and bundled (these are included by default if you use pretext new or pretext init for your project).
    To use a non-generic cover image, the publication file must also have epub/cover/@front attribute that points to the cover image (JPEG or PNG, 2048 pixels tall, 1280 pixels wide). Absent an image provided, there will be an attempt to create a simple, generic cover image. See Subsection 44.6.1 for details about specifying a cover image.
If you use the pretext/pretext script, you will need to generate any source-defined images in SVG format for standard EPUB, and PNG format for Kindle.
Finally, if you are using the pretext/pretext script, you must install a local version of MathJax (the CLI will try to do this for you). We provide a bash script in scripts/mjsre that automates this process. See Section F.2 for instructions. As updates to the EPUB conversion are released, you may occasionally want to update your local copy of MathJax. Simply use the script referenced above.
To use the CLI, you will need to create a new target in the project manifest (project.ptx). The target should look something like the following.
<target name="ebook">
    <format>epub</format>
    <source>source/main.ptx</source>
    <publication>publication/publication.ptx</publication>
    <output-dir>output/epub</output-dir>
</target>
The @name can be whatever you wish, but the <format> must be epub or kindle. You won’t be able to tell the output files apart, so if you want both an epub and a kindle, name the output directory differently for each.