跳到主要内容
食谱编号205

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

按页编号脚注的俄语小说

《战争与和平》第一章,130 × 200毫米的版面:对话破折号,托尔斯泰自己译的法语用星号注在页脚,不该拆开的词始终连在一起,卷与部的序数用文字写出。

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

第4–5页,共10页

  • 英文样例:尚无中文版本
  • 成品尺寸130 × 200 mm
  • 1栏
  • Old Standard TT 10.5/13.2
  • Oranienbaum
  • 10页
  • 难度
  • Postext 1.100.0
  • 排版用时33 ms
  • 149行代码

简单来说

俄文《战争与和平》的开头,做成老式精装书的样子。法语对话在每页页脚译出,用星号标记,翻到下一页又从一个星号数起。

成品一览

《战争与和平》(Война и мир)第一卷第一部第一章全文,依据《全集》第9卷(1937年),排在130 × 200毫米的页面上,即俄国84 × 108/32开的成品尺寸。正文用Old Standard 10.5点,行距13.2点,每页34行,行长100毫米。安娜·帕夫洛夫娜和瓦西里公爵一半说法语,托尔斯泰自己的译文放在页脚,星号每页从头数起。标题用Oranienbaum,把卷和部写成Том первый、Часть первая。前面有黑与砖红两色的书名页,背面是用本版语言写的说明。

这道食谱解答

  • 怎样排一部俄语小说:对话破折号、按页用星号编号的脚注、不拆开的词?
  • 脚注怎么做?
  • 怎样写对话破折号、段首的年份、价格和字面符号,而不被Markdown误读?
  • 怎样设置书眉:左页放书名,右页放章名,页码在外侧?

简短回答

script.js · 第45–62行在完整代码中
// The language hyphenates by the Russian patterns, keeps a preposition with its word and a
// dash off the line start (bodyText.wordTies 'avoid'), holds the space after a dialogue's
// opening dash at its own width, counts the notes again on every page and indents their
// first line. The indents below are the Russian ones: 1,5 em, the first paragraph included.
const LOCALE = 'ru';
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.5), indentAfterHeading: true, // the default leaves the first one flush
  hyphenation: { leftMin: 2, rightMin: 2 }, maxWordSpacing: 1.6, minWordSpacing: 0.8,
  wordTies: 'avoid', // the default in these languages
  maxJustifyTracking: 15, // room for the ties in a 100 mm line
};
const footnotes = { // config().footnotes: *, **, ***, again from * on the next page
  numberFormat: 'symbols', // locale 'ru' gives symbols: ['*'] and numbering: 'page'
  fontSize: pt(8.6), lineHeight: pt(10.6),
  separator: { width: 0.25, lineWidth: pt(0.4), color: col('ink') },
};

用料

类型
Old Standard TT, Oranienbaum(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 设定语言和星号

代码见上面的简短回答。locale: 'ru'按俄语规则断词,让前置词、数字和破折号与所属的词相连,并且按页给脚注编号。numberFormat: 'symbols'把编号换成星号。注号按俄语习惯输入:在句号、逗号之前,在问号之后;引擎不会让句号掉到下一行。100毫米的行长对这么多的相连规则来说偏窄,所以给一点字距。每段法语放在:ltr[…]{lang=fr}里,按法语规则断词。

#2 · 由纸张得出页面

script.js · 第36–41行在完整代码中
const [TOP, INNER, OUTER, LINES] = [22, 15, 15, 34];
const page = {
  sizePreset: '84x108/32', dpi: 150, backgroundColor: col('paper'), // the sheet of GOST 5773
  margins: { top: mm(TOP), bottom: mm(200 - TOP - LINES * LINE), // 130 × 200 mm
    left: mm(INNER), right: mm(OUTER), mirror: true },
};

sizePreset: '84x108/32'就是GOST 5773的130 × 200毫米。下边距由34行算出,mirror在偶数页把左右边距对调。

#3 · 疏排一个词,给元音加重音

script.js · 第66–68行在完整代码中
// The edition's italics (грипп, рап) are spaced here, as Russian books set an emphasis
// before italics took over. A stress is U+0301 after its vowel: что́, сто́ите.
const characterStyles = [{ id: 'razryadka', name: 'Разрядка', letterSpacing: em(0.16) }];

当时的俄文书把词疏排以示强调。разрядка是带letterSpacing的字符样式,这里用在原版排成斜体的两个词上:грипп和рап。重音是元音后面的U+0301,如что́、сто́ит。

#4 · 用文字写卷数和部数

script.js · 第72–90行在完整代码中
// The Markdown has # Том, ## Часть and ### Глава; 'replace' prints the number alone. Том is
// masculine, so its ordinal asks for -masculine; Часть is feminine, the Russian default.
const level = (n, numberingTemplate, design, minHeight, extra = {}) => ({ level: n,
  numberingTemplate, numberPosition: 'replace', marginTop: pt(0), marginBottom: pt(0),
  breakBefore: { enabled: false },
  advancedDesign: { enabled: true, minHeight: pt(minHeight * LEAD), slot: { elements: design } },
  ...extra });
const levels = [
  level(1, 'Том {1:ordinal-masculine}', [
    text('volume', '{titleText}', DISPLAY, 17, at('container', 'top', 0, 2.2 * LINE),
      caps(2.4, 'red')),
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6), color: col('red'),
      placement: { ...at('container', 'top', 0, 4.5 * LINE), size: { width: mm(18) } } },
  ], 5, { breakBefore: { enabled: true, parity: 'odd' } }),
  level(2, 'Часть {2:ordinal}', [text('part', '{titleText}', DISPLAY, 11.5,
    at('container', 'top', 0, 0.4 * LINE), caps(1.6))], 2),
  level(3, '{3:upper-roman}', [text('chapter', '{titleText}', DISPLAY, 13,
    at('container', 'top', 0, 0.9 * LINE), {})], 3),
];

{1:ordinal-masculine}和{2:ordinal}按文档语言把计数写成文字,numberPosition: 'replace'用它取代标题印出。Markdown里只有# Том和## Часть,编辑不必改写数字。

#5 · 书眉

script.js · 第94–106行在完整代码中
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content, parity,
  pages: 'body', fontFamily: TEXT, fontSize: pt(9), color: col('ink'),
  placement: at('page', edge, x, 13), ...extra });
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER),
  head('verso-author', '{author}', 'even', 'top', 0, { italic: true }),
  head('recto-title', '{title}. {chapterTitle}', 'odd', 'top', 0, { italic: true }),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER),
  { kind: 'rule', id: 'under', direction: 'horizontal', thickness: pt(0.4), color: col('ink'),
    pages: 'body', placement: { ...at('page', 'top', 0, 18), size: { width: mm(100) } } },
] };
const footer = { elements: [{ ...head('drop', '{pageNumber}', 'all', 'bottom', 0),
  pages: 'opener', placement: at('page', 'bottom', 0, -11) }] };

作者名在偶数页,书名和卷数在奇数页,都是斜体,下面一条细线。pages: 'body'让开篇没有书眉,页码落在下方。

#6 · 双色书名页

script.js · 第110–130行在完整代码中
const front = (id, elements, furniture = [], extra = {}) => ({ id, numbered: false,
  runningChapter: false, breakBefore: { enabled: true, parity: 'any' }, numberPosition: 'before',
  header: { elements: furniture }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements }, ...extra } });
const frame = (id, inset, width) => ({ kind: 'box', id,
  style: { borderColor: col('red'), borderWidth: pt(width) },
  placement: { ...at('page', 'top-left', inset, inset),
    size: { width: mm(130 - 2 * inset), height: mm(200 - 2 * inset) } } });
const headingStyles = [
  front('title-page', [
    text('author', '{attr.first}', DISPLAY, 17, at('page', 'top', 0, 30), caps(1.6)),
    text('title', '{titleText}', DISPLAY, 40, { ...at('page', 'top', 0, 66),
      size: { width: mm(98) } }, { ...caps(0.6, 'red'), lineHeight: 1.1 }),
    text('subtitle', '{subtitle}', TEXT, 11, at('page', 'top', 0, 92), { italic: true }),
    text('imprint', '{attr.imprint}', DISPLAY, 10, at('page', 'bottom', 0, -29), caps(1.6)),
    text('year', '{attr.year}', DISPLAY, 10, at('page', 'bottom', 0, -23)),
  ], [frame('outer', 10, 2.2), frame('inner', 12.2, 0.5)]), // the section's header: whole page
  // The note sits low on the verso of the title page, under its label.
  front('note-page', [text('label', '{titleText}', DISPLAY, 10,
    at('container', 'top', 0, 17 * LINE), caps(1.2, 'red'))], [], { minHeight: pt(19 * LEAD) }),
];

边框放在该节的页眉槽里,才能覆盖整页;文字来自标题和它的属性。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 205 · A Russian novel with its notes counted by page ═══════
// https://postext.dev/en/cookbook/russian-novel-notes-by-page
// Code: MIT · Text: L. Tolstoy, Война и мир, I, I, I, PSS vol. 9, 1937 (PD, ru.wikisource)
// Fonts: Old Standard TT, Oranienbaum (SIL OFL 1.1) · Needs postext ≥ 1.100.0
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' | 'ru')
const RECIPE = 'russian-novel-notes-by-page';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black on a warm paper and the brick red of a title page printed in two inks, as the
// Leningrad presses of the thirties set their classics.
const palette = {
  ink: '#1e1a17', // text, the running heads, the folios
  red: '#a3301f', // the title, the frame, the volume
  muted: '#675e55', // the note on the text, the colophon
  paper: '#faf5ea', // a cream 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: 'red (defaults)', value: { hex: palette.red, model: 'hex' } },
];
const [TEXT, DISPLAY] = ['Old Standard TT', 'Oranienbaum']; // обыкновенная; a display antiqua
const [BODY, LEAD] = [10.5, 13.2]; // pt
const LINE = (LEAD * 25.4) / 72; // mm: one line, 4.66
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), 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 caps = (tracking, color = 'ink') => ({ textTransform: 'uppercase',
  letterSpacing: pt(tracking), color: col(color) });

// #region page: 84 × 108/32, 130 × 200 mm trimmed; 34 lines of 13.2 pt, 100 mm wide
const [TOP, INNER, OUTER, LINES] = [22, 15, 15, 34];
const page = {
  sizePreset: '84x108/32', dpi: 150, backgroundColor: col('paper'), // the sheet of GOST 5773
  margins: { top: mm(TOP), bottom: mm(200 - TOP - LINES * LINE), // 130 × 200 mm
    left: mm(INNER), right: mm(OUTER), mirror: true },
};
// #endregion

// #region answer: what locale 'ru' brings, and the notes set with asterisks
// The language hyphenates by the Russian patterns, keeps a preposition with its word and a
// dash off the line start (bodyText.wordTies 'avoid'), holds the space after a dialogue's
// opening dash at its own width, counts the notes again on every page and indents their
// first line. The indents below are the Russian ones: 1,5 em, the first paragraph included.

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

常见问题

  • 一页超过三四个星号,读起来就慢,第9页达到五个。可以像本配方这样把同一段话的译文合成一条注,也可以用numberFormat: 'decimal'改用数字。
  • 输入在句号后面的注号就留在句号后面,先后由Markdown决定。

致谢

文本
  • Война и мир, volume I, part I, chapter I, complete, after the Complete Works (PSS, vol. 9, 1937) in the transcription of ru.wikisource, with slips of the transcription corrected, Tolstoy’s translations placed as in current editions and the note mark set before the stop · Leo Tolstoy · 公有领域
  • The note on the text and the colophon · Postext Cookbook · 原创
字体
Old Standard TT (SIL OFL 1.1) · Oranienbaum (SIL OFL 1.1)
沙盒