Vai al contenuto principale
Ricetta numero 112

Ricettario · Capitolo 3 · Titoli e aperture

Titoli in ordinali arabi in lettere: la prima notte…

Un modello di livello scrive ogni notte come الليلة e un ordinale femminile, الليلة الأولى, الثانية, الثالثة, così il Markdown non contiene mai un numero.

In questa pagina
Output
Canvas · PDF
Livello
Intermedio
Postext
Provata con Postext 1.65.0
Richiede ≥ 1.25.0 · postext-pdf ≥ 1.25.0
Licenza
Aggiornata il 10 ott 2026
Codice MIT · Testo MIT

pp. ٢–٣ · 2–3 di 10

  • Esempio in inglese: non c’è ancora un’edizione italiana
  • Formato 170 × 240 mm
  • 1 colonna
  • Amiri 13/26
  • Aref Ruqaa
  • Noto Kufi Arabic
  • 10 pagine
  • Livello
  • Postext 1.65.0
  • Impaginato in 129 ms
  • 158 righe di codice

In breve

L’inizio delle Mille e una notte, dove ogni notte ha come titolo il suo numero scritto in parole arabe, «la prima notte», «la seconda notte», nella forma femminile che si accorda con la parola araba per notte.

Che cosa comporrai

Dieci pagine dall’inizio delle Mille e una notte: un occhiello, poi Il mercante e il genio, il primo racconto di Shahrazad, che si estende su tre notti. Ogni notte si apre con la formula di Hindawi فلما كانت in piccolo cufico sopra il suo numero in ruqʿa verde, الليلة الأولى, الليلة الثانية, الليلة الثالثة, scritto in lettere come lo stampano i libri. Nessuno di quei numeri è nel Markdown: il livello di titolo conta le notti e scrive ogni conteggio come ordinale femminile, che si accorda con ليلة. Il racconto si apre sotto una testata con filetti d’oro, le storie dei tre vecchi hanno i loro piccoli titoli e le testatine riportano il libro e il racconto. Il testo è l’edizione del 2022 della Fondazione Hindawi, con licenza CC BY 4.0.

Questa ricetta risponde a

  • Come numero i capitoli con ordinali arabi in lettere, come الليلة الأولى?

La risposta breve

script.js · righe 34–54nel codice completo
// In the Markdown a night is a level-2 heading with no number: ## الليلة
// The level's template writes الليلة and the counter as a feminine ordinal, which agrees
// with the noun: الليلة الأولى، الليلة الثانية، الليلة الثالثة … الليلة الحادية بعد الألف.
// numberPosition 'replace' makes that number the whole title, so the heading, the PDF
// bookmarks and the alt text read الليلة الثانية. Hindawi's formula is a fixed design text.
const nights = {
  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
  marginTop: pt(LEAD), marginBottom: pt(LEAD / 2),
  advancedDesign: { enabled: true, minHeight: mm(18), slot: { elements: [
    { kind: 'text', id: 'formula', content: 'فلما كانت', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8), align: 'center', color: col('muted'), placement: top(0) },
    { kind: 'text', id: 'night', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(21), lineHeight: 1.2, align: 'center', color: col('accent'),
      placement: top(4.5) },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...top(16), size: { width: mm(16) } } },
  ] } },
};
// A tale does not count: an unnumbered heading leaves the deeper counters alone, so the
// nights run on from one tale to the next instead of starting again at الأولى.
const tale = { numbered: false, runningChapter: true };

Ingredienti

Tipo
Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
Risorse
Nessuna: ogni immagine è disegnata nel codice

Preparazione

#1 · Notti contate in lettere

Il codice è la risposta breve qui sopra. Una notte è un titolo di livello 2, ## الليلة, e il numberingTemplate del livello è 'الليلة {2:ordinal-feminine}': il modificatore -feminine scrive الأولى, الثانية, الحادية عشرة, الحادية بعد الألف (numeri ordinali e cardinali in lettere, numeri in lettere). Con numberPosition: 'replace' il numero è l’intero titolo: ciò che il Markdown scrive dopo ## viene scartato, e il titolo, i segnalibri del PDF e il testo alternativo leggono الليلة الثانية. La grafica stampa quel titolo, {titleText}, in grande, e la formula di Hindawi فلما كانت, un testo fisso, in piccolo sopra. I titoli dei racconti usano uno stile con numbered: false: un livello 1 numerato farebbe ripartire il conteggio delle notti a ogni racconto, mentre uno non numerato lascia stare i contatori più profondi, così le notti proseguono per tutto il libro.

Pagina 5: la seconda notte, con il numero scritto in lettere dal modello e stampato come intero titolo.

#2 · Una testata per ogni racconto

script.js · righe 58–75nel codice completo
const rule = (id, y, thickness) => ({ kind: 'rule', id, direction: 'horizontal',
  thickness: pt(thickness), color: col('gold'),
  placement: { ...top(y), size: { width: 'fill' } } });
const opener = {
  enabled: true, minHeight: mm(50),
  slot: { elements: [
    { kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
      placement: { ...top(4), size: { width: 'fill', height: mm(30) } } },
    rule('band-top', 4, 1.2), rule('band-foot', 34, 0.5),
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8.5), align: 'center', color: col('muted'), placement: top(7.5) },
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(30), lineHeight: 1.15, align: 'center', color: col('accent'),
      placement: top(13) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', fontFamily: NASKH, italic: true,
      fontSize: pt(9.5), align: 'center', color: col('muted'), placement: top(39) },
  ] },
};

Il titolo di livello 1 è una fascia colorata tra due filetti d’oro, con il titolo del racconto in ruqʿa sopra, un occhiello e una riga latina presi dagli attributi del titolo, {kicker="…" latin="…"}. La riga latina è l’unica parte dell’apertura che cambia con l’edizione.

#3 · Testatine che arrivano con il racconto

script.js · righe 79–93nel codice completo
// Running heads stay on the sheet's sides: in a book bound on the right the verso (even)
// is the right-hand page, so its outer edge, where the folio goes, is the right one.
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content,
  parity, pages: 'body', fontFamily: KUFI, fontWeight: 500, fontSize: pt(8.5),
  color: col('muted'), placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(12) } },
  ...extra });
const taleHeads = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-right', -OUTER, { color: col('accent') }),
  head('verso-book', '{title}', 'even', 'top-right', -(OUTER + 10)),
  head('recto-tale', '{chapterTitle}', 'odd', 'top-left', OUTER + 10),
  head('recto-folio', '{pageNumber}', 'odd', 'top-left', OUTER, { color: col('accent') }),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'bottom', 0, {
  pages: 'opener', color: col('accent'),
  placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-12) } } })] };

Le testatine appartengono allo stile di titolo tale, così ogni racconto ha le sue; l’occhiello non ne ha. Il verso riporta il titolo del libro e il recto {chapterTitle}, il racconto. In un libro rilegato a destra il verso è la pagina destra, quindi il suo numero di pagina va in alto a destra (ordine delle pagine e rilegatura a destra).

#4 · Un occhiello in ruqʿa

script.js · righe 97–115nel codice completo
const at = (y) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) } });
const line = (id, content, y, style) => ({ kind: 'text', id, content, align: 'center',
  overflow: 'wrap', color: col('ink'), placement: at(y), ...style });
const titlePage = {
  id: 'title', span: 'page', numbered: false, runningChapter: false,
  breakBefore: { enabled: true, parity: 'any' }, header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'rule', id: 'over', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...at(62), size: { width: mm(40) } } },
    line('book', '{titleText}', 70, { fontFamily: RUQAA, fontWeight: 700, fontSize: pt(54),
      lineHeight: 1.25, color: col('accent') }),
    { kind: 'rule', id: 'under', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...at(100), size: { width: mm(40) } } },
    line('volume', '{attr.kicker}', 106, { fontFamily: KUFI, fontWeight: 500, fontSize: pt(11),
      color: col('accent') }),
    line('latin', '{attr.latin}', 150, { fontFamily: NASKH, fontSize: pt(9.5), italic: true,
      color: col('muted') }),
  ] } },
};

L’occhiello è uno stile di titolo con span: 'page', numbered: false e intestazione e piè di pagina vuoti, così non conta e non ha testatina.

La ricetta completa

Sandbox
// ═══ Postext Cookbook · Nº 112 · Night headings in Arabic ordinal words ═══════════
// https://postext.dev/en/cookbook/nights-ordinal-headings
// Code: MIT · Text: Alf layla wa-layla, Hindawi Foundation 2022 (CC BY 4.0) · Pictures: none
// Fonts: Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, withLoadedFonts, renderPageToCanvas } 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 = 'nights-ordinal-headings';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text, a deep green for the titles and a gold hairline, on a cream paper.
const palette = {
  ink: '#1c1a17', // text: a warm near-black
  accent: '#1f564c', // titles, night headings, folios
  gold: '#a8833a', // the rules under the nights and around the headpiece
  tint: '#ebe3cc', // the headpiece band
  muted: '#5e594f', // running heads, kickers, the note on the text
  paper: '#faf6ec', // a cream paper
};
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 NASKH = 'Amiri'; // the text and the sub-tale titles
const RUQAA = 'Aref Ruqaa'; // display: the book, the tale, the nights
const KUFI = 'Noto Kufi Arabic'; // labels: kickers, running heads, folios
const [SIZE, LEAD] = [13, 26]; // pt: 2 × the size: a ḍamma over a hamza clears the line above
const [OUTER, TOP] = [18, 22]; // mm: a 17 × 24 cm book
const top = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });

// #region answer: the night's number in feminine ordinal words, from a level template
// In the Markdown a night is a level-2 heading with no number: ## الليلة
// The level's template writes الليلة and the counter as a feminine ordinal, which agrees
// with the noun: الليلة الأولى، الليلة الثانية، الليلة الثالثة … الليلة الحادية بعد الألف.
// numberPosition 'replace' makes that number the whole title, so the heading, the PDF
// bookmarks and the alt text read الليلة الثانية. Hindawi's formula is a fixed design text.
const nights = {
  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
  marginTop: pt(LEAD), marginBottom: pt(LEAD / 2),
  advancedDesign: { enabled: true, minHeight: mm(18), slot: { elements: [
    { kind: 'text', id: 'formula', content: 'فلما كانت', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8), align: 'center', color: col('muted'), placement: top(0) },
    { kind: 'text', id: 'night', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(21), lineHeight: 1.2, align: 'center', color: col('accent'),
      placement: top(4.5) },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),

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

#Comincia dalla notte mille e uno

{startAt=1001} su un titolo di notte imposta il suo contatore, e il modello scrive الليلة الحادية بعد الألف (attributi del titolo).

-## الليلة
+## الليلة {startAt=1001}

#Scrivi le centinaia alla maniera di Bulaq

-classical scrive مائة per مئة, così la duecentesima notte si legge الليلة المائتان.

-  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine-classical}', numberPosition: 'replace',

#Numera i capitoli al maschile

Senza modificatore l’ordinale è maschile, per un nome come الفصل: الفصل الأول، الفصل الثاني.

-  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+  level: 2, numberingTemplate: 'الفصل {2:ordinal}', numberPosition: 'replace',

Errori frequenti

Errore frequente

Assegna a un libro arabo il tag 'ar', non LANG

Le edizioni di una ricetta sono en ed es, ma un esempio arabo è arabo in entrambe: `locale: LANG` lo comporrebbe da sinistra a destra, lo rilegherebbe a sinistra, numererebbe le pagine 1 2 3 e darebbe alle figure didascalie Figure o Figura. Da postext 1.30 il tag è anche la lingua usata per lo shaping del testo (misura, disegno e incorporamento), quindi con un tag inglese o spagnolo un carattere come Markazi Text non disegna le forme arabe delle sue virgolette basse e dei suoi segni di interpunzione, e le righe vanno a capo altrove. Scrivi tu il tag: 'ar' (cifre arabo-indiane, la convenzione del Mashriq), una regione come 'ar-EG' o 'ar-SA', oppure 'ar-MA', 'ar-DZ' o 'ar-TN' per un’edizione del Maghreb con cifre europee. Una pagina latina che si limita a citare l’arabo mantiene la propria lingua. Testo da destra a sinistra →

Errore frequente

I caratteri arabi hanno bisogno del loro file arabic, tramite il blocco arabic

Fontsource serve Amiri, Noto Naskh Arabic o Scheherazade New come un file per sottoinsieme, e le lettere arabe stanno nel file arabic. loadFonts scarica solo latin (e latin-ext), così a schermo l’arabo viene da un font di sistema ed è misurato male, e fontsourceProvider passa al PDF quel file latin, che stampa riquadri vuoti. Elenca il blocco arabic del kit, chiama loadArabicFonts(FONTS, markdown) dopo loadFonts, con ogni peso che le pagine compongono in arabo elencato in FONTS, e passa a renderToPdf fontProvider: arabicPdfProvider. Font arabi →

Crediti

Testo
  • The Merchant and the Jinni, nights 1 to 3 of Alf layla wa-layla, from the Hindawi Foundation edition (2022, vol. 1), with its vowels and punctuation · Hindawi Foundation · CC BY 4.0
  • The kickers in Arabic, the note on the text and the colophon · Postext Cookbook · originale
Font
Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
SandboxPDF