かんたんな説明
中国の古典的な字典の4ページです。各ページの上の隅に最初と最後の項目が出るので、ページをめくりながら字を探せます。
できあがり
『康熙字典』(1716年)の読者向けの版から、中ほどの4ページを取り出し、天(tiān)から庭(tíng)までピンイン順に並べ替えたものです。見出し字は赤の宋体Blackで組み、上にピンインを添えます。韻書の読み(反切)と字義は1つの段落に続け、字義には同じ赤で①②と番号を付けます。判型は大32开、140 × 203mm。小五(9pt)の17字詰め2段を31行のグリッドに組み、どの段も最後の行まで埋めます。各ページの小口側の隅にある柱は、そのページの最初と最後の見出し字を示すので、蜩を探す読者は柱が「腆—髫」のページを開きます。比べるなら、ラテン文字の辞書The Sailor’s Word-Bookがあります。
このレシピが答える質問
- 辞書の柱に、各ページの最初と最後の見出し語を印字するには?
- 漢字の上にピンインを付けるには?
- 中国語の文字を、空の四角にせずにPDFへ入れるには?
手短な答え
// Each headword is a level-2 heading, '## {天|tiān}'. {firstMark.h2} prints the text of the
// first one that starts on the page, without its reading, and {lastMark.h2} the last; a
// page on which none starts repeats the one in force. They stand at the outer corner, the
// folio outside them, over a hairline as wide as the type area.
const HEAD_Y = 11; // mm from the top edge to the top of the guide words
const [GUIDE, FOLIO] = [10.5, 8]; // pt
const head = (id, content, parity, x, size, extra) => ({ kind: 'text', id, content, parity,
fontFamily: HEI, fontWeight: 700, fontSize: pt(size), lineHeight: 1, color: col('ink'),
// A design line puts its baseline 0.8 of its height down: the folio drops to share it.
placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
offset: { x: mm(parity === 'even' ? x : -x), y: mm(HEAD_Y + 0.8 * (GUIDE - size) * PT) } },
...extra });
const folio = { color: col('muted') };
const guideWords = [
head('verso-folio', '{pageNumber}', 'even', SIDE, FOLIO, folio),
head('verso-guide', '{firstMark.h2}—{lastMark.h2}', 'even', SIDE + 8, GUIDE),
head('recto-guide', '{firstMark.h2}—{lastMark.h2}', 'odd', SIDE + 8, GUIDE),
head('recto-folio', '{pageNumber}', 'odd', SIDE, FOLIO, folio),
{ kind: 'rule', id: 'hairline', direction: 'horizontal', thickness: pt(0.5), color: col('ink'),
placement: { anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(SIDE), y: mm(HEAD_Y + 5.5) }, size: { width: mm(AREA.width) } } },
];
材料
- 機能
- 柱に出す見出し語ルビ:ピンインと注音文字グリッド1段組みと2段組み段間罫段末そろえ中国語・日本語・韓国語のフォント中国語の改行中国語の約物の幅字間による両端そろえ柱とノンブル裁ち落としの帯とツメデザイン要素の基準位置太字・イタリックとその色段落スタイル見開きの余白セマンティックカラーパレットPDFの書き出し
- 併用する機能
- 用紙の色PDFに埋め込むフォント明示的な縦のアキ
- 種類
- Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 見出し字から柱の見出し語を作る
コードは上の手短な答えにあります。見出し字はどれもレベル2の見出しで、{firstMark.h2}と{lastMark.h2}は、そのページで始まる最初と最後のレベル2見出しのテキストを印字します(テキスト要素)。マークになるのは見出しの文字です。## {天|tiān}は天をマークし、読みは見出し字の上に残ります。あるページから次のページへ続く項目は、見出し字のあるページでだけ数えます。635ページは殄の終わりで始まり、柱は「腆—髫」です。レベル1はアルファベットの見出し用に取ってあります。この4ページでは1つも始まりませんが、アルファベットの見出しは柱の見出し語には数えられません。
#2 · 見出し字の上にピンイン
// A heading with no design of its own keeps its reading: '## {天|tiān}' sets tiān over 天.
// Two grid lines hold the headword and a 7.5 pt reading, so every entry stays on the grid.
// A Latin reading stands clear of its base by its descenders: the g of tīng stays off 汀.
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
// The regular Song, not the heading's Black: a reading takes the face of its base.
ruby: { fontFamily: SONG, fontSize: em(0.5), color: col('cinnabar') },
};
const headword = { level: 2, fontSize: pt(15), lineHeight: pt(2 * LEAD), marginTop: pt(0),
marginBottom: pt(0) };
{天|tiān}は:ruby[天]{rt="tiān"}の短縮形で、1文字に1つの読みを付けます(中国語の記号、ルビ、割注)。独自のデザインのない見出しは読みを組みますが、見出しにデザインを付けると天だけが印字されます。読みは、cjk.ruby.fontFamilyで書体を指定しないかぎり見出しと同じBlackになるので、レギュラーの宋体を指定しています。15ptの半分は7.5ptで、見出しの30ptの行には見出し字の上にそれを置く余地があります。そのため見出しはグリッド2行分になり、その下の本文は両段とも15ptの行に乗ったままです。ピンインの読みは、その書体のディセンダーの深さに0.04emを足した分だけ持ち上がるので、tīngのgは汀の仮想ボディの0.6pt上で終わります。
#3 · 1項目を1段落に
// As the Kangxi Dictionary sets an entry: the rhyme-book readings (反切), then the senses
// run in, each after its number. '**②**' marks a number, and the text prints its bold in
// cinnabar: the only bold on these pages. A circled number is a Chinese character to the
// composer: no line ends on one, away from the sense it opens, and no space follows it.
const bodyText = { fontFamily: SONG, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('cinnabar'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: pt(0) }; // no indent: the headword opens the entry
『康熙字典』は項目を追い込みで組みます。まず韻書の読み、続いて又で始まる各字義です。ここでは又を丸数字に替えて**②**と入力し、boldColorで見出し字と同じ朱色に印字しています。本文にほかの太字はありません。『康熙字典』が別の読みを示す字義は、跳の②に徒刀切があるように、自分の読みを保ちます。組版処理は①から⑳を漢字として扱うので、行が番号で終わってその字義が次の行から始まることはなく、番号と本文の間に漢字と欧文の間のアキも入りません。番号はそのまま入力すれば足ります。段末そろえはオフ(headings.balancing.enabled: false)なので、見出し字の上にアキを作る段はなく、どの項目も前の項目と同じ間隔で続きます。
#4 · Tのつめ
const INITIALS = 'ABCDEFGHJKLMNOPQRSTWXYZ'; // no pinyin syllable starts with I, U or V
const STEP = AREA.height / INITIALS.length; // mm: 7.13, the 23 tabs fill the type area's height
const tab = (parity) => {
const edge = parity === 'odd' ? 'top-right' : 'top-left'; // the fore-edge
const at = (x, width) => ({ anchor: { to: 'page', edge },
offset: { x: mm(parity === 'odd' ? x : -x), y: mm(TOP + INITIALS.indexOf('T') * STEP + 0.3) },
size: { width: mm(width), height: mm(STEP - 0.6) } });
// 6 mm inside the trim and 3 mm past it: the page cuts the tab square at the fore-edge
// (a print file with cutLines prints the 3 mm in its bleed); the letter on the 6 mm.
return [
{ kind: 'box', id: `tab-${parity}`, parity, placement: at(3, 9),
style: { backgroundColor: col('cinnabar'), borderRadius: mm(1.2) } },
{ kind: 'text', id: `tab-letter-${parity}`, parity, content: 'T', fontFamily: HEI,
fontWeight: 700, fontSize: pt(9), lineHeight: 1, color: col('paper'), align: 'center',
verticalAlign: 'middle', placement: at(0, 6) },
];
};
ピンインの音節は26文字のうち23文字で始まる(I、U、Vで始まるものはない)ので、版面の高さを7.13mmずつ23段に分け、Tは19番目を占めます。つめは幅9mmで、仕上がり線の3mm外から始まるので、小口では断裁で角がまっすぐに切られ、丸みが見えるのは内側の角だけです。page.cutLinesを指定した印刷用ファイルなら、その3mmは塗り足しに入ります。文字はページの内側に残る6mmの中央に置きます。4ページともTの範囲なので、つめは同じ高さにとどまります。The Sailor’s Word-Bookでは、文字が変わるたびにつめが小口を下へ移っていきます。
#5 · 書体ごとに自分の字を読み込む
// Fontsource cuts a Chinese face into about a hundred files (gotcha: cjk-fonts-slices).
// The regular Song sets the whole sample; each other voice gets only its own text.
const all = (re) => [...markdown.matchAll(re)].map((m) => m[1]).join('');
const heads = all(/^## \{(.+?)\|/gm);
await loadFonts(FONTS, markdown);
await loadCjkFonts({ [SONG]: ['400'] }, markdown);
await loadCjkFonts({ [SONG]: ['700'] }, all(/\*\*(.+?)\*\*/g));
await loadCjkFonts({ [SONG]: ['900'] }, heads);
await loadCjkFonts({ [HEI]: ['700'] }, `${heads}—0123456789T`);
await loadCjkFonts({ [KAI]: ['400'] }, all(/style="colophon-zh"\}\n(.+)\n/g));
Fontsourceは中国語の書体を文字範囲ごとに100ほどのファイルに分けており、loadCjkFontsは渡されたテキストを含むファイルを読み込みます。レギュラーの宋体には、奥付の英語も含めて見本全体を渡します。Blackには30の見出し字、太字のウェイトには字義の番号、黒体には見出し字と柱の数字、楷体には奥付の中国語の1文を渡します。cjkPdfProviderは同じファイルをPDFに埋め込み、それぞれをページで使う文字だけに絞ります。
レシピの全体
// ═══ Postext Cookbook · Nº 086 · A Chinese dictionary page with guide words ═════════
// https://postext.dev/en/cookbook/chinese-dictionary-page
// Code: MIT · Text: 康熙字典 (1716), Wikisource transcription, CC BY-SA 4.0 · Pinyin: CC BY 4.0
// Fonts: Noto Serif TC, Noto Sans TC, LXGW WenKai TC (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 sample document ('en' | 'es')
const RECIPE = 'chinese-dictionary-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black and one cinnabar, the second ink of a two-colour dictionary
const palette = {
ink: '#1f1b17', // text, guide words
cinnabar: '#a52f28', // headwords, their readings, sense numbers, the thumb tab
rule: '#bab2a4', // the column rule
muted: '#5c554d', // folios, colophon
paper: '#fbf8f2', // the page, and the letter reversed out of the tab
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the cinnabar.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.cinnabar })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [SONG, HEI, KAI] = ['Noto Serif TC', 'Noto Sans TC', 'LXGW WenKai TC'];
const PT = 25.4 / 72; // mm in a point
const [BODY, LEAD] = [9, 15]; // pt: 小五 on a 15 pt line, the grid both columns share
const [CHARS, LINES] = [17, 31]; // characters to a column's line, lines to a column
const TRIM = { width: 140, height: 203 }; // mm: 大32开
const MIN = { top: 20, bottom: 16, side: 12 }; // mm: minimums the grid grows to centre the area
// The type area the grid sets (two columns and a 2-em gutter) and the margins it leaves.
const AREA = { width: (2 * CHARS + 2) * BODY * PT, height: LINES * LEAD * PT }; // 114.3 × 164
const SIDE = (TRIM.width - AREA.width) / 2; // 12.85 mm
const TOP = MIN.top + (TRIM.height - MIN.top - MIN.bottom - AREA.height) / 2; // 21.5 mm
// #region answer: the first and the last headword of each page in its running head
// Each headword is a level-2 heading, '## {天|tiān}'. {firstMark.h2} prints the text of the
// first one that starts on the page, without its reading, and {lastMark.h2} the last; a
// page on which none starts repeats the one in force. They stand at the outer corner, the
// folio outside them, over a hairline as wide as the type area.
const HEAD_Y = 11; // mm from the top edge to the top of the guide words
const [GUIDE, FOLIO] = [10.5, 8]; // pt
const head = (id, content, parity, x, size, extra) => ({ kind: 'text', id, content, parity,
fontFamily: HEI, fontWeight: 700, fontSize: pt(size), lineHeight: 1, color: col('ink'),
// A design line puts its baseline 0.8 of its height down: the folio drops to share it.
placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
offset: { x: mm(parity === 'even' ? x : -x), y: mm(HEAD_Y + 0.8 * (GUIDE - size) * PT) } },
...extra });
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#偶数ページに最初の見出し字、奇数ページに最後の見出し字
1ページに柱の見出し語を1つだけ出す辞書もあります。偶数ページの上に最初の見出し字、奇数ページの上に最後の見出し字を置くので、見開きは天…髫と読めます。
- head('verso-guide', '{firstMark.h2}—{lastMark.h2}', 'even', SIDE + 8, GUIDE),
- head('recto-guide', '{firstMark.h2}—{lastMark.h2}', 'odd', SIDE + 8, GUIDE),
+ head('verso-guide', '{firstMark.h2}', 'even', SIDE + 8, GUIDE),
+ head('recto-guide', '{lastMark.h2}', 'odd', SIDE + 8, GUIDE),#ɑとɡのピンイン
中国語の辞書は、ピンインを1階建てのaとgの書体で組みます。読みにAndikaを指定し、FONTSに加えます('Andika': ['400']、OFLのクレジットも添えて)。
- ruby: { fontFamily: SONG, fontSize: em(0.5), color: col('cinnabar') },
+ ruby: { fontFamily: 'Andika', fontSize: em(0.5), color: col('cinnabar') },#本文と同じ大きさの見出し字
小型の辞書は、見出し字を段落の頭に太字で組みます。項目を:::paragraphs{style="entry"}に入れ、それぞれを**{天|tiān}**で始めて、{firstMark.entry}を印字します。太字の連なりで始まる段落は、その文字でページにマークを付けます。
よくあるつまずき
つまずき
ルビは本文に出て、デザイン、キャプション、セルには出ない
ルビは段落、見出し、リスト項目、引用、囲みで描かれます。デザインのテキスト要素(章扉、柱、バッジ)、キャプション、脚注、表のセルでは、ルビなしで親文字だけが印字されます。ピンインが必要なタイトルは、独自のデザインを持たない見出しにしてください。その周り(帯や課の番号)は直前の見出しのデザインで描きます。reserve: falseの要素は、span: 'page'の章扉の本文の下に描かれます。 ルビ:ピンインと注音 →
つまずき
中国語の書体はcjkブロックを通じてスライス単位で読み込む
Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →
つまずき
文書のタグはLANGではなくzh-Hansかzh-Hantにする
レシピの版はenとesですが、中国語のサンプルはどちらの版でも中国語です。`locale: LANG`では英語やスペイン語とタグ付けされ、ラテン文字の語がハイフネーションされ、図にFigureやFiguraの表示名が付き、PDFの言語も誤ります。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、英語やスペイン語のタグでは、中国語のフォントの数字と、ラテン文字のテキストと共通の約物が別の字形になり、改行の位置も変わります。タグは自分で書いてください。'zh-Hans'(中国本土の慣習:GBの改行規則、開明式の約物)または'zh-Hant'(台湾:全角で中央に置く約物)、香港なら'zh-HK'です。単なる'zh'は簡体字、本土として読まれます。日本語のサンプルには'ja'を使います(つまずき「ja-locale-tag」)。 中国語の改行 →
- 段末そろえをオンにすると、次の見出し字をその下の本文2行(
bodyText.widowMinLines)とともに入れられない段は早めに終わり、余った行は見出し字の上に、多くても1行ずつ配られます。そのため、前の項目から1行離れる項目と離れない項目ができます。オフなら、そのような段は短く終わります。
クレジット
- 本文
- Thirty entries of the Kangxi Dictionary (康熙字典, 1716), 天 to 庭, each cut to a few senses: what is kept stands in the source’s order and under its attribution, a sense with a reading of its own keeps it, and of the ancient forms (古文) only 銕 is set, the others being outside the fonts. Variant forms are written in today’s standard Traditional characters and the punctuation is revised in places. From the zh.wikisource transcription, which gives the Siku Quanshu Huiyao copy (四庫全書薈要本) as its source and notes some of Wang Yinzhi’s corrections of 1831 (字典考證); 29 pages by radical and stroke count, revisions read on 29 September 2026: 大部 2535754, 水部/八畫 2542298, 田部 2543683, 心部/六畫 2537571, 土部/十畫 2535684, 門部/十畫 2553837, 心部/四畫 2537569, 歹部/五畫 2541608, 肉部/八畫 2549900, 人部/六畫 416510, 手部/六畫 2538445, 辵部/五畫 2553283, 木部/七畫 2540094, 虫部/八畫 2551174, 言部/八畫 2551690, 髟部/五畫 2556393, 穴部/六畫 2546633, 目部/六畫 2544863, 足部/六畫 2552906, 米部/十九畫 2548884, 巾部/五畫 2536199, 貝部/五畫 2552278, 金部/十三畫 2553630, 食部/九畫 2556072, 水部/二畫 2541898, 耳部/十六畫 2549782, 广部/二十二畫 2536291, 亠部/七畫 409671, 广部/七畫 2536277 · Zhang Yushu, Chen Tingjing and others (1716); transcription by Wikisource editors · CC BY-SA 4.0
- The pinyin readings, the sense numbers, the order of the entries and the colophon · Postext Cookbook · CC BY 4.0
- フォント
- Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)


