باختصار
حين ينتهي سطران متتاليان بالكلمة نفسها أو يبدآن بها، قد تقفز العين إلى السطر الخطأ. يُنضَّد الكتاب مرتين: مرة تبيّن أين يحدث ذلك، ومرة تُقسَّم فيها الأسطر بحيث لا يحدث.
ما الذي ستنضده
بروفتان لصفحة كتاب جيب مقاسها 115 × 180 مم، فيهما مطلع A Christmas Carol (ترنيمة عيد الميلاد) مضبوط الطرفين بخط Spectral على عرض سطر 83 مم. العرض الضيق يترك لخوارزمية تقسيم الأسطر خيارات قليلة، وفي خمسة مواضع ينتهي سطران متتاليان أو يبدآن بالكلمة نفسها: sole فوق sole، وhis فوق his، وNo فوق No. تُنضَّد البروفة الأولى بـstacks: 'warn'. لا تغيّر أي موضع قطع، بل تُبلغ عن كل تكرار، وتضع تحت الكلمتين شريطًا أحمر باهتًا، وتسردهما في قسيمة بعد بيانات النشر. وتُنضَّد الثانية بـ'avoid'، فتختفي أربعة من الخمسة. وتنضّد الطبعة الإسبانية مطلع ¡Adiós, Cordera! لـClarín بالطريقة نفسها.
تجيب هذه الوصفة عن
- كيف أمنع سطرين متتاليين من أن ينتهيا أو يبدآ بالكلمة نفسها؟
الجواب المختصر
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') };
تُنضَّد كل بروفة مرتين. التنضيد الأول يجد التكرارات، والثاني ينضّد النص نفسه مع العلامات وقسيمة تُلحق بعد بيانات النشر، فتقع القسيمة في الصفحة الأخيرة. ويُبقي الـpen التنضيد الأول لكل بروفة، أي النص بلا علامات، خارج الصفحات المنشورة: يسرد capture.doc التنضيدين المعلَّمين، [1, 3].

التكرار الباقي في الطبعة الإنجليزية هو even فوق event: تشترك الكلمتان في أحرفهما الثلاثة الأولى، وكل تقسيم آخر لتلك الفقرة كان أعلى كلفة. وفي الإسبانية، بحرفين، تجد البروفة الأولى خمسة تكرارات، منها co في con فوق como وar في levantar فوق vacilar، ولا تجد الثانية أيًّا منها.
#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 المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#احسب الكلمات الطويلة وحدها
القيمة الافتراضية ثلاثة أحرف. وبخمسة لا تُحسب الكلمات القصيرة مثل his وNo تكرارًا، وتحتفظ الخوارزمية حولها بالأسطر الأضيق.
- stackMinCharacters: t({ en: 3, es: 2 }),
+ stackMinCharacters: 5,#انضد الكتاب بالكلفة الافتراضية
تُبقي القيمة الافتراضية المسافات أضيق، وتقبل تكرارين في كل طبعة حيث يؤدي تجنّبهما إلى توسيع سطر أكثر.
- stackPenalty: 10000,
+ stackPenalty: 3000,أخطاء شائعة
تحذير الإخراج · stack
تكرار
السبب. سطران متتاليان من فقرة، في عمود واحد، ينتهيان بالكلمة نفسها أو بآخر bodyText.stackMinCharacters من الأحرف نفسها (3 افتراضيًا، والمسافات محسوبة)، أو يبدآن على النحو نفسه. لا تُحتسب الحركات ولا حالة الأحرف، ولا تكرار إلا في الكتابات التي تفصل الكلمات بمسافات. إذا كانت bodyText.stacks على 'warn' يُبلَّغ عن كل تكرار، وإذا كانت على 'avoid' فعن التكرارات التي أبقاها كسر الأسطر لأنه لم يكن ثمة تنضيد ضمن التباعد بين الكلمات يتجنّبها بأقل من bodyText.stackPenalty. ويُدرج المحرّك كلًّا منها في doc.contentWarnings مع النص المكرّر والطرف (النهاية أو البداية) والسطرين وصفحتهما.
الحل. اجعل bodyText.stacks على 'avoid': ينضّد كسر الأسطر الفقرة على نحو آخر حيث يسمح التباعد بين الكلمات. والتكرار الذي يبقى كلفة تجنّبه أعلى من bodyText.stackPenalty: ارفع العقوبة لتقبل أسطرًا أوسع تباعدًا مقابله، أو أعد صياغة أحد السطرين. وفي نقل كتاب قائم أبقِها على 'warn': فالنقل يعيد كسور الأسطر في الأصل. التوثيق →
- يُبحث عن التكرارات في الأسطر بعد تقسيمها. إذا غيّرت المقاس أو حجم الخط أو النص وجدت البروفة الأولى تكرارات أخرى، فاقرأ تحذيرات كل تنضيد ولا تنسخ مواضع من تنضيد سابق.
- تُحسب التكرارات داخل الفقرة الواحدة فقط، وفي الكتابات التي تفصل الكلمات بالمسافات وحدها: فقرتان تبدأ كلتاهما بـScrooge لا تصنعان تكرارًا، والنص الصيني أو الياباني لا يُبلغ عن أي تكرار.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- 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)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


