Skip to main content

Typesetr

Path: typeset/

Typesetr converts Word documents (.docx) into print-ready PDFs using Typst as the typesetting engine. Designed for professional book printing with full support for:

  • Bleed zones and crop marks
  • Front matter (half-title, title page, copyright, dedication, TOC)
  • Custom fonts (15 curated Google Font families)
  • Color mode filtering (full color, grayscale, monochrome)
  • PA5 format (140×210mm) as primary trim size
  • Draft watermark overlay

Architecture

input.docx
|
v
docx_to_typst_markup() — parses Word paragraphs, headings, lists,
| bold/italic runs, chapter numbering
v
_build_typst_template() — generates full Typst source with:
| - page dimensions + bleed expansion
| - crop marks (optional)
| - front matter pages
| - running headers (odd/even)
| - color mode filter
| - draft watermark
v
typst compile — Typst CLI compiles to print-ready PDF
|
v
output.pdf — with bleed, crop marks, proper margins

Components

FileRole
typesetrCLI entry point (auto-re-execs under virtualenv)
typeset.py (826 lines)Core engine — settings, docx parsing, Typst template building, PDF compilation
tui.py (844 lines)Textual TUI — 6-tab interface (Overview, Front Matter, Page, Print Marks, Colour, Typography)
config.pyProduction defaults: PA5 trim, bleed, crop marks, font setup, email delivery
download_fonts.pyDownloads 15 curated Google Font families
deliver-mail.pyEmails generated PDF with production manifest
hook_postfinish.pyPost-processing hook calling deliver-mail.py

Features

Input Parsing (docx_to_typst_markup())

  • Paragraph styles: Normal, Heading 1-6, Block Text, Quote
  • Inline formatting: bold, italic, bold-italic
  • Lists: bullet, numbered
  • Line breaks and section breaks
  • Chapter detection: recognizes "KAPITEL N" patterns, merges with following heading

Page Setup (_build_typst_template())

  • Trim sizes: PA5 (140×210mm default), A3-A6, B4-B5, DL, Letter, custom
  • Bleed expansion (3mm default)
  • Crop marks (optional, with offset control)
  • Two-sided layout with mirror margins
  • Running headers: chapter title (even), author (odd)

Front Matter

  • Half-title page (title only)
  • Title page (title, subtitle, author, publisher, ISBN, year)
  • Copyright page (publisher, edition, printing info, ISBN)
  • Dedication page (centered italic)
  • Table of contents (auto-generated)

Typography

  • 15 curated Google Font families downloaded automatically
  • Presets: book (first-line indent), report (no indent), block (generous spacing)
  • Exercise blocks: bold-first-paragraph quotes rendered as guided exercises
  • Draft watermark overlay (optional)

Output

OptionValues
Trim sizesPA5, A3-A6, B4-B5, DL, Letter, custom
Bleed0-10mm (3mm default)
Color modeColor, Grayscale, Monochrome
Crop marksOn/Off with offset control
Draft watermarkOptional overlay
Front matterConfigurable pages

Usage

# Convert a document
./typesetr input.docx output.pdf

# Launch TUI
./typesetr --tui

# With options
./typesetr input.docx output.pdf \
--trim pa5 \
--bleed 3 \
--crop-marks \
--color-mode grayscale \
--front-matter standard

Defaults are persisted in .typesetr.json (gitignored).

Technology Stack

LayerTechnology
LanguagePython 3.11+
Typesetting EngineTypst
TUI FrameworkTextual
DOCX Parsingpython-docx
CLIDirect executable
FontsGoogle Fonts (15 families)

Current Status

Production-ready. Used to produce actual print-ready PDFs (samples include honsomleder25majefterlunch.pdf and UTKAST.pdf). Test suite covers CLI, escape handling, integration, markup parsing, settings, and template generation.