# Σχολιασμένο κλασικό με σχόλια στο περιθώριο

> Το τρελό τσάι της Αλίκης ως σχολιασμένη έκδοση: πράσινα και κόκκινα σχόλια στο έξω περιθώριο, δίπλα στις γραμμές τους, με ένα γράμμα στο χρώμα τους.

- Έκδοση HTML: https://postext.dev/el/cookbook/annotated-classic-glosses
- Συνταγή Αρ. 032 · Πλαίσια και σημειώσεις · Επίπεδο 3 (Προχωρημένο) · Έξοδοι: Canvas
- Είδη: Πεζογραφία, θέατρο και λογοτεχνικός λόγος
- Απαιτεί postext ≥ 1.28.0 · δοκιμασμένη με 1.65.0 στις 2026-10-31
- Σελίδες: [81](https://postext.dev/cookbook/annotated-classic-glosses/en/p01.webp?v=e49bbaba), [82](https://postext.dev/cookbook/annotated-classic-glosses/en/p02.webp?v=e49bbaba), [83](https://postext.dev/cookbook/annotated-classic-glosses/en/p03.webp?v=e49bbaba)
- Άνοιγμα στο Sandbox: https://postext.dev/el/sandbox#recipe=annotated-classic-glosses&lang=en (.postext: https://postext.dev/cookbook/annotated-classic-glosses/en/annotated-classic-glosses.postext)
- Τελευταία ενημέρωση: 2026-10-11
- Άλλες γλώσσες: [en](https://postext.dev/en/cookbook/annotated-classic-glosses.md), [es](https://postext.dev/es/cookbook/annotated-classic-glosses.md), [ca](https://postext.dev/ca/cookbook/annotated-classic-glosses.md), [de](https://postext.dev/de/cookbook/annotated-classic-glosses.md), [fr](https://postext.dev/fr/cookbook/annotated-classic-glosses.md), [it](https://postext.dev/it/cookbook/annotated-classic-glosses.md), [pt](https://postext.dev/pt/cookbook/annotated-classic-glosses.md), [zh](https://postext.dev/zh/cookbook/annotated-classic-glosses.md), [ja](https://postext.dev/ja/cookbook/annotated-classic-glosses.md), [ar](https://postext.dev/ar/cookbook/annotated-classic-glosses.md)

## Με λίγα λόγια

Λίγες σελίδες από την Αλίκη στη Χώρα των Θαυμάτων με σημειώσεις του επιμελητή στο πλάγιο περιθώριο. Κάθε σημείωση κάθεται δίπλα στις γραμμές που εξηγεί, σημαδεμένη με ένα χρωματιστό γράμμα.

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

Η αρχή του κεφαλαίου VII της *Αλίκης στη Χώρα των Θαυμάτων*, το τρελό τσάι, στοιχειοθετημένη ως τρεις σελίδες μιας σχολιασμένης έκδοσης σε σελίδα εμπορίου 156 × 234 mm. Το κείμενο του Κάρολ τρέχει σε μία στήλη Unna με πλήρη στοίχιση, περίπου 66 χαρακτήρες ανά γραμμή. Ένα κανάλι 33 mm στο εξωτερικό άκρο φιλοξενεί τα οκτώ σχόλια του επιμελητή, το καθένα δίπλα στην παράγραφο που φέρει το γράμμα του, οπότε τρέχουν κατά μήκος της δεξιάς πλευράς σε μια δεξιά σελίδα και της αριστερής σε μια αριστερή. Τα σχόλια για λέξεις και λογοπαίγνια είναι πράσινα, εκείνα για την ιστορία κόκκινα, και κάθε γράμμα στο κείμενο παίρνει το χρώμα του σχολίου του. Το κεφάλαιο ανοίγει κάτω από μια υδατογραφία του τραπεζιού του τσαγιού ιδωμένου από ψηλά, ακολουθούμενη από τον αριθμό, τον τίτλο σε Rozha One και ένα εισαγωγικό σημείωμα σε πλάγια με πράσινο αρχίγραμμα· η σημείωση για αυτή την έκδοση κάθεται στο περιθώριο δίπλα στο εισαγωγικό σημείωμα.

**Αυτή η συνταγή απαντά:**

- Πώς στοιχειοθετώ σχόλια στο περιθώριο δίπλα στην παράγραφο που εξηγούν, αντί για υποσημειώσεις;
- Πώς κάνω υποσημειώσεις;
- Πώς φτιάχνω διάταξη μιάμισης στήλης, με μια φαρδιά στήλη κειμένου και μια στενή πλευρική στήλη;
- Πώς προσθέτω σε μια εναρκτήρια σελίδα γραμμή συγγραφέα, εισαγωγικό κείμενο ή εισαγωγή με αρχίγραμμα;

## Η σύντομη απάντηση

```js
// script.js, γραμμές 36–61
const layout = {
  layoutType: 'oneAndHalf', // one text column and a narrower side column
  sideColumnPercent: 26, // of the 127 mm between the margins: a 33 mm channel
  sideColumnRole: 'floats', // no text runs in it: it holds side boxes and figures
  sideColumnSide: 'outer', // at the fore-edge, which mirrored margins move page by page
  gutterWidth: mm(4.5), // the text column keeps 127 − 33 − 4.5 = 89.5 mm
};
// A gloss is :::callout{type="note" span="side" title="a · …"} in the Markdown.
// span="side" moves it out of the flow into the channel, level with the block after
// the fence, so the fence goes just before the paragraph that carries its letter.
// Glosses never float. One that meets the gloss above stacks under it. One that would
// run past the column's foot slides up, as far as the gloss above allows, until its
// foot sits on the foot; if it still does not fit, it waits for the next page
// (gotcha: side-box-starts-at-fence).
const gloss = (id, hue) => ({ id,
  backgroundEnabled: false, // one device: a hairline over the gloss, in its colour
  stripe: { enabled: true, side: 'top', width: pt(0.5), color: col(hue) },
  padding: { top: mm(1.5), right: pt(0), bottom: pt(0), left: pt(0) },
  // Cormorant SC draws lower case as small capitals: the title needs no textTransform.
  titleStyle: { fontFamily: LABEL, fontWeight: 600, fontSize: pt(8.5),
    letterSpacing: pt(0.3), color: col(hue), gap: mm(0.8) },
  // Face and colours come from bodyText. A box body also inherits its 4 mm first-line
  // indent, which a gloss sets back to 0.
  body: { fontSize: pt(7.8), lineHeight: pt(10), textAlign: 'left',
    firstLineIndent: pt(0) } });
const calloutStyles = [gloss('note', 'lawn'), gloss('context', 'jam')]; // words, history
```

## Υλικά

**Διδάσκει**

- [Σημειώσεις περιθωρίου](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων): Πλαίσια στοιχειοθετημένα στην πλευρική στήλη στο ύψος της παραγράφου που σχολιάζουν, σε διάταξη με στήλη και μισή και κανάλι κινητών στοιχείων.
- [Στήλη περιθωρίου για κινητά στοιχεία](https://postext.dev/el/docs/configuration-page-layout.md#διάταξη): Σελίδα με στήλη και μισή, όπου η πλευρική στήλη δεν δέχεται κυρίως κείμενο αλλά μόνο τις εικόνες, τους πίνακες και τα πλαίσια που τοποθετούνται εκεί, όπως στο περιθώριο πολλών σχολικών βιβλίων.
- [Στήλη και μισή](https://postext.dev/el/docs/configuration-page-layout.md#τύποι-διάταξης): Ασύμμετρη διάταξη: μια φαρδιά κύρια στήλη και μια στενή πλευρική στήλη, σε σταθερή πλευρά ή στην εξωτερική άκρη κάθε σελίδας.

**Χρησιμοποιεί επίσης**

- [Συμμετρικά περιθώρια](https://postext.dev/el/docs/configuration-page-layout.md#κατοπτρικά-περιθώρια)
- [Πλαίσια σημειώσεων](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων)
- [Εκθέτες και δείκτες](https://postext.dev/el/docs/document-format-inline.md#μορφοποίηση-μέσα-στη-γραμμή)
- [Σχεδιασμένες εναρκτήριες σελίδες](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση)
- [Ταινία κεφαλαίου πλήρους πλάτους](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση)
- [Κείμενο, γραμμές και πλαίσια στις σχεδιάσεις σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα)
- [Εικόνες στις σχεδιάσεις σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-εικόνας)
- [Αγκύρωση στοιχείων σχεδίασης](https://postext.dev/el/docs/configuration-headers-footers.md#τοποθέτηση-στοιχείων)
- [Αρχίγραμμα στις εναρκτήριες σελίδες](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-κειμένου)
- [Ιδιότητες επικεφαλίδων](https://postext.dev/el/docs/document-format.md#χαρακτηριστικά-επικεφαλίδων)
- [Τρέχουσες κεφαλίδες και αριθμοί σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα)
- [Κεφαλίδες ανά ρόλο σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-κειμένου)
- [Εικόνες και πίνακες ως πόροι](https://postext.dev/el/docs/document-format-resources.md#πόροι)
- [Σημασιολογική χρωματική παλέτα](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων)
- [Βέλτιστη αλλαγή γραμμής (Knuth–Plass)](https://postext.dev/el/docs/justification.md#knuth-plass-η-ματιά-σε-ολόκληρη-την-παράγραφο)
- [Ετικέτες μέσα στη γραμμή](https://postext.dev/el/docs/configuration-styles.md#στιλ-ετικετών)
- [Υποσημειώσεις](https://postext.dev/el/docs/document-format-notes-references.md#υποσημειώσεις)
- [Χρώμα χαρτιού](https://postext.dev/el/docs/configuration-page-layout.md#σελίδα)

**Η διαμόρφωση με μια ματιά**

- [`bodyText`](https://postext.dev/el/docs/configuration-text.md#κυρίως-κείμενο), [`calloutStyles`](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων), [`chipStyles`](https://postext.dev/el/docs/configuration-styles.md#στιλ-ετικετών), [`colorPalette`](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων), [`footer`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`header`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`headings`](https://postext.dev/el/docs/configuration-headings.md#επικεφαλίδες), [`layout`](https://postext.dev/el/docs/configuration-page-layout.md#διάταξη), [`locale`](https://postext.dev/el/docs/configuration-language.md#συλλαβισμός), [`page`](https://postext.dev/el/docs/configuration-page-layout.md#σελίδα)

**API**

- [`buildDocumentWithFonts`](https://postext.dev/el/docs/configuration-programmatic-usage.md#φόρτωση-γραμματοσειρών-πριν-από-τη-σελιδοποίηση), [`registerResourceImage`](https://postext.dev/el/docs/architecture.md#η-επιφάνεια-του-api), [`renderPageToCanvas`](https://postext.dev/el/docs/configuration-programmatic-usage.md#απόδοση-σελίδας-σε-bitmap)

**Γραμματοσειρές**

- Unna (OFL-1.1), Rozha One (OFL-1.1), Cormorant SC (OFL-1.1)

## Προετοιμασία

### 1 · Δώστε το εξωτερικό άκρο στα σχόλια

Ο κώδικας βρίσκεται στη [σύντομη απάντηση](https://postext.dev/el/cookbook/annotated-classic-glosses.md#η-σύντομη-απάντηση) παραπάνω. Σε μια [διάταξη μιάμισης στήλης](https://postext.dev/el/docs/configuration-page-layout.md#τύποι-διάταξης), το `sideColumnPercent: 26` δίνει στην πλευρική στήλη 33 mm από τα 127 mm ανάμεσα στα περιθώρια, και το κείμενο κρατά 89,5 mm μετά το διάκενο των 4,5 mm. Το `sideColumnRole: 'floats'` κρατά τον Κάρολ έξω από την πλευρική στήλη, που περιέχει μόνο ό,τι τοποθετείται εκεί με `span: 'side'`. Μια [υποσημείωση](https://postext.dev/el/docs/document-format-notes-references.md#υποσημειώσεις) περιμένει στο πόδι της στήλης, κάτω από μια γραμμή· στο περιθώριο κάθε σχόλιο στέκεται στο ύψος της γραμμής που εξηγεί, και τα σχόλια δεν παίρνουν γραμμές από τη στήλη του κειμένου. Τα δύο στιλ σχολίων διαφέρουν μόνο στο χρώμα της λεπτής γραμμής και του τίτλου, ώστε ο αναγνώστης να ξεχωρίζει ένα σχόλιο για μια λέξη από ένα σχόλιο για την ιστορία πριν το διαβάσει.

### 2 · Αντικατοπτρίστε τη σελίδα ώστε το κανάλι να ακολουθεί το εξωτερικό άκρο

```js
// script.js, γραμμές 75–86
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [156, 234]; // mm
const [TOP, BOTTOM, INNER, OUTER] = [22, 22, 15, 14]; // mm: 38 lines of text
const page = { width: mm(TRIM_W), height: mm(TRIM_H), dpi: 150,
  backgroundColor: col('paper'),
  // left is a recto's inner margin; mirror swaps the sides on a verso, and 'outer' moves
  // the channel with them: right on a recto, left on a verso.
  margins: { top: mm(TOP), bottom: mm(BOTTOM), left: mm(INNER), right: mm(OUTER),
    mirror: true } };
const CONTENT_W = TRIM_W - INNER - OUTER; // 127 mm
const SIDE_W = CONTENT_W * layout.sideColumnPercent / 100; // 33 mm: the glosses' measure
const TEXT_W = CONTENT_W - SIDE_W - layout.gutterWidth.value;
```

Με `mirror: true` τα περιθώρια αντιστρέφονται σε κάθε αριστερή σελίδα, και το `sideColumnSide: 'outer'` μετακινεί το κανάλι μαζί τους, οπότε τα σχόλια τρέχουν στα δεξιά της [σελίδας 81](https://postext.dev/cookbook/annotated-classic-glosses/en/p01.webp?v=e49bbaba) και της [σελίδας 83](https://postext.dev/cookbook/annotated-classic-glosses/en/p03.webp?v=e49bbaba) και στα αριστερά της [σελίδας 82](https://postext.dev/cookbook/annotated-classic-glosses/en/p02.webp?v=e49bbaba). Πάνω και κάτω περιθώρια 22 mm αφήνουν 190 mm, χώρο για 38 γραμμές των 14 pt, και κάθε σχόλιο αρχίζει σε μια γραμμή του ίδιου πλέγματος.

### 3 · Βάλτε κάθε σχόλιο σε μπλοκ πριν από την παράγραφο που εξηγεί

```js
// script.js, γραμμές 90–104
const bodyText = { // justified and hyphenated (en-us) by default
  // Copy-fitted to the 89.5 mm column: at 9.5 pt '“Have some wine,” the March Hare said in
  // an encouraging tone.' fits one line. At 10.4 pt every measure from 77 to 93 mm left
  // it a short last line: 'couraging tone.', 'aging tone.', 'ing tone.' or 'tone.'.
  fontFamily: TEXT, fontSize: pt(9.5), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), firstLineIndent: mm(4),
  // The chapter's first paragraph is set flush, though the fences of glosses a and b stand
  // between the heading and it: a box that leaves the flow is not the block after a heading.
  indentAfterHeading: false,
  // Unna's space is narrow, 0.22 em. At the default 0.6 the line breaker set 'Alice felt
  // dreadfully puzzled. The Hatter’s remark seemed to have' with its spaces at 0.69.
  minWordSpacing: 0.75,
  // The dictionary divides the heroine's name, 'said Al-' | 'ice indignantly' on page 81.
  // The list keeps it whole wherever it stands; every other word is divided as before.
  hyphenation: { exceptions: ['Alice'] } };
```

Ένα πλαίσιο με `span="side"` στο [μπλοκ `:::callout`](https://postext.dev/el/docs/configuration-callouts.md#ο-περιέκτης-callout) του φεύγει από τη ροή και στέκεται στο κανάλι στο ύψος του μπλοκ μετά από αυτό, οπότε κάθε σχόλιο μπαίνει ακριβώς πριν από την παράγραφο που φέρει το γράμμα του, όπως παρακάτω. Τα σχόλια a και b ανήκουν δίπλα στην πρώτη παράγραφο, κάτι που βάζει τα μπλοκ τους ανάμεσα στην επικεφαλίδα και σε εκείνη την παράγραφο. Ένα πλαίσιο που φεύγει από τη ροή δεν μετρά ως το μπλοκ μετά την επικεφαλίδα, οπότε το `indentAfterHeading: false` στοιχειοθετεί ακόμη εκείνη την παράγραφο χωρίς εσοχή. Το κυρίως κείμενο είναι προσαρμοσμένο στη στήλη: στα 9,5 pt η παράγραφος που ανοίγει με «Have some wine,» χωρά σε μία γραμμή των 89,5 mm, ενώ στα 10,4 pt κάθε πλάτος στοιχειοθεσίας από 77 έως 93 mm της άφηνε μια κοντή τελευταία γραμμή όπως «ing tone.» ή «tone.». Το διάστημα λέξεων της Unna είναι στενό, 0,22 em, και με το προεπιλεγμένο `minWordSpacing` του 0,6 μία γραμμή στη σελίδα 83 είχε τα διαστήματά της συμπιεσμένα στο 0,69 αυτού του πλάτους· το `minWordSpacing: 0.75` αποκλείει εκείνη τη γραμμή. Στη σελίδα 81 το λεξικό χώρισε το όνομα της ηρωίδας, «Al-» και «ice», οπότε εκείνη η παράγραφος μπαίνει σε `:::paragraphs{style="whole"}`, ένα στιλ με `hyphenation: false`· η μία αλλαγή της είναι ένα μαλακό ενωτικό (U+00AD) γραμμένο μέσα στο «together».

```markdown
:::callout{type="context" span="side" title="c · Hair"}
Tenniel drew Alice with long, loose hair. …
:::

“Your hair wants cutting,”:chip[^c^]{style="context"} said the Hatter. …
```

### 4 · Τυπώστε κάθε γράμμα στο χρώμα του σχολίου του

```js
// script.js, γραμμές 65–71
// A letter in the text is a chip named after its gloss's type, :chip[^a^]{style="note"}:
// the Markdown has no mark for coloured text, and a chip style sets a colour. With no
// fill, outline, padding or gap the chip adds no width, so the lines break as they would
// with a plain ^a^.
const letter = (id, hue) => ({ id, backgroundEnabled: false, borderWidth: pt(0),
  paddingX: pt(0), gap: pt(0), color: col(hue), bold: true });
const chipStyles = [letter('note', 'lawn'), letter('context', 'jam')];
```

Το Markdown δεν έχει σημάδι για χρωματιστό κείμενο, αλλά ένα στιλ [ετικέτας](https://postext.dev/el/docs/document-format-inline.md#ετικέτες-μέσα-στη-γραμμή) ορίζει χρώμα κειμένου, οπότε κάθε γράμμα είναι μια ετικέτα της οποίας το στιλ έχει το ίδιο όνομα με τον τύπο του σχολίου της. Το `:chip[^c^]{style="context"}` τυπώνει ένα κόκκινο c, το κόκκινο της λεπτής γραμμής και του τίτλου του σχολίου c. Χωρίς γέμισμα, περίγραμμα, εσωτερικό περιθώριο ή διάκενο η ετικέτα δεν προσθέτει πλάτος, και κάθε γραμμή αλλάζει εκεί όπου άλλαζε με ένα σκέτο `^c^`.

### 5 · Ανοίξτε το κεφάλαιο κάτω από το τραπέζι του τσαγιού

```js
// script.js, γραμμές 108–155
const HEADPIECE = 72; // mm: the depth of the painting at the head of the page
const HEADNOTE = { size: 9.8, lead: LEAD }; // pt: the headnote keeps the body's leading
const CAPS = { text: 0.597, initial: 0.56 }; // cap heights, em: Unna and Rozha One
// The initial's size: its capital runs from the first line's cap height down to the
// last baseline it spans. At the default size it stops short of the first line's capitals.
const dropSize = (lines) => pt(((lines - 1) * HEADNOTE.lead + CAPS.text * HEADNOTE.size)
  / CAPS.initial);
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' },
  offset: { y: mm(y) }, size: { width } });
// The opener reserves the height of its lowest element, rounded up to the grid, and the
// heading's default bottom margin adds one blank line: with a four-line headnote the
// text starts on line 23. The kicker, the title and the headnote hang below the painting.
const opener = { enabled: true, slot: { elements: [
  // An image element draws a resource without number or caption. It hangs from the
  // trim's corner, over the top margin and both side margins.
  { kind: 'image', id: 'headpiece', resourceId: 'tea-table',
    placement: { anchor: { to: 'page', edge: 'top-left' },
      size: { width: mm(TRIM_W) } } },
  // The numeral comes from the heading line,
  // # A Mad Tea-Party {num="VII" headnote="…" …}: the excerpt stands alone, so
  // {chapterNumber} would count its one heading and print 1.
  { kind: 'text', id: 'kicker', content: 'Chapter {attr.num}', fontFamily: LABEL,
    fontWeight: 600, fontSize: pt(9), letterSpacing: pt(2), textTransform: 'uppercase',
    color: col('jam'), align: 'left',
    placement: { anchor: { to: 'container', edge: 'top-left' },
      offset: { y: mm(HEADPIECE - TOP + 8) } } }, // 8 mm under the painting's foot
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY,
    fontSize: pt(40), lineHeight: 1.05, color: col('ink'), align: 'left', // wraps when longer
    placement: below('kicker', 2, 'fill') },
  // The drop cap opens the headnote, the editor's voice, italic and ragged; Carroll's
  // text opens in the flow, justified.
  { kind: 'text', id: 'headnote', content: '{attr.headnote}', fontFamily: TEXT,
    italic: true, fontSize: pt(HEADNOTE.size),
    lineHeight: pt(HEADNOTE.lead), color: col('ink'),
    align: 'left',
    dropCap: { lines: 2, fontFamily: DISPLAY, fontSize: dropSize(2), color: col('lawn'),
      gap: mm(1.5) },
    placement: below('title', 5, mm(TEXT_W)) },
  // The note on this edition stands in the channel, level with the headnote's top.
  { kind: 'text', id: 'edition-label', content: 'This edition', fontFamily: LABEL,
    fontWeight: 600, fontSize: pt(8.5), letterSpacing: pt(0.3), color: col('muted'),
    align: 'left', placement: { anchor: { to: '#headnote', edge: 'right-of' },
      offset: { x: layout.gutterWidth }, size: { width: mm(SIDE_W) } } },
  { kind: 'text', id: 'edition', content: '{attr.source}', fontFamily: TEXT,
    fontSize: pt(7.5), lineHeight: pt(10), color: col('muted'), align: 'left',
    placement: { anchor: { to: '#edition-label', edge: 'below' }, offset: { y: mm(0.8) },
      size: { width: mm(SIDE_W) } } },
] } };
```

Η [θέση σχεδίασης](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση) της επικεφαλίδας απλώνεται σε όλη τη σελίδα ώστε ο πίνακας να φτάνει ως την άκρη κοπής. Ο υπέρτιτλος, ο τίτλος και το εισαγωγικό σημείωμα κρέμονται κάτω από τον πίνακα, και η εναρκτήρια σελίδα δεσμεύει χώρο ως το χαμηλότερο από αυτά, στρογγυλεμένο προς τα πάνω στο πλέγμα· το προεπιλεγμένο κάτω περιθώριο της επικεφαλίδας προσθέτει μία κενή γραμμή. Με εισαγωγικό σημείωμα τεσσάρων γραμμών το κείμενο αρχίζει στη γραμμή 23, και μια πέμπτη γραμμή θα το μετακινούσε στη γραμμή 24. Ο αριθμός, το εισαγωγικό σημείωμα και η σημείωση για αυτή την έκδοση προέρχονται από [χαρακτηριστικά επικεφαλίδας](https://postext.dev/el/docs/document-format.md#χαρακτηριστικά-επικεφαλίδων), `{num="VII" headnote="…" source="…"}`. Ο αριθμός προέρχεται από εκεί επειδή το `{chapterNumber}` θα τύπωνε 1 σε ένα απόσπασμα που είναι αυτοτελές έγγραφο. Το αρχίγραμμα ανοίγει το εισαγωγικό σημείωμα του επιμελητή, στοιχειοθετημένο με στοίχιση αριστερά σε πλάγια, και το κείμενο του Κάρολ αρχίζει με πλήρη στοίχιση στη ροή από κάτω. Το `dropSize()` δίνει στο αρχικό γράμμα μέγεθος ώστε η κορυφή του να ευθυγραμμίζεται με τα κεφαλαία της πρώτης γραμμής του εισαγωγικού σημειώματος.

### 6 · Χρωματίστε κάθε σχόλιο ανάλογα με ό,τι εξηγεί

```js
// script.js, γραμμές 16–30
const palette = {
  ink: '#1f1b1a', // text: a warm near-black
  lawn: '#1e6f6b', // glosses on words and jokes, the drop cap
  jam: '#b23a48', // glosses on history, the kicker
  muted: '#6e645b', // running heads, the note on this edition
  paper: '#f8f3e6', // the page, and the tablecloth
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const entry = (id, hex, name = id) => ({ id, name, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  // The engine's defaults link to 'main-color': aimed at the green, nothing prints blue.
  entry('main-color', palette.lawn, 'lawn (defaults)'),
];
```

Το πράσινο του γκαζόν σημαδεύει σχόλια για λέξεις, φράσεις και λογοπαίγνια, και το κόκκινο της μαρμελάδας πρόσωπα, ημερομηνίες και την ιστορία του κειμένου. Μια νέα τιμή για το `jam` στο ίδιο αντικείμενο `palette` ξαναχρωματίζει με μία αλλαγή τα σχόλια για την ιστορία, τα γράμματά τους και τον υπέρτιτλο· η υδατογραφία από πάνω τους διαλέχτηκε για το ίδιο πράσινο του γκαζόν και κόκκινο της μαρμελάδας.

## Η πλήρης συνταγή

Ένα αρχείο, συντεθειμένο από τον φάκελο της συνταγής με το δείγμα κειμένου και το κοινό κιτ του Συνταγολογίου ενσωματωμένα· φτιάχνει τη δική του σελίδα. Για να το εκτελέσετε, βάλτε το σε ένα `<script type="module">` σε μια κενή σελίδα, ή επικολλήστε το στο πάνελ JS ενός νέου CodePen (ως module). Εισάγει το postext από το esm.sh, οπότε δεν χρειάζεται εγκατάσταση ούτε build.

- Φάκελος πηγής: https://github.com/drnachio/postext/tree/main/cookbook/annotated-classic-glosses

### script.js

```js
// ═══ Postext Cookbook · Nº 032 · Annotated classic with margin glosses ════════════
// https://postext.dev/en/cookbook/annotated-classic-glosses
// Code: MIT · Text: Lewis Carroll (PD), glosses (CC BY 4.0) · Headpiece: diffusion models
// Fonts: Unna, Rozha One, Cormorant SC (SIL OFL 1.1) · Needs postext ≥ 1.28.0
// The mad tea-party as an annotated edition: the text keeps to one column, and its glosses stand
// in the outer margin beside the lines they explain, changing sides with the spread.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'annotated-classic-glosses';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a lawn green and a jam red on cream paper
const palette = {
  ink: '#1f1b1a', // text: a warm near-black
  lawn: '#1e6f6b', // glosses on words and jokes, the drop cap
  jam: '#b23a48', // glosses on history, the kicker
  muted: '#6e645b', // running heads, the note on this edition
  paper: '#f8f3e6', // the page, and the tablecloth
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const entry = (id, hex, name = id) => ({ id, name, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  // The engine's defaults link to 'main-color': aimed at the green, nothing prints blue.
  entry('main-color', palette.lawn, 'lawn (defaults)'),
];
// #endregion
const [TEXT, DISPLAY, LABEL] = ['Unna', 'Rozha One', 'Cormorant SC'];
const LEAD = 14; // body leading in pt: the grid of every page

// #region answer: a float-only channel at the fore-edge, and two gloss styles for it
const layout = {
  layoutType: 'oneAndHalf', // one text column and a narrower side column
  sideColumnPercent: 26, // of the 127 mm between the margins: a 33 mm channel
  sideColumnRole: 'floats', // no text runs in it: it holds side boxes and figures
  sideColumnSide: 'outer', // at the fore-edge, which mirrored margins move page by page
  gutterWidth: mm(4.5), // the text column keeps 127 − 33 − 4.5 = 89.5 mm
};
// A gloss is :::callout{type="note" span="side" title="a · …"} in the Markdown.
// span="side" moves it out of the flow into the channel, level with the block after
// the fence, so the fence goes just before the paragraph that carries its letter.
// Glosses never float. One that meets the gloss above stacks under it. One that would
// run past the column's foot slides up, as far as the gloss above allows, until its
// foot sits on the foot; if it still does not fit, it waits for the next page
// (gotcha: side-box-starts-at-fence).
const gloss = (id, hue) => ({ id,
  backgroundEnabled: false, // one device: a hairline over the gloss, in its colour
  stripe: { enabled: true, side: 'top', width: pt(0.5), color: col(hue) },
  padding: { top: mm(1.5), right: pt(0), bottom: pt(0), left: pt(0) },
  // Cormorant SC draws lower case as small capitals: the title needs no textTransform.
  titleStyle: { fontFamily: LABEL, fontWeight: 600, fontSize: pt(8.5),
    letterSpacing: pt(0.3), color: col(hue), gap: mm(0.8) },
  // Face and colours come from bodyText. A box body also inherits its 4 mm first-line
  // indent, which a gloss sets back to 0.
  body: { fontSize: pt(7.8), lineHeight: pt(10), textAlign: 'left',
    firstLineIndent: pt(0) } });
const calloutStyles = [gloss('note', 'lawn'), gloss('context', 'jam')]; // words, history
// #endregion

// #region letters: the letter that calls each gloss, in the gloss's colour
// A letter in the text is a chip named after its gloss's type, :chip[^a^]{style="note"}:
// the Markdown has no mark for coloured text, and a chip style sets a colour. With no
// fill, outline, padding or gap the chip adds no width, so the lines break as they would
// with a plain ^a^.
const letter = (id, hue) => ({ id, backgroundEnabled: false, borderWidth: pt(0),
  paddingX: pt(0), gap: pt(0), color: col(hue), bold: true });
const chipStyles = [letter('note', 'lawn'), letter('context', 'jam')];
// #endregion

// #region page: a trade page with mirrored margins, so the channel is always at the fore-edge
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [156, 234]; // mm
const [TOP, BOTTOM, INNER, OUTER] = [22, 22, 15, 14]; // mm: 38 lines of text
const page = { width: mm(TRIM_W), height: mm(TRIM_H), dpi: 150,
  backgroundColor: col('paper'),
  // left is a recto's inner margin; mirror swaps the sides on a verso, and 'outer' moves
  // the channel with them: right on a recto, left on a verso.
  margins: { top: mm(TOP), bottom: mm(BOTTOM), left: mm(INNER), right: mm(OUTER),
    mirror: true } };
const CONTENT_W = TRIM_W - INNER - OUTER; // 127 mm
const SIDE_W = CONTENT_W * layout.sideColumnPercent / 100; // 33 mm: the glosses' measure
const TEXT_W = CONTENT_W - SIDE_W - layout.gutterWidth.value;
// #endregion

// #region text: book texture, and a first paragraph set flush
const bodyText = { // justified and hyphenated (en-us) by default
  // Copy-fitted to the 89.5 mm column: at 9.5 pt '“Have some wine,” the March Hare said in
  // an encouraging tone.' fits one line. At 10.4 pt every measure from 77 to 93 mm left
  // it a short last line: 'couraging tone.', 'aging tone.', 'ing tone.' or 'tone.'.
  fontFamily: TEXT, fontSize: pt(9.5), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), firstLineIndent: mm(4),
  // The chapter's first paragraph is set flush, though the fences of glosses a and b stand
  // between the heading and it: a box that leaves the flow is not the block after a heading.
  indentAfterHeading: false,
  // Unna's space is narrow, 0.22 em. At the default 0.6 the line breaker set 'Alice felt
  // dreadfully puzzled. The Hatter’s remark seemed to have' with its spaces at 0.69.
  minWordSpacing: 0.75,
  // The dictionary divides the heroine's name, 'said Al-' | 'ice indignantly' on page 81.
  // The list keeps it whole wherever it stands; every other word is divided as before.
  hyphenation: { exceptions: ['Alice'] } };
// #endregion

// #region opener: a headpiece, the chapter's numeral and title, a headnote with a drop cap
const HEADPIECE = 72; // mm: the depth of the painting at the head of the page
const HEADNOTE = { size: 9.8, lead: LEAD }; // pt: the headnote keeps the body's leading
const CAPS = { text: 0.597, initial: 0.56 }; // cap heights, em: Unna and Rozha One
// The initial's size: its capital runs from the first line's cap height down to the
// last baseline it spans. At the default size it stops short of the first line's capitals.
const dropSize = (lines) => pt(((lines - 1) * HEADNOTE.lead + CAPS.text * HEADNOTE.size)
  / CAPS.initial);
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' },
  offset: { y: mm(y) }, size: { width } });
// The opener reserves the height of its lowest element, rounded up to the grid, and the
// heading's default bottom margin adds one blank line: with a four-line headnote the
// text starts on line 23. The kicker, the title and the headnote hang below the painting.
const opener = { enabled: true, slot: { elements: [
  // An image element draws a resource without number or caption. It hangs from the
  // trim's corner, over the top margin and both side margins.
  { kind: 'image', id: 'headpiece', resourceId: 'tea-table',
    placement: { anchor: { to: 'page', edge: 'top-left' },
      size: { width: mm(TRIM_W) } } },
  // The numeral comes from the heading line,
  // # A Mad Tea-Party {num="VII" headnote="…" …}: the excerpt stands alone, so
  // {chapterNumber} would count its one heading and print 1.
  { kind: 'text', id: 'kicker', content: 'Chapter {attr.num}', fontFamily: LABEL,
    fontWeight: 600, fontSize: pt(9), letterSpacing: pt(2), textTransform: 'uppercase',
    color: col('jam'), align: 'left',
    placement: { anchor: { to: 'container', edge: 'top-left' },
      offset: { y: mm(HEADPIECE - TOP + 8) } } }, // 8 mm under the painting's foot
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY,
    fontSize: pt(40), lineHeight: 1.05, color: col('ink'), align: 'left', // wraps when longer
    placement: below('kicker', 2, 'fill') },
  // The drop cap opens the headnote, the editor's voice, italic and ragged; Carroll's
  // text opens in the flow, justified.
  { kind: 'text', id: 'headnote', content: '{attr.headnote}', fontFamily: TEXT,
    italic: true, fontSize: pt(HEADNOTE.size),
    lineHeight: pt(HEADNOTE.lead), color: col('ink'),
    align: 'left',
    dropCap: { lines: 2, fontFamily: DISPLAY, fontSize: dropSize(2), color: col('lawn'),
      gap: mm(1.5) },
    placement: below('title', 5, mm(TEXT_W)) },
  // The note on this edition stands in the channel, level with the headnote's top.
  { kind: 'text', id: 'edition-label', content: 'This edition', fontFamily: LABEL,
    fontWeight: 600, fontSize: pt(8.5), letterSpacing: pt(0.3), color: col('muted'),
    align: 'left', placement: { anchor: { to: '#headnote', edge: 'right-of' },
      offset: { x: layout.gutterWidth }, size: { width: mm(SIDE_W) } } },
  { kind: 'text', id: 'edition', content: '{attr.source}', fontFamily: TEXT,
    fontSize: pt(7.5), lineHeight: pt(10), color: col('muted'), align: 'left',
    placement: { anchor: { to: '#edition-label', edge: 'below' }, offset: { y: mm(0.8) },
      size: { width: mm(SIDE_W) } } },
] } };
// #endregion

// The running heads: the book on the verso, the chapter on the recto, folios at the fore-edge.
const HEAD = 14; // mm from the top trim to the heads' baseline
const INSET = 8; // mm from the folio's outer edge to the running head's
const DROP = 13; // mm from the bottom trim up to the foot of the drop folio's box
// A design text's first baseline sits 0.96 em below the top of its box: the default
// lineHeight, 1.2, times 0.8, where the baseline falls in the line box.
const BASELINE = 1.2 * 0.8;
const baseline = (size) => mm(HEAD - BASELINE * size * PT);
const head = (id, parity, content, x, extra = {}) => ({ kind: 'text', id, parity, content,
  pages: 'body', fontFamily: LABEL, fontWeight: 600, fontSize: pt(8.5), letterSpacing: pt(1.2),
  textTransform: 'uppercase', color: col('muted'), ...extra,
  placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
    offset: { x: mm(x), y: baseline(extra.fontSize?.value ?? 8.5) } } });
const folio = { fontFamily: TEXT, fontWeight: 700, fontSize: pt(9), letterSpacing: pt(0),
  color: col('ink') };
const header = { elements: [
  head('verso-folio', 'even', '{pageNumber}', OUTER, folio),
  head('verso-title', 'even', '{title}', OUTER + INSET),
  head('recto-title', 'odd', '{chapterTitle}', -(OUTER + INSET)),
  head('recto-folio', 'odd', '{pageNumber}', -OUTER, folio),
] };
// The opener, a recto, carries a drop folio at the foot of its channel instead.
const footer = { elements: [{ ...head('drop-folio', 'odd', '{pageNumber}', -OUTER, folio),
  pages: 'opener', placement: { anchor: { to: 'page', edge: 'bottom-right' },
    offset: { x: mm(-OUTER), y: mm(-DROP) } } }] };

const config = () => ({
  locale: 'en-us', // the chapter is in English: its hyphenation patterns, and the bundle's language
  colorPalette, page, layout, bodyText, calloutStyles, chipStyles, header,
  footer,
  headings: {
    fontFamily: DISPLAY, fontWeight: 400, color: col('ink'), // Rozha One has one weight
    levels: [
      // 'odd' puts the opener on a recto; span 'page' lets its design cross the channel.
      { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' },
        advancedDesign: opener },
    ],
  },
});

// ─── 2 · Content ────────────────────────────────────────────────────────────
const markdown = String.raw`---
title: "Alice’s Adventures in Wonderland"
author: "Lewis Carroll"
---

# A Mad Tea-Party {num="VII" headnote="The tea-party is not in the book Carroll wrote out by hand for Alice Liddell in 1864; he added it, with the Cheshire Cat, for the book of 1865. Letters in the text point to the glosses beside it: green for words and jokes, red for history." source="Text after Project Gutenberg eBook 11; notes CC BY 4.0. Set in Unna, Rozha One and Cormorant SC (SIL OFL)."}

:::callout{type="note" span="side" title="a · The March Hare"}
‘Mad as a March hare’ is an old saying. Hares are shy, but in early spring they race about the fields and rear up on their hind legs to box.
:::

:::callout{type="context" span="side" title="b · The Hatter"}
‘Mad as a hatter’ was a saying before Carroll used it. Hatters made felt from fur treated with mercury, and the fumes gave many of them tremors and fits of shyness and temper. Carroll never calls him the Mad Hatter.
:::

There was a table set out under a tree in front of the house, and the March Hare:chip[^a^]{style="note"} and the Hatter:chip[^b^]{style="context"} were having tea at it: a Dormouse was sitting between them, fast asleep, and the other two were using it as a cushion, resting their elbows on it, and talking over its head. “Very uncomfortable for the Dormouse,” thought Alice; “only, as it’s asleep, I suppose it doesn’t mind.”

The table was a large one, but the three were all crowded together at one corner of it: “No room! No room!” they cried out when they saw Alice coming. “There’s *plenty* of room!” said Alice indignantly, and she sat down in a large arm-chair at one end of the table.

“Have some wine,” the March Hare said in an encouraging tone.

Alice looked all round the table, but there was nothing on it but tea. “I don’t see any wine,” she remarked.

“There isn’t any,” said the March Hare.

“Then it wasn’t very civil of you to offer it,” said Alice angrily.

“It wasn’t very civil of you to sit down without being invited,” said the March Hare.

“I didn’t know it was *your* table,” said Alice; “it’s laid for a great many more than three.”

:::callout{type="context" span="side" title="c · Hair"}
Tenniel drew Alice with long, loose hair. Alice Liddell, in Carroll’s photographs of her, wears hers short and dark, with a fringe.
:::

“Your hair wants cutting,”:chip[^c^]{style="context"} said the Hatter. He had been looking at Alice for some time with great curiosity, and this was his first speech.

“You should learn not to make personal remarks,” Alice said with some severity; “it’s very rude.”

:::callout{type="context" span="side" title="d · The riddle"}
Carroll made up the riddle without an answer. So many readers asked for one that in a preface of 1896 he offered this: ‘Because it can produce a few notes, tho they are very flat; and it is nevar put with the wrong end in front!’ Later printings changed *nevar*, raven spelt backwards, to *never*, and the joke was lost.
:::

The Hatter opened his eyes very wide on hearing this; but all he *said* was, “Why is a raven like a writing-desk?”:chip[^d^]{style="context"}

“Come, we shall have some fun now!” thought Alice. “I’m glad they’ve begun asking riddles.—I believe I can guess that,” she added aloud.

“Do you mean that you think you can find out the answer to it?” said the March Hare.

“Exactly so,” said Alice.

“Then you should say what you mean,” the March Hare went on.

“I do,” Alice hastily replied; “at least—at least I mean what I say—that’s the same thing, you know.”

:::callout{type="note" span="side" title="e · I see what I eat"}
The Hatter has the logic right. Turn a statement round and you get its converse, which can be false when the statement is true. Carroll, as Charles Dodgson, taught mathematics at Christ Church, Oxford, and wrote two books on logic.
:::

“Not the same thing a bit!” said the Hatter. “You might just as well say that ‘I see what I eat’ is the same thing as ‘I eat what I see’!”:chip[^e^]{style="note"}

“You might just as well say,” added the March Hare, “that ‘I like what I get’ is the same thing as ‘I get what I like’!”

“You might just as well say,” added the Dormouse, who seemed to be talking in his sleep, “that ‘I breathe when I sleep’ is the same thing as ‘I sleep when I breathe’!”

“It *is* the same thing with you,” said the Hatter, and here the conversation dropped, and the party sat silent for a minute, while Alice thought over all she could remember about ravens and writing-desks, which wasn’t much.

The Hatter was the first to break the silence. “What day of the month is it?” he said, turning to Alice: he had taken his watch out of his pocket, and was looking at it uneasily, shaking it every now and then, and holding it to his ear.

:::callout{type="context" span="side" title="f · The fourth"}
Of May: Alice Liddell was born on 4 May 1852.
:::

Alice considered a little, and then said “The fourth.”:chip[^f^]{style="context"}

“Two days wrong!” sighed the Hatter. “I told you butter wouldn’t suit the works!” he added looking angrily at the March Hare.

:::callout{type="note" span="side" title="g · The best butter"}
Grocers sold butter by grade, and ‘best’ fetched the highest price. The March Hare defends its quality, which was never the trouble.
:::

“It was the *best* butter,”:chip[^g^]{style="note"} the March Hare meekly replied.

“Yes, but some crumbs must have got in as well,” the Hatter grumbled: “you shouldn’t have put it in with the bread-knife.”

The March Hare took the watch and looked at it gloomily: then he dipped it into his cup of tea, and looked at it again: but he could think of nothing better to say than his first remark, “It was the *best* butter, you know.”

Alice had been looking over his shoulder with some curiosity. “What a funny watch!” she remarked. “It tells the day of the month, and doesn’t tell what o’clock it is!”

“Why should it?” muttered the Hatter. “Does *your* watch tell you what year it is?”

“Of course not,” Alice replied very readily: “but that’s because it stays the same year for such a long time together.”

“Which is just the case with *mine*,” said the Hatter.

Alice felt dreadfully puzzled. The Hatter’s remark seemed to have no sort of meaning in it, and yet it was certainly English. “I don’t quite understand you,” she said, as politely as she could.

“The Dormouse is asleep again,” said the Hatter, and he poured a little hot tea upon its nose.

:::callout{type="note" span="side" title="h · The Dormouse"}
Hazel dormice sleep through the day and hibernate for half the year, from autumn to spring. The name is often traced to the French *dormir*, to sleep.
:::

The Dormouse:chip[^h^]{style="note"} shook its head impatiently, and said, without opening its eyes, “Of course, of course; just what I was going to remark myself.”

“Have you guessed the riddle yet?” the Hatter said, turning to Alice again.

“No, I give it up,” Alice replied: “what’s the answer?”

“I haven’t the slightest idea,” said the Hatter.

“Nor I,” said the March Hare.

Alice sighed wearily. “I think you might do something better with the time,” she said, “than waste it in asking riddles that have no answers.”

“If you knew Time as well as I do,” said the Hatter, “you wouldn’t talk about wasting *it*. It’s *him*.”

“I don’t know what you mean,” said Alice.

“Of course you don’t!” the Hatter said, tossing his head contemptuously. “I dare say you never even spoke to Time!”
`; // content.<lang>.md, inlined by the Cookbook


// The headpiece is a resource that only the opener's design draws: never cited, never placed.
// It is a watercolour, a JPEG in assets/ cut to the trim's 156 × 72 mm, declared at its pixels.
const resources = [{ id: 'tea-table', typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
  bitmap: { fileId: 'tea-table-1560.jpg', format: 'jpeg', width: 1560, height: 720 },
  altText: 'The tea-table under a tree, seen from above: a long white cloth laid with cups, a red '
    + 'teapot, bread and butter and a watch on its chain; the Dormouse asleep in a teapot at one '
    + 'end and a red arm-chair at the other.' }];

// ─── 3 · Fonts ──────────────────────────────────────────────────────────────
const FONTS = { // text, display and label faces, loaded before the build
  Unna: ['400', '400i', '700'], // 700: the folios and the gloss letters
  'Rozha One': ['400'],
  'Cormorant SC': ['600'],
};

// ─── 4 · Build & show ───────────────────────────────────────────────────────
await loadImage('tea-table-1560.jpg', asset('tea-table-1560.jpg'));
const continuation = { pageNumbering: { startAt: 81 } }; // chapter VII of a book: an odd folio
const doc = await buildDocumentWithFonts({ markdown, resources, continuation }, config(),
  kitFonts(FONTS));
showPages(doc, { title: 'Annotated classic with margin glosses' });

// ─── Kit ── helpers shared by every Cookbook recipe · postext.dev/cookbook ─────

// ─── Kit · core v1 ── the same in every recipe · postext.dev/cookbook
function mm(value) { return { value, unit: 'mm' }; }
function pt(value) { return { value, unit: 'pt' }; }
function em(value) { return { value, unit: 'em' }; }
/** The sample language's string: t({ en: 'Figure', es: 'Figura' }). */
function t(strings) { return strings[LANG] ?? Object.values(strings)[0]; }
/** A file in this recipe's assets folder, served from the Postext repo by jsDelivr. */
function asset(file) { return `https://cdn.jsdelivr.net/gh/drnachio/postext@main/cookbook/${RECIPE}/assets/${file}`; }

// ─── Kit · fonts v3 ── the same in every recipe · postext.dev/cookbook
// Postext loads the faces a config asks for before layout and asks the kit
// for Fontsource's files, the ones the PDF embeds too.

/** buildDocumentWithFonts' options: the resolver, and FONTS' faces loaded
 *  with the config's. FONTS = { 'Family Name': ['400', '400i', '700'] }. */
function kitFonts(FONTS = {}) {
  const faces = Object.entries(FONTS).flatMap(([family, specs]) => specs.map((spec) =>
    ({ family, weight: parseInt(spec, 10), style: spec.endsWith('i') ? 'italic' : 'normal' })));
  return { resolve: fontsourceResolver, faces };
}

/** A face's files with their ranges: latin, then latin-ext and greek when
 *  `text` needs them (kitSubsetsFor). Null for a face Fontsource lacks. */
async function fontsourceResolver(family, weight, style, { text = '' } = {}) {
  const id = fontsourceId(family);
  const meta = await fontsourceMeta(family);
  if (meta && !(await fontsourceWeights(family, style)).includes(weight)) return null;
  kitStatus('Loading fonts…');
  const at = await fontsourceAt(id);
  return ['latin', ...kitSubsetsFor(text, meta)].map((subset) => ({
    source: `${at}files/${id}-${subset}-${weight}-${style}.woff2`,
    unicodeRange: kitRanges()[subset],
  }));
}

/** Each file's unicode-range (a function: the kit runs after the pen's code). */
function kitRanges() {
  return {
    latin: 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,'
      + 'U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD',
    'latin-ext': 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,'
      + 'U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF',
    greek: 'U+0370-03FF',
  };
}

/** For the cjk, arabic and comics blocks: loads `faces` (as FONTS) for the
 *  sample `text`; `optional` skips a face Fontsource lacks. Files are added in
 *  the order asked, the last winning a shared character. Resolves to the count. */
async function loadFonts(faces, text = '', { optional = false } = {}) {
  kitStatus('Loading fonts…');
  const ranges = kitRanges();
  const jobs = [];
  for (const [family, specs] of Object.entries(faces)) {
    const id = fontsourceId(family);
    const todo = [...new Set(specs)].map((spec) => [parseInt(spec, 10), spec.endsWith('i') ? 'italic' : 'normal'])
      .filter(([weight, style]) => !hasFace(family, weight, style)); // before any await
    const at = fontsourceAt(id);
    const meta = optional || /[^\0-ÿ]/u.test(text) ? await fontsourceMeta(family) : null;
    const subsets = ['latin', ...kitSubsetsFor(text, meta)];
    for (const [weight, style] of todo) {
      if (optional && !(meta && (await fontsourceWeights(family, style)).includes(weight))) continue;
      for (const subset of subsets) {
        const url = `${await at}files/${id}-${subset}-${weight}-${style}.woff2`;
        const face = new FontFace(family, `url(${url}) format('woff2')`,
          { weight: String(weight), style, unicodeRange: ranges[subset] });
        jobs.push(face.load().catch(() => {
          if (subset === 'latin' && !optional) throw new Error(`Fontsource has no ${family} ${weight} ${style}`);
        }));
      }
    }
  }
  const ready = await Promise.all(jobs).catch((error) => { kitFail(error); throw error; });
  return ready.filter((face) => face && document.fonts.add(face)).length;
}

/** A loaded FontFace covers this face (fonts.check() says yes to any family). */
function hasFace(family, weight, style) {
  for (const face of document.fonts) {
    if (face.status !== 'loaded' || face.style !== style) continue;
    if (face.family.replace(/^["']|["']$/g, '') !== family) continue;
    const [low, high = low] = face.weight.split(' ').map(Number);
    if (weight >= low && weight <= high) return true;
  }
  return false;
}

/** The files beyond latin `text` needs that `meta`'s family ships. */
function kitSubsetsFor(text, meta) {
  return [[/[Ā-˿ᴀ-ᶿḀ-ỿ†ℓⱠ-Ɀ꜠-ꟿ]/u, 'latin-ext'], [/[Ͱ-Ͽ]/u, 'greek']]
    .filter(([re, x]) => re.test(text) && meta?.subsets?.includes(x)).map(([, x]) => x);
}

/** Fontsource's id for a family: 'Source Serif 4' → 'source-serif-4'. */
function fontsourceId(family) { return family.toLowerCase().replace(/\s+/g, '-'); }

/** A package's folder at the one version @5 names now (#766). */
function fontsourceAt(id, u = `https://cdn.jsdelivr.net/npm/@fontsource/${id}@`) {
  return (fontsourceAt.c ??= {})[id] ??= fetch(u + '5/package.json').then((r) => r.json())
    .then((p) => p.version || 5, () => 5).then((v) => `${u}${v}/`);
}

/** The family's Fontsource metadata (weights, styles, subsets), or null. */
function fontsourceMeta(family, id = fontsourceId(family)) {
  return (fontsourceMeta.c ??= {})[id] ??= fetch(`https://api.fontsource.org/v1/fonts/${id}`)
    .then((res) => (res.ok ? res.json() : null), () => null);
}

/** The weights the package ships in `style`: the API pairs none (no Libre
 *  Caslon 700 italic file), so italics are read from latin-italic.css. */
function fontsourceWeights(family, style, id = fontsourceId(family)) {
  return (fontsourceWeights.c ??= {})[id + style] ??= fontsourceMeta(family).then(async (m) => {
    if (!m?.styles.includes(style)) return m ? [] : [400, 700];
    const css = style === 'italic' ? await fetch(`${await fontsourceAt(id)}latin-italic.css`).then((r) => (r.ok ? r.text() : ''), () => '') : '';
    const w = [...css.matchAll(/weight: (\d+)/g)].map((x) => +x[1]);
    return w.length ? w : m.weights;
  });
}

// ─── Kit · viewer v2 ── the same in every recipe · postext.dev/cookbook
/** The pages as spreads on a dark desk, page 1 alone, then verso | recto,
 *  each painted when it scrolls near. Other options go to renderPageToCanvas. */
function showPages(docs, { title, width = 460, ...render } = {}) {
  const root = viewer(title);
  const pages = [docs].flat().flatMap((doc) =>
    doc.pages.map((page) => ({ doc, page, n: (doc.pageIndexOffset ?? 0) + page.index })));
  const spreads = [];
  let verso = null;
  for (const p of pages) {
    if (p.n % 2 === 1) { if (verso) spreads.push([verso, null]); verso = p; }
    else { spreads.push([verso, p]); verso = null; }
  }
  if (verso) spreads.push([verso, null]);
  const density = Math.min(window.devicePixelRatio || 1, 2);
  showPages.painter?.disconnect();
  const painter = new IntersectionObserver((entries) => {
    for (const { isIntersecting, target } of entries) {
      if (!isIntersecting) continue;
      painter.unobserve(target);
      const { doc, page } = target.postext;
      renderPageToCanvas(page, doc, target, { ...render, scale: (width * density) / page.width });
    }
  }, { rootMargin: '800px' });
  showPages.painter = painter;
  root.replaceChildren(...spreads.map((pair) => {
    const spread = document.createElement('div');
    spread.className = 'pt-spread';
    for (const p of pair) {
      const figure = document.createElement('figure');
      if (p) {
        const label = p.page.pageLabel || String(p.n + 1);
        const canvas = document.createElement('canvas');
        canvas.postext = p;
        canvas.style.aspectRatio = `${p.page.width} / ${p.page.height}`;
        canvas.setAttribute('role', 'img');
        canvas.setAttribute('aria-label', `Page ${label}`);
        const folio = document.createElement('figcaption');
        folio.textContent = label;
        figure.append(canvas, folio);
        painter.observe(canvas);
      } else figure.className = 'pt-blank';
      spread.append(figure);
    }
    return spread;
  }));
  kitStatus(`${pages.length} ${pages.length === 1 ? 'page' : 'pages'}`);
  document.documentElement.dataset.postext = 'ready';
  return pages.length;
}

/** The desk, the bar and the error reporting, created once. */
function viewer(title) {
  if (!document.getElementById('pt-kit')) {
    document.head.insertAdjacentHTML('beforeend', `<style id="pt-kit">
      :root { color-scheme: dark; }
      body { margin: 0; background: #0e1014; color: #b9bcc4; font: 13px/1.45 system-ui, sans-serif; }
      #pt-bar { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center;
        gap: 6px 16px; padding: 10px 16px; background: rgb(14 16 20 / .92); backdrop-filter: blur(6px);
        border-bottom: 1px solid #23262d; }
      #pt-bar strong { color: #f4f1ea; font-weight: 600; }
      #pt-actions { display: flex; gap: 12px; margin-left: auto; }
      #pt-actions a, #pt-actions button { color: #d8a21a; font: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
      #pages { display: grid; justify-items: center; gap: 48px; padding: 32px 16px 72px; }
      .pt-spread { display: flex; }
      .pt-spread figure { margin: 0; width: min(460px, 44vw); }
      .pt-spread canvas { display: block; width: 100%; background: #fff;
        box-shadow: 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figure:first-child canvas { box-shadow: inset -14px 0 14px -14px rgb(0 0 0 / .18), 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figcaption { margin-top: 10px; text-align: center; font: 600 10px/1 system-ui, sans-serif;
        letter-spacing: .18em; text-transform: uppercase; color: #6c7079; }
      .pt-blank { visibility: hidden; }
      @media (max-width: 760px) {
        .pt-spread { flex-direction: column; gap: 32px; }
        .pt-spread figure { width: min(460px, 92vw); }
        .pt-blank { display: none; }
      }
    </style>`);
    document.body.insertAdjacentHTML('afterbegin',
      '<header id="pt-bar"><strong id="pt-title"></strong><span id="pt-status" role="status"></span><span id="pt-actions"></span></header>');
    document.getElementById('pt-title').textContent = document.title || 'Postext';
    addEventListener('error', (event) => kitFail(event.error ?? event.message));
    addEventListener('unhandledrejection', (event) => kitFail(event.reason));
  }
  if (title) document.getElementById('pt-title').textContent = title;
  return document.getElementById('pages')
    ?? document.body.appendChild(Object.assign(document.createElement('main'), { id: 'pages' }));
}

function kitStatus(text) {
  viewer();
  document.getElementById('pt-status').textContent = text;
}

function kitFail(error) {
  document.documentElement.dataset.postext = 'error';
  kitStatus(`Error: ${error?.message ?? error}`);
}

// ─── Kit · images v3 ── recipes with pictures · postext.dev/cookbook
/** Registers a photo or PNG for the canvas and keeps its bytes for the PDF.
 *  fetch → ImageBitmap never taints the canvas (a plain cross-origin <img> would). */
async function loadImage(fileId, url) {
  const res = await fetch(url);
  if (!res.ok) throw new Error(`Image not found (${res.status}): ${url}`);
  const bytes = new Uint8Array(await res.arrayBuffer());
  registerResourceImage(fileId, await createImageBitmap(new Blob([bytes])));
  (loadImage.bytes ??= new Map()).set(fileId, bytes);
}

/** Registers SVG markup as a vector image, its fonts inside (inlineSvgFonts, ≥ 1.25).
 *  `options` go to registerResourceImage: { singleInk: true } tints it on the canvas. */
async function loadSvg(fileId, svg, options) {
  if (typeof inlineSvgFonts === 'function') svg = await inlineSvgFonts(svg, svgFaces);
  const img = new Image();
  img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
  await img.decode();
  registerResourceImage(fileId, img, options);
  (loadImage.bytes ??= new Map()).set(fileId, new TextEncoder().encode(svg));
}

/** A face's Fontsource files: nearest weight; latin + what the SVG sets. */
async function svgFaces(family, weight, style, { codePoints = [] } = {}) {
  const [id, m] = [fontsourceId(family), await fontsourceMeta(family)];
  const w = m?.weights.reduce((a, b) => (Math.abs(b - weight) < Math.abs(a - weight) ? b : a)) ?? weight;
  const s = m?.styles.includes(style) === false ? 'normal' : style;
  return Promise.all(['latin', ...kitSubsetsFor(String.fromCodePoint(...codePoints), m)].map(async (x) => new Uint8Array(
    await (await fetch(`${await fontsourceAt(id)}files/${id}-${x}-${w}-${s}.woff2`)).arrayBuffer())));
}

/** renderToPdf({ resourceBytes: imageBytes }) */
function imageBytes(fileId) { return loadImage.bytes?.get(fileId); }

/** renderToHtml({ resourceImageUrl: imageUrl }) */
function imageUrl(fileId) {
  const bytes = imageBytes(fileId);
  if (!bytes) return undefined;
  imageUrl.urls ??= new Map();
  if (!imageUrl.urls.has(fileId)) {
    const type = /\.svg$/i.test(fileId) ? 'image/svg+xml' : /\.png$/i.test(fileId) ? 'image/png' : 'image/jpeg';
    imageUrl.urls.set(fileId, URL.createObjectURL(new Blob([bytes], { type })));
  }
  return imageUrl.urls.get(fileId);
}

// ─── /Kit ───────────────────────────────────────────────────────────────────────
```

## Παραλλαγές

### Κρατήστε τα σχόλια στα δεξιά κάθε σελίδας

Για μια έκδοση που διαβάζεται μία σελίδα τη φορά στην οθόνη, απενεργοποιήστε τον αντικατοπτρισμό: το `'outer'` σημαίνει τότε τη δεξιά άκρη κάθε σελίδας, και οι τρέχουσες κεφαλίδες κρατούν τις θέσεις τους, αφού είναι αγκυρωμένες στην άκρη κοπής.

```diff
-    mirror: true } };
+    mirror: false } };
```

### Στείλτε τις μακριές σημειώσεις στο πόδι της σελίδας

Γράψτε μια σημείωση πολύ μακριά για το περιθώριο ως υποσημείωση, `[^1]` στο κείμενο και τον ορισμό της `[^1]:` κάτω από την παράγραφο: το Postext τη στοιχειοθετεί στο πόδι της στήλης του κειμένου, με πλάτος 89,5 mm κάτω από μια κοντή γραμμή, και τα σχόλια κρατούν το κανάλι. Η συνταγή [Υποσημειώσεις στο κάτω μέρος της στήλης που τις αναφέρει](https://postext.dev/el/cookbook/novel-footnotes-column-foot.md) δίνει στιλ σε αυτές τις σημειώσεις.

## Συνήθη λάθη

- **Ένα πλευρικό πλαίσιο αρχίζει στο ύψος του μπλοκ μετά το fence του.** Στο postext 1.4.1 ένα πλαίσιο span: 'side' στέκεται στην πλευρική στήλη στο ύψος που έχει φτάσει το κείμενο στο fence του, στην επόμενη γραμμή πλέγματος, και κάτω από όποιο πλαίσιο βρίσκεται ήδη εκεί. Βάλτε το fence ενός σχολίου ακριβώς πριν από την παράγραφο που εξηγεί: αν μπει μετά, το σχόλιο αρχίζει δίπλα στην επόμενη παράγραφο. Ένα πλαίσιο που θα ξεπερνούσε τη βάση της στήλης γλιστρά προς τα πάνω ώσπου η βάση του να κάθεται στη βάση της στήλης, όσο επιτρέπει το πλαίσιο από πάνω του· ένα που και πάλι δεν χωρά περιμένει την πλευρική στήλη της επόμενης σελίδας.

- Τα σχόλια στοιβάζονται με τη σειρά του Markdown, το ένα κάτω από το άλλο, οπότε ένα μακρύ σχόλιο σπρώχνει το επόμενο προς τα κάτω. Στη [σελίδα 81](https://postext.dev/cookbook/annotated-classic-glosses/en/p01.webp?v=e49bbaba) και τα δύο γράμματα πέφτουν στη δεύτερη γραμμή της πρώτης παραγράφου: το σχόλιο a αρχίζει στο ύψος της παραγράφου και το σχόλιο b κάτω από αυτό, πέντε γραμμές κάτω από το γράμμα του. Όπου τα γράμματα έρχονται κοντά το ένα στο άλλο, κρατήστε τα σχόλια σύντομα.

## Ευχαριστίες

- Συνταγή: Ignacio Ferro ([@drnachio](https://github.com/drnachio))
- Κείμενο: Alice’s Adventures in Wonderland (1865), the opening of chapter VII, “A Mad Tea-Party”: Lewis Carroll ([πηγή](https://www.gutenberg.org/ebooks/11)), κοινό κτήμα
- Κείμενο: The headnote, the eight glosses and the note on this edition: Ignacio Ferro, CC-BY-4.0
- Εικόνες: The tea-table seen from above, a watercolour: Generated With Diffusion Models, πρωτότυπο
- Γραμματοσειρές: Unna (OFL-1.1), Rozha One (OFL-1.1), Cormorant SC (OFL-1.1)
- Κώδικας: MIT · Δείγμα περιεχομένου: CC-BY-4.0

## Σχετικές συνταγές

- [Αρ. 044 · Κριτική έκδοση: αριθμοί στίχων και σημειώσεις ανά στίχο](https://postext.dev/el/cookbook/critical-edition-line-numbers.md): Το Lycidas του Μίλτον του 1645: το lineNumbers αριθμεί κάθε πέμπτο στίχο στην πλευρική στήλη, και κάθε σημείωση ανοίγει με τον στίχο της σε ετικέτα. · Επίπεδο 3 (Προχωρημένο) · Ποίηση
- [Αρ. 001 · Σχολικό βιβλίο με στήλη στο περιθώριο](https://postext.dev/el/cookbook/textbook-margin-column.md): Σελίδα μιάμισης στήλης, με την εξωτερική μόνο για κινητά: εκεί μπαίνουν εικόνες και σημειώσεις span 'side', και το captionSide βάζει εκεί τις άλλες λεζάντες. · Επίπεδο 3 (Προχωρημένο) · Σχολικά βιβλία
- [Αρ. 020 · Σημειώσεις τέλους σε δική τους σελίδα, σε δύο στήλες](https://postext.dev/el/cookbook/endnotes-instead-of-footnotes.md): Ένας μικρός προεπεξεργαστής αριθμεί τις σημειώσεις [^1] και τις μαζεύει κάτω από μια επικεφαλίδα Notes, που τις βάζει σε δική τους σελίδα, σε δύο στήλες. · Επίπεδο 2 (Μεσαίο) · Επιστημονικά άρθρα και ακαδημαϊκά κείμενα
