Book4matter

Introduction

Write in Markdown. Publish everywhere. Book4matter (Book Formatter) takes in Markdown, or plain text, and formats it for distribution. It uses this one source to produce output in HTML, EPUB, PDF and print versions. (PDF versions have clickable links, print has page references).

It was built to take a manuscript to Amazon KDP without worrying about formatting while you are writing.

This webpage is rendered by Book4matter. It was written in Markdown. See our Github Project

TBH, Book4matter is not really designed as a website builder. But using it to build its own website seemed reasonable.

Book4matter is a command line tool, for now. It’s best for people who are comfortable with the command line.

Check back later for a web version.

Part 1 Overview

Chapter 1 Why it exists

Book4matter lets you keep your text, and the formatting separate:

Point ten books at one style file and restyle them all from a single edit. The manuscript never changes.

Part 2 One source, four outputs

Every output is generated from the same Markdown, so they never fall out of sync.

Chapter 3 Shareable PDF

The same book with live, clickable hyperlinks and a linked table of contents — the version you email or post, not the one you send to a printer. This version can include a cover image, if you want.

Chapter 4 EPUB

A reflowable e-book that passes the W3C EPUBCheck validator (the same class of checks KDP runs on upload), so most rejections are caught before you ever upload.

Note: Each EPUB publisher has different requirements. They restrict things like manuscript length, image size, and even limits on references to other publishers. You’ll want to check these out, before publishing.

Chapter 5 Website

One self-contained HTML page with an automatic table of contents and your own stylesheet

This is how this website was generated.

Part 3 See it in action

These three books are built by this same pipeline on every commit, in all four forms. Everything below came from Markdown — no hand-editing of the output.

Chapter 6 The manual

The book4matter manual — this tool documenting itself.

Chapter 7 The demo

The Pocket Pipeline — a short worked example that exercises the features.

Chapter 8 A novel

The Smallest Fire — fiction, to show the pipeline on plain prose.

Part 4 Quick start

The quickest way to run Book4matter is the prebuilt Docker image: nothing to clone, and nothing to install but Docker itself — no pandoc, no Typst, no fonts to hunt down. (Prefer to install the tools directly, or build the image yourself? The manual covers all three ways.)

Chapter 9 Install Docker

https://docs.docker.com/engine/install/

Chapter 10 Get book4matter

Pull the image from Docker Hub:

docker pull book4matter/book4matter

Chapter 11 Make a book

A book is just a directory:

my-book/
  book_metadata.yaml    # title, author, rights
  book_style.yaml       # trim, margins, fonts
  chapters/
    010-first.md
    020-second.md

Chapters are combined in filename order, so a numeric prefix controls the sequence.

Chapter 12 Build it

Mount the folder that holds your book at /work and name the form you want. Everything after the image name is an ordinary bf command:

docker run --rm -v "$PWD":/work book4matter/book4matter print my-book/   # KDP print interior PDF
docker run --rm -v "$PWD":/work book4matter/book4matter pdf   my-book/   # shareable PDF with live links
docker run --rm -v "$PWD":/work book4matter/book4matter epub  my-book/   # validated EPUB
docker run --rm -v "$PWD":/work book4matter/book4matter html  my-book/   # single-page website

Each command writes into my-book/out/; the tool only ever writes there, never back over your manuscript.

Part 5 What you get

Chapter 13 Real book typography

Powered by Typst under the hood: proper hyphenation and justification, small title/copyright/contents front matter, running heads, and quality book faces (Libertinus Serif for text, a Helvetica-metric sans for headings) bundled right in the image — no font wrangling. You can use your own fonts, too, of course.

Chapter 14 KDP Support

Trim sizes, gutter margins that scale with page count, and an EPUB that clears the same validator KDP uses. The defaults aim at a US 6×9 trade paperback that uploads clean.

Chapter 15 Markdown you already know

Standard Pandoc Markdown: headings, emphasis, lists, block quotes, footnotes, tables, images, and hyperlinks. Plain .txt works too, for novelists who want nothing but words and scene breaks.

Chapter 16 Novels and non-fiction alike

Treat top-level headings as parts (or sections) with chapters beneath, or flip a switch and let them be numbered chapters in a novel with no visible headings at all.

Chapter 17 Import from Word

Already have a .docx? Book4matter can import it, split it into chapter files on its headings, and pull the embedded images out for you — a running start instead of a blank page.

Chapter 18 Reproducible by design

You can run everything from a pinned Docker image. No host installs, no network at build time, and the same inputs produce the same outputs on any machine.

If you want more control, you can install locally, or you can build the docker image locally, and run that way.

Chapter 19 Afterword

Book4matter is a thin pipeline over two excellent tools, wired together so you never have to touch either directly.

  1. Pandoc reads your Markdown and your two YAML config files.
  2. For print and PDF, Pandoc emits Typst, and Typst does the page layout — margins, running heads, hyphenation, front matter.
  3. For EPUB and HTML, Pandoc writes those directly, sharing the same metadata and styling decisions.

Because the styling lives outside your prose, the same manuscript flows into every format without edits, and one change to a style file re-themes every book that points at it.

Learn more

The full manual — installation, configuration, every command, and the design decisions behind the defaults — is itself a Book4matter book. Read it online, build it from the docs/ directory, or read the source in the repository.

Book4matter is a command-line tool, and open source. If you’re comfortable in a terminal and want your words to look like a real book, it’s built for you.