Kurz gesagt
Der Anfang von Tausendundeiner Nacht, wo über jeder Nacht ihre Nummer in arabischen Worten steht, „die erste Nacht“, „die zweite Nacht“, in der femininen Form, die zum arabischen Wort für Nacht passt.
Was Sie setzen
Zehn Seiten vom Anfang von Tausendundeiner Nacht: ein Schmutztitel, dann „Der Kaufmann und der Dschinn“, die erste Geschichte, die Schahrazad erzählt und die sich über drei Nächte erstreckt. Jede Nacht beginnt mit Hindawis Formel فلما كانت in kleiner kufischer Schrift über ihrer Nummer in grüner Ruqʿa, الليلة الأولى, الليلة الثانية, الليلة الثالثة, ausgeschrieben, wie die Bücher sie drucken. Keine dieser Nummern steht im Markdown: Die Überschriftenebene zählt die Nächte und schreibt jede Zahl als feminine Ordnungszahl, die mit ليلة übereinstimmt. Die Geschichte beginnt unter einer goldlinierten Kopfleiste, die Erzählungen der drei alten Männer haben eigene kleine Titel, und die Kolumnentitel nennen Buch und Erzählung. Der Text ist die Ausgabe der Hindawi Foundation von 2022 unter CC BY 4.0.
Dieses Rezept beantwortet
- Wie nummeriere ich Kapitel mit arabischen Ordinalwörtern, etwa الليلة الأولى?
Die kurze Antwort
// 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 };
Zutaten
- Funktionen
- Arabische Ordnungszahlen in WortenNummerierte ÜberschriftenÜberschriftenformateÜberschriftenattributeGestaltete AuftakteText von rechts nach linksRechts gebundene BücherArabische SchriftenArabisch als DokumentspracheZiffern der erzeugten ZahlenKolumnentitel und SeitenzahlenKolumnentitel je AbschnittKopfzeilen nach SeitenrolleAbsatzformateAbsätze in der anderen RichtungPapierfarbeSemantische FarbpalettePDF-ExportIm PDF eingebettete Schriften
- Nutzt außerdem
- Kapitel ohne Nummer
- Schrift
- Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
- Dateien
- Keine: Jedes Bild wird im Code gezeichnet
Zubereitung
#1 · Nächte in Worten gezählt
Der Code steht oben in der kurzen Antwort. Eine Nacht ist eine Überschrift der Ebene 2, ## الليلة, und das numberingTemplate der Ebene lautet 'الليلة {2:ordinal-feminine}': Der Modifikator -feminine schreibt الأولى, الثانية, الحادية عشرة, الحادية بعد الألف (Ordnungs- und Grundzahlen in Worten, Ausgeschriebene Zahlen). Mit numberPosition: 'replace' ist die Nummer der ganze Titel der Überschrift: Was das Markdown nach ## sagt, entfällt, und Überschrift, PDF-Lesezeichen und Alternativtext lauten الليلة الثانية. Die Gestaltung setzt diesen Titel, {titleText}, groß und Hindawis Formel فلما كانت, einen festen Text, klein darüber. Die Überschriften der Erzählungen verwenden einen Stil mit numbered: false: Eine nummerierte Ebene 1 würde die Zählung der Nächte mit jeder Erzählung neu beginnen, eine unnummerierte lässt die tieferen Zähler in Ruhe, sodass die Nächte durch das ganze Buch weiterzählen.

#2 · Eine Kopfleiste für jede Erzählung
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) },
] },
};
Die Überschrift der Ebene 1 ist ein getöntes Band zwischen zwei goldenen Linien, darüber der Titel der Erzählung in Ruqʿa, eine Dachzeile und eine lateinische Zeile aus Attributen der Überschrift, {kicker="…" latin="…"}. Die lateinische Zeile ist der einzige Teil des Auftakts, der sich mit der Ausgabe ändert.
#3 · Kolumnentitel, die mit der Erzählung kommen
// 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) } } })] };
Die Kolumnentitel gehören zum Überschriftenstil tale, sodass jede Erzählung ihre eigenen mitbringt; der Schmutztitel hat keine. Auf der geraden Seite steht der Titel des Buchs, auf der ungeraden {chapterTitle}, die Erzählung. In einem rechts gebundenen Buch liegt die gerade Seite rechts, deshalb steht ihre Seitenzahl oben rechts (Seitenfolge und Bindung rechts).
#4 · Ein Schmutztitel in Ruqʿa
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') }),
] } },
};
Der Schmutztitel ist ein Überschriftenstil mit span: 'page', numbered: false und leerer Kopf- und Fußzeile, sodass er weder mitzählt noch einen Kolumnentitel hat.
Das ganze Rezept
// ═══ 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'),
Das zusammengesetzte script.js läuft unverändert: Fügen Sie es in das Modulskript einer beliebigen Seite ein, oder öffnen Sie das Rezept auf CodePen. Ordner des Rezepts auf GitHub ↗ (öffnet sich in einem neuen Tab)
Varianten
#Bei der tausendundersten Nacht beginnen
{startAt=1001} an einer Nachtüberschrift setzt ihren Zähler, und die Vorlage schreibt الليلة الحادية بعد الألف (Attribute von Überschriften).
-## الليلة
+## الليلة {startAt=1001}#Die Hunderter nach Art von Bulaq schreiben
-classical schreibt مائة statt مئة, sodass die zweihundertste Nacht الليلة المائتان lautet.
- level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+ level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine-classical}', numberPosition: 'replace',#Kapitel im Maskulinum nummerieren
Ohne Modifikator ist die Ordnungszahl maskulin, für ein Nomen wie الفصل: الفصل الأول، الفصل الثاني.
- level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+ level: 2, numberingTemplate: 'الفصل {2:ordinal}', numberPosition: 'replace',Häufige Fehler
Häufiger Fehler
Zeichnen Sie ein arabisches Buch mit 'ar' aus, nicht mit LANG
Die Ausgaben eines Rezepts sind en und es, ein arabisches Beispiel ist aber in beiden Arabisch: `locale: LANG` würde es von links nach rechts setzen, links binden, seine Seiten 1 2 3 nummerieren und seine Abbildungen mit Figure oder Figura beschriften. Seit postext 1.30 ist die Auszeichnung auch die Sprache, in der der Text geformt wird (gemessen, gezeichnet und eingebettet). Unter einer englischen oder spanischen Auszeichnung zeichnet eine Schrift wie Markazi Text daher die arabischen Formen ihrer Guillemets und Satzzeichen nicht, und die Zeilen brechen an anderer Stelle um. Schreiben Sie die Auszeichnung selbst: 'ar' (arabisch-indische Ziffern, die Maschrek-Konvention), eine Region wie 'ar-EG' oder 'ar-SA', oder 'ar-MA', 'ar-DZ' bzw. 'ar-TN' für eine Maghreb-Ausgabe mit europäischen Ziffern. Eine lateinische Seite, die Arabisch nur zitiert, behält ihr eigenes Gebietsschema. Text von rechts nach links →
Häufiger Fehler
Arabische Schnitte brauchen ihre arabic-Datei, über den Block arabic
Fontsource liefert Amiri, Noto Naskh Arabic oder Scheherazade New als eine Datei pro Teilmenge aus, und die arabischen Buchstaben stehen in der Datei arabic. loadFonts holt nur latin (und latin-ext), am Bildschirm stammt das Arabische also aus einer Systemschrift und wird falsch gemessen, und fontsourceProvider gibt dem PDF diese latin-Datei, die leere Kästchen druckt. Führen Sie den Kit-Block arabic auf, rufen Sie loadArabicFonts(FONTS, markdown) nach loadFonts auf, mit jeder Schriftstärke, die die Seiten auf Arabisch setzen, in FONTS aufgeführt, und geben Sie renderToPdf fontProvider: arabicPdfProvider. Arabische Schriften →
Nachweise
- Rezept
- Ignacio Ferro
- Text
- 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 · eigener Text
- Schriften
- Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
- Code
- MIT, wie Postext
Diesen Text bearbeiten ↗ (öffnet sich in einem neuen Tab)Ordner des Rezepts auf GitHub ↗ (öffnet sich in einem neuen Tab)


