简单来说
博士论文的一章。作者给每条文献起一个短代号写进正文,Postext按APA格式印出文中引文和章末的参考文献表。
成品一览
一篇教育学博士论文的第二章,文献综述:二十年来关于纸上阅读和屏幕阅读的研究说了什么。这一章用A4纸,左侧装订,正文是Literata,行距16 pt,章首压着一条大学蓝色的浅色色带。作者用Zotero管理文献,把导出的BibTeX贴进稿子;正文里每条文献只是一个代号。Postext把每条引文排成APA 7:作者、年份,给了页码就加页码;名字作为句子成分时写成"Delgado et al. (2018)";参考文献表按APA要求的顺序和格式生成。导师要改成Chicago时,只改样式这一行。
这道食谱解答
- 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?
简短回答
// 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
},
};
用料
- 类型
- Literata, Public Sans(SIL OFL 1.1)
- 素材
- 无:所有图片都用代码绘制
做法
#1 · 一个引擎,一种样式
代码就是上面的简短回答。Postext识别引文,措辞交给引用引擎,在第一次排版前注册一次即可;postext-citeproc封装了Zotero和Mendeley所用的citeproc-js,自带十六种CSL样式及其语言文件。[@mangen2013]得到"(Mangen et al., 2013)",不带方括号的@delgado2018把作者放进句子,[@ibanez2023, pp. 12–15]把页码范围带进括号。文档改成西班牙文时,同样的代号会改用西班牙文语言文件里的连接词和缩写,因为引擎跟随文档的语言。
#2 · 文献来自BibTeX块
本章最后一块是:::references{format=bibtex},里面贴着Zotero的导出,重音写作{\'a}。上面的:::bibliography把文献表放在References标题之下;不写它,Postext就把文献表加在文末。表里只列被引用的文献,按APA的规则排序,正文里每条引文都链接到对应条目。
#3 · 不编号的标题,用文字表达的节号引用
headingStyles: [{ id: 'references', numbered: false }],
crossRefs: { section: t({ en: 'Section {n}', es: 'Sección {n}' }) },
参考文献标题使用references样式,留在目录里但不参与编号,所以文献表不会变成第2.4节。:ref{id="sec-speed"}按crossRefs的标签印出"Section 2.2"并链接到该标题;节号来自章标题上的startAt=2,与各级标题共用同一个计数器。
#4 · 章首放在色带里
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' } } },
] },
};
色带是一个锚定在页面裁切边上的方框,正文从它下方10 mm处开始。章号用96 pt的Literata Light放在右侧,读起来像一个图形,把整行宽度留给标题。
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' } }));
完整食谱
// ═══ 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') },
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#换一种样式
同一章改用Chicago著者-出版年制,作者名后不加逗号,年份紧跟在作者之后。
- style: 'apa', // 'chicago-author-date', 'ieee', 'vancouver'… change nothing else
+ style: 'chicago-author-date',#让文献表比正文小一号
不少大学允许参考文献表缩小一号、单倍行距。
- fontSize: em(1), hangingIndent: mm(12.7), entrySpacing: pt(4),
+ fontSize: em(0.9), lineHeight: pt(13), hangingIndent: mm(12.7), entrySpacing: pt(3),常见问题
- APA要求文章和图书标题只大写首字母,而citeproc-js按数据原样印出标题。Zotero里的标题多半每个词首字母大写,所以要在Zotero或BibTeX里改好,再让它们上版。
致谢
- 文本
- 原创文字, CC BY 4.0
- 字体
- Literata (SIL OFL 1.1) · Public Sans (SIL OFL 1.1)


