かんたんな説明
子どもが声に出して読めるよう、すべての漢字の上に小さなかなを刷った国語の教科書の1ページです。Postextは読みを親文字の上に置き、長い読みは隣のかなに掛けますが、別の漢字には掛けません。
できあがり
新美南吉の『ごんぎつね』(1932年)の冒頭のページを、小学4年生の国語の教科書の体裁で組みます。日本の子どもなら誰もが9歳か10歳で出会う物語です。B5判の1ページに、教科書の手書き文字をもとにした書体Klee Oneで28字×21行を組みます。文字サイズは14 pt、行送りは28 ptで、すべての漢字の上に小さなかなの読みが付きます。主役はこの読みです。村と森には1字ごとの読みを、1字ずつの読みがない百舌鳥(もず)には語全体でひとつの読みを付けます。兵十(ひょうじゅう)には熟語ルビを付け、読みは長すぎる場合を除いてそれぞれの漢字の上に収まります。最後の囲みでは、指導者向けにこの3つの場合を示します。ピンインの入門読本では、同じ方法で中国語のすべての字の上に読みを付けています。
このレシピが答える質問
- 漢字に、1字ごとまたは語全体に1つの読みでふりがなを付けるには?
手短な答え
// In a document tagged 'ja' the compact {漢字|かん|じ} (one reading per character) is jukugo
// ruby: each reading stays over its own kanji when it fits, and when one is longer it may run
// onto the next kanji of the same word; a break may fall between the two. {百舌鳥|もず} (one
// reading for the word) is group ruby, spread over the word 1:2:1. :ruby[菜種]{rt="な たね"
// mode=jukugo} says the same as the compact form; mode=mono keeps each reading to its kanji.
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
ruby: {
fontSize: em(0.5), // 7 pt: half the text, the size JLReq gives furigana
color: col('reading'),
align: 'jis', // a reading shorter than its base: ½ unit at each end, 1 between (1:2:1)
overhang: 'kana', // a longer reading may run one ruby character onto a kana, never a kanji
smallKana: 'keep', // ひょう with its small ょ, as today's books print it
},
};
// The line gap (28 − 14 = 14 pt) holds a 7 pt reading with room to spare: no line moves for one.
const bodyText = {
fontFamily: TEXT, fontSize: pt(SIZE), lineHeight: pt(PITCH), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: em(1), indentAfterHeading: true,
avoidRunts: true, // no paragraph ends on one character
};
材料
- 機能
- ふりがな:漢字に付ける仮名の読みルビ:ピンインと注音仮名、漢字、ローマ字日本語の圏点(傍点)中国語・日本語・韓国語のフォント文字グリッド日本語の約物のアキ日本語の改行(禁則処理)行取りの見出しデザインした章扉見出しの属性囲み柱とノンブル見開きの余白用紙の色段落スタイルセマンティックカラーパレット青空文庫の取り込みPDFの書き出し
- 種類
- Klee One, Zen Maru Gothic (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 読みの3つの書き方
コードは前出の手短な答えにあります。Markdownでは、{村|むら}で村の上に「むら」を置きます。{兵十|ひょう|じゅう}は漢字ごとに読みを与え、'ja'のタグを付けた文書ではこれが熟語ルビになります。読みは収まる限りそれぞれの漢字の上にとどまり、長い読みは同じ語の次の漢字には掛かっても、別の語の漢字には掛かりません。3つの漢字にひとつの読みを付ける{百舌鳥|もず}はグループルビで、語全体にひとまとまりとして配置されます。:ruby[菜種]{rt="な たね" mode=jukugo}は、囲みの最後の例をディレクティブの形で書いたものです。この形ではmode=monoとalignも指定できます(圏点と傍線、ルビ、割注)。

#2 · 1:2:1と、かなにだけ掛ける読み
cjk.rubyの下の2つの設定は、'ja'が自動で選ぶ値です。align: 'jis'は、親文字より短い読みをJIS X 4051の方式で配置します。両端に半単位、かなの間に1単位のスペースを入れるので、25ページの百舌鳥では「も」と「ず」が中央に固まらず、字と字の継ぎ目の上に来ます。overhang: 'kana'は、親文字より長い読みを、隣のかなや約物のアキにルビ1字分まで掛けることを許し、漢字には掛けません。「ごん狐」の狐に付く「ぎつね」は「ん」と後ろのかぎ括弧に掛かり、「兵十だな」の「じゅう」は「だ」に掛かります。掛けられるかながない場合は、漢字のほうを読みの幅まで広げます。行頭や行末では、読みは行長の内側にとどまります。

#3 · 読みが収まる行間
読みは本文14 ptの半分の7 pt、行送りは28 ptです。2行の間の14 ptに読みが余裕をもって収まるので、グリッドのどの行も位置を変えません。行送りを本文と読みの合計より詰めると、ビルドがrubyExceedsLeadingの警告を出します。
#4 · 冒頭のページには読みを刷らない
// Design text sets no furigana (gotcha: ruby-not-in-designs): the author's reading is a
// line of its own.
const BAND = 92; // mm from the trim's top
const opener = { enabled: true, minHeight: pt(PITCH * 6), slot: { elements: [
{ kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('straw') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(BAND) } } },
{ kind: 'text', id: 'unit', content: '{attr.unit}', fontFamily: ROUND, fontSize: pt(16),
fontWeight: 700, color: col('paper'), align: 'center', verticalAlign: 'middle',
overflow: 'clip', box: { backgroundColor: col('red'), borderRadius: mm(6) },
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(-2) },
size: { width: mm(12), height: mm(12) } } },
{ kind: 'text', id: 'series', content: '{title}', fontFamily: ROUND, fontSize: pt(9),
fontWeight: 700, letterSpacing: pt(2), color: col('red'), align: 'left',
verticalAlign: 'middle', placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(16), y: mm(-2) }, size: { width: mm(80), height: mm(12) } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: ROUND, fontSize: pt(48),
lineHeight: 1.1, fontWeight: 700, color: col('ink'), align: 'left',
placement: { anchor: { to: '#unit', edge: 'below' }, offset: { y: mm(7) } } },
{ kind: 'text', id: 'kana', content: '{attr.kana}', fontFamily: ROUND, fontSize: pt(8),
letterSpacing: pt(1), color: col('muted'), align: 'left',
placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(5) } } },
{ kind: 'text', id: 'author', content: '{attr.author} 作', fontFamily: ROUND,
fontSize: pt(13), fontWeight: 500, color: col('ink'), align: 'left',
placement: { anchor: { to: '#kana', edge: 'below' }, offset: { y: mm(1) } } },
] } };
タイトルと作者名はデザイン要素のテキストで、ルビは組めません。そこで新美南吉の読みは、教科書の刷り方にならって、名前の上にかなで独立した1行として置きます。タイトル自体も教科書の表記どおり、かなで「ごんぎつね」と書きます。青空文庫のテキストでは題が「ごん狐」です。
#5 · ひとつのアクセント色と、少し淡い読み
const palette = {
ink: '#2a2420', // text: a warm near-black
red: '#b2402c', // the one accent: the unit badge, the section numbers, the box title
reading: '#5a4e45', // the furigana, a shade off the ink so the two layers part
straw: '#f6ecd6', // the opener band and the box
muted: '#7a6d62', // folios, the series line, the colophon
paper: '#fffdf8',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.red })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
読みには、墨より一段明るい茶色のreadingを使います。かなが薄くなりすぎることなく、本文と読みの2つの層を目で区別できます。物語に咲く彼岸花の赤を、バッジ、節番号、囲みのタイトルに使います。
レシピの全体
// ═══ Postext Cookbook · Nº 124 · A school reader with furigana: per character, per word ═══
// https://postext.dev/en/cookbook/jukugo-furigana-textbook
// Code: MIT · Text: 新美南吉「ごん狐」(1932), Aozora Bunko 628 (PD); readings: CC BY 4.0
// Fonts: Klee One, Zen Maru Gothic (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, withLoadedFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the frame; the story is Japanese in both
const RECIPE = 'jukugo-furigana-textbook';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: an autumn reader: ink, the red of the higanbana, a pale straw ground
const palette = {
ink: '#2a2420', // text: a warm near-black
red: '#b2402c', // the one accent: the unit badge, the section numbers, the box title
reading: '#5a4e45', // the furigana, a shade off the ink so the two layers part
straw: '#f6ecd6', // the opener band and the box
muted: '#7a6d62', // folios, the series line, the colophon
paper: '#fffdf8',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.red })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [TEXT, ROUND] = ['Klee One', 'Zen Maru Gothic']; // 教科書体-like text, rounded gothic
const [SIZE, PITCH] = [14, 28]; // pt: a fourth-year reader's size, on a line twice as tall
const [CHARS, LINES] = [28, 21]; // the type area in characters
// #region answer: readings over every kanji: by character, by word, jukugo, JIS 1:2:1
// In a document tagged 'ja' the compact {漢字|かん|じ} (one reading per character) is jukugo
// ruby: each reading stays over its own kanji when it fits, and when one is longer it may run
// onto the next kanji of the same word; a break may fall between the two. {百舌鳥|もず} (one
// reading for the word) is group ruby, spread over the word 1:2:1. :ruby[菜種]{rt="な たね"
// mode=jukugo} says the same as the compact form; mode=mono keeps each reading to its kanji.
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
ruby: {
fontSize: em(0.5), // 7 pt: half the text, the size JLReq gives furigana
color: col('reading'),
align: 'jis', // a reading shorter than its base: ½ unit at each end, 1 between (1:2:1)
overhang: 'kana', // a longer reading may run one ruby character onto a kana, never a kanji
smallKana: 'keep', // ひょう with its small ょ, as today's books print it
},
};
// The line gap (28 − 14 = 14 pt) holds a 7 pt reading with room to spare: no line moves for one.
const bodyText = {
fontFamily: TEXT, fontSize: pt(SIZE), lineHeight: pt(PITCH), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#読みのかなを並字にする
古い本では、ルビの「っ」や「ょ」を並字で刷り、「がっこう」を「がつこう」と書きました。smallKana: 'full'は同じ表示にし、読み上げやコピーで得られるテキストは変えません。
- smallKana: 'keep', // ひょう with its small ょ, as today's books print it
+ smallKana: 'full', // ひよう: the small kana at full size, as letterpress books printed them#すべての読みを中央に置く
align: 'center'は、短い読みを親文字の中央に置きます。中国の本の多くはこの配置です。日本語の既定は1:2:1です。
- align: 'jis', // a reading shorter than its base: ½ unit at each end, 1 between (1:2:1)
+ align: 'center', // も ず together in the middle of 百舌鳥よくあるつまずき
つまずき
日本語のテキストのタグは'ja'。zh-HansやLANGにしない
レシピの版はenとesですが、日本語のサンプルはどちらの版でも日本語です。`locale: LANG`では英語やスペイン語とタグ付けされ、中国語のタグでは中国語の規則で組まれます(開明式の約物、小書きの仮名が行頭に来てもよい、図の代わりに图、PDFでは中国の字形)。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、'ja'以外のタグでは日本語の字形ではなく別の字形(中国語のタグでは中国の字形)になり、改行の位置も変わります。'ja'と書いてください。日本の地域(JLReqの改行と約物、ゴマの圏点、ルビの間隔、図と表の表示名)が選ばれ、ハイフネーションが切られます。リントは、zhやkoのタグで仮名を含むテキストをエラーにします。 日本語の改行(禁則処理) →
つまずき
日本語は日本語の書体で組む
Noto Serif SCとTCは仮名を持っていますが、漢字は中国の字形(直、骨、角が異なります)で、仮名も中国のデザインで描きます。本文はNoto Serif JPかShippori Mincho B1、見出しはNoto Sans JPで組み、loadCjkFontsで読み込んでください。Fontsourceの日本語ファイルには変体仮名などの古い仮名(U+1B000–1B16F)がないため、loadCjkFontsはそこで失敗し、PDFには四角が印字されます。現代の仮名で書くか、それを持つ書体をレシピのassetsに同梱してください。Shippori Minchoにはマクロン付きの母音ōとūもないので、ローマ字はラテン文字の書体で組んでください。 仮名、漢字、ローマ字 →
つまずき
中国語の書体はcjkブロックを通じてスライス単位で読み込む
Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →
つまずき
ルビは本文に出て、デザイン、キャプション、セルには出ない
ルビは段落、見出し、リスト項目、引用、囲みで描かれます。デザインのテキスト要素(章扉、柱、バッジ)、キャプション、脚注、表のセルでは、ルビなしで親文字だけが印字されます。ピンインが必要なタイトルは、独自のデザインを持たない見出しにしてください。その周り(帯や課の番号)は直前の見出しのデザインで描きます。reserve: falseの要素は、span: 'page'の章扉の本文の下に描かれます。 ルビ:ピンインと注音 →
つまずき
青空文庫のファイルはShift_JISではなくCP932として読む
青空文庫のテキストファイルはWindows-31J(CP932)です。ただのShift_JISとしてデコードすると、ダッシュ――はemダッシュ(U+2014)に、~は波ダッシュ〜になり、NECやIBMの文字のいくつかは失敗します。cp932として読み、そのあとで記法を変換してください。《》のルビ、[#…]の注記、※[#…]の外字はMarkdownではないので、残すとそのまま印字されます。スキルのaozora.pyは両方を行います。 青空文庫の取り込み →
レイアウト警告 · rubyExceedsLeading
ルビが次の行に接触
原因. 本文の上または下にルビを付けた段落で、行間がルビより狭くなっています。ルビは行間に置かれるため、隣の行に接してしまいます。
対処. 段落の行送りを大きくする(少なくとも文字サイズに`cjk.ruby.fontSize`を加えた値)か、ルビを小さくしてください。 ドキュメント →
- 青空文庫は語全体にひとつの読みを書き(兵十《ひょうじゅう》)、変換ツールはこれをグループルビ
{兵十|ひょうじゅう}として保ちます。熟語ルビにするには、読みを漢字ごとに手で分けてください:{兵十|ひょう|じゅう}。 - 縦棒で区切った読みが1字ごとの部分に分けられるのは、部分の数が親文字と一致する場合だけです。
{一人|ひ|と|り}は2つの漢字に3つの部分があるので、語全体でひとつの読みとして組まれます。一人にはもともとそれが必要です。
クレジット
- 本文
- “Gon gitsune” (ごん狐), section 1, by Niimi Nankichi (1932): Aozora Bunko card 628, base text 新美南吉童話集 (Iwanami Bunko, 1996, second printing 1997), input by 林裕司, proofing by 浜野智 · Niimi Nankichi (1913–1943) · パブリックドメイン
- The readings over every kanji, the box on furigana and the opener’s labels · Postext Cookbook · CC BY 4.0
- フォント
- Klee One (SIL OFL 1.1) · Zen Maru Gothic (SIL OFL 1.1)


