简单来说
一章讲解日本排版用语的短文,书末附索引。每个收录的词都带着读音,Postext据此按日文假名的顺序给索引排序,分在あ行、か行等行标题之下。
成品一览
一本虚构的日文排版手册《組版の言葉》(排版的用语)中的一章及其索引。这一章讲版面各部分、字号和标点规则的名称,排在A5页面上,每行36字,每页28行;每个术语在讲解它的地方加索引标记。索引是这里的主题:日文汉字没有字母顺序,所以索引按每个条目的假名读音,照五十音(gojūon)表的顺序排列,归入あ行、か行、さ行等行标题之下。带振假名的术语自己就给出了读音;其他含汉字的术语在yomi属性里写出读音。中文人名索引则按拼音和笔画给中文人名排序。
这道食谱解答
- 怎样按读音以五十音顺序排日文索引?
简短回答
// Each mark gives the reading the entry sorts by. A term written with furigana gives it
// itself: :index[{版面|はん|めん}] files 版面 as はんめん. Any other term with a kanji says it
// with yomi: :index[明朝体]{yomi="みんちょうたい"}. Kana and Latin terms need nothing. The
// reading orders the entries in JIS X 4061 order (katakana as hiragana, small kana as large,
// voiced after plain, ー as the vowel before it); Latin terms come first, under A to Z.
const index = {
groupBy: 'gojuon', // what 'auto' picks in a 'ja' document: heads あ行 か行 さ行 …
fontFamily: MINCHO, fontSize: pt(8.5), lineHeight: pt(14),
separator: ' ', locatorSeparator: '、', // 版面 3、5: an ideographic space, then 、
see: { italic: false }, // → ルビ, → 柱も見よ: upright, no italic in Japanese
groups: { fontFamily: GOTHIC, fontSize: pt(9), fontWeight: 700, color: col('vermilion'),
marginTop: pt(7) },
};
用料
做法
#1 · 每个含汉字的术语都要有读音
代码就是上面的简短回答。在正文里,:index[{版面|はん|めん}]{main}印出带有はんめん注音的版面,并按はんめん归档;:index[明朝体]{yomi="みんちょうたい" main}不印读音,按みんちょうたい归档。假名术语如ノンブル、のど,以及拉丁字母术语如DTP、JIS X 4051,都不需要读音(索引标记)。读音只决定排列顺序,条目照原文印出。汉字的读音没法推断,天在这里读てん,在别的词里读あめ,所以引擎从不去猜。
#2 · JIS顺序和行标题
locale: 'ja'时,'auto'选的就是groupBy: 'gojuon'。条目按JIS X 4061排序:片假名按平假名排,小写假名按大写排,浊音紧跟在清音之后,ー按它前面的元音排。所以級(きゅう)排在行取り(ぎょうどり)之前,ゴシック体(ごしっくたい)排在小口(こぐち)之后。拉丁字母术语按JIS的规定排在最前面,归入各自的字母之下;符号和数字还会排在它们之前(索引)。

#3 · →和も見よ
“见”条是带see的标记,:index{term="振り仮名" yomi="ふりがな" see="ルビ"},印出振り仮名 →ルビ。“参见”用seealso,把目标词放在も見よ之前,印作級 10 →歯も見よ,这是日文索引的写法。see: { italic: false }让这些标签保持正体,因为日文字体没有斜体。每个术语后面的全角空格和页码之间的、来自separator和locatorSeparator。
#4 · 双栏的索引
const band = { kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(56) } } };
const opener = (sink, ground = []) => ({ enabled: true, minHeight: pt(PITCH * sink),
slot: { elements: [...ground,
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: GOTHIC, fontSize: pt(9),
fontWeight: 700, letterSpacing: pt(2), color: col('vermilion'), align: 'left',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(10) } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: GOTHIC, fontSize: pt(22),
fontWeight: 700, color: col('ink'), align: 'left', overflow: 'wrap',
placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(3) } } },
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1.5),
color: col('vermilion'), placement: { anchor: { to: '#title', edge: 'below' },
offset: { y: mm(4) }, size: { width: mm(12) } } },
] } });
索引标题用的标题样式设了span: 'page'和双栏的layout:它的设计,一条带标题的浅色色带,横跨整页,:::index在下方分两栏排。行标题用朱红色黑体,条目用正文的明朝体,8.5 pt,行距14 pt。
完整食谱
// ═══ Postext Cookbook · Nº 126 · A Japanese index in gojūon order, read from its readings ═══
// https://postext.dev/en/cookbook/gojuon-index
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Noto Serif JP, Noto Sans JP (SIL OFL 1.1) · Needs postext ≥ 1.28.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 chapter is Japanese in both
const RECIPE = 'gojuon-index';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, one vermilion for the row heads and the chapter label, pale rules
const palette = {
ink: '#211e1c', // text: a warm near-black
vermilion: '#b33a22', // the one accent: あ行 heads, the kicker, folios
tint: '#f5ece6', // the index heading's band
rule: '#d3c8c0', // the rule under each title
muted: '#6c625b', // running heads, the colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.vermilion })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [MINCHO, GOTHIC] = ['Noto Serif JP', 'Noto Sans JP'];
const [BODY, PITCH] = [9, 16]; // pt: 9 pt text on a 16 pt line
const [CHARS, LINES] = [36, 28]; // the type area in characters
// #region answer: the index in gojūon order: by reading, under あ行 か行 さ行…
// Each mark gives the reading the entry sorts by. A term written with furigana gives it
// itself: :index[{版面|はん|めん}] files 版面 as はんめん. Any other term with a kanji says it
// with yomi: :index[明朝体]{yomi="みんちょうたい"}. Kana and Latin terms need nothing. The
// reading orders the entries in JIS X 4061 order (katakana as hiragana, small kana as large,
// voiced after plain, ー as the vowel before it); Latin terms come first, under A to Z.
const index = {
groupBy: 'gojuon', // what 'auto' picks in a 'ja' document: heads あ行 か行 さ行 …
fontFamily: MINCHO, fontSize: pt(8.5), lineHeight: pt(14),
separator: ' ', locatorSeparator: '、', // 版面 3、5: an ideographic space, then 、
see: { italic: false }, // → ルビ, → 柱も見よ: upright, no italic in Japanese
groups: { fontFamily: GOTHIC, fontSize: pt(9), fontWeight: 700, color: col('vermilion'),
marginTop: pt(7) },
};
// #endregion
// #region opener: the chapter label, the title and a short rule; the index's on a band
const band = { kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(56) } } };
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#按首个假名分组
'kana'用条目的第一个假名作组标题,词典和较长的人名索引都这样做:分成か、き、く几组,而不是一个か行。
- groupBy: 'gojuon', // what 'auto' picks in a 'ja' document: heads あ行 か行 さ行 …
+ groupBy: 'kana', // heads か き く け こ…#正文不标振假名也能给出读音
想让术语第一次出现时不带注音,又要给出读音,就把读音移到yomi里。
-ページのうち、本文が組まれる範囲を:index[{版面|はん|めん}]{main}という。
+ページのうち、本文が組まれる範囲を:index[版面]{yomi="はんめん" main}という。常见问题
易错点
日文文本标记为'ja',不要用zh-Hans或LANG
食谱的版本是en和es,但日文示例在两个版本里都是日文:`locale: LANG`会把它标记为英文或西班牙文,中文标记则会按中文规则排它(开明式标点、小假名可以出现在行首、图代替図、PDF中用中文字形)。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以'ja'以外的标记给出的不是日文字形(中文标记给出中文字形),断行的位置也不同。写'ja':它选用日本地区(JLReq断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为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把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →
易错点
中文没有斜体
CJK字体家族不带斜体,中文排版用字旁的着重号标示强调,而不是倾斜。在标记为中文的文档中,*…*给其中的汉字加着重号,拉丁文词仍用斜体(cjk.emphasis: 'dots',中文的默认值);:dots[…]可以在任何地方加着重号。设置cjk.emphasis: 'italic'时,或在标记为en或es的文档中,*…*会让Canvas把正体字形倾斜,这种合成的伪斜体是中文排版从来不用的(PDF会退回正体字型):保留中文标记,或者通过段落样式或标签样式,用粗体或楷体(LXGW WenKai)表示强调。 中日韩字体 →
版面警告 · indexReadingMissing
索引词条缺少读音
原因. 日文索引按读音排列词条,而汉字的读音无法可靠地自动推出:这个词条含有汉字,它的标记都没有给出读音(yomi、标记文字上的假名注音,或用假名写的sort键),因此它按码位排在假名词条之后。
解决. 在词条的某个标记上加yomi="…",用假名写出读音(:index[東京]{yomi="とうきょう"}),或标记带注音的文字({東京|とう|きょう})。 文档 →
- 含汉字而没有读音的术语会引发
indexReadingMissing。去掉yomi后,明朝体落到了索引末尾,排在わ行之后,没有组标题,构建时还警告这个条目“有汉字而没有读音”。 - 写在
:index[…]里的:ruby[…]必须给方括号加转义,因为标记在第一个]处结束;请用简写形式{版面|はん|めん}。 - 注音读音只有覆盖术语中的每个汉字时才算数:
:index[行{取|ど}り]没给行注音,会报警告。{行取|ぎょう|ど}り给出ぎょうどり。
致谢
- 文本
- 原创文字, CC BY 4.0
- 字体
- Noto Serif JP (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)


