En poques paraules
Els mateixos dos paràgrafs sobre tipografia, amb les mateixes fonts, impresos quatre vegades. Cada pàgina fa servir una manera diferent de citar, i les citacions i la llista final hi canvien, tot i que el text es va escriure un sol cop.
Què compondràs
Un assaig de dos paràgrafs sobre per què la bona tipografia passa inadvertida, amb sis fonts: una citació narrativa, una amb pàgina, una que omet l'autor perquè la frase ja l'anomena i dues obres citades juntes. El text es compon quatre vegades en una pàgina de 155 × 235 mm, i l'únic que canvia entre les quatre composicions és citations.style: APA 7, Chicago autor-any, IEEE i ISO 690. Cada pàgina porta el nom de l'estil en una banda del seu propi color, de manera que, posades l'una al costat de l'altra, es llegeixen com una taula comparativa. Les citacions canvien de forma, d'ordre i de puntuació, la llista canvia d'ordre i de noms, i l'assaig és el mateix fitxer.
Aquesta recepta respon a
- Com passo un llibre d'un estil de cita a un altre sense tocar el text?
- Com cito obres i componc la bibliografia en APA, IEEE o un altre estil de cita?
La resposta curta
// 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' },
});
Ingredients
- Funcions
- Cites en un estil de citaBibliografia a partir de les referènciesObertures dissenyadesPaleta de color semàntica
- També fa servir
- Atributs de títol
- Tipografia
- Source Serif 4, Source Sans 3 (SIL OFL 1.1)
- Recursos
- Cap: totes les imatges es dibuixen en codi
Elaboració
#1 · Una sola opció
El codi és la resposta curta de més amunt. Les citacions s'escriuen una vegada al contingut, amb la sintaxi de Pandoc, i les referències van en un bloc BibTeX al final. citations.style indica un estil CSL, i citeproc-js l'utilitza per escriure cada citació i cada entrada: APA posa coma abans de l'any i ordena dues obres per autor, Chicago respecta l'ordre en què es van escriure, IEEE les converteix en números per ordre de primera citació, ISO 690 posa en majúscules els cognoms de la llista. En un llibre en curs, el canvi és aquest: un valor de la configuració, sense tocar el text.
#2 · Quatre composicions, dos plecs
// 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)));
}
L'estil val per a tot el document, així que les quatre versions són quatre composicions del mateix Markdown. Cadascuna rep un pageIndexOffset una unitat més gran que l'anterior, que converteix la seva pàgina en la següent d'un llibre imaginari; la taula les aparella llavors en dues dobles pàgines, amb els dos estils autor-any que menys es diferencien l'un al costat de l'altre.
#3 · El nom de l'estil 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 disseny del títol dibuixa la banda des del tall, l'avanttítol amb el número i el sistema de l'estil, i el nom a 54 pt. El nom i el sistema surten de l'script i no del Markdown, perquè el text és el mateix als quatre documents.
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 document apunta main-color a la seva pròpia banda, així que els quatre colors són entrades enllaçades de la paleta, i qualsevol valor per defecte que la configuració no fixi segueix la banda de la seva pàgina.
La recepta 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
L'script.js compost funciona tal com és: enganxa'l com a script de mòdul en qualsevol pàgina o obre la recepta a CodePen. Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)
Variants
#Prova un estil de notes
Amb Chicago notes i bibliografia, cada citació es converteix en una nota a peu de pàgina i la llista en una bibliografia; el text continua sense canviar.
- { 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' },#Escriu els números volats
Un estil numèric pot conservar la seva llista i imprimir les citacions com a números volats, com fan Nature i Vancouver.
- link: true,
+ link: true, marker: 'superscript',Errors freqüents
- El localitzador s'escriu una vegada i cada estil imprimeix la seva pròpia paraula: aquí, «p. 17» als quatre. L'estil ISO 690 en castellà que porta el motor imprimeix «p.» per a qualsevol localitzador, també per a una secció o un capítol, i per això aquest text cita una pàgina.
- El número d'edició va a BibTeX com a número (
edition = {3}): així cada estil escriu «3rd ed.», «3.ª ed.» o «3.» a la seva manera. Escrit com a «3rd», s'imprimeix tal qual i es perd la forma pròpia de l'estil.
Crèdits
- Recepta
- Ignacio Ferro
- Text
- Text original, CC BY 4.0
- Fonts
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)
- Codi
- MIT, com Postext
Editar aquest text ↗ (s'obre en una pestanya nova)Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)


