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

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

ギリシャ語の数学教科書の1章

ギリシャの生徒向けに三平方の定理を扱う3ページ。3.1〜3.3節はtonosのない大文字、図表はΕικόναとΠίνακας、数式はMathJax。

このページの内容
ジャンル
教科書
出力
Canvas · PDF
レベル
上級
Postext
Postext 1.99.1で検証済み
1.99.1以上が必要 · postext-pdf ≥ 1.99.1
ライセンス
2026年11月29日更新
コードMIT · 本文CC BY 4.0

1ページ(全3ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり205 × 275 mm
  • 1段
  • Source Serif 4 10.5/15
  • Fira Sans
  • 3ページ
  • レベル
  • Postext 1.99.1
  • 組版時間104 ms
  • コード215行

かんたんな説明

直角三角形を扱うギリシャの中学校数学教科書の3ページ。節見出しは大文字、図と表にはギリシャ語のラベル、数式にはギリシャ文字を使います。

できあがり

架空のギリシャの中学2年数学教科書から、三平方の定理を扱う第3章の冒頭です。濃い青緑の帯にΚΕΦΑΛΑΙΟ 3と章題が入り、3.1〜3.3節の見出しが字間を空けた大文字で続きます。定理は青緑の地に置き、2つの例題は黄土色の縦帯から下げ、罫で囲んだ枠が定理の由来を語ります。図3.1は3-4-5の三角形の各辺に立つ正方形を描き、表3.1はピタゴラス数5組を確かめます。本文はSource Serif 4 10.5/15 pt、見出しとラベルはFira Sans、数式はMathJaxです。ページはどの版でもギリシャ語で、このレシピのために書きました。言語が変わるのは奥付だけです。

このレシピが答える質問

  • 数式を使わずに、上付き文字、下付き文字、化学式を書くには?
  • 数式(インライン、ディスプレイ、方程式)を組み、PDFでもベクターのまま保つには?
  • 番号付きキャプションのある図を加え、本文で参照するには(「図3.2を参照」)?
  • 見出し行、結合セル、列幅、セルごとのそろえを備えた表を作るには?

手短な答え

script.js · 36〜45行コード全体で見る
// locale 'el' hyphenates the text with the monotonic patterns, names the figures and tables
// Εικόνα and Πίνακας (numbered {h1}.{n}: Εικόνα 3.1), writes «βλ. σ.» style references in
// Greek, and makes every textTransform 'uppercase' drop the tonos: the section titles
// below are written «Τι λέει το θεώρημα» and print ΤΙ ΛΕΕΙ ΤΟ ΘΕΩΡΗΜΑ.
const LOCALE = 'el';
// Between $ and $ is TeX, set by MathJax as vector paths, Greek letters included (\alpha,
// \beta, \gamma). initMathEngine() loads it before the first build.
await initMathEngine();
// Source Serif 4's x-height is 0.475 em, TeX's 0.442 em: the formulas are lifted to match.
const math = { fontSizeScale: 0.475 / 0.442, marginBottom: em(0.3), keepWithLeadIn: true };

材料

種類
Source Serif 4, Fira Sans (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · 本文・ラベル・大文字を1つのlocaleで

コードは上の手短な答えです。locale: 'el'は本文を単調ギリシャ語のパターンで分綴し、リソースの種類をΕικόναとΠίνακαςと呼び、textTransform: 'uppercase'にtonosを外させます(文書の言語)。数式は$で囲んだTeXで、await initMathEngine()の後にMathJaxが組みます(数式)。\alpha、\beta、\gammaが数式のギリシャ文字です。math.fontSizeScaleで数式を拡大し、xハイトをSource Serifに合わせます。

#2 · 第3章と大文字の3.1節

script.js · 49〜69行コード全体で見る
// # Το Πυθαγόρειο θεώρημα {startAt=3 kicker="Κεφάλαιο"}: startAt makes it chapter 3, so
// its sections, figures and tables count 3.1, 3.2.
const sans = (size, weight, color, extra = {}) => ({ fontFamily: SANS, fontSize: pt(size),
  fontWeight: weight, color: col(color), ...extra });
const chapter = { level: 1, numberingTemplate: '{1}', marginBottom: pt(LEAD),
  advancedDesign: { enabled: true, minHeight: mm(38), slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('teal') },
      placement: { ...at('page', 'top-left'), size: { width: 'fill', height: mm(52) } } },
    { kind: 'text', id: 'kicker', content: '{attr.kicker} {number}', align: 'left',
      ...sans(10, 600, 'paper', { letterSpacing: pt(2.4), textTransform: 'uppercase' }),
      placement: at('container', 'top-left', 0, 4) },
    { kind: 'text', id: 'title', content: '{titleText}', align: 'left', overflow: 'wrap',
      ...sans(28, 700, 'paper', { lineHeight: 1.1 }),
      placement: { ...at('#kicker', 'below', 0, 3), size: { width: mm(MEASURE) } } },
  ] } } };
const section = { level: 2, numberingTemplate: '{1}.{2}', numberSeparator: '  ',
  fontFamily: SANS, fontWeight: 700, fontSize: pt(11.5), lineHeight: pt(LEAD),
  letterSpacing: em(0.06), textTransform: 'uppercase', color: col('teal'),
  marginTop: pt(LEAD), marginBottom: pt(LEAD / 2) };
// ## Ασκήσεις {style="exercises"}: the same section head without a number.
const headingStyles = [{ id: 'exercises', numbered: false }];

# Το Πυθαγόρειο θεώρημα {startAt=3 kicker="Κεφάλαιο"}で章番号が3になり、節は3.1、3.2、図と表は3.1と数えます。H2は小文字で«Τι λέει το θεώρημα»と書き、ΤΙ ΛΕΕΙ ΤΟ ΘΕΩΡΗΜΑと印刷されます。## Ασκήσεις {style="exercises"}はnumbered: falseの見出しスタイルを使い、練習問題は同じ見出しで番号なしになります。

#3 · localeから来るΕικόναとΠίνακας

script.js · 92〜102行コード全体で見る
// defaultResourceTypes('el') hands over the built-in Greek types, Εικόνα and Πίνακας, numbered
// 3.1 after the chapter; :ref{id="…"} writes «Εικόνα 3.1» in the text. Only the table's
// caption moves, over its table, as school books set them.
const resourceTypes = defaultResourceTypes(LOCALE).map((type) => (type.id === 'table'
  ? { ...type, captionStyle: { position: 'above' } } : type));
const captionStyle = { ...sans(9, 400, 'ink'), gap: mm(2.5), labelColor: col('teal'),
  note: { fontFamily: SANS, fontSize: pt(7.8), color: col('muted') } };
const tableStyle = { rules: 'horizontal', borderColor: col('rule'), borderWidth: pt(0.5),
  headerBackground: col('mist'), headerColor: col('teal'), headerFontFamily: SANS,
  headerFontSize: pt(9), bodyFontFamily: SANS, bodyFontSize: pt(9.5), bodyColor: col('ink'),
  cellPadding: mm(1.6) };

defaultResourceTypes('el')が章ごとに番号を振る組み込みのギリシャ語の種類を渡します(リソース)。変えるのは表のキャプションの位置だけで、表の上に置きます。本文のΗ :ref{id="tetragona" style="full"}は«Η Εικόνα 3.1»、Ο :ref{id="triades" style="full"}は«Ο Πίνακας 3.1»と印刷されます。εικόναは女性名詞、πίνακαςは男性名詞なので、冠詞はMarkdownに書きます。

#4 · MathJaxでラベルを付けた図

script.js · 204〜250行コード全体で見る
// An SVG drawn as an image cannot use the page's fonts, so its labels are MathJax paths:
// \mathrm{A}, \mathrm{B} and \Gamma are the Greek capitals Α, Β, Γ (Alpha and Beta share
// their shapes with A and B).
const U = 7; // mm to a unit of the grid
const [FIG_W, FIG_H] = [12 * U, 13 * U]; // mm
const R = (x) => Math.round(x * 100) / 100;
function tex(markup, x, y, size, color = 'ink') { // centred on (x, y)
  const r = renderMath(markup, false, 100);
  const k = size / 1000;
  return `<g transform="translate(${R(x - (r.viewBox.width * k) / 2)} ${R(y + size * 0.35)}) `
    + `scale(${k})" fill="${palette[color]}">`
    + `${r.paths.map((p) => `<path d="${p.d}"/>`).join('')}</g>`;
}
function squares() {
  // Right angle at A; AB = 3 up, AΓ = 4 across; the square on ΒΓ tilted outwards.
  const [ax, ay] = [5 * U, 8 * U];
  const A = [ax, ay]; const B = [ax, ay - 3 * U]; const G = [ax + 4 * U, ay];
  const poly = (pts, fill, stroke = palette.teal) => `<polygon points="${pts.map((p) => p.map(R)
    .join(',')).join(' ')}" fill="${fill}" stroke="${stroke}" stroke-width="0.35"/>`;
  const grid = (o, u, v, n) => { // n × n cells on the square with corner o and sides u, v
    let d = '';
    for (let i = 1; i < n; i++) {
      d += `M${R(o[0] + u[0] * i)} ${R(o[1] + u[1] * i)}l${R(v[0] * n)} ${R(v[1] * n)}`
        + `M${R(o[0] + v[0] * i)} ${R(o[1] + v[1] * i)}l${R(u[0] * n)} ${R(u[1] * n)}`;
    }
    return `<path d="${d}" stroke="${palette.paper}" stroke-width="0.35"/>`;
  };
  const sq = (o, u, v, n, fill) => poly([o, [o[0] + u[0] * n, o[1] + u[1] * n],
    [o[0] + (u[0] + v[0]) * n, o[1] + (u[1] + v[1]) * n], [o[0] + v[0] * n, o[1] + v[1] * n]],
  fill) + grid(o, u, v, n);
  // The squares on β = AΓ (4, below), on γ = AB (3, left) and on α = BΓ (5, up and right).
  const unitBG = [(G[0] - B[0]) / 5, (G[1] - B[1]) / 5]; // along BΓ, one unit
  const out = [-unitBG[1], unitBG[0]].map((x) => -x); // perpendicular, away from A
  let s = sq(A, [U, 0], [0, U], 4, '#9cc9cf') + sq(B, [0, U], [-U, 0], 3, '#cfe3e5')
    + sq(B, unitBG, out, 5, '#7fb3ba') + poly([A, B, G], palette.paper, palette.ink);
  s += `<path d="M${A[0] + 2} ${A[1]}v-2h-2" fill="none" stroke="${palette.ink}" `
    + 'stroke-width="0.3"/>'; // the right angle
  s += tex('\\mathrm{A}', A[0] - 2.2, A[1] + 2.4, 4) + tex('\\mathrm{B}', B[0] - 2.2, B[1] - 2.2, 4)
    + tex('\\Gamma', G[0] + 2.4, G[1] + 2.2, 4)
    + tex('\\gamma = 3', A[0] - 1.5 * U, A[1] - 1.5 * U, 4)
    + tex('\\beta = 4', A[0] + 2 * U, A[1] + 2 * U, 4)
    + tex('\\alpha = 5', (B[0] + G[0]) / 2 + 2.5 * out[0], (B[1] + G[1]) / 2 + 2.5 * out[1], 4);
  // The three squares reach from 2 to 12 units across and from 1 to 12 down: a unit of
  // paper round them.
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${FIG_W * 10}" height="${FIG_H * 10}" `
    + `viewBox="0 0 ${FIG_W} ${FIG_H}"><g transform="translate(${-U} 0)">${s}</g></svg>`;
}

画像として描くSVGはページの書体を使えないので、ラベルはrenderMathが返すMathJaxのパスです。\mathrm{A}、\mathrm{B}、\Gammaが大文字のΑ、Β、Γになります。アルファとベータはAとBと同じ形だからです。図はplacement: { position: 'top' }で行長の半分の幅にし、2ページ目の頭に置くので、1ページ目の本文は定理の下に続きます。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 203 · A Greek maths textbook page with formulas ═══════════════
// https://postext.dev/en/cookbook/greek-maths-textbook
// Code: MIT · Text: original (CC BY 4.0) · Figure: drawn in code (CC BY 4.0)
// Fonts: Source Serif 4, Fira Sans (SIL OFL 1.1) · Needs postext ≥ 1.99.1
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, initMathEngine, renderMath,
  defaultResourceTypes,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the colophon ('en' | 'es' | 'el'); the page is Greek
const RECIPE = 'greek-maths-textbook';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// A school book's palette: a deep teal for the chapter, its tint behind the theorem, and an
// ochre for the worked examples.
const palette = {
  ink: '#1b2227', // text
  teal: '#0f6170', // the accent: chapter band, section numbers, figure labels
  mist: '#e3f0f1', // the theorem's ground, the table's head
  ochre: '#b4691b', // examples: stripe and title
  rule: '#c9d3d6', // hairlines
  muted: '#5c676d', // running heads, captions' notes, the colophon
  paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.teal })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [SERIF, SANS] = ['Source Serif 4', 'Fira Sans']; // both with Greek
const [BODY, LEAD] = [10.5, 15]; // pt
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER] = [205, 275, 24, 24, 26, 30]; // mm
const MEASURE = TRIM_W - INNER - OUTER; // mm: 149
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });

// #region answer: one Greek locale for the text, the labels and the capitals
// locale 'el' hyphenates the text with the monotonic patterns, names the figures and tables
// Εικόνα and Πίνακας (numbered {h1}.{n}: Εικόνα 3.1), writes «βλ. σ.» style references in
// Greek, and makes every textTransform 'uppercase' drop the tonos: the section titles
// below are written «Τι λέει το θεώρημα» and print ΤΙ ΛΕΕΙ ΤΟ ΘΕΩΡΗΜΑ.
const LOCALE = 'el';
// Between $ and $ is TeX, set by MathJax as vector paths, Greek letters included (\alpha,
// \beta, \gamma). initMathEngine() loads it before the first build.
await initMathEngine();
// Source Serif 4's x-height is 0.475 em, TeX's 0.442 em: the formulas are lifted to match.
const math = { fontSizeScale: 0.475 / 0.442, marginBottom: em(0.3), keepWithLeadIn: true };
// #endregion

// #region headings: a chapter band, then sections numbered 3.1, 3.2 in capitals

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

よくあるつまずき

つまずき

数式には最初のビルドの前にawait initMathEngine()が必要

数式エンジンが動き出す前にレイアウトした数式は、灰色のプレースホルダーの箱になります。initMathEngineをほかのシンボルと一緒にhttps://esm.sh/postextから読み込み、最初のビルドの前にawaitしてください。数式のある文書をこれなしでビルドすると、コンソールに警告が1つ出ます。postext 1.5からは、MathJaxはinitMathEngineが取得する1つのモジュールとしてパッケージに含まれているので、通常のimportがCDNから使え、?bundleは必要ありません(1.4までは、すべてのシンボルをhttps://esm.sh/postext?bundleから読み込む必要がありました)。読み込むURLは1つだけにしてください。URLが2つあると、エンジンが2つ読み込まれます。 数式 →

  • Markdownでは単位を数字と同じ行に保つためノーブレークスペース(U+00A0)を使います。«10 cm»が2行に分かれると、教科書では読みにくくなります。
  • 数式は分けられない1語です。$30^2 + 40^2 = 900 + 1600 = 2500 = 50^2$で終わる文は前の行を間延びさせるので、ここではこの和を$$の別行立てにしています。
  • 三角形の名前ΑΒΓは本文にギリシャ文字の大文字で書き、$で囲まないでください。MathJaxの斜体になってしまいます。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
フォント
Source Serif 4 (SIL OFL 1.1) · Fira Sans (SIL OFL 1.1)
SandboxPDF