In short
A whole short novel in Catalan, set as a small paperback. Words are split at the line end the way Catalan style guides ask, including the double l with a dot.
What you'll build
Narcís Oller’s El transplantat in full, in the text of his Obres completes (Barcelona, 1928), as a 12 × 18.5 cm pocket book of 32 pages. A half-title, a frontispiece of the baker at his oven, a title page in red italic Cormorant Garamond and a note on the edition come before the four chapters. Each chapter opens under an engraving twelve lines deep, with its Roman numeral in red. The text, Gentium Book Plus at 9.85 pt, breaks at Catalan syllables as the Institut d’Estudis Catalans asks: two letters at least on each side, no split between vowels in hiatus, none right after an apostrophe, and titil·laven breaks as titil- | laven, the hyphen taking the place of the middle dot. Dialogue is set with em dashes and quotations in «cometes baixes».
This recipe answers
- How do I get good justification and hyphenation for Spanish, French or German text?
- How do I give every chapter its own photo, colour or opener variant?
- How do I set unnumbered artwork: ornaments, vignettes, logos?
- How do I write dialogue dashes, years at a paragraph start, prices and literal symbols without Markdown misreading them?
The short answer
const LOCALE = 'ca'; // the exact bundled code: 'ca-ES' resolves to it too (postext ≥ 1.14)
const bodyText = { // config().bodyText
fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
firstLineIndent: mm(4.5), indentAfterHeading: false,
// The defaults justify, hyphenate in config().locale and break by Knuth–Plass. With 'ca'
// the dictionary follows the IEC: two letters on each side (ter-ra, cai-xa), no split in
// a hiatus (cièn-cia) or after an apostrophe (s’ha-via), l·l broken with the hyphen for the
// dot. From 1.30 the face is asked for its Catalan forms too: this one has a single dot.
// compounds: false divides arrossegar-se only at its own hyphen (Llibre d’estil, VI 2.5).
hyphenation: { compounds: false },
// Spaces from 0.7× to 1.6×, then up to 10‰ of tracking; a last line under 22 characters is
// a runt. A line that must keep d’inaugurar-se whole still opens to 1.94× on page 7.
maxWordSpacing: 1.6, minWordSpacing: 0.7, maxJustifyTracking: 10, runtMinCharacters: 22,
hyphenateAcrossColumns: false, // no page ends on a divided word
};
Catalan by its own code: l·l breaks as il- | lusió, no word splits its hiatus
Ingredients
- Features
- Hyphenation and document languageOptimal line breaking (Knuth–Plass)Covers, title pages and colophonsDesigned openersPictures in page designsHeading stylesHeading attributesText, rules and boxes in page designsChapters that open on a rectoRunning heads and foliosHeads by page roleMirrored marginsPaper colourParagraph stylesCustom resource typesWidows, orphans and runtsDocument metadataSemantic colour palettePDF exportFonts embedded in the PDF
- Type
- Gentium Book Plus, Cormorant Garamond, Cormorant SC (SIL OFL 1.1)
- Assets
cap1-1200.jpgcap2-1200.jpgcap3-1200.jpgcap4-1200.jpgfrontis-1000.jpg- Engraving, frontispiece: the baker at his oven's door (Generated With Diffusion Models, original)
- Engraving, chapter I: the night train into Barcelona (Generated With Diffusion Models, original)
- Engraving, chapter II: the village street in autumn (Generated With Diffusion Models, original)
- Engraving, chapter III: the Rambla at dawn (Generated With Diffusion Models, original)
- Engraving, chapter IV: the old man by the railway (Generated With Diffusion Models, original)
Method
#1 · Catalan by its code
The code is the short answer above. locale: 'ca' selects the Catalan patterns, and since postext 1.14 they follow the IEC’s Llibre d’estil (supported locales). The patterns are the ones TeX uses, with two letters at least on each side of a break instead of the three the npm package ships, so ter-ra, cai-xa and plu-ja can break. Vowels in hiatus stay together (cièn-cia, ca-mions), but an i between vowels opens its syllable (fe-ia). The ela geminada breaks between its two l: the line ends titil- and the next opens laven, with no middle dot on either side, and Knuth–Plass measures the line without the dot.

compounds: false keeps a verb and its pronoun whole but for their own hyphen (arrossegar- | se), which the IEC prefers (hyphenation). It costs one loose line: on page 7, the line before d’inaugurar-se opens its spaces to 1.88×, even with maxJustifyTracking: 10 taking the excess on the other lines.
#2 · A pocket page of whole lines
const TRIM = { width: 120, height: 185 }; // mm
const [TOP, INNER, OUTER, LINES] = [18, 16, 15, 29];
const MEASURE = TRIM.width - INNER - OUTER; // 89 mm: about 63 characters of Gentium Book Plus
const page = {
width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - LINES * LINE),
left: mm(INNER), right: mm(OUTER), mirror: true }, // left is the inner margin on a recto
};
The bottom margin comes from the trim, the top margin and LINES, so the text block holds 29 lines of 14 pt and every full page ends on the same baseline. The 89 mm measure holds about 63 characters of Gentium Book Plus. mirror: true keeps the 16 mm margin at the spine on both pages of a spread (mirrored margins).
#3 · One opener for four chapters
// # II {style="capitol" art="cap2"}: the art attribute names the picture's resource.
const PICTURE = { width: MEASURE, height: 12 * LINE }; // 89 × 59.3 mm: twelve lines, 3:2
const chapter = { id: 'capitol',
breakBefore: { enabled: true, parity: 'any' }, // a chapter opens on the next page, either side
marginBottom: pt(0), // the opener's own height already ends on a line
advancedDesign: { enabled: true, minHeight: pt(16 * LEAD), slot: { elements: [
{ kind: 'image', id: 'art', resourceId: '{attr.art}',
placement: at('container', 'top', 0, 0,
{ width: mm(PICTURE.width), height: mm(PICTURE.height) }) },
// The numeral and its rule hang from the container's top, a fixed drop under the picture.
text('numeral', '{titleText}', DISPLAY, 21, at('container', 'top', 0, PICTURE.height + 4),
{ fontWeight: 600, color: col('vermell'), lineHeight: 1 }),
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.5), color: col('vermell'),
placement: { ...at('container', 'top', 0, PICTURE.height + 13), size: { width: mm(8) } } },
] } },
};
resourceId: '{attr.art}' draws the picture the heading names, so # II {style="capitol" art="cap2"} opens chapter II under its own engraving with the same style as the others (heading attributes). minHeight holds sixteen lines, twelve for the picture and four for the numeral and its rule, so the text starts on the seventeenth line of the page, the same in every chapter.
#4 · Four pages before chapter I
const front = (id, elements, { minHeight, ...extra } = {}) => ({ id,
breakBefore: { enabled: true, parity: 'any' }, marginBottom: pt(0),
header: { elements: [] }, footer: { elements: [] }, ...extra,
advancedDesign: { enabled: true, ...(minHeight && { minHeight }), slot: { elements } } });
const FRONTIS = { width: MEASURE, height: MEASURE * 1.5 }; // mm: the engraving is 2:3
const headingStyles = [
front('avantportada', [text('title', '{titleText}', DISPLAY, 19,
at('container', 'top', 0, 9 * LINE), { italic: true, fontWeight: 500, lineHeight: 1 })]),
front('frontis', [
{ kind: 'image', id: 'art', resourceId: '{attr.art}',
placement: at('container', 'top', 0, 0,
{ width: mm(FRONTIS.width), height: mm(FRONTIS.height) }) },
text('legend', '{titleText}', LABEL, 8.5, at('container', 'top', 0, FRONTIS.height + 5),
{ ...caps(8.5, 1.4, 'muted') }),
]),
front('portada', [
text('author', '{author}', LABEL, 10, at('container', 'top', 0, 5 * LINE),
caps(10, 2.2, 'ink')),
text('title', '{titleText}', DISPLAY, 34, at('container', 'top', 0, 8 * LINE),
{ italic: true, fontWeight: 500, color: col('vermell'), lineHeight: 1 }),
text('subtitle', '{subtitle}', DISPLAY, 13, at('container', 'top', 0, 8 * LINE + 17),
{ italic: true, fontWeight: 500 }),
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.5), color: col('vermell'),
placement: { ...at('container', 'top', 0, 8 * LINE + 29), size: { width: mm(14) } } },
]),
// The note sits low on the verso behind the title, its label a line above it.
front('nota', [text('label', '{titleText}', LABEL, 8.5, at('container', 'top', 0, 13 * LINE),
caps(8.5, 1.4))], { minHeight: pt(15 * LEAD) }),
chapter,
];
Each piece of front matter is a level-one heading with a style of its own: # El transplantat {style="portada"} prints the author and the subtitle from the frontmatter and the heading as the title. Every style restates its page break, since a style inherits its level’s, and empties the header and footer, so these pages carry no running heads or folios. The frontispiece falls on page 2, a verso, so it faces the title page across the spread.
#5 · The author on the verso, the title on the recto
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre is off the page's centre
const head = (id, content, parity, edge, x, y = 10, pages = 'body') => ({
kind: 'text', id, content, parity, pages, ...caps(8, 1.3, 'muted'),
placement: at('page', edge, x, y),
});
const folio = { fontFamily: TEXT, fontWeight: 400, letterSpacing: pt(0), color: col('ink') };
const header = { elements: [
{ ...head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER), ...folio },
head('verso-author', '{author}', 'even', 'top', -SHIFT),
head('recto-title', '{title}', 'odd', 'top', SHIFT),
{ ...head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER), ...folio },
] };
const drop = (parity, x) => ({ ...head(`drop-${parity}`, '{pageNumber}', parity, 'bottom', x,
-11, 'opener'), ...folio });
const footer = { elements: [drop('odd', SHIFT), drop('even', -SHIFT)] };
parity puts the author on versos and the title on rectos; pages: 'body' keeps both off the openers, where a drop folio with pages: 'opener' takes their place. SHIFT moves each head onto the centre of the text block, half a millimetre off the page’s centre because the two margins differ.
#6 · Five engravings, no labels
const resourceTypes = [{ id: 'gravat', name: 'Gravat', namePlural: 'Gravats', shortLabel: 'Gravat',
captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal' }];
const PICTURES = { // id: [file, width, height, alt text in the book's language]
frontis: ['frontis-1000.jpg', 1000, 1500, 'Un carrer de poble al capvespre. A la porta del forn, '
+ 'on cremen les flames, el forner, gras i somrient, amb davantal blanc i els braços creuats.'],
cap1: ['cap1-1200.jpg', 1200, 800, 'De nit, el tren baixa cap a Barcelona: rengleres de fanals, '
+ 'la muntanya de Montjuïc i la lluna sobre el mar. Un pagès treu el cap per la finestreta.'],
cap2: ['cap2-1200.jpg', 1200, 800, 'Un carrer de poble buit en una nit de tardor. Per la porta '
+ 'baixa de la ferreria, el manyà pica l’enclusa enmig d’una estrella d’espurnes.'],
cap3: ['cap3-1200.jpg', 1200, 800, 'La Rambla a trenc d’alba des d’un balcó. Un fanaler apaga '
+ 'el gas amb la perxa; al fons, els pals dels vaixells del port.'],
cap4: ['cap4-1200.jpg', 1200, 800, 'Capvespre als afores. Un vell de cabells blancs, assegut '
+ 'al caire del desmunt, mira la via del tren, que es perd recta fins a l’horitzó.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
id, typeId: 'gravat', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
The pictures belong to a resource type with an empty captionPrefix, so nothing numbers or labels them. Each is declared at its pixel size and loaded under its file id before the build. Their white was mapped to the page’s cream and their black to its ink before they were saved, so they print as part of the page and not as photographs pasted on it.
The whole recipe
// ═══ Postext Cookbook · Nº 104 · A Catalan novella, hyphenated by the IEC rules ═══════
// https://postext.dev/en/cookbook/catalan-pocket-novella
// Code: MIT · Text: N. Oller, El transplantat, 1928 (PD, Viquitexts) · Pictures: diffusion models
// Fonts: Gentium Book Plus, Cormorant Garamond, Cormorant SC (OFL) · Needs postext ≥ 1.57.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document (the sample is Catalan in both)
const RECIPE = 'catalan-pocket-novella';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#2a2320', // text: a warm near-black, the pictures' ink too
vermell: '#953222', // the one accent: chapter numerals, rules, the title page's title
muted: '#6e6359', // running heads, the edition's note, the colophon
paper: '#f5efe1', // a cream book paper, the pictures' white
};
// Each colour names its palette entry and carries its hex.
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' } })),
{ id: 'main-color', name: 'vermell (defaults)', value: { hex: palette.vermell, model: 'hex' } },
];
const [TEXT, DISPLAY, LABEL] = ['Gentium Book Plus', 'Cormorant Garamond', 'Cormorant SC'];
const [BODY, LEAD] = [9.85, 14]; // pt: body and leading, the pitch of every vertical measure
const LINE = (LEAD * 25.4) / 72; // mm: one line, 4.94
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const text = (id, content, fontFamily, size, placement, extra = {}) => ({ kind: 'text', id,
content, fontFamily, fontSize: pt(size), color: col('ink'), align: 'center',
overflow: 'wrap', placement, ...extra }); // a long title takes a second line
const caps = (size, tracking, color = 'vermell') => ({ fontFamily: LABEL, fontSize: pt(size),
fontWeight: 600, letterSpacing: pt(tracking), color: col(color) });
// #region page: a 12 × 18.5 cm pocket book; the text block holds 29 whole lines
const TRIM = { width: 120, height: 185 }; // mm
const [TOP, INNER, OUTER, LINES] = [18, 16, 15, 29];
const MEASURE = TRIM.width - INNER - OUTER; // 89 mm: about 63 characters of Gentium Book Plus
const page = {
width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - LINES * LINE),
left: mm(INNER), right: mm(OUTER), mirror: true }, // left is the inner margin on a recto
};
// #endregion
// #region answer: Catalan by its own code: l·l breaks as il- | lusió, no word splits its hiatus
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
#Let pronouns divide too
With the default compounds: true, d’inaugurar-se divides inside the verb, as d’i- | naugurar-se, and page 7 loses its loose line: no line of the book opens past 1.6×. The titil- | laven break stays on page 27. The price is a lone i after the apostrophe at the end of a line.
- hyphenation: { compounds: false },
+ hyphenation: { compounds: true },#Open every chapter on a recto
parity: 'odd' adds a blank page before a chapter that would start on a verso, as in a roomier edition. Chapter IV, which opens on page 26, moves to page 27 behind a blank page.
- breakBefore: { enabled: true, parity: 'any' }, // a chapter opens on the next page, either side
+ breakBefore: { enabled: true, parity: 'odd' },Pitfalls
Pitfall
A heading style inherits its level's page break
A headingStyles entry takes every field it leaves out from its heading level, breakBefore included. A contents page or a colophon styled on an H1 after a :::pagebreak inherits parity 'odd' and lands behind a blank page. Give such a style breakBefore: { enabled: false }. Heading styles →
Pitfall
Attribute values: no { or }; single-quote a value with "
An attribute value ends at the closing brace, so it cannot hold { or }. A value that contains a double quote goes in single quotes; a dollar sign is fine. Heading attributes →
- Look at l·l in a text face before you settle on it. From postext 1.30 the document’s
localeis also the language its text is shaped in (up to 1.29 that was the language of the page showing the book), and each face answers Catalan in its own way. Gentium Book Plus has one middle dot for every language, 0.17 em between the two l. Crimson Pro, which set this book up to 1.29, widens the dot to 0.59 em in Catalan and leaves a gap in intel·ligent. Alegreya and Literata draw a closer dot only where both l reach them in one piece, so il·lustrats comes out one way in a paragraph with italics and another in a paragraph without. - Copy the text from Viquitexts with its italics: Oller marks tentu, Ensanxe and palacio as colloquial or Spanish, and a plain-text export drops them. Check doubtful words against the scan of the 1928 volume: six times the transcription has tom- where the verb is tornar (tomà, tomaré, tomar), and once jom for jorn.
- With 6,800 words, the five content files and the kit make the composed script about 69 KB. A whole book is the largest sample a pen can carry; a longer work belongs in a
.postextbundle.
Credits
- Recipe
- Ignacio Ferro
- Text
- El transplantat, complete, from the Obres completes, vol. VI (Barcelona, 1928), with misprints corrected, no opening ¿ ¡ and today’s dialogue dashes · Narcís Oller · public domain
- The note to the edition · Postext Cookbook · original
- Images
- Engraving, frontispiece: the baker at his oven's door · Generated With Diffusion Models · original
- Engraving, chapter I: the night train into Barcelona · Generated With Diffusion Models · original
- Engraving, chapter II: the village street in autumn · Generated With Diffusion Models · original
- Engraving, chapter III: the Rambla at dawn · Generated With Diffusion Models · original
- Engraving, chapter IV: the old man by the railway · Generated With Diffusion Models · original
- Fonts
- Gentium Book Plus (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · Cormorant SC (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


