简单来说
一部完整的加泰罗尼亚语中篇小说,排成小开本平装书。行末断词遵照加泰罗尼亚语的规范,带间隔点的双写l也不例外。
成品一览
Narcís Oller的《El transplantat》全文,依据他的《Obres completes》(巴塞罗那,1928年)文本,排成12 × 18.5 cm、32页的口袋本。四章之前依次是半书名页、面包师站在炉前的卷首插图、红色斜体Cormorant Garamond的书名页,以及一篇版本说明。每章在一幅十二行高的版画下开始,章号是红色罗马数字。正文为9.85 pt的Gentium Book Plus,按加泰罗尼亚研究院(IEC)的要求在音节处断开:断点两侧至少各留两个字母,元音分立处不拆,撇号之后不断,titil·laven断为titil- | laven,连字符取代中间的间隔点。对白用破折号,引文用«cometes baixes»。
这道食谱解答
- 怎样让西班牙文、法文或德文获得良好的两端对齐和断词?
- 怎样给每章不同的照片、颜色或章首页样式?
- 怎样排不编号的插图:饰图、小花饰、标志?
- 怎样写对话破折号、段首的年份、价格和字面符号,而不被Markdown误读?
简短回答
const LOCALE = 'ca'; // the exact bundled code: 'ca-ES' resolves to it too (postext ≥ 1.14)
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: mm(4.5), indentAfterHeading: false,
// The defaults justify, hyphenate in config().locale and break by Knuth–Plass. With 'ca'
// the dictionary follows the IEC: two letters on each side (ter-ra, cai-xa), no split in
// a hiatus (cièn-cia) or after an apostrophe (s’ha-via), l·l broken with the hyphen for the
// dot. From 1.30 the face is asked for its Catalan forms too: this one has a single dot.
// compounds: false divides arrossegar-se only at its own hyphen (Llibre d’estil, VI 2.5).
hyphenation: { compounds: false },
// Spaces from 0.7× to 1.6×, then up to 10‰ of tracking; a last line under 22 characters is
// a runt. A line that must keep d’inaugurar-se whole still opens to 1.94× on page 7.
maxWordSpacing: 1.6, minWordSpacing: 0.7, maxJustifyTracking: 10, runtMinCharacters: 22,
hyphenateAcrossColumns: false, // no page ends on a divided word
};
用料
- 功能
- 断词与文档语言最优断行(Knuth–Plass)封面、扉页和版权页设计过的章首页页面设计中的图片标题样式标题属性页面设计中的文字、线条和框从右页开始的章书眉与页码按页面角色显示书眉对称页边距纸张颜色段落样式自定义资源类型段末孤行、段首孤行与孤字文档元数据语义调色板导出PDF嵌入PDF的字体
- 类型
- Gentium Book Plus, Cormorant Garamond, Cormorant SC(SIL OFL 1.1)
- 素材
cap1-1200.jpgcap2-1200.jpgcap3-1200.jpgcap4-1200.jpgfrontis-1000.jpg- Engraving, frontispiece: the baker at his oven's door (Generated With Diffusion Models, 原创)
- Engraving, chapter I: the night train into Barcelona (Generated With Diffusion Models, 原创)
- Engraving, chapter II: the village street in autumn (Generated With Diffusion Models, 原创)
- Engraving, chapter III: the Rambla at dawn (Generated With Diffusion Models, 原创)
- Engraving, chapter IV: the old man by the railway (Generated With Diffusion Models, 原创)
做法
#1 · 用语言代码指定加泰罗尼亚语
代码见上面的简短回答。locale: 'ca'选用加泰罗尼亚语的断词模式,自postext 1.14起,这些模式遵循IEC的《Llibre d’estil》(支持的语言)。模式与TeX所用的相同,但断点两侧最少各留两个字母,而不是npm包里的三个,因此ter-ra、cai-xa和plu-ja都能断开。元音分立处不断开(cièn-cia、ca-mions),夹在元音之间的i则开始新的音节(fe-ia)。ela geminada在两个l之间断开:一行以titil-结束,下一行以laven开始,两边都没有间隔点,Knuth–Plass也按去掉间隔点后的宽度测量这一行。

compounds: false让动词和它的代词只在自身的连字符处断开(arrossegar- | se),这是IEC推荐的断法(断词)。代价是一行偏松:第7页d’inaugurar-se前面的那一行,词间距放宽到1.88倍,尽管maxJustifyTracking: 10已经让其他行用字距吸收了多出的部分。
#2 · 由整行构成的口袋本页面
const TRIM = { width: 120, height: 185 }; // mm
const [TOP, INNER, OUTER, LINES] = [18, 16, 15, 29];
const MEASURE = TRIM.width - INNER - OUTER; // 89 mm: about 63 characters of Gentium Book Plus
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
};
下页边距由成品尺寸、上页边距和LINES算出,所以版心恰好容纳29行14 pt,每个满页都止于同一条基线。89 mm的行长约容纳63个Gentium Book Plus字符。mirror: true让16 mm的页边距在跨页两面都留在书脊一侧(对称页边距)。
#3 · 四章共用一个章首设计
// # II {style="capitol" art="cap2"}: the art attribute names the picture's resource.
const PICTURE = { width: MEASURE, height: 12 * LINE }; // 89 × 59.3 mm: twelve lines, 3:2
const chapter = { id: 'capitol',
breakBefore: { enabled: true, parity: 'any' }, // a chapter opens on the next page, either side
marginBottom: pt(0), // the opener's own height already ends on a line
advancedDesign: { enabled: true, minHeight: pt(16 * LEAD), slot: { elements: [
{ kind: 'image', id: 'art', resourceId: '{attr.art}',
placement: at('container', 'top', 0, 0,
{ width: mm(PICTURE.width), height: mm(PICTURE.height) }) },
// The numeral and its rule hang from the container's top, a fixed drop under the picture.
text('numeral', '{titleText}', DISPLAY, 21, at('container', 'top', 0, PICTURE.height + 4),
{ fontWeight: 600, color: col('vermell'), lineHeight: 1 }),
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.5), color: col('vermell'),
placement: { ...at('container', 'top', 0, PICTURE.height + 13), size: { width: mm(8) } } },
] } },
};
resourceId: '{attr.art}'绘出标题指名的图片,所以# II {style="capitol" art="cap2"}用同一个样式让第二章在自己的版画下开始(标题属性)。minHeight留出十六行:十二行给版画,四行给章号和短线,正文从页面第十七行开始,每章都一样。
#4 · 第一章之前的四页
const front = (id, elements, { minHeight, ...extra } = {}) => ({ id,
breakBefore: { enabled: true, parity: 'any' }, marginBottom: pt(0),
header: { elements: [] }, footer: { elements: [] }, ...extra,
advancedDesign: { enabled: true, ...(minHeight && { minHeight }), slot: { elements } } });
const FRONTIS = { width: MEASURE, height: MEASURE * 1.5 }; // mm: the engraving is 2:3
const headingStyles = [
front('avantportada', [text('title', '{titleText}', DISPLAY, 19,
at('container', 'top', 0, 9 * LINE), { italic: true, fontWeight: 500, lineHeight: 1 })]),
front('frontis', [
{ kind: 'image', id: 'art', resourceId: '{attr.art}',
placement: at('container', 'top', 0, 0,
{ width: mm(FRONTIS.width), height: mm(FRONTIS.height) }) },
text('legend', '{titleText}', LABEL, 8.5, at('container', 'top', 0, FRONTIS.height + 5),
{ ...caps(8.5, 1.4, 'muted') }),
]),
front('portada', [
text('author', '{author}', LABEL, 10, at('container', 'top', 0, 5 * LINE),
caps(10, 2.2, 'ink')),
text('title', '{titleText}', DISPLAY, 34, at('container', 'top', 0, 8 * LINE),
{ italic: true, fontWeight: 500, color: col('vermell'), lineHeight: 1 }),
text('subtitle', '{subtitle}', DISPLAY, 13, at('container', 'top', 0, 8 * LINE + 17),
{ italic: true, fontWeight: 500 }),
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.5), color: col('vermell'),
placement: { ...at('container', 'top', 0, 8 * LINE + 29), size: { width: mm(14) } } },
]),
// The note sits low on the verso behind the title, its label a line above it.
front('nota', [text('label', '{titleText}', LABEL, 8.5, at('container', 'top', 0, 13 * LINE),
caps(8.5, 1.4))], { minHeight: pt(15 * LEAD) }),
chapter,
];
前置部分的每一页都是一个带自有样式的一级标题:# El transplantat {style="portada"}印出前置元数据中的作者和副标题,并把标题本身作为书名。每个样式都重申自己的分页,因为样式会继承所在级别的分页设置;每个样式也清空页眉和页脚,所以这些页没有书眉和页码。卷首插图落在第2页(左页),与书名页隔着书脊相对。
#5 · 左页印作者,右页印书名
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 = 10, pages = 'body') => ({
kind: 'text', id, content, parity, pages, ...caps(8, 1.3, 'muted'),
placement: at('page', edge, x, y),
});
const folio = { fontFamily: TEXT, fontWeight: 400, letterSpacing: pt(0), color: col('ink') };
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)] };
parity把作者放在左页、书名放在右页;pages: 'body'让两者都不出现在章首页,章首页改用pages: 'opener'的页脚页码。SHIFT把每个书眉移到版心的中线上;由于内外页边距不同,版心中线偏离页面中线半毫米。
#6 · 五幅版画,不加图注
const resourceTypes = [{ id: 'gravat', name: 'Gravat', namePlural: 'Gravats', shortLabel: 'Gravat',
captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal' }];
const PICTURES = { // id: [file, width, height, alt text in the book's language]
frontis: ['frontis-1000.jpg', 1000, 1500, 'Un carrer de poble al capvespre. A la porta del forn, '
+ 'on cremen les flames, el forner, gras i somrient, amb davantal blanc i els braços creuats.'],
cap1: ['cap1-1200.jpg', 1200, 800, 'De nit, el tren baixa cap a Barcelona: rengleres de fanals, '
+ 'la muntanya de Montjuïc i la lluna sobre el mar. Un pagès treu el cap per la finestreta.'],
cap2: ['cap2-1200.jpg', 1200, 800, 'Un carrer de poble buit en una nit de tardor. Per la porta '
+ 'baixa de la ferreria, el manyà pica l’enclusa enmig d’una estrella d’espurnes.'],
cap3: ['cap3-1200.jpg', 1200, 800, 'La Rambla a trenc d’alba des d’un balcó. Un fanaler apaga '
+ 'el gas amb la perxa; al fons, els pals dels vaixells del port.'],
cap4: ['cap4-1200.jpg', 1200, 800, 'Capvespre als afores. Un vell de cabells blancs, assegut '
+ 'al caire del desmunt, mira la via del tren, que es perd recta fins a l’horitzó.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
id, typeId: 'gravat', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
这些图片属于一个captionPrefix为空的资源类型,因此不编号也不加标签。每幅都按像素尺寸声明,并在排版前以其文件id加载。保存之前,图中的白色已映射为页面的米色,黑色映射为正文油墨色,所以它们印出来像页面的一部分,而不是贴上去的照片。
完整食谱
// ═══ Postext Cookbook · Nº 104 · A Catalan novella, hyphenated by the IEC rules ═══════
// https://postext.dev/en/cookbook/catalan-pocket-novella
// Code: MIT · Text: N. Oller, El transplantat, 1928 (PD, Viquitexts) · Pictures: diffusion models
// Fonts: Gentium Book Plus, Cormorant Garamond, Cormorant SC (OFL) · Needs postext ≥ 1.57.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document (the sample is Catalan in both)
const RECIPE = 'catalan-pocket-novella';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#2a2320', // text: a warm near-black, the pictures' ink too
vermell: '#953222', // the one accent: chapter numerals, rules, the title page's title
muted: '#6e6359', // running heads, the edition's note, the colophon
paper: '#f5efe1', // a cream book paper, the pictures' white
};
// Each colour names its palette entry and carries its hex.
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: 'vermell (defaults)', value: { hex: palette.vermell, model: 'hex' } },
];
const [TEXT, DISPLAY, LABEL] = ['Gentium Book Plus', 'Cormorant Garamond', 'Cormorant SC'];
const [BODY, LEAD] = [9.85, 14]; // pt: body and leading, the pitch of every vertical measure
const LINE = (LEAD * 25.4) / 72; // mm: one line, 4.94
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
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 }); // a long title takes a second line
const caps = (size, tracking, color = 'vermell') => ({ fontFamily: LABEL, fontSize: pt(size),
fontWeight: 600, letterSpacing: pt(tracking), color: col(color) });
// #region page: a 12 × 18.5 cm pocket book; the text block holds 29 whole lines
const TRIM = { width: 120, height: 185 }; // mm
const [TOP, INNER, OUTER, LINES] = [18, 16, 15, 29];
const MEASURE = TRIM.width - INNER - OUTER; // 89 mm: about 63 characters of Gentium Book Plus
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
};
// #endregion
// #region answer: Catalan by its own code: l·l breaks as il- | lusió, no word splits its hiatus
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#让代词也能断开
改用默认的compounds: true后,d’inaugurar-se在动词内部断开,成为d’i- | naugurar-se,第7页的松行随之消失:全书没有一行的词间距超过1.6倍。titil- | laven这个断点仍在第27页。代价是行末的撇号后面只剩一个i。
- hyphenation: { compounds: false },
+ hyphenation: { compounds: true },#每章从右页开始
parity: 'odd'会在原本从左页开始的章前插入一张空白页,就像版式更宽松的版本那样。原在第26页开始的第四章,会移到空白页之后的第27页。
- breakBefore: { enabled: true, parity: 'any' }, // a chapter opens on the next page, either side
+ breakBefore: { enabled: true, parity: 'odd' },常见问题
易错点
标题样式会继承其级别的分页设置
headingStyles中的条目没有写出的字段都取自它所属的标题级别,breakBefore也不例外。在:::pagebreak之后以H1设置样式的目录页或版权页会继承parity 'odd',结果落在一张空白页之后。给这类样式设置breakBefore: { enabled: false }。 标题样式 →
- 选定正文字体之前,先看它怎样排l·l。postext 1.30起,文档的
locale也是文字成形所用的语言(1.29及以前用的是展示这本书的网页的语言),而各款字体对加泰罗尼亚语的回应并不相同。Gentium Book Plus在所有语言里只有一个间隔点,两个l之间占0.17 em。这本书在1.29及以前用的Crimson Pro,在加泰罗尼亚语里把间隔点加宽到0.59 em,intel·ligent中间就空出一块。Alegreya和Literata只有当两个l作为一整段文字一起成形时才画出更紧的间隔点,所以il·lustrats在带斜体的段落里是一种样子,在不带斜体的段落里是另一种。 - 从Viquitexts复制文本时要保留斜体:Oller用斜体标出tentu、Ensanxe和palacio这些口语词或西班牙语词,导出纯文本会丢掉它们。可疑的词要对照1928年版的扫描件核对:转录本有六处把动词tornar写成了tom-(tomà、tomaré、tomar),还有一处把jorn写成了jom。
- 6800个词的正文分在五个内容文件里,加上工具包,合成后的脚本约69 KB。整本书已是一个pen能容纳的最长样例;更长的作品应放进
.postext包。
致谢
- 文本
- El transplantat, complete, from the Obres completes, vol. VI (Barcelona, 1928), with misprints corrected, no opening ¿ ¡ and today’s dialogue dashes · Narcís Oller · 公有领域
- The note to the edition · Postext Cookbook · 原创
- 图片
- Engraving, frontispiece: the baker at his oven's door · Generated With Diffusion Models · 原创
- Engraving, chapter I: the night train into Barcelona · Generated With Diffusion Models · 原创
- Engraving, chapter II: the village street in autumn · Generated With Diffusion Models · 原创
- Engraving, chapter III: the Rambla at dawn · Generated With Diffusion Models · 原创
- Engraving, chapter IV: the old man by the railway · Generated With Diffusion Models · 原创
- 字体
- Gentium Book Plus (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · Cormorant SC (SIL OFL 1.1)


