Μετάβαση στο κύριο περιεχόμενο
Συνταγή αριθμός 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 mm
  • Μιάμιση στήλη, Διάκενο 7 mm
  • Literata 9,6/13,6
  • Libre Franklin
  • 10 σελίδες
  • Επίπεδο
  • Postext 1.57.1
  • Σελιδοποίηση σε 43 ms
  • 213 γραμμές κώδικα

Με λίγα λόγια

Δύο κεφάλαια ενός εγχειριδίου φυσιολογίας με ένα ευρετήριο στο τέλος. Οι λέξεις σημαδεύονται μέσα στο κείμενο, και το βιβλίο βρίσκει μόνο του τους αριθμούς σελίδων τους, οπότε κανένας δεν πληκτρολογείται με το χέρι.

Τι θα στοιχειοθετήσετε

Το Μέρος IV του Principles of Human Physiology, ενός εγχειριδίου σε σελίδα 210 × 277 mm: το κεφάλαιο 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 mm, μόνο στη δική του ενότητα, και δίνει στο ευρετήριο δική του εναρκτήρια σελίδα και τρέχουσα κεφαλίδα. Το ευρετήριο στοιχειοθετείται στη γραμματοσειρά του κειμένου στα 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 mm (46 mm για το ευρετήριο), με τον τίτλο στη βάση της από ένα πλαίσιο στοιχισμένο κάτω, ώστε ένας τίτλος δύο γραμμών και ένας τίτλος μίας γραμμής να τελειώνουν στην ίδια γραμμή. Ο υπέρτιτλος τυπώνει το {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 script οποιασδήποτε σελίδας ή ανοίξτε τη συνταγή στο 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)
SandboxPDF