かんたんな説明
続く二行が同じ語で終わったり始まったりすると、目が違う行へ飛びやすくなります。この本は二度組みます。一度目はそれが起きる場所を示し、二度目は起きないように行を分けます。
できあがり
115 × 180 mm の文庫判ページの校正刷りを二つ組みます。中身は『クリスマス・キャロル』(A Christmas Carol)の冒頭で、Spectral を 83 mm の行長で両端揃えにしています。行長が狭いと改行の選択肢が少なく、五か所で続く二行が同じ語で終わるか始まります。sole の下に sole、his の下に his、No の下に No。初校は stacks: 'warn' で組みます。改行は一つも変えず、重複を一つずつ報告し、二つの語に淡い赤の帯をつけ、奥付のあとの校正票に並べます。再校は 'avoid' で組み、五つのうち四つが消えます。スペイン語版は Clarín の ¡Adiós, Cordera! の冒頭を同じ方法で組みます。
このレシピが答える質問
- 連続する2行が同じ語で終わったり始まったりしないようにするには?
手短な答え
const bodyText = {
fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: mm(4), indentAfterHeading: false,
hyphenation: { enabled: true }, optimalLineBreaking: true, // stacks need the K–P breaker
avoidWidows: true, avoidOrphans: true, avoidRunts: true,
// A stack: two lines in a row that end on the same word or the same last characters
// (“sole” over “sole”), or that start alike (“The” over “the”). 'warn' reports each one
// and changes nothing; 'avoid' adds stackPenalty to the demerits of every break that
// makes one, so the breaker sets the paragraph another way where the spacing allows.
stacks: 'avoid', // the first proof sets 'warn' (see proofs)
// Three characters by default; the Spanish rule counts a repeated syllable (co-/co-).
stackMinCharacters: t({ en: 3, es: 2 }),
// Default 3000, the cost of two hyphens in a row; a monosyllable (“his”, “lo”) costs twice.
// 3000 kept two stacks of the first proof per edition: 10000 trades them for looser lines.
stackPenalty: 10000,
maxWordSpacing: 2, // the default: past it a line is never set, stack or not
};
材料
- 機能
- 行頭・行末の重複最適な改行(Knuth–Plass)ハイフネーションと文書の言語ウィドウ、オーファン、ラント本文の書体デザインした章扉ページデザインの画像見出しの属性柱とノンブルページの役割ごとの柱見開きの余白囲み段落スタイルセマンティックカラーパレット
- 併用する機能
- ハイライトリソースとしての図と表
- 種類
- Spectral, Spectral SC, Cormorant Garamond (SIL OFL 1.1)
- 素材
carol-1100.jpgcordera-1100.jpg- Painting: Scrooge's counting-house on a foggy Christmas Eve (Generated With Diffusion Models, オリジナル)
- Painting: Rosa, Pinín and the Cordera by the telegraph pole (Generated With Diffusion Models, オリジナル)
作り方
#1 · まず報告し、次にコストに入れる
const bodyText = {
fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: mm(4), indentAfterHeading: false,
hyphenation: { enabled: true }, optimalLineBreaking: true, // stacks need the K–P breaker
avoidWidows: true, avoidOrphans: true, avoidRunts: true,
// A stack: two lines in a row that end on the same word or the same last characters
// (“sole” over “sole”), or that start alike (“The” over “the”). 'warn' reports each one
// and changes nothing; 'avoid' adds stackPenalty to the demerits of every break that
// makes one, so the breaker sets the paragraph another way where the spacing allows.
stacks: 'avoid', // the first proof sets 'warn' (see proofs)
// Three characters by default; the Spanish rule counts a repeated syllable (co-/co-).
stackMinCharacters: t({ en: 3, es: 2 }),
// Default 3000, the cost of two hyphens in a row; a monosyllable (“his”, “lo”) costs twice.
// 3000 kept two stacks of the first proof per edition: 10000 trades them for looser lines.
stackPenalty: 10000,
maxWordSpacing: 2, // the default: past it a line is never set, stack or not
};
続く二行が同じ語や同じ末尾の文字で終わるとき、または同じように始まるとき、それを重複と呼びます。何文字そろえば重複とみなすかは stackMinCharacters で決めます。既定値は三文字で、スペースも数え、アクセントと大文字小文字は区別しません。The の下の the も重複です。'warn' は報告するだけなので、組版者はまず文章のどこで重複が起きるかを確かめられます。'avoid' は重複を生む改行位置ごとに stackPenalty をコストに加え、Knuth–Plass の改行処理は段落の別の分け方を探します。optimalLineBreaking が必要です。一行ずつ決める改行処理には、加えるべきコストがありません。
スペイン語の組版の手引きは、この重複を組版上の欠陥として、リバーやハイフンの連続と並べて扱います。左端に戻った目が違う行の同じ語に引っかかり、同じ行を二度読んだり一行飛ばしたりします。右端では重複がこだまのように響きます。スペイン語の規則は語だけでなく音節の重複も対象にするので、スペイン語版では stackMinCharacters を 2 にしています。
既定のペナルティ 3000 は、二行続けてハイフンで終わるときのコストと同じで、一音節の語の重複はその二倍になります。この行長では 3000 だと各版に二つずつ重複が残りました。避けると、改行処理が受け入れるより緩い行ができるからです。10000 にすると、その緩い行を受け入れます。maxWordSpacing は既定値の 2 のままにします。もっと厳しくすると改行処理にほかの選択肢がなくなり、'avoid' は何も変えませんでした。
#2 · 本文の重複に印をつける
// A warning names its first line by its place in the source. The repeated edge of that
// line and the next is found in each line's stretch of the source and the whole word
// around it wrapped in :mark[…]: a band under ordinary text, so the breaks stay the same.
const LETTER = /[\p{L}\p{N}’-]/u;
const edgeOf = (text, n, end) => { // the words at a line's edge holding its first/last n
const s = text.replace(end ? /[^\p{L}\p{N}]+$/u : /^[^\p{L}\p{N}]+/u, '');
const cut = end ? s.lastIndexOf(' ', s.length - n) + 1 : s.indexOf(' ', n);
return end ? s.slice(cut) : s.slice(0, cut < 0 ? undefined : cut);
};
function markStacks(source, doc, stacks) {
const lines = doc.blocks.flatMap((b) => b.lines.map((line, i) => [line, b.lines[i + 1]]));
const spans = new Map(); // start → end of each marked word in the source
for (const w of stacks) {
const pair = lines.find(([line]) => line.sourceStart === w.sourceStart);
for (const line of pair?.[1] ? pair : []) {
const piece = edgeOf(line.text.trim(), w.text.length, w.edge === 'end');
const range = source.slice(line.sourceStart, line.sourceEnd);
let from = line.sourceStart
+ (w.edge === 'end' ? range.lastIndexOf(piece) : range.indexOf(piece));
if (from < line.sourceStart) continue;
let to = from + piece.length; // a piece of a hyphenated word takes the whole word
while (from > 0 && LETTER.test(source[from - 1])) from--;
while (to < source.length && LETTER.test(source[to])) to++;
if (!/[*_[\]\n]/.test(source.slice(from, to))) spans.set(from, to);
}
}
return [...spans].sort(([x], [y]) => y - x).reduce((md, [from, to]) => `${md.slice(0, from)}`
+ `:mark[${md.slice(from, to)}]{style="stack"}${md.slice(to)}`, source);
}
警告はそれぞれ、一行目が原稿のどこにあるかを示します。スクリプトは組み上がった文書でその行と次の行を探し、それぞれの重複している端を取り出して、語全体を :mark[…] で囲みます。マークは普通の文字の下に帯を塗るだけで、改行は変えません。印をつけるのは語全体だけです。語の一部だけを囲むとその語のハイフネーションが変わり、警告が見つかった位置で行が分かれなくなります。

#3 · 同じ文章から二つの校正刷り
const quote = (s) => t({ en: `“${s}”`, es: `«${s}»` });
const SIDE = { end: t({ en: 'end', es: 'final' }), start: t({ en: 'start', es: 'principio' }) };
const tally = (n) => t({ en: `${n} stack${n === 1 ? '' : 's'}`,
es: `${n} repetici${n === 1 ? 'ón' : 'ones'}` });
const byPage = (stacks) => Object.entries(Object.groupBy(stacks, (w) => w.pageIndex + 1))
.map(([page, list]) => `${t({ en: 'p.', es: 'pág.' })} ${page}: ${list.map((w) =>
`${quote(w.text)} (${SIDE[w.edge]})`).join(', ')}.`);
const slip = (mode, stacks) => ['', `:::callout{type="proof" title="${mode === 'warn'
? t({ en: 'First proof', es: 'Primeras pruebas' })
: t({ en: 'Second proof', es: 'Segundas pruebas' })}"}`,
`${t({ en: 'Set with', es: 'Compuesto con' })} stacks: '${mode}' · ${tally(stacks.length)}.`,
...byPage(stacks).flatMap((line) => ['', line]), ':::', ''].join('\n');
const build = (md, stacks) => buildDocumentWithFonts({ markdown: md, resources },
{ ...config, bodyText: { ...bodyText, stacks } }, kitFonts(FONTS));
async function proof(mode) {
const plain = await build(markdown, mode); // pass 1: where the stacks are
const stacks = (plain.contentWarnings ?? []).filter((w) => w.kind === 'stack');
return build(markStacks(markdown, plain, stacks) + slip(mode, stacks), mode); // pass 2
}
const docs = { warn: await proof('warn'), avoid: await proof('avoid') };
校正刷りはそれぞれ二回組みます。一回目で重複を見つけ、二回目で同じ文章に印と校正票を加えて組みます。校正票は奥付のあとに置くので、最終ページに来ます。各校正刷りの一回目、印のない文章は公開するページに入れません。capture.doc には印のある二回分 [1, 3] だけを並べます。

英語版に残る重複は even の下の event です。二つの語は最初の三文字が同じで、この段落のほかの分け方はどれもコストが高くなりました。スペイン語版は二文字で数えるので、初校で五つ見つかります。con の下の como の co、levantar の下の vacilar の ar などです。再校では一つもありません。
#4 · 本文の上の章扉
const PICTURE = { width: MEASURE, height: 11 * LINE }; // 83 × 52 mm, the painting's 3:2
const at = (to, edge, y, size) => ({ anchor: { to, edge }, offset: { x: mm(0), y: mm(y) },
...(size && { size }) });
const opener = {
enabled: true, minHeight: pt(16 * LEAD), // the text starts on the seventeenth line
slot: { elements: [
{ kind: 'image', id: 'art', resourceId: '{attr.art}', fit: 'cover', placement: at('container',
'top', 0, { width: mm(PICTURE.width), height: mm(PICTURE.height) }) },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: LABEL, fontWeight: 600,
fontSize: pt(8.5), letterSpacing: pt(1.7), color: col('accent'), align: 'left',
placement: at('container', 'top-left', PICTURE.height + 5.5) },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, italic: true,
fontWeight: 500, fontSize: pt(27), lineHeight: 1.05, color: col('ink'), align: 'left',
placement: at('#kicker', 'below', 1.5, { width: mm(MEASURE), height: 'auto' }) },
] },
};
見出しの art 属性が絵を指定するので、一つのスタイルで両方の版をまかなえます。minHeight で十六行分を確保し、本文は十七行目から始まります。続くページと同じ行送りの格子に乗ります。
#5 · 柱と下のノンブル
const head = (id, content, parity, edge, x, extra = {}, y = 10.5) => ({ kind: 'text', id,
content, parity, pages: 'body', fontFamily: LABEL, fontWeight: 500, fontSize: pt(8),
letterSpacing: pt(1.2), color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(y) } }, ...extra });
const folio = { fontFamily: TEXT, letterSpacing: pt(0), color: col('ink') };
const header = { elements: [
head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folio),
head('verso-author', '{author}', 'even', 'top-left', OUTER + 8),
head('recto-title', '{title}', 'odd', 'top-right', -(OUTER + 8)),
head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folio),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'odd', 'bottom-right', -OUTER,
{ ...folio, pages: 'opener' }, -11)] }; // the opener's folio sits at the foot
偶数ページに著者名、奇数ページに書名を、それぞれノンブルの横に置きます。章扉では柱を消し、ノンブルを下に移します。
レシピの全体
// ═══ Postext Cookbook · Nº 184 · Prose without stacks ═════════════════════════════
// https://postext.dev/en/cookbook/prose-without-stacks
// Code: MIT · Text: Dickens, 1843; Clarín, 1893 (public domain) · Paintings: diffusion model
// Fonts: Spectral, Spectral SC, Cormorant Garamond (SIL OFL 1.1) · Needs postext ≥ 1.73.0
//
// A pocket edition set twice from the same text. The first proof keeps the line breaks the
// breaker finds and reports every stack (two lines in a row that end or start alike); the
// second weighs each stack in the breaker's demerits and sets the paragraph another way.
// Each proof marks its stacks in the text and lists them on a slip after the colophon.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'prose-without-stacks';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a proofreader's red pencil over a warm book ink
const palette = {
ink: '#241f1b', // text: a warm near-black
accent: '#8e2f1d', // kicker, the slip's stripe and label: the red of a proof pencil
mark: '#f4cfc2', // the band under a stacked word, pale enough for ink on top
tint: '#f5efe6', // the slip's background
rule: '#d2c8bb', // hairlines
muted: '#6b6158', // running heads, colophon
paper: '#ffffff',
};
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: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// #endregion
const [TEXT, LABEL, DISPLAY] = ['Spectral', 'Spectral SC', 'Cormorant Garamond'];
const [BODY, LEAD] = [9.6, 13.4]; // pt
const LINE = (LEAD * 25.4) / 72; // mm: one line, 4.73
const [TRIM_W, TRIM_H, TOP, INNER, OUTER, LINES] = [115, 180, 17, 15, 17, 30];
const MEASURE = TRIM_W - INNER - OUTER; // 83 mm: about 50 characters, a narrow pocket measure
// #region answer: stacks reported in the first proof and weighed in the second
const bodyText = {
fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: mm(4), indentAfterHeading: false,
hyphenation: { enabled: true }, optimalLineBreaking: true, // stacks need the K–P breaker
avoidWidows: true, avoidOrphans: true, avoidRunts: true,
// A stack: two lines in a row that end on the same word or the same last characters
// (“sole” over “sole”), or that start alike (“The” over “the”). 'warn' reports each one
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
よくあるつまずき
レイアウト警告 · stack
行頭・行末の重複
原因. 段落の同じ段にある連続した2行が、同じ単語または同じ末尾のbodyText.stackMinCharacters文字(既定は3、スペースを含む)で終わるか、同じように始まっています。アクセントと大文字・小文字は区別せず、重複があるのは単語をスペースで区切る文字体系だけです。bodyText.stacksが'warn'ならすべてを報告し、'avoid'なら改行処理が残したもの、つまり語間の範囲内でbodyText.stackPenaltyより安く避ける組み方がなかったものを報告します。エンジンは各重複を、繰り返された文字列、端(行末か行頭)、2行の文字列、ページとともにdoc.contentWarningsに記録します。
対処. bodyText.stacksを'avoid'にします。改行処理は語間の許す範囲で段落を組み直します。残った重複は、避けるコストがbodyText.stackPenaltyより高いものです。ペナルティを上げて行の緩みと引き換えにするか、2行のどちらかの文を書き換えます。既存の本の移植では'warn'のままにします。移植は原本の改行を再現するためです。 ドキュメント →
- 重複は、改行が決まった行の中で探します。判型や文字サイズ、文章を変えると初校で見つかる重複も変わります。組むたびに警告を読み、前の組版の位置を写さないでください。
- 重複は一つの段落の中でだけ数え、語をスペースで区切る文字体系だけが対象です。二つの段落がどちらも Scrooge で始まっても重複にはならず、中国語や日本語の文章では警告は出ません。
クレジット
- 本文
- A Christmas Carol (1843), the opening of Stave One, from Project Gutenberg eBook #46, with typographic quotes and dashes · Charles Dickens · パブリックドメイン
- ¡Adiós, Cordera!, the opening of the story, from El Señor y lo demás son cuentos (Madrid, 1919), with « » quotation marks · Leopoldo Alas, Clarín · パブリックドメイン
- 画像
- Painting: Scrooge's counting-house on a foggy Christmas Eve · Generated With Diffusion Models · オリジナル
- Painting: Rosa, Pinín and the Cordera by the telegraph pole · Generated With Diffusion Models · オリジナル
- フォント
- Spectral (SIL OFL 1.1) · Spectral SC (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1)


