本文へスキップ
レシピ番号156

レシピ集 · 第12章 · 教科書

10か国語の子ども向け教科書の単元

小学3年生の社会科の単元9ページを10か国語で。アラビア語は右から左へ、中国語と日本語は縦組み。色地の見開き、文章に合わせて伸びるタブ付きの囲み、本文から地名を付けた描き下ろしの地図。

このページの内容

6〜7ページ(全9ページ)

  • 仕上がり210 × 280 mm
  • 1段
  • Klee One 12/21
  • Zen Maru Gothic
  • 9ページ
  • レベル
  • Postext 1.65.0
  • 組版時間194 ms
  • コード296行

かんたんな説明

川を扱う教科書の単元で、全9ページ。各テーマは色地の見開きで、タイトルのタブ、本文、画像、囲みがあります。地図には文字を一つも描かず、地名はすべて本文から付けます。言語ごとに長さが違っても同じテンプレートに収まります。

できあがり

架空の小学3年生の社会科の本の第4単元「わたしたちの川」を、210 × 280 mmのページで9ページ、スペイン語、カタルーニャ語、英語、ポルトガル語、フランス語、ドイツ語、イタリア語、アラビア語、中国語、日本語の10か国語で組みます。描いた谷が単元を開き、二つの部を並べた目次のページがあり、そのあとにテーマが3つ、見開きで続きます。地色は水の青、野の緑、日の砂色とテーマごとに違います。どのテーマにも番号とタイトルのタブがあり、本文は2段、囲みは文章に合わせて伸びるタブ付きです。2つ目のテーマは2ページにまたがる1枚の絵地図で、川、村、三つの区間の名前をMarkdownから載せ、区間の囲みそれぞれから川のその区間へ線を引きます。繰り返すものは一度だけ描きます。テンプレートは、画像のカード、区間の囲み、画像付きの囲みをそれぞれ一つずつ持ち、Markdownが求める数だけ並べます。単元の初めの三つの問いは、一つのモジュールを3回使ったものです。本文は言語によって5分の1以上も長さが違いますが、同じテンプレートに収まります。囲みは言葉に必要な高さを取って次の囲みを押し下げ、地図は文字より先に少しだけ縮みます。アラビア語の本は右から左へ、中国語と日本語の本はページを上から下へ進みます。三つとも右綴じで、見開きごとに右ページから左ページへと読みます。

このレシピが答える質問

  • 言語ごとに文章の長さが違うとき、同じページテンプレートで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) }];

材料

種類
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'を指定すると、エンジンはこの座標系を左右反転させるので、アラビア語の本はラテン文字用の枠をそのまま使えます。タイトルは右ページに先に来て、写真3枚と川の区間の囲み3つは右から左へ並び、囲みのタブ、色帯、余白は行に従います。layout.writingMode: 'vertical-rl'では、xはページを下へ、yは右から左へ進みます。枠のwidthは下向きの長さになり、積み重ねは左へ進み、columns: 2は27字詰めの2段(段)になり、別の枠の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') } },
];

囲みのスタイルは3段階で作ります。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) }];

土台は見開きのテンプレートで、塗り足しまでの地色、番号付きのタイトルのタブ、2段の本文があります。各テーマはextends: 'tema'でこれを引き継ぎ、自分のpaletteを決め(3つの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]の下に付きます。日のテーマの囲みは1列のグリッドで、組は囲みとその画像です(['uso', 'uso-foto'])。:::frame{slot="uso"}のそれぞれが自分の言葉を持ち、その中に対応する:::figure{slot="uso-foto"}を入れます。問いのページはモジュールを積みます。preguntaはrole: 'module'のテンプレートで、地色の囲みと答えを書く線があり、ページのpreguntasグループ(modules: true)がMarkdownの:::module{template="pregunta"}一つごとに一つ置きます。枠は言葉の分だけ高くなり、minHeightより低くなることはないので、長いスペイン語の本文は下の行を押し下げます。ページが窮屈になると、調整の手順が本文より先に地図と画像を縮め、本文は90 %まで縮めます。

区間の囲みは地図の下に並ぶ3つのグリッドです(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は、目次の一行と柱の区切りになるだけで、扉のページは増えません。目次はテンプレートページです。そのテンプレートにはtakes: "toc"の枠があり、:::tocを受け取って目次自身の規則で組みます。部の行、リーダー、keepは本文の中と同じように働き、淡い地はテンプレートの装飾です。

レシピの全体

Sandbox
// ═══ 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 = 'ja'; // @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上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#4つ目の系統を足す

海のテーマなら、FAMILIESに4つ目の項目を足し、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にリンクすれば、テーマに従います。
  • アラビア・インド数字を中黒の隣に置くと、2桁の数字に見えます。アラビア語のゼロは点なので、١ · ماءは٠١ ماءのように見えます。アラビア語版は١- ماء للحقولと書き、単元の番号は言葉で書きます。
  • 装飾の要素は流れではなく紙面の上にあります。枠のtop-leftに置いたバッジは、アラビア語でも左に残ります。corner('top')とinward(x)は、ページの読み始めの側からそれを配置します。
  • グリッドでは、項目の一つひとつが独立したブロックです。囲みの画像がその組に入るのは、:::figureを囲みの:::frameの中に書いたときだけです。後ろに書くと、画像は別の項目になり、自分のセルを一つ取ります。
  • 同じリソースを指定する2つの図は、最初の図の言葉を取ります。目次ページの小さな地図は同じファイルを別のリソースrioとして使い、アンカーはありません。

クレジット

レシピ
Ignacio Ferro
本文
  • 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)
SandboxPDF