In short
Five pages of a Brazilian classic novel as a small pocket book. Each short chapter starts right after the one before, and no page begins or ends with a lone line.
What you'll build
Five pages of text from near the end of Dom Casmurro, Machado de Assis’s novel of 1899, set in the original Portuguese as a 110 × 178 mm pocket book in an invented series, Coleção Casuarina. A cover in plum, cream and plum bands carries the title in Abril Fatface and the series’ saffron roundel, and a painted plate of the heavy sea off Flamengo, generated with diffusion models, faces page 213. The text runs from the end of chapter CXVIII to the end of CXXIII, and no chapter opens a page. Each starts two lines below the end of the one before (three at CXIX, to fill page 213), under a plum roman numeral, its title in tracked capitals and a short saffron rule. Page 214 has two chapter heads, 215 and 216 one each. Every page of text but the last ends on its 33rd line, and none opens on a single line.
This recipe answers
- How do I avoid widows, orphans and one-word last lines (runts), and keep a heading with its text?
- How do I get flush column bottoms and a balanced last page (vertical justification)?
- How do I number headings (1, 1.1, 1.1.1) and style each level differently?
- How do I set running heads: book title on the left page, chapter title on the right, page number outside?
The short answer
// Machado's chapters run a page or two, so none opens a page. The level's break is off (the
// H1 default would open each chapter on a recto) and a chapter starts two lines under the last.
const [NUMERAL, TITLE, TRACK, GAP] = [14, 7.5, 1.3, 1.6]; // pt, pt, pt, mm
const RULE_Y = NUMERAL * PT + GAP + TITLE * 1.2 * PT + GAP; // mm: under the title's line
const chapterHead = { enabled: true, slot: { elements: [ // no span: the head stays in the text
{ kind: 'text', id: 'numeral', content: '{number}', fontFamily: DISPLAY, fontSize: pt(NUMERAL),
lineHeight: 1, color: col('plum'), align: 'center',
placement: { ...at('container', 'top'), size: { width: 'fill' } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...caps(TITLE, TRACK), color: col('ink'),
align: 'center', overflow: 'wrap', // a long title takes a second line
placement: { anchor: { to: '#numeral', edge: 'below' }, offset: { y: mm(GAP) },
size: { width: 'fill' } } },
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1), color: col('saffron'),
placement: { ...at('container', 'top', 0, RULE_Y), size: { width: mm(8) } } },
] } }; // 11.7 mm deep: the head takes three lines, and the text under it stays on the grid
const chapters = { level: 1, numberingTemplate: '{1:I}', // {number} prints CXIX, CXX…
fontSize: pt(TITLE), // the hidden heading line, measured in the headings' face
breakBefore: { enabled: false }, marginTop: pt(2 * LEAD), advancedDesign: chapterHead };
// The keep rules are on by default. avoidWidows keeps widowMinLines (2) lines of a paragraph
// at the foot of a page, and headings.keepWithNext takes the head along when the paragraph
// moves on; avoidOrphans keeps two lines at the head of the next page; avoidRunts weighs a
// last line shorter than about 20 characters as a fault. Column balancing adds lines above
// a head so that the page ends on line 33.
Chapters that run on, each under a centred head drawn in the column
Ingredients
- Features
- Widows, orphans and runtsDesigned openersChapters that open on a rectoNumbered headingsColumn balancingHyphenation and document languageIndents, alignment and paragraph spacingRunning heads and foliosHeads by page roleHeading stylesUnnumbered chaptersCovers, title pages and colophonsPage and column breaksPictures in page designsText, rules and boxes in page designsHeading attributesMirrored marginsFloated boxesDocument metadata
- Also uses
- Box icons and corner badgesCallout boxesPaper colourFigures and tables as resourcesRoman front matterLine breaks in titles
- Type
- Tinos (Apache 2.0) · Abril Fatface, League Spartan (SIL OFL 1.1)
- Assets
plate-1100.jpg- The plate of the sea off Flamengo under the Sugarloaf, a painting (Generated With Diffusion Models, original)
- The casuarina roundel, drawn in code in the book’s palette (Ignacio Ferro, MIT)
Method
#1 · Run the chapters on, each head kept with its text
// Machado's chapters run a page or two, so none opens a page. The level's break is off (the
// H1 default would open each chapter on a recto) and a chapter starts two lines under the last.
const [NUMERAL, TITLE, TRACK, GAP] = [14, 7.5, 1.3, 1.6]; // pt, pt, pt, mm
const RULE_Y = NUMERAL * PT + GAP + TITLE * 1.2 * PT + GAP; // mm: under the title's line
const chapterHead = { enabled: true, slot: { elements: [ // no span: the head stays in the text
{ kind: 'text', id: 'numeral', content: '{number}', fontFamily: DISPLAY, fontSize: pt(NUMERAL),
lineHeight: 1, color: col('plum'), align: 'center',
placement: { ...at('container', 'top'), size: { width: 'fill' } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...caps(TITLE, TRACK), color: col('ink'),
align: 'center', overflow: 'wrap', // a long title takes a second line
placement: { anchor: { to: '#numeral', edge: 'below' }, offset: { y: mm(GAP) },
size: { width: 'fill' } } },
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1), color: col('saffron'),
placement: { ...at('container', 'top', 0, RULE_Y), size: { width: mm(8) } } },
] } }; // 11.7 mm deep: the head takes three lines, and the text under it stays on the grid
const chapters = { level: 1, numberingTemplate: '{1:I}', // {number} prints CXIX, CXX…
fontSize: pt(TITLE), // the hidden heading line, measured in the headings' face
breakBefore: { enabled: false }, marginTop: pt(2 * LEAD), advancedDesign: chapterHead };
// The keep rules are on by default. avoidWidows keeps widowMinLines (2) lines of a paragraph
// at the foot of a page, and headings.keepWithNext takes the head along when the paragraph
// moves on; avoidOrphans keeps two lines at the head of the next page; avoidRunts weighs a
// last line shorter than about 20 characters as a fault. Column balancing adds lines above
// a head so that the page ends on line 33.
The chapter level has its break turned off, and marginTop sets each head two lines under the last line of the chapter before. Its design has no span, so the head is drawn in the column, in a block three lines deep, and the text under it stays on the grid (break before, span and advanced design). The keep rules are left at their defaults. The four-line paragraphs under CXIX and CXXI each leave two lines at the foot of their page and carry two over; with avoidOrphans: false they would split three and one, and pages 214 and 215 would open on a single line (orphans, widows, runts). Column balancing adds a third line of space above CXIX, so that page 213 ends on line 33 (column balancing).

#2 · Set a page of 33 lines, with Portuguese hyphenation
const bodyText = { fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD),
color: col('ink'), referenceColor: col('ink'), // a :ref added later prints in ink
firstLineIndent: mm(5) }; // every paragraph indented, the first after a head too
const page = { sizePreset: 'custom', width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150,
backgroundColor: col('paper'),
margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - LINES * LEAD * PT), // 16.3 mm
left: mm(INNER), right: mm(OUTER), mirror: true } };
const LOCALE = 'pt'; // the Portuguese hyphenation patterns
The bottom margin is 16.3 mm, what the 178 mm height leaves after the 15 mm top margin and 33 lines of 12.6 pt, so every full page ends on the same line. Tinos, which has the widths of Times New Roman, sets about 59 characters a line on the 84 mm measure at 9.5 pt. locale: 'pt' hyphenates with the Portuguese patterns: at-tracção, af-fluencia, genealogica-mente (supported locales). Every paragraph is indented, the first after a head too, as Portuguese and Brazilian editions usually are, so indentAfterHeading keeps its default.
#3 · Name the book over the verso and the chapter over the recto
const SHIFT = (INNER - OUTER) / 2; // mm: the text block sits off the page's centre
const [HEAD_Y, FOLIO_Y] = [8.5, 167]; // mm below the top edge
const head = (id, content, parity, x) => ({ kind: 'text', id, content, parity,
pages: 'body', // never on the cover or the plate, which are opener pages
...caps(7.5, TRACK), color: col('muted'), align: 'center',
placement: at('page', 'top', x, HEAD_Y) });
const folio = (id, parity, edge, x) => ({ kind: 'text', id, content: '{pageNumber}', parity,
pages: 'body', ...caps(7.5, 0), color: col('ink'), placement: at('page', edge, x, FOLIO_Y) });
const header = { elements: [
head('verso-title', '{title}', 'even', -SHIFT), // the title in the frontmatter
head('recto-chapter', '{chapterTitle}', 'odd', SHIFT), // last chapter begun on or before it
] };
const footer = { elements: [folio('verso-folio', 'even', 'top-left', OUTER),
{ ...folio('recto-folio', 'odd', 'top-right', -OUTER), align: 'right' }] };
{title} prints the title in the frontmatter, and {chapterTitle} the last chapter that starts on or before the page, so page 217 names CXXIII, which began on page 216 (text elements). Page 213 names CXIX, which begins at its foot, though its first 25 lines close CXVIII. {chapterTitleAtTop} names the chapter a page opens in instead, but this excerpt holds no heading for CXVIII. SHIFT moves the heads onto the centre of the text block, 1 mm off the page’s centre because the inner margin is 2 mm wider than the outer one.
#4 · Draw the cover and the plate as headings
// span: 'page', in one column too, makes each an opener page: its art runs past the foot of
// the text column, and no running head or folio prints on it. Each design reaches the foot of
// the page, so the heading reserves the whole page and the text starts on the next one.
const onPage = (y, size) => ({ ...at('page', 'top', 0, y), ...(size && { size }) });
const cover = { id: 'cover', numbered: false, span: 'page',
advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'box', id: 'top-band', style: { backgroundColor: col('plum') },
placement: { ...at('page', 'top-left'), size: { width: 'fill', height: mm(62) } } },
{ kind: 'text', id: 'author', content: '{author}', ...caps(10, 2.4), color: col('paper'),
align: 'center', placement: at('page', 'top', 0, 44) },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(44),
lineHeight: 1, color: col('plum'), align: 'center', overflow: 'wrap',
placement: onPage(72, { width: 'fill' }) },
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1.5),
color: col('saffron'), placement: onPage(111, { width: mm(12) }) },
{ kind: 'box', id: 'foot-band', style: { backgroundColor: col('plum') },
placement: { ...at('page', 'top-left', 0, 124), size: { width: 'fill', height: mm(54) } } },
{ kind: 'image', id: 'roundel', resourceId: 'roundel',
placement: onPage(133, { width: mm(20) }) },
{ kind: 'text', id: 'series', content: 'Coleção Casuarina', ...caps(7.5, 1.8),
color: col('saffron'), align: 'center', placement: at('page', 'top', 0, 159) },
] } } };
// The plate faces the first page of text: the morning sea off Flamengo, captioned with the
// line of chapter CXXIII it illustrates, which the heading carries in its quote attribute.
const plate = { id: 'plate', numbered: false, span: 'page',
advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'image', id: 'sea', resourceId: 'sea',
placement: { ...at('page', 'top-left'), size: { width: 'fill', height: 'fill' } } },
{ kind: 'text', id: 'label', content: '{titleText}', ...caps(7.5, 1.6), color: col('saffron'),
align: 'center', placement: at('page', 'top', 0, 146) },
{ kind: 'text', id: 'quote', content: '{attr.quote}', fontFamily: TEXT, italic: true,
fontSize: pt(8.6), lineHeight: 1.35, color: col('paper'), align: 'center', overflow: 'wrap',
placement: onPage(152, { width: mm(78) }) },
] } } };
const resources = [
{ id: 'roundel', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
svg: { fileId: 'roundel.svg', width: 60, height: 60 },
altText: 'The series mark: a casuarina tree in a ring.' },
// The plate is a painting, a JPEG in assets/ cut to the trim, declared at its pixels.
{ id: 'sea', typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
bitmap: { fileId: 'plate-1100.jpg', format: 'jpeg', width: 1100, height: 1780 },
altText: 'A heavy morning sea under the Sugarloaf, a low sun, and a lone swimmer among '
+ 'the breakers.' },
];
Both are heading styles with numbered: false, so the first numbered chapter is still CXIX. span: 'page' makes each an opener page. Without it the cover’s foot band and the plate’s picture stop at the foot of the text block, and the running head and the folio print on both pages. The plate’s caption comes from its heading: CAPÍTULO CXXIII is the heading’s text, and the italic quotation is its quote attribute (heading attributes). Each design reaches the foot of its page, so the heading reserves the whole page and the text starts on the next one with no :::pagebreak.
#5 · Tell the excerpt where it stands in the book
const continuation = { headings: { h1: 118, h2: 0, h3: 0, h4: 0, h5: 0, h6: 0 } };
continuation.headings gives the heading counters the excerpt starts from. With h1: 118 the first numbered heading is chapter CXIX; without it the five chapters are numbered I to V. numberingTemplate: '{1:I}' in the chapter level sets those numbers in roman numerals, and the design prints them with {number}. :::numbering{startAt=212}, after the cover, numbers the plate 212 and the text pages 213 to 217 (numbering).
The whole recipe
// ═══ Postext Cookbook · Nº 065 · Pocket classic: short chapters that run on ═══════════
// https://postext.dev/en/cookbook/short-chapters-run-on
// Code: MIT · Text: Machado de Assis, Dom Casmurro, 1899 (PD, Gutenberg #55752) · Plate: painted
// Fonts: Tinos (Apache 2.0), Abril Fatface, League Spartan (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the viewer's title; the sample is Portuguese
const RECIPE = 'short-chapters-run-on';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#24202a', // the text: a violet near-black
paper: '#f6f1e6', // the pocket book's paper
plum: '#4f2a49', // the series colour: cover bands, the chapter numerals
saffron: '#d9a03c', // the second ink: rules and drawings, never text on paper (2.1:1)
muted: '#6b616e', // the running heads and the colophon (5.2:1 on paper)
};
// Each colour names its palette entry and carries its hex.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
// The default bold and italic colours link to main-color, set here to the ink, not blue.
{ id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
const [TEXT, DISPLAY, LABEL] = ['Tinos', 'Abril Fatface', 'League Spartan'];
const TRIM = { width: 110, height: 178 }; // mm: a pocket book
const [TOP, INNER, OUTER] = [15, 14, 12]; // mm; mirrored, so the inner margin is at the spine
const [BODY, LEAD, LINES] = [9.5, 12.6, 33]; // pt, pt, and the lines of a full page
const PT = 25.4 / 72; // mm per point
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const caps = (size, track) => ({ fontFamily: LABEL, fontWeight: 600, fontSize: pt(size),
letterSpacing: pt(track), textTransform: 'uppercase' });
// #region answer: chapters that run on, each under a centred head drawn in the column
// Machado's chapters run a page or two, so none opens a page. The level's break is off (the
// H1 default would open each chapter on a recto) and a chapter starts two lines under the last.
const [NUMERAL, TITLE, TRACK, GAP] = [14, 7.5, 1.3, 1.6]; // pt, pt, pt, mm
const RULE_Y = NUMERAL * PT + GAP + TITLE * 1.2 * PT + GAP; // mm: under the title's line
const chapterHead = { enabled: true, slot: { elements: [ // no span: the head stays in the text
{ kind: 'text', id: 'numeral', content: '{number}', fontFamily: DISPLAY, fontSize: pt(NUMERAL),
lineHeight: 1, color: col('plum'), align: 'center',
placement: { ...at('container', 'top'), size: { width: 'fill' } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...caps(TITLE, TRACK), color: col('ink'),
align: 'center', overflow: 'wrap', // a long title takes a second line
placement: { anchor: { to: '#numeral', edge: 'below' }, offset: { y: mm(GAP) },
size: { width: 'fill' } } },
The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)
Variations
#Open every chapter on a new page
With a break before each chapter the five pages of text become seven: page 214 holds only CXIX, its head and four lines, and page 213, where no chapter starts, takes the plate’s title, CAPÍTULO CXXIII, as its running head.
- breakBefore: { enabled: false }, marginTop: pt(2 * LEAD), advancedDesign: chapterHead };
+ breakBefore: { enabled: true, parity: 'any' }, marginTop: pt(2 * LEAD),
+ advancedDesign: chapterHead };#Put the chapter number over the recto
{chapterNumber} prints the numeral of the same chapter the title comes from: CXIX · NÃO FAÇA ISSO, QUERIDA.
- head('recto-chapter', '{chapterTitle}', 'odd', SHIFT),
+ head('recto-chapter', '{chapterNumber} · {chapterTitle}', 'odd', SHIFT),Pitfalls
Pitfall
avoidWidows guards the foot of a column, avoidOrphans its head
Postext names the two lone lines its own way: avoidWidows (widowMinLines, widowPenalty) keeps a paragraph's first line from standing alone at the foot of a column, and avoidOrphans (orphanMinLines, orphanPenalty) keeps its last line from standing alone at the head of the next. Many style manuals give the two names the other way round, so pick the setting by where it acts. Both are on by default, except on a character grid (cjk.grid): there avoidWidows is off, and avoidOrphans too in the Japan region, so that a page holds the lines its grid counts (since postext 1.28). They work as penalties: the layout weighs each one against the empty lines that obeying it would leave. Widows, orphans and runts →
Pitfall
:::numbering takes effect at the next page
:::numbering changes the count from the next page that starts, not the current one. Put it right after a :::pagebreak (parity odd before chapter one) so the new numbering begins where you mean. Roman front matter →
- Raising
widowMinLinesto 3 leaves the four-line paragraph under CXIX no place to split: three lines and one would open page 214 on a single line. The head moves on with its text, and page 213 ends six lines short. - If CXVIII grows by a few lines, CXIX has room for only one line under its head.
keepWithNextthen carries the head over to page 214 and page 213 ends four or five lines short; withkeepWithNext: falsethe head closes page 213 with no text under it. - The plate is an H1, so
{chapterTitle}falls back on it: a page of text where no chapter has started since the plate, like page 213 once CXIX moves on, prints CAPÍTULO CXXIII as its running head. Give the plate’s stylerunningChapter: falseand the running heads pass over it. - Turn
avoidRuntsoff and the last line of the book holds manhã. alone instead of nadador da manhã. - These page breaks hold only for this text at 9.5 on 12.6 pt on an 84 mm measure. After you change the text, the size or the measure, look again at the foot of every page and the space above every head.
Credits
- Recipe
- Ignacio Ferro
- Text
- Dom Casmurro (1899), from the end of chapter CXVIII to the end of chapter CXXIII, in the spelling of the Garnier edition, with one transcription slip corrected (homens, chapter CXXIII) · Machado de Assis · public domain
- The colophon, and the series name Coleção Casuarina (invented for this recipe) · Postext Cookbook · original
- Images
- The plate of the sea off Flamengo under the Sugarloaf, a painting · Generated With Diffusion Models · original
- The casuarina roundel, drawn in code in the book’s palette · Ignacio Ferro · MIT
- Fonts
- Tinos (Apache 2.0) · Abril Fatface (SIL OFL 1.1) · League Spartan (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


