En pocas palabras
Las últimas páginas de una tesis doctoral, del capítulo final al índice. Postext crea el índice a partir de palabras marcadas en el texto y pone sus números de página.
Lo que vas a componer
Las siete últimas páginas de una tesis doctoral sobre la lectura en pantalla y en papel, en formato B5 y en blanco y negro. El capítulo 6, el apéndice A, el glosario, la bibliografía y el índice alfabético abren bajo la misma banda negra de 62 mm, con el título calado en blanco. El capítulo lleva su numeral en la banda; el apéndice, su letra; y las secciones finales, el antetítulo BACK MATTER y una nota breve en cursiva. El capítulo va a una columna justificada. El glosario y el índice pasan a dos columnas en bandera y la bibliografía vuelve a una, con las líneas de continuación de cada entrada sangradas. El índice sale de marcas en el texto: el motor ordena los términos bajo su letra, busca la página de cada marca y agrupa las seguidas en tramos como 171–73. Los números en negrita remiten a las definiciones del glosario.
Esta receta responde a
- ¿Cómo compongo una bibliografía o un glosario (sangría francesa, cuerpo menor)?
- ¿Cómo hago un índice analítico cuyos números de página cambien solos cuando el texto se mueve?
- ¿Cómo evito que los títulos, las negritas y las viñetas salgan en azul?
- ¿Cómo numero los títulos (1, 1.1, 1.1.1) y doy a cada nivel un estilo distinto?
- ¿Cómo pongo cabeceras: el título del libro en la página izquierda, el del capítulo en la derecha y el folio por fuera?
- ¿Cómo fuerzo un salto de página o de columna, y hago que cada capítulo empiece en página impar?
La respuesta corta
// '# Glossary {style="glossary"}' in the Markdown picks a style. Each style starts a page
// of either parity, the appendix a recto (a style that sets no break inherits its level's
// 'odd': gotcha style-inherits-break), stays out of the chapter count (numbered: false, so
// its band has no numeral) and brings its own running heads; the glossary and the index
// set their pages in two columns until the next '#'. The appendix counts, in letters: its
// template prints the level's counter as A, B… config() takes both lists below.
const twoColumns = { layoutType: 'double', gutterWidth: mm(6) };
const backMatter = (id, extra) => ({ id, numbered: false, breakBefore: { enabled: true,
parity: 'any' }, advancedDesign: opener('Back matter'), header: sectionHeads, ...extra });
const headingStyles = () => [
backMatter('appendix', { numbered: true, numberingTemplate: '{1:A}', header: appendixHeads,
breakBefore: { enabled: true, parity: 'odd' }, advancedDesign: opener('Appendix') }),
backMatter('glossary', { layout: twoColumns }),
backMatter('references'),
backMatter('index', { layout: twoColumns }),
];
// One paragraph per entry, in :::paragraphs{style="…"}: the turnover lines hang, so the
// first word of every entry stands clear at the left. Ragged, as APA asks of references,
// with every word whole (hyphenation.ragged is off). The index has its own settings.
const entries = (id, size, lead, hang, extra) => ({ id, fontSize: pt(size),
lineHeight: pt(lead), textAlign: 'left', hangingIndent: em(hang), ...extra });
const paragraphStyles = () => [
entries('term', 9.3, 12.4, 1), // the glossary: a bold term, then its definition
entries('reference', 9.3, 12.4, 1.5, { spaceBetween: pt(2.4) }),
];
Ingredientes
- Funciones
- Geometría por secciónBibliografías y glosariosCapítulos sin númeroÍndice analíticoCabeceras por secciónEstilos de títuloTítulos numeradosCapítulos que abren en página imparBanda de capítulo a todo el anchoAperturas diseñadasAtributos de títuloCabeceras según el tipo de páginaEstilos de párrafoTipos de recurso propiosCitas que colocan las figurasTablas a partir de datosEstilo de los piesPaleta de color semánticaNegrita, cursiva y sus coloresExportación a PDF
- También usa
- RecuadrosEquilibrado de columnasFigura y Tabla en tu idiomaSalir de la rejilla a propósitoFuentes incrustadas en el PDF
- Tipografía
- Libertinus Serif, Libertinus Serif Display, Libertinus Sans (SIL OFL 1.1)
- Recursos
- Ninguno: todas las imágenes se dibujan en código
Elaboración
#1 · Un estilo de título para cada parte del final
El código es la respuesta corta de arriba. # Glossary {style="glossary" note="…"} abre una sección que llega hasta el siguiente encabezado de nivel 1, y sus páginas toman la disposición, las cabeceras y la apertura del estilo (estilos de encabezado), de modo que el glosario y el índice pasan a dos columnas y la bibliografía, cuyo estilo no fija disposición, vuelve a la columna única del documento. numbered: false deja estos títulos fuera de la cuenta de capítulos (sin él, en la banda del glosario saldría un 2), y cada estilo declara su salto de página, porque el que no lo declara hereda el 'odd' del capítulo y deja páginas pares en blanco. Las entradas del glosario y de la bibliografía son párrafos de un bloque :::paragraphs{style="…"} en cuerpo 9,3 sobre 12,4 pt, frente al 11 sobre 14,6 del texto, con las líneas de continuación sangradas 1 em en el glosario y 1,5 em en la bibliografía (estilos de párrafo).
#2 · Una sola banda para todas las aperturas
const SINK = 8; // lines reserved, 41.2 mm: 3.2 mm more than the band, and text on the grid
// Design text sets each baseline 0.8 of its line under the line's top, and a line is 1.2 × the
// size unless lineHeight says otherwise. In mm, a line's part above its baseline and below it:
const PT = 25.4 / 72;
const above = (size, lineHeight = 1.2) => 0.8 * size * lineHeight * PT;
const below = (size, lineHeight = 1.2) => 0.2 * size * lineHeight * PT;
const KICKER = 4.3, TITLE = BAND - TOP - 9.5; // mm under the text block's top: two baselines
// A bottom-aligned box that ends below() under a baseline sets its last line on it. The
// numeral's line is 0.72 of its size, so the line fits inside its box.
const text = (id, content, family, size, lineHeight, baseline, edge, w, extra) => ({
kind: 'text', id, content, fontFamily: family, fontSize: pt(size), lineHeight,
color: col('paper'), overflow: 'wrap', align: edge.endsWith('right') ? 'right' : 'left',
verticalAlign: 'bottom', ...extra, placement: { anchor: { to: 'container', edge },
size: { width: mm(w), height: mm(baseline + below(size, lineHeight)) } } });
// The mark is '{number}': the chapter's 6, the appendix's A, nothing on an unnumbered heading.
const opener = (label) => ({ enabled: true, minHeight: pt(SINK * LEAD),
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('band') }, placement: {
anchor: { to: 'page', edge: 'top-left' }, size: { width: 'fill', height: mm(BAND) } } },
text('label', label, LABEL, 8, 1.2, KICKER, 'top-left', 80,
{ fontWeight: 700, letterSpacing: pt(1.6), textTransform: 'uppercase' }),
text('title', '{titleText}', DISPLAY, 34, 1.04, TITLE, 'top-left', 84),
text('mark', '{number}', DISPLAY, 118, 0.72, TITLE, 'top-right', 34),
text('note', '{attr.note}', TEXT, 8.6, 1.3, TITLE, 'top-right', 44, { italic: true }),
] } });
La marca es {number}: un 6 en el capítulo, una A en el apéndice y nada en un título sin numerar. El mismo diseño sirve para los tres, y las secciones finales imprimen su {attr.note} donde iría el numeral. minHeight reserva ocho líneas de 14,6 pt, 41,2 mm desde la cabeza de la caja de texto, que dejan 3,2 mm libres bajo la banda y mantienen el texto en su rejilla. En los textos de diseño, la línea base cae a 0,8 de la altura de línea, de modo que una caja alineada abajo cuyo pie queda a below() de una línea base asienta en ella su última línea. Así, el título, el numeral de 118 pt y la última línea de la nota se apoyan en la línea base del título, a 52,5 mm del corte. La línea del numeral mide 0,72 veces su cuerpo, y así cabe en su caja.
#3 · La letra del apéndice sale de su estilo
// The style's '{1:A}' (see answer) prints the level's counter as a letter, and startAt=1 on the
// first appendix restarts it after chapter 6. The band and the running head read that letter.
// A resource template's {h1} is a number unless it names a style: '{h1:A}.{n}' counts the
// tables A.1, A.2… and B.1 in a second appendix, with one type for all of them.
const appendixHeads = heads('Appendix {chapterNumber}. {chapterTitle}');
const appendixTables = { ...defaultResourceTypes(LANG).find((type) => type.id === 'table'),
id: 'table-a', numberingTemplate: '{h1:A}.{n}', resetOn: 'h1' }; // a copy of 'table'
El estilo del apéndice lleva numberingTemplate: '{1:A}', que imprime el contador del nivel como letra, y # Interview guide {style="appendix" startAt=1} reinicia ese contador, así que el primer apéndice es el A y no el G (estilos de encabezado). La banda lee la letra con {number} y la cabecera con {chapterNumber}. El {h1} de un tipo de recurso imprime el contador como número salvo que nombre un estilo, y por eso las tablas del apéndice llevan un tipo con la plantilla '{h1:A}.{n}': A.1, A.2, etc., y B.1 en un segundo apéndice; con el tipo por defecto, la tabla sería la 1.1. Los títulos del capítulo se numeran con las plantillas de cada nivel: '{1}.{2}' imprime 6.1, y continuation.headings.h1: 5 hace de este el sexto capítulo.
#4 · Las cabeceras, hacia el margen exterior
const HEAD = 17.5, GAP = 9; // mm: the heads' baseline under the trim; the folio to the words
// Each text is placed by its top, above() over HEAD: the folio and the capitals share a baseline.
const head = (id, content, parity, edge, x, size = 7.5, extra) => ({ kind: 'text', id, content,
parity, pages: 'body', fontFamily: LABEL, fontSize: pt(size), fontWeight: 700,
letterSpacing: pt(1.3), textTransform: 'uppercase', color: col('ink'), ...extra, placement: {
anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(HEAD - above(size)) } } });
const folio = { fontFamily: TEXT, fontWeight: 400, letterSpacing: pt(0) };
const heads = (recto) => ({ elements: [
head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, 9.5, folio),
head('verso', '{title}', 'even', 'top-left', OUTER + GAP),
head('recto', recto, 'odd', 'top-right', -(OUTER + GAP)),
head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, 9.5, folio),
// The header's container spans the text block, so one rule serves both pages.
{ kind: 'rule', id: 'hairline', pages: 'body', direction: 'horizontal', thickness: pt(0.5),
color: col('rule'), placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { y: mm(HEAD + 2) }, size: { width: 'fill' } } },
] });
const chapterHeads = heads('Chapter {chapterNumber}. {chapterTitle}');
const sectionHeads = heads('{chapterTitle}'); // 'Glossary', 'References', 'Index'
// Openers drop the folio to the foot, centred under the text block, its baseline 12 mm below.
const footer = { elements: [{ kind: 'text', id: 'drop-folio', content: '{pageNumber}',
pages: 'opener', ...folio, fontSize: pt(9.5), color: col('ink'), align: 'center',
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(12 - above(9.5)) } } }] };
Los cuatro textos se anclan a la página y se filtran por parity, lo que mantiene el folio en el borde exterior de las dos páginas; cada uno se coloca por su borde superior, a above() por encima de una línea base situada a 17,5 mm del corte, así que el folio de 9,5 pt y las mayúsculas de 7,5 pt quedan en la misma línea. La par lleva el título de la tesis ({title}, del frontmatter) y la impar el de la sección ({chapterTitle}), como INDEX en la página 177. pages: 'body' las deja fuera de las aperturas, donde el folio pasa al pie. La impar del capítulo diría Chapter 6. Conclusion y la del apéndice Appendix A. Interview guide, pero en esta muestra solo el índice sigue en una página impar después de su apertura.
#5 · Marca los términos donde el texto habla de ellos
// Glossary definitions carry 'main' (bold numbers); runs of pages join as 171–72 (Chicago).
// The heads stand on the entries' 11.6 pt pitch, 7.5 pt of space above them: 19 pt from the
// last entry of a letter to the next letter's baseline, 11.6 pt from a letter to its first entry.
const index = { fontFamily: TEXT, fontSize: pt(9), lineHeight: pt(11.6), color: col('ink'),
indent: em(1), turnoverIndent: em(2), rangeFormat: 'chicago',
groups: { fontFamily: DISPLAY, fontSize: pt(13), fontWeight: 400, color: col('ink'),
marginTop: pt(7.5) } };
:index[tablet] imprime la palabra y la registra tal cual; Rayner:index{term="Rayner, Keith"} no imprime nada y registra la página de Rayner bajo el nombre completo; term="interviews!timing of" crea una subentrada. Los términos del glosario llevan main, así que su página sale en negrita, como avisa la nota de la banda del índice. :::index, bajo # Index {style="index"}, imprime las entradas en las dos columnas del estilo, y buildDocument vuelve a componer el documento hasta que los números de página dejan de moverse. Las entradas van en cuerpo 9 sobre 11,6 pt, con las líneas de continuación sangradas 2 em y las subentradas 1 em; las letras, en 13 pt con la fuente de titulares. Las marcas no funcionan en las celdas de tabla, así que las filas de la tabla 6.1 no añaden páginas: look-backs remite al párrafo que las comenta, no a la tabla.
#6 · Todos los valores por defecto, en negro
const palette = { ink: '#000000', band: '#000000', rule: '#000000', paper: '#ffffff' };
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Bold, italic and list markers default to 'main-color': pointed at the ink, they print black.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ink })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
La negrita, la cursiva, las viñetas y números de las listas y las referencias siguen por defecto la entrada main-color de la paleta, así que, si le das el color de la tinta, salen en negro y no en azul (paleta de colores). referenceBold: false pone Table 6.1 en redonda, como las citas autor-año que la rodean.
La receta completa
// ═══ Postext Cookbook · Nº 031 · Thesis back matter: appendix, glossary and index ═══
// https://postext.dev/en/cookbook/thesis-back-matter
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Libertinus Serif, Serif Display and Sans (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import {
buildDocumentWithFonts, renderPageToCanvas, defaultResourceTypes,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'thesis-back-matter';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink; every colour is black or white, each under its own name
const palette = { ink: '#000000', band: '#000000', rule: '#000000', paper: '#ffffff' };
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Bold, italic and list markers default to 'main-color': pointed at the ink, they print black.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ink })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TEXT = 'Libertinus Serif', DISPLAY = 'Libertinus Serif Display', LABEL = 'Libertinus Sans';
const TOP = 24, INNER = 25, OUTER = 31; // mm: a 120 mm measure, about 70 characters at 11 pt
const LEAD = 14.6; // pt: the body's leading, the grid every page is set on
const BAND = 62; // mm from the trim's top: the black band at the head of every opener
// #region answer: back matter as unnumbered heading styles, entries in hanging indents
// '# Glossary {style="glossary"}' in the Markdown picks a style. Each style starts a page
// of either parity, the appendix a recto (a style that sets no break inherits its level's
// 'odd': gotcha style-inherits-break), stays out of the chapter count (numbered: false, so
// its band has no numeral) and brings its own running heads; the glossary and the index
// set their pages in two columns until the next '#'. The appendix counts, in letters: its
// template prints the level's counter as A, B… config() takes both lists below.
const twoColumns = { layoutType: 'double', gutterWidth: mm(6) };
const backMatter = (id, extra) => ({ id, numbered: false, breakBefore: { enabled: true,
parity: 'any' }, advancedDesign: opener('Back matter'), header: sectionHeads, ...extra });
const headingStyles = () => [
backMatter('appendix', { numbered: true, numberingTemplate: '{1:A}', header: appendixHeads,
breakBefore: { enabled: true, parity: 'odd' }, advancedDesign: opener('Appendix') }),
backMatter('glossary', { layout: twoColumns }),
backMatter('references'),
backMatter('index', { layout: twoColumns }),
];
// One paragraph per entry, in :::paragraphs{style="…"}: the turnover lines hang, so the
// first word of every entry stands clear at the left. Ragged, as APA asks of references,
// with every word whole (hyphenation.ragged is off). The index has its own settings.
const entries = (id, size, lead, hang, extra) => ({ id, fontSize: pt(size),
lineHeight: pt(lead), textAlign: 'left', hangingIndent: em(hang), ...extra });
const paragraphStyles = () => [
El script.js compuesto funciona tal cual: pégalo como script de módulo en cualquier página o abre la receta en CodePen. Carpeta de la receta en GitHub ↗ (se abre en una nueva pestaña)
Variantes
#Abre cada sección en página impar
Las tesis que se encuadernan para una biblioteca suelen abrir cada sección en página impar. El glosario, la bibliografía y el índice pasan entonces a las páginas 175, 177 y 179, cada una tras una par en blanco, y los números en negrita del índice apuntan a la 175.
-const backMatter = (id, extra) => ({ id, numbered: false, breakBefore: { enabled: true,
- parity: 'any' }, advancedDesign: opener('Back matter'), header: sectionHeads, ...extra });
+const backMatter = (id, extra) => ({ id, numbered: false, breakBefore: { enabled: true,
+ parity: 'odd' }, advancedDesign: opener('Back matter'), header: sectionHeads, ...extra });#Compón también el principio de la tesis
Los preliminares, numerados en romanos antes de la página 1, están en Preliminares con folios romanos y luego la página 1.
Errores frecuentes
Error frecuente
Un estilo de título hereda el salto de página de su nivel
Una entrada de headingStyles toma de su nivel de título todo lo que no fija, también breakBefore. Un índice o un colofón con estilo sobre un H1 tras un :::pagebreak hereda la paridad 'odd' y cae detrás de una página en blanco. Dale a ese estilo breakBefore: { enabled: false }. Estilos de título →
Error frecuente
La página 1 es impar: planifica con números físicos
La página 1 queda a la derecha y la 2 es la primera página par, así que planifica los pliegos con números de página físicos: una apertura en página par queda frente a la impar que la sigue. Saltos de página y de columna →
Créditos
- Receta
- Ignacio Ferro
- Texto
- Texto original, CC BY 4.0
- Fuentes
- Libertinus Serif (SIL OFL 1.1) · Libertinus Serif Display (SIL OFL 1.1) · Libertinus Sans (SIL OFL 1.1)
- Código
- MIT, como Postext
Editar este texto ↗ (se abre en una nueva pestaña)Carpeta de la receta en GitHub ↗ (se abre en una nueva pestaña)


