本文へスキップ
レシピ番号117

レシピ集 · 第1章 · ページとグリッド

ルビ付きの縦組み文庫

夏目漱石『夢十夜』をA6の文庫判に組みます。1行38字×15行、右から読み、難読の漢字にルビを振り、見出しは3行取りです。

このページの内容
出力
Canvas · PDF
レベル
中級
Postext
Postext 1.65.0で検証済み
1.28.0以上が必要 · postext-pdf ≥ 1.28.0
ライセンス
2026年10月11日更新
コードMIT · 本文CC BY 4.0

二〜三ページ · 2〜3/9

  • 英語の見本:日本語版はまだありません
  • 仕上がり105 × 148 mm
  • 1段
  • Shippori Mincho B1 9/15.8
  • Noto Sans JP
  • 9ページ
  • レベル
  • Postext 1.65.0
  • 組版時間74 ms
  • コード145行

かんたんな説明

日本の古典の冒頭を文庫本の形にします。文字は上から下へ行を作り、右から左へ読み進め、むずかしい字の横には小さなかなを添えます。

できあがり

夏目漱石『夢十夜』の第一夜と第二夜を、日本の文庫本として組んだ9ページです。判型は105×148mmのA6、右綴じです。扉は背の左側に一枚だけ置き、2ページ目から本文が上から下へ行を作り、右から読み進めます。1行38字、15行、Shippori Mincho B1の9ptで、行送りは1.75emです。青空文庫が難読の漢字に付けている読みは、半分の大きさのかなでその横に立ちます。各夜の題はグリッドの3行を取り、左ページには小口側に本の題が縦に入り、その下に漢数字のノンブルが付きます。同じ構造のヨーロッパの文庫はNo. 104、中国語の縦組み小説はNo. 075です。

このレシピが答える質問

  • 日本語の小説を、文庫本のように縦組み・右綴じで組むには?
  • 漢字に、1字ごとまたは語全体に1つの読みでふりがなを付けるには?
  • 青空文庫のテキストをPostextの本にするには?
  • 日本語の見出しを本文3行分(3行取り)にして、本文をグリッドに乗せたままにするには?

手短な答え

script.js · 33〜52行コード全体で見る
// '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
};

材料

種類
Shippori Mincho B1, Noto Sans JP (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · ページを回し、字数で数え、jaのタグを付ける

コードは上の手短な答えにあります。layout.writingMode: 'vertical-rl'は、横組みのページを時計回りに90度回したものとして各ページを組みます。page.bindingを'auto'のままにすると、縦組みの本は右綴じになります。1ページ目は奇数ページのままですが背の左側に来て、mirror: trueがそののど側の余白を右に置きます(縦組み、綴じ)。文字グリッドは、版面を縦に9ptの文字38字(120.7mm)、横に15.75ptの行15行(83.3mm)にします。pageの余白は最小値で、グリッドは向かい合う余白を同じ量ずつ広げるため、天は地より4mm深いままです。余白に収まる以上の行数を求めると、グリッドは何も言わずに1行減らします(doc.configWarningsにcjkGridClampedが出ます)。15行が収まるのは、のど9mm、小口12mmだからです。

残りはlocale: 'ja'が日本の本の組み方に設定するので、ここに書いたcjkの4行は何も変えません。このタグが何を選ぶかを見せるために書いてあります。ja-very-strictはJIS X 4051の行頭禁則で、行頭に、。」やー、っのような小書きのかなを置きません。hangingPunctuation: 'allow'は、行頭に来てしまう、や。を前の行の最後の字の下にぶら下げます。文庫は行を詰める代わりにこうします。paragraphStartBracket: 'half'はJLReqの③の形式です。「で始まる段落は1字下げの後半にかぎ括弧を置くので、会話の最初の字が他の段落の最初の字と同じ位置にそろいます(東アジアの組版)。中国語の本はどちらの点でも違い、既定ではぶら下げをせず、括弧の有無にかかわらず段落を2字下げます。

#2 · 各夜の題にグリッドの3行を与える

script.js · 56〜63行コード全体で見る
// 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
};

日本語の見出しは本文の行を整数で占めます。これが行取りで、見出しのあとの行も前の行と同じグリッドに乗ります。lineSpan: 3は「第一夜」を15.75ptの行3つ分の帯に置き、字をその中央にそろえます。見出しの12.5ptはグリッドを動かしません。6ページでは「第二夜」がページの最初の3行を占め、そのあとの本文はグリッドの4行目から始まります。indent: em(5)は本文の字数で読みます(五字下げ)。青空文庫のテキストが中見出しをこう示し、JLReqも見出しの字下げをこう数えます(レベルごとの上書き)。

#3 · 本文とルビを青空文庫から持ってくる

2つの夜は青空文庫の図書カード799から取り、postext-portスキルのaozora.pyで変換しています。変換スクリプトはファイルをCP932として読み、仰向《あおむき》と書かれた読みを、語全体に一続きのかなを振るグループルビ{仰向|あおむき}に変え、[#5字下げ]…[#「第一夜」は中見出し]を見出しに変えます。jaの文書では、ルビはJIS X 4051に従います。親文字より短いルビは1:2:1の比で親文字に沿って割り付け、長いルビは隣のかなには掛かっても漢字には掛かりません(圏点と傍線、ルビ、割注)。行送り1.75emで行間は6.75ptとなり、4.5ptのルビが入る余地ができます。

#4 · 柱を小口側に縦に、ノンブルを漢数字に

script.js · 67〜78行コード全体で見る
// 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: [] };

縦組みの文庫では、柱は小さく、外側の余白に置きます。anchor.to: 'outer'は要素をそこに置きます。右綴じの本では、奇数ページなら左の余白、偶数ページなら右の余白です。writingMode: 'vertical-rl'はそれを上から下へ組みます(縦組みのテキスト要素)。題「夢十夜」は左ページにだけ入り(parity: 'odd')、pages: 'body'にすれば章の始まるページからは外れます。pageNumbering.format: 'japanese-informal'はノンブルを二、三…九と刷ります(ノンブル)。

#5 · 扉を仕上がりの中央に置く

script.js · 82〜110行コード全体で見る
// 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) },
  ] } },
};

扉は独自のスタイルを付けたレベル1の見出し# 夢十夜 {style="title" …}で、そのデザインがページを埋めます。要素は版面ではなくページそのものに固定します。左右対称にしたページの版面は中心から1.5mmずれているからです。xはページを下へ、yは右端から横へ進むので、AXISは背のどちら側でもページ幅の半分になります。フッターの奥付はNoto Sans JPで組みます。Shippori Mincho B1にはōもūもなく、PDFではSōsekiの字が空の箱になってしまいます。

#6 · ウェイトごとに、組む文字の分だけ読み込む

script.js · 219〜228行コード全体で見る
// 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は日本語書体の各ウェイトを、文字の範囲ごとに分けたおよそ120のファイルで配信します。loadCjkFontsは、渡されたテキストが触れるファイルだけを取ってきます。本文のウェイトには見本全体をvertical: true付きで渡します。これでCanvas用に書体の縦組み用字形も読み込まれます。、。「」とー、それに縦組みでは字面の右上に立つ小書きのかなです。renderToPdfはcjkPdfProviderを受け取り、同じファイルをサブセットとして埋め込みます。

レシピの全体

Sandbox
// ═══ 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

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#原文が強調する語に印を付ける

漱石の第一夜と第二夜には圏点がありませんが、青空文庫の多くの作品にはあり、変換スクリプトはそれを:dots[…]{style=sesame}と書きます。jaの文書では*…*も行の横に同じゴマ点を付け、イタリックにはしません。

-こんな夢を見た。
+こんな*夢*を見た。

#かぎ括弧を全角1字下げる

①の形式は1字下げを残し、そのあとにかぎ括弧を置きます。年少の読者向けの小説の多くがこうしています。

-  paragraphStartBracket: 'half', // ③: a 「 that opens a paragraph fills the indent cell
+  paragraphStartBracket: 'indent', // ①: the bracket after the one-character indent

#ぶら下げの代わりに詰める

hangingPunctuation: 'none'にすると、行頭に来てしまう、や。は、括弧や読点を詰めて前の行に収めるか(追い込み)、行末の字を道連れに次の行へ送ります(追い出し)。行の下に約物がはみ出すことはありません。

-  hangingPunctuation: 'allow', // ぶら下げ: a 、。 that would open a line hangs below the last
+  hangingPunctuation: 'none',

よくあるつまずき

つまずき

日本語のテキストのタグは'ja'。zh-HansやLANGにしない

レシピの版はenとesですが、日本語のサンプルはどちらの版でも日本語です。`locale: LANG`では英語やスペイン語とタグ付けされ、中国語のタグでは中国語の規則で組まれます(開明式の約物、小書きの仮名が行頭に来てもよい、図の代わりに图、PDFでは中国の字形)。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、'ja'以外のタグでは日本語の字形ではなく別の字形(中国語のタグでは中国の字形)になり、改行の位置も変わります。'ja'と書いてください。日本の地域(JLReqの改行と約物、ゴマの圏点、ルビの間隔、図と表の表示名)が選ばれ、ハイフネーションが切られます。リントは、zhやkoのタグで仮名を含むテキストをエラーにします。 日本語の改行(禁則処理) →

つまずき

中国語の書体はcjkブロックを通じてスライス単位で読み込む

Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →

つまずき

右綴じの本の見開きはshowBookで表示する

右綴じの本(アラビア語、ヘブライ語、ペルシア語のテキスト、縦組みの中国語、またはpage.binding 'right')でも1ページは奇数ページですが、背の左側に来て、見開きは[3 | 2]と並びます。showPagesはどの本も左綴じとして並べます。bookブロックのshowBook(cjkブロックにも同じ関数があります)はdoc.bindingを読み、見開きを左右反転します。capture.heroでは、見開きは引き続き読む順の[偶数ページ, 奇数ページ]、つまり[2, 3]と指定します。 右綴じの本 →

つまずき

青空文庫のファイルはShift_JISではなくCP932として読む

青空文庫のテキストファイルはWindows-31J(CP932)です。ただのShift_JISとしてデコードすると、ダッシュ――はemダッシュ(U+2014)に、~は波ダッシュ〜になり、NECやIBMの文字のいくつかは失敗します。cp932として読み、そのあとで記法を変換してください。《》のルビ、[#…]の注記、※[#…]の外字はMarkdownではないので、残すとそのまま印字されます。スキルのaozora.pyは両方を行います。 青空文庫の取り込み →

つまずき

Fontsourceの範囲は、ファイルにない文字を含むことがある

Fontsourceは各ファイルにunicode-rangeを与え、loadCjkFontsはサンプルを範囲で覆うファイルを読み込みますが、範囲はファイルの実際の中身より多くを主張することがあります。Zen Old MinchoのU+3028–303Fの断片には〻も長い繰り返し記号〳〴〵もなく、この書体にはマクロン付きの母音ō ū āもありません。Shippori Mincho B1のlatin-extファイルにはわずかな文字しかなく、ō、ū、āはどれも含まれません。サンプルの実行中は何も失敗しません。画面ではこれらの文字がシステムの書体で出てその書体で計測され、PDFにはフォントの.notdefの四角が印字されます。それを報告するのは、あとで行うC25の検査だけです。珍しい記号やローマ字の語は、書体を選ぶ前にフォントで確認し(Fontsourceのファイルに対してfontToolsを使う)、それを持つ書体で組んでください。Shippori Mincho B1とNoto Serif JPには〻と〳〴〵があり、Noto Serif JPとNoto Sans JPにはマクロン付きの母音があります。 中国語・日本語・韓国語のフォント →

つまずき

縦組みのページには、回転した本文の座標系と用紙の座標系の2つがある

vertical-rlの文書は、本文を時計回りに90度回した横組みのページとして組み、見出しのデザイン(advancedDesign.slotの要素)もその回転した座標系に置きます。xはページを下へ、yは右端から左へページを横切って進み、要素の幅はページの下方向に測ります。ヘッダーとフッターの要素は用紙の座標系のままで、xは左端から右へ、yは上端から下へ進みます。そのため、ヘッダーに描いた枠と見出しのデザインに置いたタイトルとでは、オフセットを取る軸が異なります。縦組みの本扉では、要素を`page`に固定し、その端から測ってください。`container`に固定すると、フッターの要素は版面の中心から数mm(約5 mm)ずれます。 縦組み →

クレジット

レシピ
Ignacio Ferro
本文
フォント
Shippori Mincho B1 (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
SandboxPDF