In short
A school textbook unit about a river, nine pages long. Each topic is a double page on a coloured ground with a title tab, text, pictures and boxes. The map has no word painted on it: its names come from the text.
What you'll build
Nine pages of Our river, unit 4 of an invented Year 3 social science book, on a 210 × 280 mm page, in ten languages: Spanish, Catalan, English, Portuguese, French, German, Italian, Arabic, Chinese and Japanese. A painted valley opens the unit, a contents page lists two parts, and three topics follow as double pages, each on its own ground: water blue, field green, sun sand. Every topic has a tab with its number and title, text in two columns and boxes with tabs that grow with their text. The second topic is one painted map across both pages, with the river, the villages and the three courses named on it from the Markdown, and a line from each course box to its stretch of the river. What repeats is drawn once: the template lays one picture card, one course box and one box with a picture as many times as the Markdown asks, and the three questions before the unit are three uses of one module. The texts differ in length by a fifth or more and settle in the same templates: a box takes the height its words need and pushes the next one down, and the map is set a little smaller before any text is. The Arabic book runs right to left and the Chinese and Japanese books run down the page; all three are bound on the right and read from the right page of each spread to the left one.
This recipe answers
- How do I set a textbook unit in three languages from the same page templates, when each language's text has a different length?
- How do I make the boxes of a page grow with their text and push the boxes below them down?
- How do I put the names on a map from the text, so a translation changes the words and not the drawing?
The short answer
// 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) }];
One base template and a family of topics that extend it
Ingredients
- Features
- Composed pagesGrids that repeat a frame setModules stacked in a pageLeaders and legends on figuresFrames that grow in a groupNumbered box tabsLabels on a pictureTable of contentsSpread templatesCallout boxesText, rules and boxes in page designsPictures in page designsAnchoring design elementsDecoration anchored to framesMirrored marginsRunning heads and foliosHeading stylesSemantic colour paletteFigures and tables as resources
- Also uses
- Frames that push text, by box or contourHeading attributesPart divider pagesPDF exportFonts embedded in the PDFCustom resource typesUnnumbered chapters
- Type
- Nunito, Fredoka, Noto Naskh Arabic, Baloo Bhaijaan 2, Klee One, Zen Maru Gothic, Noto Serif SC, ZCOOL KuaiLe (SIL OFL 1.1)
- Assets
arroyo-720.jpgcascada-720.jpglimpieza-720.jpgmapa-1900-rtl.jpgmapa-1900.jpgmolino-720.jpgnacimiento-720.jpgpiraguas-720.jpgportada-1400.jpgriego-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, original)
- 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, original)
- The same painted map mirrored, the mountains on the right, for the books bound on the right (Arabic, Chinese, Japanese). (Generated With Diffusion Models, original)
- A spring between mossy rocks. (Generated With Diffusion Models, original)
- A mountain stream over round stones. (Generated With Diffusion Models, original)
- A small waterfall into a green pool. (Generated With Diffusion Models, original)
- A farmer opening the gate of an irrigation canal. (Generated With Diffusion Models, original)
- An old stone watermill with its wheel. (Generated With Diffusion Models, original)
- Children paddling canoes on a calm river. (Generated With Diffusion Models, original)
- Children and a teacher picking up litter on a river bank. (Generated With Diffusion Models, original)
Method
#1 · Know which side each language starts from
// 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
A template's frames stand in the page's flow frame, where x runs along the lines. With locale: 'ar' the engine mirrors that frame, so the Arabic book uses the Latin frames unchanged: the title comes first on the right page, the three photographs and the three course boxes run from right to left, and the boxes' tabs, stripes and paddings follow the lines. With layout.writingMode: 'vertical-rl' x runs down the page and y from right to left: a frame's width is a length down the page, a stack moves leftward, columns: 2 gives two tiers (段) of 27 characters, and a frame set below another stands to its left. Decoration (the grounds, the title tab, the number, the running heads and the folios) stands on the sheet itself, so it is placed from START, the side a page starts reading from. Each script has a text face and a rounded display face, and the Arabic, Chinese and Japanese editions have no italics, capitals or tracking.
#2 · Build the boxes with extends
// 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') } },
];
A box style is made in three steps. caja holds the shape, the type and the geometry of the tab; caja-tema puts the topic's colour on the tab and the bullets; dato, palabras and actividad set the kind: a tinted box, an outlined one or one with a stripe. Their colours are palette entries (tema, tema-tint), so each style is written once and a topic's template tints it.
#3 · Let every topic extend one base template
// 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) }];
The base is a spread: a ground to the bleed, a title tab with its number, and a text in two columns. A topic extends it (extends: 'tema'), sets its palette (the three tema entries take the family's colours, and the ground, the tab, the number and every box change together) and adds its own frames. The tab and the number are decoration anchored to the title frame, so the tab is as tall as the title the language needs. The number is {headingNumber}, the counter of the heading the frame took, painted over the frame's padding before its words: no page fence repeats it, and a click on it reaches the number, not the frame.
#4 · Draw once what repeats
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) }] };
A grid group repeats a set of frames once for every item of the page. The strip of pictures is grid('fotos', ['foto'], 3, …): three :::figure{slot="foto"} blocks give three cards, named #foto[1] to #foto[3], and the Try it box hangs under #foto[1]. The sun topic's boxes are a grid of one column whose set is a box and its picture (['uso', 'uso-foto']): each :::frame{slot="uso"} holds its words and, inside it, the :::figure{slot="uso-foto"} that goes with them. The questions page stacks a module: pregunta is a template with role: 'module', a tinted box and the lines to answer on, and the page's preguntas group (modules: true) lays one for every :::module{template="pregunta"} of the Markdown. A frame is as tall as its words, never less than its minHeight, so a longer Spanish text pushes the rows under it down, and when a page runs short the reflow ladder sets the map and the pictures smaller before the text, down to 90 %.
The course boxes are a grid of three under the map (grid('cursos', ['curso'], 3, …)), one box for every :::frame{slot="curso"}. The map names the same three stretches with labels in the curso style, on the green of the boxes' tabs, so a reader finds each box's stretch by its name and its colour. On a vertical page the courses stand in one column beside the map.
#5 · Put the names on the map from the text
// 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;
The map is a painting with no letter on it. Each place is an anchor of the picture, a point in fractions of its width and height with a label style, and each edition writes its own ::label lines at those anchors. Penalta Reservoir, Pantà de Penyalta and Embalse de Peñalta stand at the same place, and a longer name breaks inside the anchor's width. A right-bound book shows the same painting mirrored (mapa-1900-rtl.jpg), so the river runs from the mountains on the right to the sea on the left, the way its pages are read; flipped takes each anchor, and the place its label is set at, to the other side and turns a rotation the other way. Spring and Penalta Reservoir are set away from their places with labelAt, and the agua style's leader draws a line with a dot from the name to the spring and to the dam.
#6 · Keep each part of the contents together
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"} lists the topics and their sections and keeps each part row with its entries. A :::part fence with parts.page: false is only a row of the contents and a section for the running heads: it adds no divider page. The contents are a composed page: its template has a frame with takes: "toc" that receives the :::toc and lays it by the contents' own rules, so the part rows, the leaders and keep work as in the running text, and the pale ground is the template's decoration.
The whole recipe
// ═══ 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 = 'en'; // @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
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
#Add a fourth family
A topic about the sea is a fourth entry in FAMILIES and a template made with topic('tema-mar', 'mar', { frames }). swap('mar') writes its palette, and the boxes and the ground follow it.
- sol: { main: '#9a5209', tint: '#fcefd2', ground: '#f8e6b8' },
+ sol: { main: '#9a5209', tint: '#fcefd2', ground: '#f8e6b8' },
+ mar: { main: '#0f5a6b', tint: '#dcf0f2', ground: '#cbe6ea' },#Keep the text at its size
A frame that must not shrink its text takes fit: { shrinkText: false }. A longer text then pushes harder on the frames around it, and the ladder reaches the pictures first.
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 } }],Pitfalls
- A name painted into a picture could not change with the language: the map carries no word, and every name is a label.
- A topic's palette changes the
temaentries only. The folios and the contents useagua, which has the same blue, so they stay blue on the green and sand pages; link them totemaand they follow the topic. - An Arabic-Indic digit next to a middle dot reads as two digits:
١ · ماءlooks like٠١ ماء, because the Arabic zero is a dot. The Arabic edition writes١- ماء للحقولand spells the unit's number out. - A decoration element stands on the sheet, not in the flow: a badge placed
top-leftof a frame stays at the left in Arabic.corner('top')andinward(x)place it from the side the page starts reading from. - In a grid, each item is a fence of its own: a box's picture is a member of its set only when its
:::figureis written inside the box's:::frame. Written after it, the picture is an item of its own and gets a cell of its own. - Two figures that set the same resource take the words of the first one: the small map on the contents page is the same file under its own resource,
rio, with no anchors.
Credits
- Recipe
- Ignacio Ferro
- Text
- Our river, a children's textbook unit written for this recipe in Spanish and set in ten languages · Postext Cookbook · CC BY 4.0
- Images
- The valley of the River Aldara, painted from the mountains to the sea, with two children watching the water. · Generated With Diffusion Models · original
- 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 · original
- The same painted map mirrored, the mountains on the right, for the books bound on the right (Arabic, Chinese, Japanese). · Generated With Diffusion Models · original
- A spring between mossy rocks. · Generated With Diffusion Models · original
- A mountain stream over round stones. · Generated With Diffusion Models · original
- A small waterfall into a green pool. · Generated With Diffusion Models · original
- A farmer opening the gate of an irrigation canal. · Generated With Diffusion Models · original
- An old stone watermill with its wheel. · Generated With Diffusion Models · original
- Children paddling canoes on a calm river. · Generated With Diffusion Models · original
- Children and a teacher picking up litter on a river bank. · Generated With Diffusion Models · original
- Fonts
- 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)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


