In short
The first pages of a Spanish novel from 1878 as a pocket book. It shows how to keep the gaps between words even, with words split at the right Spanish syllables.
What you'll build
The opening of Galdós’s Marianela (1878) in an 11.5 × 18 cm pocket edition, with a conjectural map of the Socartes mines facing chapter I. Above the chapter’s italic Libre Bodoni title, capítulo primero is spelled out in small capitals; the text, in Gentium Book Plus, starts a quarter of the way down with a raised oxblood initial. Words break at Spanish syllables (hie-rro, esta-blecimiento) and word spaces stay under 1.7 times their normal width; no paragraph ends on the tail of a hyphenated word. Dialogue is set with rayas, the em dashes that also open and close the narrator’s incisos (asides). The traveller’s watchword is in «comillas latinas», and in English double quotes where the edition’s note quotes it inside a quotation. The map is Figura 1, cited in the text as [fig. 1]. Running heads in Marcellus SC name the author on versos and the title on rectos.
This recipe answers
- How do I get good justification and hyphenation for Spanish, French or German text?
- How do I avoid widows, orphans and one-word last lines (runts), and keep a heading with its text?
- How do I write dialogue dashes, years at a paragraph start, prices and literal symbols without Markdown misreading them?
- How do I get "Figure" and "Table" labels in my document's language?
- How do I add an author line, a standfirst or a lead with a drop cap to an opener?
The short answer
const LOCALE = 'es'; // config().locale: Spanish hyphenation, and Spanish caption labels
const bodyText = { // config().bodyText
fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
referenceBold: false, // '[fig. 1]' reads in roman, like the words around it
firstLineIndent: mm(4), indentAfterHeading: false, // a paragraph after a heading starts flush
// The defaults justify, hyphenate, break by Knuth–Plass and keep widows and orphans out.
// Long Spanish words on an 86 mm measure need two more settings. Spaces under 1.7×: at
// the default 2×, eight lines here open past 1.6×; at 1.7 it hyphenates hie-rro, ca-lles.
// A last line under 26 space widths is a runt; at 20, 'siem- / pre adelante.' got through.
maxWordSpacing: 1.7, runtMinCharacters: 26,
};
// config().resourceTypes: the built-in types, 'Figura' and 'Fig.' in Spanish, renumbered
// through the book (Figura 1) where the default counts by chapter (Figura 1.1).
const resourceTypes = defaultResourceTypes(LOCALE)
.map((type) => ({ ...type, numberingTemplate: '{n}', resetOn: 'never' }));
Spanish syllables, word spaces under 1.7×, captions that say Figura
Ingredients
- Features
- Hyphenation and document languageOptimal line breaking (Knuth–Plass)Drop caps in body paragraphsDesigned openersHeading attributesText, rules and boxes in page designsWidows, orphans and runtsMirrored marginsChapters that open on a rectoHeads by page roleRunning heads and foliosCitations that place figuresNumbered captionsFigure and Table in your languageFigures exactly hereHeading stylesExplicit vertical spaceParagraph stylesEscapes and literal charactersPaper colour
- Type
- Gentium Book Plus, Libre Bodoni, Marcellus SC (SIL OFL 1.1)
- Assets
- The conjectural map of the Socartes mines, drawn in code in the page’s palette (Ignacio Ferro, MIT)
Method
#1 · Spanish syllables, spaces held in
The code is the short answer above. locale: 'es' picks the Spanish hyphenation patterns, as a regional tag such as 'es-ES' or 'es-MX' does; the American rules of the default locale would break cabal-los, hi-erro and establec-imiento (supported locales). Justification, Knuth–Plass and the widow and orphan rules are on by default. The 86 mm measure also needs its spaces held in: at the default maxWordSpacing: 2, eight lines open past 1.6× and the widest reaches 1.89×; at 1.7 the widest is 1.65×, because the breaker hyphenates hie-rro and ca-lles instead (word spacing bounds). Past the limit a line costs far more but stays legal, so on a narrower measure with no better break it can still go over. runtMinCharacters: 26 catches the hyphenated scraps that the default of 20 space widths lets through: siem- / pre adelante. becomes Adelante, / siempre adelante., and So- / cartes [fig. 1]. becomes de / Socartes [fig. 1]. (runts).
#2 · A pocket page of whole lines
const TRIM = { width: 115, height: 180 }; // mm: 11.5 × 18 cm
const [TOP, INNER, OUTER] = [16, 15, 14]; // mm: a pocket page keeps its margins tight
const LINES = 30; // lines of LEAD per page, so every full page ends on the same line
const MEASURE = TRIM.width - INNER - OUTER; // 86 mm: about 57 characters of Gentium at 10 pt
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 * LEAD * 25.4) / 72),
left: mm(INNER), right: mm(OUTER), mirror: true }, // left is inner on a recto
};
The bottom margin is computed from the trim, the top margin and LINES, so the text block holds exactly 30 lines of 13.8 pt and every full page ends on the same baseline, as pages 10 and 11 do. With mirror: true the 15 mm inner margin stays at the spine and the 14 mm outer one at the fore-edge on both pages of a spread (mirrored margins), and the 86 mm measure holds about 57 characters of Gentium Book Plus at 10 pt.
#3 · The chapter in words and a raised initial
const [LABEL_Y, RULE_Y, TITLE_Y] = [4, 10.5, 13.5]; // mm below the top of the text block
const SINK = 8; // lines of LEAD above the text: the chapter drops a quarter of the page
const INITIAL = 3 * LEAD; // pt: the initial's size, three leads
const RISE = 2; // lines of LEAD the raised initial keeps clear above the first line
const centred = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });
const opener = {
enabled: true,
slot: { elements: [
// The ordinal is written in the heading, # Perdido {ordinal="primero"}: the plate before
// the chapter is a level-1 heading too, so the level carries no counter.
{ kind: 'text', id: 'chapter', content: 'capítulo {attr.ordinal}', ...smallCaps,
placement: centred(LABEL_Y) },
{ kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6),
color: col('oxblood'), placement: { ...centred(RULE_Y), size: { width: mm(9) } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, italic: true,
fontSize: pt(26), lineHeight: 1.1, color: col('ink'), align: 'center',
overflow: 'wrap', // a longer title takes a second line
placement: centred(TITLE_Y) },
] },
// The text starts SINK lines down; the initial's rise takes the last RISE of them.
minHeight: pt((SINK - RISE) * LEAD),
};
// parity 'any': each chapter opens on the next page, as pocket books do.
// marginBottom replaces the level's default, a blank line of its own. The first paragraph
// of the chapter opens with a raised initial: lines: 1 stands it on the first baseline,
// three leads tall, and the paragraph keeps its rise clear above it.
const chapter = { level: 1, breakBefore: { enabled: true, parity: 'any' },
marginBottom: pt(0), advancedDesign: opener,
dropCap: { lines: 1, fontFamily: DISPLAY, fontWeight: 700, fontSize: pt(INITIAL),
color: col('oxblood') } };
capítulo primero comes from the heading’s own ordinal attribute (heading attributes). A level numbered with '{1:ordinal}' would spell the word out by itself, but the plate before the chapter is a level-1 heading too, so this level carries no counter. The initial belongs to the chapter level: its dropCap opens the first paragraph after every level-1 heading, and the paragraph is written in the Markdown as it reads (drop caps). lines: 1 with a fontSize of three leads makes it a raised initial, standing on the first baseline; the first line is shortened by its width and the default gap, and justified with the rest of the paragraph. The letter rises above the first line, and the paragraph keeps that rise clear above it in whole lines: two here (RISE), so minHeight ends the opener at SINK - RISE lines and the first line of text still falls on line SINK, a quarter of the way down. The chapter level’s marginBottom: 0 replaces the default margin, which would add a blank line. A paragraph with a drop cap drops its first-line indent.

#4 · The map faces the chapter as Figura 1
const MAP_H = 112; // mm: a frontispiece map, the measure wide
const resources = [{
id: 'plano', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
svg: { fileId: 'plano.svg', width: MEASURE, height: MAP_H }, // the ratio: set column-wide
placement: { position: 'here' }, // where ::resource{id="plano"} stands, not a float
caption: 'El camino de Golfín: de Villafangosa, por la pasadera y el cerro, al talud de '
+ 'las minas de Socartes.',
note: 'Plano conjetural dibujado para esta edición a partir del capítulo primero.',
altText: 'Plano: abajo, la villa, el río y la pasadera; en medio, un cerro arbolado; arriba, '
+ 'las minas en gradas. Un punteado lleva de la villa al talud de las minas.',
}];
// The plate's heading, # Las minas de Socartes {style="lamina"}, opens a page the heads skip.
const frontispiece = {
id: 'lamina', // its own break, or it takes the chapter's (gotcha: style-inherits-break)
breakBefore: { enabled: true, parity: 'any' }, marginBottom: pt(0),
footer: { elements: [] }, // no drop folio
advancedDesign: { enabled: true, slot: { elements: [{ kind: 'text', id: 'name',
content: '{titleText}', ...smallCaps, // a line down: the plate centres on the page
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: pt(LEAD) } } }] } },
};
const captionStyle = { fontFamily: TEXT, fontSize: pt(8.3), gap: mm(2),
labelColor: col('oxblood'), descriptionItalic: true, note: { color: col('muted') } };
position: 'here' sets the map where ::resource{id="plano"} stands, under a heading of its own. That heading makes book page 8 an opener, and the running heads skip openers. Its style empties the footer and sets its own break, which keeps the plate opposite chapter I, with no head or folio, even when chapters open on rectos (heading styles). The Spanish types of the short answer print Figura 1. under the map (with no resourceTypes it reads Figura 1.1, numbered by chapter) and Fig. 1 in the text, which case="lower" in the Markdown’s :ref turns into fig. 1. The reference sits in square brackets, which Spanish editions use to mark what the editor adds to the author’s text.
#5 · The author on the verso, the title on the recto
const [HEAD_Y, DROP_Y] = [9, -10]; // mm: heads from the top edge, drop folio from the foot
const head = (id, content, parity, edge, x, y = HEAD_Y, pages = 'body') => ({
kind: 'text', id, content, parity, pages, // running heads skip the openers
fontFamily: LABEL, fontSize: pt(8), letterSpacing: pt(1.2), color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(y) } },
});
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre is off the page's centre
// Folios in the text face (Marcellus SC's 1 and 0 read as I and O), on the heads' baseline.
const folio = { fontFamily: TEXT, 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,
DROP_Y, 'opener'), ...folio }); // a chapter can open on either side of the spread
const footer = { elements: [drop('odd', SHIFT), drop('even', -SHIFT)] };
parity: 'even' puts the author on versos and 'odd' the title on rectos, and pages: 'body' keeps both off the opener, where the only furniture is the drop folio set with pages: 'opener'. Each head is anchored to the page and moved by SHIFT onto the centre of the text block, which sits half a millimetre off the page’s centre because the inner and outer margins differ. The drop folio comes in two parities for the same reason. The folios are set in Gentium, because Marcellus SC draws 1 and 0 like I and O.
#6 · Spanish punctuation in the Markdown
const paragraphStyles = [
{ id: 'asterismo', fontFamily: DISPLAY, fontSize: pt(11), color: col('oxblood'),
textAlign: 'center' },
// In ink: a muted note would need italicColor too, for its italic Marianela.
{ id: 'nota', fontSize: pt(8.3), lineHeight: pt(LEAD * 0.8), firstLineIndent: pt(0),
marginTop: pt(LEAD) },
{ id: 'colofon', fontSize: pt(7.5), color: col('muted'), textAlign: 'center',
firstLineIndent: pt(0), marginTop: pt(LEAD / 2) },
];
Page 12, the last, ends with three paragraph styles. The asterisks, in oxblood Bodoni, are centred after a :::space{lines=2}, since blank lines add no space. The edition’s note is 8.3 pt on 11 pt leading, and the colophon is 7.5 pt in the grey of the running heads. The note stays in ink; set it in grey and the style needs an italicColor as well, or the italic Marianela prints darker than the words around it. In the Markdown, dialogue opens with a raya (—), never a hyphen, because a hyphen and a space at the start of a line open a list. 1878. at the start of the note would open a numbered list, so a word joiner (U+2060) goes before the year. The asterisks are escaped (\*); unescaped, the first would open a bullet list and the other two an italic run, and the line would vanish.
The whole recipe
// ═══ Postext Cookbook · Nº 016 · Justified Spanish in a pocket novel ═════════════════
// https://postext.dev/en/cookbook/spanish-pocket-novel
// Code: MIT · Text: B. Pérez Galdós, Marianela, 1878 (PD, Gutenberg #17340) · Map: drawn in code
// Fonts: Gentium Book Plus, Libre Bodoni, Marcellus SC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, renderPageToCanvas, defaultResourceTypes, registerResourceImage,
inlineSvgFonts,
} from 'https://esm.sh/postext';
const LANG = 'es'; // @lang: the language of the sample document (this recipe is Spanish only)
const RECIPE = 'spanish-pocket-novel';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1e1b18', // text: a warm near-black
oxblood: '#8b2e2a', // the one accent: chapter label, rule, initial, asterisks, route
muted: '#6d645a', // running heads, the map's paths, the caption's credit
paper: '#f7f2e8', // an ivory book paper
slag: '#c8553d', moss: '#6f7a4f', water: '#58707f', // the map: mined earth, woods, river
};
// col(id): a colour linked to its palette entry, in text styles and design slots alike.
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: 'oxblood (defaults)', value: { hex: palette.oxblood, model: 'hex' } },
];
const TEXT = 'Gentium Book Plus'; // the text face
const DISPLAY = 'Libre Bodoni'; // the chapter's title and the initial
const LABEL = 'Marcellus SC'; // small capitals: chapter label, running heads, map names
const [BODY, LEAD] = [10, 13.8]; // pt: the body size, and its leading: the grid's pitch
const smallCaps = { fontFamily: LABEL, fontSize: pt(9), letterSpacing: pt(1.6), // 2 labels
color: col('oxblood'), align: 'center' };
// #region page: a pocket paperback; the text block holds 30 whole lines
const TRIM = { width: 115, height: 180 }; // mm: 11.5 × 18 cm
const [TOP, INNER, OUTER] = [16, 15, 14]; // mm: a pocket page keeps its margins tight
const LINES = 30; // lines of LEAD per page, so every full page ends on the same line
const MEASURE = TRIM.width - INNER - OUTER; // 86 mm: about 57 characters of Gentium at 10 pt
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 * LEAD * 25.4) / 72),
left: mm(INNER), right: mm(OUTER), mirror: true }, // left is inner on a recto
};
// #endregion
// #region answer: Spanish syllables, word spaces under 1.7×, captions that say Figura
const LOCALE = 'es'; // config().locale: Spanish hyphenation, and Spanish caption labels
const bodyText = { // config().bodyText
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
#Open every chapter on a recto
With 'odd', a chapter that would start on a verso gets a blank page before it, as in a roomier edition. Chapter I already opens on a recto, and the plate keeps its page because its style sets its own break.
-const chapter = { level: 1, breakBefore: { enabled: true, parity: 'any' },
+const chapter = { level: 1, breakBefore: { enabled: true, parity: 'odd' },#Number the figures by chapter
Left as they come, the built-in Spanish types number figures within each first-level heading: the map becomes Figura 1.1 and the reference fig. 1.1.
-const resourceTypes = defaultResourceTypes(LOCALE)
- .map((type) => ({ ...type, numberingTemplate: '{n}', resetOn: 'never' }));
+const resourceTypes = defaultResourceTypes(LOCALE);Pitfalls
Pitfall
'1998. ' or '- ' at a paragraph start opens a list
A paragraph that starts with a number, a period and a space, or with a hyphen and a space, becomes a list item. Put a word joiner (U+2060) before the number, and write dialogue with an em dash. Escapes and literal characters →
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 →
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 →
- A sink of nine lines instead of eight left page 11 one line short, because
avoidWidowswould not start a paragraph on the last line of the page. After any change to the settings or the text, check the foot of every page. RISEis the number of lines the raised initial keeps clear above the text. Another face or size changes that rise: a smaller initial may need one line, and the text then starts a line higher unlessminHeightchanges with it.- None of these faces has the asterism ⁂ (U+2042) in its Fontsource latin file, so the browser would take it from a system font. Spanish books mark the break with three spaced asterisks in any case.
Credits
- Recipe
- Ignacio Ferro
- Text
- Marianela (1878), the opening of chapter I, “Perdido”, with today’s spelling and punctuation · Benito Pérez Galdós · public domain
- The edition’s note and the map’s caption · Postext Cookbook · original
- Images
- The conjectural map of the Socartes mines, drawn in code in the page’s palette · Ignacio Ferro · MIT
- Fonts
- Gentium Book Plus (SIL OFL 1.1) · Libre Bodoni (SIL OFL 1.1) · Marcellus SC (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


