Skip to main content
Recipe number 60

Cookbook · Chapter 2 · Type & text

Early reader with syllable chips

A primer unit on the letter M: the sounds of each word as chips in the colour of its vowel, and a grid of picture words with a watercolour in each cell.

p. 37 · 1 of 3

  • Trim 210 × 260 mm
  • 1 column
  • Andika 11/15
  • DynaPuff
  • Playpen Sans
  • 3 pages
  • Level
  • Postext 1.57.1
  • Laid out in 52 ms
  • 180 lines of code

In short

Three pages of a reading book for young children, on the letter M. Each sound of a word sits in a small coloured label, and each word in a grid has its own picture.

What you'll build

Unit 12 of Letter by Letter, an invented English phonics primer: three pages on the sound m. The opener sets a 190 pt DynaPuff Mm on a cream band beside two things whose names start with m, a monkey and a moon. Each word is split into its sounds, and every sound is a chip in the colour of the word's vowel: red a, orange e, teal i, blue o, purple u. The m is filled and the other sounds are outlined, so a child sees where this unit's sound falls in map and in gum. Page 38 sets six picture words in a rounded grid, a watercolour in each cell, then three rows to trace. The watercolours were generated with diffusion models; the band, the icons and the tracing rows are drawn in code. Page 39 has four sentences at 24 pt, a box of words to colour in and a note for parents and carers.

The Spanish edition is another unit, not a translation: unit 7 of Letra a letra, on the same letter. Spanish is taught by open syllables (ma, me, mi, mo, mu), so its chips hold syllables, {mi·mo·sa}. Those syllables are not English words, and English primers work sound by sound, so the English unit blends the sounds of short words, {m·a·p}, and groups them in rhyming families (-at, -an, -ug, -op). Both units come out of the same pen: the same chip styles, the same syllables() function, the same grid, tracing rows and boxes.

This recipe answers

  • How do I make inline chips: keyboard keys, tags, word banks for exercises?
  • How do I put pictures or icons inside table cells?
  • How do I add extra vertical space between two blocks, when blank lines do nothing?
  • How do I build a worksheet page: fill-in lines, answer boxes, word banks, checklists?

The short answer

script.js · lines 27–48in full code
// 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(''));

One chip style per vowel, and {ma·má} in the text written out as chips

Ingredients

Type
Andika, DynaPuff, Playpen Sans (SIL OFL 1.1)
Assets
  • man-640.jpg
  • mano-640.jpg
  • manzana-480.jpg
  • mapa-640.jpg
  • mariposa-660.jpg
  • mat-640.jpg
  • mesa-640.jpg
  • mimosa-640.jpg
  • mono-640.jpg
  • moon-480.jpg
  • mop-640.jpg
  • mud-640.jpg
  • mug-640.jpg
  • muneca-640.jpg
  • A watercolour of the butterfly on the opener (Generated With Diffusion Models, original)
  • A watercolour of the apple on the opener (Generated With Diffusion Models, original)
  • A watercolour of the hand in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the map in the picture grid of both units (Generated With Diffusion Models, original)
  • A watercolour of the table in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the mimosa sprig in the picture grid (Generated With Diffusion Models, original)
  • 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, original)
  • A watercolour of the doll in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the moon on the opener of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mat in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the man in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mug in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mop in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mud in the picture grid of the English unit (Generated With Diffusion Models, original)
  • The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette (Ignacio Ferro, MIT)

Method

#1 · A chip style per vowel and a function that writes the chips

The short answer builds 21 chip styles by spreading one syllable object. There is a filled style per vowel for the m, an outlined one per vowel for the other sounds, a -frase twin of each of those ten, and pinta, the ink outline a child colours in. syllables() turns {m·a·p} into three :chip[…] with nothing between them, so the sounds of a word touch and the white border draws the seam. A chip takes the colour of its vowel, and a piece with no vowel, the m and the p here, takes the vowel of its word, so map is red from end to end. Across a word space a chip keeps at least its gap, and 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 that gap would nearly double the space before the new word, so a word that follows another word gets the -frase twins, whose gap of 0 leaves the 2.3 mm space as it is. In the Spanish edition the pieces are syllables, {mi·mo·sa}, and each has a vowel of its own.

#2 · Leading that clears the chips

script.js · lines 144–154in full code
  // 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) },
  ],

A chip's vertical padding and border paint outside its line and add no leading, so a chip taller than the line pitch runs into the chips of the line below. A 24 pt chip is 10.4 mm tall; at 30 pt leading (10.6 mm), the chips of two sentences would stand 0.1 mm apart. The lines a child reads get 45 pt and the 34 pt rows of the first activity 60 pt, three and four lines of the instructions' 15 pt grid.

#3 · A picture in every cell

script.js · lines 96–109in full code
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 sets a picture above a cell's text at a fraction of the cell's inner width, 0.72 here (36.5 mm), and the row grows to hold it. Each picture is a JPEG painted on white and multiplied by the tiles' cream, so it sits on the tile without a box. Under each picture is the word in sound chips. A table cell takes chip markup like any paragraph. The dibujos table style rounds the frame and its fills at 5 mm and parts the cream tiles with 4 pt white rules.

#4 · One line of space before the box

script.js · lines 157–169in full code
  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) } },
  ],

The Markdown puts :::space{lines=1} between the last sentence and the colouring box, one 15 pt line (5.3 mm). The box's marginTop is 0, so that line is the whole gap; without it the box would start where the last sentence's line ends. A :::space that opens a box is dropped, so the box starts with its prompt line and the chips of the colour key, and its own :::space comes after them, between the key and the colouring task.

#5 · The letter's opener

script.js · lines 60–79in full code
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
  ] } };

The Mm is the heading's text ({titleText}); the unit number, the series and the name under the letter are attributes on the same heading line. The band, the monkey and the moon are images. The band is 104 mm deep, and the opener reserves the page down to the first grid line under its foot, so the first activity title starts at 118.5 mm, on the grid and 16.6 mm below the lowest point of the wave (101.9 mm).

#6 · Icons beside the activity titles

script.js · lines 83–92in full code
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
] } } });

Each activity title names its heading style, as in ## Read the sentences {style="lee"}, and the style draws an icon with the title centred beside it. The titles are still level-2 headings, so the H2 level spaces them: two grid lines of lineHeight for the title and two more of marginTop above it.

The whole recipe

Sandbox
// ═══ 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(''));

The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)

Variations

#Round the chips into pills

A radius over half the chip's height is clamped to that half, so a large value draws round ends. A one-letter chip comes out nearly a circle, and the seams inside a word become notches.

-  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) };

Pitfalls

Pitfall

Chips taller than the line pitch touch the next line

A chip whose box is taller than the line pitch touches the chips on the next line (the chipOverlap warning). Reduce its vertical padding, border or size, or open the leading. Inline chips →

Pitfall

:::space is dropped at the top of a box or column

:::space is dropped at the top of a column, of a :::columns group, of an untitled box that has other content and of the continuation of a split box. Since postext 1.5 a box made only of :::space is as tall as the space asks (an answer box, room to write), and space right under a box's title opens the body that much lower. To open an untitled box with space, give it a title or a first line and add the space after it. Explicit vertical space →

Sandbox check · chipOverlap

Chips touch the next line

Why. A chip style's box is taller than the line pitch, so chips on consecutive lines touch.

Fix. Reduce the chip's vertical padding, outline or size, or increase the leading. Docs →

Credits

Text
Original prose, CC BY 4.0
Images
  • A watercolour of the butterfly on the opener · Generated With Diffusion Models · original
  • A watercolour of the apple on the opener · Generated With Diffusion Models · original
  • A watercolour of the hand in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the map in the picture grid of both units · Generated With Diffusion Models · original
  • A watercolour of the table in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the mimosa sprig in the picture grid · Generated With Diffusion Models · original
  • 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 · original
  • A watercolour of the doll in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the moon on the opener of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mat in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the man in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mug in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mop in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mud in the picture grid of the English unit · Generated With Diffusion Models · original
  • The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette · Ignacio Ferro · MIT
Fonts
Andika (SIL OFL 1.1) · DynaPuff (SIL OFL 1.1) · Playpen Sans (SIL OFL 1.1)
Sandbox