باختصار
أربع صفحات من كتاب فيزياء مدرسي روسي عن جسم على سطح مائل. الرسم والجدول والمسألة المحلولة والأسئلة موسومة ومرقّمة كما في الكتب المدرسية الروسية.
ما الذي ستنضده
قسم من كتاب فيزياء متخيَّل للصف التاسع، عن جسم على سطح مائل، بقياس 145 × 215 مم، وهو القطع الذي يسميه الناشرون الروس 60 × 90/16. يبدأ بـ«§ 14» على لسان أزرق. يرسم Рис. 1 القوى؛ ويعطي Таблица 1 احتكاك ستة أزواج من المواد مع الزاوية الحدية المحسوبة من tg α. يذكر إطار ما يجب حفظه، وتأتي مسألة محلولة في خليتين، «Дано» و«Решение». الأسئلة مرقّمة 1) و2) وفي داخلها а) وб). النص بخط PT Serif قياس 10 على 13,6 نقطة، والعناوين والتعليقات بخط Golos Text، والصيغ بـMathJax. الصفحة روسية في كل الطبعات وكُتبت لهذه الوصفة؛ ولا يتغير إلا الحرد.
تجيب هذه الوصفة عن
- كيف أنضد كتابًا مدرسيًا روسيًا فيه Рис. وعنوان جدول على سطرين وقوائم 1) а) وtg؟
- كيف أنضد الرياضيات (مضمّنة، ومعروضة، ومعادلات) وأبقيها متجهية في ملف PDF؟
- كيف أضيف شكلًا بتعليق مرقّم وأحيل إليه في النص («انظر الشكل 3.2»)؟
- كيف أخصّص القوائم: نقاط لكل مستوى، وترقيم (a)/(i)، ومربعات اختيار للمهام، وتباعد يبقى على الشبكة؟
الجواب المختصر
// locale 'ru' hyphenates by the Russian patterns, keeps a short preposition with its word and a
// number with its unit (9,8 м/с², 0,4 кг), counts the notes again on every page and indents
// them, and gives the resource types Рис. and Таблица.
const LOCALE = 'ru';
// A figure is «Рис. 1. …» under the drawing. A table has «Таблица 1» at the right on a line of
// its own and its title centred under it, which is how defaultResourceTypes('ru') comes. Both
// count through the book here ({n}, no chapter), and a reference in a sentence is «рис. 1».
const resourceTypes = [
...defaultResourceTypes(LOCALE).map((type) => ({ ...type, numberingTemplate: '{n}',
resetOn: 'never' })),
// «Дано | Решение» is a table without label or title.
{ id: 'given', name: 'Решение', shortLabel: '', captionPrefix: '', numberingTemplate: '{n}',
resetOn: 'never', counterFormat: 'decimal', defaultPlacement: { position: 'here' } },
];
// Lists count 1) 2) and, inside, а) б) в): the Cyrillic series leaves out ё й ъ ы ь.
const orderedLists = { color: col('ink'), fontWeight: 400, separator: ')', marginTop: pt(0),
marginBottom: pt(0), indent: em(1.5), separatorColor: col('brick'), levels: [
{ level: 1, numberFormat: 'decimal', separator: ')', color: col('brick'), fontWeight: 700 },
{ level: 2, numberFormat: 'lower-russian', separator: ')', color: col('brick') },
] };
// MathJax knows the operators of the Russian school: \tg, \ctg, \arctg. The decimal comma is
// written {,}: 9{,}8 sets without the space a comma takes in a list.
await initMathEngine();
const math = { fontSizeScale: 1.1, marginTop: em(0.7), marginBottom: em(0.7),
keepWithLeadIn: true, indentAfterDisplay: true }; // PT Serif's x-height is 0.5 em, TeX's 0.44
المكونات
- الميزات
- اللغات الكيريلية لغةً للمستندالرياضيات«شكل» و«جدول» بلغتككلمات لا تُفصل عند نهاية السطرتقسيم الكلمات ولغة المستندالحواشي السفليةالقوائم المرقّمةصفحات افتتاح مصمَّمةسمات العنواناستشهادات تضع الأشكالتعليقات مرقّمةنمط التعليقجداول من البياناتنمط الجدولإطارات التنبيهالنصوص والخطوط والمربعات في تصاميم الصفحةالترويسات وأرقام الصفحاتهوامش متناظرةالتصدير إلى PDF
- تستخدم أيضًا
- العناوين المرقّمةأنماط العناوينأشكال في هذا الموضع بالضبطفواصل الصفحات والأعمدةالترويسات بحسب دور الصفحةأنماط الفقراتالخطوط المضمَّنة في PDFأنواع موارد مخصّصةالأشكال والجداول بوصفها مواردترقيم روماني للصفحات التمهيديةالنص المرتفع والمنخفضأنماط الجداول المسمّاة
- الخطوط
- PT Serif, Golos Text (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · محلية واحدة للنص والحواشي والتسميات
الشيفرة هي الجواب المختصر أعلاه. يقطّع locale: 'ru' الكلمات بالأنماط الروسية، ويبقي в أو на أو с على سطر الكلمة التالية و0,4 مع кг، ويعيد عدّ الحواشي في كل صفحة (الإخراج السيريلي). يسلّم defaultResourceTypes('ru') النوع Рис. وتعليقه أسفله، وТаблица ورقمه إلى اليمين وعنوانه في الوسط تحته (الموارد). ويرقّم numberFormat: 'lower-russian' القائمة а) وб) وв) ويتخطى ё وй وъ وы وь (القوائم والرياضيات). ويعرف MathJax الأسماء الروسية \tg و\ctg و\arctg.
#2 · § 14 على لسان
// # Тело на наклонной плоскости {startAt=14 kicker="…"}: a section (параграф) is the H1.
const paragraph = { level: 1, numberingTemplate: '§ {1}', marginBottom: pt(0),
advancedDesign: { enabled: true, minHeight: pt(5 * LEAD), slot: { elements: [
{ kind: 'box', id: 'tab', style: { backgroundColor: col('blue') },
placement: { ...at('page', 'top-left', 0, 0), size: { width: mm(INNER + 25),
height: mm(TOP + 17) } } },
{ kind: 'text', id: 'number', content: '{number}', align: 'left', ...sans(27, 700, 'paper'),
placement: at('container', 'top-left', 0, 3.5) },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', align: 'left',
...sans(7.8, 500, 'muted'), placement: at('container', 'top-left', 31, -7) },
{ kind: 'text', id: 'title', content: '{titleText}', align: 'left', overflow: 'wrap',
...sans(21, 700, 'ink', { lineHeight: 1.12 }),
placement: { ...at('container', 'top-left', 31, 0), size: { width: mm(MEASURE - 31) } } },
] } } };
const subhead = { level: 2, numberingTemplate: '', fontFamily: SANS, fontWeight: 600,
fontSize: pt(11.5), lineHeight: pt(LEAD), color: col('blue'), marginTop: pt(LEAD * 1.3),
marginBottom: pt(LEAD * 0.5) };
// ## Вопросы {style="plain"}: what the pupil does, in red.
const headingStyles = [{ id: 'plain', color: col('brick') }];
يعطي # Тело на наклонной плоскости {startAt=14 kicker="…"} القسم الرقم 14، ويطبعه numberingTemplate: '§ {1}' على صورة § 14. يمد التصميم مربعًا أزرق من زاوية الصفحة حتى الرقم مع نزف إلى الحافة، ويمنح minHeight الافتتاح خمسة أسطر. ويأخذ الترويس في الصفحة الفردية الرقم نفسه عبر {chapterNumber}. أما ## Вопросы {style="plain"} فيستعمل نمط العنوان الذي يلوّن بالأحمر ما يفعله التلميذ.
#3 · إطار للقاعدة وشريط للمسألة
const title = (color) => sans(8.2, 700, color, { gap: mm(1) });
const box = { body: { firstLineIndent: pt(0) }, marginTop: pt(LEAD / 2),
marginBottom: pt(LEAD / 2) };
const calloutStyles = [
{ id: 'rule', ...box, background: col('mist'), backgroundEnabled: true, titleStyle: title('blue'),
stripe: { enabled: true, width: pt(3), color: col('blue') },
padding: { top: mm(3), right: mm(4), bottom: mm(2), left: mm(5) } },
{ id: 'problem', ...box, backgroundEnabled: false, titleStyle: title('brick'),
stripe: { enabled: true, width: pt(2), color: col('brick') },
padding: { top: mm(0.5), right: mm(0), bottom: mm(0.5), left: mm(4) } },
];
يتشارك نمطا الإطار متن النص ويختلفان في الخلفية: يضع rule كلمة «Запомните» على أزرق شاحب خلف شريط عرضه 3 نقاط، وللنمط problem شريط أحمر بلا خلفية. ويلغي firstLineIndent: 0 مسافة السطر الأول داخل الإطار، بينما تبدأ فقرات الصفحة كلها بمسافة 1,5 em.
#4 · شكل حروفه من MathJax
// An SVG drawn as an image cannot use the page's fonts, so its letters are MathJax paths.
// Millimetres; the slope falls to the right, along x.
const [FIG_W, FIG_H] = [104, 58];
const A = (25 * Math.PI) / 180, R = (x) => Math.round(x * 100) / 100;
function tex(markup, x, y, size = 4.6, color = 'ink') { // centred on (x, y)
const [r, k] = [renderMath(markup, false, 100), size / 1000];
return `<g transform="translate(${R(x - (r.viewBox.width * k) / 2)} ${R(y + size * 0.33)}) `
+ `scale(${k})" fill="${palette[color]}">`
+ `${r.paths.map((p) => `<path d="${p.d}"/>`).join('')}</g>`;
}
function arrow([x, y], angle, length, color, width = 0.7) { // angle in radians, y down
const [c, s, head, half] = [Math.cos(angle), Math.sin(angle), 2.6, 0.95];
const p = (u, v) => `${R(x + u * c - v * s)} ${R(y + u * s + v * c)}`;
return `<path d="M${p(0, 0)}L${p(length - head + 0.2, 0)}" stroke="${palette[color]}" `
+ `stroke-width="${width}"/><path d="M${p(length, 0)}L${p(length - head, half)}`
+ `L${p(length - head, -half)}Z" fill="${palette[color]}"/>`;
}
function slope() {
const foot = [96, 55], run = 88, base = [foot[0] - run, foot[1]];
const top = [base[0], base[1] - run * Math.tan(A)];
const along = (d, out = 0) => [foot[0] - d * Math.cos(A) + out * Math.sin(A),
foot[1] - d * Math.sin(A) - out * Math.cos(A)]; // d up the slope from its foot
const poly = (pts, fill, stroke, w) => `<polygon points="${pts.map((p) => p.map(R).join(','))
.join(' ')}" fill="${fill}" stroke="${stroke}" stroke-width="${w}" stroke-linejoin="round"/>`;
const [bw, bh, d] = [17, 11, 55]; // the body, and how far up the slope it stands
const [C, mid] = [along(d, bh / 2), bh / 2];
const ray = (d1, o1, d2, o2, dash = '') => { const [p, q] = [along(d1, o1), along(d2, o2)];
return `<path d="M${p.map(R).join(' ')}L${q.map(R).join(' ')}" stroke="${palette.muted}" `
+ `stroke-width="0.3"${dash}/>`; };
let s = poly([base, foot, top], palette.mist, palette.ink, 0.45)
+ poly([along(d - bw / 2), along(d + bw / 2), along(d + bw / 2, bh), along(d - bw / 2, bh)],
'#cdd9e8', palette.blue, 0.45);
// The axes through the centre of the body: x down the slope, y away from it.
s += ray(d + 22, mid, d - 34, mid) + ray(d, mid - 23, d, mid + 24);
s += arrow(along(d - 31, mid), A, 4.5, 'muted', 0.3)
+ arrow(along(d, mid + 22), A - Math.PI / 2, 4.5, 'muted', 0.3);
// mg and its components, dashed to the axes.
const [G, dash] = [23, ' stroke-dasharray="1.2 0.9"']; // mm of arrow for mg; N follows
const tip = [C[0], C[1] + G];
s += [along(d - G * Math.sin(A), mid), along(d, mid - G * Math.cos(A))].map((p) =>
`<path d="M${tip.map(R).join(' ')}L${p.map(R).join(' ')}" `
+ `stroke="${palette.muted}" stroke-width="0.3"${dash}/>`).join('');
s += arrow(C, Math.PI / 2, G, 'brick') + arrow(C, A - Math.PI / 2, G * Math.cos(A), 'brick')
+ arrow(C, A + Math.PI, 15, 'brick')
+ `<circle cx="${R(C[0])}" cy="${R(C[1])}" r="0.8" fill="${palette.ink}"/>`;
// The angle at the foot, and the equal one between mg and the normal.
const arc = (o, r, from, to) => `<path d="M${R(o[0] + r * Math.cos(from))} `
+ `${R(o[1] + r * Math.sin(from))}A${r} ${r} 0 0 1 ${R(o[0] + r * Math.cos(to))} `
+ `${R(o[1] + r * Math.sin(to))}" stroke="${palette.ink}" stroke-width="0.3"/>`;
s += arc(foot, 14, Math.PI, Math.PI + A) + arc(C, 11, Math.PI / 2, Math.PI / 2 + A);
s += tex('\\alpha', foot[0] - 17.5, foot[1] - 3.8)
+ tex('\\alpha', C[0] - 2.9, C[1] + 13.6, 4)
+ tex('m\\vec{g}', C[0] + 5.6, C[1] + G - 3.6, 4.6, 'brick')
+ tex('\\vec{N}', ...along(d - 4.6, mid + 18), 4.6, 'brick')
+ tex('\\vec{F}_{\\text{тр}}', ...along(d + 14, mid + 5), 4.6, 'brick')
+ tex('x', ...along(d - 33.5, mid + 3.6), 4.2) + tex('y', ...along(d + 3.4, mid + 25), 4.2);
return `<svg xmlns="http://www.w3.org/2000/svg" width="${FIG_W * 10}" height="${FIG_H * 10}" `
+ `viewBox="0 0 ${FIG_W} ${FIG_H}" fill="none">${s}</svg>`;
}
لا يستطيع SVG المرسوم صورةً أن يستعمل خطوط الصفحة، لذلك حروفه مسارات MathJax من renderMath، ومنها \vec{N} وm\vec{g} كما في النص. الميل 25°، وطول السهم N يساوي مركّبة mg العمودية على السطح كما في الفيزياء. ويطبع :ref{id="sily"} داخل الجملة «рис. 1».
#5 · جدول محسوب و«Дано | Решение»
const cell = (content, extra = {}) => ({ content, align: 'center', ...extra });
const PAIRS = [['Сталь по льду', 0.02], ['Лыжи по снегу', 0.05], ['Сталь по стали', 0.15],
['Дерево по дереву', 0.25], ['Резина по мокрому асфальту', 0.4],
['Резина по сухому асфальту', 0.7]];
const angles = { headerRowCount: 1, columnWidths: [2.2, 1, 1.2], rows: [
[cell('Материалы', { align: 'left', isHeader: true }), cell('$\\mu$', { isHeader: true }),
cell('$\\alpha_0$', { isHeader: true })],
...PAIRS.map(([name, mu]) => [cell(name, { align: 'left' }), cell(String(mu).replace('.', ',')),
cell(`${Math.round((Math.atan(mu) * 180) / Math.PI)}°`)]),
] };
const given = { columnWidths: [1, 2.9], rows: [[
{ content: ['**Дано:**', '$\\alpha = 30^\\circ$', '$\\mu = 0{,}25$', '$l = 2$ м',
'$v_0 = 0$', '**Найти:** $a$, $v$'].join('\n'), background: col('sand'), verticalAlign: 'top' },
{ content: ['**Решение**',
'Так как $\\tg\\alpha \\approx 0{,}58 > \\mu$, ящик скользит:',
'$a = g\\,(\\sin\\alpha - \\mu\\cos\\alpha)$,',
'$a = 9{,}8 \\cdot (0{,}5 - 0{,}25 \\cdot 0{,}87) \\approx 2{,}8$ м/с^2^.',
'Начальная скорость равна нулю, $v^2 = 2al$:',
'$v = \\sqrt{2al} = \\sqrt{2 \\cdot 2{,}8 \\cdot 2} \\approx 3{,}3$ м/с.'].join('\n'),
verticalAlign: 'top' },
]] };
يملأ Math.atan(mu) عمود الزوايا، ويكتب replace('.', ',') الفاصلة العشرية. والحل جدول ثانٍ من صف واحد: لا headerRowCount فيه، ونوع المورد given بلا تسمية، فيعرض الإطار خليتين بلا عنوان. ويحمل :ref{id="ugly" text="таблице 1"} الكلمة في الحالة الإعرابية التي تطلبها الجملة.
الوصفة كاملة
// ═══ Postext Cookbook · Nº 207 · A section of a Russian physics textbook ═════════════════
// https://postext.dev/en/cookbook/russian-physics-textbook
// Code: MIT · Text: original (CC BY 4.0) · Diagram: drawn in code (CC BY 4.0)
// Fonts: PT Serif, Golos Text (SIL OFL 1.1) · Needs postext ≥ 1.100.0
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' | 'ru'); the page is Russian
const RECIPE = 'russian-physics-textbook';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Two inks on white, as a school press prints them: a blue for what is learnt, a brick red for
// what is asked.
const palette = {
ink: '#1d2126', // text
blue: '#1c4c86', // the accent: section number, headings, rule box, the body in the diagram
mist: '#e8eef6', // the rule box's ground, the table's head, the slope in the diagram
brick: '#b03a2a', // problems, questions and the forces in the diagram
sand: '#f6efe6', // the «Дано» column
rule: '#bcc8d6', // hairlines
muted: '#586370', // running heads, the colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.blue })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [SERIF, SANS] = ['PT Serif', 'Golos Text']; // both with Cyrillic
const [BODY, LEAD] = [10, 13.6]; // pt
const [TOP, BOTTOM, INNER, OUTER] = [20, 19, 16, 18]; // mm, on a 145 × 215 page
const MEASURE = 145 - INNER - OUTER; // mm: 111, about 64 characters
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const sans = (size, weight, color, extra = {}) => ({ fontFamily: SANS, fontSize: pt(size),
fontWeight: weight, color: col(color), ...extra });
// #region answer: one Russian locale: patterns, ties, notes by page, Рис. and Таблица
// locale 'ru' hyphenates by the Russian patterns, keeps a short preposition with its word and a
// number with its unit (9,8 м/с², 0,4 кг), counts the notes again on every page and indents
// them, and gives the resource types Рис. and Таблица.
const LOCALE = 'ru';
// A figure is «Рис. 1. …» under the drawing. A table has «Таблица 1» at the right on a line of
// its own and its title centred under it, which is how defaultResourceTypes('ru') comes. Both
// count through the book here ({n}, no chapter), and a reference in a sentence is «рис. 1».
const resourceTypes = [
...defaultResourceTypes(LOCALE).map((type) => ({ ...type, numberingTemplate: '{n}',
resetOn: 'never' })),
يعمل ملف 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 واحد فقط: عنوانان يحمّلان محرّكين. الرياضيات →
- اكتب الفاصلة العشرية
9{,}8. الفاصلة المفردة علامة ترقيم عند TeX، فتُنضد 9, 8 بمسافة. - نضّد مربع
м/с^2^في النص بـ^2^. الحرف ² يأتي من الخط بقياس وثقل آخرين.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- نص أصلي, CC BY 4.0
- الخطوط
- PT Serif (SIL OFL 1.1) · Golos Text (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


