Skip to main content
Recipe number 23

Cookbook · Chapter 9 · Complete publications

Magazine cover and sectioned contents

A photo cover whose cover lines hang below the masthead, and contents generated with a coloured row per section. Each section is a part that opens no page.

  • Trim 230 × 300 mm
  • 2 columns, 6 mm gutter
  • Spectral 9.5/13.5
  • Bodoni Moda
  • Jost
  • 6 pages
  • Level
  • Postext 1.57.1
  • Laid out in 194 ms
  • 249 lines of code

In short

The cover and first pages of a food and farming magazine, with a photo cover and a contents page. It shows how to give each section its own colour, which carries through its pages.

What you'll build

Six pages from an issue of FALLOW, an imaginary quarterly of food and land, on a 230 × 300 mm page. A Tuscan valley bleeds off the cover under a 118 pt Bodoni masthead, and three cover lines sit on a paper panel, each kicker in its section's colour, with the price and barcode in the corner. Page 2 holds the generated contents: a coloured tab per section, with the story's title, page number and standfirst under it. The right-hand column carries the editor's letter, the contributors and the colophon. The sections that follow are terracotta, olive and wine. Every story opens with a picture bled across the head of the page and a panel in the section's colour rising into it, and its folio tabs, bullets and boxes take that colour. The colour is set by the :::part fence above each story, which opens no divider page.

This recipe answers

  • How do I make a cover, a half title, a title page and a colophon?
  • How do I add a table of contents that updates itself (leaders, page numbers, authors, part rows)?
  • How do I divide a book into parts or sections, each with its own colour and divider page?
  • How do I give every chapter its own photo, colour or opener variant?

The short answer

script.js · lines 39–74in full code
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),
    box: sheet(n === 1 ? 5 : 4, 1.5) },
  { ...at(above, 'below', 0, n === 1 ? 8 : -SEAM), size: { width: mm(PANEL) } }),
  text(`line${n}`, `{attr.line${n}}`, { ...bodoni, italic: true, fontSize: pt(15),
    lineHeight: 1.12, color: col('ink'), box: sheet(0, n === 3 ? 5 : 0) }, // line 3 ends the panel
  { ...at(`#kicker${n}`, 'below', 0, -SEAM), size: { width: mm(PANEL) } }),
];
const cover = { enabled: true, slot: { elements: [
  { kind: 'image', id: 'photo', resourceId: 'cover', // the JPEG is cropped to the trim, 23 : 30
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } } },
  text('strap', '{subtitle}', small, at('page', 'top-left', MARGIN.inner, 12)), // a recto
  text('issue', '{attr.issue}', { ...small, align: 'right' },
    at('page', 'top-right', -MARGIN.outer, 12)),
  text('masthead', '{titleText}', { ...bodoni, fontWeight: 900, fontSize: pt(118),
    lineHeight: 0.86, // set tight: the masthead is capitals, with no descenders
    letterSpacing: pt(1), textTransform: 'uppercase', align: 'center', color: col('ink') },
  { ...at('#strap', 'below', 0, 6), size: { width: mm(MASTHEAD) } }),
  ...coverLine(1, 'olive'), ...coverLine(2, 'terracotta'), ...coverLine(3, 'wine'),
  // The price and a made-up barcode sit in the corner, anchored to the page, not the words.
  text('price', '{attr.price}', { ...small, fontSize: pt(7), box: sheet(1, 1.5) },
    { ...at('page', 'bottom-right', -MARGIN.outer, -12), size: { width: mm(32) } }),
  { kind: 'image', id: 'barcode', resourceId: 'barcode',
    placement: { ...at('#price', 'above', 0, SEAM), size: { width: mm(32) } } },
] } };
// hook-up: headingStyles gets { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
// footer: { elements: [] } }, with no folio; the Markdown's first line is
// # Fallow {style="cover" issue="…" price="…" kicker1="…" line1="…" … kicker3="…" line3="…"}

The cover, one design slot whose words hang from each other

Ingredients

Type
Spectral, Bodoni Moda, Jost (SIL OFL 1.1)
Assets
  • castellina-cover-1150.jpg
  • castellina-farm-1530.jpg
  • fields-1610.jpg
  • flasks-1920.jpg
  • harvest-1840.jpg
  • Castellina in Chianti (the cover and its copy in the contents) (Rowan Heuvel, CC0 1.0)
  • Castellina in Chianti, a detail (the feature's photograph) (Rowan Heuvel, CC0 1.0)
  • Plants in beakers (the Field notes opener) (chuttersnap, CC0 1.0)
  • Harvesting the wheat crop (the Kitchen opener) (meriç tuna, CC0 1.0)
  • Fields from above near Castellina in Chianti (the feature's opener) (Generated With Diffusion Models, original)
  • The cover's barcode, drawn in code (Ignacio Ferro, MIT)

Method

#1 · Hang the cover from its masthead

The code is the short answer above. Only the photograph, the two lines at the head and the price are anchored to the page. Everything else is anchored to another element (element placement): the masthead below the strap, the first kicker 8 mm below the masthead, then each line below its kicker and each kicker below the line before, so a longer cover line or a bigger masthead pushes down what sits under it instead of printing over it. Each kicker and each line carries its own paper box, 84 mm wide, and the six boxes stacked together make the panel, which grows with the words. Every box after the first overlaps the one above by 0.3 mm (SEAM), and the barcode overlaps the price the same way, because on the canvas two fills that only touch leave a hairline of the photograph between them. A magazine has no half title and no title page; the cover carries its name, and the contents page carries the issue number, the season and the colophon. For a book's front matter, see Front matter in roman folios, then page 1.

#2 · Make each section a part without a page

script.js · lines 78–87in full code
const parts = { page: false }; // a :::part now only sets the section's title and palette
const story = (id, picture) => ({ id, numbered: false, advancedDesign: opener(picture) });
const headingStyles = () => [
  { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
    footer: { elements: [] } }, // no folio on the cover (the header is empty everywhere)
  { id: 'contents', numbered: false, toc: false, advancedDesign: contentsOpener,
    footer: folioLine('{title}', '{publishDate}') }, // no section yet: the issue instead
  // One opener for every story; the style names its picture, the part its colour.
  story('grain', 'flasks'), story('rest', 'fields'), story('bread', 'harvest'),
];

With parts.page: false, a fence such as :::part{title="Features" palette="band=#5d6a2b"} opens no divider page and only sets the section's title and palette from the next block on (the :::part container). Each story's H1 takes a heading style with numbered: false, so the contents list it without a number. The style picks the opener's picture, and the part supplies the colour.

#3 · Link every section colour to one entry

script.js · lines 14–27in full code
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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 ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];

A part overrides palette entries by id, so everything that changes with the section links to band: the opener's panel, the folio tab, the bullets and list numbers, the pull quote, and the fact box's stripe and title. In the text the override goes by value: any colour whose hex equals band's base hex (#8b6a3e) takes the section's, which is why no other entry uses that hex. Design elements work the other way round: a part's override reaches them through the paletteId, so col() writes the id beside the hex.

#4 · Let the contents group themselves

script.js · lines 91–124in full code
const mid = at('container', 'left', 0, -1); // the row's middle, 1 mm up: air above the title
const contents = { // passed to the config as `toc`
  levels: [{ level: 1, fontFamily: 'Bodoni Moda', fontSize: pt(17), fontWeight: 600,
    marginBottom: pt(2 * LEAD) }], // in ink, on the body's 13.5 pt leading
  pageNumber: { fontSize: pt(26), width: mm(14) }, // in the levels' Bodoni
  leader: { enabled: false }, subtitle: { enabled: true, attr: 'standfirst', // in italic
    fontFamily: 'Spectral', fontSize: pt(10), color: col('muted') },
  // A part row is a design as wide as the column; its 'band' takes the part's palette. No
  // {pageNumber} in it: each story under the tab prints its own page.
  parts: { height: pt(2 * LEAD), design: { elements: [ // two grid lines (the default: 2 em)
    { kind: 'rule', id: 'line', thickness: pt(0.75), color: col('band'), // behind the tab
      placement: { ...mid, size: { width: 'fill' } } },
    text('tab', '{titleText}', { ...label, fontSize: pt(8), letterSpacing: pt(1.6),
      color: col('paper'), box: { backgroundColor: col('band'),
        padding: { top: mm(1.2), right: mm(2.4), bottom: mm(1.2), left: mm(2.4) } } },
    mid),
  ] } },
};
// The colophon closes the contents page; the Markdown calls it with :::paragraphs.
const colophon = { id: 'colophon', fontFamily: 'Jost', fontSize: pt(7), lineHeight: pt(10),
  color: col('muted'), textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD) };
const air = { padding: { bottom: mm(9) } }; // empty padding counts: the columns start lower
const contentsOpener = { enabled: true, slot: { elements: [
  { kind: 'rule', id: 'rule', thickness: pt(1), color: col('ink'),
    placement: { ...at('container', 'top-left'), size: { width: 'fill' } } },
  text('kicker', '{titleText}', { ...label, fontSize: pt(9), letterSpacing: pt(1.8),
    color: col('band') }, at('#rule', 'below', 0, 5)),
  text('issue', '{attr.issue}', { ...bodoni, italic: true, fontSize: pt(44), lineHeight: 1.05,
    color: col('ink') }, at('#kicker', 'below', 0, 2)),
  text('strap', '{subtitle}', { fontFamily: 'Spectral', italic: true, fontSize: pt(11),
    color: col('muted'), align: 'left' }, at('#issue', 'below', 0, 1.5)),
  text('number', '{attr.number}', { ...bodoni, fontWeight: 900, fontSize: pt(160), lineHeight: 1,
    align: 'right', color: col('band'), box: air }, at('container', 'top-right', 0, 4)),
] } };

:::toc lists the stories and gives each :::part a row laid out from toc.parts.design with that part's palette (table of contents), so one row design prints three tabs in three colours. The rule and the tab both hang from mid, the row's middle raised 1 mm, which keeps the tab clear of the title below. With the leader off, nothing runs between a title and its page number (3, 4 and 6), and subtitle.attr prints the opener's standfirst attribute under the title in italic. The colophon that ends the right-hand column is a paragraph style, Jost 7 pt in muted, which the Markdown applies with :::paragraphs{style="colophon"}.

#5 · Give every story the same opener

script.js · lines 128–152in full code
const PHOTO = 150; // mm from the top edge to the foot of the picture
const FOOT = PHOTO - MARGIN.top; // the same foot from the container, which starts at the margin
const LIFT = 34; // mm: how far the panel rises into the picture
const WIDE = 136; // mm: the panel's width
const panel = (top, bottom) => ({ backgroundColor: col('band'),
  padding: { top: mm(top), right: mm(6), bottom: mm(bottom), left: mm(6) } });
const below = (id) => ({ ...at(`#${id}`, 'below', 0, -SEAM), size: { width: mm(WIDE) } });
const opener = (resourceId) => ({ enabled: true, slot: { elements: [
  { kind: 'image', id: 'picture', resourceId, // fitted, never cropped: each file is 230 : 150
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: mm(PHOTO) } } },
  text('credit', '{attr.credit}', { ...small, fontSize: pt(6.5), color: col('muted'),
    letterSpacing: pt(0.6), align: 'right' }, at('container', 'top-right', 0, FOOT + 2)),
  text('section', '{partTitle}', { ...label, fontSize: pt(8.5), letterSpacing: pt(1.7),
    color: col('paper'), box: panel(6, 2) }, { ...at('container', 'top-left', 0, FOOT - LIFT),
    size: { width: mm(WIDE) } }),
  text('title', '{titleText}', { ...bodoni, fontWeight: 700, fontSize: pt(32), lineHeight: 1.02,
    color: col('paper'), box: panel(0, 3) }, below('section')),
  text('standfirst', '{attr.standfirst}', { fontFamily: 'Spectral', italic: true,
    fontSize: pt(11.5), lineHeight: 1.35, overflow: 'wrap', align: 'left',
    color: col('paper'), box: panel(0, 6) }, below('title')),
  // The panel and the byline reach below the picture's foot, so they set where the story
  // starts; the byline's empty padding keeps the first line 5 mm under it.
  text('byline', '{attr.byline}', { ...small, fontSize: pt(7.5), letterSpacing: pt(1.3),
    box: { padding: { top: mm(4), bottom: mm(5) } } }, at('#standfirst', 'below')),
] } });

The picture bleeds off the top of the page and reaches 150 mm down it. A panel in band rises 34 mm into its foot. The panel is three text boxes 136 mm wide, each chained below the one before, holding the section's name from {partTitle}, the title and the standfirst. The panel and the byline reach below the picture's foot, so the story starts under the lowest element, the byline, whose empty 5 mm of bottom padding keeps the first line at least that far below it.

#6 · Name the section in the folio

script.js · lines 156–171in full code
const TAB = 6.5; // mm: the tab's side; the words beside it take its height and centre on it
const folioLine = (first, second) => ({ elements: [['even', 'left', 1], ['odd', 'right', -1]]
  .flatMap(([parity, side, s]) => {
    const inward = s > 0 ? 'right-of' : 'left-of'; // from the outer edge towards the gutter
    const beside = (id, content, style, to, gap) => text(id, content, { ...style, align: side },
      { ...at(to, inward, s * gap), size: { height: mm(TAB) } }); // text centres vertically
    return [
      text(`tab-${parity}`, '{pageNumber}', { ...label, fontSize: pt(8), color: col('paper'),
        align: 'center', box: { backgroundColor: col('band') } },
      { ...at('page', `bottom-${side}`, s * MARGIN.outer, -11),
        size: { width: mm(TAB), height: mm(TAB) } }),
      beside(`first-${parity}`, first, { ...small, color: col('band') }, `#tab-${parity}`, 3),
      beside(`second-${parity}`, second, { fontFamily: 'Spectral', italic: true,
        fontSize: pt(8), color: col('muted') }, `#first-${parity}`, 2.5),
    ].map((element) => ({ ...element, parity })); // no pages filter: openers get folios too
  }) });

The page number sits in a 6.5 mm square of band at the outer foot. The section's name is anchored beside it, towards the gutter, and the story's title beside the name; all three boxes are 6.5 mm tall with their text centred vertically, so they share one centre line. Magazines print the folio on an opening page too, so the footer has no pages filter. The cover's heading style empties the footer, and the contents' style puts the magazine's name and the issue's season ({title} and {publishDate}) where the section and the story go.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 023 · Magazine cover and sectioned contents ═══════════════
// https://postext.dev/en/cookbook/magazine-cover-and-contents
// Code: MIT · Text: original (CC BY 4.0) · Photos: R. Heuvel, chuttersnap, m. tuna (CC0), diffusion
// Fonts: Spectral, Bodoni Moda, Jost (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'magazine-cover-and-contents';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one house colour, 'band', that every section overrides
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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 ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const TRIM = { width: 230, height: 300 }; // an independent-magazine trim, in mm
const MARGIN = { top: 22, bottom: 20, inner: 16, outer: 14 }; // mirrored
const LEAD = 13.5; // body leading in pt: the baseline grid
const caps = { fontFamily: 'Jost', fontWeight: 600, textTransform: 'uppercase' }; // the label face
const label = { ...caps, align: 'left' }; // design text is centred by default
const bodoni = { fontFamily: 'Bodoni Moda', overflow: 'wrap', align: 'left' };
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, placement, ...look });

// #region answer: the cover, one design slot whose words hang from each other
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),

The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)

Variations

#Set the masthead in the house colour

The masthead takes the earth brown of the big 14 on the contents page.

-    textTransform: 'uppercase', align: 'center', color: col('ink') },
+    textTransform: 'uppercase', align: 'center', color: col('band') },

#Open each section on a divider page

For parts with a page of their own, and a page number in each part row of the contents, see Parts in colour from one attribute.

Pitfalls

Pitfall

A 'top' float goes to the page after its citation unless it may head the citing page

By default a float never goes above its own reference, so a page-wide 'top' float cited on page N opens page N+1. Set placement.citingPage: true on the resource or its type's defaultPlacement (or layout.floatsAtCitingPage for the whole book, since postext 1.25) and it heads page N instead, the text above the reference moving down under it, when it fits within layout.maxTopFraction and the citing line stays on that page. It never heads a chapter's first page or a page after a forced break: there it still opens the next page, and 'auto' or 'bottom' can take the foot of the citing page. Figure placement →

Pitfall

Bitmaps take their print size from a resolution: declare it, not print-size pixels

A bitmap without a resolution is laid out one pixel per layout pixel at the document's dpi, so a 2400 px photo is 406 mm wide on a 150 dpi page. Declare the file's real pixels and give the picture its resolution (bitmap.resolution: 300), or set layout.bitmapResolution for every bitmap: a ppi, or 'file' to read the one the file states. The column still caps the picture. Figures and tables as resources →

  • An image element fits its picture inside its box and never crops it. Cut each JPEG to its box first, 23 : 30 for the cover and 230 × 150 mm for the openers, or the picture shrinks and leaves white strips at the edges.
  • In the text, a part recolours every colour whose hex equals band's base hex, whether or not it links to band. Keep that hex for what should change with the section.
  • The stories are copy-fitted in both languages: some sentences of the Spanish Field notes were shortened so that it stays on one page, and one sentence of the English feature lost three words so that both columns of page 4 end level. After an edit, check that no story spills a few lines onto a new page and that every page except a story's last ends level.

Credits

Text
Original prose, CC BY 4.0
Images
  • Castellina in Chianti (the cover and its copy in the contents) · Rowan Heuvel · CC0 1.0
  • Castellina in Chianti, a detail (the feature's photograph) · Rowan Heuvel · CC0 1.0
  • Plants in beakers (the Field notes opener) · chuttersnap · CC0 1.0
  • Harvesting the wheat crop (the Kitchen opener) · meriç tuna · CC0 1.0
  • Fields from above near Castellina in Chianti (the feature's opener) · Generated With Diffusion Models · original
  • The cover's barcode, drawn in code · Ignacio Ferro · MIT
Fonts
Spectral (SIL OFL 1.1) · Bodoni Moda (SIL OFL 1.1) · Jost (SIL OFL 1.1)
Sandbox