In short
A classical Arabic poem printed the way old poetry books print it: every line split into two halves that stand side by side, both halves stretched to the same width so their ends line up down the page.
What you'll build
Four pages of a diwan, the collected poems of al-Mutanabbī, as Cairo printers set them a century ago: a half-title with ديوان in red Ruqʿa, then the qaṣīda he recited before Sayf al-Dawla in 954, under a red-ruled headpiece. Each of the forty-six bayts is one line of two hemistichs, the ṣadr on the right and the ʿajuz on the left, both stretched with kashidas to one width, so the rhymes in ‑mu run down the left edge in a straight line. The book is bound on the right and the folios count in Arabic-Indic digits. Only the note on the text, at the end, changes with the edition. Tang poems facing their English verse sets classical Chinese verse on its own grid.
This recipe answers
- How do I set classical Arabic verse with each line in two hemistichs?
The short answer
// In the Markdown, a :::verse block takes one bayt a line, the ṣadr and the ʿajuz parted
// by ||:
// :::verse{style="bayt"}
// عَلى قَدْرِ أهْلِ العَزْم تأتي العَزائِمُ || وَتأتي علَى قَدْرِ الكِرامِ المَكارمُ
// :::
// The ṣadr goes on the right, the ʿajuz on the left, both stretched to the width of the
// widest half with a gap of 2 em between them. The style gives the poem its face and a
// leading deep enough for the harakat: 1.9 × the size.
const bayt = { id: 'bayt', fontFamily: NASKH, fontSize: pt(14), lineHeight: pt(26.6),
color: col('ink'), marginTop: pt(LEAD / 2), marginBottom: pt(LEAD) };
// Justified lines lengthen their words with kashidas (tatweel) before they open the
// spaces wide: 'auto' is the default in an Arabic document, written out here to say so.
// A hemistich may stretch a word twice as far as a line of prose does: 1.2 em.
const bodyKashida = { kashida: 'auto', kashidaPatterns: 'naskh', kashidaMaxLength: 0.6 };
One bayt a line, both hemistichs stretched to one width
Ingredients
- Features
- Arabic verse (bayt in two hemistichs)Kashida justificationRight-to-left textArabic fontsArabic as the document languageBooks bound on the rightDigits of the generated numbersDesigned openersHeading attributesHeading stylesCovers, title pages and colophonsRunning heads and foliosHeads by page rolePaper colourParagraph stylesParagraphs in the other directionSemantic colour palettePDF exportFonts embedded in the PDF
- Also uses
- Running heads per section
- Type
- Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · One bayt a line, both halves to one width
The code is the short answer above. Inside :::verse each line is a bayt, and || parts the two hemistichs, so the Markdown reads like the Wikisource text it came from (:::verse). The poem measures every hemistich, takes the widest half as the width of both columns (up to half the measure less the gap) and fills each half to that width, with kashidas first and the word spaces after (Classical verse). The bayt style is set at 14 pt on a 26.6 pt pitch, 1.9 × the size, so the shaddas and kasras of adjacent lines do not meet (Vowel marks). The trim is 17 × 24 cm: at 14 × 21 cm a third of the bayts did not fit their half of the 104 mm measure and fell back to a staggered layout, ṣadr and ʿajuz on lines of their own.

#2 · A headpiece band in Ruqʿa
const rule = (id, y, thickness) => ({ kind: 'rule', id, direction: 'horizontal',
thickness: pt(thickness), color: col('rubric'),
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) },
size: { width: 'fill' } } });
const opener = {
enabled: true, minHeight: mm(46),
slot: { elements: [
{ kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(4) },
size: { width: 'fill', height: mm(26) } } },
rule('band-top', 4, 1.5), rule('band-foot', 30, 0.5),
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
fontSize: pt(34), lineHeight: 1.1, align: 'center', color: col('rubric'),
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(7.5) } } },
{ kind: 'text', id: 'metre', content: '{attr.metre}', fontFamily: KUFI, fontWeight: 500,
fontSize: pt(9), align: 'center', color: col('muted'),
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(35) } } },
] },
};
The level-1 heading is drawn by its design: a tinted box ruled in red above and below, the title centred over it in Aref Ruqaa, and the metre under it from a heading attribute, {metre="من البحر الطويل"}. Display type in Ruqʿa takes no kashida, so the title keeps its natural width (Justification and kashida).
#3 · Running heads on the sheet’s sides
// 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 header = { elements: [
head('verso-folio', '{pageNumber}', 'even', 'top-right', -OUTER, { color: col('ink') }),
head('verso-book', '{title}', 'even', 'top-right', -(OUTER + 10)),
head('recto-rhyme', '{subtitle}', 'odd', 'top-left', OUTER + 10),
head('recto-folio', '{pageNumber}', 'odd', 'top-left', OUTER, { color: col('ink') }),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'bottom', 0, {
pages: 'opener', color: col('ink'),
placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-12) } } })] };
The body text runs right to left, and its left and right mean start and end. Running heads stay physical. In a book bound on the right the verso, an even page, lies on the right of the spread, so its folio goes to the top right and the recto’s to the top left: both sit on the outer edge (Page order and right binding). The locale: 'ar' tag alone sets the direction, the binding and the Arabic-Indic digits.
#4 · A half-title with nothing in the flow
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', runningChapter: false,
breakBefore: { enabled: true, parity: 'any' },
header: { elements: [] }, footer: { elements: [] },
advancedDesign: { enabled: true, slot: { elements: [
line('diwan', 'ديوان', 52, { fontFamily: RUQAA, fontWeight: 700, fontSize: pt(64),
lineHeight: 1.2, color: col('rubric') }),
line('poet', '{titleText}', 84, { fontFamily: NASKH, fontWeight: 700, fontSize: pt(20) }),
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.75),
color: col('rubric'), placement: { anchor: { to: 'page', edge: 'top' },
offset: { y: mm(100) }, size: { width: mm(24) } } },
line('rhyme', '{attr.rhyme}', 106, { fontFamily: KUFI, fontWeight: 500, fontSize: pt(11),
color: col('rubric') }),
line('latin', '{attr.latin}', 150, { fontFamily: NASKH, fontSize: pt(9.5),
color: col('muted'), italic: true }),
] } },
};
The half-title is a heading style with span: 'page' and its own empty header and footer. Its heading text is the poet’s name, so the word ديوان is design text, set at 64 pt above it, and the Latin line under the rhyme comes from the latin attribute, which each edition writes in its language.
The whole recipe
// ═══ Postext Cookbook · Nº 110 · A qasida on a diwan page, in two hemistichs ═══════════
// https://postext.dev/en/cookbook/qasida-diwan-page
// Code: MIT · Text: al-Mutanabbī, Dīwān, ar.wikisource (PD) · Pictures: none
// Fonts: Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1) · Needs postext ≥ 1.28.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 = 'qasida-diwan-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text and red rubrics on a warm paper, as a Cairo diwan of the 1900s prints them.
const palette = {
ink: '#1f1a16', // text: a warm near-black
rubric: '#9a2b1f', // the accent: titles, the metre, the headpiece rules
tint: '#f1e6cf', // the headpiece band
rule: '#b8a27c', // hairlines
muted: '#6b6156', // running heads and the note on the text
paper: '#fbf7ee', // 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: 'rubric (defaults)', value: { hex: palette.rubric, model: 'hex' } },
];
const NASKH = 'Amiri'; // the text: a Bulaq Naskh
const RUQAA = 'Aref Ruqaa'; // display: the titles
const KUFI = 'Noto Kufi Arabic'; // labels: metre, running heads, folios
const [SIZE, LEAD] = [13, 21]; // pt: the prose, at 1.6 × for a lightly vocalised headnote
const [OUTER, TOP] = [18, 23]; // mm: a 17 × 24 cm diwan
// #region answer: one bayt a line, both hemistichs stretched to one width
// In the Markdown, a :::verse block takes one bayt a line, the ṣadr and the ʿajuz parted
// by ||:
// :::verse{style="bayt"}
// عَلى قَدْرِ أهْلِ العَزْم تأتي العَزائِمُ || وَتأتي علَى قَدْرِ الكِرامِ المَكارمُ
// :::
// The ṣadr goes on the right, the ʿajuz on the left, both stretched to the width of the
// widest half with a gap of 2 em between them. The style gives the poem its face and a
// leading deep enough for the harakat: 1.9 × the size.
const bayt = { id: 'bayt', fontFamily: NASKH, fontSize: pt(14), lineHeight: pt(26.6),
color: col('ink'), marginTop: pt(LEAD / 2), marginBottom: pt(LEAD) };
// Justified lines lengthen their words with kashidas (tatweel) before they open the
// spaces wide: 'auto' is the default in an Arabic document, written out here to say so.
// A hemistich may stretch a word twice as far as a line of prose does: 1.2 em.
const bodyKashida = { kashida: 'auto', kashidaPatterns: 'naskh', kashidaMaxLength: 0.6 };
// #endregion
The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)
Variations
#Mark the gap with an ornament
Some diwans print a small star between the hemistichs. ornament puts a mark in the middle of the gap without adding it to the text.
-:::verse{style="bayt"}
+:::verse{style="bayt" ornament="٭"}#Give every hemistich the same width
A fixed width sets both columns to one measure on every page of the diwan, whatever the widest half of a given poem is.
-:::verse{style="bayt"}
+:::verse{style="bayt" width=58mm}Pitfalls
Pitfall
Tag an Arabic book 'ar', not with LANG
A recipe's editions are en and es, but an Arabic sample is Arabic in both: `locale: LANG` would set it left to right, bind it on the left, number its pages 1 2 3 and caption its figures Figure or Figura. From postext 1.30 the tag is also the language the text is shaped in (measured, painted and embedded), so under an English or Spanish tag a face such as Markazi Text does not draw the Arabic forms of its guillemets and stops, and the lines break elsewhere. Write the tag yourself: 'ar' (Arabic-Indic digits, the Mashriq convention), a region such as 'ar-EG' or 'ar-SA', or 'ar-MA', 'ar-DZ' or 'ar-TN' for a Maghreb edition with European digits. A Latin page that only quotes Arabic keeps its own locale. Right-to-left text →
Pitfall
Arabic faces need their arabic file, through the arabic block
Fontsource serves Amiri, Noto Naskh Arabic or Scheherazade New as one file per subset, and the Arabic letters are in the arabic file. loadFonts fetches only latin (and latin-ext), so on screen the Arabic comes from a system face and measures wrong, and fontsourceProvider hands the PDF that latin file, which prints empty boxes. List the arabic kit block, call loadArabicFonts(FONTS, markdown) after loadFonts, with every weight the pages set in Arabic listed in FONTS, and give renderToPdf fontProvider: arabicPdfProvider. Arabic fonts →
Credits
- Recipe
- Ignacio Ferro
- Text
- The qasida ʿAlā qadri ahli l-ʿazmi taʾtī l-ʿazāʾimu, as ar.wikisource gives it (revision 447620), with its vowels · al-Mutanabbī · public domain
- The headnote in Arabic, the note on the text and the colophon · Postext Cookbook · original
- Fonts
- Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


