# Postext — Programmable Typesetter for the Web

> A layout engine that bridges centuries-old print typesetting craft with modern web technology. Semantic markdown in, publication-grade pages out — rendered to HTML, canvas, and print-ready PDF.

- HTML version: https://postext.dev/en
- Other languages: [es](https://postext.dev/es.md)

## The Programmable Typesetter for the Web

Postext takes semantic markdown and applies centuries-old editorial layout rules — Knuth-Plass justification, orphan prevention, figure placement — producing publication-grade pages rendered to HTML, canvas, or print-ready PDF.

## Editorial Layout, Computed for the Web

CSS gives you responsive layout — flexbox, grid, columns. But it cannot balance columns, prevent orphans, flow text around figures, or place footnotes at the bottom of a column. These are editorial decisions that have been refined over centuries of print typesetting.

Postext bridges that gap. Feed it semantic markdown and a configuration object. It measures text 300–600× faster than the DOM using [@chenglou/pretext](https://github.com/chenglou/pretext), then computes the complete page geometry — every line, float, and caption — and renders it through HTML, canvas, or print-ready PDF backends.

## What Print Typesetters Knew All Along

### Knuth-Plass Justification

The same optimal line-breaking algorithm TeX uses, with TeX-pattern hyphenation and orphan control — evenly set text blocks with no rivers of whitespace, beyond anything CSS can express.

### Resources & Cross-References

Figures, SVG diagrams, and tables float to the top or bottom of columns and pages — the way print floats work — with typed numbering and :ref cross-references that always stay in sync.

### Table & Caption Styling

Tables typeset with independent body and header typography, and captions that follow your configuration — numbered, styled, and placed alongside the resource they describe.

### Single-Ink Diagrams

Recolor SVG diagrams to tints of one ink by luminance, so every illustration matches your design — ready for spot-colour printing.

### LaTeX Math

Inline and display equations written in LaTeX, measured and typeset by the engine so they sit on the baseline grid alongside the text.

### Web & Print-Ready PDF

One layout engine, three renderers. The same computed pages render to HTML, canvas, or print-ready PDF — with bookmarks and CMYK colour.

## One Function, Full Control

Call `buildDocument` with your content and a configuration object. Get back the complete page geometry, ready to render with `renderToHtml` — or the canvas and PDF backends.

```ts
import { buildDocument, renderToHtml } from "postext";

const doc = buildDocument(
  { markdown },
  {
    layout: { layoutType: "double" },
    bodyText: {
      textAlign: "justify",
      hyphenation: { enabled: true, locale: "en-us" },
    },
  }
);

const html = renderToHtml(doc);
```

## Three Steps to Publication-Grade Layout

1. **Write Semantic Markdown.** Author your content in enriched markdown with resource references and footnote markers. No layout concerns — just content.
2. **Configure Layout Rules.** Define columns, typography rules, resource placement strategies, and section overrides in a PostextConfig object.
3. **Render to HTML, Canvas, or PDF.** Call buildDocument and receive the complete layout geometry — then render it with the HTML, canvas, or print-ready PDF backend.

## Start in Under a Minute

```bash
pnpm add postext
```

```ts
import { buildDocument, renderToHtml } from "postext";

const doc = buildDocument({
  markdown: "# Hello World\n\nYour content here.",
});

const html = renderToHtml(doc);
```

## Documentation

- [Introduction to Postext](https://postext.dev/en/docs/introduction.md): What Postext is, why it exists, and the problem it solves
- [Postext Architecture](https://postext.dev/en/docs/architecture.md): Technical architecture of the Postext layout engine
- [Postext Configuration](https://postext.dev/en/docs/configuration.md): Complete reference for all Postext layout configuration options
- [Hyphenation & Justification](https://postext.dev/en/docs/justification.md): How Postext breaks lines, justifies text, and controls word spacing using the Knuth-Plass algorithm
- [Document Format](https://postext.dev/en/docs/document-format.md): The markdown subset Postext parses, and the rules for authoring source documents
- [Contributing to Postext](https://postext.dev/en/docs/contributing.md): How to join the Postext community and contribute to the project
- [Sandbox](https://postext.dev/en/docs/sandbox.md): Interactive playground for experimenting with the Postext layout engine
- [Agent skill: port a publication to Postext](https://postext.dev/en/docs/skill.md): Install the postext-port skill in Claude Code, Codex or any agent and let it turn a PDF, Word, PowerPoint, EPUB, InDesign or HTML source into a Postext project that follows the original layout

## Links

- [GitHub](https://github.com/drnachio/postext)
- [npm](https://www.npmjs.com/package/postext)
- [Sandbox](https://postext.dev/en/sandbox): Interactive in-browser editor: write markdown, tune the configuration and export print-ready PDF.
- [MIT License](https://postext.dev/en/license.md)
