docx-book-typeset
Turn a Word manuscript (.docx) into a retail EPUB 3 and a print-ready PDF interior, from one small
YAML file per edition. No desktop layout app, no proprietary fonts.
- EPUB: semantic XHTML, navigation document + NCX, landmarks, series metadata, optional cover, accessibility metadata. Passes epubcheck with no errors or warnings. No embedded fonts: readers use their own serif.
- PDF: laid out with Typst. Trim sizes 5x8, 5.25x8, 5.5x8.5, 6x9 and A5; mirrored margins with a gutter; chapters opening on a recto; running heads and folios (left off opening and blank pages); PDF bookmarks; optional half title and contents page. The default font is Libertinus Serif (SIL Open Font License), which ships inside Typst, so a build needs no font installation.
The look is deliberately plain: one serif family, centred headings, * * * scene breaks in print and a short
rule in the EPUB. No ornaments, no drop caps, no small-caps lead-ins.
For authors: start here
The author's guide walks you through everything step by step, no technical background needed: installing, preparing the manuscript in Word, building the book, copy-and-paste settings for common needs, and uploading to KDP, IngramSpark and the ebook stores.
The short version:
py -m pip install https://github.com/acato/docx-book-typeset/archive/refs/heads/main.zip # once (Mac: python3)
typeset-book new # answer a few questions -> book.yaml
typeset-book check # see the chapters it found
typeset-book build # -> build/My-Book.epub and build/My-Book-Print.pdf
For developers
pip install -e ".[test]" # lxml, PyYAML, Pillow, typst; pytest, pymupdf, epubcheck for the tests
pytest -q tests
If the typst command-line tool is on your PATH it is used; otherwise the typst Python package is.
Python 3.10 or newer. The modules can also be run one by one:
python examples/make_sample_docx.py # writes examples/sample.docx
python -m typeset.docx2epub examples/sample.yaml # -> examples/build/The-Tide-Tables.epub
python -m typeset.docx2pdf examples/sample.yaml # -> examples/build/The-Tide-Tables-Print.pdf
How it compares
Vellum is limited to Mac, while Atticus is a paid app available on multiple operating systems. Calibre handles ebooks but is not a print layout tool. Reedsy Studio is a free, web-based editor where your book lives in their online interface. Pandoc and LaTeX setups are powerful but heavy to install.
docx-book-typeset accepts .docx files directly and outputs both retail EPUB 3 and print-ready PDF. It is free, open source, and runs on Windows, Mac, and Linux. There is no LaTeX, Pandoc, or font installation required. The design is deliberately plain and classic, reading Word styles rather than visual formatting. It is a command-line tool without a graphical interface, but it offers a simple, one-line installation for authors who want a clean, semantic output.
Preparing the manuscript
The builders read the styles of the DOCX, not its visual formatting:
| In Word | Becomes |
|---|---|
| Heading 1 | the start of a new element: a chapter, a part, or a front/back-matter section |
| Subtitle style right after a Heading 1 | the chapter (or part) subtitle |
| Heading 2 / Heading 3 | subheads inside a chapter (bold / italic) |
| Quote (or Intense Quote, Block Text) | block quote; consecutive Quote paragraphs form one quote |
a paragraph that reads * * * |
a scene break (configurable) |
| italic, bold, small caps, underline, strikethrough, super/subscript | kept |
| hyperlinks (external, internal to bookmarks, HYPERLINK and REF fields) | live links in EPUB and PDF |
| pictures placed in line with text | images (the picture's alt text is used in the EPUB) |
Anything before the first Heading 1 is ignored (with a warning): put the book's title and author in the YAML, not at the top of the manuscript; the builders generate the title page.
Check what the builders will see with:
python -m typeset.docx_reader manuscript.docx # headings, quotes, links, anchors, images
python -m typeset.docx_reader manuscript.docx --all # every paragraph
The edition file
One YAML per edition (book + language + format choices). Relative paths resolve against the YAML file.
A complete example is examples/sample.yaml.
docx: manuscript.docx
metadata:
title: "The Tide Tables" # required
subtitle: "A Novel" # optional
creator: "A. N. Author" # required
file_as: "Author, A. N." # sort name, optional
language: en-US # required (BCP 47)
identifier: "urn:uuid:..." # keep it stable across releases; derived from title/author if absent
publisher: "Example Press" # optional; also printed at the foot of the title page
description: "..." # optional, EPUB only
series: { name: "Harbour Books", position: 1, position_label: "Book One" } # optional
default_type: chapter # type of any Heading 1 not listed in `elements`
elements: # exact Heading 1 text -> element type
"Copyright": copyright
"Dedication": dedication
"Epigraph": epigraph
"Part One": part
"Prologue": prologue
"Acknowledgments": acknowledgments
"About the Author": about-author
chapter_heading: '^Chapter \d+: (?P<title>.+)$' # optional: strip "Chapter N" from headings and keep the title;
# a regex without (?P<title>) makes the chapter title "Chapter N"
chapter_numbers: true # false: chapters show their title only
subtitle_style: Subtitle # paragraph style used for chapter subtitles
scene_breaks: ["* * *"] # paragraph texts that mean "scene break"
labels: # words the builders print; translate for other languages
chapter: Chapter
contents: Contents
copyright: Copyright
dedication: Dedication
epigraph: Epigraph
title_page: Title Page
cover: Cover
beginning: Start
epub:
output: My-Book.epub # default: <Title>.epub
cover: cover.jpg # optional; re-encoded as JPEG, at most cover_width px wide (1600)
contents_page: true # an HTML contents page after the opening front matter
image_width: 1200 # inline images are scaled down to this width
print:
output: My-Book-Print.pdf # default: <Title>-Print.pdf
trim: 6x9 # 5x8 | 5.25x8 | 5.5x8.5 | 6x9 | a5
margins: { inside: 0.85, outside: 0.65, top: 0.8, bottom: 0.85 } # inches; overrides the trim defaults
font: "Libertinus Serif" # a family name or a list (fallbacks)
font_fallback: ["Noto Serif CJK SC"] # appended after `font` (e.g. for a few CJK names in Latin text)
font_paths: [fonts/] # extra font folders (also: TYPST_FONT_PATHS)
font_check: true # fail if the PDF does not embed `font` (see Fonts)
font_size: 11 # pt
leading: 0.62 # space between lines, in em
indent: 1.5 # paragraph indent, in em
hyphenate: true
chapter_start: recto # recto | any
running_heads: author-title # author-title | title-chapter | none
head_verso: "A. N. Author" # defaults: author on the left page, title on the right
head_recto: "The Tide Tables"
half_title: false
contents: false # a contents page with page numbers
image_size: large # small | medium | large | full (share of the text width)
Element types
| type | heading shown | notes |
|---|---|---|
chapter |
yes, numbered "Chapter N" (unless chapter_numbers: false) |
numbered in order, whatever the DOCX says |
part |
yes, on a page of its own | |
copyright |
no | print: foot of the title page's verso |
dedication, epigraph |
no | print: centred on a recto |
none, foreword, preface, introduction, prologue, epilogue, afterword, acknowledgments, also-by, about-author |
yes, unnumbered | the type sets the EPUB semantics |
Fonts
Print uses Libertinus Serif unless you name another family. The EPUB embeds no fonts at all, so a font licence only matters for the print PDF.
Why Libertinus and not a public-domain font: there is no book-quality serif with a true italic whose public-domain status is clear. The fonts sometimes described as public domain either lack an italic (Goudy Bookletter 1911) or are distributed under the OFL or GUST licences in every usable OpenType form (the Computer Modern descendants). The SIL Open Font License lets you embed the font in books you sell; what it restricts is selling the font itself, or redistributing a modified version under the original name.
Using a font you own a licence for
Two lines in the edition file swap the typeface; nothing in the code or the template changes.
-
Put the font files in a folder next to your edition file, for example
fonts/. Use the desktop OpenType or TrueType files (.otf/.ttf), not web fonts. Include every style the book uses: regular and italic at least; bold if your manuscript has bold text or Heading 2 subheads. Typst does not fake a missing italic or bold. -
Point the edition file at it:
print: font: "Minion Pro" # the family name exactly as the font reports it font_paths: [fonts/] # folder(s), relative to this YAML file
The family name is the one your system's font manager shows (Font Book on macOS, the Fonts settings page on Windows,
fc-list : familyon Linux); with the Typst CLI,typst fonts --font-path fonts/lists exactly what the build will see. -
Build as usual. After compiling,
docx2pdfchecks that the PDF really embeds the font you asked for. If the name is misspelled or the folder is wrong, Typst would quietly fall back to Libertinus, so the build stops instead and renames the PDF*.WRONG-FONT.pdf. If a font's internal name differs from its family name and the check fails wrongly, setprint.font_check: false.
Before you publish, read the licence: most commercial desktop licences allow embedding a subset of the font in
a PDF for print (that is what the build does), but some do not, and some limit the number of computers.
Keep licensed font files out of public repositories: fonts/ is in .gitignore for that reason. To
use the same font on several machines without copying it into the project, list its folder in the
TYPST_FONT_PATHS environment variable instead of font_paths (separated by ; on Windows, : elsewhere).
You can also give a list, for example font: ["Minion Pro", "Noto Serif CJK SC"], and the later families
are used for any characters the first one lacks.
Notes for KDP / IngramSpark / Lulu
- The PDF has the exact trim size, with no bleed (text-only interiors do not need one) and all fonts embedded.
- The default gutter suits books up to roughly 500 pages. KDP asks for more inside margin as page count grows
(0.625 in from 301 to 500 pages, 0.75 in from 501 to 700); raise
print.margins.insideif needed. - Store uploads of an ebook usually should not carry a print ISBN: keep the ISBN line in a separate DOCX (or edition) for print.
Layout of the code
typeset/cli.py the `typeset-book` command (new, check, build, sample)
typeset/docx_reader.py DOCX -> paragraphs with styles, formatted runs, links, bookmarks, images
typeset/model.py paragraphs -> elements and blocks (shared by both outputs); the edition file
typeset/docx2epub.py EPUB 3 writer
typeset/epub/book.css the EPUB stylesheet
typeset/docx2pdf.py writes book.json and compiles templates/book.typ with Typst
typeset/templates/book.typ the print layout
typeset/sample.py the practice manuscript (`typeset-book sample`)
examples/ the sample edition file
docs/ the author's guide
tests/ pytest tests, including one that loads every recipe in docs/4-recipes.md
Books typeset with docx-book-typeset
Alessandro Catorcini has used docx-book-typeset for every English book he has published since The Master of the Seal.
If you have published a book using this tool, we would love to feature it. Please submit a pull request adding your cover image (under 300 px wide) to docs/images/showcase/, along with the title, author, and a link. There is no pressure; this list is simply a way to see the tool in action.
License
Apache License 2.0, see LICENSE. Libertinus Serif is distributed with Typst under the SIL Open Font License.
Made by Alessandro Catorcini to typeset his own historical novels. Learn more at www.catorcini.com.
Metadata
Release files for docx-book-typeset 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docx_book_typeset-1.0.0.tar.gz | 46.5 kB | Without provenance | Details for docx_book_typeset-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docx_book_typeset-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for docx_book_typeset-1.0.0-py3-none-any.whl |
Total release size: 94.6 kB
Release files / docx_book_typeset-1.0.0.tar.gz
| Download URL | docx_book_typeset-1.0.0.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa06ecc919bf052402fe6d77f04168c4f811290b586700802405a0cede28c3ab
|
|
BLAKE2b-256 checksum How to use checksums |
c83ab6c6f56cb1abe3a96f8f62ff29a105e50350b69c101c50d0a3f083a83490
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / docx_book_typeset-1.0.0-py3-none-any.whl
| Download URL | docx_book_typeset-1.0.0-py3-none-any.whl |
|---|---|
| Size | 48.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b28e0fe233461ce9610a016b7930d64033fbc481c783769ca327950b0d20b8a
|
|
BLAKE2b-256 checksum How to use checksums |
c6faacdaf1f4e807ff1a26b7815980a663308e0977eed8b0e0f26b914c2221af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for docx-book-typeset 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.