Skip to main content

Chapter 19 · Part III · In practice

Command line: postext in a terminal, a script or an agent

A single self-contained executable for macOS, Linux and Windows. It turns a .postext book, a book folder or loose Markdown into PDF, HTML, EPUB, page images and Word, packs bundles, checks books, and gives JSON output for scripts and agents

Updated 2026-11-0614 minenescadefritptzhjaar

In short

This page is for people who want to make books with Postext from a terminal instead of the website. You download one file for your computer and run it, with nothing to install. You give it your book, or a few text files, and it makes a PDF, a web page, an e-book, pictures of the pages or a Word document. It can also check a book for problems and pack its files into one. Programs and AI helpers can use it too, because it can answer in a format they read easily.

postext sets your book from a terminal, a script or an agent.

The Sandbox is where you write and design a book by eye. The command line takes the same book and produces its files without a browser: a print-ready PDF, the pages as HTML, an EPUB, an image of one page or of every page, a Word document. It also packs and unpacks .postext bundles, imports Word documents, describes a book and checks it for problems.

It is one self-contained executable per system. The postext engine, the PDF, EPUB, HTML and Word writers, the page painter (Skia), HarfBuzz for Arabic and other complex scripts, the ICC print profiles and the default fonts (EB Garamond and Open Sans) are all inside it. There is no runtime, package or library to install, and the layout is the Sandbox's: the same book breaks into the same pages.

#Get it

With Homebrew, on macOS or Linux:

brew install drnachio/postext/postext

With Scoop, on Windows:

scoop bucket add postext https://github.com/drnachio/scoop-postext
scoop install postext

Both install the executable of the newest release as a postext command, checked against its checksum, and brew upgrade postext or scoop update postext brings the next one. Without a package manager, download the file yourself.

Every release of Postext publishes the executables on its GitHub Release, with their checksums (SHA256SUMS) and a readme.txt:

FileSystem
postext-macos-arm64macOS on Apple silicon (M1 and later)
postext-macos-x64macOS on Intel
postext-linux-x64Linux x86-64 with glibc (Debian, Ubuntu, Fedora…)
postext-linux-arm64Linux ARM64 with glibc (Raspberry Pi OS 64-bit, cloud ARM servers)
postext-linux-x64-muslLinux x86-64 with musl (Alpine; run apk add libstdc++ libgcc first)
postext-windows-x64.exeWindows x64

Each file weighs between 115 and 140 MB. The link https://github.com/drnachio/postext/releases/latest/download/<file> always gives the newest one.

On Linux or macOS:

curl -fL -o postext https://github.com/drnachio/postext/releases/latest/download/postext-linux-x64
chmod +x postext
./postext

Move it to a folder on your PATH (/usr/local/bin, ~/.local/bin) to run it as postext from anywhere. macOS quarantines a file downloaded with a browser; clear the flag once:

xattr -d com.apple.quarantine postext-macos-arm64

On Windows, in PowerShell:

Invoke-WebRequest https://github.com/drnachio/postext/releases/latest/download/postext-windows-x64.exe -OutFile postext.exe
.\postext.exe

With Node.js installed, npx postext-cli downloads the executable of your system from npm and runs it, and npm install -g postext-cli keeps it as a postext command.

Run with no arguments, postext prints its help; postext help <command> lists the options of one command.

#A first book

Three Markdown files in a folder are a book, one chapter each, in name order:

postext pdf chapters/ --name "Field notes" -o field-notes.pdf

The first chapter's front matter gives the book its title and author, and the engine's defaults do the rest: two columns, a baseline grid, justified and hyphenated text, running heads. Add a configuration and pictures when you need them:

postext pdf chapters/ --config design.json --resources pictures/ -o field-notes.pdf

A book made in the Sandbox (Books › Download (.postext)) works as it is:

postext pdf my-book.postext -o my-book.pdf
postext image my-book.postext --page 1 -o cover.png

#What a book can be

Every command that reads a book takes any of these:

  • A .postext file: the bundle the Sandbox exports and opens (see Bundles).
  • A book folder: an unpacked bundle, with its preset.json, its chapters, resources and fonts. The agent skill delivers this, and postext unpack writes one.
  • Loose Markdown: one or more .md files, one chapter each in the order given, or a folder whose .md files are taken by name (01-intro.md, 02-method.md…). With them:
    • --config design.json: the configuration, either a bare configuration object or a whole preset.json;
    • --resources pictures/: the pictures, each one a figure named by its file name without the extension (map.png is ::resource{id="map"}); a resources.json in the folder describes them instead (ids, types, captions, alternative text), in the same form as the resources of a preset.json;
    • --fonts fonts/: font files the book carries (TTF, OTF, WOFF2), named by the family their tables give;
    • --name "Title": the book's name.

--config also works on a bundle or a folder: it is merged over the book's own configuration. A multilingual bundle is read in its own language unless --locale asks for another (--locale en).

#Commands

CommandWhat it does
pdfThe PDF, with bookmarks, links, embedded fonts and, by default, tagged for accessibility (PDF/UA); PDF/X and CMYK for print.
htmlThe pages as HTML with real text: one self-contained file, or a folder with index.html and assets/.
epubAn EPUB 3 book, with fixed pages as printed or reflowable text.
imageOne page as a PNG, JPEG or WebP picture.
imagesEvery page, or a range, as pictures in a folder.
docxThe chapters as a Word document: semantic (the content alone, in plain Word styles), formatted (the same editable text with the book's design) or a page facsimile (every line in a fixed text box).
idmlThe pages as an InDesign package (IDML), for finishing in InDesign.
import-docxThe corrections made in an exported Word file, back into the book; any other Word document as a new book (a folder or a .postext).
import-idmlAn InDesign document saved as IDML, as a new book (a folder or a .postext).
packA book folder or loose Markdown as one .postext file.
unpackA .postext file as a folder.
infoThe book's chapters, languages, resources and fonts, and with --pages its page count.
checkLays the book out and reports every problem; for print, the preflight.
buildLays the book out once and writes several of the outputs above; --watch keeps going and rebuilds on every save.

Every command writes next to where you run it, named after the input, unless -o gives the path (images writes into pages/). -o - writes a single output to the standard output.

#pdf

postext pdf book.postext -o book.pdf
postext pdf book/ --pdfx x4 --profile fogra51 -o book-print.pdf
postext pdf book/ --color-space grayscale --no-outlines

The PDF follows the book's own settings (see PDF generation and Print production); these options change them for one run:

  • --pdfx none|x1a|x4: the PDF/X standard for a printer.
  • --profile NAME|FILE: the output ICC profile, by name (fogra39, fogra51, fogra52, swop5, gracol2006, snap2007, ifra26 and the other profiles of the print settings) or an .icc file.
  • --color-space rgb|cmyk|grayscale.
  • --accessible / --no-accessible: the tagged structure for screen readers.
  • --no-outlines: leave out the bookmarks.
  • --page-negative: negative pages, for some print workflows.

#html

postext html book.postext -o book.html
postext html book.postext -o site/ --mode single

A path ending in .html gets one file with the pictures and fonts inside it, easy to send. Any other path is a folder: index.html beside assets/, which holds the pictures, the fonts and self-hosted videos. --assets embed|folder chooses either way for any path. The pages are the print layout, shown at screen size: side by side (--mode multi, the default) or one under another (--mode single). Fonts marked redistributable: false are named but not copied. When the family names a fallback, the faces of that open family are written instead, under the family's name (since postext 1.43).

#epub

postext epub book.postext -o book.epub
postext epub book.postext --layout reflowable --cover cover.jpg

--layout fixed (the default) keeps every page as printed, with selectable text; --layout reflowable lets the reading system set the text again for its screen (see EPUB books). The cover is the book's thumbnail unless --cover gives a picture. The package metadata (title, authors, language, identifier) comes from the first chapter's front matter, as in the Sandbox. Fonts marked redistributable: false are not copied; a family that names a fallback is embedded in that open family's faces under its own name (since postext 1.43).

#image and images

postext image book.postext --page 12 -o page-12.png
postext image book.postext --page "#1" --dpi 300 -f jpeg -o cover.jpg
postext images book.postext -o pages/ --dpi 100
postext images book.postext --pages 1-10,iv -f webp --pattern "{chapter}-{label}"

Pages are named as printed (12, iv, a range 7-9) or by position in the book with # (#1 is the first page whatever it prints, #10-#20, #30- to the end). --pages takes a comma-separated list. The painter is the Sandbox's Canvas view, so an image shows the page exactly as laid out, without going through a PDF.

  • --format png|jpeg|webp (or the extension of -o), --quality 1-100 for JPEG and WebP.
  • --dpi: resolution, 150 by default; 72–100 is enough to read a page, 300 for print.
  • --pattern: the file names of images, from {n} (the position, {n:03} padded to three digits), {label} (the printed number) and {chapter}; page-{n:03} by default.
  • --print-preview: the page as the printer will reproduce it, through the output profile, with the trim and bleed drawn.
  • --jobs N: how many pictures are encoded at once (by default, as many as the computer has processors).

#docx and import-docx

postext docx book.postext -o book.docx
postext docx book/ --variant semantic -o words.docx
postext docx book/ --variant facsimile -o pages.docx
postext import-docx book.docx book/ --dry-run
postext import-docx book.docx book/
postext import-docx manuscript.docx -o manuscript/ --locale es --report

docx writes the Word documents the Sandbox exports (see Sandbox › Word documents), and a third one. --variant formatted, the default, builds an editable document from the Markdown, with Word's own headings, lists, footnotes, tables, equations and sections, set with the book's design as far as Word allows and with the book's faces embedded (--no-embed-fonts only names them); what Word has no structure for travels as its source in Postext Source content controls. --variant semantic writes the same text as content only: a plain document (A4, one column, Arial) in Word styles that name each part, with none of the page design and no fonts embedded. Neither needs a layout; both open in Word and in Google Docs, and both come back through import-docx. --variant facsimile lays the book out as pdf does and writes each page as a Word section, every line in a fixed text box, with the faces embedded: a file for looking at the layout in desktop Word, not for editing and not for Google Docs. A family the book may not hand on (redistributable: false in customFonts) is left out and its open fallback goes in, as in the EPUB; a face whose licence forbids embedding, one with PostScript outlines and a variable font are reported and only named. In build, --docx FILE writes the same file, with --docx-variant and --no-docx-fonts. Since postext 1.68; --template no longer applies to docx or build.

With a book after the file, import-docx brings back the corrections made in a document docx exported from that book. It reads the map the file carries, compares the text with the copy of the chapters made at the export, and merges each correction into the book as it is now: the chapter files of a folder, a .postext or loose Markdown, and the wording of the resources (captions, notes, alternative text, table cells) in preset.json, or in the resources.json of --resources DIR for loose Markdown. For a book in several languages, --locale names the edition the file was exported from, and a correction to a resource's wording goes into that edition's localized block. Every correction is reported on a line of its own:

  • applied, with the file and line it went to;
  • conflict: the text also changed in the book since the export, the chapter or resource is gone, or two corrections overlap;
  • rejected: text the book makes itself (numbers, caption labels), or formatting that crosses Postext markup.

Tracked changes are taken as accepted, and comments are listed with their author and place but not written. The exit code is 3 when a correction was not applied. --dry-run (-n) prints the report and a unified diff of every file it would change, and writes nothing. Each file is written beside its target and renamed over it, so an interrupted run never leaves half a chapter; a chapter file that changed while the import ran is left alone with a docx.fileChanged warning. -o does not go with a book. With --json the answer has variant, exportId, edits (each with status, reason, kind, before, after and at), comments, files and, on a dry run, diff.

A file edited in Google Docs and downloaded as .docx comes back too. Docs leaves out the map and the copy of the chapters; the import writes the map again from the book, and says so in the report. Because that file carries no copy of the exported text, it is compared with the book as it is now. If the book changed since the export, the report warns about it, and a change made in the book meanwhile may show as an edit that undoes it. Import a Docs file into the book it was exported from, before changing that book; a file saved by Word keeps its map and merges with later changes to the book. Docs also removes the hidden bookmark of a text that is replaced whole (a heading, a table cell, a caption, a box title, a footnote). The import finds such a text by its place between its neighbours, so a heading stays a heading and a caption goes to its resource. When that cannot be decided, for example because a paragraph was also typed beside it and nothing tells the two apart, the report shows a deletion and an addition instead. Importing the same file a second time brings nothing.

Without a book, import-docx turns any Word document into a new book: a chapter at each level-1 heading (--no-split keeps one), pictures and tables as resources, and --report prints the quality report the Sandbox shows (styles in use, direct formatting, typed numbering…). --template takes an import template (a .json saved from the Sandbox, or a .docx that carries one).

Character spacing is a property of a style, not of the text, so it is not in the Markdown. docx writes the letterSpacing of paragraph styles, heading styles and heading levels as the Word style's character spacing, and import-docx reads it back in em of the style's size: it sets letterSpacing on the book's styles that have none (the paragraph and heading styles of the --config file that the Word styles map to, and the heading levels), and leaves any tracking the book already sets as it is. With --json, styleTracking lists what was set (applied) and what was left (skipped). Since postext 1.39.

#idml

postext idml book/ -o book.idml
postext idml book.postext -o book.idml --images link
postext idml book/ -o out/book.idml --lines reflow --fonts

idml lays the book out as pdf does and writes the pages as an InDesign Markup package, for finishing in InDesign: the pages in spreads about the spine for a book with facing-page margins (one page per spread for any other), rules, boxes, paths and pictures as page items, tables as InDesign tables, each composed-page frame's text as a text frame with its own story (frames chained by next share one), callout styles as paragraph styles and authored CMYK colours as swatches. Chips that carry a form field become InDesign form fields. --lines keep (the default) ends every line where Postext ended it, so InDesign shows the same lines as the PDF; --lines reflow leaves the paragraphs to InDesign's composer, and line breaks may differ. --spreads facing or --spreads single pairs the pages, or not, whatever the margins say. --images link puts the pictures beside the file in Links/ instead of inside it. --fonts writes the font files of the faces used beside the package, in Document fonts/, where InDesign finds them for that document; it needs -o to name a file, and a family the book may not redistribute is left out with a warning. What the package cannot carry as the book has it (emphasis dots in vertical text, a table's rounded frame) is reported as an idml.* warning. The writer is the postext-idml package: see Programmatic usage › InDesign packages. In build, --idml FILE writes the same package, with --idml-images, --idml-lines, --idml-spreads and --idml-fonts. Since postext 1.71; --lines and --fonts since 1.76, --spreads since 1.78.

#import-idml

postext import-idml book.idml -o book/
postext import-idml book.idml -o book.postext --layout flow --links pictures/
postext import-idml book.idml --report --json

import-idml reads an InDesign Markup package and writes a new book, a folder or a .postext: the chapters as Markdown, the configuration the document's styles and pages give, and its pictures and tables as resources. An .indd is not read: save it from InDesign as InDesign Markup first. --layout pages follows the document page for page as composed pages, each frame where it stood; --layout flow writes a flowing book, the text in reading order under the document's styles, for Postext to set again; auto (the default) picks one and says why. Linked pictures are read from --links, or else from beside the file and its Links/ folder, and the ones not found are listed. The fonts the document names are listed too: a package carries no font files, so give them with --font-dir when the book is built.

A book exported from Postext comes back with the same lines. A document made in InDesign is read with losses: the command prints the verdict (faithful, approximate or lossy), the counts and what was lost or approximated; --report adds the notes and how each paragraph style was read, and --json carries all of it as data. --hidden, --pasteboard and --non-printing also read hidden layers and objects, the pasteboard and non-printing objects; --conditions all reads all the conditional text, --changes reject reads tracked changes as rejected, and --no-masters leaves out master-page items. --name and --locale give the title and the language. The importer is idmlToPostext of the postext-idml package: see Programmatic usage › InDesign packages. The import copies the document as it is; to port a book you will keep, with its layout rules worked out, use the agent skill instead (see InDesign: import, export and porting).

#pack and unpack

postext pack my-book/ -o my-book.postext
postext pack 01.md 02.md --name "Notes" --config design.json --resources img/ -o notes.postext
postext unpack my-book.postext -o my-book/

pack zips a book folder as it is, or builds a bundle from loose Markdown. The same input always gives the same bytes, so a bundle can be compared or hashed. For loose Markdown, --id, --description and --thumbnail FILE (a cover picture) set the bundle's id, description and thumbnail; the id is a slug of the name by default. A folder keeps what its preset.json says. A book that names no cover gets its first page as one (thumbnail.jpg, 1024 px on its long side), the picture a file manager can show for the file; --no-auto-thumbnail leaves it out. unpack refuses to write into a folder that is not empty unless --force is given.

#info and check

postext info book.postext --pages
postext check book.postext
postext check chapters/ --strict --json

info lists the chapters (title, words, file, and with --pages their pages), the resources and every font family with where it comes from (the book, a folder, the executable, the download cache, or the fallback). For a book that says where it starts (start in preset.json: an excerpt that opens on page 58, in chapter 4), it prints that too, and every command lays the book out from there.

check lays the book out and reports what the Sandbox's Checks panel shows: Markdown that does not close, unknown resources, directives and styles, boxes the layout had to force, fonts that are missing, settings the engine had to replace, and, for a book set up for print (or with --preflight), the preflight: low-resolution pictures, hairlines, small text in several inks, ink over the limit, text near the trim. It also lists text that is hard to read against its background (contrast), once per pair of colours, with the ratio on screen and, for print, on the paper of the output profile. Each problem names the chapter file, the line and the page. The exit code is 3 when an error is found, or any warning with --strict.

It also reports texts in the configuration's designs that hold the book's text instead of placeholders (contentInConfig), once per heading style, running head or part design, with the path of each text: move that text into the Markdown, or list a title or a publisher's name in checks.contentInConfig.allow.

For a book with page templates, check also reports text that does not fit its frame (frameOverflow, with the steps the reflow ladder tried and the changes that would fix it), a story that runs past the pages a frame may add (frameContinuationLimit), a jump to a page that does not follow (continueTargetMissing), figure labels that cannot be drawn or that collide (labelAnchorUnknown, anchorUnlabelled, labelOverflow, labelOverlap), frames hidden under other frames or running past their edge (frameCovered, frameOutsideArea), more cards than a grid holds (repeatOverflow) and modules a page cannot lay (moduleUnknown, moduleAsPage, moduleNested, moduleNameRejected). After the warnings it prints one reflow line per composed page that has events, and --json carries the steps, the proposals and the reflow log as data. See Composed pages › Warnings and Reflow log.

#build and --watch

postext build book/ --pdf out/book.pdf --html out/book.html --images out/pages --pages 1-4
postext build chapters/ --pdf book.pdf --watch

build lays the book out once and writes every output you name (--pdf, --html, --epub, --images, --docx, --idml), with the options of each command. --watch stays running: when a chapter, the configuration or a picture changes, the book is laid out again with the fonts and the engine still loaded, typically in a fraction of a second for a chapter, and the outputs are rewritten. A save that breaks the book prints the error and keeps the last good files.

#Options for every book

OptionWhat it does
--locale TAGThe language to read a multilingual book in (es, en, pt-BR…).
--chapters LISTLays out some chapters only: 2, 1,3-5, 4-. Faster on a long book; their pages are numbered from their own first page.
--set PATH=VALUEChanges one setting for this run, as a dotted path: --set page.dpi=150, --set bodyText.fontFamily=Lora, --set headings.levels.0.italic=true. The value is read as JSON when it can be (numbers, true and false, objects), otherwise as text. Repeatable.
--config FILEA configuration (or a preset.json) for loose Markdown, or merged over a book's own.
--resources DIR, --fonts DIR, --name TEXTPictures, fonts and title for loose Markdown.
--font-dir DIRA folder to look in for fonts the book does not carry. Repeatable.
--offlineNever download fonts.
--cache-dir DIRWhere downloaded fonts are kept.

And for every command: --json, --quiet (-q, errors only), --verbose (progress and every warning), --no-color, --help (-h), --version (-v).

#Fonts

A book that carries its fonts (a bundle, or --fonts with loose Markdown) is set with them and nothing else. For each family the configuration names that the book does not carry, postext looks, in order:

  1. in the folders given with --font-dir;
  2. among the faces compiled into the executable: EB Garamond and Open Sans, the engine's defaults;
  3. in the download cache;
  4. on Google Fonts, which gives whole static TrueType files, or on Fontsource for a family Google Fonts does not have (Commit Mono, FiraGO); they are kept in the cache, so a family is downloaded once.

A weight a family does not ship is set in the face a browser would choose for it (CSS font matching: the heavier faces first above 500, the lighter first below 400, so a 600 of a family with a 400 and a 700 is its 700, and so is a 550), and a slant it does not ship is set in its upright. Each is used as it is, in the page images as in the PDF: a display face with one weight keeps its own letters for a bold, and an upright family keeps its upright for an italic.

The weights the configuration names are the ones fetched: regular, bold and their italics for every family, and any other weight a setting gives, the bold's included (bodyText.boldFontWeight: 600 asks for the 600 face). When a weight the family ships could not be loaded (offline with no cached file, a download that failed, a font folder without the file), the text is set in the face of the family that the same rule picks in its place, and postext check lists it as a fontFallback warning: its lines may break differently from the Sandbox.

A character a face has no glyph for is drawn from another face. postext check reads the cmap of every face it loads and lists such characters once per face for the whole book as a glyphFallback warning; with --json, its data holds the characters and their count.

The cache is ~/.cache/postext (%LOCALAPPDATA%\postext\cache on Windows); POSTEXT_CACHE_DIR or --cache-dir moves it. --offline skips the download. A family found nowhere is set in EB Garamond under its own name, so the layout and the PDF still agree, and a missingFont warning names it. postext info shows where each family came from.

A bundle that leaves a licensed family's files out may name an open family of about the same width for it (fallback in the manifest's fonts, since postext 1.42). postext then looks that family up by the steps above and sets the faces the book does not carry in its cuts of the same weight and slant, under the licensed family's name, so the layout is close to the one with the files and postext check does not report a missingFont for it. A family the book carries only in part takes from the fallback only a slant it has no face for. The PDF embeds the open face.

#For scripts and agents

The command line is built to be driven by other programs, including coding agents.

  • --json prints one JSON object on the standard output when the command ends; every message goes to the standard error. The report lists what was written, the pages, every warning with its source, and how long each step took (in milliseconds):
{
  "ok": true,
  "command": "pdf",
  "version": "1.22.1",
  "book": { "name": "notes", "id": "notes", "locale": "en", "chapters": 2 },
  "pages": 3,
  "outputs": [{ "kind": "pdf", "path": "notes.pdf", "bytes": 29746, "pages": 3 }],
  "warnings": [
    {
      "kind": "unknownResourceId",
      "severity": "warning",
      "message": "Unknown resource id \"map\" in ::resource — nothing is embedded (offset 26)",
      "at": "notes/02-more.md:5"
    }
  ],
  "timings": { "read": 13, "fonts": 8.4, "math": 28.2, "layout": 51.6, "pdf": 132.1, "total": 1638 },
  "exitCode": 0
}
  • Exit codes: 0 done, 1 failed, 2 wrong usage (an unknown option, a missing input), 3 check found errors (or warnings with --strict), or import-docx left a Word correction out.
  • No questions. It never waits for input; a folder that is not empty is refused instead of asked about.
  • Standard output: -o - writes a PDF, an image or a bundle there, to be piped onwards.
  • Speed. The executable starts in a few hundredths of a second. A short book becomes a PDF or a page image in well under a second; a long one takes what its layout takes (a 140-page illustrated novel, about ten seconds). To look at a few pages of a long book, combine --chapters with image or images --pages. To work on a book over many changes, keep postext build --watch running and read its outputs.

The agent skill uses the command line to render the pages it is working on and to check a port.

#Python

pip install postext makes the command line a Python library. The package is pure Python, with no dependencies, and its version is postext's. The first time it runs a command it downloads the executable of your system from the GitHub Release of that version, checks it against SHA256SUMS and keeps it in the cache folder above, under bin/<version>/. Set POSTEXT_BIN to an executable you already have (from Homebrew, Scoop or your own build) and nothing is downloaded.

import postext
 
report = postext.pdf("book.postext", out="book.pdf", set={"page.dpi": 300}, locale="es")
print(report.output.pages)
for warning in report.warnings:
    print(warning.kind, warning.at, warning.message)
 
pdf = postext.pdf_bytes(open("book.postext", "rb").read())
  • One function per command: pdf, html, epub, image, images, docx, import_docx, pack, unpack, info, check and build. The options keep their names, with underscores (color_space, font_dirs, dry_run). set takes a dict, config a file or a dict, chapters a number, a list, a range or "1,3-5".
  • Reports as objects. Each function runs its command with --json and returns the report: outputs, pages, timings and warnings, each a Diagnostic with kind, severity, message, at and page. info adds chapters, resources and fonts; check adds passed, error_count and warning_count.
  • Errors as exceptions. A failure raises PostextError, a wrong option UsageError. When check finds errors it raises ProblemsFound, whose report lists them; with raise_on_problems=False it returns the report.
  • Bytes. A book can be given as the bytes of a .postext bundle. With out="-" the file comes back in report.content; pdf_bytes, html_bytes, epub_bytes, image_bytes, docx_bytes and pack_bytes return it directly.
  • postext.Postext(binary, cwd=…, timeout=…) runs a given executable, and python -m postext … is the command line itself.

Each call starts the executable again. The package's README lists every option.

#How it is made

The command line is the postext-cli package of the repository. Bun compiles it, with the engine and its writers, into one executable per system, and Skia (through @napi-rs/canvas) measures and paints the text, as the browser's canvas does in the Sandbox. An SVG picture that holds a raster image (a PNG or JPEG embedded as a data URI, as pdftocairo -svg writes artwork cut from a PDF) is drawn by resvg instead, because Skia's SVG renderer leaves such images out. On every release the executables are built, run on Linux, Alpine, macOS and Windows, and attached to the GitHub Release; npm receives postext-cli and one postext-cli-<system> package per executable.

To run it from a copy of the repository:

pnpm install
pnpm --filter postext-cli start pdf book.postext
pnpm --filter postext-cli build:bin --current

The first runs it from its sources; the second writes this computer's executable to packages/postext-cli/bin/.

#Differences from the Sandbox

  • HTML is the print layout shown at screen size. The Sandbox's HTML tab lays the text out again for the window.
  • --chapters lays out the chapters on their own: their page numbers start again, where the Sandbox continues the book's numbering.
  • Fonts come from the book, your folders, the executable, Google Fonts or Fontsource (for a family Google Fonts does not have), never from the fonts installed on the computer, so a book comes out the same on every machine.
  • The language of the text is the document's own in a browser (bodyText.shapingLanguage: 'document', the default since postext 1.30). Skia's canvas accepts a language but shapes without it, so the command line measures the forms of each font's default language and always lays its books out with shapingLanguage: 'host', whatever the configuration says; its PDF and its pictures paint those same forms. A book whose face has forms for a language (a Catalan l·l, a Turkish fi, the digits of a Chinese face in an English book) is set in the default forms here. What 'document' measures otherwise (the parts of a word broken at a line end, a right-to-left word, a design text) is measured here as 'host' measures it, so a line can break at a different word than in the Sandbox.