Vai al contenuto principale
Ricetta numero 47

Ricettario · Capitolo 4 · Testatine e folio

Guida a piedi con unghiature

Una guida tascabile con uno stile di titolo per passeggiata, la cui tavolozza ricolora unghiatura, numeri delle tappe, fondo del riquadro e il verso bianco.

pp. 6–7 di 7

  • Esempio in inglese: non c’è ancora un’edizione italiana
  • Formato 120 × 200 mm
  • 1 colonna
  • Albert Sans 9,4/13,2
  • Asap Condensed
  • DM Serif Display
  • 7 pagine
  • Livello
  • Postext 1.57.1
  • Impaginato in 56 ms
  • 245 righe di codice

In breve

Una guida tascabile alle passeggiate intorno a Lisbona. Ogni passeggiata ha un suo colore, mostrato in un’unghiatura sul bordo della pagina, così la trovi con il pollice.

Che cosa comporrai

Le prime sette pagine di Lisbon on Foot, una guida tascabile di 120 × 200 mm. La copertina è un muro di azulejos bianchi e blu con il titolo su un riquadro incorniciato come una targa stradale di Lisbona, e pagina 2 presenta le tre passeggiate con una mappa dei loro percorsi. Ogni passeggiata ha un colore, terracotta per l’Alfama e giallo per la Baixa, e un’unghiatura sul margine esterno mostra quel colore e il numero della passeggiata alla stessa altezza su ogni sua pagina. La fascia dell’apertura, le tappe numerate, la testatina del recto e il fondo del riquadro «Don’t miss» cambiano con essa. Il verso bianco che manda la passeggiata 2 su un recto è dipinto nel giallo della passeggiata 2 e ne stampa il numero. Il testo è in Albert Sans, in bandiera; i nomi sono in DM Serif Display e le etichette in Asap Condensed.

Questa ricetta risponde a

  • Come nascondo le testatine nelle aperture e nelle pagine bianche, o coloro un verso bianco con il colore della parte?
  • Come imposto le testatine: titolo del libro sulla pagina sinistra, titolo del capitolo sulla destra, numero di pagina all’esterno?
  • Come aggiungo una linguetta numerata («BOX 1-1»), un’icona d’angolo o un’icona a margine con un filetto?
  • Come aggiungo campioni di colore come legenda nel testo, nelle didascalie o nelle note di tabella?

La risposta breve

script.js · righe 60–81nel codice completo
// '# Alfama {style="alfama"}' opens a section that runs to the next level-1 heading. Its
// palette gives band, bandInk, onBand and wash the walk's values on the section's pages,
// in the page furniture and in the text alike.
const walkStyles = Object.keys(WALKS).map((id) => ({ id, palette: WALKS[id] }));
// The tab has one size and one place on every page, hanging from the foot of the opener
// band; only its colour and its number change from walk to walk.
const TAB = { y: BAND, width: 7, height: 24 }; // mm
const tab = (parity, edge) => text(`tab-${parity}`, '{chapterNumber}', {
  ...label, fontSize: pt(11), fontWeight: 700, color: col('onBand'), align: 'center',
  verticalAlign: 'middle', overflow: 'clip', box: { backgroundColor: col('band') },
  parity, pages: 'all', // the walk's first page is an 'opener' page: the tab goes there too
}, { ...at('bleed', edge, 0, TAB.y), ...size(mm(TAB.width), mm(TAB.height)) });
const tabs = [tab('odd', 'top-right'), tab('even', 'top-left')]; // on the fore-edge
// The blank verso that pushes a walk onto a recto belongs to that walk (gotcha:
// section-last-wins), so the field takes the next walk's colour and its numeral the number.
const blankPage = [
  box('field', { backgroundColor: col('band') },
    { ...at('bleed', 'top-left', 0, 0), ...size('fill', 'fill') }),
  tileImage('field-tiles', 'tiles-page', 'top-left', 'fill', 'auto'),
  text('field-number', '{chapterNumber}', { ...display, fontSize: pt(220), lineHeight: 1,
    color: col('onBand'), overflow: 'clip' }, at('page', 'bottom-left', MARGIN.outer, -24)),
].map((el) => ({ ...el, pages: 'blank' }));

Ingredienti

Tipo
Albert Sans, DM Serif Display, Asap Condensed (SIL OFL 1.1)
Risorse
  • The tiles, the map of the routes and its pins, drawn in code (Ignacio Ferro, CC BY 4.0)

Preparazione

#1 · Nomina i colori che una passeggiata cambia

script.js · righe 16–40nel codice completo
const palette = {
  ink: '#1b2430', // text: a blue-black
  paper: '#fffdf8', // the page
  band: '#1f4e9c', // the section colour: tile blue until a walk replaces it
  bandInk: '#1d4a94', // the section colour for type on paper
  onBand: '#ffffff', // type set on the band
  wash: '#e8eef8', // the section's box tint
  muted: '#5e6875', // running heads, notes, chip outlines
};
// Each walk's values for those four. Baixa yellow is too light for white type, so its
// onBand is the ink. The text is recoloured by value, so the four base values must differ.
const WALKS = {
  alfama: { band: '#b9533a', bandInk: '#a1432b', onBand: '#ffffff', wash: '#f7e7e0' },
  baixa: { band: '#e2b23d', bandInk: '#7d5a0f', onBand: '#1b2430', wash: '#fbf0d5' },
  belem: { band: '#2b7a78', bandInk: '#236866', onBand: '#ffffff', wash: '#e1eeed' },
};
const NAMES = { alfama: 'Alfama', baixa: 'Baixa', belem: 'Belém' };
// A walk's palette follows the paletteId; the hex beside it is the colour's base value.
const col = (id) => ({ hex: palette[id] ?? WALKS[id].band, model: 'hex', paletteId: id });
const entry = (id, hex) => ({ id, name: id, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  ...Object.entries(WALKS).map(([id, w]) => entry(id, w.band)), // for :swatch{color="alfama"}
  entry('main-color', palette.ink), // the engine's defaults link here: nothing prints blue
];

La palette di uno stile di titolo sostituisce le voci per id sulle pagine della sua sezione (stili di titolo), quindi ogni colore che deve seguire la passeggiata è collegato a una di quattro voci: band per i campi, l’unghiatura e i cerchi delle tappe, bandInk per il testo sulla carta, onBand per il testo su un campo e wash per il riquadro. Il bianco sul giallo della Baixa misura 2:1, quindi l’onBand di quella passeggiata è il nero, a 8:1. Gli elementi grafici seguono l’id, mentre il testo si ricolora per valore: un colore uguale all’esadecimale di base di una voce prende il valore della passeggiata, ed è per questo che i quattro valori di base sono tutti diversi. Il titolo del riquadro a pagina 4 e la riga che rimanda alla passeggiata 2 a pagina 5 sono testo in bandInk, ed entrambi si stampano in terracotta.

#2 · Tieni le testatine sulle pagine di testo

script.js · righe 85–107nel codice completo
const head = (id, content, parity, placement, style = {}) => ({ ...text(id, content, {
  ...label, fontSize: pt(7.8), letterSpacing: pt(1.3), color: col('muted'), overflow: 'clip',
  ...style }, placement), parity, pages: 'body' }); // never on openers or blank pages
const folio = { fontSize: pt(8.5), fontWeight: 700, color: col('ink') };
// Anchored to the page: from its top-right corner a negative x runs inwards
// (gotcha: negative-offsets).
const heads = [
  head('verso-folio', '{pageNumber}', 'even', at('page', 'top-left', MARGIN.outer, HEAD.y), folio),
  head('verso-title', '{title}', 'even', at('page', 'top-left', MARGIN.outer + HEAD.gap, HEAD.y)),
  head('recto-title', `${t({ en: 'Walk', es: 'Paseo' })} {chapterNumber} · {chapterTitle}`, 'odd',
    at('page', 'top-right', -(MARGIN.outer + HEAD.gap), HEAD.y), { color: col('bandInk') }),
  head('recto-folio', '{pageNumber}', 'odd', at('page', 'top-right', -MARGIN.outer, HEAD.y), folio),
];
// Array order is paint order: the blank page's field comes last and covers the tab there.
const header = { elements: [...heads, ...tabs, ...blankPage] };
// A walk's first page has no running head: its folio drops to the foot.
const footer = { elements: [{ ...head('drop-folio', '{pageNumber}', 'all',
  at('container', 'top', 0, 7), folio), pages: 'opener', align: 'center' }] };
// Page 2 comes before Walk 1, where {chapterNumber} is empty, so its header has no tabs. With
// the level's break off (gotcha: style-inherits-break), it is a 'body' page.
const introStyle = { id: 'intro', numbered: false, header: { elements: heads },
  breakBefore: { enabled: false }, advancedDesign: { enabled: false },
  fontSize: pt(24), lineHeight: pt(2 * LEAD), marginBottom: pt(LEAD / 2) };

Dopo l’impaginazione ogni pagina riceve un ruolo (elementi di testo). La prima pagina di una passeggiata è un’opener, perché il suo titolo interrompe la pagina; la pagina di riempimento prima di un recto è blank; le altre sono body. Le testatine prendono pages: 'body', quindi le aperture alle pagine 3 e 7 e la pagina bianca 6 non ne hanno, e il numero di pagina al piede prende 'opener'. Il verso stampa il {title} del front matter, il recto Walk {chapterNumber} · {chapterTitle} in bandInk, terracotta a pagina 5. Le unghiature della risposta breve prendono 'all'. Il campo della pagina bianca viene dopo di esse nell’array, e poiché l’ordine dell’array è l’ordine di disegno copre l’unghiatura a pagina 6. Pagina 2, l’introduzione, viene prima della passeggiata 1, quindi lì {chapterNumber} è vuoto, e il suo stile ha un header tutto suo con le quattro testatine e nessuna unghiatura. Senza, pagina 2 stamperebbe un’unghiatura blu vuota.

#3 · Apri ogni passeggiata sotto la sua fascia, e numera le tappe

script.js · righe 111–138nel codice completo
const walkLevel = { level: 1, breakBefore: { enabled: true, parity: 'odd' }, // a recto
  // The band ends 30 mm into the text area; a floor of 8 grid lines, with nothing added
  // under it, starts the text 7.3 mm below the band.
  marginBottom: pt(0), advancedDesign: { enabled: true, minHeight: pt(8 * LEAD), slot: {
    elements: [
      box('band', { backgroundColor: col('band') },
        { ...at('bleed', 'top-left', 0, 0), ...size('fill', mm(BAND)) }),
      tileImage('tiles', 'tiles-band', 'top-right', 'auto', mm(BAND)),
      text('kicker', `${t({ en: 'Walk', es: 'Paseo' })} {chapterNumber}`, { ...label,
        fontSize: pt(9), letterSpacing: pt(2), color: col('onBand') },
      at('page', 'top-left', MARGIN.inner, 17)), // walks open on rectos: inner is left
      text('title', '{titleText}', { ...display, fontSize: pt(34), lineHeight: 1,
        color: col('onBand') }, { ...at('#kicker', 'below', 0, 1), ...size(mm(70), 'auto') }),
      text('route', '{attr.route}', { fontFamily: 'Albert Sans', italic: true, fontSize: pt(10),
        color: col('onBand') }, { ...at('#title', 'below', 0, 1.5), ...size(mm(70), 'auto') }),
    ] } } };
const STOP = 5.4; // mm: the diameter of a stop's circle
const stopLevel = { level: 3, numberingTemplate: '{3}', // restarts at every walk
  // A grid line above a stop and no margin under it, so the circle can sit 3.2 mm down its
  // two grid lines: about 8.3 mm of white above a stop and 2.1 under it, 6.4 between paragraphs.
  marginTop: pt(LEAD), marginBottom: pt(0), advancedDesign: { enabled: true, slot: { elements: [
    text('number', '{number}', { ...label, fontSize: pt(9), fontWeight: 700, align: 'center',
      verticalAlign: 'middle', color: col('onBand'), overflow: 'clip',
      box: { backgroundColor: col('band'), borderRadius: mm(STOP / 2) } },
    { ...at('container', 'top-left', 0, 3.2), ...size(mm(STOP), mm(STOP)) }),
    text('name', '{titleText}', { ...display, fontSize: pt(13.5), lineHeight: 1.1,
      color: col('ink') }, { ...at('#number', 'right-of', 2.4, 0.2), ...size('fill', 'auto') }),
  ] } } };

La fascia è ancorata all’abbondanza, che qui coincide con il rifilo, e scende per 30 mm nell’area del testo. La grafica finisce con la fascia e minHeight riserva otto righe di griglia, 37,3 mm; l’apertura prende la profondità maggiore, quindi alle pagine 3 e 7 il testo comincia 7,3 mm sotto la fascia. Ogni tappa è un titolo di livello 3 la cui grafica compone {number} in un cerchio di 5,4 mm riempito di band. Il modello {3} ricomincia a ogni passeggiata, perché un titolo di livello 1 azzera i contatori più profondi, e i segnaposto sulla mappa riportano gli stessi numeri. Una tappa ha una riga di griglia di margine sopra e nessuna sotto, e il suo cerchio sta 3,2 mm più in basso nelle due righe di griglia che il titolo occupa. Restano così circa 8,3 mm di bianco sopra il cerchio e 2,1 mm sotto; i paragrafi distano 6,4 mm.

#4 · Appendi una piastrella al riquadro, e tieni i chip in nero

script.js · righe 166–181nel codice completo
const calloutStyles = [{ id: 'dontmiss', title: t({ en: 'Don’t miss', es: 'No te lo pierdas' }),
  background: col('wash'), // one device: the walk's tint
  // The tile hangs half off the box's outer side, flush with its top: the left side on a verso.
  // With 6.5 mm of padding on both sides the title stays in line with the box's text there too.
  // The tile's colours are drawn into the SVG, so it stays tile blue in every walk.
  padding: { top: mm(3.4), right: mm(6.5), bottom: mm(3.4), left: mm(6.5) },
  icon: { kind: 'resource', resourceId: 'tile', size: mm(10), position: 'corner',
    cornerSide: 'outer' },
  titleStyle: { ...label, fontSize: pt(8.5), fontWeight: 700, letterSpacing: pt(1.5),
    color: col('bandInk') },
  body: { fontSize: pt(9), lineHeight: pt(12.4), color: col('ink') } }];
// The facts are ink on paper in every walk: the walk's colour is kept for the tab, the stops
// and the box, and a chip linked to 'band' would follow it too.
const chipStyles = [{ id: 'fact', background: col('paper'), borderColor: col('muted'),
  borderWidth: pt(0.6), borderRadius: mm(0.8), paddingX: mm(1.4), paddingY: mm(0.5),
  fontFamily: 'Asap Condensed', fontSize: em(0.92), color: col('ink'), bold: true }];

Il riquadro non ha filetto né bordo, solo il fondo della passeggiata e una piastrella disegnata nel codice sul suo angolo (stili dei riquadri). cornerSide: 'outer' appende la piastrella per metà fuori dal lato esterno del riquadro, a filo con la sua testa; a pagina 4, un verso, è il lato sinistro, dove comincia il titolo. Con 6,5 mm di padding su entrambi i lati il titolo evita la piastrella e resta allineato al testo del riquadro su entrambe le pagine. La tavolozza della passeggiata ricolora il fondo e il titolo, mentre la piastrella resta blu, perché i suoi colori sono disegnati nell’SVG. Anche un chip collegato a band prenderebbe il colore della passeggiata; qui le informazioni pratiche ne restano fuori, quindi i chip sono neri sulla carta con un contorno grigio in muted, uguali in ogni passeggiata.

#5 · Fai la legenda della mappa con i campioni delle passeggiate

script.js · righe 529–543nel codice completo
const map = svg('routes', MAP.width, MAP.height, { placement: { position: 'here' }, ...t({ en: {
  caption: 'The three walks. The numbered pins are the stops in the text.',
  note: ':swatch{color="alfama"} Walk 1, Alfama · :swatch{color="baixa"} Walk 2, Baixa · '
    + ':swatch{color="belem"} Walk 3, Belém, 6 km west (inset)',
  altText: 'Map of central Lisbon north of the river: the yellow route runs from the '
    + 'waterfront up the Baixa grid to Rossio; the terracotta route climbs east from the '
    + 'cathedral through Alfama. An inset shows the teal Belém route.',
}, es: {
  caption: 'Los tres paseos. Los pines numerados son las paradas del texto.',
  note: ':swatch{color="alfama"} Paseo 1, Alfama · :swatch{color="baixa"} Paseo 2, Baixa · '
    + ':swatch{color="belem"} Paseo 3, Belém, 6 km al oeste (en el detalle)',
  altText: 'Plano del centro de Lisboa al norte del río: la ruta amarilla sube desde el '
    + 'muelle por la cuadrícula de la Baixa hasta el Rossio; la terracota sube hacia el este '
    + 'desde la catedral por Alfama. En un detalle, la ruta verde azulada de Belém.',
} }) });

La mappa è una risorsa SVG composta dove sta ::resource{id="routes"}, con un tipo di risorsa tutto suo perché la didascalia dica «Map 1». La nota fa la legenda dei percorsi con tre campioni di colore, :swatch{color="alfama"} e lo stesso per baixa e belem. Un campione di colore prende l’id di una voce della tavolozza (formattazione in linea). La tavolozza riceve una voce per passeggiata da WALKS, e il disegno prende i colori dei percorsi dallo stesso oggetto, così la legenda corrisponde ai percorsi e alle unghiature. I numeri nei segnaposto sono disegnati come tracciati, quindi la mappa non richiede alcun font.

La ricetta completa

Sandbox
// ═══ Postext Cookbook · Nº 047 · Walking guide with thumb tabs ═══════════════════
// https://postext.dev/en/cookbook/walking-guide-thumb-tabs
// Code: MIT · Text: original (CC BY 4.0) · Map and tiles: drawn in code (CC BY 4.0)
// Fonts: Albert Sans, DM Serif Display, Asap Condensed (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// A pocket guide to Lisbon. Each walk is a heading style that sets four colours, and the tab,
// the stop numbers, the box's tint and title and the blank page before the walk take them.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'walking-guide-thumb-tabs';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: 'band' and three partners are the entries a walk overrides
const palette = {
  ink: '#1b2430', // text: a blue-black
  paper: '#fffdf8', // the page
  band: '#1f4e9c', // the section colour: tile blue until a walk replaces it
  bandInk: '#1d4a94', // the section colour for type on paper
  onBand: '#ffffff', // type set on the band
  wash: '#e8eef8', // the section's box tint
  muted: '#5e6875', // running heads, notes, chip outlines
};
// Each walk's values for those four. Baixa yellow is too light for white type, so its
// onBand is the ink. The text is recoloured by value, so the four base values must differ.
const WALKS = {
  alfama: { band: '#b9533a', bandInk: '#a1432b', onBand: '#ffffff', wash: '#f7e7e0' },
  baixa: { band: '#e2b23d', bandInk: '#7d5a0f', onBand: '#1b2430', wash: '#fbf0d5' },
  belem: { band: '#2b7a78', bandInk: '#236866', onBand: '#ffffff', wash: '#e1eeed' },
};
const NAMES = { alfama: 'Alfama', baixa: 'Baixa', belem: 'Belém' };
// A walk's palette follows the paletteId; the hex beside it is the colour's base value.
const col = (id) => ({ hex: palette[id] ?? WALKS[id].band, model: 'hex', paletteId: id });
const entry = (id, hex) => ({ id, name: id, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  ...Object.entries(WALKS).map(([id, w]) => entry(id, w.band)), // for :swatch{color="alfama"}
  entry('main-color', palette.ink), // the engine's defaults link here: nothing prints blue
];
// #endregion
const TRIM = { width: 120, height: 200 }; // a pocket guide
// Mirrored, and tighter than a book's at top and foot: a pocket guide keeps 164 mm of text.
const MARGIN = { top: 18, bottom: 18, inner: 14, outer: 16 };
const MEASURE = TRIM.width - MARGIN.inner - MARGIN.outer; // 90 mm, about 55 characters
const LEAD = 13.2; // body leading in pt: the baseline grid
const BAND = 48; // mm: a walk opener's colour band, from the top edge
const HEAD = { y: 10, gap: 7 }; // running heads from the top edge; folio to title (mm)

Lo script.js composto funziona così com’è: incollalo nello script modulo di qualsiasi pagina, oppure apri la ricetta su CodePen. Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)

Varianti

#Lascia il verso bianco senza colore

Senza il campo, pagina 6 mantiene la sua unghiatura: pages: 'all' la stampa anche sulla pagina bianca, nel giallo della passeggiata 2 con un 2.

-const header = { elements: [...heads, ...tabs, ...blankPage] };
+const header = { elements: [...heads, ...tabs] };

#Aggiungi la terza passeggiata

WALKS contiene già i colori di Belém e walkStyles il suo stile, quindi la passeggiata ha bisogno solo del suo titolo nel contenuto. La passeggiata si apre a pagina 9, dopo una pagina 8 bianca dipinta di verde petrolio con un 3 bianco.

+# Belém {style="belem" route="From the monastery to the tower"}
+
+Tram 15 runs from Praça da Figueira to Belém along the river.

Errori frequenti

Errore frequente

Una pagina prende l’intestazione dell’ultima sezione che comincia su di essa

Quando due stili di titolo cominciano sulla stessa pagina, la pagina prende l’intestazione, il piè di pagina e la tavolozza dell’ultimo. Una pagina bianca di separazione appartiene al capitolo che la precede, il riempimento di parità al capitolo che la segue. Testatine per sezione →

Errore frequente

Uno stile di titolo eredita l’interruzione di pagina del suo livello

Una voce di headingStyles prende dal suo livello di titolo ogni campo che omette, breakBefore compreso. Un indice o un colophon con lo stile di un H1 dopo un :::pagebreak eredita parity 'odd' e finisce dietro una pagina bianca. Dai a uno stile del genere breakBefore: { enabled: false }. Stili di titolo →

Errore frequente

Gli scostamenti negativi relativi al contenitore non mostrano nulla

Il testo del progetto a larghezza automatica è confinato nel suo contenitore, quindi uno scostamento negativo dal contenitore lo spinge fuori e non viene mostrato nulla. Ancora questi elementi alla pagina o all’abbondanza con scostamenti espliciti in mm, o dai loro una larghezza fissa. Ancoraggio degli elementi del progetto →

Errore frequente

La pagina 1 è un recto: pianifica le pagine con i numeri fisici

La pagina 1 è una pagina destra e la pagina 2 il primo verso, quindi pianifica le doppie pagine con i numeri di pagina fisici: un’apertura su una pagina pari sta di fronte alla pagina dispari che la segue. Interruzioni di pagina e di colonna →

  • Pagina 6 esiste perché la passeggiata 1 finisce a pagina 5, un recto. Una passeggiata che finisce su un verso non lascia pagine bianche, e il colore della passeggiata successiva si vede allora solo sulle sue pagine.
  • Prima della prima passeggiata numerata {chapterNumber} è vuoto, quindi un elemento che lo stampa, come l’unghiatura, ha bisogno lì di uno stile che lo escluda.

Crediti

Testo
Testo originale, CC BY 4.0
Immagini
  • The tiles, the map of the routes and its pins, drawn in code · Ignacio Ferro · CC BY 4.0
Font
Albert Sans (SIL OFL 1.1) · DM Serif Display (SIL OFL 1.1) · Asap Condensed (SIL OFL 1.1)
Sandbox