باختصار
فصل قصير يعلّم قراءة رموز المنطق ونظرية المجموعات. خطوط الكتاب لا تحوي هذه الرموز، فيأتي بها خط ثانٍ على الشاشة وفي ملف PDF المطبوع.
ما الذي ستنضده
الفصل الأول من كتيّب جيب في المنطق، على صفحة مقاسها 155 × 235 مم: شريط عنابي تُصفّ عليه رموز الفصل بحجم كبير، ثم أربعة أقسام تقرأ بصوت عالٍ ∀ و∃ و∈ و∪ و∅ وℵ، والصيغ في متن الكلام وبارزة بين الفقرات. يُصفّ الكتاب بخط Crimson Pro، وعناوينه بـ Cormorant Garamond، ووسومه بـ IBM Plex Sans Condensed. لا يحوي أيّ من الثلاثة ∀ ولا ∈ ولا حرفًا يونانيًا في الملفات التي يقدّمها Fontsource. إعداد واحد، symbolFont، يضع Noto Sans Math خلف كلٍّ منها، فتأتي الرموز كلها من الخط نفسه في المتن والعناوين والترويسات وخلايا الجداول، ويطبعها PDF كلها.
تجيب هذه الوصفة عن
- كيف أطبع رموز المنطق والمجموعات (∀ و∈ وℵ) والحروف اليونانية التي يفتقدها خط النص، دون مربعات فارغة في PDF؟
الجواب المختصر
// None of the three faces has ∀, ∈, ℵ or Greek. config.symbolFont (below) lists Noto Sans
// Math after every family the document names: what a face lacks is drawn from it, at the
// face's size and colour, in the canvas, the PDF, the HTML and the EPUB.
const SYMBOLS = 'Noto Sans Math';
// Fontsource serves Noto Sans Math whole in its "latin" file, and the kit would declare
// that file for the Latin range only. The screen and the PDF take it here with no range,
// so every glyph in it can be used.
const symbolFile = async () =>
`${await fontsourceAt('noto-sans-math')}files/noto-sans-math-latin-400-normal.woff2`;
const resolve = async (family, ...face) =>
(family === SYMBOLS ? [{ source: await symbolFile() }] : fontsourceResolver(family, ...face));
const pdfFonts = async (family, ...face) => (family !== SYMBOLS
? fontsourceProvider(family, ...face)
: decompressWoff2(new Uint8Array(await (await fetch(await symbolFile())).arrayBuffer())));
المكونات
- الميزات
- خط الرموزالخطوط المضمَّنة في PDFالخطوط قبل الإخراجالنص المرتفع والمنخفضأنماط الفقراتجداول من البياناتنمط الجدولصفحات افتتاح مصمَّمةسمات العنوانالترويسات وأرقام الصفحاتهوامش متناظرةلوحة ألوان دلاليةالتصدير إلى PDF
- تستخدم أيضًا
- أشكال في هذا الموضع بالضبط«شكل» و«جدول» بلغتكالترويسات بحسب دور الصفحةأنواع موارد مخصّصة
- الخطوط
- Crimson Pro, Cormorant Garamond, IBM Plex Sans Condensed, Noto Sans Math (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · خط للرموز خلف الخطوط كلها
شيفرة هذه الخطوة هي الجواب المختصر في الأعلى. يضع symbolFont: 'Noto Sans Math' (خط الرموز) هذه العائلة خلف كل عائلة يذكرها الإعداد: الحرف الذي لا يحويه الخط يُرسم بـ Noto Sans Math، بحجم الخط ولونه، ويبقى باقي السطر بخطه. يقدّم Fontsource خط Noto Sans Math كاملًا في ملف latin، أي 3033 حرفًا، لكن العُدّة تعلن هذا الملف لنطاق اللاتينية وحده، فلا يطلب منه المتصفح ∀. وتمرّر resolve وpdfFonts في هذه الوصفة الملف نفسه بلا نطاق، على الشاشة وإلى renderToPdf. لا يتغيّر الخط إلا للحروف الناقصة: في Crimson Pro علامة ¬، فتبقى علامة النفي في المتن بخط Crimson Pro.
#2 · صفٌّ أول بدونه يكشف الناقص
// Each paragraph that sets a character its face lacks is a glyphFallbackAt warning with its
// page; with no symbol font it names no family that draws them, and the PDF would print
// empty boxes. The pages shown are the second build's.
const fonts = { ...kitFonts(FONTS), resolve }; // the kit's resolver, with the symbol file
const bare = await buildDocumentWithFonts({ markdown, resources }, { ...config, symbolFont: '' },
fonts);
console.info((bare.contentWarnings ?? []).filter((w) => w.kind === 'glyphFallbackAt')
.map(formatWarning).join('\n'));
يترك الصفّ الأول symbolFont فارغًا ويطبع تحذيرات glyphFallbackAt، واحدًا لكل فقرة أو عنوان أو جدول فيه حروف لا شكل لها في خطه، مع الصفحة والحروف. تعطي النسخة الإنجليزية ثمانية عشر تحذيرًا: أربع عشرة فقرة بخط Crimson Pro، وثلاثة عناوين بـ Cormorant Garamond، وصف الترويسة في الجدول 1.1 بـ IBM Plex Sans Condensed العريض. من دون عائلة ترسمها، تأخذ اللوحة الرموز من خط في نظام القارئ، ويطبع PDF لكلٍّ منها مربعًا فارغًا. الصفّ الثاني، مع خط الرموز، هو ما يظهر على الصفحة، وتحذيراته تسمّي "Noto Sans Math" العائلة التي ترسمها.
#3 · رموز الافتتاحية نص
const BAND = 78; // mm from the trim to the foot of the band
const onBand = { color: col('paper'), align: 'left' };
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' }, offset: { y: mm(y) },
size: { width: mm(width) } });
const opener = { enabled: true, minHeight: mm(BAND - TOP + 2), slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(BAND) } } },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', ...onBand, fontFamily: LABEL,
fontWeight: 600, fontSize: pt(8.5), letterSpacing: pt(1.8), textTransform: 'uppercase',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(2) } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: DISPLAY,
fontWeight: 600, fontSize: pt(38), lineHeight: 1.02, placement: below('kicker', 3, 110) },
// The signs are text in Cormorant Garamond, which has none of them: Noto Sans Math draws
// every one, at 30 pt, in the band's white.
{ kind: 'text', id: 'signs', content: '{attr.signs}', ...onBand, fontFamily: DISPLAY,
fontSize: pt(30), lineHeight: 1, letterSpacing: pt(9), placement: below('title', 7, 114) },
] } };
سطر الرموز السبعة تحت العنوان نص تصميمي بخط Cormorant Garamond بحجم 30 pt، يأخذ محتواه من السمة signs في العنوان. لا يحوي Cormorant Garamond أيًّا منها، فتأتي السبعة كلها من خط الرموز، بالأبيض على الشريط. ويوزّعها تباعد قدره 9 pt على عرض الصندوق.
#4 · الخلايا والترويسات بالخط نفسه
const [T, F] = t({ en: ['T', 'F'], es: ['V', 'F'] });
const connectives = [['¬*p*', (p) => !p], ['*p* ∧ *q*', (p, q) => p && q],
['*p* ∨ *q*', (p, q) => p || q], ['*p* → *q*', (p, q) => !p || q],
['*p* ↔ *q*', (p, q) => p === q]];
const cell = (content, isHeader = false) => ({ content, align: 'center', isHeader });
const truth = [[true, true], [true, false], [false, true], [false, false]].map(([p, q]) =>
[p, q, ...connectives.map(([, f]) => f(p, q))].map((v) => cell(v ? T : F)));
const table = (id, rows, columnWidths, caption, position) => ({ id, typeId: 'table',
kind: 'table', caption, createdAt: 0, updatedAt: 0, placement: { position },
table: { model: { headerRowCount: 1, columnWidths, rows } } });
const resources = [
table('truth', [['*p*', '*q*', ...connectives.map(([s]) => s)].map((s) => cell(s, true)),
...truth],
[1, 1, 1.3, 1.6, 1.6, 1.6, 1.6], t({ en: 'The five connectives, row by row.',
es: 'Las cinco conectivas, fila a fila.' }), 'top'), // to the head of a page
table('signs', parseTSV(signs.trim()).rows.map((row, r) => row.map(({ content }, c) => ({
content, align: c === 0 ? 'center' : 'left', isHeader: r === 0 }))), [0.8, 2.1, 5.3],
t({ en: 'Where the signs come from.', es: 'De dónde vienen los signos.' }), 'here'),
];
يُبنى جدول الصدق من أدوات الربط نفسها: رأس كل عمود هو الصيغة، وكل خلية ما تعطيه الصيغة في ذلك الصف. خلايا الرأس بـ IBM Plex Sans Condensed العريض المائل، وخلايا المتن بـ Crimson Pro، وخط الرموز يخدم الاثنين. ونمطه القائم الوحيد يرسم لكل وزن وميل، فيكون ∧ في الرأس العريض و∈ في صيغة مائلة الرمزَ القائم نفسه. وترويسة الصفحة الفردية تطبع القسم الجاري {firstMark.h2}، وSETS: ∈, ∪, ∩ AND ∅ في الصفحة 3 تأخذ رموزها هي أيضًا من Noto Sans Math.

الوصفة كاملة
// ═══ Postext Cookbook · Nº 185 · Logic signs from a symbol font ═════════════════════
// https://postext.dev/en/cookbook/symbol-font-for-logic
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Crimson Pro, Cormorant Garamond, IBM Plex, Noto Sans Math (OFL) · Needs postext ≥ 1.73.0
// A primer of logical notation set in faces that have no ∀, no ∈, no ℵ and no Greek:
// symbolFont names Noto Sans Math, which draws those characters on the canvas and in the PDF.
import {
buildDocumentWithFonts, renderPageToCanvas, defaultResourceTypes, parseTSV, formatWarning,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'symbol-font-for-logic';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1f1c22', // text: a cool near-black
accent: '#7b2a3b', // claret: the opener band, labels, the table heads
tint: '#f4ece9', // the even rows of the truth table
rule: '#c3b4b2', // hairlines
muted: '#6a6064', // running heads, the colophon
paper: '#ffffff',
};
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: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
const TEXT = 'Crimson Pro', DISPLAY = 'Cormorant Garamond', LABEL = 'IBM Plex Sans Condensed';
const TRIM = [155, 235], INNER = 20, OUTER = 21, TOP = 23; // mm: a trade-size primer
const LEAD = 15; // pt: the body leading
// #region answer: one symbol font behind every face, on the canvas and in the PDF
// None of the three faces has ∀, ∈, ℵ or Greek. config.symbolFont (below) lists Noto Sans
// Math after every family the document names: what a face lacks is drawn from it, at the
// face's size and colour, in the canvas, the PDF, the HTML and the EPUB.
const SYMBOLS = 'Noto Sans Math';
// Fontsource serves Noto Sans Math whole in its "latin" file, and the kit would declare
// that file for the Latin range only. The screen and the PDF take it here with no range,
// so every glyph in it can be used.
const symbolFile = async () =>
`${await fontsourceAt('noto-sans-math')}files/noto-sans-math-latin-400-normal.woff2`;
const resolve = async (family, ...face) =>
(family === SYMBOLS ? [{ source: await symbolFile() }] : fontsourceResolver(family, ...face));
const pdfFonts = async (family, ...face) => (family !== SYMBOLS
? fontsourceProvider(family, ...face)
: decompressWoff2(new Uint8Array(await (await fetch(await symbolFile())).arrayBuffer())));
// #endregion
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#احذف الصفّ الأول
بعد قراءة التحذيرات يكفي صفٌّ واحد.
-const bare = await buildDocumentWithFonts({ markdown, resources }, { ...config, symbolFont: '' },
- fonts);
-console.info((bare.contentWarnings ?? []).filter((w) => w.kind === 'glyphFallbackAt')
- .map(formatWarning).join('\n'));أخطاء شائعة
تحذير الإخراج · glyphFallbackAt
محارف لا يملكها الخط هنا
السبب. فقرة فيها محارف لا يملكها خط نصها: حروف ومؤثرات رياضية (∪، ℵ)، يونانية في خط لاتيني، أسهم (glyphFallback يسمّي الخط، وهذا الفقرة). supplier العائلة التي ترسمها، وعادةً symbolFont؛ وبدونها يطبعها PDF مربعات فارغة.
الحل. حدّد symbolFont تحويها (يغطي Noto Sans Math معظم الرياضيات)، أو اختر عائلة نص تحويها. وإن كان المحرف خاطئًا (ألف عبرية حيث أراد المؤلف المتمِّمة)، فصحّح النص. التوثيق →
- الخط الذي تحوي ملفاته في Fontsource اليونانية (Source Serif 4، Alegreya) يصفّ φ وΓ بنفسه، وتحمّل العُدّة ذلك الملف حين يحوي النص يونانية، فلا يذهب إلى خط الرموز عندئذ إلا الرموز. ليس لـ Crimson Pro ملف يوناني، فتأتي يونانيته من Noto Sans Math.
- لخط الرموز نمط واحد، قائم عادي. العنوان العريض والصيغة المائلة يصفّان رموزهما بهذا النمط، وهكذا تطبعها كتب الرياضيات.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- The primer of logical notation, in English and Spanish · Ignacio Ferro · CC BY 4.0
- الخطوط
- Crimson Pro (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · IBM Plex Sans Condensed (SIL OFL 1.1) · Noto Sans Math (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


