In short
The first chapter of a classic Chinese novel as a paperback from Taiwan. The text runs in columns from top to bottom, read from right to left, and the book opens from the right.
What you'll build
Eleven pages of a Taiwan paperback of Romance of the Three Kingdoms: the whole of chapter 1, in Mao Zonggang's recension, set top to bottom in columns read from the right on a 148 × 210 mm page (25開) bound on the right. The title page lies alone on the left of the spine. On the next spread a woodcut of the oath in the peach garden, cut in 1592, faces the opening of the chapter, where 第一回 and its couplet stand between vermilion rules. Every page of text holds 16 columns of 40 characters, each mark centred in its cell. The book's title runs down the outer margin of the right-hand pages and the chapter's down the left-hand ones, over folios in Chinese numerals. The same book structure in a European paperback is Nº 038.
This recipe answers
- How do I set a Chinese book vertically, bound on the right?
- How do I number chapters 第一回, 第二回 in Chinese numerals?
The short answer
// 'vertical-rl' turns the flow a quarter turn: lines run down, columns from right to left,
// and page.binding 'auto' becomes 'right', so page 1 is a left-hand page and the spreads
// read [3 | 2]. The grid sets the type area in characters; the margins are minimums it
// grows. zh-Hant resolves to Taiwan's rules: every mark full width and centred in its cell.
const page = {
sizePreset: 'custom', width: mm(148), height: mm(210), dpi: 150,
backgroundColor: col('paper'),
// 天頭 above 地腳; left is the spine side (the right edge of a left-hand page).
margins: { top: mm(32), bottom: mm(26), left: mm(16), right: mm(22), mirror: true },
pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = { grid: { enabled: true, charsPerLine: 40, linesPerPage: 16 } };
const chapter = {
level: 1, numberingTemplate: '第{1:一}回', numberSeparator: ' ', // 第一回 宴桃園…
breakBefore: { enabled: true, parity: 'odd' }, // a recto, with no blank page forced
marginBottom: pt(0),
};
Vertical text on a 25開 page, bound on the right, 40 characters × 16 columns
Ingredients
- Features
- Vertical textBooks bound on the rightChinese numeralsChinese line breakingChinese punctuation widthsCharacter gridChinese, Japanese and Korean fontsDesigned openersHeading stylesHeading attributesNumbered headingsLine breaks in titlesRunning heads and foliosRunning heads per sectionHeads by page roleMirrored marginsParagraph stylesPictures in page designsPDF exportPaper colour
- Also uses
- Fonts embedded in the PDFFigures and tables as resourcesRoman front matterUnnumbered chapters
- Type
- Noto Serif TC, LXGW WenKai TC, Noto Sans TC, Source Serif 4 (SIL OFL 1.1)
- Assets
peach-garden-oath-1592-v2.jpg- 桃園結義 (The Oath in the Peach Garden), woodcut from Yu Xiangdou’s 新刊京本校正演義全像三國志傳評林, Jianyang, 1592 (Waseda University Library); scan from Wikimedia Commons, cropped inside its frame and clear of what was left of it, cleaned and toned to the page’s ink and paper (Yu Xiangdou (publisher), anonymous block cutter, public domain)
Method
#1 · Turn the page a quarter turn and bind it on the right
The code is the short answer above. layout.writingMode: 'vertical-rl' lays each page out as a horizontal page turned a quarter turn clockwise: a line of the flow is a column of characters, read from the right, and line breaking, justification and the two-character indent work down the column (Vertical writing). page.binding stays at 'auto', which binds a vertical book on the right: page 1 is still the recto, but it is a left-hand page, and mirror: true puts its inner margin, left, on its right (Binding). The kit's showBook lays the spreads out as the book opens, page 1 alone and then [3 | 2]; the PDF asks viewers for the same order with /Direction /R2L, which Acrobat follows and Chrome's viewer ignores.
The character grid sets the type area as 40 characters of 10.5 pt down and 16 columns of 19 pt across, 148.2 × 107.2 mm. The margins in page are minimums: the grid grows each pair alike, to 33.9 mm at the head and 27.9 at the foot, 17.4 at the spine and 23.4 at the fore-edge. locale: 'zh-Hant' gives the East Asian settings Taiwan's values, every mark a full em and centred in its cell, with no compression between marks. trad-chinese-informal prints the folios 一 to 九, and 第{1:一}回 numbers the chapter (Numbering).
#2 · Rule the 回目 in two columns
// In the flow frame x runs down the column and y across the page, right to left, so a
// 'horizontal' rule is a vertical line on the sheet: three of them rule the title columns.
const [TITLE, PITCH] = [13.5, 1.5 * LEAD]; // pt: the couplet's size and its column pitch
const rule = (n) => ({ kind: 'rule', id: `rule-${n}`, direction: 'horizontal',
thickness: pt(0.5), color: col('vermilion'),
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { y: pt(LEAD + n * PITCH) }, size: { width: 'fill' } } });
const title = (id, content, x, family, weight) => ({ kind: 'text', id, content,
fontFamily: family, fontWeight: weight, fontSize: pt(TITLE), lineHeight: PITCH / TITLE,
color: col('ink'), align: 'left', // the head of the column
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: pt(x), y: pt(LEAD) } } }); // a line of PITCH, centred between two rules
const opener = {
enabled: true,
minHeight: cols(5), // a blank column, the two title columns, a blank one: 5 × 19 pt
slot: { elements: [
rule(0), rule(1), rule(2),
title('number', '{number}', 2 * BODY, SONG, 700), // 第一回, two characters down
// The couplet's two halves, broken by the \\ in the heading, start level with each other.
title('couplet', '{titleText}', 2 * BODY + 4 * TITLE, KAI, 400),
] },
};
A heading design on a vertical page is laid out in the flow frame: x runs down the column from the head of the type area and y across the page from its right edge. A 'horizontal' rule is therefore a vertical line on the sheet, as long as the column. Three rules of 0.5 pt frame two title columns 28.5 pt apart, 1.5 times the column pitch of the text. Each column is a line 28.5 pt tall whose characters stand in its middle, halfway between two rules. {number} prints 第一回 in Noto Serif TC Bold two characters down; {titleText} prints the couplet in LXGW WenKai TC, one character after it. The heading is written # 宴桃園豪傑三結義 \\ 斬黃巾英雄首立功, and the forced break starts the second half in the next column, level with the first. minHeight reserves five columns of 19 pt, so the text starts on its grid (Span and advanced design). Where the title is read on one line, in the running heads and the PDF bookmarks, the break becomes an ideographic space.
#3 · Set the heads and folios down the fore-edge
const foreEdge = (id, content, parity, edge, y, pages) => ({
kind: 'text', id, content, parity, pages, writingMode: 'vertical-rl',
fontFamily: HEI, fontSize: pt(8.5), color: col('muted'), overflow: 'clip',
placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
});
const header = { elements: [
foreEdge('book', '{title}', 'even', 'top', 4, 'body'), // 三國演義 on the right-hand page
foreEdge('chapter', '{chapterNumber} {chapterTitle}', 'odd', 'top', 4, 'body'),
foreEdge('folio', '{pageNumber}', 'all', 'bottom', -5, 'all'), // on openers too
] };
Vertical books in Taiwan often put the running head and the folio down the outer margin. writingMode: 'vertical-rl' sets a header element top to bottom on the sheet, and anchor.to: 'outer' places it in the outer margin, the left one of an odd page and the right one of an even page when the book is bound on the right (Vertical text elements). The offsets are in ems of the element's own 8.5 pt, about 80 % of the text size: the head starts four characters below the head of the type area and the folio ends five characters above its foot. parity puts 三國演義 on the right-hand pages and the chapter on the left-hand ones. pages: 'body' keeps both heads off the opening page, which keeps its folio.
#4 · Put the plate before the chapter
const none = { elements: [] };
// A point of a page design in the flow frame: mm down the column, mm leftward across the
// page from the right edge of the type area.
const at = (down, across) => ({ anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(down), y: mm(across) } });
// The title slip (題簽), 96 × 22 mm: its axis, 55 mm in from the right of the type area, is
// the axis of the page, and of the imprint under it.
const SLIP = { down: 10, across: 44, long: 96, wide: 22 };
const AXIS = SLIP.across + SLIP.wide / 2;
const slip = (id, inset, thickness) => ({ kind: 'box', id,
placement: { ...at(SLIP.down + inset, SLIP.across + inset),
size: { width: mm(SLIP.long - 2 * inset), height: mm(SLIP.wide - 2 * inset) } },
style: { borderColor: col('vermilion'), borderWidth: pt(thickness) } });
const RUN = (4 * 40 + 3 * 10) * PT; // 三國演義 down the slip: four 40 pt characters, 3 gaps
const titlePage = {
id: 'title', numbered: false, toc: false, span: 'page', header: none,
breakBefore: { enabled: true, parity: 'any' },
footer: { elements: [{ kind: 'text', id: 'imprint', content: '{attr.colophon}',
fontFamily: ROMAN, fontSize: pt(6.5), lineHeight: 1.4, color: col('muted'),
// In the edition's language, set across and centred on the axis: the box runs from the
// left of the type area (16 columns) as far past the axis. Each \n in the attribute
// starts a line, and *…* sets the book's title in italic.
inlineMarks: true, overflow: 'wrap', align: 'center',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(4) },
size: { width: mm(2 * (16 * LEAD * PT - AXIS)) } } }] },
advancedDesign: { enabled: true, minHeight: cols(16), slot: { elements: [
slip('slip', 0, 1.4), slip('slip-in', 1.2, 0.4), // a heavy and a light vermilion rule
{ kind: 'text', id: 'book', content: '{titleText}', fontFamily: SONG, fontWeight: 700,
fontSize: pt(40), lineHeight: 1, letterSpacing: pt(10), color: col('ink'),
placement: at(SLIP.down + (SLIP.long - RUN) / 2, AXIS - 20 * PT) }, // 40 pt line on the axis
{ kind: 'text', id: 'author', content: '{author} 著', fontFamily: KAI, fontSize: pt(12),
color: col('ink'), placement: at(52, 72) },
{ kind: 'text', id: 'editor', content: '{attr.editor}', fontFamily: KAI, fontSize: pt(12),
color: col('ink'), placement: at(52, 80) },
] } },
};
// The woodcut, 138 mm tall in a double frame (四周雙邊), hangs from the top right corner of
// the type area, and its caption runs down the column on its left. In the flow frame a
// box's width runs down the page: the picture's width is its height on the sheet, and it
// stands upright in the canvas, the HTML and the PDF.
const PLATE = { right: 8.3, top: 5.1, h: 138, w: (138 * 806) / 1427 }; // mm
const frame = (id, inset, thickness) => ({ kind: 'box', id,
placement: { ...at(PLATE.top - inset, PLATE.right - inset),
size: { width: mm(PLATE.h + 2 * inset), height: mm(PLATE.w + 2 * inset) } },
style: { borderColor: col('ink'), borderWidth: pt(thickness) } });
const plate = {
id: 'plate', numbered: false, toc: false, span: 'page', header: none, footer: none,
breakBefore: { enabled: true, parity: 'any' },
advancedDesign: { enabled: true, minHeight: cols(16), slot: { elements: [
{ kind: 'image', id: 'woodcut', resourceId: 'peach-garden',
placement: { ...at(PLATE.top, PLATE.right), size: { width: mm(PLATE.h), height: 'auto' } } },
frame('inner', 1.6, 0.4), frame('outer', 2.8, 1.4),
{ kind: 'text', id: 'caption', content: '{titleText}', fontFamily: HEI, fontSize: pt(9),
color: col('ink'), placement: at(PLATE.top - 2.8, PLATE.right + PLATE.w + 7) },
{ kind: 'text', id: 'note', content: '{attr.note}', fontFamily: KAI, fontSize: pt(8),
color: col('muted'), placement: at(PLATE.top - 2.8, PLATE.right + PLATE.w + 12) },
] } },
};
const resources = [{
id: 'peach-garden', typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
bitmap: { fileId: 'peach-garden.jpg', format: 'jpeg', width: 806, height: 1427 },
caption: '桃園結義',
altText: '桃園結義圖:劉備、關羽、張飛立於祭桌前,桌上香爐燭臺與三杯酒,旁有烏牛白馬。',
}];
The title page and the plate are level-1 headings with styles of their own, # 三國演義 {style="title" …} and # 桃園結義 {style="plate" …}. numbered: false leaves them out of the count, so the chapter is still 第一回, and their own header, empty, replaces the fore-edge heads. The chapter's breakBefore asks for an odd page, page 3, whose spread has the plate on its right: the reader sees the picture before the text, as in the illustrated (繡像) editions (Heading styles). The folios leave the two pages out as well. A Chinese editor numbers the text (正文) from its first page, so a :::numbering{startAt=1} line just before the chapter's heading starts the count again at 一 on page 3 (:::numbering); the title page and the plate still count as sheets for the parity, and the viewer and the PDF label them 一 and 二 all the same (a variation below labels them apart).
三國演義 is centred down its slip: RUN is the length of four characters of 40 pt and the three 10 pt gaps between them, without the tracking after the last one. The title page's footer sets the imprint across the foot, in the edition's language, from the heading's colophon attribute. Noto Serif TC has no italic, so the imprint is set in Source Serif 4: inlineMarks: true reads the asterisks round the book's title, and each \n in the attribute starts a line, so the lines break where the sense does (Text elements). The box is twice as wide as the distance from the left of the type area to the slip's axis, which puts the centre of every line under 三國演義. The plate's design hangs the woodcut and its double frame from the top right corner of the type area and sets the caption down two columns on its left. In the flow frame a box's width runs down the page, so the picture's width is its height on the sheet; it stands upright in the canvas, the HTML and the PDF, and the tagged PDF reads it as a figure with its alternative text.
#5 · Load each voice with the characters it sets
// Fontsource cuts a Chinese face into about a hundred files; loadCjkFonts fetches those
// that hold the characters it is given (gotcha: cjk-fonts-slices). vertical: true loads the
// face again with its vertical punctuation forms, for the canvas.
const heads = markdown.match(/^# .*$/gm).join('').replace(/\{[^}]*\}/g, ''); // no attributes
const attr = (key) => markdown.match(new RegExp(`${key}="([^"]*)"`))?.[1] ?? '';
const verse = markdown.match(/:::paragraphs\{style="verse"\}[\s\S]*?\n:::/g).join('');
await loadFonts(FONTS, markdown); // the Latin files: the imprint
await loadCjkFonts({ [SONG]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [SONG]: ['700'] }, '三國演義第一回'); // no punctuation: no vertical twin
await loadCjkFonts({ [KAI]: ['400'] }, `${heads}${verse}${attr('editor')}${attr('note')}羅貫中著`,
{ vertical: true });
await loadCjkFonts({ [HEI]: ['400'] }, `${heads}第回一二三四五六七八九十`, { vertical: true });
The book has three voices: Noto Serif TC (宋) for the text, LXGW WenKai TC (楷) for the couplet and the verse, Noto Sans TC (黑) for the fore-edge. Fontsource serves each weight of a Chinese face as about a hundred files, each covering a range of characters, and loadCjkFonts fetches the files that hold the text it is given (Chinese, Japanese and Korean fonts). The text face gets the whole chapter and fetches 67 files; the Kai face gets the headings and the verse and fetches 25, the Hei face 15 and the bold 4. The bold sets seven characters and no punctuation, so it loads no vertical forms. The imprint's Source Serif 4 comes in through loadFonts like any Latin face, roman and italic. renderToPdf takes cjkPdfProvider, which embeds the same files as subsets, and imageBytes for the woodcut.
The whole recipe
// ═══ Postext Cookbook · Nº 075 · A vertical Chinese novel, bound on the right ════════
// https://postext.dev/en/cookbook/vertical-novel-right-bound
// Code: MIT · Text: 三國演義 ch. 1, zh.wikisource (CC BY-SA 4.0) · Plate: woodcut, 1592 (PD)
// Fonts: Noto Serif TC, LXGW WenKai TC, Noto Sans TC, Source Serif 4 (OFL) · Needs postext ≥ 1.25.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the frame; the novel is Chinese in both editions
const RECIPE = 'vertical-novel-right-bound';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black ink, one vermilion, the paper the plate was toned to
const palette = {
ink: '#2a221d', // the text, and the woodcut's lines
vermilion: '#a3301f', // 朱: the ruled columns of the opener, the title slip
muted: '#6f655c', // fore-edge heads, folios, the imprint
paper: '#fbf8f1', // the page; the plate's paper was toned to this value
};
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: 'defaults', value: { hex: palette.vermilion, model: 'hex' } },
];
// #endregion
const [SONG, KAI, HEI] = ['Noto Serif TC', 'LXGW WenKai TC', 'Noto Sans TC']; // 宋, 楷, 黑
const ROMAN = 'Source Serif 4'; // the imprint: Noto Serif TC has no italic
const [BODY, LEAD] = [10.5, 19]; // pt: 五號 text on a column pitch of 1.8 em
const cols = (n) => pt(n * LEAD); // n columns across the page
const PT = 25.4 / 72; // mm in a point
// #region answer: vertical text on a 25開 page, bound on the right, 40 characters × 16 columns
// 'vertical-rl' turns the flow a quarter turn: lines run down, columns from right to left,
// and page.binding 'auto' becomes 'right', so page 1 is a left-hand page and the spreads
// read [3 | 2]. The grid sets the type area in characters; the margins are minimums it
// grows. zh-Hant resolves to Taiwan's rules: every mark full width and centred in its cell.
const page = {
sizePreset: 'custom', width: mm(148), height: mm(210), dpi: 150,
backgroundColor: col('paper'),
// 天頭 above 地腳; left is the spine side (the right edge of a left-hand page).
margins: { top: mm(32), bottom: mm(26), left: mm(16), right: mm(22), mirror: true },
pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = { grid: { enabled: true, charsPerLine: 40, linesPerPage: 16 } };
const chapter = {
level: 1, numberingTemplate: '第{1:一}回', numberSeparator: ' ', // 第一回 宴桃園…
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
#Write the folios digit by digit
cjk-decimal writes one numeral per digit. This chapter ends on folio 九, where the two formats agree; from the tenth page of text on, 十 and 十一 would read 一〇 and 一一.
- pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
+ pageNumbering: { format: 'cjk-decimal' }, // folios 一, 二 … 九, 一〇, 一一#Label the front pages apart
The title page and the plate print no folio, yet the viewer and the PDF label them 一 and 二, like the first two pages of the text; with Roman labels for the front and the Chinese numerals moved to the :::numbering line, the PDF counts i, ii, 一, 二 …
- pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
+ pageNumbering: { format: 'lower-roman' }, // i, ii: the title page and the plate-:::numbering{startAt=1}
+:::numbering{format="trad-chinese-informal" startAt=1}#Set the chapter across the page
The mainland convention sets the same kind of chapter horizontally, bound on the left, in Simplified characters with Kaiming punctuation: A Chinese novel page on a 28 × 28 grid.
Pitfalls
Pitfall
Tag the document zh-Hans or zh-Hant, not with LANG
A recipe's editions are en and es, but a Chinese sample is Chinese in both: `locale: LANG` would tag it English or Spanish, hyphenate its Latin words, label its figures Figure or Figura and give the PDF the wrong language. 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 Chinese face sets its digits and the punctuation it shares with Latin text in other forms, and the lines break elsewhere. Write the tag yourself: 'zh-Hans' (mainland conventions: GB line breaking, Kaiming punctuation) or 'zh-Hant' (Taiwan: full-width centred punctuation); 'zh-HK' for Hong Kong. A bare 'zh' reads as Simplified, mainland. A Japanese sample takes 'ja' (gotcha ja-locale-tag). Chinese line breaking →
Pitfall
Chinese faces load by slices, through the cjk block
Fontsource serves a Chinese, Japanese or Korean family as about a hundred files per weight, each covering a range of characters. loadFonts fetches only the latin file, so on screen the Han characters come from a system face and measure wrong, and fontsourceProvider hands the PDF that latin file, which prints them as empty boxes. List the cjk kit block, call loadCjkFonts(FONTS, markdown) after loadFonts (once per voice, with the text it sets, when the book uses several CJK faces) and give renderToPdf fontProvider: cjkPdfProvider: both take the files that hold the text's characters. Chinese, Japanese and Korean fonts →
Pitfall
A right-bound book shows its spreads with showBook
In a book bound on the right (Arabic, Hebrew or Persian text, vertical Chinese, or page.binding 'right') page 1 is still the recto, but it lies on the left of the spine, and the pairs read [3 | 2]. showPages lays every book out left-bound; showBook from the book block (the cjk block carries the same function) reads doc.binding and mirrors the pairs. capture.hero still names a spread in reading order, [verso, recto]: [2, 3]. Books bound on the right →
Pitfall
Traditional transcriptions carry stray Simplified characters
Texts copied from Wikisource or another web edition of a Traditional book sometimes carry a Simplified form (颙 for 顒 in 三國演義, chapter 1), and a TC face such as Noto Serif TC may not have it. loadCjkFonts stops the pen with the character in its message; on a page it would print in a fallback face. Restore the Traditional form in the sample and say so in the credits. Chinese, Japanese and Korean fonts →
Credits
- Recipe
- Ignacio Ferro
- Text
- 三國演義 (Romance of the Three Kingdoms), chapter 1, Mao Zonggang recension (about 1679); Wikisource transcription, revision 2583915, with one character corrected (颙 → 顒) · Luo Guanzhong; transcription by Wikisource editors · CC BY-SA 4.0
- Images
- 桃園結義 (The Oath in the Peach Garden), woodcut from Yu Xiangdou’s 新刊京本校正演義全像三國志傳評林, Jianyang, 1592 (Waseda University Library); scan from Wikimedia Commons, cropped inside its frame and clear of what was left of it, cleaned and toned to the page’s ink and paper · Yu Xiangdou (publisher), anonymous block cutter · public domain
- Fonts
- Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · Source Serif 4 (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


