Saltar al contenido principal
Receta número 185

Recetario · Capítulo 2 · Texto y tipografía

Signos de lógica y de conjuntos con una fuente de símbolos

Una cartilla de lógica en fuentes sin ∀, ∈ ni ℵ: symbolFont nombra Noto Sans Math, que dibuja esos signos y el griego en el lienzo y en el PDF.

En esta página
Salida
Canvas · PDF
Postext
Probada con Postext 1.73.0
Requiere ≥ 1.73.0 · postext-pdf ≥ 1.73.0
Licencia
Actualizada el 10 nov 2026
Código MIT · Texto CC BY 4.0
  • Formato 155 × 235 mm
  • 1 columna
  • Crimson Pro 11/15
  • Cormorant Garamond
  • IBM Plex Sans Condensed
  • 4 páginas
  • Nivel
  • Postext 1.73.0
  • Compuesto en 15 ms
  • 163 líneas de código

En pocas palabras

Un capítulo breve que enseña a leer los signos de la lógica y de la teoría de conjuntos. Las fuentes del libro no tienen esos signos, así que una segunda fuente los pone, en pantalla y en el PDF impreso.

Lo que vas a componer

El primer capítulo de una cartilla de lógica de bolsillo, en una página de 155 × 235 mm: una banda granate con los signos del capítulo a gran tamaño y después cuatro secciones que leen en voz alta ∀, ∃, ∈, ∪, ∅ y ℵ, con las fórmulas en el texto corrido y destacadas entre párrafos. El libro va en Crimson Pro, los títulos en Cormorant Garamond y los rótulos en IBM Plex Sans Condensed. Ninguna de las tres tiene ∀, ∈ ni una letra griega en los archivos que sirve Fontsource. Un solo ajuste, symbolFont, pone Noto Sans Math detrás de cada una, así que todos los signos salen de la misma fuente en el cuerpo, los títulos, las cabeceras y las celdas de las tablas, y el PDF los imprime todos.

Esta receta responde a

  • ¿Cómo imprimo los signos de lógica y de conjuntos (∀, ∈, ℵ) y el griego que no tiene mi fuente de texto, sin cajas vacías en el PDF?

La respuesta corta

script.js · líneas 34–47en el código completo
// 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())));

Ingredientes

Tipografía
Crimson Pro, Cormorant Garamond, IBM Plex Sans Condensed, Noto Sans Math (SIL OFL 1.1)
Recursos
Ninguno: todas las imágenes se dibujan en código

Elaboración

#1 · Una fuente de símbolos detrás de todas

El código de este paso es la respuesta corta, más arriba. symbolFont: 'Noto Sans Math' (fuente de símbolos) coloca esa familia detrás de todas las que nombra la configuración: un carácter que la fuente no tiene se dibuja con Noto Sans Math, al tamaño y en el color de la fuente, y el resto de la línea sigue en la suya. Fontsource sirve Noto Sans Math entera en su archivo latin, con 3033 caracteres, pero el kit declara ese archivo solo para el rango latino, y el navegador no le pediría ∀. El resolve y el pdfFonts de la receta entregan el mismo archivo sin rango, en pantalla y a renderToPdf. Solo cambian de fuente los caracteres que faltan: Crimson Pro tiene ¬, así que la negación del texto sigue en Crimson Pro.

#2 · Una primera composición sin ella enseña lo que falta

script.js · líneas 243–250en el código completo
// 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 primera composición deja symbolFont vacío e imprime sus avisos glyphFallbackAt, uno por cada párrafo, título o tabla que lleva caracteres para los que su fuente no tiene glifo, con la página y los caracteres. La edición inglesa da dieciocho: catorce párrafos en Crimson Pro, tres títulos en Cormorant Garamond y la fila de cabecera de la tabla 1.1 en IBM Plex Sans Condensed negrita. Sin una familia que los dibuje, el lienzo toma los signos de una fuente del sistema del lector y el PDF imprime una caja vacía por cada uno. La segunda composición, con la fuente de símbolos, es la que se ve en la página; sus avisos nombran "Noto Sans Math" como la familia que los dibuja.

#3 · Los signos de la apertura son texto

script.js · líneas 51–67en el código completo
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 línea de siete signos bajo el título es un texto de diseño en Cormorant Garamond a 30 pt, que toma su contenido del atributo signs del título. Cormorant Garamond no tiene ninguno, así que los siete salen de la fuente de símbolos, en el blanco de la banda. Un espaciado de 9 pt los reparte a lo ancho de la caja.

#4 · Las celdas y las cabeceras usan la misma fuente

script.js · líneas 212–230en el código completo
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 tabla de verdad se construye con las propias conectivas: la cabecera de cada columna es la fórmula, y cada celda, lo que la fórmula da en esa fila. Las celdas de cabecera van en IBM Plex Sans Condensed negrita cursiva y las del cuerpo en Crimson Pro; la fuente de símbolos sirve a las dos. Su única variante redonda dibuja para todos los pesos e inclinaciones, de modo que el ∧ de la cabecera en negrita y el ∈ de una fórmula en cursiva son el mismo signo recto. La cabecera de la página impar imprime la sección en curso, {firstMark.h2}, y CONJUNTOS: ∈, ∪, ∩ Y ∅, en la página 3, también toma sus signos de Noto Sans Math.

Página 3: las fórmulas de conjuntos, en Crimson Pro cursiva, con todos los signos de Noto Sans Math.

La receta completa

Sandbox
// ═══ 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 = 'es'; // @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

El script.js compuesto funciona tal cual: pégalo como script de módulo en cualquier página o abre la receta en CodePen. Carpeta de la receta en GitHub ↗ (se abre en una nueva pestaña)

Variantes

#Quita la primera composición

Leídos los avisos, basta con una composición.

-const bare = await buildDocumentWithFonts({ markdown, resources }, { ...config, symbolFont: '' },
-  fonts);
-console.info((bare.contentWarnings ?? []).filter((w) => w.kind === 'glyphFallbackAt')
-  .map(formatWarning).join('\n'));

Errores frecuentes

Aviso de maquetación · glyphFallbackAt

Caracteres que la fuente no tiene, aquí

Por qué. Un párrafo lleva caracteres que la fuente de su texto no tiene: letras y operadores matemáticos (∪, ℵ), griego en una fuente latina, flechas (glyphFallback nombra la fuente, este el párrafo). supplier es la familia que los dibuja, normalmente la symbolFont; sin ella, el PDF los imprime como cajas vacías.

Solución. Indica una symbolFont que los tenga (Noto Sans Math cubre casi toda la matemática) o elige una familia de texto que los tenga. Si el carácter está mal (una alef hebrea donde el autor quería un complemento), corrige el texto. Documentación →

  • Una fuente cuyos archivos de Fontsource incluyen el griego (Source Serif 4, Alegreya) compone φ y Γ por sí misma, y el kit carga ese archivo cuando el texto lleva griego: entonces solo los signos pasan a la fuente de símbolos. Crimson Pro no tiene archivo griego, así que su griego sale de Noto Sans Math.
  • La fuente de símbolos tiene una sola variante, redonda y regular. Un título en negrita o una fórmula en cursiva compone sus signos en esa variante, que es como los imprimen las matemáticas.

Créditos

Texto
  • La cartilla de notación lógica, en inglés y en español · Ignacio Ferro · CC BY 4.0
Fuentes
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)
SandboxPDF