انتقل إلى المحتوى الرئيسي
الوصفة رقم 72

دليل الوصفات · الفصل 5 · بنية الكتاب

فهرس أبجدي لكتاب مدرسي يتبع النص

مصطلحات تُعلَّم حيث يشرحها النص، ويطبعها :::index في عمودين مع الصفحات التي يجدها لها buildBundle، والنطاقات والإحالات المتبادلة.

في هذه الصفحة
المُخرَج
Canvas · PDF
المستوى
متقدم
Postext
اختُبرت مع Postext 1.65.0
تتطلب ≥ 1.28.0 · postext-pdf ≥ 1.28.0
الترخيص
حُدّثت في 11 أكتوبر 2026
الشيفرة MIT · النص CC BY 4.0

ص 304–305 · 8–9 من 10

  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 210 × 277 مم
  • عمود ونصف, فاصل 7 مم بين الأعمدة
  • Literata 9.6/13.6
  • Libre Franklin
  • 10 صفحات
  • المستوى
  • Postext 1.57.1
  • أُخرجت في 43 ms
  • أسطر الشيفرة: 213

باختصار

فصلان من كتاب مدرسي في علم وظائف الأعضاء وفي آخره فهرس أبجدي. تُعلَّم الكلمات في النص، ويجد الكتاب أرقام صفحاتها وحده، فلا يُكتب أي رقم باليد.

ما الذي ستنضده

الجزء الرابع من Principles of Human Physiology، كتاب مدرسي على صفحة بقياس 210 × 277 مم: الفصل 14، The heart as a pump، والفصل 15، Vessels and blood pressure، ينفتحان على صفحات فردية تحت شريط أحمر ويضعان ملاحظاتهما السريرية وتعليقات أشكالهما في قناة خارجية. ويُختم الجزء بفهرس أبجدي من نحو تسعين مدخلًا وثلاثين مدخلًا فرعيًا في عمودين، كما تنضّده الكتب الطبية: مداخل بالحروف الصغيرة، ورؤوس حروف بلون التمييز، ومداخل فرعية مزاحة بمقدار em واحد، والصفحة التي تعرّف المصطلح بالخط العريض، وsee وsee also بالمائل. لم يُكتب فيه رقم صفحة واحد باليد. كل مصطلح معلَّم في الفصل حيث يشرحه النص، والفهرس يقرأ الصفحات التي وقعت عليها هذه العلامات، من الصفحة 297 إلى 304.

تجيب هذه الوصفة عن

  • كيف أبني فهرسًا أبجديًّا في آخر الكتاب تتغير أرقام صفحاته من تلقاء نفسها حين يتحرك النص؟

الجواب المختصر

script.js · الأسطر 45–68في الشيفرة الكاملة
// The chapters mark each term where the text discusses it:
//   the :index[stroke volume]{main}         prints the words, files them, bold page
//   mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
//   ## Venous return :index{term="venous return" range="start" main}  … range="end"
//   :index{term="inotropy" see="contractility"}      a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
  id: 'index', numbered: false, toc: false, // not counted: no chapter 16
  layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
  advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
  header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
  fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
  indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
  // English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
  // writes both numbers in full and joins them with a hyphen (301-303).
  rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
  main: { bold: true }, // the defining page in bold
  see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
  groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};

المكونات

الخطوط
Literata, Libre Franklin (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

طريقة التحضير

#1 · علّم المقطع لا الكلمة

script.js · الأسطر 45–68في الشيفرة الكاملة
// The chapters mark each term where the text discusses it:
//   the :index[stroke volume]{main}         prints the words, files them, bold page
//   mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
//   ## Venous return :index{term="venous return" range="start" main}  … range="end"
//   :index{term="inotropy" see="contractility"}      a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
  id: 'index', numbered: false, toc: false, // not counted: no chapter 16
  layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
  advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
  header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
  fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
  indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
  // English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
  // writes both numbers in full and joins them with a hyphen (301-303).
  rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
  main: { bold: true }, // the defining page in bold
  see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
  groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};

يعلّم المفهرِس المواضع التي يُشرح فيها المصطلح، لا كل موضع ترد فيه الكلمة. يستعمل الفصلان stroke volume اثنتي عشرة مرة، والفهرس يرسل القارئ إلى موضعين: الصفحة 298، حيث يُعرَّف المصطلح، و299–300، حيث يشرح النص ما يتحكم فيه. العلامة المرئية، :index[cardiac output]{main}، تطبع كلماتها وتسجّلها في الفهرس. والعلامة غير المرئية، mitral:index{term="heart!valves!mitral"}، لا تطبع شيئًا وتأخذ صفحة الكلمة التي قبلها، وبهذا يسجّل المقطع الذي يتناول الصمامات الأربعة mitral وtricuspid وaortic وpulmonary تحت heart دون إعادة صياغة الجملة. الرمز ! يفصل بين المستويات، فيأخذ heart ثلاثة: الصمامات، ثم كل صمام. والعلامة تعمل أيضًا في عنوان (نطاقا 14.1 و15.6 يبدآن هناك) وفي إطار (heart failure معرَّف في الملاحظة الجانبية في الصفحة 300).

#2 · الصفحات الرئيسية والنطاقات والإحالات المتبادلة

script.js · الأسطر 45–68في الشيفرة الكاملة
// The chapters mark each term where the text discusses it:
//   the :index[stroke volume]{main}         prints the words, files them, bold page
//   mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
//   ## Venous return :index{term="venous return" range="start" main}  … range="end"
//   :index{term="inotropy" see="contractility"}      a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
  id: 'index', numbered: false, toc: false, // not counted: no chapter 16
  layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
  advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
  header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
  fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
  indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
  // English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
  // writes both numbers in full and joins them with a hyphen (301-303).
  rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
  main: { bold: true }, // the defining page in bold
  see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
  groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};

يضع main الصفحة التي تعرّف المصطلح بالخط العريض، فالطالب الذي يبحث عن preload يذهب أولًا إلى الصفحة 299. وrange="start" وrange="end"، مع المصطلح نفسه، يحدّان نقاشًا يمتد عبر فاصل صفحة: stroke volume, regulation, 299–300، baroreceptor reflex, 303–4. ووضع main على البداية يجعل النطاق كله عريضًا. والصفحة المعلَّمة مرة أخرى داخل نطاقها تندمج فيه، وmain هناك يجعل النطاق عريضًا. يحلّ see محل أرقام الصفحات (inotropy. See contractility)، ويأتي seealso بعدها (heart failure, 300. See also ejection fraction). والهدف الذي له مستويات يُكتب بـ! ويُطبع بنقطتين: See blood pressure: mean arterial.

#3 · فصل الفهرس في عمودين

script.js · الأسطر 45–68في الشيفرة الكاملة
// The chapters mark each term where the text discusses it:
//   the :index[stroke volume]{main}         prints the words, files them, bold page
//   mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
//   ## Venous return :index{term="venous return" range="start" main}  … range="end"
//   :index{term="inotropy" see="contractility"}      a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
  id: 'index', numbered: false, toc: false, // not counted: no chapter 16
  layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
  advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
  header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
  fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
  indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
  // English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
  // writes both numbers in full and joins them with a hyphen (301-303).
  rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
  main: { bold: true }, // the defining page in bold
  see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
  groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};

الفهرس هو آخر مستند Markdown في الكتاب، # Index {style="index"} يليه :::index. يستبدل نمط العنوان بتخطيط العمود ونصف العمود في الفصول عمودين بينهما 6 مم، في قسمه وحده، ويمنح الفهرس صفحة افتتاح وترويسة خاصتين به. يُضبط الفهرس بخط المتن بحجم 8.6/11.4 pt، وem واحد لكل مستوى فرعي، والسطر المتابع يُزاح بمقدار em اثنين، فلا يصطف السطر الملتف أبدًا مع مدخل فرعي. ويحذف rangeFormat: 'chicago' الأرقام التي يكررها النطاق (303–4، لكن 299–300). والطبعة الإسبانية تكتب النطاقات كاملة بواصلة (303-304)، وهي العادة الجارية في الكتب الإسبانية.

#4 · لماذا تتبع الأرقام النص

script.js · الأسطر 377–385في الشيفرة الكاملة
const text = chapters.map((chapter) => chapter.markdown).join('\n');
await loadSvg('pv-loop.svg', pvLoop());
await prepareFonts(text, config, kitFonts(FONTS));
const docs = await withLoadedFonts(() => buildBundle({ chapters, config, resources }),
  { ...kitFonts(FONTS), text });
showPages(docs, { title: t({ en: 'Principles of Human Physiology',
  es: 'Principios de fisiología humana' }) });
offerPdf(() => renderToPdf(docs, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
  `${RECIPE}.pdf`);

يخرج buildBundle الفصول بالترتيب ويجد أن الثالث منها فيه :::index. بعد التمريرة الأولى يجمع كل علامة في كل فصل مع الصفحة التي وقعت عليها، ويسلّم هذه القائمة إلى فصل الفهرس مخططًا له. ثم يخرج الكتاب من جديد، حتى ثلاث تمريرات، إلى أن لا يتحرك أي رقم صفحة. أعِد كتابة فقرة من الفصل 14، أو غيّر مقاس القص أو حجم المتن، فيُطبع الفهرس من جديد بالصفحات الجديدة. وفي ملف PDF يرتبط كل رقم صفحة بصفحته.

#5 · صفحات الافتتاح والترويسات

script.js · الأسطر 72–91في الشيفرة الكاملة
function opener(band = BAND, kicker = '') {
  const onBand = { color: col('paper'), align: 'left', overflow: 'wrap' }; // wrap: never '…'
  const inBand = band - MARGIN.top - 8; // the title's box: it stands on a line 8 mm above the foot
  return { enabled: true, minHeight: mm(inBand + 8 + 31), slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
      placement: { ...at('bleed', 'top-left', 0, 0), size: { height: mm(band) } } },
    { kind: 'text', id: 'kicker', content: kicker, ...label, ...onBand, fontSize: pt(8.5),
      placement: at('container', 'top-left', 0, -6) },
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: SANS,
      fontWeight: 800, fontSize: pt(30), lineHeight: 1.05, // a multiple, never pt()
      verticalAlign: 'bottom', // one line or two, the title sits on the same line
      placement: { ...at('container', 'top-left', 0, 0),
        size: { width: mm(170), height: mm(inBand) } } },
    { kind: 'text', id: 'lead', content: '{attr.lead}', fontFamily: SERIF, italic: true,
      fontSize: pt(10.5), lineHeight: 1.4, color: col('ink'), align: 'left', overflow: 'wrap',
      inlineMarks: true, // *See* in the index's lead
      placement: { ...at('container', 'top-left', 0, inBand + 15),
        size: { width: mm(118) } } },
  ] } };
}

تتشارك الفصول والفهرس صفحة افتتاح واحدة: شريط من حدّ القص حتى 62 مم (46 مم للفهرس)، والعنوان موضوع على أسفله بإطار محاذى إلى الأسفل، فينتهي العنوان ذو السطرين والعنوان ذو السطر الواحد على السطر نفسه. يطبع العنوان الصغير {chapterNumber}، الذي تجعله سمة العنوان {startAt=14} مساويًا لـ14، ويضع page.pageNumbering.startAt: 297 الجزء حيث كان سيقع في الكتاب. ونمط الفهرس numbered: false، فلا يصير الفصل 16.

الوصفة كاملة

Sandbox
// ═══ Postext Cookbook · Nº 072 · A textbook index that follows the text ═══════════════
// https://postext.dev/en/cookbook/back-of-book-index
// Code: MIT · Text: original (CC BY 4.0) · Drawing: generated in code (CC BY 4.0)
// Fonts: Literata, Libre Franklin (SIL OFL 1.1) · Needs postext ≥ 1.28.0
// Two chapters of a physiology textbook and the index that closes them, laid out by
// buildBundle as one book: the terms are marked where the text discusses them, and the
// index chapter prints them with the pages they land on.
import {
  buildBundle, prepareFonts, withLoadedFonts, renderPageToCanvas, registerResourceImage,
  defaultResourceTypes,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'back-of-book-index';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config links to one of these ids
  ink: '#1f1a1c', // text: a warm near-black
  accent: '#9e1b32', // the one accent (7.4:1 on paper): bands, letter heads, numbers, labels
  tint: '#f7ebe9', // the loop in Figure 14.1
  rule: '#d9c6c3', // hairlines
  muted: '#6b5f61', // running heads, notes, the colophon
  paper: '#ffffff', // type on the bands
};
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' } })),
  // The engine's defaults link to 'main-color': point it at the accent, so nothing prints blue.
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// A textbook trim, mirrored, in mm. The body is a column and a half: text in the main column,
// figures' captions and clinical notes in the outer channel.
const TRIM = { width: 210, height: 277 };
const MARGIN = { top: 24, bottom: 22, inner: 20, outer: 14 };
const LEAD = 13.6; // body leading in pt: the baseline grid
const [SERIF, SANS] = ['Literata', 'Libre Franklin'];
const [BAND, INDEX_BAND] = [62, 46]; // mm from the trim to the foot of the opener bands
const HEAD_Y = 13; // mm from the top trim to the running heads
const at = (to, edge, x, y) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const label = { fontFamily: SANS, fontSize: pt(7.5), fontWeight: 700, letterSpacing: pt(1.3),
  textTransform: 'uppercase' };

// #region answer: marks in the chapters, and an index chapter set in two columns
// The chapters mark each term where the text discusses it:
//   the :index[stroke volume]{main}         prints the words, files them, bold page
//   mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
//   ## Venous return :index{term="venous return" range="start" main}  … range="end"

يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

تنويعات

#اكتب كل نطاق كاملًا

بعض الأدلة التحريرية تطبع رقمي النطاق كاملين.

-  rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
+  rangeFormat: 'full', rangeSeparator: t({ en: '–', es: '-' }),

#فهرس بلا رؤوس حروف

الفهرس القصير يصل مجموعاته في الغالب بعضها ببعض، لا يفصل بينها إلا سطر فارغ.

-  groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
+  groups: { enabled: false },

أخطاء شائعة

خطأ شائع

الخلايا المدمجة تحتاج إلى خلايا نائبة hiddenBy: استخدم mergeCells

تُوزَّع الخلايا بحسب موضعها في مصفوفة الصف، فالخلية المدمجة تحتاج إلى خلايا نائبة معلَّمة بـ hiddenBy حيث تمتد؛ وحذفها، كما يفعل HTML، يزيح كل الأعمدة التالية. ابنِ الدمج بـ mergeCells. ومنذ postext 1.5 يُبلَّغ عن الجدول غير المنتظم الشبكة في doc.contentWarnings تحت raggedTableGrid، ويعلّم parseTSV(text, { headerRows }) صفوف الترويسة. جداول من البيانات →

  • لا تُبلغ لقطة هذه الوصفة عن indexSeeUnknown: الإحالة المتبادلة التي يُكتب هدفها بصيغة تختلف عن المدخل (Reynolds number مقابل number, Reynolds) تُطبع دون أي اعتراض. راجع كل See في الفهرس النهائي مقابل هدفها.
  • قائمة المداخل الفرعية التي تنكسر بين عمودين لا تكرر عنوانها الرئيسي في سطر heart (cont.)؛ والمدخل الذي ليست له صفحة خاصة يبقى دائمًا مع أول مدخل فرعي له، فلا ينتهي عمود أبدًا بعنوان وحده.

الحقوق

الوصفة
Ignacio Ferro
النص
نص أصلي, CC BY 4.0
الخطوط
Literata (SIL OFL 1.1) · Libre Franklin (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext
SandboxPDF