In short
Five pages from a small book of essays. It shows how to print the book's title at the top of left-hand pages and the essay's title on right-hand pages.
What you'll build
Pages 29 to 33 of a pocket edition of Montaigne’s Essays in Charles Cotton’s English: the whole of chapter IV and the opening of chapter V. Versos carry the book’s title in spaced capitals. Rectos carry the essay’s title in italic, cut short with an ellipsis, since chapter IV’s title runs to 81 characters. Each folio sits in a sepia tab in the outer margin, 3 mm from a 0.5 pt rule on the edge of the text block. An opener has no head, only a folio at the foot. The text is Baskervville on a warm off-white page, the titles Libre Caslon Display, the folios and the book’s title Alegreya SC. Every head is defined in the configuration, so the engine’s built-in head, blue Open Sans at 8 pt, never prints.
This recipe answers
- How do I set running heads: book title on the left page, chapter title on the right, page number outside?
- How do I hide running heads on openers and blank pages, or paint a blank verso in the part colour?
- How do I stop headings, bold words and bullets from coming out blue?
The short answer
const GAP = 3; // mm from the tab to the divider, which lands on the text block's edge
const HEAD = 12; // mm from the top edge of the page to the top of the tab
const CAP = t({ en: 60.5, es: 66.8 }); // mm: the head's widest line, set per edition so
// essay IV's is cut after 'false' and 'objetos'; a short running title suits any title
const page = (edge) => ({ to: 'page', edge }); // the trim box (gotcha: negative-offsets)
const header = { elements: [
// Verso (even): tab | divider | THE BOOK'S TITLE from the frontmatter
folio({ id: 'folio-even', parity: 'even', pages: 'body', anchor: page('top-left'),
x: OUTER - GAP - TAB, y: HEAD }),
divider({ id: 'rule-even', parity: 'even', from: 'folio-even', edge: 'right-of', x: GAP }),
{ kind: 'text', id: 'book', content: '{title}', parity: 'even', pages: 'body',
fontFamily: 'Alegreya SC', fontSize: pt(FOLIO_PT), lineHeight: LINE / FOLIO_PT,
color: col('muted'), textTransform: 'uppercase', letterSpacing: pt(1.3),
placement: { anchor: { to: '#rule-even', edge: 'right-of' }, // top: the tab's top
offset: { x: mm(2.5), y: pt(PAD.top) } } }, // PAD.top down: on the folio's baseline
// Recto (odd): the essay's title, cut short with an ellipsis | divider | tab.
folio({ id: 'folio-odd', parity: 'odd', pages: 'body', anchor: page('top-right'),
x: -(OUTER - GAP - TAB), y: HEAD }), // from the right edge, a negative x runs inwards
divider({ id: 'rule-odd', parity: 'odd', from: 'folio-odd', edge: 'left-of', x: -GAP }),
{ kind: 'text', id: 'essay', content: '{chapterTitle}', parity: 'odd', pages: 'body',
fontFamily: 'Baskervville', italic: true, fontSize: pt(TITLE_PT),
lineHeight: LINE / TITLE_PT, color: col('muted'),
overflow: 'ellipsis-end', // stated, though a running head's default
placement: { anchor: { to: '#rule-odd', edge: 'left-of' },
offset: { x: mm(-2.5), y: pt(PAD.top) }, size: { maxWidth: mm(CAP) } } },
] };
// Openers: no head, only a drop folio HEAD above the page's foot, centred under the text block.
const footer = { elements: [folio({ id: 'drop-folio', parity: 'all', pages: 'opener',
anchor: { to: 'container', edge: 'bottom' }, y: -HEAD })] };
Running heads by parity: book on the verso, essay on the recto, folios outside
Ingredients
- Features
- Running heads and foliosHeads by page roleAnchoring design elementsText, rules and boxes in page designsDesigned openersHeading attributesLine breaks in titlesChapters that open on a rectoMirrored marginsTrim sizePaper colourDocument metadataBold, italic and their coloursSemantic colour paletteCallout boxesParagraph stylesWidows, orphans and runtsPages on a canvasBooks built chapter by chapter
- Also uses
- Full-width chapter band
- Type
- Baskervville, Libre Caslon Display, Alegreya SC (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Replace the built-in blue head
const palette = {
ink: '#1f1b16', // text: a warm near-black, never #000
sepia: '#8a5a2b', // the one accent: folio tabs, dividers, opener plates (5.3:1 on paper)
muted: '#6f6558', // running heads, verse glosses, the colophon (5.2:1 on paper)
paper: '#f8f4ec', // a warm off-white page; also the type reversed out of the sepia
};
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' } })),
// Text-style defaults (headings, bold, italic, lists, boxes) link to 'main-color':
// pointed at the sepia, none of them prints in the engine's blue.
{ id: 'main-color', name: 'sepia (defaults)', value: { hex: palette.sepia, model: 'hex' } },
];
Every colour in the configuration links to one of these entries. If you leave header undefined, the engine draws its built-in head: {title} on rectos and {chapterTitle} on versos over a 1 pt rule, in Open Sans 600 at 8 pt and #295AA3 blue (headers and footers). Pointing main-color at the sepia recolours the text defaults and that head with them, but its face, its rule and the side each title prints on stay the engine’s. So each head here is written out in full, with every colour linked to a palette entry. Bold, italic and references also default to main-color, and bodyText sets them back to the ink.
#2 · Build every head from one tab
const FOLIO_PT = 7.5; // pt: the folio, and the book's title in capitals beside it
const TITLE_PT = 8.8; // pt: the essay's title, whose italic lowercase reads small at 7.5
const LINE = FOLIO_PT * 1.2; // pt: the folio and both titles share this line box and baseline
const PAD = { top: 1, bottom: 1.4 }; // pt: 0.4 pt more below for the descending 3, 5, 7, 9
const TAB = 7.5; // mm: the tab's width
const TAB_H = LINE + PAD.top + PAD.bottom; // pt: the tab's height, which the divider matches
const folio = ({ id, parity, pages, anchor, x = 0, y }) => ({
kind: 'text', id, content: '{pageNumber}', parity, pages, fontFamily: 'Alegreya SC',
fontSize: pt(FOLIO_PT), fontWeight: 700, lineHeight: LINE / FOLIO_PT, color: col('paper'),
box: { backgroundColor: col('sepia'), borderRadius: mm(2), // a pill; the number is centred
padding: { top: pt(PAD.top), bottom: pt(PAD.bottom) } }, // by default in both directions
placement: { anchor, offset: { x: mm(x), y: mm(y) }, size: { width: mm(TAB) } },
});
const divider = ({ id, parity, from, edge, x }) => ({
kind: 'rule', id, parity, pages: 'body', direction: 'vertical', thickness: pt(0.5),
color: col('sepia'), placement: { anchor: { to: `#${from}`, edge }, offset: { x: mm(x) },
size: { height: pt(TAB_H) } },
});
The short answer anchors each head’s tab to 'page', so its offsets are measured from the trim. From the top-right corner a positive x runs off the page, which is why the recto tab takes a negative one. The divider hangs from the tab and the title from the divider (element placement). The tab’s sizes are named constants because the other pieces are measured from them. The divider is TAB_H tall. The folio and both titles share one 9 pt line box, and a design text’s baseline sits 80% of the way down its line box, so all three stand on one baseline at any type size.


#3 · Mirror the margins and count whole lines
const TRIM = { width: 132, height: 198 }; // mm
const TOP = 22; // mm: the top margin, which holds the heads (gotcha: header-paints-over-text)
const INNER = 15; // mm
const OUTER = 21; // mm: the outer margin, where the folio tabs hang
const LINES = 31; // whole lines of LEAD in the text block, so full pages end level
const MEASURE = TRIM.width - INNER - OUTER; // the text block's width: 96 mm
const geometry = { // left is the inner margin on a recto; mirror swaps it on the versos
width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, // 150 dpi is for the screen
backgroundColor: col('paper'),
margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - (LINES * LEAD * 25.4) / 72),
left: mm(INNER), right: mm(OUTER), mirror: true },
};
With mirror: true, the right margin is the outer one on a recto and moves to the left on a verso, so OUTER is always the fore-edge margin, where the tabs hang. The bottom margin is derived from the trim, the top margin and LINES, which keeps the text block at exactly LINES lines of LEAD (31 × 14 pt here) whatever trim or top margin you set. Every full page ends on the 31st line, so facing pages such as 30 and 31 end level.
#4 · Let the opener show the whole title
const PLATE = 26; // mm: a square plate at the head of the text block
const opener = {
enabled: true,
minHeight: mm(58), // the text of every essay starts on the same line
slot: { elements: [
{ kind: 'box', id: 'plate', style: { backgroundColor: col('sepia') },
placement: { anchor: { to: 'container', edge: 'top-left' },
size: { width: mm(PLATE), height: mm(PLATE) } } },
{ kind: 'text', id: 'numeral', content: '{attr.num}', fontFamily: 'Libre Caslon Display',
fontSize: pt(48), lineHeight: 1, color: col('paper'),
placement: { anchor: { to: '#plate', edge: 'align-top' }, // the plate's own box, where
size: { width: mm(PLATE), height: mm(PLATE) } } }, // the text centres by default
{ kind: 'text', id: 'book', content: '{subtitle}', fontFamily: 'Alegreya SC',
fontSize: pt(8.5), letterSpacing: pt(1.4), color: col('sepia'), align: 'left',
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(PLATE + 4.5), y: mm(PLATE - 2.9) } } }, // its baseline on the plate's foot
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Libre Caslon Display',
fontSize: pt(20), lineHeight: 1.12, color: col('ink'), align: 'left',
overflow: 'wrap', // an opener shows the whole title; the running head cuts it
placement: { anchor: { to: '#plate', edge: 'below' }, offset: { y: mm(6) },
size: { width: mm(MEASURE) } } },
] },
};
The opener sets the title in full with overflow: 'wrap' and breaks it at each \\ in the heading line. Only a page-spanning opener honours those breaks, so the level has span: 'page' (line breaks in titles). In the running head, {chapterTitle} always gives the title on one line, and the ellipsis cuts that line. The numeral comes from the heading’s {num="IV"} attribute and the small capitals beside the plate from the frontmatter’s subtitle.
#5 · Open every essay on a recto
headings: { // 400, the face's only weight: the default 700 would ask for one that is missing
fontFamily: 'Libre Caslon Display', fontWeight: 400, color: col('ink'),
levels: [
// 'odd' puts every opener on a recto, adding a blank verso when one is needed;
// span: 'page' makes the design an opener, where a \\ in the title breaks the line.
{ level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' },
marginTop: pt(0), marginBottom: pt(0), advancedDesign: opener },
],
},
With 'odd', an essay that ends on a recto is followed by a blank verso. The Spanish edition has one, because its chapter IV ends on page 31; here chapter IV ends on page 32, a verso, and chapter V opens on page 33. The heads’ pages: 'body' keeps them off blank pages and off openers (the pages whose first block is this heading). The footer’s pages: 'opener' prints the drop folio on openers only (text elements).
#6 · Start the folios at 29
// 28 pages come before this one, so recto and verso, the mirrored margins and the odd/even
// heads follow the book page (gotcha: parity-page1-recto); the folios start at 29.
const continuation = { pageIndexOffset: 28, pageNumbering: { startAt: 29 } };
const doc = await buildDocumentWithFonts({ markdown, continuation }, config(), kitFonts(FONTS));
showPages(doc, { title: t({ en: 'Running heads by parity', es: 'Cabeceras según la paridad' }) });
parity goes by the page’s place in the book and ignores its folio. pageIndexOffset: 28 adds 28 to every page’s index, so recto and verso, the mirrored margins and the odd and even heads follow the book page. pageNumbering.startAt then numbers these pages 29 to 33. Without the offset the first page of the build is a recto whatever folio it prints. That happens to suit page 29, but with startAt: 30 the book’s title would land on page 31 and the essay’s on page 32, each on the wrong side of the spread.
The whole recipe
// ═══ Postext Cookbook · Nº 005 · Running heads by parity ═══════════════════════════════
// https://postext.dev/en/cookbook/running-heads-by-parity
// Code: MIT · Text: Montaigne, tr. Cotton (PD, Gutenberg #3600); es: new translation (MIT)
// Fonts: Baskervville, Libre Caslon Display, Alegreya SC (SIL OFL 1.1) · Needs postext ≥ 1.57.0
// Pages 29 to 33 of a pocket Montaigne. Versos carry the book's title and rectos the essay's,
// the folios sit in tabs in the outer margin, and an opener prints only a folio at the foot.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'running-heads-by-parity';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: four colours with semantic ids; main-color points at the sepia
const palette = {
ink: '#1f1b16', // text: a warm near-black, never #000
sepia: '#8a5a2b', // the one accent: folio tabs, dividers, opener plates (5.3:1 on paper)
muted: '#6f6558', // running heads, verse glosses, the colophon (5.2:1 on paper)
paper: '#f8f4ec', // a warm off-white page; also the type reversed out of the sepia
};
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' } })),
// Text-style defaults (headings, bold, italic, lists, boxes) link to 'main-color':
// pointed at the sepia, none of them prints in the engine's blue.
{ id: 'main-color', name: 'sepia (defaults)', value: { hex: palette.sepia, model: 'hex' } },
];
// #endregion
const LEAD = 14; // pt: the body leading, the pitch of the baseline grid
// #region tab: the folio tab and its divider, the two pieces every head is built from
const FOLIO_PT = 7.5; // pt: the folio, and the book's title in capitals beside it
const TITLE_PT = 8.8; // pt: the essay's title, whose italic lowercase reads small at 7.5
const LINE = FOLIO_PT * 1.2; // pt: the folio and both titles share this line box and baseline
const PAD = { top: 1, bottom: 1.4 }; // pt: 0.4 pt more below for the descending 3, 5, 7, 9
const TAB = 7.5; // mm: the tab's width
const TAB_H = LINE + PAD.top + PAD.bottom; // pt: the tab's height, which the divider matches
const folio = ({ id, parity, pages, anchor, x = 0, y }) => ({
kind: 'text', id, content: '{pageNumber}', parity, pages, fontFamily: 'Alegreya SC',
fontSize: pt(FOLIO_PT), fontWeight: 700, lineHeight: LINE / FOLIO_PT, color: col('paper'),
box: { backgroundColor: col('sepia'), borderRadius: mm(2), // a pill; the number is centred
padding: { top: pt(PAD.top), bottom: pt(PAD.bottom) } }, // by default in both directions
placement: { anchor, offset: { x: mm(x), y: mm(y) }, size: { width: mm(TAB) } },
});
const divider = ({ id, parity, from, edge, x }) => ({
kind: 'rule', id, parity, pages: 'body', direction: 'vertical', thickness: pt(0.5),
color: col('sepia'), placement: { anchor: { to: `#${from}`, edge }, offset: { x: mm(x) },
size: { height: pt(TAB_H) } },
});
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
#Give long titles a short running title
Write the running title on the heading line, {num="IV" short="Of false objects"}, and print the attribute instead of the whole title; a chapter without short prints nothing there.
- { kind: 'text', id: 'essay', content: '{chapterTitle}', parity: 'odd', pages: 'body',
+ { kind: 'text', id: 'essay', content: '{attr.short}', parity: 'odd', pages: 'body',#Let essays open on either side
With 'any' an essay starts on the next page, recto or verso, and no blank page is ever added. The plate hangs from the top-left corner of the text block and the drop folio is centred under it, so both sit the same way on a verso as on a recto.
- { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' },
+ { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'any' },#Paint the blank verso in the accent
A box with pages: 'blank' prints only on the pages the recto break adds: in the Spanish edition it fills page 32 with sepia, and the English edition, which has no blank page, is unchanged.
const footer = { elements: [folio({ id: 'drop-folio', parity: 'all', pages: 'opener',
- anchor: { to: 'container', edge: 'bottom' }, y: -HEAD })] };
+ anchor: { to: 'container', edge: 'bottom' }, y: -HEAD }),
+ { kind: 'box', id: 'blank-leaf', pages: 'blank', style: { backgroundColor: col('sepia') },
+ placement: { anchor: page('top-left'),
+ size: { width: mm(TRIM.width), height: mm(TRIM.height) } } }] };Pitfalls
Pitfall
Container-relative negative offsets render nothing
Auto-width design text is clamped to its container, so a negative offset from the container pushes it out and nothing renders. Anchor such elements to the page or the bleed with explicit mm offsets, or give them a fixed width. Anchoring design elements →
Pitfall
Header and footer elements paint over text
Header and footer elements are painted over the page and the text area does not make room for them. Keep them within the margins, which are what reserve their space. Running heads and folios →
Pitfall
Page 1 is a recto: plan pages with physical numbers
Page 1 is a right-hand page and page 2 the first verso, so plan spreads with physical page numbers: an opener on an even page faces the odd page after it. Page and column breaks →
Layout warning · designTextTruncated
Design text cut short
Why. A text element of a design (a running head, a folio, a chapter opener, a part page, a contents part row) was wider than its room and lost part of a line: cut with an ellipsis, as its overflow asks, or clipped with ink past its box under overflow: 'clip'. Running heads, folios and contents part rows end in an ellipsis by default; heading and part designs wrap unless the element says otherwise. A running head cut on every page of a chapter is reported once.
Fix. Set overflow: 'wrap' on the element to break the text onto more lines, give it more room (a wider size.width or maxWidth, a smaller fontSize, tighter letterSpacing) or shorten the text. Keep the ellipsis where a single line is the design, as in a running head; the warning then only confirms what was cut. Docs →
CAPis set in each edition for essay IV’s title, the only one a running head shows here. The ellipsis follows the last whole word that fits, and that word can be a preposition: at 64 mm the Spanish head would end “…sus pasiones sobre…”. A book of long titles needs the short running title from Variations.- In the English edition, raising
minWordSpacingfrom 0.7 to 0.75 leaves the first line of essay V (“Quintus Marcius, the Roman legate…”) with no break inside the band, and its word spaces stretch to 2.4 times their normal width. The Spanish edition has no such line. After any change, check the loosest lines the capture lists.
Credits
- Recipe
- Ignacio Ferro
- Text
- Essays, Book I, chapters IV and V, in Charles Cotton’s translation edited by William Carew Hazlitt (1877) · Michel de Montaigne; Charles Cotton; William Carew Hazlitt · public domain
- Essais, livre I, chapitres IV et V: the 1595 French text in the Général Michaud edition (Firmin-Didot, 1907) · Michel de Montaigne · public domain
- Spanish translation, with its verse glosses · Postext Cookbook · original
- Fonts
- Baskervville (SIL OFL 1.1) · Libre Caslon Display (SIL OFL 1.1) · Alegreya SC (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)

