跳到主要内容
食谱编号202

排版食谱 · 第2章 · 字体与文字

多调希腊语荷马与译文对照

左页是《奥德赛》开头,右页是Eftaliotis的现代希腊语译文,用grc模式断词,每五行标一个行号。

本页内容
类型
诗歌
输出
Canvas
难度
中级
Postext
已用Postext 1.99.1测试
需要≥ 1.99.1
许可证
更新于2026年11月29日
代码MIT · 文本CC BY 4.0

第2–3页,共6页

  • 英文样例:尚无中文版本
  • 成品尺寸140 × 215 mm
  • 1栏
  • GFS Didot 10.2/15
  • 6页
  • 难度
  • Postext 1.99.1
  • 排版用时43 ms
  • 150行代码

简单来说

荷马《奥德赛》开头几行古希腊语原文,带全部重音和气符,排在左页;右页是现代希腊语诗体译文,每行与所译的原文对齐。

成品一览

一本14 × 21.5 cm的小型古典文本,用GFS Didot排,这是希腊字体协会的多调字体。开头一页是拜占庭时代的《荷马传》,《苏达辞书》把它归在米利都的Hesychius名下,附荷马在伊奥斯岛的墓志铭。接着是两个对页:左页是《奥德赛》第一卷第1至27行,右页是Argyris Eftaliotis用十五音节诗行写的现代希腊语译文,逐行对应,每五行在外侧页边标号。三份文本都属公有领域,取自希腊语维基文库。书眉和章首把标题排成大写,去掉所有气符和重音。

这道食谱解答

  • 怎样把诗和译文排在对页上,原文总在右页?
  • 怎样在诗的页边每隔五行标一个行号,并让注释对应这些行号?
  • 怎样排诗歌:每句一行,诗节间留空,折行悬挂缩进,不断词?
  • 怎样让西班牙文、法文或德文获得良好的两端对齐和断词?

简短回答

script.js · 第31–51行在完整代码中
// locale 'grc' takes the polytonic patterns, which read breathings, circumflexes, the iota
// subscript and the diaeresis as the letters they sit on (Πει-σι-στρά-του, ὀφ-θαλ-μῶν,
// ἀ-ναμ-φί-λε-κτα). Eftaliotis's modern Greek is written polytonic too; under 'el' a
// polytonic word would be divided by the same patterns, so the two pages hyphenate alike.
// The labels are the modern Greek ones (Εικόνα, Πίνακας), as for 'el'.
const LOCALE = 'grc';
// Fontsource cuts each face into files by script, and loadFonts adds latin and greek. The
// accented letters of polytonic Greek (ἀ ὃ ῷ, U+1F00–1FFF) are in a third file, greek-ext:
// each face takes it too before the build, so no letter falls to a system font.
async function loadGreekExtended(faces) {
  const jobs = Object.entries(faces).flatMap(([family, specs]) => specs.map(async (spec) => {
    const id = fontsourceId(family);
    const style = spec.endsWith('i') ? 'italic' : 'normal';
    const file = `${id}-greek-ext-${parseInt(spec, 10)}-${style}.woff2`;
    const url = `${await fontsourceAt(id)}files/${file}`;
    const face = new FontFace(family, `url(${url}) format('woff2')`,
      { weight: String(parseInt(spec, 10)), style, unicodeRange: 'U+1F00-1FFF' });
    document.fonts.add(await face.load());
  }));
  await Promise.all(jobs);
}

用料

类型
GFS Didot(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 把文本标为grc并加载带重音的字母

代码就是上面的简短回答。locale: 'grc'选用多调断词模式(断词),把气符、扬抑符、下标iota或分音符当作所在字母的一部分。第1页断成Βατρα-χομυομαχία、ἐπι-δειξάμενος和τυράν-νου。Fontsource按文字系统拆分每款字体,loadFonts只加入latin和greek文件。预组合的多调字母U+1F00–1FFF在第三个文件greek-ext里,由loadGreekExtended在排版前为每款字体加入。要在loadFonts之后调用,否则引擎会认为字体已加载而跳过greek文件。

#2 · 在外侧页边每五行标号

script.js · 第67–73行在完整代码中
// Each page of verse is its own :::verse block. The Greek and the translation of a spread
// both open with {lineStart=11}, so the numbers on the two pages agree: restart 'poem'
// counts each block from its own start, and the epitaph, {numbered=false}, is not counted.
const lineNumbers = {
  enabled: true, count: 'verse', interval: 5, restart: 'poem', position: 'outer',
  gap: mm(6), fontFamily: DIDOT, fontSize: em(0.8), color: col('rubric'),
};

count: 'verse'只给诗行编号,restart: 'poem'让每个:::verse块从自己的起点计数。每页诗行是单独的一块。第二个对页的原文和译文都以{lineStart=11}开头,所以对页上的行号一致。position: 'outer'把行号放在左页的左边、右页的右边(行号)。墓志铭用{numbered=false},不编号。

#3 · 大写的章首和书眉

script.js · 第83–124行在完整代码中
// textTransform 'uppercase' turns Ὀδύσσεια into ΟΔΥΣΣΕΙΑ and Ῥαψῳδία into ΡΑΨΩΔΙΑ: Greek
// capitals take no breathing, no accent and no iota subscript (a dialytika stays, Ϊ Ϋ).
const caps = (size, tracking, color = 'muted') => ({ fontFamily: DIDOT, fontSize: pt(size),
  letterSpacing: pt(tracking), textTransform: 'uppercase', color: col(color) });
const opener = (title) => ({ enabled: true, minHeight: pt(5 * LEAD), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{attr.kicker}', align: 'center', ...caps(8, 2, 'rubric'),
    placement: { ...at('container', 'top', 0, LINE), size: { width: 'fill' } } },
  { kind: 'text', id: 'title', content: title, align: 'center', ...caps(17, 3.5, 'ink'),
    placement: { ...at('container', 'top', 0, 2.2 * LINE), size: { width: 'fill' } } },
] } });
// # Ὀδύσσεια {style="original"} opens a verso, {style="translation"} the recto facing it;
// a style sets its own break side (gotcha: style-inherits-break).
const headingStyles = [
  { id: 'original', breakBefore: { enabled: true, parity: 'even' }, marginBottom: pt(0),
    advancedDesign: opener('{titleText}') },
  { id: 'translation', breakBefore: { enabled: true, parity: 'odd' }, marginBottom: pt(0),
    advancedDesign: opener('{titleText}') },
  { id: 'life', breakBefore: { enabled: true, parity: 'odd' }, marginBottom: pt(0),
    advancedDesign: { enabled: true, minHeight: pt(6 * LEAD), slot: { elements: [
      { kind: 'text', id: 'title', content: '{titleText}', align: 'center', ...caps(15, 3, 'ink'),
        placement: { ...at('container', 'top', 0, 1.6 * LINE), size: { width: 'fill' } } },
      { kind: 'text', id: 'source', content: '{attr.source}', align: 'center', fontFamily: DIDOT,
        fontSize: pt(10), color: col('muted'),
        placement: { ...at('container', 'top', 0, 3.2 * LINE), size: { width: 'fill' } } },
    ] } } },
  { id: 'note-page', breakBefore: { enabled: true, parity: 'even' }, marginBottom: pt(LEAD),
    header: { elements: [] }, advancedDesign: { enabled: true, minHeight: pt(3 * LEAD),
      slot: { elements: [{ kind: 'text', id: 'label', content: '{titleText}', align: 'center',
        ...caps(7.5, 1.6, 'rubric'), placement: { ...at('container', 'top', 0, LINE),
          size: { width: 'fill' } } }] } } },
];
// The author and the title over the versos, the translator over the rectos; folios outside.
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content, parity,
  pages: 'body', ...caps(7.5, 1.5), ...extra, placement: at('page', edge, x, 12) });
const folio = { textTransform: 'none', letterSpacing: pt(0), fontSize: pt(9), color: col('ink') };
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre is off the page's centre
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folio),
  head('verso-head', '{author} · {title}', 'even', 'top', -SHIFT),
  head('recto-head', '{subtitle}', 'odd', 'top', SHIFT),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folio),
] };

textTransform: 'uppercase'把Ὀδύσσεια排成ΟΔΥΣΣΕΙΑ,把Ῥαψῳδία排成ΡΑΨΩΔΙΑ:希腊语大写不带气符、重音和下标iota,引擎排字时去掉它们。original样式让原文从左页开始,translation让译文在对面的右页开始。:::pagebreak{parity="even"}和{parity="odd"}对第二个对页做同样的事。标题文字和PDF文字保持原样,所有符号都在。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 202 · Homer in polytonic Greek, facing its translation ═══════
// https://postext.dev/en/cookbook/homer-polytonic-facing-translation
// Code: MIT · Texts: Homer, Hesychius, A. Eftaliotis (PD, el.wikisource) · Pictures: none
// Fonts: GFS Didot (SIL OFL 1.1) · Needs postext ≥ 1.99.1
// The opening of the Odyssey on the versos, Eftaliotis's line-for-line modern Greek on the
// rectos, both numbered every fifth line, after a page of the Byzantine Life of Homer.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the note on the text ('en' | 'es' | 'el')
const RECIPE = 'homer-polytonic-facing-translation';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text on a warm white, and the dull red of a classical text's rubrics.
const palette = {
  ink: '#1c1a18', // the texts
  rubric: '#8c2f23', // line numbers, headings, rules
  muted: '#6b6359', // running heads, the note on the text, the colophon
  paper: '#fcfaf5',
};
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: 'rubric (defaults)', value: { hex: palette.rubric, model: 'hex' } },
];
const DIDOT = 'GFS Didot'; // the Greek Font Society's Didot: polytonic, with its own Latin
const [BODY, LEAD] = [10.2, 15]; // pt
const LINE = (LEAD * 25.4) / 72; // mm: one line, 5.29
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });

// #region answer: Ancient Greek is 'grc', with the polytonic accents written in the text
// locale 'grc' takes the polytonic patterns, which read breathings, circumflexes, the iota
// subscript and the diaeresis as the letters they sit on (Πει-σι-στρά-του, ὀφ-θαλ-μῶν,
// ἀ-ναμ-φί-λε-κτα). Eftaliotis's modern Greek is written polytonic too; under 'el' a
// polytonic word would be divided by the same patterns, so the two pages hyphenate alike.
// The labels are the modern Greek ones (Εικόνα, Πίνακας), as for 'el'.
const LOCALE = 'grc';
// Fontsource cuts each face into files by script, and loadFonts adds latin and greek. The
// accented letters of polytonic Greek (ἀ ὃ ῷ, U+1F00–1FFF) are in a third file, greek-ext:
// each face takes it too before the build, so no letter falls to a system font.
async function loadGreekExtended(faces) {
  const jobs = Object.entries(faces).flatMap(([family, specs]) => specs.map(async (spec) => {
    const id = fontsourceId(family);
    const style = spec.endsWith('i') ? 'italic' : 'normal';
    const file = `${id}-greek-ext-${parseInt(spec, 10)}-${style}.woff2`;
    const url = `${await fontsourceAt(id)}files/${file}`;
    const face = new FontFace(family, `url(${url}) format('woff2')`,
      { weight: String(parseInt(spec, 10)), style, unicodeRange: 'U+1F00-1FFF' });
    document.fonts.add(await face.load());

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

常见问题

易错点

标题样式会继承其级别的分页设置

headingStyles中的条目没有写出的字段都取自它所属的标题级别,breakBefore也不例外。在:::pagebreak之后以H1设置样式的目录页或版权页会继承parity 'odd',结果落在一张空白页之后。给这类样式设置breakBefore: { enabled: false }。 标题样式 →

  • 没有greek-ext文件,每个带重音的元音都会落到很少匹配的系统字体上。捕获会对照已加载的文件检查每个字形(C36),并判这样的页面不合格。
  • GFS Didot只有一个字重,没有斜体:强调会被渲染器硬斜。所以文本说明用正体。
  • 工具包的PDF字体提供器只加载latin和greek,所以本例只显示画布,不提供PDF。
  • 译文的每一行都不能超出行宽。转行的一行会把该页其余部分往下推一行,两页就不再逐行对应;10.2 pt下的103 mm能容纳Eftaliotis最长的一行,59个字母。

致谢

文本
  • Odyssey, Book I, lines 1–27, in the polytonic text of el.wikisource (revision 165777) · Homer · 公有领域
  • The modern Greek translation of the same lines, line for line, from el.wikisource (revision 166701), with one accent corrected · Argyris Eftaliotis · 公有领域
  • Life of Homer, §§ 6–7 and the epitaph, from the Suda (ed. A. Westermann, 1845), via el.wikisource (revision 152483), with four slips corrected · Hesychius of Miletus · 公有领域
  • The note on the text and the colophon · Postext Cookbook · 原创
字体
GFS Didot (SIL OFL 1.1)
沙盒