跳到主要内容
食谱编号156

排版食谱 · 第12章 · 教科书

十种语言的儿童教科书单元

三年级社会课一个单元的九页,共十种语言版本,阿拉伯语从右往左排,中文和日文竖排:彩色底的跨页,带页签、随文字变高的框,以及按正文标注地名的手绘地图。

本页内容

第6–7页,共9页

  • 成品尺寸210 × 280 mm
  • 1栏
  • Noto Serif SC 12/21
  • ZCOOL KuaiLe
  • 9页
  • 难度
  • Postext 1.65.0
  • 排版用时142 ms
  • 296行代码

简单来说

一个讲河流的教科书单元,共九页。每个主题是一个彩色底的跨页,有标题标签、文字、插图和各种框。地图上没有画任何文字,地名全都来自正文。各种语言篇幅不同,却用同一套模板。

成品一览

《我们的河流》是一本虚构的三年级社会课本的第 4 单元,这里排了九页,开本 210 × 280 mm,共有十种语言:西班牙语、加泰罗尼亚语、英语、葡萄牙语、法语、德语、意大利语、阿拉伯语、中文和日语。单元开篇是一幅画出来的河谷,接着是列出两个篇目的目录页,然后是三个跨页主题,每个主题各有底色:水的蓝、田野的绿、阳光的沙色。每个主题都有写着编号和标题的标签、两栏文字,以及带页签、随文字变高的框。第二个主题是一幅横跨两页的手绘地图,河流、村镇和三个河段的名字都由 Markdown 标在图上,每个河段框还有一条线连到它那一段河。重复的东西只画一次:模板按 Markdown 的需要,把一张图片卡、一个河段框和一个带图的框排上若干次;单元开头的三道问题,是同一个模块的三次使用。各语言的篇幅相差五分之一以上,却排进同一套模板:框按文字需要变高,把下一个框往下推,而地图会比任何文字先缩小一点。阿拉伯语版从右往左排,中文版和日文版从上往下排;这三本都在右侧装订,每个跨页先读右页,再读左页。

这道食谱解答

  • 同一套页面模板要排三种语言的教科书单元,而各语言的文字长短不一,该怎么做?
  • 怎样让页面上的框随文字变高,并把下面的框往下推?
  • 怎样从正文里给地图写上地名,让译本只换文字、不动地图本身?

简短回答

script.js · 第90–122行在完整代码中
// Ground, tab and number are decoration anchored to the title frame; the number,
// `{headingNumber}`, stands over the padding before its words. A topic extends the base.
const ground = () => ({ kind: 'box', id: 'ground',
  placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } },
  style: { backgroundColor: col('tema-ground') } });
const titleTab = () => ({ kind: 'box', id: 'tab', placement: { ...at('#titulo',
  'top-left'), size: { width: { to: '#titulo', edge: 'right' }, height: { to: '#titulo',
    edge: 'bottom' } } }, style: { backgroundColor: col('tema'), borderRadius: mm(4) } });
const badge = () => ({ kind: 'text', id: 'number', content: '{headingNumber}',
  fontFamily: DISPLAY, fontSize: pt(22), fontWeight: fw(700), color: col('tema'), align: 'center',
  box: { backgroundColor: col('paper'), borderRadius: mm(6) }, placement: { ...at('#titulo',
    corner('top'), inward(CJK ? 2.6 : 5), CJK ? 5 : 2.4), size: { width: mm(12), height: mm(12) } },
});
const title = { name: 'titulo', takes: 'h1', style: 'titulo', width: mm(MEASURE),
  placement: at('container', 'top-left') };

const base = {
  id: 'tema', spread: true, gutter: mm(12),
  decoration: { elements: [ground(), titleTab(), badge()] },
  frames: [title, { name: 'texto', flow: true, columns: 2, columnGap: mm(CJK ? 16 : 7), // 段
    width: mm(MEASURE), fit: { minScale: 0.9 } }],
  groups: [{ name: 'izquierda', kind: 'stack', gap: mm(6), frames: ['titulo', 'texto'] }],
};
const topic = (id, f, more) => ({ id, extends: 'tema', palette: swap(f), ...more });
const box = (name, style, minHeight, more) => ({ name, style, width: mm(MEASURE),
  minHeight: mm(minHeight), ...more });
const answer = (name, lines) => ({ name, optional: true, style: 'respuesta', width: mm(MEASURE),
  height: mm(LINE * lines), minHeight: mm(LINE * lines),
  rules: { every: mm(LINE), color: col('rule'), width: pt(0.75) } });
const PIC = CJK ? 30 : 56; // a picture at the end of a box's first lines pushes the text aside
const withPic = (name, style, minHeight, more) => [box(name, style, minHeight,
  { padding: { right: mm(PIC + 8) }, ...more }), { name: `${name}-foto`, layer: 2, width: mm(PIC),
  exclude: 'push', placement: at(`#${name}`, 'top-right', -5, 8) }];

用料

类型
Nunito, Fredoka, Noto Naskh Arabic, Baloo Bhaijaan 2, Klee One, Zen Maru Gothic, Noto Serif SC, ZCOOL KuaiLe(SIL OFL 1.1)
素材
  • arroyo-720.jpg
  • cascada-720.jpg
  • limpieza-720.jpg
  • mapa-1900-rtl.jpg
  • mapa-1900.jpg
  • molino-720.jpg
  • nacimiento-720.jpg
  • piraguas-720.jpg
  • portada-1400.jpg
  • riego-720.jpg
  • The valley of the River Aldara, painted from the mountains to the sea, with two children watching the water. (Generated With Diffusion Models, 原创)
  • The painted map of the valley, from the spring to the port, with no lettering: the names are labels set from the Markdown. (Generated With Diffusion Models, 原创)
  • The same painted map mirrored, the mountains on the right, for the books bound on the right (Arabic, Chinese, Japanese). (Generated With Diffusion Models, 原创)
  • A spring between mossy rocks. (Generated With Diffusion Models, 原创)
  • A mountain stream over round stones. (Generated With Diffusion Models, 原创)
  • A small waterfall into a green pool. (Generated With Diffusion Models, 原创)
  • A farmer opening the gate of an irrigation canal. (Generated With Diffusion Models, 原创)
  • An old stone watermill with its wheel. (Generated With Diffusion Models, 原创)
  • Children paddling canoes on a calm river. (Generated With Diffusion Models, 原创)
  • Children and a teacher picking up litter on a river bank. (Generated With Diffusion Models, 原创)

做法

#1 · 弄清每种语言从哪一侧开始

script.js · 第33–44行在完整代码中
// Arabic runs right to left, Chinese and Japanese down the page, all bound on the right. Frames
// stand in the flow (x along the lines, mirrored in Arabic, down the page when vertical).
const AR = LANG === 'ar', CJK = LANG === 'zh' || LANG === 'ja';
const RIGHT_BOUND = AR || CJK, LATIN = !RIGHT_BOUND; // italics, capitals, tracking, hyphens
const [TEXT, DISPLAY] = { ar: ['Noto Naskh Arabic', 'Baloo Bhaijaan 2'], ja: ['Klee One',
  'Zen Maru Gothic'], zh: ['Noto Serif SC', 'ZCOOL KuaiLe'] }[LANG] ?? ['Nunito', 'Fredoka'];
const START = RIGHT_BOUND ? 'right' : 'left'; // the side a page starts reading from
const corner = (v) => `${v}-${START}`, inward = (x) => (RIGHT_BOUND ? -x : x);
const [SLANT, CAPS] = LATIN ? ['italic', 'uppercase'] : ['normal', 'none'];
const LEAD = AR ? 20 : CJK ? 21 : 17.5, track = (v) => (LATIN ? v : 0); // Naskh, ruby need room
const fw = (w) => ({ 'ZCOOL KuaiLe': 400, 'Zen Maru Gothic': w > 550 ? 700 : 500 })[DISPLAY] ?? w;
const BOLD = TEXT === 'Klee One' ? 600 : 700; // and the weights the faces have

模板里的框位于页面的流向坐标系中,x 沿着行的方向延伸。设置 locale: 'ar' 时,引擎把这个坐标系左右镜像,所以阿拉伯语版原样使用拉丁文的框:标题先出现在右页,三张照片和三个河段框从右往左排,框的页签、色条和内边距都跟着行走。设置 layout.writingMode: 'vertical-rl' 时,x 沿页面向下,y 从右往左:框的 width 是向下的长度,堆叠组向左推进,columns: 2 分出上下两栏(段),每栏 27 个字,放在另一个框 below 的框位于它的左边。装饰(底色、标题标签、编号、书眉和页码)放在纸面本身上,所以从 START 定位,也就是页面开始阅读的那一侧。每种文字都有一款正文字体和一款圆体标题字体,阿拉伯语、中文和日文版不用斜体、大写字母和字距调整。

#2 · 用 extends 搭出各种框

script.js · 第59–86行在完整代码中
// Two steps of `extends`: the box (shape, type, tab), then the kind. The colours are `tema`
// entries, so one style serves the three topics; paddings, stripes and tabs are in the flow.
const tab = (f) => ({ position: 'top-left', background: col(f), color: col('paper'),
  fontFamily: DISPLAY, fontSize: pt(12), fontWeight: fw(600), height: mm(7), paddingX: mm(3.2),
  offset: mm(7), inset: mm(5), rule: { enabled: false, color: col(f) } });
const boxText = { fontFamily: TEXT, fontSize: pt(12), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), boldFontWeight: BOLD, firstLineIndent: pt(0),
  textAlign: CJK ? 'justify' : 'left', paragraphSpacing: true };
const calloutStyles = [
  { id: 'caja', backgroundEnabled: true, background: col('paper'), borderRadius: mm(3),
    border: { enabled: false }, padding: { top: mm(3.4), right: mm(5), bottom: mm(4), left: mm(5) },
    body: boxText, lists: { color: col('ink'), gap: mm(2), itemSpacing: mm(1.6) } },
  { id: 'caja-tema', extends: 'caja', label: tab('tema'), lists: { color: col('tema') } },
  { id: 'dato', extends: 'caja-tema', background: col('tema-tint') },
  { id: 'palabras', extends: 'caja-tema', border: { enabled: true, color: col('tema'),
    width: pt(1.4) } }, { id: 'actividad', extends: 'caja-tema',
    stripe: { enabled: true, side: 'left', width: pt(4), color: col('tema') } },
  { id: 'titulo', extends: 'caja', backgroundEnabled: false,
    padding: { top: mm(2.6), right: mm(6), bottom: mm(3.2), left: mm(TAB) } },
  { id: 'titulo-plano', extends: 'titulo', padding: { left: mm(8) } },
  { id: 'portada', extends: 'caja', background: col('agua'), borderRadius: mm(4),
    padding: { top: mm(2.6), right: mm(8), bottom: mm(3.6), left: mm(8) } },
  { id: 'foto', extends: 'caja', borderRadius: mm(2),
    padding: { top: mm(1.8), right: mm(1.8), bottom: mm(2.2), left: mm(1.8) } },
  { id: 'respuesta', extends: 'caja', padding: NONE }, { id: 'colofon', extends: 'caja',
    backgroundEnabled: false, padding: NONE,
    body: { ...boxText, fontSize: pt(8), lineHeight: pt(AR ? 13 : 11), color: col('muted') } },
];

框样式分三步做成。caja 保存形状、字体和页签的几何;caja-tema 把主题的颜色加到页签和项目符号上;dato、palabras、actividad 决定种类:带底色的框、带描边的框、带色条的框。它们的颜色是调色板条目(tema、tema-tint),所以每个样式只写一次,由主题的模板给它上色。

#3 · 让每个主题继承同一个底板模板

script.js · 第90–122行在完整代码中
// Ground, tab and number are decoration anchored to the title frame; the number,
// `{headingNumber}`, stands over the padding before its words. A topic extends the base.
const ground = () => ({ kind: 'box', id: 'ground',
  placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } },
  style: { backgroundColor: col('tema-ground') } });
const titleTab = () => ({ kind: 'box', id: 'tab', placement: { ...at('#titulo',
  'top-left'), size: { width: { to: '#titulo', edge: 'right' }, height: { to: '#titulo',
    edge: 'bottom' } } }, style: { backgroundColor: col('tema'), borderRadius: mm(4) } });
const badge = () => ({ kind: 'text', id: 'number', content: '{headingNumber}',
  fontFamily: DISPLAY, fontSize: pt(22), fontWeight: fw(700), color: col('tema'), align: 'center',
  box: { backgroundColor: col('paper'), borderRadius: mm(6) }, placement: { ...at('#titulo',
    corner('top'), inward(CJK ? 2.6 : 5), CJK ? 5 : 2.4), size: { width: mm(12), height: mm(12) } },
});
const title = { name: 'titulo', takes: 'h1', style: 'titulo', width: mm(MEASURE),
  placement: at('container', 'top-left') };

const base = {
  id: 'tema', spread: true, gutter: mm(12),
  decoration: { elements: [ground(), titleTab(), badge()] },
  frames: [title, { name: 'texto', flow: true, columns: 2, columnGap: mm(CJK ? 16 : 7), // 段
    width: mm(MEASURE), fit: { minScale: 0.9 } }],
  groups: [{ name: 'izquierda', kind: 'stack', gap: mm(6), frames: ['titulo', 'texto'] }],
};
const topic = (id, f, more) => ({ id, extends: 'tema', palette: swap(f), ...more });
const box = (name, style, minHeight, more) => ({ name, style, width: mm(MEASURE),
  minHeight: mm(minHeight), ...more });
const answer = (name, lines) => ({ name, optional: true, style: 'respuesta', width: mm(MEASURE),
  height: mm(LINE * lines), minHeight: mm(LINE * lines),
  rules: { every: mm(LINE), color: col('rule'), width: pt(0.75) } });
const PIC = CJK ? 30 : 56; // a picture at the end of a box's first lines pushes the text aside
const withPic = (name, style, minHeight, more) => [box(name, style, minHeight,
  { padding: { right: mm(PIC + 8) }, ...more }), { name: `${name}-foto`, layer: 2, width: mm(PIC),
  exclude: 'push', placement: at(`#${name}`, 'top-right', -5, 8) }];

底板是一个跨页模板:铺到出血位的底色、带编号的标题标签,以及两栏文字。每个主题用 extends: 'tema' 继承它,设置自己的 palette(三个 tema 条目取该色系的颜色,底色、标签、编号和所有框一起变),再加上自己的框。标签和编号是锚定在标题框上的装饰,所以标签的高度正好是这种语言的标题所需。编号是 {headingNumber},即标题框所取标题的计数,画在框中文字之前的内边距上:页面块里不再重复写它,点击它会点到编号,而不是框。

#4 · 重复的东西只画一次

script.js · 第126–131行在完整代码中
const grid = (name, frames, columns, placement, more, width = MEASURE) => ({ name, kind: 'grid',
  columns, columnGap: mm(5), rowGap: mm(CJK ? 8 : 12), repeat: { frames },
  placement: { ...placement, size: { width: mm(width), height: 'fill' } }, ...more });
const question = { id: 'pregunta', role: 'module', // a question and the lines to answer it on
  frames: [box('caja', 'dato', CJK ? 22 : 14, { width: 'fill' }), { ...answer('lineas',
    CJK ? 2 : 3), width: 'fill', placement: at('#caja', 'below', 0, CJK ? 4 : 7) }] };

网格组为页面上的每一项重复一组框。配图条是 grid('fotos', ['foto'], 3, …):三个 :::figure{slot="foto"} 块给出三张图片卡,名为 #foto[1] 到 #foto[3],“试一试”框挂在 #foto[1] 下面。阳光主题的框是一个单栏网格,每组是一个框和它的图(['uso', 'uso-foto']):每个 :::frame{slot="uso"} 装着自己的文字,里面再放与之对应的 :::figure{slot="uso-foto"}。问题页堆叠的是模块:pregunta 是一个 role: 'module' 的模板,含一个浅色底的框和作答用的横线;页面上的 preguntas 组(modules: true)为 Markdown 里的每个 :::module{template="pregunta"} 排一个。框和自己的文字一样高,但不低于 minHeight,所以较长的西班牙语文字会把下面的各行往下推;页面不够用时,重排阶梯先缩小地图和图片,再缩文字,最多缩到 90 %。

河段框是地图下方一个三格的网格(grid('cursos', ['curso'], 3, …)),每个 :::frame{slot="curso"} 占一格。地图用 curso 样式的标注写出同样三段河的名字,底色与框的页签同为绿色,读者凭名字和颜色就能找到每个框对应的河段。竖排页面上,三个河段框排成一列,立在地图旁边。

#5 · 按正文给地图标上名字

script.js · 第250–290行在完整代码中
// An anchor is a point of the painting (fractions of its width and height) and a label style;
// every language's ::label lines use the same anchors. A right-bound book shows the painting
// mirrored, the mountains on the right, so the river runs the way its pages are read: x comes
// from the other edge and a turn goes the other way. `start` is a label's own start, so the
// spring's label keeps it in Arabic and takes `end` in a label set left to right.
const halo = { color: col('paper'), width: pt(1.8) };
const labelStyles = [
  { id: 'sierra', fontFamily: DISPLAY, fontSize: pt(13), fontWeight: fw(600), color: col('ink'),
    textTransform: CAPS, letterSpacing: track(0.14), halo },
  { id: 'agua', fontFamily: TEXT, fontSize: pt(11), fontWeight: BOLD, fontStyle: SLANT,
    color: { hex: '#0b3a5c', model: 'hex' }, halo, // a name set away draws a leader to its point
    leader: { width: pt(1), endCap: 'dot', capSize: mm(1.6) } },
  { id: 'mar', fontFamily: TEXT, fontSize: pt(12), fontWeight: BOLD, fontStyle: SLANT,
    color: col('paper'), halo: { color: { hex: '#0b3a5c', model: 'hex' }, width: pt(1.8) } },
  { id: 'pueblo', fontFamily: DISPLAY, fontSize: pt(12), fontWeight: fw(600), color: col('ink'),
    halo },
  { id: 'curso', fontFamily: DISPLAY, fontSize: pt(10.5), fontWeight: fw(600), color: col('paper'),
    textTransform: CAPS, letterSpacing: track(0.08), background: col('campo'),
    padding: mm(1.6) },
];
const ANCHORS = [
  { id: 'sierra', x: 0.21, y: 0.055, style: 'sierra' },
  // The spring and the dam: the point is the place, `labelAt` where its name stands.
  { id: 'nacimiento', x: 0.049, y: 0.098, labelAt: { x: 0.075, y: 0.115 }, style: 'agua',
    align: 'start' },
  { id: 'fontalba', x: 0.135, y: 0.255, style: 'pueblo', verticalAlign: 'top' },
  { id: 'embalse', x: 0.293, y: 0.275, labelAt: { x: 0.31, y: 0.155 }, style: 'agua',
    width: 0.12 },
  { id: 'molinar', x: 0.505, y: 0.35, style: 'pueblo', verticalAlign: 'bottom' },
  { id: 'aldamar', x: 0.845, y: 0.505, style: 'pueblo', verticalAlign: 'bottom' },
  { id: 'mar', x: 0.965, y: 0.28, style: 'mar' },
  { id: 'rio', x: 0.61, y: 0.715, style: 'agua', rotate: -3 },
  { id: 'alto', x: 0.17, y: 0.45, style: 'curso' },
  { id: 'medio', x: 0.4, y: 0.77, style: 'curso' },
  { id: 'bajo', x: 0.74, y: 0.865, style: 'curso' },
];
const flip = (x) => Math.round((1 - x) * 1000) / 1000;
const flipped = (a) => ({ ...a, x: flip(a.x), ...(a.labelAt && { labelAt: { ...a.labelAt,
    x: flip(a.labelAt.x) } }),
  ...(a.rotate && { rotate: -a.rotate }), ...(a.align && !AR && { align: 'end' }) });
const anchors = RIGHT_BOUND ? ANCHORS.map(flipped) : ANCHORS;

地图是一幅没有一个字母的绘画。每个地点是图上的一个锚点,用占图宽和图高的比例表示,并带一种标注样式;各版本在这些锚点上写自己的 ::label 行。Penalta Reservoir、Pantà de Penyalta 和 Embalse de Peñalta 站在同一个位置上,更长的名字会在锚点的 width 里换行。右侧装订的书使用同一幅画的镜像(mapa-1900-rtl.jpg),这样河流从右边的山流向左边的海,与页面的阅读方向一致;flipped 把每个锚点连同它的标注所在的位置移到另一侧,并把旋转反过来。“源头”和“佩尼亚尔塔水库”用 labelAt 排在离所指地点稍远的地方,agua 样式的 leader 从名字画一条带圆点的线,分别连到源头和水坝。

#6 · 让目录的每一篇不被拆开

script.js · 第227–246行在完整代码中
const partAt = (x) => (CJK ? at('container', 'left', x) : at('container', START, inward(x)));
const toc = {
  levels: [{ level: 1, fontFamily: DISPLAY, fontSize: pt(15), lineHeight: pt(22),
    fontWeight: fw(500), color: col('ink'), numberFontWeight: fw(600), numberColor: col('agua'),
    numberWidth: mm(9), marginTop: pt(4) }, { level: 2, fontFamily: TEXT, fontSize: pt(11.5),
    lineHeight: pt(18), indent: mm(9), color: col('ink') }],
  pageNumber: { fontFamily: DISPLAY, fontWeight: fw(500), width: mm(9), color: col('agua') },
  leader: { char: CJK ? '…' : '.', gap: mm(1.5) },
  parts: { height: pt(34), marginTop: pt(12), marginBottom: pt(4), design: { elements: [
    { kind: 'box', id: 'band',
      placement: { ...at('container', 'top-left'), size: { width: 'fill', height: 'fill' } },
      style: { backgroundColor: col('paper'), borderRadius: mm(3) } },
    { kind: 'text', id: 'letter', content: '{number}', fontFamily: DISPLAY, fontSize: pt(16),
      fontWeight: fw(700), color: col('paper'), align: 'center',
      box: { backgroundColor: col('agua'), borderRadius: mm(4) },
      placement: { ...partAt(2), size: { width: mm(8), height: mm(8) } } },
    { kind: 'text', id: 'name', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(13),
      fontWeight: fw(600), color: col('agua'), align: START, placement: partAt(14) },
  ] } },
};

:::toc{keep="part" levels="1-2"} 列出各个主题和小节,并让每个篇名行和它的条目待在一起。带 parts.page: false 的 :::part 围栏只是目录里的一行,也是running head的一个分节,不会多出一页扉页。目录是一张模板页:它的模板有一个 takes: "toc" 的框,接收 :::toc 并按目录自己的规则排版,所以篇名行、点状前导符和 keep 都和正文里一样有效,浅色底色则是模板的装饰。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 156 · A children's textbook unit in ten languages ═════
// https://postext.dev/en/cookbook/children-textbook-pages
// Code: MIT · Text: original (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Nunito, Fredoka and three pairs for Arabic, Chinese, Japanese · Needs postext ≥ 1.65.0
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
  loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'zh'; // @lang: the language of the unit (es en ca pt fr de it ar zh ja)
const RECIPE = 'children-textbook-pages';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// One ink and three families (accent, box tint, page ground); a topic swaps the `tema` entries.
const FAMILIES = {
  agua: { main: '#1b6aa0', tint: '#e1f0fa', ground: '#d3e8f6' },
  campo: { main: '#336f27', tint: '#e5f1dc', ground: '#d9ebcb' },
  sol: { main: '#9a5209', tint: '#fcefd2', ground: '#f8e6b8' },
};
const palette = { ink: '#1d2f3f', muted: '#4f6272', rule: '#7e98ab', paper: '#ffffff',
  agua: FAMILIES.agua.main, campo: FAMILIES.campo.main, // the blue of the folios and the contents
  tema: FAMILIES.agua.main, 'tema-tint': FAMILIES.agua.tint, 'tema-ground': FAMILIES.agua.ground };
const swap = (f) => `tema=${FAMILIES[f].main}, tema-tint=${FAMILIES[f].tint}, `
  + `tema-ground=${FAMILIES[f].ground}`;
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: 'water (defaults)', value: { hex: palette.agua, model: 'hex' } },
];

// #region editions: how each language runs and is bound, and the two faces of its script
// Arabic runs right to left, Chinese and Japanese down the page, all bound on the right. Frames
// stand in the flow (x along the lines, mirrored in Arabic, down the page when vertical).
const AR = LANG === 'ar', CJK = LANG === 'zh' || LANG === 'ja';
const RIGHT_BOUND = AR || CJK, LATIN = !RIGHT_BOUND; // italics, capitals, tracking, hyphens
const [TEXT, DISPLAY] = { ar: ['Noto Naskh Arabic', 'Baloo Bhaijaan 2'], ja: ['Klee One',
  'Zen Maru Gothic'], zh: ['Noto Serif SC', 'ZCOOL KuaiLe'] }[LANG] ?? ['Nunito', 'Fredoka'];
const START = RIGHT_BOUND ? 'right' : 'left'; // the side a page starts reading from
const corner = (v) => `${v}-${START}`, inward = (x) => (RIGHT_BOUND ? -x : x);
const [SLANT, CAPS] = LATIN ? ['italic', 'uppercase'] : ['normal', 'none'];
const LEAD = AR ? 20 : CJK ? 21 : 17.5, track = (v) => (LATIN ? v : 0); // Naskh, ruby need room
const fw = (w) => ({ 'ZCOOL KuaiLe': 400, 'Zen Maru Gothic': w > 550 ? 700 : 500 })[DISPLAY] ?? w;
const BOLD = TEXT === 'Klee One' ? 600 : 700; // and the weights the faces have
// #endregion

const PAGE = { w: 210, h: 280, top: 18, bottom: 18, inner: 14, outer: 12 }; // mm, mirrored
const HALF = PAGE.w - PAGE.inner - PAGE.outer, TALL = PAGE.h - PAGE.top - PAGE.bottom; // 184, 244

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

变化

#再加一个色系

一个讲海的主题,就是 FAMILIES 里的第四项,再加一个用 topic('tema-mar', 'mar', { frames }) 做的模板。swap('mar') 写出它的调色板,框和底色随之变化。

-  sol: { main: '#9a5209', tint: '#fcefd2', ground: '#f8e6b8' },
+  sol: { main: '#9a5209', tint: '#fcefd2', ground: '#f8e6b8' },
+  mar: { main: '#0f5a6b', tint: '#dcf0f2', ground: '#cbe6ea' },

#让文字保持原来的字号

不能缩小文字的框写 fit: { shrinkText: false }。这样较长的文字会更用力地推周围的框,阶梯也会更早轮到图片。

   frames: [title, { name: 'texto', flow: true, columns: 2, columnGap: mm(CJK ? 16 : 7), // 段
-    width: mm(MEASURE), fit: { minScale: 0.9 } }],
+    width: mm(MEASURE), fit: { shrinkText: false } }],

常见问题

  • 画进图里的名字无法随语言改变:地图上没有任何文字,每个地名都是一个标注。
  • 主题的调色板只改 tema 条目。页码圆标和目录用的是 agua,它的蓝色相同,所以在绿色和沙色页面上仍是蓝色;把它们链接到 tema,就会跟着主题走。
  • 阿拉伯-印度数字紧挨着中点时会读成两个数字:١ · ماء 看起来像 ٠١ ماء,因为阿拉伯语的零是一个点。阿拉伯语版写成 ١- ماء للحقول,单元编号则用文字写出。
  • 装饰元素位于纸面上,不在文字流里:放在框 top-left 位置的徽标,在阿拉伯语版里仍在左边。corner('top') 和 inward(x) 从页面开始阅读的那一侧定位它。
  • 在网格里,每一项都是一个单独的围栏:框里的图只有把它的 :::figure 写在该框的 :::frame 里面,才属于这一组。写在后面的图会成为单独的一项,占一个自己的格子。
  • 两处图框使用同一个资源时,两处都取第一处写的文字:目录页上的小地图是同一个文件,用另一个资源 rio,不带锚点。

致谢

文本
  • Our river, a children's textbook unit written for this recipe in Spanish and set in ten languages · Postext Cookbook · CC BY 4.0
图片
  • The valley of the River Aldara, painted from the mountains to the sea, with two children watching the water. · Generated With Diffusion Models · 原创
  • The painted map of the valley, from the spring to the port, with no lettering: the names are labels set from the Markdown. · Generated With Diffusion Models · 原创
  • The same painted map mirrored, the mountains on the right, for the books bound on the right (Arabic, Chinese, Japanese). · Generated With Diffusion Models · 原创
  • A spring between mossy rocks. · Generated With Diffusion Models · 原创
  • A mountain stream over round stones. · Generated With Diffusion Models · 原创
  • A small waterfall into a green pool. · Generated With Diffusion Models · 原创
  • A farmer opening the gate of an irrigation canal. · Generated With Diffusion Models · 原创
  • An old stone watermill with its wheel. · Generated With Diffusion Models · 原创
  • Children paddling canoes on a calm river. · Generated With Diffusion Models · 原创
  • Children and a teacher picking up litter on a river bank. · Generated With Diffusion Models · 原创
字体
Nunito (SIL OFL 1.1) · Fredoka (SIL OFL 1.1) · Noto Naskh Arabic (SIL OFL 1.1) · Baloo Bhaijaan 2 (SIL OFL 1.1) · Klee One (SIL OFL 1.1) · Zen Maru Gothic (SIL OFL 1.1) · Noto Serif SC (SIL OFL 1.1) · ZCOOL KuaiLe (SIL OFL 1.1)
沙盒PDF