Pular para o conteúdo principal
Receita número 112

Receitas · Capítulo 3 · Títulos e aberturas

Títulos com ordinais árabes por extenso: a primeira noite…

Um modelo de nível escreve cada noite como الليلة e um ordinal feminino, الليلة الأولى, الثانية, الثالثة, sem que o Markdown traga número nenhum.

Nesta página
Saída
Canvas · PDF
Postext
Testada com o Postext 1.65.0
Requer ≥ 1.25.0 · postext-pdf ≥ 1.25.0
Licença
Atualizada em 10 de out. de 2026
Código MIT · Texto MIT

p. ٢–٣ · 2–3 de 10

  • Amostra em inglês: ainda sem edição em português
  • Refile 170 × 240 mm
  • 1 coluna
  • Amiri 13/26
  • Aref Ruqaa
  • Noto Kufi Arabic
  • 10 páginas
  • Nível
  • Postext 1.65.0
  • Diagramado em 129 ms
  • 158 linhas de código

Em poucas palavras

O começo das Mil e uma noites, em que cada noite traz o número escrito por extenso em árabe, “a primeira noite”, “a segunda noite”, na forma feminina que concorda com a palavra árabe para noite.

O que você vai compor

Dez páginas do começo das Mil e uma noites: uma falsa folha de rosto e depois O mercador e o gênio, o primeiro conto que Sherazade narra, que se estende por três noites. Cada noite abre com a fórmula de Hindawi, فلما كانت, em cúfico pequeno sobre o número em ruqʿa verde, الليلة الأولى, الليلة الثانية, الليلة الثالثة, escrito por extenso como os livros o imprimem. Nenhum desses números está no Markdown: o nível de título conta as noites e escreve cada número como um ordinal feminino, que concorda com ليلة. O conto abre sob um cabeção entre fios dourados, as histórias dos três velhos têm os próprios títulos pequenos, e os cabeços trazem o livro e o conto. O texto é a edição de 2022 da Fundação Hindawi, sob CC BY 4.0.

Esta receita responde a

  • Como numero os capítulos com ordinais árabes por extenso, como الليلة الأولى?

A resposta curta

script.js · linhas 34–54no código 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 };

Ingredientes

Tipografia
Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
Materiais
Nenhum: todas as imagens são desenhadas em código

Preparo

#1 · Noites contadas por extenso

O código é a resposta curta acima. Uma noite é um título de nível 2, ## الليلة, e o numberingTemplate do nível é 'الليلة {2:ordinal-feminine}': o modificador -feminine escreve الأولى, الثانية, الحادية عشرة, الحادية بعد الألف (Ordinais e cardinais por extenso, Números por extenso). Com numberPosition: 'replace', o número é o título inteiro: o que o Markdown disser depois de ## é descartado, e o título, os marcadores do PDF e o texto alternativo dizem الليلة الثانية. O design imprime esse título, {titleText}, em tamanho grande, e a fórmula de Hindawi, فلما كانت, um texto fixo, em tamanho pequeno acima dele. Os títulos dos contos usam um estilo com numbered: false: um nível 1 numerado reiniciaria a contagem das noites a cada conto, enquanto um sem número deixa os contadores mais profundos em paz, e as noites continuam correndo pelo livro inteiro.

Página 5: a segunda noite, com o número escrito pelo modelo e impresso como o título inteiro.

#2 · Um cabeção para cada conto

script.js · linhas 58–75no código 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) },
  ] },
};

O título de nível 1 é uma faixa de cor entre dois fios dourados, com o título do conto em ruqʿa sobre ela e um chapéu e uma linha em latim tirados de atributos do título, {kicker="…" latin="…"}. A linha em latim é a única parte da abertura que muda com a edição.

#3 · Cabeços que chegam com o conto

script.js · linhas 79–93no código 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) } } })] };

Os cabeços pertencem ao estilo de título tale, por isso cada conto traz os seus; a falsa folha de rosto não tem nenhum. A página par leva o título do livro e a ímpar {chapterTitle}, o conto. Num livro encadernado pela direita, a página par fica à direita, e por isso o fólio dela vai no alto à direita (Ordem das páginas e encadernação pela direita).

#4 · Uma falsa folha de rosto em ruqʿa

script.js · linhas 97–115no código 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') }),
  ] } },
};

A falsa folha de rosto é um estilo de título com span: 'page', numbered: false e cabeçalho e rodapé vazios, de modo que não conta nem leva cabeço.

A receita 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'),

O script.js montado funciona como está: cole-o como script de módulo em qualquer página ou abra a receita no CodePen. Pasta da receita no GitHub ↗ (abre em uma nova aba)

Variações

#Começar na noite mil e um

{startAt=1001} num título de noite define o contador dele, e o modelo escreve الليلة الحادية بعد الألف (Atributos de título).

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

#Escrever as centenas à maneira de Bulaq

-classical escreve مائة no lugar de مئة, e a ducentésima noite fica الليلة المائتان.

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

#Numerar capítulos no masculino

Sem modificador, o ordinal é masculino, para um substantivo como الفصل: الفصل الأول، الفصل الثاني.

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

Erros comuns

Erro comum

Marque um livro árabe como 'ar', não com LANG

As edições de uma receita são en e es, mas uma amostra árabe é árabe nas duas: `locale: LANG` a comporia da esquerda para a direita, a encadernaria pela esquerda, numeraria as suas páginas 1 2 3 e chamaria as suas figuras de Figure ou Figura. Desde o postext 1.30 a marcação é também o idioma em que o texto é composto (em que é medido, pintado e incorporado), então, sob uma marcação inglesa ou espanhola, uma fonte como a Markazi Text não desenha as formas árabes das aspas angulares e dos pontos, e as linhas quebram em outro ponto. Escreva você mesmo a marcação: 'ar' (algarismos arábico-índicos, a convenção do Machrek), uma região como 'ar-EG' ou 'ar-SA', ou 'ar-MA', 'ar-DZ' ou 'ar-TN' para uma edição magrebina com algarismos europeus. Uma página latina que só cita árabe mantém o seu próprio locale. Texto da direita para a esquerda →

Erro comum

Fontes árabes precisam do seu arquivo arabic, pelo bloco arabic

O Fontsource serve Amiri, Noto Naskh Arabic ou Scheherazade New em um arquivo por subconjunto, e as letras árabes estão no arquivo arabic. loadFonts baixa só latin (e latin-ext), então na tela o árabe vem de uma fonte do sistema e é medido errado, e o fontsourceProvider entrega ao PDF esse arquivo latin, que imprime caixas vazias. Inclua o bloco arabic do kit, chame loadArabicFonts(FONTS, markdown) depois de loadFonts, com todos os pesos que as páginas usam em árabe listados em FONTS, e passe a renderToPdf fontProvider: arabicPdfProvider. Fontes árabes →

Créditos

Texto
  • 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 · original
Fontes
Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
SandboxPDF