In short
The opening of a classic Japanese book as a pocket paperback: the text runs in columns from top to bottom, read from right to left, with small kana beside the harder characters.
What you'll build
Nine pages of a Japanese pocket paperback (文庫, bunko) of Natsume Sōseki's Ten Nights of Dreams, the first and second nights, on an A6 page of 105 × 148 mm bound on the right. The title page lies alone on the left of the spine; from page 2 the text runs top to bottom in lines read from the right, 38 characters down and 15 lines across, Shippori Mincho B1 at 9 pt on a pitch of 1.75 em. The readings Aozora Bunko gives for the harder kanji stand beside them in half-size kana, each night's title takes three lines of the grid, and the left-hand pages carry the book's title down the fore-edge over a folio in kanji numerals. The European pocket book with the same structure is Nº 104, and the Chinese vertical novel is Nº 075.
This recipe answers
- How do I set a Japanese novel vertically, bound on the right, like a bunko paperback?
- How do I add furigana over kanji, one reading per character or one for the whole word?
- How do I turn an Aozora Bunko text into a Postext book?
- How do I make a Japanese heading take three body lines (3行取り), so the text stays on the grid?
The short answer
// 'vertical-rl' sets each line top to bottom and the lines from right to left; with the
// binding left to 'auto' the book opens from the right, so page 1 is a left-hand page and
// the spreads read [3 | 2]. locale 'ja' gives the cjk settings Japan's values: they are
// written out below so you can see them, and leaving them out sets the same page.
const page = {
sizePreset: 'custom', width: mm(105), height: mm(148), dpi: 200, // 文庫判 A6
backgroundColor: col('paper'),
// 天 above 地; left is the spine side (the right edge of a left-hand page). The grid
// grows the margins of each pair alike, so the head stays deeper than the foot.
margins: { top: mm(15), bottom: mm(11), left: mm(9), right: mm(12), mirror: true },
pageNumbering: { format: 'japanese-informal' }, // folios 一, 二 … 十, 十一
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
lineBreak: 'ja-very-strict', // 行頭禁則: no 、。」ー or small kana at the head of a line
hangingPunctuation: 'allow', // ぶら下げ: a 、。 that would open a line hangs below the last
paragraphStartBracket: 'half', // ③: a 「 that opens a paragraph fills the indent cell
ruby: { align: 'jis', overhang: 'kana' }, // JIS 1:2:1, a reading may run onto kana only
};
A bunko page, 38 characters down 15 lines, bound on the right
Ingredients
- Features
- Vertical textFurigana: kana readings over kanjiHeadings over body lines (gyōdori)Books bound on the rightJapanese line breaking (kinsoku)Japanese punctuation spacing (yakumono)Character gridJapanese numerals and kana countersAozora Bunko importKana, kanji and rōmajiChinese, Japanese and Korean fontsRuby: pinyin and zhuyin readingsRunning heads and foliosHeads by page roleMirrored marginsHeading stylesHeading levelsPaper colourSemantic colour palettePDF export
- Also uses
- Chinese line breakingChinese punctuation widthsHeading attributesDesigned openersFonts embedded in the PDFRoman front matterRunning heads per sectionUnnumbered chapters
- Type
- Shippori Mincho B1, Noto Sans JP (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Turn the page, count it in characters and tag it ja
The code is the short answer above. layout.writingMode: 'vertical-rl' lays each page out as a horizontal page turned a quarter turn clockwise, and page.binding, left at 'auto', binds a vertical book on the right: page 1 is still the recto, but it lies on the left of the spine, and mirror: true puts its inner margin on its right (Vertical writing, Binding). The character grid makes the type area 38 characters of 9 pt down (120.7 mm) and 15 lines of 15.75 pt across (83.3 mm); the margins in page are minimums, and the grid grows each pair by the same amount, so the head stays 4 mm deeper than the foot. Ask for more lines than the margins leave room for and the grid quietly drops one (cjkGridClamped in doc.configWarnings): the 9 mm spine and 12 mm fore-edge are what lets 15 lines fit.
locale: 'ja' sets the rest the way Japanese books are set, so the four cjk lines written out here change nothing; they show what the tag picks. ja-very-strict is JIS X 4051's line-start rule (行頭禁則): no line opens with 、。」, ー or a small kana such as っ. hangingPunctuation: 'allow' lets a 、 or 。 that would otherwise open a line hang below the last character (ぶら下げ), which bunko do instead of squeezing the line. paragraphStartBracket: 'half' is JLReq's pattern ③: a paragraph that opens with 「 sets the bracket in the second half of its one-character indent, so the first character of speech stands where every other paragraph's does (East Asian typography). Chinese books differ on both counts: they hang no mark by default and indent a paragraph two characters, bracket or not.
#2 · Give each night's title three lines of the grid
// lineSpan sets the heading in a band of three body lines, its characters centred in it, so
// the text after it stands on the grid's lines. Aozora marks the titles 5字下げ (中見出し);
// indent counts body characters, whatever the heading's own size.
const night = {
level: 1, fontFamily: MINCHO, fontWeight: 600, fontSize: pt(12.5),
lineSpan: 3, indent: em(5), // JLReq §4.1.3
breakBefore: { enabled: false }, // the nights run on
};
A Japanese heading takes a whole number of body lines, 行取り (gyōdori), so the lines after it stay on the same grid as the lines before. lineSpan: 3 sets 第一夜 in a band of three 15.75 pt lines with its characters centred across them; the heading's 12.5 pt does not move the grid, and on page 6 第二夜 takes the first three lines of the page, so the text after it starts on the fourth line of the grid. indent: em(5) reads body characters (五字下げ), which is how the Aozora text marks a 中見出し and how JLReq counts heading indents (Per-level overrides).
#3 · Bring the text and its readings from Aozora Bunko
The two nights come from Aozora Bunko's card 799, converted with aozora.py from the postext-port skill. The converter reads the file as CP932, turns each reading written 仰向《あおむき》 into a group reading {仰向|あおむき}, one run of kana over the whole word, and each [#5字下げ]…[#「第一夜」は中見出し] into a heading. In a ja document the readings follow JIS X 4051: a reading shorter than its base is spread along it 1:2:1, and a longer one may run onto a neighbouring kana but never onto a kanji (Marks, ruby and warichu). The leading of 1.75 em leaves 6.75 pt between lines, room for the 4.5 pt readings.
#4 · Put the hashira down the fore-edge, the folios in kanji
// anchor 'outer' is the fore-edge: the left margin of an odd page, the right of an even one
// in a book bound on the right. The 柱 starts two characters below the head of the text.
const foreEdge = (id, content, parity, edge, y, pages) => ({
kind: 'text', id, content, parity, pages, writingMode: 'vertical-rl',
fontFamily: GOTHIC, fontSize: pt(7), letterSpacing: pt(1), color: col('muted'),
overflow: 'clip', placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
});
const header = { elements: [
foreEdge('hashira', '{title}', 'odd', 'top', 2, 'body'), // never on the opening page
foreEdge('folio', '{pageNumber}', 'all', 'bottom', -2, 'all'),
] };
const none = { elements: [] };
In a vertical bunko the running head (柱, hashira) is small and sits in the outer margin. anchor.to: 'outer' places an element there, the left margin of an odd page and the right one of an even page in a book bound on the right, and writingMode: 'vertical-rl' sets it top to bottom (Vertical text elements). The title 夢十夜 runs on the left-hand pages only (parity: 'odd'), and pages: 'body' would keep it off any page that opens a chapter. pageNumbering.format: 'japanese-informal' prints the folios 二, 三 … 九 (Numbering).
#5 · Centre the title page on the trim
// A design on a vertical page is laid out in the flow frame: x runs down the page and y
// across it, leftwards from the right edge. Anchored to the page (the trim), the frame and
// the title stand on the page's axis, 52.5 mm in, whichever side the spine is on.
const at = (down, across) => ({ anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(down), y: mm(across) } });
const AXIS = 105 / 2; // mm
const TITLE = 28 * PT; // mm: 夢十夜 in 28 pt, three characters and two 8 pt gaps down
const frame = { kind: 'box', id: 'frame', placement: { ...at(30, AXIS - 23),
size: { width: mm(88), height: mm(46) } }, // 88 mm down, 46 mm across
style: { borderColor: col('vermilion'), borderWidth: pt(0.75) } };
const titlePage = {
id: 'title', numbered: false, toc: false, span: 'page', header: none, footer: { elements: [
// The colophon across the foot, in the edition's language: each \n in the attribute
// starts a line; the box hangs from the foot of the page, centred.
// Noto Sans JP: Shippori Mincho B1 has no ō or ū for the rōmaji.
{ kind: 'text', id: 'colophon', content: '{attr.colophon}', fontFamily: GOTHIC,
fontSize: pt(5.25), lineHeight: 1.45, color: col('muted'), overflow: 'wrap',
align: 'center', placement: { anchor: { to: 'page', edge: 'bottom' },
offset: { y: mm(-4) }, size: { width: mm(84) } } }] },
breakBefore: { enabled: true, parity: 'any' },
advancedDesign: { enabled: true, minHeight: lines(LINES), slot: { elements: [
frame,
{ kind: 'text', id: 'book', content: '{titleText}', fontFamily: MINCHO, fontWeight: 800,
fontSize: pt(28), lineHeight: 1, letterSpacing: pt(8), color: col('ink'),
placement: at(44, AXIS - TITLE / 2) },
{ kind: 'text', id: 'author', content: '{author}', fontFamily: MINCHO, fontSize: pt(11),
letterSpacing: pt(4), color: col('ink'), placement: at(92, AXIS + TITLE / 2 + 4) },
] } },
};
The title page is a level-1 heading with a style of its own, # 夢十夜 {style="title" …}, whose design fills the page. Its elements are anchored to the page itself, not the type area, because the type area of a mirrored page sits 1.5 mm off centre: x runs down the page and y across it from the right edge, so AXIS is half the page's width on either side of the spine. The colophon in the footer is set in Noto Sans JP: Shippori Mincho B1 has no ō or ū, and the PDF would draw empty boxes for Sōseki.
#6 · Load each weight with the characters it sets
// Fontsource cuts a Japanese face into about 120 files; loadCjkFonts fetches the ones the
// text touches (gotcha: cjk-fonts-slices). vertical: true loads the face's vertical forms
// for the canvas: 、。「」ー and small kana such as っ stand differently down a line.
const title = markdown.match(/^title: "(.*)"$/m)[1];
const author = markdown.match(/^author: "(.*)"$/m)[1];
const heads = markdown.match(/^# [^{\n]*/gm).join('');
await loadFonts(FONTS, markdown); // the Latin files: the colophon, with ō and ū
await loadCjkFonts({ [MINCHO]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [MINCHO]: ['600', '800'] }, `${heads}${title}${author}`);
await loadCjkFonts({ [GOTHIC]: ['400'] }, `${title}一二三四五六七八九十`, { vertical: true });
Fontsource serves each weight of a Japanese face as about 120 files, each covering a range of characters, and loadCjkFonts fetches the files the text it is given touches. The text weight gets the whole sample with vertical: true, which also loads the face's vertical forms for the canvas: 、。「」 and ー, and the small kana, which stand in the upper right of their cell in vertical text. renderToPdf takes cjkPdfProvider, which embeds the same files as subsets.
The whole recipe
// ═══ Postext Cookbook · Nº 117 · A bunko novel set vertically, with furigana ════════
// https://postext.dev/en/cookbook/bunko-novel-furigana
// Code: MIT · Text: 夏目漱石『夢十夜』, Aozora Bunko 799 (public domain) · Pictures: none
// Fonts: Shippori Mincho B1, Noto Sans JP (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the colophon; the novel is Japanese in both
const RECIPE = 'bunko-novel-furigana';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: sumi ink on a cream bunko stock, one vermilion
const palette = {
ink: '#1f1b18', // the text: a warm sumi black
vermilion: '#a8392b', // 朱: the frame of the title page
muted: '#6b635b', // the hashira and the folios
paper: '#fbf7ee', // bunko paper is cream, not white
};
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 [MINCHO, GOTHIC] = ['Shippori Mincho B1', 'Noto Sans JP'];
const [BODY, LEAD, CHARS, LINES] = [9, 15.75, 38, 15]; // pt, pt: 38字 × 15行 at 1.75 em
const lines = (n) => pt(n * LEAD); // n lines across the page
const PT = 25.4 / 72; // mm in a point
// #region answer: a bunko page, 38 characters down 15 lines, bound on the right
// 'vertical-rl' sets each line top to bottom and the lines from right to left; with the
// binding left to 'auto' the book opens from the right, so page 1 is a left-hand page and
// the spreads read [3 | 2]. locale 'ja' gives the cjk settings Japan's values: they are
// written out below so you can see them, and leaving them out sets the same page.
const page = {
sizePreset: 'custom', width: mm(105), height: mm(148), dpi: 200, // 文庫判 A6
backgroundColor: col('paper'),
// 天 above 地; left is the spine side (the right edge of a left-hand page). The grid
// grows the margins of each pair alike, so the head stays deeper than the foot.
margins: { top: mm(15), bottom: mm(11), left: mm(9), right: mm(12), mirror: true },
pageNumbering: { format: 'japanese-informal' }, // folios 一, 二 … 十, 十一
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
lineBreak: 'ja-very-strict', // 行頭禁則: no 、。」ー or small kana at the head of a line
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 words the source stresses
Sōseki's first two nights have no 傍点, but much of Aozora does, and the converter writes it as :dots[…]{style=sesame}. In a ja document *…* gives the same sesame marks beside the line, never italics.
-こんな夢を見た。
+こんな*夢*を見た。#Set every bracket a full character down
Pattern ① keeps the one-character indent and sets the bracket after it, as many novels for younger readers do.
- paragraphStartBracket: 'half', // ③: a 「 that opens a paragraph fills the indent cell
+ paragraphStartBracket: 'indent', // ①: the bracket after the one-character indent#Squeeze instead of hanging
With hangingPunctuation: 'none' a 、 or 。 that would open a line is taken into the line before it by squeezing its brackets and commas (追い込み), or the line's last character goes down with it (追い出し), and no mark stands below the line.
- hangingPunctuation: 'allow', // ぶら下げ: a 、。 that would open a line hangs below the last
+ hangingPunctuation: 'none',Pitfalls
Pitfall
Tag a Japanese text 'ja', never zh-Hans or LANG
A recipe's editions are en and es, but a Japanese sample is Japanese in both: `locale: LANG` would tag it English or Spanish, and a Chinese tag would set it by the Chinese rules (Kaiming punctuation, small kana free to start a line, 图 for 図, Chinese glyph forms in the PDF). From postext 1.30 the tag is also the language the text is shaped in (measured, painted and embedded), so any tag but 'ja' gives other glyph forms than the Japanese ones (the Chinese ones under a Chinese tag) and other line breaks. Write 'ja': it picks the Japan region (JLReq line breaking and punctuation, sesame emphasis marks, furigana spacing, 図 and 表 labels) and turns hyphenation off. The lint fails a text with kana under a zh or ko tag. Japanese line breaking (kinsoku) →
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
Read Aozora files as CP932, not Shift_JIS
Aozora Bunko's text files are Windows-31J (CP932). Decoded as plain Shift_JIS, the dash ―― comes out as em dashes (U+2014), ~ as the wave dash 〜, and a few NEC and IBM characters fail. Read them as cp932, then convert the markup: ruby in 《》, the [#…] notes and the ※[#…] gaiji are not Markdown and print as they are if left in. The skill's aozora.py does both. Aozora Bunko import →
Pitfall
A Fontsource range can name characters its file lacks
Fontsource gives each file a unicode-range, and loadCjkFonts loads the files whose ranges cover the sample, but a range can claim more than its file holds. Zen Old Mincho's fragment for U+3028–303F has no 〻 or the long repeat marks 〳〴〵, and the face has no macron vowels ō ū ā either; Shippori Mincho B1's latin-ext file has a handful of characters and none of them is ō, ū or ā. Nothing fails while the pen runs: on screen those characters come from a system face and are measured in it, and the PDF prints the font's .notdef box, which only the C25 check reports afterwards. Look a rare mark or a rōmaji word up in the font before you choose the face (fontTools on the Fontsource file), and set it in one that has it: Shippori Mincho B1 and Noto Serif JP have 〻 and 〳〴〵, Noto Serif JP and Noto Sans JP the macron vowels. Chinese, Japanese and Korean fonts →
Pitfall
A vertical page has two frames: the turned text's and the sheet's
A vertical-rl document lays its text out as a horizontal page turned a quarter turn clockwise, and a heading's design (the elements of advancedDesign.slot) is placed in that turned frame: x runs down the page, y across it leftwards from the right edge, and an element's width is measured down the page. Header and footer elements stay on the sheet: x runs right from the left edge and y down from the top. A frame drawn in the header and a title placed in the heading's design therefore take their offsets on different axes. On a vertical title page, anchor the elements to `page` and measure from its edges: anchored to `container`, footer elements stand a few millimetres (about 5 mm) off the centre of the type area. Vertical text →
Credits
- Recipe
- Ignacio Ferro
- Text
- 夏目漱石『坊っちゃん』 (Botchan, 1906), the opening of chapter one; Aozora Bunko card 752, from 「ちくま日本文学全集 夏目漱石」 (Chikuma Shobō, 1992), input 真先芳秋, proofreading 柳沢成雄, converted with aozora.py · Natsume Sōseki; Aozora Bunko volunteers · public domain
- Fonts
- Shippori Mincho B1 (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


