跳到主要内容
食谱编号97

排版食谱 · 第5章 · 图书结构

用Zotero导出的BibTeX排阅读书目

一份研讨课阅读书目:参考文献是原样粘贴的Zotero BibTeX导出,按Chicago著者-出版年制引用,nocite收入正文未引用的文献。

本页内容
类型
教科书 · 报告
输出
Canvas
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.65.0
许可证
更新于2026年10月31日
代码MIT · 文本CC BY 4.0
  • 英文样例:尚无中文版本
  • 成品尺寸210 × 280 mm
  • 2栏, 栏间距7 mm
  • Spectral 9.6/13.4
  • IBM Plex Sans Condensed
  • 2页
  • 难度
  • Postext 1.65.0
  • 排版用时547 ms
  • 121行代码

简单来说

大学研讨课的阅读书目。老师把Zotero导出的文件贴进稿子,Postext排出文中引文,书目里还收了正文没提到的书。

成品一览

一门为期六周的科学史与科学社会学研讨课的阅读书目,开本210 × 280 mm,分两栏排。第一页上半部是一块深绿色色带,课程名用50 pt的Spectral Light;下面是任课教师逐周的阅读说明。参考文献是这门课的Zotero文献集,导出为BibTeX后一行不改贴进文档:Zotero生成的引用键、保护大写字母的花括号、{\"o}式的重音、month = dec,以及file、keywords、urldate字段。正文引用了其中八种,另外五种是研讨课不讨论的背景读物,通过nocite进入参考文献表。

这道食谱解答

  • 怎样使用从Zotero导出的BibTeX,并列出正文未引用的文献?
  • 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?

简短回答

script.js · 第28–40行在完整代码中
// The works come from a :::references{format=bibtex} block: the Zotero export pasted as it
// is. The text cites some of them; `nocite` in the front matter adds the rest by key, and
// `nocite: "@*"` would add the whole export. citeproc-js writes both in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = {
  style: 'chicago-author-date', // '(Gieryn 1983)', 'Shapin and Schaffer (1985)'
  link: true, // a citation jumps to its entry
  bibliography: {
    // includeUncited: true is the same as nocite: "@*", set from the design side.
    fontSize: em(0.94), lineHeight: pt(12.4), hangingIndent: mm(5), entrySpacing: pt(3.5),
    doi: 'link', // Zotero's doi field prints as https://doi.org/…; its url field is dropped
  },
};

用料

类型
Spectral, IBM Plex Sans Condensed(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 样式只写一次

代码就是上面的简短回答。引用引擎在第一次排版前注册,样式只是一项设置:Chicago著者-出版年制把[@shapin_pump_1984]排成"(Shapin 1984)",把句中的@shapin_leviathan_1985排成"Shapin and Schaffer (1985)"。引用键是Zotero用第一作者、标题第一个实词和年份生成的,所以gieryn_boundary-work_1983里带连字符;Postext把键内部的连字符和下划线都当作键的一部分。

#2 · 导出内容按Zotero写的原样粘贴

文档最后一块是导出内容,每种文献一条,像Zotero那样用制表符缩进:

@article{gieryn_boundary-work_1983,
	title = {Boundary-{Work} and the {Demarcation} of {Science} from {Non}-{Science}: …},
	url = {https://www.jstor.org/stable/2095325},
	doi = {10.2307/2095325},
	urldate = {2026-08-21},
	journal = {American Sociological Review},
	author = {Gieryn, Thomas F.},
	month = dec,
	year = {1983},
	keywords = {demarcation, week 4},
	pages = {781--795},
	file = {JSTOR Full Text PDF:/Users/hps214/Zotero/storage/2HJ8M6PA/Gieryn - 1983 - ….pdf:application/pdf},
}

读取器去掉保护大写的花括号,把{\"o}和{\'e}合成ö和é,把--变成短破折号,并把不带括号的month = dec读作月份名。urldate成为访问日期,language成为文献的语种;file、keywords、abstract和shorttitle被跳过,硬盘上的路径不会印到页面上。

#3 · 收入正文没有引用的文献

在前置元数据里按键列出:

---
title: "Science as a Social Practice"
nocite: "@fleck_genesis_1979, @merton_sociology_1973, @latour_science_1987, @rheinberger_toward_1997, @lopez_pinero_ciencia_1979"
---

参考文献表收入全部被引文献和这五种,按Chicago的要求一起按作者排序,未引用的条目没有任何标记。nocite: "@*"列出整个导出内容;配置里的bibliography.includeUncited: true效果相同,适合总要印出整个文献库的设计。

#4 · 卡片上的一块绿色

script.js · 第44–68行在完整代码中
const BAND = 132; // mm from the trim's top to the band's foot
const onBand = { color: col('paper'), align: 'left', overflow: 'wrap' };
const opener = {
  enabled: true,
  minHeight: mm(BAND - TOP + 9), // the columns start 9 mm under the band
  slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
      placement: { anchor: { to: 'page', edge: 'top-left' },
        size: { width: 'fill', height: mm(BAND) } } },
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', ...onBand, fontFamily: LABEL,
      fontSize: pt(8.5), fontWeight: 600, letterSpacing: pt(1.7), textTransform: 'uppercase',
      placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(14) } } },
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: TEXT,
      fontSize: pt(50), fontWeight: 300, lineHeight: 1.02,
      placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(7) },
        size: { width: mm(150), height: 'auto' } } },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1), color: col('tint'),
      placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(7) },
        size: { width: mm(18) } } },
    { kind: 'text', id: 'lead', content: '{attr.lead}', ...onBand, fontFamily: TEXT,
      italic: true, fontSize: pt(13), lineHeight: 1.3, color: col('tint'),
      placement: { anchor: { to: '#rule', edge: 'below' }, offset: { y: mm(6) },
        size: { width: mm(128), height: 'auto' } } },
  ] },
};

色带是锚定在裁切边上的方框,深132 mm,两栏正文从它下方9 mm处开始。标题、短线和导语用below锚点串在一起,课程名更长时会把导语往下推,而不会叠在一起。

script.js · 第15–21行在完整代码中
const palette = {
  ink: '#1c211f', accent: '#2d5b48', tint: '#dfe9e2', rule: '#c3cdc6', muted: '#5c6862',
  paper: '#ffffff',
};
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º 097 · A reading list from a Zotero BibTeX export ═══════
// https://postext.dev/en/cookbook/zotero-bibtex-nocite
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Spectral, IBM Plex Sans Condensed (SIL OFL 1.1) · Needs postext ≥ 1.65.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 = 'zotero-bibtex-nocite';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a department green, one tint, everything else in ink
const palette = {
  ink: '#1c211f', accent: '#2d5b48', tint: '#dfe9e2', rule: '#c3cdc6', muted: '#5c6862',
  paper: '#ffffff',
};
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, LABEL] = ['Spectral', 'IBM Plex Sans Condensed'];
const LEAD = 13.4; // pt
const [TOP, OUTER] = [24, 18]; // mm

// #region answer: Chicago author-date, and a list that holds more than the text cites
// The works come from a :::references{format=bibtex} block: the Zotero export pasted as it
// is. The text cites some of them; `nocite` in the front matter adds the rest by key, and
// `nocite: "@*"` would add the whole export. citeproc-js writes both in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = {
  style: 'chicago-author-date', // '(Gieryn 1983)', 'Shapin and Schaffer (1985)'
  link: true, // a citation jumps to its entry
  bibliography: {
    // includeUncited: true is the same as nocite: "@*", set from the design side.
    fontSize: em(0.94), lineHeight: pt(12.4), hangingIndent: mm(5), entrySpacing: pt(3.5),
    doi: 'link', // Zotero's doi field prints as https://doi.org/…; its url field is dropped
  },
};
// #endregion

// #region opener: a green field over the top half, the course in white on it
const BAND = 132; // mm from the trim's top to the band's foot
const onBand = { color: col('paper'), align: 'left', overflow: 'wrap' };
const opener = {
  enabled: true,
  minHeight: mm(BAND - TOP + 9), // the columns start 9 mm under the band

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#列出整个Zotero文献集

导出内容本身就是参考文献表时,不必写键:块里的每一条都会印出,无论是否被引用。

-nocite: "@fleck_genesis_1979, @merton_sociology_1973, @latour_science_1987, …"
+nocite: "@*"

#换一种样式

同样的键不做其他改动,就能得到Harvard(Cite Them Right)格式的参考文献表。

-  style: 'chicago-author-date', // '(Gieryn 1983)', 'Shapin and Schaffer (1985)'
+  style: 'harvard-cite-them-right',

常见问题

易错点

nocite中找不到的键会被悄悄丢弃

被引用却没有文献数据的键会触发unknownCitationKey警告,但nocite中对不上任何条目的键会被直接跳过,没有警告。从导出文件里复制键,并数一数列表中的条目。 由参考文献数据生成的文献表 →

  • nocite里的键如果对不上任何条目,会被直接丢掉,没有警告。键要从导出内容里复制,不要手打,并核对页面上的条目数。
  • Zotero按数据生成键:在Zotero里改了作者名或标题,下次导出时键可能变化,所有引用它的地方都会失效。动笔之前先把键固定下来:Zotero会读取条目“其他”(Extra)字段里的Citation Key: …一行。
  • Zotero默认以UTF-8导出,重音字符原样保留。本例的块是用Western编码选项导出的,所以写成{\"o};Postext两种都能读。
  • Chicago第18版不印出版地,所以address字段不出现;有DOI的文章印DOI,而不印JSTOR的url。

致谢

文本
原创文字, CC BY 4.0
字体
Spectral (SIL OFL 1.1) · IBM Plex Sans Condensed (SIL OFL 1.1)
沙盒