In short
A chapter of a doctoral thesis. The author writes a short code for each source; Postext prints the citations and the list of references at the end in APA style.
What you'll build
The second chapter of a doctoral thesis in education, the literature review: what twenty years of studies say about reading on paper and on screens. The chapter is set on an A4 page bound at the left, in Literata with a 16 pt lead, under a pale band in the university's blue. The author keeps the sources in Zotero and pastes the export as BibTeX; in the text, each source is a key. Postext formats every citation in APA 7, with the author, the year and the page where one is given, writes "Delgado et al. (2018)" when the name is part of the sentence, and builds the reference list in the order and form the style asks for. When the supervisor asks for Chicago, the style is the one line that changes.
This recipe answers
- How do I cite works and build the bibliography in APA, IEEE or another citation style?
The short answer
// Citations are written [@key, p. 33] and formatted by citeproc-js in the chosen CSL
// style; the references come from the BibTeX block at the end of the chapter. Register
// the engine once, before the first build, then the style is one setting.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = {
style: 'apa', // 'chicago-author-date', 'ieee', 'vancouver'… change nothing else
link: true, // each citation jumps to its entry in the PDF and on screen
bibliography: {
// APA asks for a half-inch hanging indent and keeps the list in the text size.
fontSize: em(1), hangingIndent: mm(12.7), entrySpacing: pt(4),
doi: 'link', // printed whole, as APA wants, and clickable
},
};
The citation engine, APA 7 and how its references look
Ingredients
- Features
- Citations in a citation styleBibliography from the referencesCross-referencesNumbered headingsHeading stylesUnnumbered chaptersDesigned openersRunning heads and foliosSemantic colour palettePDF export
- Type
- Literata, Public Sans (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · One engine, one style
The code is the short answer above. Postext reads the citations and leaves their wording to a citation engine, registered once before the first build; postext-citeproc wraps citeproc-js, the engine Zotero and Mendeley use, with sixteen CSL styles and their locale files. [@mangen2013] gives "(Mangen et al., 2013)", @delgado2018 without brackets puts the authors in the sentence, and [@ibanez2023, pp. 12–15] carries the page range into the parentheses. With the document in Spanish, the same keys take their connectives and abbreviations from the Spanish locale file, because the engine follows the document's locale.
#2 · The references come from a BibTeX block
The last block of the chapter is :::references{format=bibtex} with the Zotero export pasted inside, accents written as {\'a}. :::bibliography above it places the list under the References heading; without it, Postext appends the list at the end. Only cited works appear, sorted as APA sorts them, and every citation in the text links to its entry.
#3 · A heading without a number, references in words
headingStyles: [{ id: 'references', numbered: false }],
crossRefs: { section: t({ en: 'Section {n}', es: 'Sección {n}' }) },
The references heading takes the references style, which keeps it in the contents but outside the numbering, so the list does not become section 2.4. :ref{id="sec-speed"} prints "Section 2.2" from the crossRefs label and links to the heading; the numbers come from startAt=2 on the chapter title, the same counter the headings use.
#4 · The opener sits in a band
const BAND = 92; // mm from the trim's top
const opener = {
enabled: true,
minHeight: mm(BAND - 28 + 10), // the body starts 10 mm under the band
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('tint') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(BAND) } } },
{ kind: 'text', id: 'label', content: t({ en: 'Chapter', es: 'Capítulo' }),
fontFamily: LABEL, fontSize: pt(9), fontWeight: 600, letterSpacing: pt(1.8),
textTransform: 'uppercase',
color: col('accent'), align: 'left',
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(0), y: mm(2) } } },
{ kind: 'text', id: 'number', content: '{number}', fontFamily: TEXT, fontSize: pt(96),
fontWeight: 300, lineHeight: 0.9, color: col('accent'), align: 'right',
placement: { anchor: { to: 'container', edge: 'top-right' },
offset: { x: mm(0), y: mm(-6) },
size: { width: mm(40), height: 'auto' } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: TEXT, fontSize: pt(24),
lineHeight: 1.12, fontWeight: 600, color: col('ink'), align: 'left', overflow: 'wrap',
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(0), y: mm(14) },
size: { width: mm(108), height: 'auto' } } },
] },
};
The band is a box anchored to the trim and the body starts 10 mm below it. The number is set in Literata Light at 96 pt to the right, where it reads as a shape and leaves the title its full measure.
const palette = {
ink: '#1b1b1f', accent: '#22406a', tint: '#e6ecf4', rule: '#b9bec8', muted: '#5d6370',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.accent })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
The whole recipe
// ═══ Postext Cookbook · Nº 087 · A thesis chapter cited in APA 7 ═══════════════════
// https://postext.dev/en/cookbook/apa-thesis-with-bibtex
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Literata, Public Sans (SIL OFL 1.1) · Needs postext ≥ 1.57.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createCiteprocEngine, STYLES, LOCALES } from 'https://esm.sh/postext-citeproc';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'apa-thesis-with-bibtex';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a thesis prints in black; the one colour is the university's
const palette = {
ink: '#1b1b1f', accent: '#22406a', tint: '#e6ecf4', rule: '#b9bec8', muted: '#5d6370',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.accent })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TEXT = 'Literata', LABEL = 'Public Sans';
const LEAD = 16; // pt: double spacing is a typewriter habit; 1.45 reads as well and fits more
// #region answer: the citation engine, APA 7 and how its references look
// Citations are written [@key, p. 33] and formatted by citeproc-js in the chosen CSL
// style; the references come from the BibTeX block at the end of the chapter. Register
// the engine once, before the first build, then the style is one setting.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = {
style: 'apa', // 'chicago-author-date', 'ieee', 'vancouver'… change nothing else
link: true, // each citation jumps to its entry in the PDF and on screen
bibliography: {
// APA asks for a half-inch hanging indent and keeps the list in the text size.
fontSize: em(1), hangingIndent: mm(12.7), entrySpacing: pt(4),
doi: 'link', // printed whole, as APA wants, and clickable
},
};
// #endregion
// #region opener: a pale band at the head of the page, the number large and light in it
const BAND = 92; // mm from the trim's top
const opener = {
enabled: true,
minHeight: mm(BAND - 28 + 10), // the body starts 10 mm under the band
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('tint') },
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
#Change the style
The same chapter in Chicago author-date drops the comma after the name and lists the year after the authors.
- style: 'apa', // 'chicago-author-date', 'ieee', 'vancouver'… change nothing else
+ style: 'chicago-author-date',#Keep the list smaller than the text
Many universities allow the reference list one size down and single-spaced.
- fontSize: em(1), hangingIndent: mm(12.7), entrySpacing: pt(4),
+ fontSize: em(0.9), lineHeight: pt(13), hangingIndent: mm(12.7), entrySpacing: pt(3),Pitfalls
- APA writes article and book titles in sentence case, and citeproc-js prints titles as the data gives them. Zotero stores most titles in title case, so correct them in Zotero or in the BibTeX before they reach the page.
Credits
- Recipe
- Ignacio Ferro
- Text
- Original prose, CC BY 4.0
- Fonts
- Literata (SIL OFL 1.1) · Public Sans (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


