Brifing

Typesetting Novellas with Groff

A technical deep dive into using Groff for creative book production.

1Transitioning to Creative Writing

The author, typically focused on technical subjects like mathematics and physics, unexpectedly wrote two novellas. The first, approximately 15,000 words, took seven months to complete, while the second, longer 40,000-word piece, was finished in just ten days. This shift followed a newfound interest in reading fiction, totaling 30 novels since July 2025.

2Choosing Groff for Typesetting

Rather than using standard word processors, the author utilized groff, a typesetting system traditionally used for Linux manual pages. The primary appeal lies in its speed and efficiency; rendering a 120-page document takes only 1.6 seconds on a 13.5-year-old PC. It provides high-quality output without the bloat of modern software.

3Custom Macro Development

To manage the layout, the author created a minimalist macro package. Since the novellas do not require complex features like tables of contents, cross-references, or diagrams, the macros focus on simple paragraph flow and text emphasis. The author uses the .de command to define these macros, stored in separate files per chapter.

4Managing Page Layouts

The author configured the document for A5 paper size using the -dpaper=a5 flag. By default, groff does not include page numbers, which the author deemed unnecessary for digital PDFs but useful for printing. To implement them, a footer trap was created at the bottom of the page using a specific register and macro.

5Implementing Footer Traps

The footer implementation uses a vertical trap, .wh, set at five units from the bottom. The _FooterTrap macro switches environments to ensure consistent formatting, prints the page number, and triggers a page break. The author noted that adding the 'u' suffix to the register value was essential for the code to function correctly.

6Header and Footer Symmetry

To maintain visual balance, a header trap was also implemented at the top of the page. The author observed that the header and footer are not perfectly symmetrical due to page size settings, which remain a pending task. The header trap uses a similar mechanism to the footer to reserve space at the top.

7Understanding Trap Mechanics

Traps are triggered when the output reaches a specific vertical position. By switching environments using .ev, the author can insert content like headers or footers without disrupting the main text flow. This technique allows for precise control over where elements appear on the page, effectively separating the main document buffer from the trap.

8Controlling Break Behavior

The author discovered that using the no-break control character, the apostrophe, is crucial when manipulating vertical positions. Using .sp triggers a break, which can cause unwanted line shifts. By using 'sp instead, the author suppresses the break until the next command, allowing for precise placement of text elements within the typesetting process.

9Refining Typography Settings

To achieve professional results, the author adjusted inter-sentence spacing using the .ss request, setting supplemental spacing to zero to match German book conventions. Additionally, the .hla and .hpf requests were used to apply German hyphenation rules from 2006, ensuring the text adheres to standard linguistic formatting for the language of the novellas.

10Markdown to Groff Workflow

While the novellas were written in plain groff, the author experimented with a simplified Markdown-like syntax for better creative focus. A small Perl script was developed to convert these Markdown elements, such as headers and paragraphs, into the corresponding groff macros, streamlining the transition from drafting to final typesetting for the second story.

11Justification and Output Quality

The author rejected HTML for book production because it lacks a robust engine for text justification, which often results in poor visual quality. Groff and TeX were chosen specifically for their superior ability to handle justification. The Perl script also handles character replacements, such as converting standard quotes into preferred typographic Guillemets.

12Technical Creative Synthesis

This project demonstrates that technical tools like groff are viable for creative writing, offering speed and control that modern word processors often lack. By building a custom, lightweight pipeline, the author successfully bridged the gap between technical documentation systems and literary creation, proving that specialized software can effectively support diverse writing workflows.

Original article: Hacker News (news.ycombinator.com) — Typesetting Novellas with Groff