かんたんな説明
『千夜一夜物語』の冒頭。各夜の見出しには番号をアラビア語の言葉で「第一夜」「第二夜」と書き、アラビア語の「夜」に合わせた女性形を使います。
できあがり
『千夜一夜物語』の冒頭から10ページを組みます。小扉に続いて、シャハラザードが最初に語る物語「商人と魔神」が3夜にわたって続きます。各夜は、小さなクーフィー体で組んだHindawi版の決まり文句فلما كانتと、その下に緑のルクア体で組んだ夜の番号で始まります。番号はالليلة الأولى、الليلة الثانية、الليلة الثالثةと、本に印刷されるとおり言葉で書きます。これらの番号はどれもMarkdownにはありません。見出しレベルが夜を数え、その数をليلةに一致する女性形の序数詞で書きます。物語は金の罫を引いた頭飾りの下で始まり、3人の老人の話にはそれぞれ小さな題が付き、柱には書名と物語の題が入ります。本文はHindawi財団の2022年版で、CC BY 4.0で公開されています。
このレシピが答える質問
- الليلة الأولىのように、章番号をアラビア語の序数詞で振るには?
手短な答え
// 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 };
材料
- 機能
- アラビア語の序数詞番号付き見出し見出しスタイル見出しの属性デザインした章扉右から左のテキスト右綴じの本アラビア語のフォント文書の言語としてのアラビア語生成される番号の数字柱とノンブル節ごとの柱ページの役割ごとの柱段落スタイル逆方向の段落用紙の色セマンティックカラーパレットPDFの書き出しPDFに埋め込むフォント
- 併用する機能
- 番号のない章
- 種類
- Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 夜を言葉で数える
コードは上の手短な答えにあります。夜はレベル2の見出し## الليلةで、そのレベルのnumberingTemplateは'الليلة {2:ordinal-feminine}'です。修飾子-feminineは、الأولى、الثانية、الحادية عشرة、الحادية بعد الألفと書きます(序数詞と基数詞、語で綴る番号)。numberPosition: 'replace'にすると番号が見出しの題のすべてになり、Markdownで##の後に書いたものは捨てられます。見出しもPDFのしおりも代替テキストも、الليلة الثانيةと読まれます。デザインはその題{titleText}を大きく印刷し、その上にHindawi版の決まり文句فلما كانتを固定のテキストとして小さく置きます。物語の見出しにはnumbered: falseのスタイルを使います。番号付きのレベル1だと物語ごとに夜の数が振り出しに戻りますが、番号なしならより深いカウンターに触れないので、夜は本全体を通して数え続けられます。

#2 · 物語ごとの頭飾り
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) },
] },
};
レベル1の見出しは2本の金の罫に挟まれた淡い色の帯です。その上にルクア体の物語の題を置き、見出し上のラベルとラテン文字の行は見出しの属性{kicker="…" latin="…"}から取ります。ラテン文字の行は、扉の中で版によって変わる唯一の部分です。
#3 · 物語とともに替わる柱
// 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) } } })] };
柱はtale見出しスタイルに属するので、物語ごとに自分の柱を持ち込みます。小扉には柱がありません。偶数ページには書名、奇数ページには{chapterTitle}、つまり物語の題が入ります。右綴じの本では偶数ページが右側のページになるので、そのノンブルは右上に置きます(ページの順序と右綴じ)。
#4 · ルクア体の小扉
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') }),
] } },
};
小扉はspan: 'page'、numbered: false、空のヘッダーとフッターを指定した見出しスタイルです。そのため番号を数えず、柱も付きません。
レシピの全体
// ═══ 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'),
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#第千一夜から始める
夜の見出しに{startAt=1001}を付けるとそのカウンターが設定され、テンプレートはالليلة الحادية بعد الألفと書きます(見出しの属性)。
-## الليلة
+## الليلة {startAt=1001}#百の位をブーラーク版の綴りにする
-classicalはمئةの代わりにمائةと書くので、第二百夜はالليلة المائتانになります。
- level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+ level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine-classical}', numberPosition: 'replace',#章を男性形で数える
修飾子がなければ序数詞は男性形になり、الفصلのような名詞に合います。الفصل الأول، الفصل الثاني。
- level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+ level: 2, numberingTemplate: 'الفصل {2:ordinal}', numberPosition: 'replace',よくあるつまずき
つまずき
アラビア語の本のタグはLANGではなく'ar'にする
レシピの版はenとesですが、アラビア語のサンプルはどちらの版でもアラビア語です。`locale: LANG`では左から右に組まれ、左綴じになり、ページ番号は1 2 3となり、図のキャプションにはFigureやFiguraが付きます。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、英語やスペイン語のタグでは、Markazi Textのようなフォントがギュメ(« »)や終止符をアラビア語の字形で描かず、改行の位置も変わります。タグは自分で書いてください。'ar'(アラビア・インド数字、マシュリク地域の慣習)、'ar-EG'や'ar-SA'のような地域付きのタグ、ヨーロッパ式数字を使うマグレブ版なら'ar-MA'、'ar-DZ'、'ar-TN'です。アラビア語を引用するだけのラテン文字のページは、自分のロケールのままにします。 右から左のテキスト →
つまずき
アラビア語の書体にはarabicブロックを通じてarabicファイルが必要
FontsourceはAmiri、Noto Naskh Arabic、Scheherazade Newをサブセットごとに1ファイルとして配信し、アラビア文字はarabicファイルに入っています。loadFontsが取得するのはlatin(とlatin-ext)だけなので、画面ではアラビア文字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、空の四角が印字されます。キットのarabicブロックを挙げ、loadFontsのあとにloadArabicFonts(FONTS, markdown)を呼び(ページでアラビア文字に使うすべてのウェイトをFONTSに挙げておきます)、renderToPdfにfontProvider: arabicPdfProviderを渡してください。 アラビア語のフォント →
クレジット
- 本文
- 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 · オリジナル
- フォント
- Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)


