Skip to main content
Recipe number 93

Cookbook · Chapter 5 · Book structure

One text in four citation styles

One short essay with six citations, built in APA 7, Chicago author-date, IEEE and ISO 690: the style setting is the only thing that changes.

On this page
Output
Canvas
Postext
Tested with Postext 1.65.0
Needs ≥ 1.34.0
Licence
Updated 16 Oct 2026
Code MIT · Text CC BY 4.0

pp. 1–1 · 1–2 of 4

  • Trim 155 × 235 mm
  • 1 column
  • Source Serif 4 10/14
  • Source Sans 3
  • 4 pages
  • Level
  • Postext 1.57.1
  • Laid out in 271 ms
  • 116 lines of code

In short

The same two paragraphs about typography, with the same sources, printed four times. Each page uses a different way of citing sources, and the citations and the list at the end change with it, though the text was written once.

What you'll build

A two-paragraph essay on why good typography goes unnoticed, with six sources: a narrative citation, one with a page, one that leaves the author out because the sentence names him, and two works cited together. The text is set four times on a 155 × 235 mm page, and the only change between the four builds is citations.style: APA 7, Chicago author-date, IEEE and ISO 690. Each page carries the style's name in a band of its own colour, so laid side by side they read as a comparison chart. The citations change form, order and punctuation, the list changes its sorting and its names, and the essay itself is the same file.

This recipe answers

  • How do I change a book from one citation style to another without touching the text?
  • How do I cite works and build the bibliography in APA, IEEE or another citation style?

The short answer

script.js · lines 28–47in full code
// 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' },
});

The style is one setting; everything else stays the same

Ingredients

Type
Source Serif 4, Source Sans 3 (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · One setting

The code is the short answer above. The citations are written once in the content, in Pandoc's syntax, and the references sit in a BibTeX block at the end. citations.style names a CSL style, and citeproc-js writes every citation and every entry from it: APA puts a comma before the year and sorts two works by author, Chicago keeps the order in which they were written, IEEE turns them into numbers in order of first citation, ISO 690 sets the surnames in the list in capitals. For a book in progress this is the whole change: one value in the config, and the text is not touched.

#2 · Four builds, two spreads

script.js · lines 150–157in full code
// 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)));
}

The style holds for the whole document, so the four versions are four builds of the same Markdown. Each gets a pageIndexOffset one higher than the last, which makes its page the next page of an imaginary book; the desk then pairs them as two spreads, the two author-date styles that differ least beside each other.

#3 · The style's name in a band

script.js · lines 51–74in full code
// 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' } } },
  ] },
});

The heading's design draws the band from the trim, the kicker with the style's number and system, and the name at 54 pt. The name and the system come from the script, not from the Markdown, because the text is the same in all four documents.

script.js · lines 15–22in full code
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' } }));

Each document points main-color at its own band, so the four colours are linked palette entries, and any default the config leaves unstated follows the band of its page.

The whole recipe

Sandbox
// ═══ 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

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

#Try a note style

With Chicago notes and bibliography, each citation becomes a footnote and the list a bibliography; the text still does not change.

-  { 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' },

#Write the numbers as superscripts

A numbered style can keep its list and print the citations as superscript numbers, as Nature and Vancouver do.

-  link: true,
+  link: true, marker: 'superscript',

Pitfalls

  • A locator is written once and each style prints its own word for it: "p. 17" in all four here. The bundled ISO 690 Spanish style prints "p." for every kind of locator, a section or a chapter included, so this text cites a page.
  • Edition numbers belong in BibTeX as numbers (edition = {3}): each style then writes "3rd ed.", "3.ª ed." or "3." in its own way. Written as "3rd", the word is printed as it stands and the style's own form is lost.

Credits

Text
Original prose, CC BY 4.0
Fonts
Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)
Sandbox