In short
Four pages of an old sailors' dictionary. Letter tabs run down the outer edge of each page, and the tab for the current letter is dark and sits lower as the alphabet goes on.
What you'll build
Four pages from a new edition of Admiral Smyth’s Sailor’s Word-Book (1867), letters A to C, on a 150 × 200 mm page. The entries run in two justified columns of 8 pt Alegreya divided by a hairline, each headword bold in navy and each turnover line hung 1 em. A letter opens inside its column, as a four-line navy initial over a brass rule, and the entries run on without a page break. Down the fore-edge every page prints the whole thumb index, 22 tabs in a pale tint. The current letter’s tab is navy, 3.2 mm wider than the others, and sits one step lower for each letter. The Spanish edition keeps Smyth’s English headwords and translates the entries.
This recipe answers
- How do I add a thumb index: a tab on the fore-edge that steps down the page from one letter or chapter to the next?
- How do I set a bibliography or glossary (hanging indent, smaller type)?
- How do I colour key terms (bold or italic) in the body or inside boxes?
- 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?
The short answer
// 22 tabs share the 44 lines of the text block, two lines each; letters with few words
// share a tab, as in most thumb-indexed dictionaries.
const TABS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'QR', 'S', 'T', 'UV', 'W', 'XYZ'];
const STEP = 2 * LEAD * PT; // mm: 7.34
const EDGE = { odd: 'top-right', even: 'top-left' }; // the fore-edge: right on a recto
// A cell of the index, `width` mm inside the trim and 3 mm past it, so that only its
// inner corners show their rounding; its label is centred on the part inside the trim.
const cell = (id, label, i, parity, width, fill, ink, size) => {
const y = mm(TOP + i * STEP + 0.3); // a 0.6 mm gap between neighbours
const at = (x, w) => ({ anchor: { to: 'page', edge: EDGE[parity] }, offset: { x: mm(x), y },
size: { width: mm(w), height: mm(STEP - 0.6) } });
return [
{ kind: 'box', id, parity, style: { backgroundColor: col(fill), borderRadius: mm(1.2) },
placement: at(parity === 'odd' ? 3 : -3, width + 3) },
{ kind: 'text', id: `${id}-label`, parity, content: label, fontFamily: LABEL, fontWeight: 700,
fontSize: pt(size), lineHeight: 1, color: col(ink), align: 'center',
verticalAlign: 'middle', placement: at(0, width) },
];
};
const sides = (make) => ['odd', 'even'].flatMap(make);
// Every page prints the whole index, pale, in the book's header (hook-up in config()).
const ladder = sides((p) => TABS.flatMap((label, i) =>
cell(`index-${i}-${p}`, label, i, p, 5.8, 'tint', 'slate', 7.5)));
// The section's own tab goes in its footer, which paints after the header: it lies over
// its pale cell. Elements anchored to 'page' can sit anywhere, whichever slot holds them.
const letterStyles = () => TABS.flatMap((label, i) => [...label].map((letter) => ({
id: letter,
// '# B {style="B"}' opens the section of B: its pages take this footer, and a page
// where A ends and B begins takes B's (gotcha: section-last-wins).
footer: { elements: [...footer.elements,
...sides((p) => cell(`tab-${p}`, label, i, p, 9, 'navy', 'paper', 8.5))] },
})));
One heading style per letter, each with its tab one step down the fore-edge
Ingredients
- Features
- Bleed bands and thumb tabsRunning heads per sectionBold, italic and their coloursHeading stylesDesigned openersAnchoring design elementsPictures in page designsHeading attributesParagraph stylesBibliographies and glossariesHeads by page roleRunning heads and foliosColumn ruleColumn balancingWidows, orphans and runtsHyphenation and document languageSemantic colour palettePaper colourMirrored marginsFigures and tables as resources
- Type
- Alegreya, Alegreya SC, Alegreya Sans SC (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Give each letter a heading style with its own tab
The code is the short answer above. TABS lists 22 tabs, with the rare letters sharing one (QR, UV, XYZ). Each tab is two body lines (7.34 mm) deep, so together they fill the 44 lines of the text block. The book’s header prints the running heads and the pale index on every page. The loop gives each letter a heading style whose footer adds that letter’s navy tab, one step lower than the last (heading styles). The footer paints after the header, so the tab lies over its pale cell, and the configuration holds the index once rather than once per letter. Every cell is written twice, once per parity, and anchored to the outer edge of the page rather than to its slot’s own container. That container is a margin as wide as the text block, while the tabs have to reach the fore-edge and run down all 44 lines. A page takes the footer of the last section that starts on it, so page 2 begins in A and shows the tab for B.
#2 · Keep the running heads off the first page
const HEAD = 11; // mm from the trim's top to the heads' top
const head = (id, content, parity, edge, x, extra) => ({ kind: 'text', id, content, parity,
pages: 'body', fontFamily: LABEL, fontSize: pt(8), fontWeight: 500, letterSpacing: pt(1),
color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(HEAD) } }, ...extra });
const folio = { fontWeight: 700, color: col('ink'), letterSpacing: pt(0) };
const runningHeads = [
head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folio),
head('verso-title', '{title}', 'even', 'top-left', OUTER + 8),
head('recto-letter', t({ en: 'Letter {chapterTitle}', es: 'Letra {chapterTitle}' }), 'odd',
'top-right', -(OUTER + 8)),
head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folio),
];
// The first page drops its folio to the foot, under the text block.
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'top', 0, {
...folio, pages: 'opener',
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(6) } } })] };
The heads are text elements anchored to the page and filtered by parity and pages: 'body' (text elements). The title on page 1 spans both columns, which makes page 1 an opener. The heads skip it, and its folio comes from the footer, an element set to pages: 'opener' that prints 6 mm below the text block. On a recto {chapterTitle} prints the letter of the last level-1 heading on or before the page, Letter C. {firstMark.<key>} and {lastMark.<key>} print a page’s first and last headword instead, the guide words most dictionaries carry; this recipe keeps the letter, which is what its tabs index.
#3 · Colour the headwords and nothing else
// Bold and italic default to the engine's blue: the body sets them to ink, and only the
// entry style prints its bold, the headwords, in navy.
const BODY = 8; // pt: a reference size, about 50 characters to the 60 mm column
const bodyText = { fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), firstLineIndent: mm(0),
minWordSpacing: 0.7, maxWordSpacing: 1.7,
maxJustifyTracking: 10, // up to 1 % of tracking before a line's spaces pass 1.7
hyphenateAcrossColumns: false, // no word is divided over a column or a page
maxRuntTracking: 0 }; // a short last line stays: tracking it away crushes a 60 mm line
const paragraphStyles = [
{ id: 'entry', hangingIndent: em(1), boldColor: col('navy') }, // :::paragraphs{style="entry"}
{ id: 'colophon', fontSize: pt(7), color: col('muted'), textAlign: 'center',
marginTop: pt(LEAD) },
];
Each entry is one paragraph of a :::paragraphs{style="entry"} block, its turnover lines hung 1 em (paragraph styles). The body’s boldColor keeps Note. on page 1 in ink, and the entry style’s boldColor prints the headwords in navy. A paragraph style has no italicColor, so the italic sub-entries keep the body’s ink.
#4 · Drop a four-line initial into the column
// Its cap line meets the first body line's and it stands on the fourth baseline. Cap
// heights measured on the glyph H: 0.652 em in Alegreya SC 900, 0.646 em in Alegreya.
const DROP = 4; // body lines the letter spans
const LETTER = ((DROP - 1) * LEAD + 0.646 * BODY) / 0.652; // pt: 55.8
// A design line sets its baseline 0.8 of its height below its top; a body line does too.
const letterHead = { enabled: true, slot: { elements: [
{ kind: 'text', id: 'letter', content: '{titleText}', fontFamily: DISPLAY, fontWeight: 900,
fontSize: pt(LETTER), lineHeight: 1, color: col('navy'), align: 'left',
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { y: pt((DROP - 0.2) * LEAD - 0.8 * LETTER) } } },
{ kind: 'rule', id: 'hairline', direction: 'horizontal', thickness: pt(0.6), color: col('brass'),
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { y: pt((DROP + 0.55) * LEAD) }, size: { width: 'fill' } } },
] } };
LETTER, 55.8 pt, is the size at which a capital of Alegreya SC 900 (0.652 em tall) stands on the fourth baseline and reaches the cap line of the first body line. The letter and the brass rule end inside the fifth line, and the heading block snaps down to the next grid line, so each head is five lines deep and the entries under it stay on the grid. On page 3 the C at the head of the second column is level with the first four lines of the first column. Level 1 sets breakBefore: { enabled: false }, which switches off the page break a level-1 heading has by default, and the letter styles inherit it, so B and C open mid-column.
#5 · Lay the title across both columns
const centred = (id, content, family, size, lineHeight, y, width, extra) => ({ kind: 'text', id,
content, fontFamily: family, fontSize: pt(size), lineHeight, color: col('navy'), align: 'center',
overflow: 'wrap', ...extra, placement: { anchor: { to: 'container', edge: 'top' },
offset: { y: mm(y) }, size: { width: width ? mm(width) : 'fill' } } });
const rule = (id, y, thickness) => ({ kind: 'rule', id, direction: 'horizontal',
thickness: pt(thickness), color: col('navy'), placement: { anchor: { to: 'container',
edge: 'top-left' }, offset: { y: mm(y) }, size: { width: 'fill' } } });
const titleBand = { enabled: true, slot: { elements: [
{ kind: 'image', id: 'anchor', resourceId: 'anchor', placement: {
anchor: { to: 'container', edge: 'top' }, size: { width: 'auto', height: mm(18) } } },
centred('name', '{titleText}', DISPLAY, 22, 1.1, 20, 0, { fontWeight: 900 }),
centred('subtitle', '{attr.subtitle}', TEXT, 9, 1.25, 29.5, 92, { italic: true,
color: col('ink') }),
centred('byline', '{attr.byline}', LABEL, 7, 1.2, 38.8, 0, { fontWeight: 500,
letterSpacing: pt(1.2), color: col('muted') }),
rule('thick', 43.6, 1.2),
rule('thin', 45, 0.4),
] } };
// '# The Sailor’s Word-Book {style="title" subtitle="…" byline="…"}' opens page 1.
const titleStyle = { id: 'title', span: 'page', advancedDesign: titleBand };
The title style spans the page with a band that holds the anchor, the name, a subtitle and a byline read from heading attributes, and a double rule (span and advanced design). The thin rule ends 45.1 mm below the top of the text block, so the band snaps to 13 grid lines, or 47.7 mm. The column rule starts under the band, on the line where the text of the two columns starts.
The whole recipe
// ═══ Postext Cookbook · Nº 046 · Dictionary with a moving thumb index ═══════════════
// https://postext.dev/en/cookbook/dictionary-thumb-index
// Code: MIT · Text: W. H. Smyth, 1867 (PD); Spanish translation CC BY 4.0 · Pictures: code
// Fonts: Alegreya, Alegreya SC, Alegreya Sans SC (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'dictionary-thumb-index';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink and navy on a warm paper, brass for the rules and the rope
const palette = {
ink: '#1b1f24', // text
navy: '#1f3a5f', // headwords, letters and tabs
brass: '#a4834f', // hairlines and the rope of the vignette
rule: '#cfccc3', // the column rule
tint: '#e4e9f0', // the pale cells of the index
slate: '#56657b', // their letters
muted: '#62666b', // running heads
paper: '#fbfaf6', // the page, and the letter reversed out of each tab
};
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' } }));
// #endregion
const TEXT = 'Alegreya', DISPLAY = 'Alegreya SC', LABEL = 'Alegreya Sans SC';
const PT = 25.4 / 72; // mm in a point
const LEAD = 10.4; // pt: the body's leading, the grid every column is set on
const LINES = 44; // lines in a full column
const TOP = 18, INNER = 12, OUTER = 14; // mm; the foot margin makes the block whole lines
const BOTTOM = 200 - TOP - LINES * LEAD * PT;
// #region answer: one heading style per letter, each with its tab one step down the fore-edge
// 22 tabs share the 44 lines of the text block, two lines each; letters with few words
// share a tab, as in most thumb-indexed dictionaries.
const TABS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'QR', 'S', 'T', 'UV', 'W', 'XYZ'];
const STEP = 2 * LEAD * PT; // mm: 7.34
const EDGE = { odd: 'top-right', even: 'top-left' }; // the fore-edge: right on a recto
// A cell of the index, `width` mm inside the trim and 3 mm past it, so that only its
// inner corners show their rounding; its label is centred on the part inside the trim.
const cell = (id, label, i, parity, width, fill, ink, size) => {
const y = mm(TOP + i * STEP + 0.3); // a 0.6 mm gap between neighbours
const at = (x, w) => ({ anchor: { to: 'page', edge: EDGE[parity] }, offset: { x: mm(x), y },
size: { width: mm(w), height: mm(STEP - 0.6) } });
return [
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
#Print only the current tab
Printed thumb indexes usually show only the current letter’s tab; take ladder out of the header and the navy tab still steps down from A to C.
- header: { elements: [...runningHeads, ...ladder] }, // the same on every page
+ header: { elements: [...runningHeads] }, // the same on every pagePitfalls
Pitfall
A page takes the header of the last section that starts on it
When two heading styles start on one page, the page takes the header, footer and palette of the last one. A separator blank belongs to the chapter before it, parity padding to the chapter after it. Running heads per section →
Pitfall
A heading style inherits its level's page break
A headingStyles entry takes every field it leaves out from its heading level, breakBefore included. A contents page or a colophon styled on an H1 after a :::pagebreak inherits parity 'odd' and lands behind a blank page. Give such a style breakBefore: { enabled: false }. Heading styles →
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
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 →
- A 60 mm column holds about 50 characters, and Smyth’s English cannot be reworded. Set by its word spaces alone, 18 of the 218 justified English lines (8 %) stretched them past 1.7 times the normal width, against under 2 % in the Spanish, whose translation was fitted to the column, and the first line of Cross-trees could not be filled at all.
maxJustifyTracking: 10lets a line take up to 1 % of tracking before its spaces pass that limit: in the capture 25 of the 217 English lines and 9 of the 223 Spanish ones carry some, and none passes 1.7. The English stood at 17 % before the five entries that set worst (Aground, Aloft, Belay, Cockpit, Crow’s nest) were swapped for others. Choose entries that set well, or widen the column.
Credits
- Recipe
- Ignacio Ferro
- Text
- The Sailor’s Word-Book (London: Blackie and Son, 1867), entries from A, B and C · W. H. Smyth; Sir Edward Belcher · public domain
- Spanish translation, editor’s note and colophon · Postext Cookbook · original
- Fonts
- Alegreya (SIL OFL 1.1) · Alegreya SC (SIL OFL 1.1) · Alegreya Sans SC (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


