跳到主要内容
食谱编号201

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

按单调正字法断词的希腊语小说

把Theotokis《Η τιμή και το χρήμα》第一章排成13.5 × 20.5 cm的书:单调希腊语断词、«»引号、不带重音的大写书眉。

本页内容
输出
Canvas · PDF
难度
中级
Postext
已用Postext 1.99.1测试
需要≥ 1.99.1 · postext-pdf ≥ 1.99.1
许可证
更新于2026年11月29日
代码MIT · 文本MIT

第4–5页,共7页

  • 英文样例:尚无中文版本
  • 成品尺寸135 × 205 mm
  • 1栏
  • Literata 9.7/14.2
  • GFS Didot
  • 7页
  • 难度
  • Postext 1.99.1
  • 排版用时82 ms
  • 151行代码

简单来说

一部1914年希腊语小说的第一章,排成小开本。行末断词遵照希腊学校语法,书眉用大写字母,而希腊语大写不带重音。

成品一览

Konstantinos Theotokis的长篇小说《Η τιμή και το χρήμα》(《荣誉与金钱》,1914年)第一章,取自希腊语维基文库,排成13.5 × 20.5 cm的书。前面是书名页和一则文本说明;正文在右页开始,章号Αʹ用GFS Didot,下沉十行。正文是Literata 9.7/14.2 pt,每页31行,两端对齐,按单调希腊语的断词模式断行。书眉左页印作者、右页印书名,用加了字距的大写字母,并按希腊语大写的规矩去掉重音。说明和版权页随版本的语言变化;小说本身在三个版本里都是希腊语。

这道食谱解答

  • 怎样让西班牙文、法文或德文获得良好的两端对齐和断词?
  • 怎样设置书眉:左页放书名,右页放章名,页码在外侧?
  • 怎样写对话破折号、段首的年份、价格和字面符号,而不被Markdown误读?

简短回答

script.js · 第51–65行在完整代码中
// locale 'el' picks the monotonic patterns, which keep the digraphs and the diphthongs
// whole (μπρά-τσα, ευ-τυ-χί-α) and divide between two consonants the way a Greek school
// grammar does (κάρ-βου-να, αν-θρώ-πους). The same tag gives the Greek labels and tags the
// PDF as Greek. The defaults justify, hyphenate in config().locale and break by Knuth–Plass.
const LOCALE = 'el';
const bodyText = { // config().bodyText
  fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  firstLineIndent: em(1.2), indentAfterHeading: false,
  // Two letters at least on either side of a break (ξα-νά, not ξ-ανά) and no page that ends
  // on a divided word. Greek words run long: spaces from 0.8× to 1.6× of the face's own,
  // then up to 12‰ of tracking, and a last line under about eleven letters is a runt.
  hyphenation: { leftMin: 2, rightMin: 2 }, hyphenateAcrossColumns: false,
  maxWordSpacing: 1.6, minWordSpacing: 0.8, maxJustifyTracking: 12, runtMinCharacters: 22,
};

用料

还用到
分节书眉
类型
Literata, GFS Didot(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 指定语言:el

代码就是上面的简短回答。locale: 'el'选用单调希腊语的断词模式(断词)。它保留μπ、ντ、γκ、τσ、τζ这些二合字母和双元音不拆开,在两个辅音之间断开,和希腊学校语法一致:第3页断成εση-κώθηκε和μεσο-φόρι。leftMin和rightMin设为2,断点两侧至少各留两个字母;hyphenateAcrossColumns: false不让一页以断开的词结束。希腊语单词长,词距允许在字体本身的0.8到1.6倍之间,再加最多12‰的字距,让各行均匀。

#2 · 大写的书眉

script.js · 第69–88行在完整代码中
// textTransform 'uppercase' in a Greek document writes ΚΩΝΣΤΑΝΤΙΝΟΣ ΘΕΟΤΟΚΗΣ for
// Κωνσταντίνος Θεοτόκης: Greek capitals carry no accent, and the engine removes the tonos
// (and keeps a dialytika, ΑΫΠΝΙΑ) as it sets the letters. The Markdown keeps the accents,
// so search and the PDF's text read the words as written.
const caps = (size, tracking, color = 'muted') => ({ fontFamily: TEXT, fontSize: pt(size),
  fontWeight: 500, letterSpacing: pt(tracking), textTransform: 'uppercase', color: col(color) });
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre is off the page's centre
const head = (id, content, parity, edge, x, y = 11.5, pages = 'body') => ({
  kind: 'text', id, content, parity, pages, ...caps(7.5, 1.4), placement: at('page', edge, x, y),
});
const folio = { fontWeight: 400, letterSpacing: pt(0), color: col('ink') }; // digits: no case
const header = { elements: [
  { ...head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER), ...folio },
  head('verso-author', '{author}', 'even', 'top', -SHIFT),
  head('recto-title', '{title}', 'odd', 'top', SHIFT),
  { ...head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER), ...folio },
] };
const drop = (parity, x) => ({ ...head(`drop-${parity}`, '{pageNumber}', parity, 'bottom', x,
  -11, 'opener'), ...folio });
const footer = { elements: [drop('odd', SHIFT), drop('even', -SHIFT)] };

在希腊语文档里,textTransform: 'uppercase'把Κωνσταντίνος Θεοτόκης排成ΚΩΝΣΤΑΝΤΙΝΟΣ ΘΕΟΤΟΚΗΣ:希腊语大写不带tonos,引擎在排字时去掉它,分音符保留(ΑΫΠΝΙΑ)。Markdown和PDF里的文字仍保留带重音的词,所以搜索能找到。页码没有大小写之分,保持400字重。

#3 · 用Didot排的章号

script.js · 第92–103行在完整代码中
// # Α΄ {style="chapter"}: the numeral is the heading's text, a capital and the Greek numeral
// sign ʹ (U+0374), as Greek books number their chapters.
const chapter = { id: 'chapter', breakBefore: { enabled: true, parity: 'odd' },
  marginBottom: pt(0), // the opener's own height already ends on a line
  advancedDesign: { enabled: true, minHeight: pt(10 * LEAD), slot: { elements: [
    text('book', '{title}', TEXT, 8, at('container', 'top', 0, 2 * LINE),
      caps(8, 2.2, 'muted')),
    text('numeral', '{titleText}', DISPLAY, 30, at('container', 'top', 0, 3.6 * LINE),
      { color: col('accent'), lineHeight: 1 }),
    rule('rule', 6.4 * LINE, 10),
  ] } },
};

标题# Αʹ {style="chapter"}本身就是章号:一个大写字母加上数字记号ʹ,希腊图书就这样给章编号。设计把它以30 pt的GFS Didot放在书名下面,配一条短线,minHeight让正文下沉十行。breakBefore的parity设为odd,章从右页开始;标题样式自己决定分页落在哪一侧。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 201 · A Greek novel page, hyphenated in monotonic Greek ═══════
// https://postext.dev/en/cookbook/monotonic-greek-novel
// Code: MIT · Text: K. Theotokis, Η τιμή και το χρήμα, 1914 (PD, el.wikisource) · Pictures: none
// Fonts: Literata, GFS Didot (SIL OFL 1.1) · Needs postext ≥ 1.99.1
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the note on the text ('en' | 'es' | 'el')
const RECIPE = 'monotonic-greek-novel';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text on an ivory paper and one blue-grey accent, as the Athens literary presses
// set their novels between the wars.
const palette = {
  ink: '#1f1d1b', // text
  accent: '#2f4f6b', // chapter numeral, rules, the title on the title page
  muted: '#6a645c', // running heads, the note on the text, the colophon
  paper: '#fbf8f1', // an ivory book 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: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
const [TEXT, DISPLAY] = ['Literata', 'GFS Didot']; // a text face with Greek; a Greek Didot
const [BODY, LEAD] = [9.7, 14.2]; // pt
const LINE = (LEAD * 25.4) / 72; // mm: one line, 5.01
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
// Hung under another element, centred on it.
const under = (id, y) => ({ anchor: { to: id, edge: 'below', at: 'center' },
  offset: { y: mm(y) } });
const text = (id, content, fontFamily, size, placement, extra = {}) => ({ kind: 'text', id,
  content, fontFamily, fontSize: pt(size), color: col('ink'), align: 'center',
  overflow: 'wrap', placement, ...extra });
const rule = (id, y, width) => ({ kind: 'rule', id, direction: 'horizontal', thickness: pt(0.5),
  color: col('accent'),
  placement: { ...at('container', 'top', 0, y), size: { width: mm(width) } } });

// #region page: a 13.5 × 20.5 cm novel; the text block holds 31 whole lines
const TRIM = { width: 135, height: 205 }; // mm
const [TOP, INNER, OUTER, LINES] = [20, 18, 21, 31];
const page = {
  width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
  margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - LINES * LINE),
    left: mm(INNER), right: mm(OUTER), mirror: true }, // left is the inner margin on a recto
};
// 96 mm of measure: about 60 characters of Literata, nine or ten Greek words.
// #endregion

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

常见问题

易错点

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

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

  • 正文里位于词首的大写字母保留tonos,写在字母左侧(Ό,τι、Ή κάνεις)。只有textTransform: 'uppercase'才去掉重音;Markdown里要一直写上重音。
  • GFS Didot没有❦花饰,也没有斜体。用这款字体排花饰或强调,会落到别的字体或倾斜的正体上;本例只在书名和章号上用Didot。
  • 96 mm行宽里的短对白给断行留的余地小。捕获统计97行中有3行超过正常词距的1.6倍,最差的在第4页;加宽行宽或缩小字号可以减少。

致谢

文本
  • Η τιμή και το χρήμα (1914), chapter I, complete, from the monotonic transcription of el.wikisource (revision 101144), with one misprint corrected, one opening guillemet restored, elision marks as ’ and each line of dialogue a paragraph · Konstantinos Theotokis · 公有领域
  • The note on the text and the colophon · Postext Cookbook · 原创
字体
Literata (SIL OFL 1.1) · GFS Didot (SIL OFL 1.1)
沙盒