简单来说
一本英语识字课本里讲字母M的三页。单词的每个音放在按元音上色的小标签里,格子里的每个词都配一幅小图。
成品一览
Letter by Letter第12课。这是一本虚构的英语自然拼读课本,三页讲m这个音。开篇用190 pt的DynaPuff排出Mm,放在奶油色色带上,旁边是两样英语名称以m开头的东西:猴子(monkey)和月亮(moon)。每个单词拆成一个个音,每个音是一个行内标签,颜色取自单词里的元音:a红、e橙、i青、o蓝、u紫。m是实心的,其余的音是空心的,孩子能看出本课的音落在map和gum的什么位置。第38页把六个看图单词排成圆角表格,每格一幅水彩画,下面是三行描红。这些水彩画由扩散模型生成;色带、图标和描红行用代码绘制。第39页有四个24 pt的句子、一个涂色单词框和一段给家长的提示。
西班牙语版是另一课,不是译文:Letra a letra第7课,讲的是同一个字母。西班牙语按开音节(ma、me、mi、mo、mu)教阅读,所以那一课的标签里装的是音节,如{mi·mo·sa}。这些音节在英语里不成词,英语课本又是一个音一个音地教,所以英语这一课把短单词的音拼起来,如{m·a·p},并按押韵的词族(-at、-an、-ug、-op)归组。两课出自同一份代码:同样的标签样式、同一个syllables()函数、同样的表格、描红行和框。
这道食谱解答
- 怎样做行内标签:键盘按键、标签、练习用的词库?
- 怎样在表格单元格里放图片或图标?
- 空行不起作用时,怎样在两个块之间加额外的垂直间距?
- 怎样做练习页:填空横线、答题框、词库、清单?
简短回答
// A word's syllables are chips with nothing between them, so their boxes touch and the white
// border draws the seam. Across a word space a chip keeps at least `gap`: 0.5 em sets the
// words of a 24 pt row 4.2 mm apart, where the space alone leaves 2.3 mm. Inside a sentence
// the '-frase' twins keep no gap, so the word space alone parts a chip from the word before.
// A 24 pt chip, padding and border included, is 10.4 mm tall (gotcha: chip-overlap).
const syllable = { fontFamily: TEXT, bold: true, borderWidth: pt(1), borderColor: col('paper'),
paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
const chipStyles = [
...'aeiou'.split('').flatMap((v) => [ // one pair per vowel
{ ...syllable, id: v, background: col(v), color: col('paper') }, // a syllable with m
{ ...syllable, id: `${v}-borde`, background: col('paper'), color: col(v), borderColor: col(v) },
]).flatMap((style) => [style, { ...style, id: `${style.id}-frase`, gap: em(0) }]),
{ ...syllable, id: 'pinta', bold: false, background: col('paper'), color: col('ink'),
borderColor: col('ink'), borderWidth: pt(0.8) }, // an outline for the child to colour in
];
const vowel = (s) => s.normalize('NFD').toLowerCase().match(/[aeiou]/)[0]; // 'mú' → 'u'
const chipOf = (s, v, end) => `:chip[${s}]{style="${v}${/m/i.test(s) ? '' : '-borde'}${end}"}`;
// {mi·mo·sa} → :chip[mi]{style="i"}:chip[mo]{style="o"}:chip[sa]{style="a-borde"}, and a word
// written after another word, as in 'me {mi·ma}.', takes the '-frase' twins. A piece with no
// vowel, the m and the p of the English {m·a·p}, takes the vowel of its word.
const syllables = (text) => text.replace(/(\p{L} )?\{([\p{L}·]+)\}/gu, (_, before = '', word) =>
before + word.split('·').map((s) => chipOf(s, vowel(s + word), before && '-frase')).join(''));
用料
- 功能
- 行内标签表格单元格中的图片设计过的章首页标题属性标题样式页面设计中的图片页面设计中的文字、线条和框锚定设计元素书眉与页码命名表格样式段落样式显式竖向间距标注框语义调色板作为资源的图和表自定义资源类型图就放在这里在Canvas上绘制页面
- 类型
- Andika, DynaPuff, Playpen Sans(SIL OFL 1.1)
- 素材
man-640.jpgmano-640.jpgmanzana-480.jpgmapa-640.jpgmariposa-660.jpgmat-640.jpgmesa-640.jpgmimosa-640.jpgmono-640.jpgmoon-480.jpgmop-640.jpgmud-640.jpgmug-640.jpgmuneca-640.jpg- A watercolour of the butterfly on the opener (Generated With Diffusion Models, 原创)
- A watercolour of the apple on the opener (Generated With Diffusion Models, 原创)
- A watercolour of the hand in the picture grid (Generated With Diffusion Models, 原创)
- A watercolour of the map in the picture grid of both units (Generated With Diffusion Models, 原创)
- A watercolour of the table in the picture grid (Generated With Diffusion Models, 原创)
- A watercolour of the mimosa sprig in the picture grid (Generated With Diffusion Models, 原创)
- A watercolour of the monkey: in the picture grid of the Spanish unit and on the opener of the English one (Generated With Diffusion Models, 原创)
- A watercolour of the doll in the picture grid (Generated With Diffusion Models, 原创)
- A watercolour of the moon on the opener of the English unit (Generated With Diffusion Models, 原创)
- A watercolour of the mat in the picture grid of the English unit (Generated With Diffusion Models, 原创)
- A watercolour of the man in the picture grid of the English unit (Generated With Diffusion Models, 原创)
- A watercolour of the mug in the picture grid of the English unit (Generated With Diffusion Models, 原创)
- A watercolour of the mop in the picture grid of the English unit (Generated With Diffusion Models, 原创)
- A watercolour of the mud in the picture grid of the English unit (Generated With Diffusion Models, 原创)
- The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette (Ignacio Ferro, MIT)
做法
#1 · 每个元音一种标签样式,再用一个函数写出标签
简短回答展开同一个syllable对象,得到21种标签样式:m这个音每个元音一种实心样式,其余的音每个元音一种空心样式,这十种各有一个-frase孪生样式,再加上pinta,即供孩子涂色的墨线空心样式。syllables()把{m·a·p}变成三个紧挨着的:chip[…],中间什么也没有,于是一个单词的各个音首尾相接,由白色边框画出接缝。标签的颜色取自其中的元音;不含元音的那一段,比如这里的m和p,取所在单词的元音,所以map从头到尾都是红色。隔着词间空格时,标签至少保留自己的gap;0.5 em让24 pt一行里的单词相隔4.2 mm,只靠空格则只有2.3 mm。在句子里,这个间隙会让新词前的空白差不多翻倍,所以跟在另一个单词后面的词使用-frase孪生样式,它的gap为0,2.3 mm的空格保持原样。西班牙语版里每一段是一个音节,如{mi·mo·sa},各有自己的元音。
#2 · 给标签留足行距
// A 24 pt chip is 10.4 mm tall: at 30 pt (10.6 mm) leading the chips of two sentences would
// stand 0.1 mm apart, so every line the child reads has 45 pt, and the syllables 60 pt.
paragraphStyles: [
{ id: 'consigna', fontFamily: LABEL, fontSize: pt(10), lineHeight: pt(GRID),
color: col('muted') }, // the instruction under each activity
{ id: 'fila', fontSize: pt(34), lineHeight: pt(4 * GRID), textAlign: 'center' },
{ id: 'palabras', fontSize: pt(24), lineHeight: pt(3 * GRID), textAlign: 'center' },
{ id: 'lectura', fontSize: pt(24), lineHeight: pt(3 * GRID) },
{ id: 'colofon', fontSize: pt(7.5), lineHeight: pt(10), // Andika: Playpen has no italic
color: col('muted'), marginTop: pt(GRID) },
],
标签的上下内边距和边框画在所在行之外,不增加行距,所以比行高还高的标签会撞上下一行的标签。24 pt的标签高10.4 mm;行距30 pt(10.6 mm)时,两句话的标签只会相隔0.1 mm。孩子读的句子行距设为45 pt,第一个活动的34 pt单词行设为60 pt,分别是说明文字15 pt网格的三行和四行。
#3 · 每个格子一幅图
const PICTURE_WORDS = t({ en: ['m·a·p', 'm·a·t', 'm·a·n', 'm·u·g', 'm·o·p', 'm·u·d'],
es: ['ma·no', 'ma·pa', 'me·sa', 'mi·mo·sa', 'mo·no', 'mu·ñe·ca'] });
const tableStyles = [{ id: 'dibujos', borderRadius: mm(5), // the frame and its fills, rounded
headerBackgroundEnabled: false, // a header row added later would print grey (#f0f0f0)
bodyBackgroundEnabled: true, bodyBackground: col('cream'), // cream tiles…
rules: 'grid', borderColor: col('paper'), borderWidth: pt(4), // …parted by white rules
bodyFontSize: pt(20), cellPadding: mm(3) }]; // the words' chips are 20 pt
const cells = (row) => PICTURE_WORDS.slice(row * 3, row * 3 + 3)
.map((word) => ({ content: syllables(`{${word}}`), align: 'center' }));
let grid = { columnWidths: [1, 1, 1], rows: [cells(0), cells(1)] };
PICTURE_WORDS.forEach((word, k) => { // the picture above the word, 0.72 of the cell's width
const resourceId = word.replaceAll('·', '').replace('ñ', 'n');
grid = setCellImage(grid, { row: Math.floor(k / 3), col: k % 3 }, { resourceId, width: 0.72 });
});
setCellImage把一幅图放在格子文字的上方,宽度取格子内宽的一个比例,这里是0.72(36.5 mm),行高随之增加。每幅图都是画在白底上的JPEG,与格子的奶油色正片叠底,所以贴在格子上不露边框。每幅图下面是用音素标签写出的单词。表格单元格和普通段落一样接受标签标记。dibujos表格样式把外框及其填充做成5 mm圆角,并用4 pt白线隔开奶油色格子。
#4 · 框前空一行
calloutStyles: [
{ id: 'colorea', background: col('cream'), borderRadius: mm(4),
marginTop: pt(0), // the :::space before the box is the whole gap above it
padding: { top: mm(4), right: mm(5), bottom: mm(5), left: mm(5) },
titleStyle: { fontFamily: LABEL, fontSize: pt(15), fontWeight: 700, color: col('ink') },
body: { fontFamily: LABEL, fontSize: pt(10), lineHeight: pt(GRID), color: col('muted') } },
{ id: 'familia', backgroundEnabled: false,
stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('rule') },
padding: { top: mm(3), right: mm(0), bottom: mm(0), left: mm(0) },
titleStyle: { fontFamily: LABEL, fontSize: pt(8.5), fontWeight: 700, color: col('ink'),
...tag },
body: { fontSize: pt(10.5), lineHeight: pt(GRID) } },
],
Markdown在最后一句和涂色框之间放了:::space{lines=1},即一行15 pt(5.3 mm)。框的marginTop为0,所以这一行就是全部间距;没有它,框会紧接最后一句所在行的末尾开始。位于框开头的:::space会被丢弃,所以框先排提示行和颜色图例的标签,框内自己的:::space放在它们之后,隔开图例和涂色任务。
#5 · 字母的开篇
const THINGS = t({ en: ['monkey', 'moon'], es: ['mariposa', 'manzana'] }); // ids and labels
const BAND = 104; // mm: the depth of the band's drawing; its wave dips to 101.9 mm
// The opener reserves seventeen grid lines, the first grid line past the foot of the band's
// image, so the first activity title stands on the grid like the others: two lines under
// the band, its instruction right under it.
const opener = { enabled: true, minHeight: pt(17 * GRID),
slot: { elements: [
picture('band', 'banda', at(0, 0, { width: mm(210), height: mm(BAND) })),
words('unit', '{attr.unit}', LABEL, 9, 700, 'paper', at(SIDE, 12.5), { ...tag,
box: { backgroundColor: col('ink'), borderRadius: mm(3),
padding: { top: mm(1.2), right: mm(2.8), bottom: mm(1.2), left: mm(2.8) } } }),
words('kicker', '{attr.kicker}', LABEL, 8.5, 600, 'muted', // level with the pill's text
{ anchor: { to: '#unit', edge: 'right-of' }, offset: { x: mm(4), y: mm(1.4) } }, tag),
words('letter', '{titleText}', DISPLAY, 190, 700, 'ink', at(SIDE - 3, 19), { lineHeight: 1 }),
words('name', '{attr.name}', LABEL, 20, 600, 'ink', at(SIDE + 1, 76)),
picture('first', THINGS[0], at(146, 12, { width: mm(40) })),
picture('second', THINGS[1], at(151, 53, { width: mm(30) })),
...[45.5, 84.5].map((y, k) => words(THINGS[k], THINGS[k], LABEL, 10, 600, 'muted',
at(146, y, { width: mm(40) }), { align: 'center' })), // its name under each picture
] } };
Mm是标题的文字({titleText});课号、系列名和字母下方的名称写成同一标题行上的属性。色带、猴子和月亮都是图片。色带高104 mm,开篇一直预留到它底边下方的第一条网格线,所以第一个活动标题从118.5 mm开始,落在网格上,比波浪的最低点(101.9 mm)低16.6 mm。
#6 · 活动标题旁的图标
const ICON = 9; // mm
const H2 = { level: 2, marginBottom: pt(0), // two grid lines per title, and two above it
lineHeight: pt(2 * GRID), marginTop: pt(2 * GRID) };
const activity = (id, icon) => ({ id, advancedDesign: { enabled: true, slot: { elements: [
picture('icon', icon, { anchor: { to: 'container', edge: 'top-left' },
size: { width: mm(ICON), height: mm(ICON) } }),
words('title', '{titleText}', LABEL, 15, 700, 'ink', { anchor: { to: '#icon',
edge: 'right-of' }, offset: { x: mm(3) }, size: { width: mm(140), height: mm(ICON) } },
{ verticalAlign: 'middle' }), // centred on the icon
] } } });
每个活动标题都写明自己的标题样式,如## Read the sentences {style="lee"},该样式画出一个图标,标题在旁边居中。这些标题仍是二级标题,所以由H2级别控制间距:标题的lineHeight占两个网格行,上方的marginTop再占两个。
完整食谱
// ═══ Postext Cookbook · Nº 060 · Early reader with syllable chips ════════════════
// https://postext.dev/en/cookbook/reading-primer-syllables
// Code: MIT · Text: original (CC BY 4.0) · Pictures: diffusion models · Icons: drawn in code
// Fonts: Andika, DynaPuff, Playpen Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage, setCellImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'reading-primer-syllables';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#242832', paper: '#ffffff', muted: '#5f6470', // text; instructions
cream: '#f6f0e3', rule: '#d3c9b6', // the band, the tiles and the pictures' ground; guides
// The vowel code: a syllable takes its vowel's colour. White on these fills measures
// 3.2–4.9:1, above WCAG's 3:1 for large text: the vowel chips are bold, 20 pt or more.
a: '#d9482b', e: '#dd740c', i: '#1f9a8f', o: '#3f6fd8', u: '#9152cf' };
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults are linked to 'main-color': point it at the ink.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ink })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Andika', 'DynaPuff', 'Playpen Sans']; // Andika: one-storey a
const [TOP, SIDE, GRID] = [18, 20, 15]; // mm, mm, pt: every activity starts on the 15 pt grid
// #region answer: one chip style per vowel, and {ma·má} in the text written out as chips
// A word's syllables are chips with nothing between them, so their boxes touch and the white
// border draws the seam. Across a word space a chip keeps at least `gap`: 0.5 em sets the
// words of a 24 pt row 4.2 mm apart, where the space alone leaves 2.3 mm. Inside a sentence
// the '-frase' twins keep no gap, so the word space alone parts a chip from the word before.
// A 24 pt chip, padding and border included, is 10.4 mm tall (gotcha: chip-overlap).
const syllable = { fontFamily: TEXT, bold: true, borderWidth: pt(1), borderColor: col('paper'),
paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
const chipStyles = [
...'aeiou'.split('').flatMap((v) => [ // one pair per vowel
{ ...syllable, id: v, background: col(v), color: col('paper') }, // a syllable with m
{ ...syllable, id: `${v}-borde`, background: col('paper'), color: col(v), borderColor: col(v) },
]).flatMap((style) => [style, { ...style, id: `${style.id}-frase`, gap: em(0) }]),
{ ...syllable, id: 'pinta', bold: false, background: col('paper'), color: col('ink'),
borderColor: col('ink'), borderWidth: pt(0.8) }, // an outline for the child to colour in
];
const vowel = (s) => s.normalize('NFD').toLowerCase().match(/[aeiou]/)[0]; // 'mú' → 'u'
const chipOf = (s, v, end) => `:chip[${s}]{style="${v}${/m/i.test(s) ? '' : '-borde'}${end}"}`;
// {mi·mo·sa} → :chip[mi]{style="i"}:chip[mo]{style="o"}:chip[sa]{style="a-borde"}, and a word
// written after another word, as in 'me {mi·ma}.', takes the '-frase' twins. A piece with no
// vowel, the m and the p of the English {m·a·p}, takes the vowel of its word.
const syllables = (text) => text.replace(/(\p{L} )?\{([\p{L}·]+)\}/gu, (_, before = '', word) =>
before + word.split('·').map((s) => chipOf(s, vowel(s + word), before && '-frase')).join(''));
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#把标签改成胶囊形
大于标签一半高度的圆角半径会被限制为一半高度,所以设一个大值就能画出圆头。单字母标签几乎成了圆形,单词内部的接缝变成凹口。
- paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
+ paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5), borderRadius: em(1) };常见问题
易错点
:::space在框顶或栏顶会被丢掉
在栏顶、:::columns组顶部、还有其他内容的无标题框的顶部,以及被拆分的框的接续部分顶部,:::space会被丢掉。从postext 1.5起,只由:::space组成的框高度等于所要求的空白(答题框、填写用的空间),紧接在框标题下面的空白会让框内正文相应地往下开始。要让无标题框以空白开头,给它一个标题或一行首行,再在后面加空白。 显式竖向间距 →
致谢
- 文本
- 原创文字, CC BY 4.0
- 图片
- A watercolour of the butterfly on the opener · Generated With Diffusion Models · 原创
- A watercolour of the apple on the opener · Generated With Diffusion Models · 原创
- A watercolour of the hand in the picture grid · Generated With Diffusion Models · 原创
- A watercolour of the map in the picture grid of both units · Generated With Diffusion Models · 原创
- A watercolour of the table in the picture grid · Generated With Diffusion Models · 原创
- A watercolour of the mimosa sprig in the picture grid · Generated With Diffusion Models · 原创
- A watercolour of the monkey: in the picture grid of the Spanish unit and on the opener of the English one · Generated With Diffusion Models · 原创
- A watercolour of the doll in the picture grid · Generated With Diffusion Models · 原创
- A watercolour of the moon on the opener of the English unit · Generated With Diffusion Models · 原创
- A watercolour of the mat in the picture grid of the English unit · Generated With Diffusion Models · 原创
- A watercolour of the man in the picture grid of the English unit · Generated With Diffusion Models · 原创
- A watercolour of the mug in the picture grid of the English unit · Generated With Diffusion Models · 原创
- A watercolour of the mop in the picture grid of the English unit · Generated With Diffusion Models · 原创
- A watercolour of the mud in the picture grid of the English unit · Generated With Diffusion Models · 原创
- The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette · Ignacio Ferro · MIT
- 字体
- Andika (SIL OFL 1.1) · DynaPuff (SIL OFL 1.1) · Playpen Sans (SIL OFL 1.1)


