Skip to main content
Recipe number 43

Cookbook · Chapter 2 · Type & text

Facing translation, stanza by stanza

Each poem is a frameless box with two columns: a fixed column break opens the English at its title, and :::space keeps each stanza level with its original.

On this page

pp. 2–3 of 5

  • Trim 156 × 234 mm
  • 1 column
  • Castoro 10.5/14.5
  • Castoro Titling
  • Tenor Sans
  • 5 pages
  • Level
  • Postext 1.57.1
  • Laid out in 53 ms
  • 164 lines of code

In short

A small book of poems with the Spanish on one side and the English translation beside it. Each group of lines in the translation starts level with the original.

What you'll build

A bilingual chapbook of five poems about a salt pan in the south of Spain, 156 × 234 mm, with the Spanish on the left and the poet’s own English version on the right, line for line. A title page with a flamingo and the author’s note come first; the poems open under a watercolour of pink ponds, heaps of salt and flamingos at sunrise. Each poem sits in a frameless box under a madder numeral in Castoro Titling, the Spanish in one column and the English in the other. The English starts on the same line as the Spanish, and every stanza starts level with its original. When an English line is too long for its column, the rest of it turns over 2 em in, and the Spanish stanza opposite ends with an extra blank line.

This recipe answers

  • How do I put two columns inside a box (a text column beside a figure column)?
  • How do I set poetry: one line per verse, stanza gaps, hanging indents for wrapped lines, no hyphenation?
  • How do I add extra vertical space between two blocks, when blank lines do nothing?
  • How do I get good justification and hyphenation for Spanish, French or German text?

The short answer

script.js · lines 28–52in full code
// Each poem is a box titled with its numeral, holding one two-column group. breaks="5"
// opens the second column at the group's 5th block, since the Spanish title and its three
// stanzas come before it. A :::space is not a block, so the gaps leave the count alone:
//   :::callout{type="poem" title="I"}
//   :::columns{count=2 breaks="5"}
//   Spanish title, :::space{lines=0.5}, its stanzas in :::verse blocks
//   English title, :::space{lines=0.5}, its stanzas in :::verse blocks
//   :::
//   :::
// Both columns open on the same line, so matching :::space gaps keep the stanzas level.
// keepTogether: false lets a poem that does not fit go on overleaf. A group with breaks is
// cut stream by stream (flow="parallel"): each language goes on in its own column, level.
const poem = {
  id: 'poem',
  backgroundEnabled: false, // no fill, border or stripe
  padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
  columnGap: mm(GAP),
  titleStyle: { fontFamily: 'Castoro Titling', fontSize: pt(22), fontWeight: 400,
    color: col('madder'), gap: pt(4) },
  // A box starts on the first grid line at least two lines down, under the picture as under
  // a poem (12.3 mm there: its box ends off the grid). The default marginBottom (0.75 em)
  // would add to marginTop and open 17.4 mm between poems.
  marginTop: pt(LEAD * 2), marginBottom: pt(0),
  keepTogether: false, // a long poem goes on overleaf instead of moving whole
};

A poem and its translation: a box with two columns and a fixed break

Ingredients

Type
Castoro, Castoro Titling, Tenor Sans (SIL OFL 1.1)
Assets
  • flamingo-680.jpg
  • salina-1560.jpg
  • The salt pans at sunrise over the poems, a watercolour (Generated With Diffusion Models, original)
  • The flamingo on the title page, a watercolour (Generated With Diffusion Models, original)

Method

#1 · A poem is a box with a fixed column break

The code is the short answer above. Each poem is a callout around a :::columns group; its style drops the fill and the padding and prints the fence’s title, the numeral (:::columns). Without breaks, the group cuts where its two columns come out level. Both halves of these poems are the same height, so the cut falls on the English title anyway; lengthen two lines of The Rake until they turn over, and the cut moves one block down and leaves THE RAKE at the foot of the Spanish column. breaks="5" names the block that opens the second column, so the English title heads it whatever the heights of the two halves.

#2 · A :::verse block per column, a blank line per stanza break

script.js · lines 56–64in full code
// Each half of a poem is a :::verse block, a line of verse a line of Markdown and a blank line
// between stanzas. A line too long for its 55 mm column turns over 2 em in, where it cannot
// pass for the next line; the Spanish half then ends that stanza's block and a
// :::space{lines=2} before the next keeps the stanzas level across the gutter.
const verse = { id: 'verse', hangingIndent: em(2) };
// Castoro Titling draws capitals only. A :::space{lines=0.5} in the Markdown sets each title
// off its poem.
const poemTitle = { id: 'poem-title', fontFamily: 'Castoro Titling', fontSize: pt(9.5),
  color: col('madder'), firstLineIndent: pt(0) };

Each half of a poem is a :::verse block: a line of verse a line of the Markdown, ragged and never hyphenated, and a blank line between stanzas, which leaves a blank line in the column (:::verse). Every stanza is a block, so breaks counts stanzas, not lines. The English each one standing on its own reflection. is too long for its 55 mm column and turns over 2 em in; the Spanish half closes its block after the stanza opposite and puts a :::space{lines=2} before the next one, so the next stanzas start on the same line. A :::space is not a block, and breaks does not count it (:::space).

Poem I on page 3: reflection. turns over in the English, and the Spanish stanza ends with two blank lines instead of one.

#3 · The note is hyphenated in its own language

script.js · lines 68–82in full code
const LOCALE = t({ en: 'en-us', es: 'es' }); // the patterns of the edition's language
const bodyText = {
  fontFamily: 'Castoro', fontSize: pt(10.5), lineHeight: pt(LEAD), color: col('ink'),
  italicColor: col('ink'), firstLineIndent: mm(4.5), indentAfterHeading: false,
  minWordSpacing: 0.8, maxWordSpacing: 1.35, // word spaces from 0.8 to 1.35 of normal
  // No bold on these pages: ink keeps a **bold** or a :ref added later off the default blue
  // (#295AA3). References take boldColor while referenceColor is unset.
  boldColor: col('ink'),
};
// The heading prints its title 36 mm down the text block, and the note starts under it.
const notePage = { id: 'note', advancedDesign: { enabled: true, slot: {
  elements: [{ kind: 'text', id: 'title', content: '{titleText}', align: 'left',
    fontFamily: 'Castoro Titling', fontSize: pt(13), color: col('madder'), overflow: 'wrap',
    placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(36) } } }],
} } };

locale picks the hyphenation patterns. With 'es' the Spanish note breaks ori-ginal and Duna-liella; with the English patterns both words go whole to the next line, and only arras-traba breaks under either (supported locales). Word spaces may shrink to 0.8 and stretch to 1.35 of their normal width, and no justified line in either note stretches past that. The note’s heading is a design whose one element, the title, sits 36 mm below the top of the text block, so the note starts 73 mm from the top edge of its page.

#4 · The title page and the watercolour are headings

script.js · lines 86–114in full code
const onPage = (y) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) } });
const face = (id, content, font, size, y, extra = {}) => ({ kind: 'text', id, content,
  fontFamily: font, fontSize: pt(size), color: col('ink'), align: 'center', overflow: 'wrap',
  placement: onPage(y), ...extra });
const tracked = { letterSpacing: pt(2), textTransform: 'uppercase' };
const image = (id, placement) => ({ kind: 'image', id, resourceId: id, placement });
const titlePage = {
  id: 'title-page',
  header: { elements: [] }, footer: { elements: [] }, // no running head, no folio
  advancedDesign: { enabled: true, slot: { elements: [
    face('author', '{author}', 'Tenor Sans', 9, 44, { ...tracked, color: col('muted') }),
    face('title', '{titleText}', 'Castoro Titling', 34, 58, { lineHeight: 1 }),
    face('other', '{attr.other}', 'Castoro', 16, 76, { italic: true, color: col('madder') }),
    image('flamingo', { ...onPage(96), size: { width: mm(34) } }),
    face('edition', '{attr.edition}', 'Tenor Sans', 8.5, 170, tracked),
    face('version', '{attr.version}', 'Castoro', 10.5, 176, { italic: true }),
    face('press', '{attr.press}', 'Tenor Sans', 8, 206, { ...tracked, color: col('muted') }),
  ] } },
};
// The picture of the salt pans runs 84 mm down from the top edge of the page, and the heading
// reserves down to its foot. No margin under it: the poem's own marginTop sets the gap.
const poemsOpener = {
  id: 'poems', marginBottom: pt(0),
  advancedDesign: { enabled: true, slot: { elements: [
    image('salina', { anchor: { to: 'page', edge: 'top-left' }, size: { width: 'fill' } }),
    face('title', '{titleText}', 'Castoro Titling', 38, 17, { lineHeight: 1 }),
    face('other', '{attr.other}', 'Castoro', 15, 33, { italic: true, color: col('madder') }),
  ] } },
};

Each is a level-1 heading with a style of its own (heading styles): the title page’s design takes {author} from the frontmatter, and both designs take {attr.other} from the heading’s attributes. The watercolour is anchored to the top edge of the page, above the text block, and the heading reserves down to its foot, 84 mm down the page. The style sets marginBottom: pt(0), so the gap under the picture is the poem’s own two-line top margin, and poem I starts on the first grid line at least two lines below the picture.

#5 · The running heads name both languages

script.js · lines 118–132in full code
const edgeAt = (edge, x, y) => ({ anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(y) } });
const head = (id, content, parity, placement, extra = {}) => ({ kind: 'text', id, content,
  parity, pages: 'body', fontFamily: 'Tenor Sans', fontSize: pt(7.5), color: col('muted'),
  ...tracked, letterSpacing: pt(1.5), placement, ...extra });
const folio = { color: col('ink'), letterSpacing: pt(0) };
const TITLES = ['Sal de agosto', 'August Salt']; // the book's title in its two languages
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', edgeAt('top-left', OUTER, 12), folio),
  head('verso-title', TITLES[0], 'even', edgeAt('top-left', OUTER + 8, 12)),
  head('recto-title', TITLES[1], 'odd', edgeAt('top-right', -(OUTER + 8), 12)),
  head('recto-folio', '{pageNumber}', 'odd', edgeAt('top-right', -OUTER, 12), folio),
] };
// The note and the picture open their pages ('opener'): a folio at the foot instead.
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', edgeAt('bottom', 0, -12),
  { ...folio, pages: 'opener' })] };

The verso carries the Spanish title and the recto the English one, in the order of the columns. pages: 'body' keeps them off the three pages that open with a heading. The note and the watercolour get a folio at the foot instead, and the title page’s style empties its header and its footer (text elements).

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 043 · Facing translation, stanza by stanza ═══════════════════
// https://postext.dev/en/cookbook/bilingual-facing-verse
// Code: MIT · Text: original (CC BY 4.0) · Salt pans and flamingo: diffusion models
// Fonts: Castoro, Castoro Titling, Tenor Sans (SIL OFL 1.1) · Needs postext ≥ 1.34.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'bilingual-facing-verse';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config links to one of these
  ink: '#1f2430', // the text: a blue-black
  madder: '#9a3c52', // the one accent: numerals, poem titles, the other language's title
  muted: '#6a6770', // running heads, folios, the author's name, the colophon
  paper: '#ffffff',
};
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 TRIM_W = 156, TRIM_H = 234; // mm
const TOP = 22, OUTER = 18, INNER = 20; // mm: the text block is 118 mm wide
const LEAD = 14.5; // pt: the leading of the note and of every line of verse
const GAP = 8; // mm between the original and the translation: each column is 55 mm wide

// #region answer: a poem and its translation: a box with two columns and a fixed break
// Each poem is a box titled with its numeral, holding one two-column group. breaks="5"
// opens the second column at the group's 5th block, since the Spanish title and its three
// stanzas come before it. A :::space is not a block, so the gaps leave the count alone:
//   :::callout{type="poem" title="I"}
//   :::columns{count=2 breaks="5"}
//   Spanish title, :::space{lines=0.5}, its stanzas in :::verse blocks
//   English title, :::space{lines=0.5}, its stanzas in :::verse blocks
//   :::
//   :::
// Both columns open on the same line, so matching :::space gaps keep the stanzas level.
// keepTogether: false lets a poem that does not fit go on overleaf. A group with breaks is
// cut stream by stream (flow="parallel"): each language goes on in its own column, level.
const poem = {
  id: 'poem',
  backgroundEnabled: false, // no fill, border or stripe
  padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
  columnGap: mm(GAP),
  titleStyle: { fontFamily: 'Castoro Titling', fontSize: pt(22), fontWeight: 400,
    color: col('madder'), gap: pt(4) },
  // A box starts on the first grid line at least two lines down, under the picture as under
  // a poem (12.3 mm there: its box ends off the grid). The default marginBottom (0.75 em)

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

#Widen the gutter

At 12 mm the columns narrow to 53 mm, and Los turistas paran y hacen fotos: turns over in poem III, so its second stanza starts a line below the English; close the English block after that stanza and put a :::space{lines=2} before the next one to level them.

-const GAP = 8; // mm between the original and the translation: each column is 55 mm wide
+const GAP = 12; // mm between the original and the translation: each column is 53 mm wide

#Hang turnovers deeper

At 3 em, reflection. on page 3 starts one em further in.

-const verse = { id: 'verse', hangingIndent: em(2) };
+const verse = { id: 'verse', hangingIndent: em(3) };

Pitfalls

  • A :::space put before the English title vanishes: the second column opens at the block breaks names, and the space falls at the cut. Put it after the title, like the :::space{lines=0.5} under each column title here.
  • Count breaks from the Spanish title: with a title and three stanzas, the English title is block 5. Every stanza is a block, so one more Spanish stanza moves the English title to block 6, and breaks has to go up with it; a line more inside a stanza moves nothing.

Credits

Text
  • The poem cycle Sal de agosto and its English version, August Salt, with the author’s note, written for this recipe; the poet Adela Membrives is fictional · Postext Cookbook · CC BY 4.0
Images
  • The salt pans at sunrise over the poems, a watercolour · Generated With Diffusion Models · original
  • The flamingo on the title page, a watercolour · Generated With Diffusion Models · original
Fonts
Castoro (SIL OFL 1.1) · Castoro Titling (SIL OFL 1.1) · Tenor Sans (SIL OFL 1.1)
Sandbox