跳到主要内容
食谱编号117

排版食谱 · 第1章 · 页面与网格

竖排并标振假名的日文文库本小说

漱石《夢十夜》排在A6文库本页面上:每行38字、共15行,从右向左读,生僻汉字旁标读音,每夜的标题占三行。

本页内容
输出
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行代码

简单来说

一本日本经典小说的开头,排成口袋大小的平装书:文字从上往下排成一列一列,从右往左读,较难的汉字旁边印着小号假名。

成品一览

一本日文口袋平装书(文庫,bunko)的九页:夏目漱石《夢十夜》的第一夜和第二夜,排在105 × 148 mm、右侧装订的A6页面上。书名页独自位于书脊左侧;从第2页起,正文从上到下排成各行,从右向左读,每行38字、共15行,用9 pt的Shippori Mincho B1,行距1.75 em。青空文库为难字标出的读音以半号假名排在字旁,每一夜的标题占网格的三行,左页沿切口竖排书名,下面是汉字数字页码。结构相同的欧洲口袋书见Nº 104,中文竖排小说见Nº 075。

这道食谱解答

  • 怎样像文库本那样,把日文小说竖排并在右侧装订?
  • 怎样在汉字上加振假名,是一字一音还是整个词一个读音?
  • 怎样把青空文库的文本做成Postext的书?
  • 怎样让日文标题占三个正文行(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'把每一页当作顺时针转了四分之一圈的横排页面来排;page.binding保持'auto',竖排书就在右侧装订:第1页仍是奇数页,但它位于书脊左侧,mirror: true把它的内页边距放到右边(竖排、装订)。字符网格把版心设为竖向38个9 pt的字(120.7 mm)、横向15行、行距15.75 pt(83.3 mm);page里的页边距是最小值,网格把每一对页边距放大同样的量,所以天头始终比地脚深4 mm。要的行数超出页边距所能容纳时,网格会不声不响地少排一行(doc.configWarnings里的cjkGridClamped):正是9 mm的订口和12 mm的切口让15行排得下。

locale: 'ja'按日文书籍的做法设定其余各项,所以这里写出的四行cjk设置不改变任何结果,只是展示这个语言标记选了什么。ja-very-strict是JIS X 4051的行首禁则(行頭禁則):行首不出现、。」、ー或っ这样的小写假名。hangingPunctuation: 'allow'让本该落在行首的、或。悬挂在最后一个字之下(ぶら下げ),文库本这样做,而不去挤压这一行。paragraphStartBracket: 'half'是JLReq的方式③:以「开头的段落把括号放在一字缩进的后半格,于是对白的第一个字与其他段落的第一个字对齐(东亚排版)。中文书在这两点上都不同:默认不悬挂标点,段首缩进两字,有没有括号都一样。

#2 · 每一夜的标题占网格的三行

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

日文标题占整数个正文行,称为行取り(gyōdori),这样标题后面的行与前面的行在同一套网格上。lineSpan: 3把第一夜排在三个15.75 pt行宽的带里,字居于其中;标题的12.5 pt不移动网格,第6页上第二夜占页面开头的三行,它后面的正文从网格的第四行排起。indent: em(5)以正文字计(五字下げ),青空文库的文本就是这样标中見出し的,JLReq也这样计算标题的缩进(按级别覆盖)。

#3 · 从青空文库取来正文和读音

这两夜取自青空文库的第799号作品卡,用postext-port技能里的aozora.py转换。转换脚本以CP932读取文件,把写成仰向《あおむき》的读音变成整组读音{仰向|あおむき},即一串假名覆盖整个词,并把[#5字下げ]…[#「第一夜」は中見出し]变成标题。在ja文档中,读音遵循JIS X 4051:比基字短的读音按1:2:1沿基字分布,比基字长的读音可以伸到相邻的假名旁,但不会伸到汉字旁(着重号、注音与夹注)。1.75 em的行距在行与行之间留出6.75 pt,容得下4.5 pt的读音。

#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: [] };

竖排文库本的书眉(柱,hashira)字小,放在外页边距里。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) },
  ] } },
};

书名页是一个一级标题,有自己的样式# 夢十夜 {style="title" …},它的设计占满整页。设计中的元素锚定在页面本身而不是版心上,因为镜像页面的版心偏离中心1.5 mm: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,它把同样的文件以子集形式嵌入。

完整食谱

沙盒
// ═══ 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文档中,*…*在字行旁印出同样的芝麻点,不会变成斜体。

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

#把括号整个放在一字缩进之后

方式①保留一字缩进,把括号排在缩进之后,很多面向少年读者的小说这样做。

-  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断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为zh或ko的文本失败。 日文禁则处理 →

易错点

中文字体通过cjk块分片加载

Fontsource把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →

易错点

右装订的书用showBook显示跨页

在右装订的书中(阿拉伯文、希伯来文或波斯文,竖排中文,或page.binding 'right'),第1页仍是奇数页(recto),但它位于书脊左侧,跨页读作[3 | 2]。showPages把所有书都按左装订排列;book块中的showBook(cjk块中也有同一个函数)读取doc.binding,把跨页左右镜像。capture.hero仍按阅读顺序[偶数页, 奇数页]指定跨页:[2, 3]。 右翻书 →

易错点

按CP932而不是Shift_JIS读取青空文库文件

青空文库的文本文件是Windows-31J(CP932)编码。如果按普通Shift_JIS解码,――会变成U+2014的破折号,~会变成波浪号〜,一些NEC和IBM扩展字符会出错。要按cp932读取,再转换标记:《》中的注音、[#…]注记和※[#…]外字都不是Markdown,留着就会原样印出来。技能中的aozora.py两件事都做。 导入青空文库文本 →

易错点

Fontsource的字符范围可能包含文件里没有的字

Fontsource给每个文件标出unicode-range,loadCjkFonts按示例文字加载范围覆盖它们的文件,但范围可能比文件实际收录的字多。Zen Old Mincho负责U+3028–303F的切片没有〻,也没有长重复符号〳〴〵,这款字体也没有带长音符号的ō、ū、ā;Shippori Mincho B1的latin-ext文件只有寥寥几个字符,ō、ū、ā都不在其中。pen运行时不会报错:屏幕上这些字符来自系统字体并按它测量,PDF印出该字体的.notdef方框,只有事后的C25检查才会报告。选定字体之前,先在字体里查一查生僻符号或罗马字词(用fontTools检查Fontsource的文件),再用收有这些字的字体来排:Shippori Mincho B1和Noto Serif JP有〻和〳〴〵,Noto Serif JP和Noto Sans JP有带长音符号的元音。 中日韩字体 →

易错点

竖排页面有两套坐标:转过来的正文和纸面

vertical-rl文档把正文当作一张顺时针转了九十度的横排页面来排,标题的设计(advancedDesign.slot中的元素)也放在这个转过的坐标系里:x沿页面向下,y从右边缘向左横跨页面,元素的宽度沿页面向下量。页眉和页脚的元素仍在纸面上:x从左边缘向右,y从顶端向下。所以页眉里画的框和标题设计里放的书名,偏移量是在不同的轴上量的。竖排扉页上的元素要锚定到`page`,从页面边缘量起:锚定到`container`时,页脚的元素会偏离版心中线几毫米(约5 mm)。 竖排 →

致谢

文本
  • 夏目漱石『坊っちゃん』 (Botchan, 1906), the opening of chapter one; Aozora Bunko card 752, from 「ちくま日本文学全集 夏目漱石」 (Chikuma Shobō, 1992), input 真先芳秋, proofreading 柳沢成雄, converted with aozora.py · Natsume Sōseki; Aozora Bunko volunteers · 公有领域
字体
Shippori Mincho B1 (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
沙盒PDF