Additional Formats for MfGames Writing
Not everyone in the world uses EPUB. Yes, I consider it one of the best formats for me because I can change font size or layout, there is still a big need for print books and Amazon is the source of most ebook sales (though I don't care for that either).
To handle that, MfGames Writing provides a pluggable collection of different output formats. This allows you to use only the formats that you way (EPUB2, PDF, HTML) and they can be updated separately.
Series
I appear to be writing a short series of post about the tools I use for publication and writing.
- Semantic Versions and Releases: Why semantic versioning helps with the writing process.
- Evolution of MfGames Writing: A brief history and reasoning behind the tools.
- First Steps Using MfGames Writing: Starting a new project with MfGames Writing.
- Adding Content to MfGames Writing: Adding front and back matter to novels.
- Working with MfGames Writing, CI, and Docker: Adding automatic building with commits.
- Additional Formats for MfGames Writing: How to create PDF, MOBI, DOCX, and HTML versions.
- Theming for MfGames Writing: A light introduction on how to customize the output.
- Integrating Semantic Versioning into MfGames Writing: Tying semantic releases into the process.
Using Formats
Formats are consumed in the edition section of the publication.yaml
file.
metadata:
title: Test Project
author: D. Moonfire
language: en
theme: "@mfgames-writing/clean"
outputDirectory: .
outputFilename: test-project-{{edition.version}}.{{edition.editionName}}
editions:
epub:
format: "@mfgames-writing/epub2"
pdf:
format: "@mfgames-writing/weasyprint"
isbn: 978-1-999999
html:
format: "@mfgames-writing/html"
images:
scale: 0.25
The format is the name of the package installed with npm install
.
EPUB
The easiest format to use is EPUB2.
$ npm install @mfgames-writing/epub2
$ npm run build:html
The setup for the NPM commands can be found yesterday.
When this runs, it will generate an EPUB2 file that will be verifiable with epubcheck
.
HTML
HTML is also pretty easy.
$ npm install @mfgames-writing/html
PDF is the complicated one and why I use a Docker image. I decided to use WeasyPrint for PDF generation because it creates good-quality PDF files and works with HTML, the format themes use.
$ npm install @mfgames-writing/weasyprint
This assumes that weasyprint
and pdftk
are both in the PATH.
MOBI
There isn't a good package for generating MOBI files directly, so the best approach to creating a Amazon MOBI file for uploading is to create a EPUB file and then use kindlegen
to convert it.
$ npm run build:epub
$ kindlegen *.epub
DOCX
Like MOBI, it is hard to write a DOCX in a clean manner. To do that, we create a HTML and then convert it.
$ npm run build:html
$ sed 's@­@@g' < *.html \
| pandoc -f html -t docx -o test-package-0.0.0.docx
We have the extra sed
command to remove the hypenation from @mfgames-writing/hyphen
which makes a cleaner file.
Metadata
Categories:
Tags: