En pocas palabras
Los mismos dos párrafos sobre tipografía, con las mismas fuentes, impresos cuatro veces. Cada página usa una manera distinta de citar, y las citas y la lista final cambian con ella, aunque el texto se escribió una sola vez.
Lo que vas a componer
Un ensayo de dos párrafos sobre por qué la buena tipografía pasa inadvertida, con seis fuentes: una cita narrativa, una con página, una que omite el autor porque la frase ya lo nombra y dos obras citadas juntas. El texto se compone cuatro veces en una página de 155 × 235 mm, y lo único que cambia entre las cuatro composiciones es citations.style: APA 7, Chicago autor-año, IEEE e ISO 690. Cada página lleva el nombre del estilo en una banda de su propio color, de modo que, puestas una junto a otra, se leen como una tabla comparativa. Las citas cambian de forma, de orden y de puntuación, la lista cambia de orden y de nombres, y el ensayo es el mismo archivo.
Esta receta responde a
- ¿Cómo paso un libro de un estilo de cita a otro sin tocar el texto?
- ¿Cómo cito obras y compongo la bibliografía en APA, IEEE u otro estilo de cita?
La respuesta corta
// Citations are written once, Pandoc's way: [@key], [@a; @b], [-@key] without the author,
// @key [p. 17] inside the sentence. citeproc-js writes them, and the list, in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const SHOWN = [ // the same text, built once per entry
{ style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'chicago-author-date', band: 'chicago', name: 'Chicago',
system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'ieee', band: 'ieee', name: 'IEEE', system: t({ en: 'numbered', es: 'numérico' }) },
{ style: t({ en: 'iso690-author-date-en', es: 'iso690-author-date-es' }), band: 'iso',
name: 'ISO 690', system: t({ en: 'author-date', es: 'autor-año' }) },
];
const citations = (style) => ({
style, // 'apa' → '(Warde, 1955)'; 'ieee' → '[1]'; the list is sorted and set to match
link: true,
// The authors' names stay whole in the citations, the text and the list: the APA build
// set '(Lup-' | 'ton, 2010)'.
hyphenateNames: false,
bibliography: { fontSize: em(0.85), lineHeight: pt(11.2), hangingIndent: mm(6),
entrySpacing: pt(2), labelWidth: mm(6), doi: 'hide' },
});
Ingredientes
- Funciones
- Citas en un estilo de citaBibliografía a partir de las referenciasAperturas diseñadasPaleta de color semántica
- También usa
- Atributos de título
- Tipografía
- Source Serif 4, Source Sans 3 (SIL OFL 1.1)
- Recursos
- Ninguno: todas las imágenes se dibujan en código
Elaboración
#1 · Un solo ajuste
El código es la respuesta corta de arriba. Las citas se escriben una vez en el contenido, con la sintaxis de Pandoc, y las referencias van en un bloque BibTeX al final. citations.style elige un estilo CSL, y citeproc-js escribe con él cada cita y cada entrada: APA pone coma antes del año y ordena dos obras por autor, Chicago respeta el orden en que se escribieron, IEEE las convierte en números por orden de primera cita, ISO 690 pone en mayúsculas los apellidos de la lista. En un libro en marcha, el cambio es este: un valor de la configuración, sin tocar el texto.
#2 · Cuatro composiciones, dos pliegos
// The style is set for the whole document, so each style is a build of its own.
const docs = [];
for (at = 0; at < SHOWN.length; at++) {
// pageIndexOffset makes each page the next one of a book, so the desk pairs them:
// APA beside Chicago, IEEE beside ISO 690.
const content = { markdown, continuation: { pageIndexOffset: at + 1 } };
docs.push(await buildDocumentWithFonts(content, config(), kitFonts(FONTS)));
}
El estilo vale para todo el documento, así que las cuatro versiones son cuatro composiciones del mismo Markdown. Cada una recibe un pageIndexOffset una unidad mayor que la anterior, que convierte su página en la siguiente de un libro imaginario; la mesa las empareja entonces en dos dobles páginas, con los dos estilos autor-año que menos se diferencian uno al lado del otro.
#3 · El nombre del estilo en una banda
// The kicker names the build's citation style: a label of the design (#849).
const kicker = (s, i) => `${t({ en: 'Citation style', es: 'Estilo de cita' })}`
+ ` · ${i + 1} / ${SHOWN.length} · ${s.system}`;
const opener = (s, i) => ({
enabled: true,
minHeight: mm(41), // from the top margin to under the title, 63 mm from the trim
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col(s.band) },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(44) } } },
{ kind: 'text', id: 'kicker', content: kicker(s, i), fontFamily: SANS, fontSize: pt(8),
fontWeight: 600, letterSpacing: pt(1.4), textTransform: 'uppercase', color: col('paper'),
align: 'left',
placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(18), y: mm(12) } } },
{ kind: 'text', id: 'name', content: s.name, fontFamily: SERIF, fontSize: pt(54),
fontWeight: 600, lineHeight: 1, color: col('paper'), align: 'left', overflow: 'clip',
placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { x: mm(0), y: mm(5) },
size: { width: mm(119), height: 'auto' } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: SERIF, fontSize: pt(20),
fontWeight: 600, lineHeight: 1.15, color: col('ink'), align: 'left', overflow: 'wrap',
placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(18), y: mm(52) },
size: { width: mm(119), height: 'auto' } } },
] },
});
El diseño del encabezado dibuja la banda desde el corte, el antetítulo con el número y el sistema del estilo, y el nombre a 54 pt. El nombre y el sistema salen del script y no del Markdown, porque el texto es el mismo en los cuatro documentos.
const palette = {
ink: '#1d1b19', muted: '#66605a', rule: '#cfc8bf', paper: '#ffffff',
apa: '#2f5d8a', chicago: '#8c2f2b', ieee: '#24476b', iso: '#3c6b4f', // the four bands
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Each document points main-color at its own band, so any default left follows it.
const colorPalette = (band) => Object.entries({ ...palette, 'main-color': palette[band] })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
Cada documento apunta main-color a su propia banda, así que los cuatro colores son entradas enlazadas de la paleta, y cualquier valor por defecto que la configuración no fije sigue la banda de su página.
La receta completa
// ═══ Postext Cookbook · Nº 093 · One text in four citation styles ════════════════
// https://postext.dev/en/cookbook/one-text-four-citation-styles
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Source Serif 4, Source Sans 3 (SIL OFL 1.1) · Needs postext ≥ 1.34.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine,
} from 'https://esm.sh/postext';
import { createCiteprocEngine, STYLES, LOCALES } from 'https://esm.sh/postext-citeproc';
const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'one-text-four-citation-styles';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink, and a colour for each style's band
const palette = {
ink: '#1d1b19', muted: '#66605a', rule: '#cfc8bf', paper: '#ffffff',
apa: '#2f5d8a', chicago: '#8c2f2b', ieee: '#24476b', iso: '#3c6b4f', // the four bands
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Each document points main-color at its own band, so any default left follows it.
const colorPalette = (band) => Object.entries({ ...palette, 'main-color': palette[band] })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [SERIF, SANS] = ['Source Serif 4', 'Source Sans 3'];
const LEAD = 14; // pt
// #region answer: the style is one setting; everything else stays the same
// Citations are written once, Pandoc's way: [@key], [@a; @b], [-@key] without the author,
// @key [p. 17] inside the sentence. citeproc-js writes them, and the list, in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const SHOWN = [ // the same text, built once per entry
{ style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'chicago-author-date', band: 'chicago', name: 'Chicago',
system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'ieee', band: 'ieee', name: 'IEEE', system: t({ en: 'numbered', es: 'numérico' }) },
{ style: t({ en: 'iso690-author-date-en', es: 'iso690-author-date-es' }), band: 'iso',
name: 'ISO 690', system: t({ en: 'author-date', es: 'autor-año' }) },
];
const citations = (style) => ({
style, // 'apa' → '(Warde, 1955)'; 'ieee' → '[1]'; the list is sorted and set to match
link: true,
// The authors' names stay whole in the citations, the text and the list: the APA build
// set '(Lup-' | 'ton, 2010)'.
hyphenateNames: false,
bibliography: { fontSize: em(0.85), lineHeight: pt(11.2), hangingIndent: mm(6),
entrySpacing: pt(2), labelWidth: mm(6), doi: 'hide' },
});
// #endregion
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
#Prueba un estilo de notas
Con Chicago notas y bibliografía, cada cita se convierte en una nota al pie y la lista en una bibliografía; el texto sigue sin cambiar.
- { style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
+ { style: 'chicago-notes-bibliography', band: 'apa', name: 'Chicago', system: 'notas' },#Escribe los números volados
Un estilo numérico puede conservar su lista e imprimir las citas como números volados, como hacen Nature y Vancouver.
- link: true,
+ link: true, marker: 'superscript',Errores frecuentes
- El localizador se escribe una vez y cada estilo imprime su propia palabra: aquí, «p. 17» en los cuatro. El estilo ISO 690 en español que trae el motor imprime «p.» para cualquier localizador, también para una sección o un capítulo, y por eso este texto cita una página.
- El número de edición va en BibTeX como número (
edition = {3}): así cada estilo escribe «3rd ed.», «3.ª ed.» o «3.» a su manera. Escrito como «3rd», se imprime tal cual y se pierde la forma propia del estilo.
Créditos
- Receta
- Ignacio Ferro
- Texto
- Texto original, CC BY 4.0
- Fuentes
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (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)


