In breve
Gli stessi due paragrafi sulla tipografia, con le stesse fonti, stampati quattro volte. Ogni pagina usa un modo diverso di citare le fonti, e con esso cambiano le citazioni e l’elenco finale, anche se il testo è scritto una volta sola.
Che cosa comporrai
Un saggio di due paragrafi sul perché la buona tipografia passa inosservata, con sei fonti: una citazione narrativa, una con la pagina, una che omette l’autore perché la frase lo nomina, e due opere citate insieme. Il testo è composto quattro volte su una pagina di 155 × 235 mm, e l’unica differenza tra le quattro costruzioni è citations.style: APA 7, Chicago autore-data, IEEE e ISO 690. Ogni pagina riporta il nome dello stile in una fascia di un colore proprio, così, affiancate, si leggono come una tabella di confronto. Le citazioni cambiano forma, ordine e punteggiatura, la lista cambia ordinamento e nomi, e il saggio è sempre lo stesso file.
Questa ricetta risponde a
- Come passo un libro da uno stile citazionale a un altro senza toccare il testo?
- Come cito le opere e costruisco la bibliografia in APA, IEEE o un altro stile citazionale?
La risposta breve
// 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' },
});
Ingredienti
- Funzionalità
- Citazioni in uno stile citazionaleBibliografia dai riferimentiAperture progettateTavolozza di colori semantica
- Usa anche
- Attributi dei titoli
- Tipo
- Source Serif 4, Source Sans 3 (SIL OFL 1.1)
- Risorse
- Nessuna: ogni immagine è disegnata nel codice
Preparazione
#1 · Una sola impostazione
Il codice è nella risposta breve qui sopra. Le citazioni si scrivono una volta sola nel contenuto, con la sintassi di Pandoc, e i riferimenti stanno in un blocco BibTeX alla fine. citations.style indica uno stile CSL, e citeproc-js scrive da esso ogni citazione e ogni voce: APA mette una virgola prima dell’anno e ordina due opere per autore, Chicago mantiene l’ordine in cui sono state scritte, IEEE le trasforma in numeri in ordine di prima citazione, ISO 690 mette in maiuscolo i cognomi della lista. Per un libro in lavorazione questo è tutto il cambiamento: un valore nella configurazione, e il testo non si tocca.
#2 · Quattro costruzioni, due doppie pagine
// 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)));
}
Lo stile vale per l’intero documento, quindi le quattro versioni sono quattro costruzioni dello stesso Markdown. Ciascuna riceve un pageIndexOffset più alto di uno rispetto alla precedente, il che fa della sua pagina la pagina successiva di un libro immaginario; il tavolo le accoppia poi in due doppie pagine, con affiancati i due stili autore-data che differiscono meno.
#3 · Il nome dello stile in una fascia
// 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' } } },
] },
});
La grafica del titolo disegna la fascia dal rifilo, l’occhiello con il numero e il sistema dello stile, e il nome in corpo 54. Il nome e il sistema vengono dallo script, non dal Markdown, perché il testo è lo stesso in tutti e quattro i documenti.
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' } }));
Ogni documento punta main-color sulla propria fascia, così i quattro colori sono voci collegate della tavolozza, e ogni valore predefinito che la configurazione non dichiara segue la fascia della sua pagina.
La ricetta 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 = 'en'; // @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
Lo script.js composto funziona così com’è: incollalo nello script modulo di qualsiasi pagina, oppure apri la ricetta su CodePen. Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)
Varianti
#Prova uno stile a note
Con Chicago note e bibliografia, ogni citazione diventa una nota a piè di pagina e la lista una bibliografia; il testo continua a non cambiare.
- { 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: 'notes' },#Scrivi i numeri in esponente
Uno stile numerico può mantenere la sua lista e stampare le citazioni come numeri in esponente, come fanno Nature e Vancouver.
- link: true,
+ link: true, marker: 'superscript',Errori frequenti
- Un localizzatore si scrive una volta e ogni stile stampa la propria parola per esso: qui «p. 17» in tutti e quattro. Lo stile ISO 690 spagnolo incluso stampa «p.» per ogni tipo di localizzatore, sezione e capitolo compresi, quindi questo testo cita una pagina.
- I numeri di edizione vanno in BibTeX come numeri (
edition = {3}): ogni stile scrive allora «3rd ed.», «3.ª ed.» o «3.» a modo suo. Scritto come «3rd», la parola si stampa così com’è e la forma propria dello stile va persa.
Crediti
- Ricetta
- Ignacio Ferro
- Testo
- Testo originale, CC BY 4.0
- Font
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)
- Codice
- MIT, come Postext
Modifica questo testo ↗ (si apre in una nuova scheda)Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)


