简单来说
同样两段谈排版的文字、同样的文献,印了四遍。每一页用一种不同的引用方式,文中引文和文末的文献表随之改变,而正文只写了一次。
成品一览
一篇两段的短文,谈好的排版为什么让人察觉不到,引用了六种文献:一处叙述式引文,一处带页码,一处因句子已提到作者而省去作者,还有两部一起引用的著作。正文在155 × 235 mm的页面上排了四遍,四次排版之间唯一的差别是citations.style:APA 7、Chicago著者-出版年制、IEEE和ISO 690。每页在各自颜色的色带上印出样式名,并排放在一起就是一张对照表。引文的形式、顺序和标点都变了,文献表的排序和姓名写法也变了,而短文本身是同一个文件。
这道食谱解答
- 怎样在不改正文的情况下把全书换成另一种引用样式?
- 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?
简短回答
// 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' },
});
用料
- 还用到
- 标题属性
- 类型
- Source Serif 4, Source Sans 3(SIL OFL 1.1)
- 素材
- 无:所有图片都用代码绘制
做法
#1 · 一项设置
代码就是上面的简短回答。引文按Pandoc的语法在内容里写一次,文献放在末尾的BibTeX块里。citations.style指定一种CSL样式,citeproc-js据此写出每条引文和每个条目:APA在年份前加逗号,并按作者给两部著作排序;Chicago保持书写的顺序;IEEE按首次引用的顺序改成数字;ISO 690把文献表里的姓氏改成大写。对于正在写的书,要改的就只有这些:配置里的一个值,正文一字不动。
#2 · 四次排版,两个对开页
// 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)));
}
样式对整份文档生效,所以四个版本是同一份Markdown的四次排版。每次的pageIndexOffset比上一次多一,让这一页成为一本假想书的下一页;展示台于是把它们配成两个对开页,差别最小的两种著者-出版年样式并排。
#3 · 色带上的样式名
// 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' } } },
] },
});
标题的设计从裁切边画出色带,再写上标明样式序号和体系的眉题,以及54 pt的样式名。样式名和体系来自脚本而不是Markdown,因为四份文档的正文完全相同。
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' } }));
每份文档把main-color指向自己的色带,所以四种颜色都是调色板里的关联条目,配置没有写明的默认值会跟随本页的色带。
完整食谱
// ═══ 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
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#试试注释样式
换成Chicago注释-书目样式,每条引文变成脚注,文献表改为参考文献(bibliography);正文仍然不变。
- { 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' },#把编号写成上标
顺序编码样式可以保留文献表,把文中引文印成上标数字,Nature和Vancouver就是这样。
- link: true,
+ link: true, marker: 'superscript',常见问题
- 定位信息只写一次,各样式用自己的词印出来:这里四种样式都印作"p. 17"。引擎自带的西班牙文ISO 690样式对任何定位信息都印"p.",章节也不例外,所以这篇文字引的是页码。
- BibTeX里的版次要写成数字(
edition = {3}),各样式才会按自己的方式写成"3rd ed."、"3.ª ed."或"3."。写成"3rd"就会原样印出,样式自己的写法便丢了。
致谢
- 文本
- 原创文字, CC BY 4.0
- 字体
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)


