简单来说
一篇双栏排的会议短论文。作者给每条文献起一个代号,Postext按方括号数字编号引文,按编号和页码引用各节,并在文末印出编号的参考文献表。
成品一览
一篇为文献工程小型研讨会写的两页论文,按IEEE会议论文集的做法排版:US Letter开本,两栏各宽三英寸半,10 pt的Times类字体,各节用居中大写的I、II、III编号。标题、三个作者信息块、摘要和关键词横跨两栏,压在一条研讨会蓝色的浅色色带下,这是页面上唯一的颜色。作者用BibTeX代号引用;Postext按文献首次被引的顺序印出[1],把三条连续文献合并成[2]–[4],作者名作为句子成分时写成"Knuth and Plass [1]",并在文末生成8 pt的编号文献表。节号引用印作"Section IV, on p. 2",正文变动后仍然正确。
这道食谱解答
- 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?
- 怎样引用某一节及其所在页码,并在书变动时保持正确?
简短回答
// [@key] prints [1] in order of first citation, @key in the sentence "Knuth and Plass [1]".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// The bundled IEEE style lists [2], [3], [4]; the IEEE editorial guide writes [2]–[4].
// One attribute on the CSL <citation> element makes citeproc-js join the run.
const ieee = STYLES.ieee.replace('<citation>', '<citation collapse="citation-number">');
const citations = {
style: 'custom', customStyle: ieee, // or style: 'ieee' for the file as it ships
link: true,
bibliography: {
fontSize: em(0.8), lineHeight: pt(9.4), // 8 pt on 9.4 pt, two sizes under the text
labelWidth: mm(6), // the [n] column: wide enough for [10], the turnovers align after it
entrySpacing: pt(1.2),
doi: 'text', // printed, not linked: the PDF stays black
},
};
用料
- 类型
- STIX Two Text, Schibsted Grotesk(SIL OFL 1.1)
- 素材
- 无:所有图片都用代码绘制
做法
#1 · IEEE样式和编号合并
代码就是上面的简短回答。注册一次后,postext-citeproc用citeproc-js和IEEE的CSL样式排出每个[@key],按首次引用的顺序编号。引擎自带的样式文件把三条连续文献写成[2], [3], [4];IEEE编辑指南则合并为[2]–[4]。在样式的<citation>元素上加collapse="citation-number",再把结果作为customStyle传入,citeproc-js就会合并。labelWidth让文献表的编号单独占一栏,条目的第二行从第一个词下方开始,而不是从方括号下方开始。
#2 · 横跨两栏的标题区
const text = (id, content, size, extra) => ({ kind: 'text', id, content, fontFamily: SERIF,
fontSize: pt(size), color: col('ink'), align: 'center', overflow: 'wrap', ...extra });
const at = (to, edge, x, y, width) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
...(width && { size: { width: mm(width), height: 'auto' } }) });
const AUTHOR_W = MEASURE / 3;
const titleBlock = {
enabled: true,
minHeight: mm(64), // venue line, two lines of title and five of author block
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('tint') }, // from the trim's top
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(TOP + 66) } } },
text('venue', '{attr.venue}', 7.5, { fontFamily: SANS, fontWeight: 600, color: col('accent'),
letterSpacing: pt(1.2), textTransform: 'uppercase',
placement: at('container', 'top-left', 0, 0, MEASURE) }),
{ kind: 'rule', id: 'venue-rule', thickness: pt(0.5), color: col('rule'),
placement: at('#venue', 'below', 0, 2, MEASURE) },
text('title', '{titleText}', 23, { lineHeight: 1.1, placement: at('#venue', 'below', 0, 7,
MEASURE) }),
...['a1', 'a2', 'a3'].map((id, i) => text(id, `{attr.${id}}`, 9.5, { lineHeight: 1.25,
placement: at('#title', 'below', i * AUTHOR_W, 6, AUTHOR_W) })),
] },
};
标题是文档中唯一的一级标题,使用paper样式。该样式通栏,用自己的设计绘制标题:研讨会名称、论文标题和三个各占三分之一版心宽的作者信息块,每块读取一个标题属性,属性里的\n用来换行。色带是锚定在裁切边上的方框,所以一直延伸到纸张上边缘。
#3 · 粗体的摘要和关键词
const calloutStyles = [{ id: 'abstract', span: 'page', backgroundEnabled: false,
border: { enabled: false }, stripe: { enabled: true, side: 'top', width: pt(0.5),
color: col('rule') },
padding: { top: mm(3), right: mm(14), bottom: mm(1), left: mm(14) },
marginTop: pt(0), marginBottom: pt(LEAD),
body: { fontSize: pt(9), lineHeight: pt(11), fontWeight: 700, firstLineIndent: pt(0),
textAlign: 'justify', paragraphSpacing: true } }];
一个通栏的标注框装着摘要和关键词。框内正文是9 pt粗体,和IEEE的做法一样;正文里的***Abstract*—**得到带破折号的斜体标签。上方的细线是框的色条,内边距把行长收窄到约一百个字符。
#4 · 编号的节和对节的引用
const levels = [
{ level: 1, breakBefore: { enabled: true, parity: 'any' } }, // any page: no forced recto
{ level: 2, numberingTemplate: '{2:I}.', numberSeparator: ' ', fontSize: pt(9),
lineHeight: pt(LEAD), fontWeight: 400, letterSpacing: em(0.06), textTransform: 'uppercase',
marginTop: pt(LEAD), marginBottom: pt(0) }, // a line above, none below: at a column's head
// the margin above drops and the text still starts on the next grid line
];
const headingStyles = [
{ id: 'paper', numbered: false, span: 'page', advancedDesign: titleBlock },
{ id: 'back', numbered: false }, // Acknowledgment and References: no number
];
const crossRefs = { section: t({ en: 'Section {n}', es: 'sección {n}' }) };
{2:I}.把各节编为I.、II.、III.。引用印出不带句点的编号,所以:ref{id="sec:results"}按crossRefs的模板得到"Section IV",:ref{id="sec:results" style=page}得到"p. 2"。两者都根据排好的页面计算,增加段落或移动某节后仍会随正文更新。致谢和参考文献标题使用back样式,不编号。
const palette = {
ink: '#16181d', accent: '#1d4a7a', tint: '#e9eef5', rule: '#aeb6c2', muted: '#5a606b',
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º 088 · A two-column conference paper in IEEE style ═══════
// https://postext.dev/en/cookbook/ieee-conference-paper
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: STIX Two Text, Schibsted Grotesk (SIL OFL 1.1) · Needs postext ≥ 1.65.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 = 'ieee-conference-paper';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black type on white, with one blue for the workshop's own marks
const palette = {
ink: '#16181d', accent: '#1d4a7a', tint: '#e9eef5', rule: '#aeb6c2', muted: '#5a606b',
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 [SERIF, SANS] = ['STIX Two Text', 'Schibsted Grotesk'];
// The IEEE conference template in mm: US letter, 0.75 in head, 1 in foot, 0.625 in sides,
// two columns of 3.5 in with 0.25 in between.
const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 19, 25.4, 15.9, 6.35];
const MEASURE = TRIM_W - 2 * SIDE;
const LEAD = 12; // pt: 10 pt type on 12 pt, as the template sets it
// #region answer: IEEE numbers, collapsed ranges and a references list with a label column
// [@key] prints [1] in order of first citation, @key in the sentence "Knuth and Plass [1]".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// The bundled IEEE style lists [2], [3], [4]; the IEEE editorial guide writes [2]–[4].
// One attribute on the CSL <citation> element makes citeproc-js join the run.
const ieee = STYLES.ieee.replace('<citation>', '<citation collapse="citation-number">');
const citations = {
style: 'custom', customStyle: ieee, // or style: 'ieee' for the file as it ships
link: true,
bibliography: {
fontSize: em(0.8), lineHeight: pt(9.4), // 8 pt on 9.4 pt, two sizes under the text
labelWidth: mm(6), // the [n] column: wide enough for [10], the turnovers align after it
entrySpacing: pt(1.2),
doi: 'text', // printed, not linked: the PDF stays black
},
};
// #endregion
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#保留样式原样
不做修改时,三条连续文献逐条印出,有些期刊就要求这样。
- style: 'custom', customStyle: ieee, // or style: 'ieee' for the file as it ships
+ style: 'ieee',#把区间写在一对方括号里
另一些顺序编码样式印作[2–4]。brackets标记自己写编号,并把连续的编号合并。
- style: 'custom', customStyle: ieee, // or style: 'ieee' for the file as it ships
+ style: 'ieee', marker: 'brackets', collapseRanges: true,常见问题
- 末页两栏底部不齐时,看看本该切齐的位置上是什么:引擎不会把节标题留在栏底而让正文去下一栏,宁可放弃切齐。在最后几节里增删一句,就能把切齐的位置移过标题。
- BibTeX命令如
{\TeX}不会展开。写成The {TeX}book,花括号会保持字母大小写不变。
致谢
- 文本
- 原创文字, CC BY 4.0
- 字体
- STIX Two Text (SIL OFL 1.1) · Schibsted Grotesk (SIL OFL 1.1)


