Skip to main content
Recipe number 44

Cookbook · Chapter 2 · Type & text

Critical edition: line numbers and line-keyed notes

Milton’s Lycidas in the 1645 text: lineNumbers prints every fifth line number in the side column, and each note opens on its line number, set as a chip.

On this page
  • Trim 138 × 216 mm
  • Column and a half, 4 mm gutter
  • Linden Hill 10.5/14.5
  • Imbue
  • Libre Franklin
  • 9 pages
  • Level
  • Postext 1.57.1
  • Laid out in 71 ms
  • 168 lines of code

In short

A scholarly edition of a poem by Milton. Every fifth line is numbered in the margin, and the notes after the poem point to the lines they explain by their number.

What you'll build

Lycidas, Milton’s elegy for Edward King, set as a small critical edition of 138 × 216 mm in the text and spelling of the 1645 Poems. The first page opens under a sprig of bay laurel, with the title in tall Imbue capitals over the headnote Milton added in 1645. The 193 lines follow one to a line of type, with a blank line between verse paragraphs and the short lines set in. Every fifth line has its number in laurel green, in a 6 mm column at the fore-edge: right of the verse on a recto, left of it on a verso. The verse carries no note markers. The notes fill the two pages after the poem, and each opens on the number of its line, in the same green Libre Franklin as the numbers in the margin.

This recipe answers

  • How do I number every fifth line of a poem in the margin and key my notes to those line numbers?
  • How do I set poetry: one line per verse, stanza gaps, hanging indents for wrapped lines, no hyphenation?
  • How do I do footnotes?
  • How do I make a column-and-a-half layout, with a wide text column and a narrow side column?
  • How do I add extra vertical space between two blocks, when blank lines do nothing?

The short answer

script.js · lines 30–43in full code
// The poem is one :::verse block, written as 1645 prints it: a line of verse a line, a blank
// line between verse paragraphs and two spaces before a short line. lineNumbers counts its
// lines of verse (a line that turned over would still count once) and prints the multiples
// of five beside their lines, on their baselines. position 'side' puts them in the side
// column of the one-and-a-half layout, flush with its edge next to the verse.
const lineNumbers = {
  enabled: true,
  count: 'verse', // the lines of :::verse poems; the notes are prose and not counted
  interval: 5,
  restart: 'document', // one count through the poem
  position: 'side',
  fontFamily: LABEL, fontSize: pt(7.5), color: col('laurel'),
};
// Hook-up: lineNumbers in the config; the Markdown goes to buildDocument as it is written.

Count the lines, and set every fifth number in the margin

Ingredients

Type
Linden Hill, Imbue, Libre Franklin (SIL OFL 1.1)
Assets
  • laurel-1040.jpg
  • The sprig of bay laurel on the first page, a watercolour (Generated With Diffusion Models, original)

Method

#1 · Count the lines of verse

The code for this step is the short answer above. lineNumbers counts the lines of the poem and prints the number of every fifth beside its line, on its baseline, in 7.5 pt Libre Franklin and laurel green (line numbers). count: 'verse' counts the lines of :::verse poems only, so the note on the text and the notes after the poem take no numbers, and a line too long for the measure would still count once: its turnover takes no number. restart: 'document' keeps one count through the poem. The numbers are painted beside lines the layout has already set, so they never move a line.

#2 · A channel six millimetres wide

script.js · lines 47–63in full code
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [138, 216]; // mm
const [TOP, INNER] = [21, 20]; // mm
const LINES = 34; // lines of verse to a page
const BOTTOM = TRIM_H - TOP - LINES * LEAD * PT; // 21.08 mm
const [MEASURE, GUTTER, CHANNEL] = [80, 4, 6]; // mm: the longest line of Lycidas is 78.1 mm
const OUTER = TRIM_W - INNER - MEASURE - GUTTER - CHANNEL; // 28 mm beyond the numbers
const layout = {
  layoutType: 'oneAndHalf',
  sideColumnRole: 'floats', // the side column takes the numbers, never text
  sideColumnSide: 'outer', // right of the verse on a recto, left of it on a verso
  // 6 of 90 mm. The zero is Libre Franklin's widest figure, so '100' (4.9 mm) is the widest number.
  sideColumnPercent: (CHANNEL / (MEASURE + GUTTER + CHANNEL)) * 100,
  gutterWidth: mm(GUTTER),
};
const page = { sizePreset: 'custom', width: mm(TRIM_W), height: mm(TRIM_H), dpi: 150,
  margins: { top: mm(TOP), bottom: mm(BOTTOM), left: mm(INNER), right: mm(OUTER), mirror: true } };

With sideColumnRole: 'floats', the narrow column of a oneAndHalf layout never takes text (layout types), and position: 'side' sets the numbers in it, flush with its edge next to the verse; the 4 mm gutter is the space between a line and its number. sideColumnPercent is a share of the text block, so the pen derives it from millimetres: 6 of 90 mm, enough for the widest number. Libre Franklin’s figures are proportional, and at 7.5 pt the zero is the widest of them (1.8 mm, against 1.2 mm for the one), so 100, at 4.9 mm, is the widest number in the poem; 180 and 190 set 4.8 mm. 'outer' follows the mirrored margins, so the numbers stand right of the verse on a recto, set flush left, and left of it on a verso, set flush right: on both they start or end the same distance from the verse. The verse column is 80 mm, 1.9 mm more than line 31, the longest, so no line turns over.

#3 · The poem is one :::verse block

script.js · lines 67–72in full code
// A blank line between verse paragraphs leaves one line of the grid (stanzaSpace, 1). Two
// leading spaces set a short line in 2 em (indentStep, 1 em a space here, against the default
// half em). The verse is ragged, like all the text here; a line too long for the measure would
// turn over and hang 2 em past its own start, but none does at 80 mm.
const verse = { indentStep: em(1) };
const verseStyles = [{ id: 'verse', hangingIndent: em(2) }];

A :::verse block keeps the poem as it is written: each line of Markdown a line of verse, a blank line between verse paragraphs, and the spaces before a line its indent (:::verse). The fence names the verse style and align=start, which sets the poem flush with the margin instead of centring it on its longest line. Each verse paragraph is a stanza, and a blank line of the grid stands between two (stanzaSpace, one line). Milton’s fourteen short lines, line 4 among them, start with two spaces, and indentStep: em(1) makes those 2 em. A stanza space is dropped at the head of a page, so page 2 starts on line 15 at the top of the text block, and the paragraph break between lines 14 and 15 does not show (see Pitfalls).

#4 · The laurel, the title and the headnote

script.js · lines 76–101in full code
const OPENER_LINES = 20; // of the page's 34: the first verse paragraph, 14 lines, takes the rest
const at = (id, edge, y) => ({ anchor: { to: id, edge }, offset: { x: mm(0), y: mm(y) } });
const title = (size, tracking, placement) => ({ kind: 'text', id: 'title', content: '{titleText}',
  fontFamily: DISPLAY, fontWeight: 300, fontSize: pt(size), lineHeight: 1,
  letterSpacing: pt(tracking), textTransform: 'uppercase', color: col('ink'), placement });
const opener = { enabled: true, minHeight: pt(OPENER_LINES * LEAD), slot: { elements: [
  // The laurel ends above the kicker, so the depth comes from the texts: kicker, title and
  // headnote reach down 20 lines. minHeight is a floor at the same depth, so a shorter
  // headnote leaves the verse on line 21.
  { kind: 'image', id: 'laurel', resourceId: 'laurel',
    placement: { anchor: { to: 'page', edge: 'top-right' }, size: { width: mm(104) } } },
  { kind: 'text', id: 'kicker', content: '{author}', fontFamily: LABEL, fontWeight: 500,
    fontSize: pt(8), letterSpacing: pt(1.6), textTransform: 'uppercase', color: col('laurel'),
    placement: at('container', 'top-left', 50) },
  title(66, 2, at('#kicker', 'below', 1)),
  // # Lycidas {headnote="In this Monody …"}: the whole headnote in italic, ragged; at
  // 64 mm no word stands alone.
  { kind: 'text', id: 'headnote', content: '{attr.headnote}', fontFamily: TEXT, italic: true,
    fontSize: pt(9.5), lineHeight: 13 / 9.5, color: col('ink'), align: 'left',
    placement: { ...at('#title', 'below', 3), size: { width: mm(64) } } },
] } };
// The poem opens on a recto. Its design stays in the column, and the laurel, anchored to the
// page's corner, is painted above the text block all the same. With the default
// marginBottom the verse would start on line 22 and send line 14 to page 2.
const poem = { level: 1, breakBefore: { enabled: true, parity: 'odd' },
  advancedDesign: opener, marginBottom: pt(0) };

The first-level heading prints a design instead of its own text (span and advanced design). {author} comes from the frontmatter, and the headnote from an attribute on the heading line, # Lycidas {headnote="In this Monody …"} (heading attributes). The laurel ends above the kicker, so the depth of the opener comes from the texts under it: the kicker, 50 mm below the top of the text block, the title and the four lines of the headnote reach down 20 of the page’s 34 lines, and the first verse paragraph, 14 lines, takes the rest. minHeight is a floor at the same depth: cut the headnote to three lines and the verse still starts on line 21, where without the floor it rises to line 20. marginBottom: pt(0) keeps the heading’s default margin out of the gap; with it, the verse would start on line 22 and send line 14 to page 2. The design stays in the column, and the laurel, anchored to the page’s top-right corner, is still painted from the trim: only the foot of a column cuts a design kept in it.

#5 · Notes keyed to line numbers

script.js · lines 105–124in full code
const NOTE = 8.6; // pt: the notes, and the note on the text
const noteStyles = [
  { id: 'textnote', fontSize: pt(NOTE), lineHeight: pt(NOTE * 1.33) },
  // The note on the text ends on the grid, 2.4 mm below its last line; half a line more
  // leaves one blank line before the first note.
  { id: 'note', fontSize: pt(NOTE), lineHeight: pt(NOTE * 1.33), hangingIndent: em(1.6),
    marginTop: pt(LEAD / 2) },
  { id: 'colophon', fontFamily: LABEL, fontSize: pt(7), lineHeight: pt(9.5), color: col('muted'),
    marginTop: pt(LEAD) },
];
// :chip[8]{style="line"}: Linden Hill has no bold, so the number changes face and colour.
// The chip has no fill, outline or side padding, so nothing is drawn around the number.
const chipStyles = [{ id: 'line', backgroundEnabled: false, borderWidth: pt(0), paddingX: pt(0),
  fontFamily: LABEL, fontSize: em(0.9), color: col('laurel') }];
// # Notes {style="notes"} opens the next page under the title's capitals, smaller. A heading
// style keeps the level's break unless it sets its own (gotcha: style-inherits-break). Its
// design stays in the column too, so the title lines up with the notes on either page.
const notesHead = { id: 'notes', breakBefore: { enabled: true, parity: 'any' },
  advancedDesign: { enabled: true,
    slot: { elements: [title(30, 1, at('container', 'top-left', 0))] } } };

The notes are keyed to line numbers, so the verse carries no note markers, and they follow the poem as a commentary, taking no lines from its pages. Each note opens on its line number, written :chip[8]{style="line"}, then the words it explains in italic and a closing bracket. The chip has no fill, outline or side padding, so only the face and the colour change: 7.7 pt Libre Franklin in laurel green (chip styles). Linden Hill has no bold, so the numbers are marked by a change of face instead. The note style indents every line after the first by 1.6 em, which leaves the numbers clear at the left, and the notes are set ragged, like the verse. # Notes {style="notes"} breaks to page 8 and sets its title in the capitals of the opener, at 30 pt.

Page 8: each note opens on the green number of its line; the verse on pages 1 to 7 carries no markers.

#6 · Running heads by parity

script.js · lines 128–149in full code
const HEAD = 13; // mm from the trim to the running heads' baseline
// A design text's first baseline sits 0.8 of a line below the top of its box: 0.96 em at the
// default lineHeight of 1.2, which the running heads keep.
const BASE = 1.2 * 0.8;
const head = (id, parity, content, x, size = 7.5, extra = {}) => ({ kind: 'text', id, parity,
  content, pages: 'body', fontFamily: LABEL, fontWeight: 500, fontSize: pt(size),
  letterSpacing: pt(1.3), textTransform: 'uppercase', color: col('muted'), ...extra,
  placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
    offset: { x: mm(x), y: mm(HEAD - BASE * size * PT) } } });
const folio = { fontFamily: TEXT, fontWeight: 400, letterSpacing: pt(0), color: col('ink') };
const header = { elements: [
  head('verso-folio', 'even', '{pageNumber}', OUTER, 10, folio),
  head('verso-head', 'even', '{author}', OUTER + 9),
  head('recto-head', 'odd', '{chapterTitle}', -(OUTER + 9)), // LYCIDAS, then NOTES
  head('recto-folio', 'odd', '{pageNumber}', -OUTER, 10, folio),
] };
// The two openers carry their folio at the foot instead, at the outer edge of the text block.
const drop = (parity, edge, x) => ({ ...head(`drop-${parity}`, parity, '{pageNumber}', 0, 10,
  folio), pages: 'opener', placement: { anchor: { to: 'page', edge },
  offset: { x: mm(x), y: mm(-12) } } });
const footer = { elements: [drop('odd', 'bottom-right', -OUTER),
  drop('even', 'bottom-left', OUTER)] };

Each element is anchored to the page and filtered by parity and pages: 'body' (text elements). The verso carries the author and the recto {chapterTitle}, which reads LYCIDAS over the poem and NOTES over the notes, because the notes open with a heading of their own. The folio stands at the outer edge of the text block; the two opening pages, 1 and 8, carry it at the foot instead.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 044 · Critical edition: line numbers and line-keyed notes ═══
// https://postext.dev/en/cookbook/critical-edition-line-numbers
// Code: MIT · Text: Milton, Poems (1645) (PD) · Notes: CC BY 4.0 · Laurel: diffusion models
// Fonts: Linden Hill, Imbue, Libre Franklin (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Lycidas in the spelling of 1645, with a number beside every fifth line and two pages of
// notes keyed to those numbers, so the verse carries no note markers.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'critical-edition-line-numbers';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text on white, and one laurel green for the apparatus.
const palette = {
  ink: '#1b1b1b', // the text
  laurel: '#3c5a3e', // line numbers, note numbers, the kicker
  muted: '#6a706a', // running heads, the colophon
  paper: '#ffffff',
};
// col(id) carries the hex beside the id of its palette entry.
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' } }));
const [TEXT, DISPLAY, LABEL] = ['Linden Hill', 'Imbue', 'Libre Franklin'];
const LEAD = 14.5; // pt: the leading of the verse, and the grid every page keeps

// #region answer: count the lines, and set every fifth number in the margin
// The poem is one :::verse block, written as 1645 prints it: a line of verse a line, a blank
// line between verse paragraphs and two spaces before a short line. lineNumbers counts its
// lines of verse (a line that turned over would still count once) and prints the multiples
// of five beside their lines, on their baselines. position 'side' puts them in the side
// column of the one-and-a-half layout, flush with its edge next to the verse.
const lineNumbers = {
  enabled: true,
  count: 'verse', // the lines of :::verse poems; the notes are prose and not counted
  interval: 5,
  restart: 'document', // one count through the poem
  position: 'side',
  fontFamily: LABEL, fontSize: pt(7.5), color: col('laurel'),
};
// Hook-up: lineNumbers in the config; the Markdown goes to buildDocument as it is written.
// #endregion

// #region page: a poetry trim, and a channel for the numbers at the fore-edge
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [138, 216]; // mm

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

#Number every tenth line

Long poems are often numbered by tens; the 6 mm column needs no change.

-  interval: 5,
+  interval: 10,

#Keep every number right of the verse

With the side column fixed on the right, the numbers stand right of the verse on every page, which puts them by the spine on a verso.

-  sideColumnSide: 'outer', // right of the verse on a recto, left of it on a verso
+  sideColumnSide: 'right', // right of the verse on every page

Pitfalls

Pitfall

Attribute values: no { or }; single-quote a value with "

An attribute value ends at the closing brace, so it cannot hold { or }. A value that contains a double quote goes in single quotes; a dollar sign is fine. Heading attributes →

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 →

  • The stanza space is dropped at the head of a page, so the paragraph break between lines 14 and 15, which falls at the turn from page 1 to page 2, does not show. If your edition must show every break, give the first line of each verse paragraph an indent instead, as 1645 does: two leading spaces on that line.
  • The numbers share the side column with any side box or side caption you add. A number that lands on one is still printed, and the Sandbox reports it (lineNumberOverlap); move the box, or set the numbers in the outer margin with position: 'outer'.
  • The notes still type their line numbers (:chip[8]{style="line"}): a note cannot yet point at a line and print its number. If you change the text, check the numbers in the notes against the margin.

Credits

Text
  • Lycidas, with its headnote, in the text of Poems of Mr. John Milton (1645), pages 57–65, from the proofread Wikisource transcription of the 1927 facsimile; checked against H. C. Beeching’s Oxford text (Project Gutenberg eBook 1745) · John Milton · public domain
  • The note on the text, the notes and the colophon · Ignacio Ferro · CC BY 4.0
Images
  • The sprig of bay laurel on the first page, a watercolour · Generated With Diffusion Models · original
Fonts
Linden Hill (SIL OFL 1.1) · Imbue (SIL OFL 1.1) · Libre Franklin (SIL OFL 1.1)
Sandbox