Skip to main content
Recipe number 120

Cookbook · Chapter 1 · Page & grid

A story on genkō yōshi, one character to a square

Botchan's opening on 400-square manuscript paper: a drawn 20 × 20 grid, a character or mark in every square, and any 、。 that cannot head a line hung below.

On this page
Output
Canvas · PDF
Postext
Tested with Postext 1.65.0
Needs ≥ 1.28.0 · postext-pdf ≥ 1.28.0
Licence
Updated 11 Oct 2026
Code MIT · Text CC BY 4.0
  • Trim 230 × 200 mm
  • 1 column
  • Klee One 20/27
  • Noto Sans JP
  • 3 pages
  • Level
  • Postext 1.65.0
  • Laid out in 52 ms
  • 131 lines of code

In short

Japanese manuscript paper has a square for every character. This page writes the first lines of a famous novel on it, with the title, the author's name and each punctuation mark where Japanese school rules put them.

What you'll build

Three sheets of Japanese manuscript paper (原稿用紙, genkō yōshi), the 400-square kind, with the first three paragraphs of Natsume Sōseki's Botchan copied out on them as a writer or a pupil would: 20 lines of 20 squares, read top to bottom from the right, in Klee One, a face drawn with a pen. The title stands in the first line from the third square and the author's name in the second, one square above the foot; each paragraph starts after one empty square. Every character, small kana and mark has a square of its own, and a 、 or 。 that would head a line is written below the last square of the line before. A red-brown frame, the sheet number and the paper's printed label 20×20 make the sheet. The Chinese page counted in characters is Nº 082.

This recipe answers

  • How do I set the type area in characters, so many to the line and so many lines to the page?
  • Why may small kana, ー and closing brackets not start a line of Japanese, and how do I choose how strict the rule is?

The short answer

script.js · lines 38–53in full code
// The grid makes the type area 20 characters of 20 pt down and 20 lines of 27 pt across, and
// show draws its squares. The marks are set full width with nothing squeezed, so each
// character, mark or bracket fills its own square, as on manuscript paper (原稿用紙).
const cjk = {
  // fullLines: on manuscript paper every square of a full line is written in, so a line
  // gives up no character to keep a lone last one company (the runt rule would leave the
  // twentieth square empty in the middle of a paragraph).
  grid: { enabled: true, charsPerLine: N, linesPerPage: N, show: true, fullLines: true },
  compressAdjacent: false, // 。」 take two squares, not one and a half
  trimLineStart: false, // a bracket at the head of a line keeps its square
  // The manuscript rule: a small kana or ー may head a line (each has its own square), but
  // never 、。 or a closing bracket: such a mark is written in the last square of the line
  // before, hanging below it here, and no line is squeezed to take it in.
  lineBreak: 'ja-loose',
  hangingPunctuation: 'force',
};

20 squares down 20 lines, the squares drawn, every character in one

Ingredients

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

Method

#1 · Draw the squares and give every mark a whole one

The code is the short answer above. The character grid makes the type area 20 characters of 20 pt (7.1 mm) down and 20 lines of 27 pt (9.5 mm) across, and show: true draws its squares in a light grey of its own, on screen, and in the PDF when renderToPdf is given characterGrid: true (a grid is a proofing aid in a book, so a PDF leaves it out by default); the 2.5 mm strip between two lines is where a writer adds readings and corrections. A Japanese mark is half a glyph and half an em of blank, and a book takes in blanks where two marks meet or a bracket starts a line. On manuscript paper each mark keeps its square, so compressAdjacent: false sets 。」 in two squares and trimLineStart: false leaves a bracket at the head of a line its whole square (East Asian typography).

#2 · Follow the manuscript's line rules

Manuscript paper has its own kinsoku. A small kana or ー may start a line, each in its own square; ja-loose allows it. A 、 or 。 that would head a line is written in the last square of the line before, with the character there, or just below it; hangingPunctuation: 'force' hangs it below the twentieth square, and no line is ever squeezed. With 'allow', the default for Japanese, the engine first takes the mark into the line by squeezing a 、 inside it to half a square, which a printed book does and a manuscript never does: the rest of that line would sit half a square up, across the grid's lines.

The last line of a paragraph needs one more setting. Postext keeps a paragraph from ending on a single character: the line before gives it its last one, and since the text here is not justified, that line would stop a square short. On manuscript paper every square of a full line is written in, so the grid sets fullLines: true: on sheet 3 the line that ends 来 keeps its twenty squares and the paragraph closes on た。 alone (character grid).

#3 · Write the title and the name where the rules put them

script.js · lines 57–64in full code
// The title on the first line, two squares down; the writer's name on the second, ending a
// square above the foot (地から一字上げ), a blank square between family and given names.
// lineSpan: 1 keeps the title on one line of the grid, in the text's own size and face.
const title = { level: 1, fontFamily: PEN, fontSize: pt(CELL), fontWeight: 400, lineSpan: 1,
  indent: em(2), breakBefore: { enabled: true, parity: 'any' } }; // the next sheet, either side
const paragraphStyles = [
  { id: 'name', textAlign: 'end', endIndent: em(1), firstLineIndent: em(0) },
];

The title is a heading the size and face of the text, so it fills squares like any other line: lineSpan: 1 keeps it on one line of the grid and indent: em(2) leaves two empty squares above it (Per-level overrides). The name is a paragraph with textAlign: 'end' and endIndent: em(1), which ends it one square above the foot, and the Markdown writes the blank square between family and given name as an ideographic space: 夏目 漱石. The text starts on the third line, each paragraph after one empty square from firstLineIndent: em(1).

#4 · Print the sheet around the squares

script.js · lines 68–92in full code
// The header is drawn on the sheet itself, not in the turned frame of the text: x runs right
// from the left edge, y down from the top. The frame stands 1.5 mm off the squares and 8 mm
// below them, where a 、 or 。 that cannot head a line is written outside the last square.
const box = (id, inset, foot, thickness) => ({ kind: 'box', id, pages: 'all',
  placement: { anchor: { to: 'page', edge: 'top-left' },
    offset: { x: mm(MARGIN.side - inset), y: mm(MARGIN.top - inset) },
    size: { width: mm(GRID.across + 2 * inset), height: mm(GRID.down + inset + foot) } },
  style: { borderColor: col('ruling'), borderWidth: pt(thickness) } });
const FOOT = MARGIN.top + GRID.down + 8; // mm: the frame's foot
const below = (id, content, x, extra) => ({ kind: 'text', id, content, pages: 'all',
  placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(x), y: mm(FOOT + 3) } },
  ...extra });
const header = { elements: [
  box('outer', 2.6, 9.1, 1.2), box('inner', 1.5, 8, 0.4),
  // The sheet number, as a writer numbers the sheets; the paper's printed label.
  below('sheet', '({pageNumber})', MARGIN.side, { fontFamily: PEN, fontSize: pt(9),
    color: col('muted') }),
  below('label', '20×20', MARGIN.side + GRID.across - 12, { fontFamily: 'Noto Sans JP',
    fontSize: pt(7), letterSpacing: pt(0.5), color: col('ruling') }),
] };
const footer = { elements: [{ kind: 'text', id: 'colophon', content: '{attr.colophon}',
  pages: 'opener', fontFamily: 'Noto Sans JP', fontSize: pt(6), lineHeight: 1.4,
  color: col('muted'), overflow: 'wrap', align: 'center',
  placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-5) },
    size: { width: mm(120) } } }] };

The header's elements are drawn on the sheet itself: on a vertical page x runs right and y down from the top-left corner, unlike a heading's design, which is laid out in the turned frame of the text. The double frame stands 1.5 mm off the squares on three sides and 8 mm below them, where the hanging marks fall. GRID and MARGIN place it from the same numbers the page's margins are made of; the margins handed to the page are half a millimetre smaller, because the grid treats them as minimums and an exact fit could round to 19 lines.

#5 · Set it in a pen face

script.js · lines 144–149in full code
// Klee One draws the strokes of a pen, with the Japanese forms of the kanji; its vertical
// forms put 、。 in the upper right of their square and turn ー and the brackets.
const colophon = markdown.match(/colophon="([^"]*)"/)[1];
await loadFonts(FONTS, markdown); // the Latin files: the colophon
await loadCjkFonts({ [PEN]: ['400'] }, `${markdown}()一二三四五六七八九十`, { vertical: true });
await loadCjkFonts({ 'Noto Sans JP': ['400'] }, `20×20${colophon}`);

Klee One is drawn with a pen and keeps the Japanese forms of the kanji, so the sheets read as handwriting without the irregularity of a scan. Its vertical forms put 、。 in the upper right of their square and turn ー and the brackets, which is where a writer puts them. Like every Japanese family on Fontsource it comes as about 120 files, and loadCjkFonts fetches the ones the text needs (Chinese, Japanese and Korean fonts).

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 120 · A story on genkō yōshi, one character to a square ═══
// https://postext.dev/en/cookbook/genko-yoshi-manuscript
// Code: MIT · Text: 夏目漱石『坊っちゃん』, Aozora Bunko 752 (public domain) · Pictures: none
// Fonts: Klee One, 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 manuscript is Japanese in both
const RECIPE = 'genko-yoshi-manuscript';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: blue-black ink on a sheet ruled in red-brown
const palette = {
  ink: '#1f2a44', // the pen: a blue-black
  ruling: '#b0573f', // the sheet's printed frame, its label
  muted: '#7b6f66', // the sheet number
  paper: '#fdfaf3',
};
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.ruling, model: 'hex' } },
];
// #endregion
const PEN = 'Klee One'; // a pen-written kaisho with Japanese forms
const [CELL, PITCH, N] = [20, 27, 20]; // pt: a 7 mm square, a 2.5 mm strip beside each line
const PT = 25.4 / 72; // mm in a point
const SHEET = { w: 230, h: 200 }; // mm
const GRID = { down: N * CELL * PT, across: N * PITCH * PT }; // 141.1 × 190.5 mm
const MARGIN = { top: 32, side: (SHEET.w - GRID.across) / 2 }; // mm
// The margins handed to the page are a hair smaller: the grid takes them as minimums and
// grows them back, where an exact fit could round to 19 lines.
const SLACK = 0.5; // mm

// #region answer: 20 squares down 20 lines, the squares drawn, every character in one
// The grid makes the type area 20 characters of 20 pt down and 20 lines of 27 pt across, and
// show draws its squares. The marks are set full width with nothing squeezed, so each
// character, mark or bracket fills its own square, as on manuscript paper (原稿用紙).
const cjk = {
  // fullLines: on manuscript paper every square of a full line is written in, so a line
  // gives up no character to keep a lone last one company (the runt rule would leave the
  // twentieth square empty in the middle of a paragraph).
  grid: { enabled: true, charsPerLine: N, linesPerPage: N, show: true, fullLines: true },
  compressAdjacent: false, // 。」 take two squares, not one and a half
  trimLineStart: false, // a bracket at the head of a line keeps its square
  // The manuscript rule: a small kana or ー may head a line (each has its own square), but

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

#Check a book's grid with the same squares

show: true works on any character grid: on the bunko of Nº 117 it draws the 38 × 15 squares over the text, a quick check that every line keeps to the grid and every heading to its three lines.

-  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
+  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES, show: true },

#Let the marks squeeze, as a printed page does

With the Japanese default the sheets read like a book typed on squared paper: a 、 that would head a line is taken in by squeezing another one, and the rest of that line sits half a square off the grid.

-  hangingPunctuation: 'force',
+  hangingPunctuation: 'allow',

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 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

Text
  • 夏目漱石『坊っちゃん』 (Botchan, 1906), the first three paragraphs, without the readings; Aozora Bunko card 752, from 「ちくま日本文学全集 夏目漱石」 (Chikuma Shobō, 1992), input 真先芳秋, proofreading 柳沢成雄, converted with aozora.py · Natsume Sōseki; Aozora Bunko volunteers · public domain
Fonts
Klee One (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
SandboxPDF