简单来说
一本小诗集,左边是西班牙语原文,右边是英文译文。译文的每一节都和原文那一节从同一行开始。
成品一览
一本收录五首诗的双语小诗集,写的是西班牙南部的一片盐田,开本156 × 234 mm,左边是西班牙语原文,右边是诗人自己的英文译本,逐行对应。书前是一张带火烈鸟的扉页和作者说明;诗作从一幅水彩画下开始,画的是日出时粉色的盐池、盐堆和火烈鸟。每首诗放在一个无边框的框里,上方是Castoro Titling字体的茜红色编号,西班牙语在一栏,英文在另一栏。英文与西班牙语从同一行开始,每一节都与原文齐平。英文诗行太长、一栏放不下时,余下部分转行并缩进2 em,对面的西班牙语诗节则在结尾多留一个空行。
这道食谱解答
- 怎样在框里分两栏(文字栏旁边是图栏)?
- 怎样排诗歌:每句一行,诗节间留空,折行悬挂缩进,不断词?
- 空行不起作用时,怎样在两个块之间加额外的垂直间距?
- 怎样让西班牙文、法文或德文获得良好的两端对齐和断词?
简短回答
// 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
};
用料
- 功能
- 逐行排诗框内或正文中的分栏显式竖向间距段落样式标注框断词与文档语言标题样式设计过的章首页标题属性页面设计中的图片封面、扉页和版权页文档元数据各栏齐底书眉与页码按页面角色显示书眉对称页边距语义调色板作为资源的图和表分节书眉在Canvas上绘制页面
- 类型
- Castoro, Castoro Titling, Tenor Sans(SIL OFL 1.1)
- 素材
flamingo-680.jpgsalina-1560.jpg- The salt pans at sunrise over the poems, a watercolour (Generated With Diffusion Models, 原创)
- The flamingo on the title page, a watercolour (Generated With Diffusion Models, 原创)
做法
#1 · 一首诗就是一个带固定分栏点的框
代码见上文的简短回答。每首诗都是一个标注框,里面放一个:::columns分栏组;它的样式去掉了填色和内边距,并印出围栏的title,也就是编号(:::columns)。不设breaks时,这一组在两栏高度相等的地方切开。这些诗的两半高度相同,所以切点本来就落在英文标题上;但如果把The Rake的两行加长到需要转行,切点就会下移一个块,让THE RAKE落在西班牙语栏的栏尾。breaks="5"指定开启第二栏的那个块,所以无论两半高度如何,英文标题都位于第二栏栏首。
#2 · 每栏一个:::verse块,诗节之间一个空行
// 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) };
每首诗的一半是一个:::verse块:Markdown的一行就是一行诗,齐左且不断词,诗节之间一个空行,在栏里留出一个空行(:::verse)。每个诗节是一个块,所以breaks数的是诗节而不是诗行。英文*each one standing on its own reflection.*对55 mm的栏来说太长,转行并缩进2 em;西班牙语一半在对面那一节之后结束自己的块,并在下一节之前放一个:::space{lines=2},所以下一节从同一行开始。:::space不是块,breaks不计算它(:::space)。

#3 · 说明按它自己的语言断词
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选择断词模式。用'es'时,西班牙语说明断成ori-ginal和Duna-liella;用英文模式时,这两个词都会整个移到下一行,只有arras-traba在两种模式下都会断开(支持的语言)。词间距可以压缩到正常宽度的0.8倍、拉伸到1.35倍,两篇说明中没有一行两端对齐的文字超过这个限度。说明的标题是一个版面设计,其中唯一的元素即标题,位于版心顶端下方36 mm处,所以说明从页面上边缘往下73 mm处开始。
#4 · 扉页和水彩画都是标题
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') }),
] } },
};
它们都是一级标题,各有自己的样式(标题样式):扉页的版面设计从前置元数据取{author},两个版面设计都从标题属性取{attr.other}。水彩画锚定在页面上边缘,在版心之上,标题一直预留到画的底边,即距页面上边缘84 mm处。样式设了marginBottom: pt(0),所以画下面的空白就是诗自己两行的上外边距,诗I从画下方至少两行处的第一条网格线开始。
#5 · 书眉写出两种语言
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' })] };
左页书眉是西班牙语书名,右页是英文书名,顺序与栏的顺序一致。pages: 'body'让三个以标题开篇的页面不印书眉。说明和水彩画页改为在页脚印页码,扉页的样式则清空了页眉和页脚(文本元素)。
完整食谱
// ═══ 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 = 'es'; // @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)
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#加宽栏间距
栏间距为12 mm时,每栏缩窄到53 mm,诗III中的*Los turistas paran y hacen fotos:*会转行,于是第二节比英文晚一行开始;在该节之后结束英文的块,并在下一节之前放一个:::space{lines=2},即可让两边齐平。
-const GAP = 8; // 原文与译文之间的毫米数:每栏宽55 mm
+const GAP = 12; // 原文与译文之间的毫米数:每栏宽53 mm#转行悬挂得更深
设为3 em时,第3页的*reflection.*会再往里缩进一个em。
-const verse = { id: 'verse', hangingIndent: em(2) };
+const verse = { id: 'verse', hangingIndent: em(3) };常见问题
- 放在英文标题之前的
:::space会消失:第二栏从breaks指定的块开始,这个空行正好落在切点上。应当把它放在标题之后,就像这里每个栏标题下的:::space{lines=0.5}。 breaks要从西班牙语标题开始数:一个标题加三个诗节,英文标题就是第5块。每个诗节都是一个块,所以西班牙语多一个诗节,英文标题就变成第6块,breaks也要跟着加一;诗节内多一行则不影响。
致谢
- 文本
- 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
- 图片
- The salt pans at sunrise over the poems, a watercolour · Generated With Diffusion Models · 原创
- The flamingo on the title page, a watercolour · Generated With Diffusion Models · 原创
- 字体
- Castoro (SIL OFL 1.1) · Castoro Titling (SIL OFL 1.1) · Tenor Sans (SIL OFL 1.1)


