Skip to main content
Recipe number 119

Cookbook · Chapter 2 · Type & text

Haiku and tanka set vertically

Bashō's haiku inside his travel prose and eleven of Takuboku's three-line tanka down a 四六判 page: a verse per line, set in from the head, signatures at the foot.

On this page
Genre
Poetry
Output
Canvas · PDF
Postext
Tested with Postext 1.65.0
Needs ≥ 1.25.0 · postext-pdf ≥ 1.25.0
Licence
Updated 11 Oct 2026
Code MIT · Text CC BY 4.0

pp. 二–三 · 2–3 of 8

  • Trim 127 × 188 mm
  • 1 column
  • Shippori Mincho 10/19
  • Noto Sans JP
  • 8 pages
  • Level
  • Postext 1.65.0
  • Laid out in 91 ms
  • 155 lines of code

In short

A small book of Japanese poems: Bashō's travel diary with its haiku on lines of their own, and Takuboku's short poems in three lines each, never cut by a page turn.

What you'll build

Eight pages of a small poetry book on a 四六判 page of 127 × 188 mm, bound on the right. The first part is seven stations of Bashō's Narrow Road to the Deep North, his prose with its haiku; the second, eleven tanka from Ishikawa Takuboku's A Handful of Sand, each in the three lines he wrote it in. The prose runs top to bottom, 36 characters to the line, in Shippori Mincho at 10 pt on a generous pitch of 1.9 em. Each haiku stands on a line of its own three characters down, each tanka two down, and Sora's haiku is signed 曾良 near the foot of the line. A tanka never breaks across a page, and a persimmon * separates the groups. The European poetry book is Nº 015; Tang poems in vertical Chinese are Nº 083.

This recipe answers

  • How do I set poetry: one line per verse, stanza gaps, hanging indents for wrapped lines, no hyphenation?
  • Which fonts set Japanese, with kanji in their Japanese forms, on screen and in the PDF?

The short answer

script.js · lines 33–48in full code
// A haiku is a paragraph of one line, so a style sets where it starts: three characters down
// from the head of the line. Takuboku's tanka keep his three lines in a :::verse block, two
// down; 曾良 signs his haiku raised five characters from the foot (地から五字上げ).
const paragraphStyles = [
  { id: 'haiku', indent: em(3), firstLineIndent: em(0), marginTop: pt(0), marginBottom: pt(0) },
  // A poem's style gives its indent and the space under the poem: one blank line.
  { id: 'tanka', indent: em(2), marginTop: pt(0), marginBottom: pt(LEAD) },
  { id: 'by', textAlign: 'end', endIndent: em(5), firstLineIndent: em(0) },
  // The ornament between groups of poems, in the middle of its line, with a blank line after
  // it to match the one the group before it leaves.
  { id: 'ornament', textAlign: 'center', firstLineIndent: em(0), color: col('persimmon'),
    marginBottom: pt(LEAD) },
];
//   :::paragraphs{style="haiku"}       :::paragraphs{style="by"}
//   夏草や兵どもが夢の跡                   曾良
//   :::                                :::

A haiku on one line three characters down, a tanka in three, 地付き names

Ingredients

Type
Shippori Mincho, Noto Sans JP (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · A line of verse is a paragraph, and its style says where it starts

The code is the short answer above. A haiku is one line, so it is a paragraph of its own inside a :::paragraphs fence, and the fence's style sets the indent: indent: em(3) stands a haiku three characters below the head of the line (the Aozora text sets them two down; three gives the poems more air), and firstLineIndent: em(0) stops the body's one-character indent from adding to it. A haiku's 17 or so characters fit any line of 36, so it never wraps. The signature is a paragraph of its own: textAlign: 'end' sets it against the foot of the line (地付き, jitsuki) and endIndent: em(5) raises it five characters from there (地から五字上げ), as the edition this text comes from does (Paragraph styles).

#2 · Keep each tanka on one page

script.js · lines 52–63in full code
// The tanka of a group are one :::verse block, each a stanza of three lines with a blank
// line between: a line of verse a line of Markdown, one blank line of the grid between two
// tanka. keepStanzas=3 keeps a stanza of three lines whole, so a tanka is never cut at the
// foot of a page: it moves on to the next.
//   :::verse{style="tanka" keepStanzas=3}
//   東海の小島の磯の白砂に
//   われ泣きぬれて
//   蟹とたはむる
//
//   頬につたふ
//   …
//   :::

Takuboku's tanka are a :::verse block, each tanka a stanza: its three lines are three lines of the Markdown, and the blank line between two tanka in the source leaves a blank line of the grid between the poems. The poem's style gives the two-character indent and the line under the group, and the lines hang from the head as any column does. keepStanzas=3 keeps every stanza of three lines whole: on page 5 the third tanka does not fit under the part title and the first two, so it opens page 6 whole, rather than leaving its first line behind. The ornament between two groups introduces the next one, so it goes on with its first tanka instead of standing alone at a page's foot (:::verse).

#3 · Space the place names to one width

script.js · lines 67–72in full code
// The place names over the prose take two lines (2行取り), four characters down, and a
// two-character name is spaced out to three (字取り: 平泉 → 平 泉), so they all end level.
const place = {
  level: 2, fontFamily: MINCHO, fontWeight: 700, fontSize: pt(11),
  lineSpan: 2, indent: em(4), jidori: 3,
};

The stations of Bashō's route are second-level headings two body lines tall (2行取り), so the prose and haiku after them stay on the grid. jidori: 3 spaces a shorter name out to three of its own characters (字取り): 平泉 prints 平 泉 with a full character between, and every name ends at the same height as 立石寺 and 最上川. A name already three characters long is left alone (Per-level overrides).

#4 · Open each part on its own page

script.js · lines 76–97in full code
// A design on a vertical page is laid out in the flow frame: x runs down the column from
// the head of the type area, y across the page leftwards from its right edge.
const at = (down, across) => ({ anchor: { to: 'container', edge: 'top-left' },
  offset: { x: pt(down), y: pt(across) } });
const TITLE = 18; // pt
const part = {
  level: 1, breakBefore: { enabled: true, parity: 'any' }, // the next page, either side
  advancedDesign: { enabled: true, minHeight: lines(5), slot: { elements: [
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: MINCHO, fontWeight: 700,
      fontSize: pt(TITLE), lineHeight: 1, letterSpacing: pt(4), color: col('ink'),
      placement: at(3 * BODY, 1.5 * LEAD - TITLE / 2) },
    { kind: 'text', id: 'abridged', content: '(抄)', fontFamily: MINCHO, fontSize: pt(9),
      color: col('ink'), placement: { anchor: { to: '#title', edge: 'right-of' },
        offset: { x: pt(6), y: pt((TITLE - 9) / 2) } } },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6),
      color: col('persimmon'), placement: { ...at(3 * BODY, 2.5 * LEAD),
        size: { width: pt(4 * TITLE) } } },
    { kind: 'text', id: 'poet', content: '{attr.author}', fontFamily: MINCHO, fontSize: pt(11),
      letterSpacing: pt(3), color: col('ink'),
      placement: at(CHARS * BODY - 4 * 11 - 3 * 3 - 2 * BODY, 3.5 * LEAD - 11 / 2) },
  ] } },
};

Each part is a level-1 heading whose design sets the title, a small (抄), "selections", placed just after it with anchor.to: '#title', a short persimmon rule beside the title, and the poet near the foot of the line. The design reserves five lines, and the text starts after them on the same grid.

#5 · Choose a face that has the old marks

script.js · lines 279–285in full code
const title = markdown.match(/^title: "(.*)"$/m)[1];
const heads = markdown.match(/^#+ [^{\n]*/gm).join('');
await loadFonts(FONTS, markdown); // the Latin files: the colophon
await loadCjkFonts({ [MINCHO]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [MINCHO]: ['700'] }, heads);
await loadCjkFonts({ [GOTHIC]: ['400'] },
  `${title}${heads}${markdown.match(/colophon="([^"]*)"/)[1]}一二三四五六七八九十`, { vertical: true });

Bashō's prose writes repeated words with the old iteration mark 〻 (日〻, 人〻), and older texts use the long くの字点 〳〵 as well. Zen Old Mincho has neither: the canvas would borrow them from a system face and the PDF would draw empty boxes. Shippori Mincho, Noto Serif JP and Shippori Mincho B1 have both, so the poems are set in Shippori Mincho (Chinese, Japanese and Korean fonts). The Aozora text also keeps the editor's notes on old spellings, とら{え|(へ)}て, which print the expected kana beside the one Bashō wrote.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 119 · Haiku and tanka set vertically ═══════════════════
// https://postext.dev/en/cookbook/haiku-and-tanka
// Code: MIT · Text: 芭蕉『おくのほそ道』, 啄木『一握の砂』, Aozora Bunko (PD) · Pictures: none
// Fonts: Shippori Mincho, Noto Sans JP (SIL OFL 1.1) · Needs postext ≥ 1.25.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 poems are Japanese in both
const RECIPE = 'haiku-and-tanka';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, one persimmon, a soft poetry stock
const palette = {
  ink: '#22201d', // the poems
  persimmon: '#b5512c', // 柿: the part titles' rule and the ornaments
  muted: '#6a645c', // the hashira, the folios, the colophon
  paper: '#fbf8f1',
};
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.persimmon, model: 'hex' } },
];
// #endregion
// Shippori Mincho: it has the 〻 of 日〻 and 人〻, which Zen Old Mincho lacks.
const [MINCHO, GOTHIC] = ['Shippori Mincho', 'Noto Sans JP'];
const [BODY, LEAD, CHARS, LINES] = [10, 19, 36, 14]; // pt, pt: 36字 × 14行, a 1.9 em pitch
const lines = (n) => pt(n * LEAD);

// #region answer: a haiku on one line three characters down, a tanka in three, 地付き names
// A haiku is a paragraph of one line, so a style sets where it starts: three characters down
// from the head of the line. Takuboku's tanka keep his three lines in a :::verse block, two
// down; 曾良 signs his haiku raised five characters from the foot (地から五字上げ).
const paragraphStyles = [
  { id: 'haiku', indent: em(3), firstLineIndent: em(0), marginTop: pt(0), marginBottom: pt(0) },
  // A poem's style gives its indent and the space under the poem: one blank line.
  { id: 'tanka', indent: em(2), marginTop: pt(0), marginBottom: pt(LEAD) },
  { id: 'by', textAlign: 'end', endIndent: em(5), firstLineIndent: em(0) },
  // The ornament between groups of poems, in the middle of its line, with a blank line after
  // it to match the one the group before it leaves.
  { id: 'ornament', textAlign: 'center', firstLineIndent: em(0), color: col('persimmon'),
    marginBottom: pt(LEAD) },
];
//   :::paragraphs{style="haiku"}       :::paragraphs{style="by"}
//   夏草や兵どもが夢の跡                   曾良
//   :::                                :::

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

#Space the haiku's three phrases

School anthologies sometimes set an ideographic space between the 5, 7 and 5 sounds, for readers learning the form; the space is a character of the text.

-{夏草|なつくさ}や{兵|つはもの}どもが夢の跡
+{夏草|なつくさ}や {兵|つはもの}どもが 夢の跡

#Let a long tanka break

Without keepStanzas, a tanka may start at the foot of a page and go on overleaf as the orphan and widow rules allow, as a dense anthology of a thousand poems would.

-:::verse{style="tanka" keepStanzas=3}
+:::verse{style="tanka"}

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

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 →

Credits

Text
Fonts
Shippori Mincho (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
SandboxPDF