跳到主要内容
食谱编号120

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

写在原稿用紙上的小说,一格一字

《坊っちゃん》的开头写在400字的原稿用紙上:画出20 × 20的方格,每个字或符号占一格,不能居行首的、。悬挂在格下。

本页内容
输出
Canvas · PDF
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.28.0 · postext-pdf ≥ 1.28.0
许可证
更新于2026年10月11日
代码MIT · 文本CC BY 4.0
  • 英文样例:尚无中文版本
  • 成品尺寸230 × 200 mm
  • 1栏
  • Klee One 20/27
  • Noto Sans JP
  • 3页
  • 难度
  • Postext 1.65.0
  • 排版用时52 ms
  • 131行代码

简单来说

日本的稿纸每个字都有一个方格。这一页把一部名作的开头几行抄在稿纸上,标题、作者名和每个标点都放在日本学校规定的位置。

成品一览

三张日文稿纸(原稿用紙,genkō yōshi),400格的那种,上面抄着夏目漱石《坊っちゃん》的头三段,就像作家或学生那样写:20行,每行20格,从右起自上而下读,用Klee One,一款以钢笔书写为基础的字体。标题在第一行,从第三格起;作者名在第二行,在底端上方一格结束;每段从一个空格之后开始。每个字、小写假名和符号都占一个自己的方格,本该落在行首的、或。写在上一行最后一格之下。红褐色的框、稿纸编号和纸上印的规格20×20构成这张纸。按字数计量的中文页面见Nº 082。

这道食谱解答

  • 怎样按字数设定版心,每行多少字、每页多少行?
  • 为什么日文的小假名、ー和闭括号不能出现在行首?怎样选择规则的严格程度?

简短回答

script.js · 第38–53行在完整代码中
// The grid makes the type area 20 characters of 20 pt down and 20 lines of 27 pt across, and
// show draws its squares. The marks are set full width with nothing squeezed, so each
// character, mark or bracket fills its own square, as on manuscript paper (原稿用紙).
const cjk = {
  // fullLines: on manuscript paper every square of a full line is written in, so a line
  // gives up no character to keep a lone last one company (the runt rule would leave the
  // twentieth square empty in the middle of a paragraph).
  grid: { enabled: true, charsPerLine: N, linesPerPage: N, show: true, fullLines: true },
  compressAdjacent: false, // 。」 take two squares, not one and a half
  trimLineStart: false, // a bracket at the head of a line keeps its square
  // The manuscript rule: a small kana or ー may head a line (each has its own square), but
  // never 、。 or a closing bracket: such a mark is written in the last square of the line
  // before, hanging below it here, and no line is squeezed to take it in.
  lineBreak: 'ja-loose',
  hangingPunctuation: 'force',
};

用料

类型
Klee One, Noto Sans JP(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 画出方格,每个符号占一整格

代码见上文的简短回答。字符网格把版心设为竖向20个20 pt(7.1 mm)的字、横向20行、行距27 pt(9.5 mm),show: true用它自己的浅灰色把方格画出来:屏幕上总会画,PDF里只有在renderToPdf收到characterGrid: true时才画(在书里网格是校样用的辅助线,所以PDF默认不画);两行之间2.5 mm的窄条,是写作者添读音、改字的地方。日文的标点一半是字形,一半是半个em的空白;印刷的书在两个标点相遇或括号位于行首时会吃掉这些空白。稿纸上每个符号保住自己的格子,所以compressAdjacent: false把。」排在两格里,trimLineStart: false让行首的括号占一整格(东亚排版)。

#2 · 遵守稿纸的行规

稿纸有自己的禁则。小写假名和ー可以放在行首,各占一格,ja-loose允许这样做。本该落在行首的、或。写在上一行的最后一格里,与那里的字挤在一起,或者写在它的正下方;hangingPunctuation: 'force'把它悬挂在第二十格之下,任何一行都不挤压。如果用日文的默认值'allow',引擎会先把行内的一个、挤到半格,把这个符号收进本行,印刷的书这样做,稿纸从不这样做:那一行其余的字会往上错半格,与网格线错开。

段落的末行还要再加一项设置。Postext不让段落以孤字结尾:上一行会让出最后一个字,而这里的正文不两端对齐,那一行就会空出一格。稿纸上整行的每一格都要写满,所以网格设了fullLines: true:第3张上末字为来的那一行保住二十格,段落以单独的た。收尾(字符网格)。

#3 · 把标题和姓名写在规定的位置

script.js · 第57–64行在完整代码中
// The title on the first line, two squares down; the writer's name on the second, ending a
// square above the foot (地から一字上げ), a blank square between family and given names.
// lineSpan: 1 keeps the title on one line of the grid, in the text's own size and face.
const title = { level: 1, fontFamily: PEN, fontSize: pt(CELL), fontWeight: 400, lineSpan: 1,
  indent: em(2), breakBefore: { enabled: true, parity: 'any' } }; // the next sheet, either side
const paragraphStyles = [
  { id: 'name', textAlign: 'end', endIndent: em(1), firstLineIndent: em(0) },
];

标题是一个与正文字号、字体相同的标题,所以它像其他行一样填格子:lineSpan: 1让它保持在网格的一行里,indent: em(2)在它上方留两个空格(按级别覆盖)。姓名是一个段落,设textAlign: 'end'和endIndent: em(1),让它在底端上方一格结束;姓与名之间的空格在Markdown里写作全角空格:夏目 漱石。正文从第三行开始,firstLineIndent: em(1)让每段空一格开始。

#4 · 在方格周围印出稿纸

script.js · 第68–92行在完整代码中
// The header is drawn on the sheet itself, not in the turned frame of the text: x runs right
// from the left edge, y down from the top. The frame stands 1.5 mm off the squares and 8 mm
// below them, where a 、 or 。 that cannot head a line is written outside the last square.
const box = (id, inset, foot, thickness) => ({ kind: 'box', id, pages: 'all',
  placement: { anchor: { to: 'page', edge: 'top-left' },
    offset: { x: mm(MARGIN.side - inset), y: mm(MARGIN.top - inset) },
    size: { width: mm(GRID.across + 2 * inset), height: mm(GRID.down + inset + foot) } },
  style: { borderColor: col('ruling'), borderWidth: pt(thickness) } });
const FOOT = MARGIN.top + GRID.down + 8; // mm: the frame's foot
const below = (id, content, x, extra) => ({ kind: 'text', id, content, pages: 'all',
  placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(x), y: mm(FOOT + 3) } },
  ...extra });
const header = { elements: [
  box('outer', 2.6, 9.1, 1.2), box('inner', 1.5, 8, 0.4),
  // The sheet number, as a writer numbers the sheets; the paper's printed label.
  below('sheet', '({pageNumber})', MARGIN.side, { fontFamily: PEN, fontSize: pt(9),
    color: col('muted') }),
  below('label', '20×20', MARGIN.side + GRID.across - 12, { fontFamily: 'Noto Sans JP',
    fontSize: pt(7), letterSpacing: pt(0.5), color: col('ruling') }),
] };
const footer = { elements: [{ kind: 'text', id: 'colophon', content: '{attr.colophon}',
  pages: 'opener', fontFamily: 'Noto Sans JP', fontSize: pt(6), lineHeight: 1.4,
  color: col('muted'), overflow: 'wrap', align: 'center',
  placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-5) },
    size: { width: mm(120) } } }] };

页眉的元素画在纸面上:在竖排页面上,x从左上角向右、y向下,这与标题的设计不同,后者在文字的旋转坐标系中排。双线框在三边离方格1.5 mm,在下方离方格8 mm,悬挂的符号就落在那里。GRID和MARGIN用页边距所依据的同一组数字来放置它;交给页面的页边距要小半毫米,因为网格把它们当作最小值,正好相等时可能取整成19行。

#5 · 用钢笔字体来排

script.js · 第144–149行在完整代码中
// Klee One draws the strokes of a pen, with the Japanese forms of the kanji; its vertical
// forms put 、。 in the upper right of their square and turn ー and the brackets.
const colophon = markdown.match(/colophon="([^"]*)"/)[1];
await loadFonts(FONTS, markdown); // the Latin files: the colophon
await loadCjkFonts({ [PEN]: ['400'] }, `${markdown}()一二三四五六七八九十`, { vertical: true });
await loadCjkFonts({ 'Noto Sans JP': ['400'] }, `20×20${colophon}`);

Klee One以钢笔书写为基础,汉字保留日本的字形,所以稿纸读起来像手写的,又没有扫描件的那种参差。它的竖排字形把、。放在格子的右上方,并把ー和括号转过来,写作者也正是把它们写在那里。和Fontsource上的所有日文字体一样,它拆成大约120个文件,loadCjkFonts只取文本用到的那些(中文、日文和韩文字体)。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 120 · A story on genkō yōshi, one character to a square ═══
// https://postext.dev/en/cookbook/genko-yoshi-manuscript
// Code: MIT · Text: 夏目漱石『坊っちゃん』, Aozora Bunko 752 (public domain) · Pictures: none
// Fonts: Klee One, 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 manuscript is Japanese in both
const RECIPE = 'genko-yoshi-manuscript';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: blue-black ink on a sheet ruled in red-brown
const palette = {
  ink: '#1f2a44', // the pen: a blue-black
  ruling: '#b0573f', // the sheet's printed frame, its label
  muted: '#7b6f66', // the sheet number
  paper: '#fdfaf3',
};
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.ruling, model: 'hex' } },
];
// #endregion
const PEN = 'Klee One'; // a pen-written kaisho with Japanese forms
const [CELL, PITCH, N] = [20, 27, 20]; // pt: a 7 mm square, a 2.5 mm strip beside each line
const PT = 25.4 / 72; // mm in a point
const SHEET = { w: 230, h: 200 }; // mm
const GRID = { down: N * CELL * PT, across: N * PITCH * PT }; // 141.1 × 190.5 mm
const MARGIN = { top: 32, side: (SHEET.w - GRID.across) / 2 }; // mm
// The margins handed to the page are a hair smaller: the grid takes them as minimums and
// grows them back, where an exact fit could round to 19 lines.
const SLACK = 0.5; // mm

// #region answer: 20 squares down 20 lines, the squares drawn, every character in one
// The grid makes the type area 20 characters of 20 pt down and 20 lines of 27 pt across, and
// show draws its squares. The marks are set full width with nothing squeezed, so each
// character, mark or bracket fills its own square, as on manuscript paper (原稿用紙).
const cjk = {
  // fullLines: on manuscript paper every square of a full line is written in, so a line
  // gives up no character to keep a lone last one company (the runt rule would leave the
  // twentieth square empty in the middle of a paragraph).
  grid: { enabled: true, charsPerLine: N, linesPerPage: N, show: true, fullLines: true },
  compressAdjacent: false, // 。」 take two squares, not one and a half
  trimLineStart: false, // a bracket at the head of a line keeps its square
  // The manuscript rule: a small kana or ー may head a line (each has its own square), but

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#用同样的方格检查一本书的网格

show: true适用于任何字符网格:在Nº 117的文库本上,它在正文上画出38 × 15的方格,可以很快查看每一行是否守在网格上,每个标题是否占满三行。

-  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
+  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES, show: true },

#像印刷页那样挤压符号

用日文的默认值,稿纸读起来就像在方格纸上打字排出的一本书:本该落在行首的、靠挤压另一个、收进行内,那一行其余的字偏离网格半格。

-  hangingPunctuation: 'force',
+  hangingPunctuation: 'allow',

常见问题

易错点

日文文本标记为'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:两者都会取用包含文中字符的那些文件。 中日韩字体 →

易错点

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

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

致谢

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