かんたんな説明
論理学と集合論の記号の読み方を教える短い章です。本の書体にはこれらの記号がないため、二つ目の書体が画面でも印刷用の PDF でも補います。
できあがり
ポケット判の論理学の手引きの第 1 章、判型は 155 × 235 mm です。章の記号を大きく組んだ臙脂の帯のあと、∀・∃・∈・∪・∅・ℵ を一つずつ読み上げる四つの節が続き、数式は本文の中にも段落の間にも置かれます。本文は 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 ファイルに収めていて 3,033 字ありますが、キットはこのファイルをラテン文字の範囲にしか宣言しないので、ブラウザーは ∀ をこのファイルに求めません。このレシピの 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) },
] } };
タイトルの下の七つの記号の行は、30 pt の Cormorant Garamond で組んだデザイン用のテキストで、見出しの 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} を印刷し、3 ページの SETS: ∈, ∪, ∩ AND ∅ もやはり 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はそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピを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 から出ます。
- 記号フォントにはローマン体のレギュラーが一つしかありません。ボールドの見出しでもイタリックの式でも記号はこの書体で組まれ、数学の本の印刷もそうなっています。
クレジット
- 本文
- 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)


