简单来说
一本唐诗小册子,对页是1901年的英文译诗。每行两句中文诗,都和译它的两行英文平齐。
成品一览
一本小型的唐诗双语书,按对照本排经典的方式来排:中文在右页,页面带有旧纸般的底纹;Herbert A. Giles于1901年所作的押韵英译在对面的左页。李白、杜甫、王维的四首诗各占一个跨页,每首用两种语言分别加标题,并署上诗人名字。中文用LXGW WenKai排,这是一款仿毛笔书写的楷体。两句诗排成一行,所以每一行都与翻译它的两行英文平齐。用读者语言写的注释放在中文页的页脚。逐节对照的译诗把一首西班牙语诗和它的英译排在同一页上;这里每种语言各占一页。
这道食谱解答
- 怎样把诗和译文排在对页上,原文总在右页?
- 怎样排诗歌:每句一行,诗节间留空,折行悬挂缩进,不断词?
- 脚注怎么做?
- 怎样强制分页或分栏,并让每章都从右页开始?
简短回答
const SINK = 6; // lines of LEAD under both titles, so the two poems start on the same line
const at = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });
// A title whose foot is 23 mm down at any size, and the poet's line under it at 24 mm.
const titled = (size, title, poet, under = []) => ({
enabled: true, minHeight: pt(SINK * LEAD),
slot: { elements: [...under,
{ kind: 'text', id: 'title', content: '{titleText}', fontSize: pt(size), lineHeight: 1.2,
align: 'center', overflow: 'wrap', color: col('ink'),
placement: at(23 - (size * 1.2 * 25.4) / 72), ...title },
{ kind: 'text', id: 'poet', align: 'center', overflow: 'wrap', color: col('seal'),
placement: at(24), ...poet },
] },
});
// Each style breaks to its own side of the spread (gotcha: style-inherits-break).
const english = { id: 'en', breakBefore: { enabled: true, parity: 'even' }, // a verso
advancedDesign: titled(19, { fontFamily: ROMAN, italic: true },
{ content: '{attr.kicker}', fontFamily: LABEL, fontSize: pt(7.5), fontWeight: 600,
letterSpacing: pt(1.5), textTransform: 'uppercase' }) };
// The original on a tinted leaf: span 'page' lets the tint reach past the text column.
const chinese = { id: 'zh', span: 'page', breakBefore: { enabled: true, parity: 'odd' },
advancedDesign: titled(28, { fontFamily: SERIF, fontWeight: 700, letterSpacing: pt(7) },
{ content: '{attr.poet}', fontFamily: HEI, fontSize: pt(9), letterSpacing: pt(1.5) },
[{ kind: 'box', id: 'leaf', reserve: false, style: { backgroundColor: col('leaf') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: 'fill' } } }]) };
用料
做法
#1 · 跨页两侧各用一种标题样式
代码见上文的简短回答。每首诗由两个一级标题组成:先是# Night Thoughts {style="en" …}及Giles的译诗,再是# 靜夜思 {style="zh" …}及原诗。en样式分页到下一个偶数页,即左页;zh样式分页到下一个奇数页,即与之相对的右页。只要每首诗都排得进一页,就不会插入空白页;如果某首英译超出一页,它的原文会被推到再下一个右页,前面隔一个空白左页(前置分页)。两种版面设计都预留了网格的六行,所以英文和中文从同一行开始。中文样式设了span: 'page',因为它的第一个元素是一个与页面等大的框,也就是带底纹的页面;而留在栏内的版面设计到栏底就截止了(通栏与高级版面设计)。

#2 · 一行中文对两行英文
// Each English poem is a :::verse block: a line of verse a line of Markdown, Giles's indents
// as two leading spaces (two ems: bodyText.verse.indentStep), a blank line between stanzas.
// The block is centred on its longest line in the 103.7 mm measure, so a short poem and a
// long one both sit in the middle.
const verse = { id: 'verse', fontFamily: ROMAN, fontSize: pt(BODY), lineHeight: pt(LEAD) };
const shi = { id: 'shi', fontFamily: KAI, fontSize: pt(SHI), lineHeight: pt(2 * LEAD),
textAlign: 'left', firstLineIndent: pt(0), // two lines of verse to a row: 2 × LEAD
// Five characters and a full-width mark, twice: 12 ems, centred in the 28 of the grid.
// A fixed left edge, and the note numbers after each row's 。: every character keeps its column.
indent: pt((CHARS * BODY - 12 * SHI) / 2) };
中文行的行距是英文行的两倍,32 pt对16 pt,所以一行两句五言正对Giles译成的一联。在第4、5页那首写月光的诗里,英文诗节之间的空行和中文诗节之间的:::space{lines=1}各留出一行,三节诗在跨页两边保持平齐。中文行从51 pt处开始,这样它的12 em在网格的28 em中居中。每个注码放在本行的“。”之后,在这12 em之外:如果放在行内,它会把后面的每个字向右推0.6 em,与下一行错开。每首英文诗是一个:::verse块,以最长的一行为准居中,所以不必测量缩进。Giles隔行缩进;Markdown保留了他的两个空格,bodyText.verse.indentStep让它们缩进两个em。
#3 · 注释放在中文页的页脚
const footnotes = { placement: 'column', numbering: 'page', // the page foot; ① again on each page
numberFormat: 'circled-decimal', markerSize: em(0.6), fontSize: pt(8), lineHeight: pt(11),
color: col('ink'), textAlign: 'left', spaceAbove: pt(LEAD), spaceBelowRule: pt(5),
spaceBetween: pt(3), separator: { width: 0.12, lineWidth: pt(0.6), color: col('seal') },
wordBreak: 'keep-all' }; // a reading a note quotes (山月, 看月光) is never broken
注释是脚注,每行一条:疑是地上霜。[^bed]结束诗的第一行,[^bed]: …紧随其后。由于注码不再紧挨被注的词,每条注释都用粗体写出所注的词。编号按中文书页下注的方式:带圈数字排在基线上,每页从①重新起算(numberFormat: 'circled-decimal'、numbering: 'page')。诗行中的注码按诗句字号的十分之六排,即markerSize: em(0.6),与注文字号相近;页脚每条注文以与注文同大的①开头(脚注)。注释用正文字体排,而本书的正文字体是Noto Serif TC,因为注释里汉字和拼音混排;Noto Serif TC的拉丁字母取自Source Serif,所以英文页用Source Serif 4排。注释用本版本的语言书写:它与左页的书眉、关于文本的说明一起,是西班牙语版本要改的部分。
#4 · 每页的书眉用该页的语言
const head = (id, content, parity, edge, x, style) => ({ kind: 'text', id, content, parity,
pages: 'opener', // every poem page opens with its title; a blank page stays bare
fontFamily: LABEL, fontSize: pt(7.5), fontWeight: 600, color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(12) } }, ...style });
const header = { elements: [
head('verso-folio', '{pageNumber}', 'even', 'top-left', EDGE, { color: col('ink') }),
head('verso-book', '{subtitle}', 'even', 'top-left', EDGE + 8,
{ letterSpacing: pt(1.2), textTransform: 'uppercase' }),
head('recto-poet', '{attr.name}', 'odd', 'top-right', -(EDGE + 8),
{ fontFamily: HEI, fontWeight: 400, fontSize: pt(8), letterSpacing: pt(3) }),
head('recto-folio', '{pageNumber}', 'odd', 'top-right', -EDGE, { color: col('ink') }),
] };
本书每一页都以标题开头,所以每页都是章首页,书眉因此用pages: 'opener'。分页插入的空白页不带书眉,扉页则用自己的空页眉清掉书眉。左页取前置元数据中的subtitle作书名,每个版本用自己的语言写它;右页取中文标题的name属性作诗人名(页眉与页脚)。
#5 · 月亮上的扉页
const onPage = (y, size) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) },
...(size ? { size: { width: mm(size), height: mm(size) } } : {}) });
const [MOON_Y, MOON, HAN] = [36, 78, 60]; // mm: the moon's top and width; pt: the title
const UNDER = MOON_Y + MOON; // mm: the English lines start under the moon
const line = (id, content, y, style) => ({ kind: 'text', id, content, align: 'center',
overflow: 'wrap', color: col('ink'), placement: onPage(y), ...style });
const titlePage = { id: 'title', span: 'page', runningChapter: false,
header: { elements: [] }, footer: { elements: [] },
advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'box', id: 'moon', placement: onPage(MOON_Y, MOON),
style: { backgroundColor: col('moon'), borderRadius: mm(MOON / 2) } },
line('han', '{titleText}', MOON_Y + MOON / 2 - (HAN * 25.4) / 144, { fontFamily: SERIF,
fontWeight: 900, fontSize: pt(HAN), letterSpacing: pt(HAN / 4), lineHeight: 1 }),
line('en', '{attr.en}', UNDER + 10, { fontFamily: LABEL, fontSize: pt(10), fontWeight: 600,
letterSpacing: pt(3), textTransform: 'uppercase', color: col('seal') }),
line('poets', '{attr.poets}', UNDER + 19, { fontFamily: ROMAN, fontSize: pt(12) }),
line('giles', '{attr.english}', UNDER + 26, { fontFamily: ROMAN, fontSize: pt(11),
italic: true }),
// A seal reading 明月, the bright moon of three of the four poems, set down its square.
{ kind: 'box', id: 'seal', placement: onPage(170, 13),
style: { backgroundColor: col('seal'), borderRadius: mm(1) } },
line('seal-text', '明月', 170, { placement: onPage(170, 13), writingMode: 'vertical-rl',
fontFamily: KAI, fontSize: pt(14), lineHeight: 1, color: col('paper'),
verticalAlign: 'middle' }),
] } },
};
扉页也是一种标题样式,设了runningChapter: false,不作为任何章的名字。月亮是一个版面设计框,圆角半径为边长的一半;“唐詩”靠计算居中在月亮上:月亮的中线减去标题高度的一半。印章用writingMode: 'vertical-rl'排“明月”,一字在上一字在下,与刻印的方式相同。
#6 · 每款中文字体只加载它要排的字
const grab = (re) => (markdown.match(re) ?? []).join('');
// Each poem to its closing `:::` (not the `:::space` between stanzas), then the note numbers.
const poems = grab(/:::paragraphs\{style="shi"\}[\s\S]*?\n:::(?=\n|$)/g) + '①②③④⑤⑥⑦⑧⑨⑩';
await loadFonts(FONTS, markdown);
await Promise.all([
loadCjkFonts({ [SERIF]: ['400'] }, markdown + poems), // the notes and their ①, the heading blocks
loadCjkFonts({ [SERIF]: ['700'] }, grab(/^# \S+(?= \{style="zh")|\*\*[^*]+\*\*/gm)),
loadCjkFonts({ [SERIF]: ['900'] }, grab(/^# \S+(?= \{style="title")/gm)),
loadCjkFonts({ [KAI]: ['400'] }, `${poems}明月`),
loadCjkFonts({ [HEI]: ['400'] }, grab(/(?<=(?:poet|name)=")[^"]*/g)),
]);
Fontsource把每款中文字体按字符范围切成大约一百个文件,loadCjkFonts只获取文本用得到的文件(中文、日文和韩文字体)。楷体排诗和印章,黑体排诗人行和名字,粗宋体排四个诗题和注释的词头,它的特粗字重排扉页上的两个字。
完整食谱
// ═══ Postext Cookbook · Nº 083 · Tang poems facing their English verse ═══════════════
// https://postext.dev/en/cookbook/tang-poems-facing-english
// Code: MIT · Text: Tang poems, zh.wikisource; H. A. Giles, 1901, Project Gutenberg (PD)
// Fonts: Noto Serif TC, LXGW WenKai TC, Noto Sans TC, Source Serif 4 (OFL) · Needs postext ≥ 1.28.0
import { buildDocument, withLoadedFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'tang-poems-facing-english';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Ink and seal red on a cream paper, and a pale moon for the title page.
const palette = {
ink: '#1f1b18', // text: a warm near-black
seal: '#ad3526', // the accent: vermilion seal paste, for the poets, the rules and the seal
moon: '#eadcb4', // the title page's moon
leaf: '#f2e8cf', // the recto's tint, under the Chinese
muted: '#6d655c', // running heads and the colophon
paper: '#faf6ed', // a cream paper
};
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' } })),
{ id: 'main-color', name: 'seal (defaults)', value: { hex: palette.seal, model: 'hex' } },
];
const SERIF = 'Noto Serif TC'; // 明: the Chinese titles and the notes
const KAI = 'LXGW WenKai TC'; // 楷: the poems
const HEI = 'Noto Sans TC'; // 黑: the poet lines and the recto's running head
const ROMAN = 'Source Serif 4'; // the English: the Latin that Noto Serif TC is built on
const LABEL = 'Source Sans 3'; // English labels and folios
const [BODY, LEAD, SHI] = [10.5, 16, 16]; // pt: 五号 on a 16 pt pitch; the poems' size
const [CHARS, LINES] = [28, 30]; // the character grid: 28 ems by 30 lines
const TRIM = { width: 148, height: 210 }; // mm: 25開, a Taiwan trade trim
const [INNER, OUTER] = [18, 21]; // mm: minimum sides; the grid centres its measure between them
const MEASURE = (CHARS * BODY * 25.4) / 72; // 103.7 mm: 28 ems of 五号
const EDGE = OUTER + (TRIM.width - INNER - OUTER - MEASURE) / 2; // 23.6 mm: the outer text edge
// #region answer: the English opens the next verso, the Chinese the recto that faces it
const SINK = 6; // lines of LEAD under both titles, so the two poems start on the same line
const at = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });
// A title whose foot is 23 mm down at any size, and the poet's line under it at 24 mm.
const titled = (size, title, poet, under = []) => ({
enabled: true, minHeight: pt(SINK * LEAD),
slot: { elements: [...under,
{ kind: 'text', id: 'title', content: '{titleText}', fontSize: pt(size), lineHeight: 1.2,
align: 'center', overflow: 'wrap', color: col('ink'),
placement: at(23 - (size * 1.2 * 25.4) / 72), ...title },
{ kind: 'text', id: 'poet', align: 'center', overflow: 'wrap', color: col('seal'),
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#把原文放在左页
洛布古典丛书和许多汉英读本把原文放在左边:交换两种标题样式的奇偶,以及写书名和诗人名的两个书眉的奇偶,并在Markdown中把每首诗的中文标题和原诗写在英文之前。
-const english = { id: 'en', breakBefore: { enabled: true, parity: 'even' }, // 左页
+const english = { id: 'en', breakBefore: { enabled: true, parity: 'odd' }, // 右页
-const chinese = { id: 'zh', span: 'page', breakBefore: { enabled: true, parity: 'odd' },
+const chinese = { id: 'zh', span: 'page', breakBefore: { enabled: true, parity: 'even' },
- head('verso-book', '{subtitle}', 'even', 'top-left', EDGE + 8,
+ head('verso-book', '{subtitle}', 'odd', 'top-right', -(EDGE + 8),
- head('recto-poet', '{attr.name}', 'odd', 'top-right', -(EDGE + 8),
+ head('recto-poet', '{attr.name}', 'even', 'top-left', EDGE + 8,#把注释紧接在诗后
中文注释本把注释印在每首诗之后。这里用章末注实现,因为每首诗本身就是一章。
-const footnotes = { placement: 'column', numbering: 'page', // 页底;每页从①重新编号
+const footnotes = { placement: 'chapterEnd', chapterEndAlign: 'text',常见问题
易错点
标题样式会继承其级别的分页设置
headingStyles中的条目没有写出的字段都取自它所属的标题级别,breakBefore也不例外。在:::pagebreak之后以H1设置样式的目录页或版权页会继承parity 'odd',结果落在一张空白页之后。给这类样式设置breakBefore: { enabled: false }。 标题样式 →
易错点
中文字体通过cjk块分片加载
Fontsource把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →
易错点
用zh-Hans或zh-Hant标记文档,不要用LANG
食谱的版本是en和es,但中文示例在两个版本里都是中文:`locale: LANG`会把它标记为英文或西班牙文,给其中的拉丁文词断词,把图标注为Figure或Figura,并给PDF标上错误的语言。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以标记成英文或西班牙文时,中文字体的数字和与拉丁文共用的标点会换成另一套字形,断行的位置也随之改变。自己写出标记:'zh-Hans'(大陆规范:GB断行规则、开明式标点)或'zh-Hant'(台湾:全角居中标点);香港用'zh-HK'。单写'zh'按简体、大陆规范处理。日文示例写'ja'(见gotcha ja-locale-tag)。 中文断行 →
易错点
中文字体把引号和撇号排成全角,拉丁文中也一样
Noto Serif TC和其他繁体中文字体把‘ ’ “ ”画成一个em宽,这是中文使用它们的方式,而用该字体排的拉丁文词得到的也是这个字形:Li Bai’s的撇号后面出现很宽的空隙,英文引文开头和结尾各空出整整一个em。CJK字体也没有斜体,屏幕上模拟的倾斜在PDF中印成正体。在同一种字体中混排中文和拉丁语言的文字(脚注,它取正文字体;或带拼音的注释),最好不用撇号、弯引号和斜体;« »和Latin-1标点保持原宽度。拉丁文单独成段时,通过段落样式给它一个拉丁字体。 中日韩字体 →
致谢
- 文本
- Three Tang poems in traditional characters, Li Bai’s 靜夜思 and 月下獨酌 and Wang Wei’s 竹里館, as Three Hundred Tang Poems (1763) gives them · Li Bai, Wang Wei · 公有领域
- Du Fu’s 絕句, the second of his 絕句二首, as the Complete Tang Poems (1705, juan 228) prints it · Du Fu · 公有领域
- The English verse translations, from A History of Chinese Literature (1901), Project Gutenberg eBook 43711 · Herbert A. Giles · 公有领域
- The notes, the English titles, the note on the text and the colophon · Postext Cookbook · 原创
- 字体
- Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)


