In breve
Un breve capitolo che insegna a leggere i segni della logica e della teoria degli insiemi. I font del libro non hanno quei segni, così un secondo font li fornisce, a schermo e nel PDF stampato.
Che cosa comporrai
Il primo capitolo di un manualetto tascabile di logica, su una pagina di 155 × 235 mm: una fascia granata con i segni del capitolo in grande, poi quattro sezioni che leggono ad alta voce ∀, ∃, ∈, ∪, ∅ e ℵ, con le formule nel testo corrente e in evidenza fra i paragrafi. Il libro è composto in Crimson Pro, i titoli in Cormorant Garamond e le etichette in IBM Plex Sans Condensed. Nessuno dei tre ha ∀, ∈ o una lettera greca nei file che serve Fontsource. Una sola impostazione, symbolFont, mette Noto Sans Math dietro a ciascuno: tutti i segni vengono dallo stesso font nel testo, nei titoli, nelle testatine e nelle celle delle tabelle, e il PDF li stampa tutti.
Questa ricetta risponde a
- Come stampo i segni di logica e di insiemi (∀, ∈, ℵ) e il greco che il mio font di testo non ha, senza riquadri vuoti nel PDF?
La risposta breve
// 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())));
Ingredienti
- Funzionalità
- Font dei simboliFont incorporati nel PDFI font prima dell’impaginazioneApici e pediciStili di paragrafoTabelle dai datiStile delle tabelleAperture progettateAttributi dei titoliTestatine e folioMargini speculariTavolozza di colori semanticaEsportazione in PDF
- Usa anche
- Figure proprio quiFigura e Tabella nella tua linguaTestatine secondo il ruolo della paginaTipi di risorsa personalizzati
- Tipo
- Crimson Pro, Cormorant Garamond, IBM Plex Sans Condensed, Noto Sans Math (SIL OFL 1.1)
- Risorse
- Nessuna: ogni immagine è disegnata nel codice
Preparazione
#1 · Un font dei simboli dietro a tutti gli altri
Il codice di questo passo è la risposta breve, più sopra. symbolFont: 'Noto Sans Math' (font dei simboli) mette quella famiglia dietro a tutte quelle che la configurazione nomina: un carattere che il font non ha viene disegnato in Noto Sans Math, al corpo e nel colore del font, e il resto della riga resta nel suo. Fontsource serve Noto Sans Math intero nel file latin, 3033 caratteri, ma il kit dichiara quel file solo per l’intervallo latino, e il browser non gli chiederebbe ∀. Il resolve e il pdfFonts della ricetta passano lo stesso file senza intervallo, a schermo e a renderToPdf. Cambiano font solo i caratteri che mancano: Crimson Pro ha ¬, quindi la negazione nel testo resta in Crimson Pro.
#2 · Una prima composizione senza mostra che cosa manca
// 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'));
La prima composizione lascia symbolFont vuoto e stampa i suoi avvisi glyphFallbackAt, uno per ogni paragrafo, titolo o tabella che contiene caratteri per cui il suo font non ha glifo, con la pagina e i caratteri. L’edizione inglese ne conta diciotto: quattordici paragrafi in Crimson Pro, tre titoli in Cormorant Garamond e la riga d’intestazione della tabella 1.1 in IBM Plex Sans Condensed neretto. Senza una famiglia che li disegni, il canvas prende i segni da un font di sistema del lettore e il PDF stampa un riquadro vuoto per ciascuno. La seconda composizione, con il font dei simboli, è quella che si vede sulla pagina; i suoi avvisi nominano "Noto Sans Math" come la famiglia che li disegna.
#3 · I segni dell’apertura sono testo
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) },
] } };
La riga di sette segni sotto il titolo è un testo di design in Cormorant Garamond a 30 pt, alimentato dall’attributo signs del titolo. Cormorant Garamond non ne ha nessuno, così tutti e sette vengono dal font dei simboli, nel bianco della fascia. Una spaziatura di 9 pt li distribuisce sulla giustezza.
#4 · Celle e testatine usano lo stesso font
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'),
];
La tavola di verità si costruisce con i connettivi stessi: l’intestazione di ogni colonna è la formula, e ogni cella ciò che la formula dà in quella riga. Le celle d’intestazione sono in IBM Plex Sans Condensed neretto corsivo e quelle del corpo in Crimson Pro; il font dei simboli serve entrambe. Il suo unico stile tondo disegna per ogni peso e inclinazione, così il ∧ dell’intestazione in neretto e il ∈ di una formula in corsivo sono lo stesso segno diritto. La testatina della pagina dispari stampa la sezione in corso, {firstMark.h2}, e SETS: ∈, ∪, ∩ AND ∅, a pagina 3, prende anch’essa i segni da Noto Sans Math.

La ricetta completa
// ═══ 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
Lo script.js composto funziona così com’è: incollalo nello script modulo di qualsiasi pagina, oppure apri la ricetta su CodePen. Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)
Varianti
#Togli la prima composizione
Letti gli avvisi, basta una composizione.
-const bare = await buildDocumentWithFonts({ markdown, resources }, { ...config, symbolFont: '' },
- fonts);
-console.info((bare.contentWarnings ?? []).filter((w) => w.kind === 'glyphFallbackAt')
- .map(formatWarning).join('\n'));Errori frequenti
Avviso di impaginazione · glyphFallbackAt
Caratteri che il font non ha, qui
Perché. Un paragrafo contiene caratteri che il font del suo testo non ha: lettere e operatori matematici (∪, ℵ), greco in un font latino, frecce (glyphFallback nomina il font, questo il paragrafo). supplier è la famiglia che li disegna, di solito la symbolFont; senza, il PDF li stampa come caselle vuote.
Soluzione. Indica una symbolFont che li contenga (Noto Sans Math copre quasi tutta la matematica) o scegli una famiglia di testo che li abbia. Se il carattere è sbagliato (un aleph ebraico dove l’autore voleva un complementare), correggi il testo. Documentazione →
- Un font i cui file Fontsource comprendono il greco (Source Serif 4, Alegreya) compone da sé φ e Γ, e il kit carica quel file quando il testo contiene greco: allora passano al font dei simboli solo i segni. Crimson Pro non ha un file greco, quindi il suo greco viene da Noto Sans Math.
- Il font dei simboli ha un solo stile, tondo e normale. Un titolo in neretto o una formula in corsivo compone i segni in quello stile, come li stampa la matematica.
Crediti
- Ricetta
- Ignacio Ferro
- Testo
- The primer of logical notation, in English and Spanish · Ignacio Ferro · CC BY 4.0
- Font
- 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)
- Codice
- MIT, come Postext
Modifica questo testo ↗ (si apre in una nuova scheda)Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)


