انتقل إلى المحتوى الرئيسي
الوصفة رقم 203

دليل الوصفات · الفصل 12 · الكتب المدرسية

فصل من كتاب رياضيات مدرسي يوناني

ثلاث صفحات عن مبرهنة فيثاغورس لتلاميذ يونانيين: الأقسام 3.1 إلى 3.3 بحروف كبيرة بلا tonos، وتسميات Εικόνα وΠίνακας، وصيغ MathJax.

في هذه الصفحة
المُخرَج
Canvas · PDF
المستوى
متقدم
Postext
اختُبرت مع Postext 1.99.1
تتطلب ≥ 1.99.1 · postext-pdf ≥ 1.99.1
الترخيص
حُدّثت في 29 نوفمبر 2026
الشيفرة MIT · النص CC BY 4.0
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 205 × 275 مم
  • عمود واحد
  • Source Serif 4 10.5/15
  • Fira Sans
  • 3 صفحات
  • المستوى
  • Postext 1.99.1
  • أُخرجت في 104 ms
  • أسطر الشيفرة: 215

باختصار

ثلاث صفحات من كتاب رياضيات مدرسي يوناني عن المثلث القائم. عناوين الأقسام بحروف كبيرة، والرسم والجدول يحملان تسميات يونانية، والصيغ تستعمل الحروف اليونانية.

ما الذي ستنضده

مطلع الفصل 3 من كتاب رياضيات متخيَّل للسنة الثانية من المرحلة الإعدادية اليونانية، عن مبرهنة فيثاغورس. يحمل شريط أزرق مخضر ΚΕΦΑΛΑΙΟ 3 وعنوان الفصل؛ وتتبعه الأقسام 3.1 إلى 3.3 بحروف كبيرة متباعدة. تجلس المبرهنة على خلفية زرقاء مخضرة، ويتدلى مثالان محلولان من شريط بلون المغرة، ويحكي إطار مخطط من أين جاءت المبرهنة. يرسم الشكل 3.1 المربعات على أضلاع مثلث 3-4-5؛ ويتحقق الجدول 3.1 من خمس ثلاثيات فيثاغورية. النص بخط Source Serif 4 قياس 10,5 على 15 نقطة، والعناوين والتسميات بخط 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 · محلية واحدة للنص والتسميات والحروف الكبيرة

الشيفرة هي الجواب المختصر أعلاه. يقطّع locale: 'el' النص بالأنماط أحادية النبر، ويسمي أنواع الموارد Εικόνα وΠίνακας، ويجعل textTransform: 'uppercase' يحذف tonos (لغة الوثيقة). الرياضيات TeX بين علامتي $، ينضدها MathJax بعد await initMathEngine() (الرياضيات)؛ وتعطي \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 · Εικόνα وΠίνακας من المحلية

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 مرسوم كصورة أن يستعمل خطوط الصفحة، فتسمياته مسارات MathJax يعيدها renderMath: ‏\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 المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

أخطاء شائعة

خطأ شائع

الرياضيات تحتاج إلى await initMathEngine() قبل البناء الأول

الصيغ التي تُنضَّد قبل أن يعمل محرّك الرياضيات مربعات رمادية نائبة. استورد initMathEngine من https://esm.sh/postext مع سائر الرموز وانتظرها بـ await قبل البناء الأول؛ والمستند الذي فيه رياضيات ويُبنى من دونها يطبع تحذيرًا واحدًا في وحدة التحكم. ومنذ postext 1.5 يأتي MathJax داخل حزمة postext وحدةً واحدة تجلبها initMathEngine، فالاستيراد العادي يعمل من CDN ولا حاجة إلى ?bundle (حتى 1.4 كان يجب أن يأتي كل رمز من https://esm.sh/postext?bundle). استورد من عنوان URL واحد فقط: عنوانان يحمّلان محرّكين. الرياضيات →

  • أبقِ الوحدة على سطر رقمها بمسافة غير فاصلة (U+00A0) في Markdown: «10 cm» مقسومة على سطرين تُقرأ بصعوبة في كتاب مدرسي.
  • الصيغة كلمة واحدة لا تنقسم. الجملة التي تنتهي بـ$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)
الشيفرة
MIT، مثل Postext
SandboxPDF